clang 20.0.0git
ASTImporter.cpp
Go to the documentation of this file.
1//===- ASTImporter.cpp - Importing ASTs from other Contexts ---------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ASTImporter class which imports AST nodes from one
10// context into another context.
11//
12//===----------------------------------------------------------------------===//
13
19#include "clang/AST/Attr.h"
20#include "clang/AST/Decl.h"
22#include "clang/AST/DeclBase.h"
23#include "clang/AST/DeclCXX.h"
25#include "clang/AST/DeclGroup.h"
26#include "clang/AST/DeclObjC.h"
30#include "clang/AST/Expr.h"
31#include "clang/AST/ExprCXX.h"
32#include "clang/AST/ExprObjC.h"
37#include "clang/AST/Stmt.h"
38#include "clang/AST/StmtCXX.h"
39#include "clang/AST/StmtObjC.h"
43#include "clang/AST/Type.h"
44#include "clang/AST/TypeLoc.h"
51#include "clang/Basic/LLVM.h"
56#include "llvm/ADT/ArrayRef.h"
57#include "llvm/ADT/DenseMap.h"
58#include "llvm/ADT/STLExtras.h"
59#include "llvm/ADT/ScopeExit.h"
60#include "llvm/ADT/SmallVector.h"
61#include "llvm/Support/ErrorHandling.h"
62#include "llvm/Support/MemoryBuffer.h"
63#include <algorithm>
64#include <cassert>
65#include <cstddef>
66#include <memory>
67#include <optional>
68#include <type_traits>
69#include <utility>
70
71namespace clang {
72
73 using llvm::make_error;
74 using llvm::Error;
75 using llvm::Expected;
83
84 std::string ASTImportError::toString() const {
85 // FIXME: Improve error texts.
86 switch (Error) {
87 case NameConflict:
88 return "NameConflict";
90 return "UnsupportedConstruct";
91 case Unknown:
92 return "Unknown error";
93 }
94 llvm_unreachable("Invalid error code.");
95 return "Invalid error code.";
96 }
97
98 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
99
100 std::error_code ASTImportError::convertToErrorCode() const {
101 llvm_unreachable("Function not implemented.");
102 }
103
105
106 template <class T>
110 for (auto *R : D->getFirstDecl()->redecls()) {
111 if (R != D->getFirstDecl())
112 Redecls.push_back(R);
113 }
114 Redecls.push_back(D->getFirstDecl());
115 std::reverse(Redecls.begin(), Redecls.end());
116 return Redecls;
117 }
118
120 if (auto *FD = dyn_cast<FunctionDecl>(D))
121 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
122 if (auto *VD = dyn_cast<VarDecl>(D))
123 return getCanonicalForwardRedeclChain<VarDecl>(VD);
124 if (auto *TD = dyn_cast<TagDecl>(D))
125 return getCanonicalForwardRedeclChain<TagDecl>(TD);
126 llvm_unreachable("Bad declaration kind");
127 }
128
129 static void updateFlags(const Decl *From, Decl *To) {
130 // Check if some flags or attrs are new in 'From' and copy into 'To'.
131 // FIXME: Other flags or attrs?
132 if (From->isUsed(false) && !To->isUsed(false))
133 To->setIsUsed();
134 }
135
136 /// How to handle import errors that occur when import of a child declaration
137 /// of a DeclContext fails.
139 /// This context is imported (in the 'from' domain).
140 /// It is nullptr if a non-DeclContext is imported.
141 const DeclContext *const FromDC;
142 /// Ignore import errors of the children.
143 /// If true, the context can be imported successfully if a child
144 /// of it failed to import. Otherwise the import errors of the child nodes
145 /// are accumulated (joined) into the import error object of the parent.
146 /// (Import of a parent can fail in other ways.)
147 bool const IgnoreChildErrors;
148
149 public:
151 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
153 : FromDC(dyn_cast<DeclContext>(FromD)),
154 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
155
156 /// Process the import result of a child (of the current declaration).
157 /// \param ResultErr The import error that can be used as result of
158 /// importing the parent. This may be changed by the function.
159 /// \param ChildErr Result of importing a child. Can be success or error.
160 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
161 if (ChildErr && !IgnoreChildErrors)
162 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
163 else
164 consumeError(std::move(ChildErr));
165 }
166
167 /// Determine if import failure of a child does not cause import failure of
168 /// its parent.
169 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
170 if (!IgnoreChildErrors || !FromDC)
171 return false;
172 return FromDC->containsDecl(FromChildD);
173 }
174 };
175
176 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
177 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
178 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
179 ASTImporter &Importer;
180
181 // Use this instead of Importer.importInto .
182 template <typename ImportT>
183 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
184 return Importer.importInto(To, From);
185 }
186
187 // Use this to import pointers of specific type.
188 template <typename ImportT>
189 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
190 auto ToOrErr = Importer.Import(From);
191 if (ToOrErr)
192 To = cast_or_null<ImportT>(*ToOrErr);
193 return ToOrErr.takeError();
194 }
195
196 // Call the import function of ASTImporter for a baseclass of type `T` and
197 // cast the return value to `T`.
198 template <typename T>
199 auto import(T *From)
200 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
202 auto ToOrErr = Importer.Import(From);
203 if (!ToOrErr)
204 return ToOrErr.takeError();
205 return cast_or_null<T>(*ToOrErr);
206 }
207
208 template <typename T>
209 auto import(const T *From) {
210 return import(const_cast<T *>(From));
211 }
212
213 // Call the import function of ASTImporter for type `T`.
214 template <typename T>
215 Expected<T> import(const T &From) {
216 return Importer.Import(From);
217 }
218
219 // Import an std::optional<T> by importing the contained T, if any.
220 template <typename T>
221 Expected<std::optional<T>> import(std::optional<T> From) {
222 if (!From)
223 return std::nullopt;
224 return import(*From);
225 }
226
227 ExplicitSpecifier importExplicitSpecifier(Error &Err,
228 ExplicitSpecifier ESpec);
229
230 // Wrapper for an overload set.
231 template <typename ToDeclT> struct CallOverloadedCreateFun {
232 template <typename... Args> decltype(auto) operator()(Args &&... args) {
233 return ToDeclT::Create(std::forward<Args>(args)...);
234 }
235 };
236
237 // Always use these functions to create a Decl during import. There are
238 // certain tasks which must be done after the Decl was created, e.g. we
239 // must immediately register that as an imported Decl. The parameter `ToD`
240 // will be set to the newly created Decl or if had been imported before
241 // then to the already imported Decl. Returns a bool value set to true if
242 // the `FromD` had been imported before.
243 template <typename ToDeclT, typename FromDeclT, typename... Args>
244 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
245 Args &&...args) {
246 // There may be several overloads of ToDeclT::Create. We must make sure
247 // to call the one which would be chosen by the arguments, thus we use a
248 // wrapper for the overload set.
249 CallOverloadedCreateFun<ToDeclT> OC;
250 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
251 std::forward<Args>(args)...);
252 }
253 // Use this overload if a special Type is needed to be created. E.g if we
254 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
255 // then:
256 // TypedefNameDecl *ToTypedef;
257 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
258 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
259 typename... Args>
260 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
261 Args &&...args) {
262 CallOverloadedCreateFun<NewDeclT> OC;
263 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
264 std::forward<Args>(args)...);
265 }
266 // Use this version if a special create function must be
267 // used, e.g. CXXRecordDecl::CreateLambda .
268 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
269 typename... Args>
270 [[nodiscard]] bool
271 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
272 FromDeclT *FromD, Args &&...args) {
273 if (Importer.getImportDeclErrorIfAny(FromD)) {
274 ToD = nullptr;
275 return true; // Already imported but with error.
276 }
277 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
278 if (ToD)
279 return true; // Already imported.
280 ToD = CreateFun(std::forward<Args>(args)...);
281 // Keep track of imported Decls.
282 Importer.RegisterImportedDecl(FromD, ToD);
283 Importer.SharedState->markAsNewDecl(ToD);
284 InitializeImportedDecl(FromD, ToD);
285 return false; // A new Decl is created.
286 }
287
288 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
289 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
290 if (FromD->isUsed())
291 ToD->setIsUsed();
292 if (FromD->isImplicit())
293 ToD->setImplicit();
294 }
295
296 // Check if we have found an existing definition. Returns with that
297 // definition if yes, otherwise returns null.
298 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
299 const FunctionDecl *Definition = nullptr;
300 if (D->doesThisDeclarationHaveABody() &&
301 FoundFunction->hasBody(Definition))
302 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
303 return nullptr;
304 }
305
306 void addDeclToContexts(Decl *FromD, Decl *ToD) {
307 if (Importer.isMinimalImport()) {
308 // In minimal import case the decl must be added even if it is not
309 // contained in original context, for LLDB compatibility.
310 // FIXME: Check if a better solution is possible.
311 if (!FromD->getDescribedTemplate() &&
312 FromD->getFriendObjectKind() == Decl::FOK_None)
314 return;
315 }
316
317 DeclContext *FromDC = FromD->getDeclContext();
318 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
319 DeclContext *ToDC = ToD->getDeclContext();
320 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
321
322 bool Visible = false;
323 if (FromDC->containsDeclAndLoad(FromD)) {
324 ToDC->addDeclInternal(ToD);
325 Visible = true;
326 }
327 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
328 ToLexicalDC->addDeclInternal(ToD);
329 Visible = true;
330 }
331
332 // If the Decl was added to any context, it was made already visible.
333 // Otherwise it is still possible that it should be visible.
334 if (!Visible) {
335 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
336 auto *ToNamed = cast<NamedDecl>(ToD);
337 DeclContextLookupResult FromLookup =
338 FromDC->lookup(FromNamed->getDeclName());
339 if (llvm::is_contained(FromLookup, FromNamed))
340 ToDC->makeDeclVisibleInContext(ToNamed);
341 }
342 }
343 }
344
345 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
346 DeclContext *OldDC) {
347 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
348 if (!LT)
349 return;
350
351 for (NamedDecl *TP : Params)
352 LT->update(TP, OldDC);
353 }
354
355 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
356 updateLookupTableForTemplateParameters(
357 Params, Importer.getToContext().getTranslationUnitDecl());
358 }
359
360 template <typename TemplateParmDeclT>
361 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
362 TemplateParmDeclT *ToD) {
363 if (D->hasDefaultArgument()) {
364 if (D->defaultArgumentWasInherited()) {
365 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
366 import(D->getDefaultArgStorage().getInheritedFrom());
367 if (!ToInheritedFromOrErr)
368 return ToInheritedFromOrErr.takeError();
369 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
370 if (!ToInheritedFrom->hasDefaultArgument()) {
371 // Resolve possible circular dependency between default value of the
372 // template argument and the template declaration.
373 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
374 import(D->getDefaultArgStorage()
375 .getInheritedFrom()
376 ->getDefaultArgument());
377 if (!ToInheritedDefaultArgOrErr)
378 return ToInheritedDefaultArgOrErr.takeError();
379 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
380 *ToInheritedDefaultArgOrErr);
381 }
382 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
383 ToInheritedFrom);
384 } else {
385 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
386 import(D->getDefaultArgument());
387 if (!ToDefaultArgOrErr)
388 return ToDefaultArgOrErr.takeError();
389 // Default argument could have been set in the
390 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
391 if (!ToD->hasDefaultArgument())
392 ToD->setDefaultArgument(Importer.getToContext(),
393 *ToDefaultArgOrErr);
394 }
395 }
396 return Error::success();
397 }
398
399 public:
400 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
401
405
406 // Importing types
408#define TYPE(Class, Base) \
409 ExpectedType Visit##Class##Type(const Class##Type *T);
410#include "clang/AST/TypeNodes.inc"
411
412 // Importing declarations
415 Error ImportDeclParts(
416 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
418 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
421 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
422 Error ImportDeclContext(
423 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
424 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
425
426 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
428 Expected<APValue> ImportAPValue(const APValue &FromValue);
429
431
432 /// What we should import from the definition.
434 /// Import the default subset of the definition, which might be
435 /// nothing (if minimal import is set) or might be everything (if minimal
436 /// import is not set).
438 /// Import everything.
440 /// Import only the bare bones needed to establish a valid
441 /// DeclContext.
443 };
444
446 return IDK == IDK_Everything ||
447 (IDK == IDK_Default && !Importer.isMinimalImport());
448 }
449
450 Error ImportInitializer(VarDecl *From, VarDecl *To);
451 Error ImportDefinition(
452 RecordDecl *From, RecordDecl *To,
454 Error ImportDefinition(
455 EnumDecl *From, EnumDecl *To,
457 Error ImportDefinition(
460 Error ImportDefinition(
467
468 template <typename InContainerTy>
470 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
471
472 template<typename InContainerTy>
474 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
475 const InContainerTy &Container, TemplateArgumentListInfo &Result);
476
479 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
482 FunctionDecl *FromFD);
483
484 template <typename DeclTy>
485 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
486
488
490
491 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
492 ParmVarDecl *ToParam);
493
496
497 template <typename T>
499
500 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
501 bool IgnoreTemplateParmDepth = false);
548
551
566
567 // Importing statements
587 // FIXME: MSAsmStmt
588 // FIXME: SEHExceptStmt
589 // FIXME: SEHFinallyStmt
590 // FIXME: SEHTryStmt
591 // FIXME: SEHLeaveStmt
592 // FIXME: CapturedStmt
596 // FIXME: MSDependentExistsStmt
604
605 // Importing expressions
682
683 // Helper for chaining together multiple imports. If an error is detected,
684 // subsequent imports will return default constructed nodes, so that failure
685 // can be detected with a single conditional branch after a sequence of
686 // imports.
687 template <typename T> T importChecked(Error &Err, const T &From) {
688 // Don't attempt to import nodes if we hit an error earlier.
689 if (Err)
690 return T{};
691 Expected<T> MaybeVal = import(From);
692 if (!MaybeVal) {
693 Err = MaybeVal.takeError();
694 return T{};
695 }
696 return *MaybeVal;
697 }
698
699 template<typename IIter, typename OIter>
700 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
701 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
702 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
703 Expected<ItemT> ToOrErr = import(*Ibegin);
704 if (!ToOrErr)
705 return ToOrErr.takeError();
706 *Obegin = *ToOrErr;
707 }
708 return Error::success();
709 }
710
711 // Import every item from a container structure into an output container.
712 // If error occurs, stops at first error and returns the error.
713 // The output container should have space for all needed elements (it is not
714 // expanded, new items are put into from the beginning).
715 template<typename InContainerTy, typename OutContainerTy>
717 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
718 return ImportArrayChecked(
719 InContainer.begin(), InContainer.end(), OutContainer.begin());
720 }
721
722 template<typename InContainerTy, typename OIter>
723 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
724 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
725 }
726
728 CXXMethodDecl *FromMethod);
729
731 FunctionDecl *FromFD);
732
733 // Returns true if the given function has a placeholder return type and
734 // that type is declared inside the body of the function.
735 // E.g. auto f() { struct X{}; return X(); }
737 };
738
739template <typename InContainerTy>
741 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
742 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
743 auto ToLAngleLocOrErr = import(FromLAngleLoc);
744 if (!ToLAngleLocOrErr)
745 return ToLAngleLocOrErr.takeError();
746 auto ToRAngleLocOrErr = import(FromRAngleLoc);
747 if (!ToRAngleLocOrErr)
748 return ToRAngleLocOrErr.takeError();
749
750 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
751 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
752 return Err;
753 Result = ToTAInfo;
754 return Error::success();
755}
756
757template <>
758Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
761 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
762}
763
764template <>
767 const ASTTemplateArgumentListInfo &From,
769 return ImportTemplateArgumentListInfo(
770 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
771}
772
775 FunctionDecl *FromFD) {
776 assert(FromFD->getTemplatedKind() ==
778
780
781 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
782 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
783 return std::move(Err);
784
785 // Import template arguments.
786 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
787 std::get<1>(Result)))
788 return std::move(Err);
789
790 return Result;
791}
792
793template <>
795ASTNodeImporter::import(TemplateParameterList *From) {
797 if (Error Err = ImportContainerChecked(*From, To))
798 return std::move(Err);
799
800 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
801 if (!ToRequiresClause)
802 return ToRequiresClause.takeError();
803
804 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
805 if (!ToTemplateLocOrErr)
806 return ToTemplateLocOrErr.takeError();
807 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
808 if (!ToLAngleLocOrErr)
809 return ToLAngleLocOrErr.takeError();
810 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
811 if (!ToRAngleLocOrErr)
812 return ToRAngleLocOrErr.takeError();
813
815 Importer.getToContext(),
816 *ToTemplateLocOrErr,
817 *ToLAngleLocOrErr,
818 To,
819 *ToRAngleLocOrErr,
820 *ToRequiresClause);
821}
822
823template <>
825ASTNodeImporter::import(const TemplateArgument &From) {
826 switch (From.getKind()) {
828 return TemplateArgument();
829
831 ExpectedType ToTypeOrErr = import(From.getAsType());
832 if (!ToTypeOrErr)
833 return ToTypeOrErr.takeError();
834 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
835 From.getIsDefaulted());
836 }
837
839 ExpectedType ToTypeOrErr = import(From.getIntegralType());
840 if (!ToTypeOrErr)
841 return ToTypeOrErr.takeError();
842 return TemplateArgument(From, *ToTypeOrErr);
843 }
844
846 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
847 if (!ToOrErr)
848 return ToOrErr.takeError();
849 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
850 if (!ToTypeOrErr)
851 return ToTypeOrErr.takeError();
852 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
853 *ToTypeOrErr, From.getIsDefaulted());
854 }
855
857 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
858 if (!ToTypeOrErr)
859 return ToTypeOrErr.takeError();
860 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
861 From.getIsDefaulted());
862 }
863
865 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
866 if (!ToTypeOrErr)
867 return ToTypeOrErr.takeError();
868 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
869 if (!ToValueOrErr)
870 return ToValueOrErr.takeError();
871 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
872 *ToValueOrErr);
873 }
874
876 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
877 if (!ToTemplateOrErr)
878 return ToTemplateOrErr.takeError();
879
880 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
881 }
882
884 Expected<TemplateName> ToTemplateOrErr =
885 import(From.getAsTemplateOrTemplatePattern());
886 if (!ToTemplateOrErr)
887 return ToTemplateOrErr.takeError();
888
889 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
890 From.getIsDefaulted());
891 }
892
894 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
895 return TemplateArgument(*ToExpr, From.getIsDefaulted());
896 else
897 return ToExpr.takeError();
898
901 ToPack.reserve(From.pack_size());
902 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
903 return std::move(Err);
904
905 return TemplateArgument(
906 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
907 }
908 }
909
910 llvm_unreachable("Invalid template argument kind");
911}
912
913template <>
915ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
916 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
917 if (!ArgOrErr)
918 return ArgOrErr.takeError();
919 TemplateArgument Arg = *ArgOrErr;
920
921 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
922
925 ExpectedExpr E = import(FromInfo.getAsExpr());
926 if (!E)
927 return E.takeError();
928 ToInfo = TemplateArgumentLocInfo(*E);
929 } else if (Arg.getKind() == TemplateArgument::Type) {
930 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
931 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
932 else
933 return TSIOrErr.takeError();
934 } else {
935 auto ToTemplateQualifierLocOrErr =
936 import(FromInfo.getTemplateQualifierLoc());
937 if (!ToTemplateQualifierLocOrErr)
938 return ToTemplateQualifierLocOrErr.takeError();
939 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
940 if (!ToTemplateNameLocOrErr)
941 return ToTemplateNameLocOrErr.takeError();
942 auto ToTemplateEllipsisLocOrErr =
943 import(FromInfo.getTemplateEllipsisLoc());
944 if (!ToTemplateEllipsisLocOrErr)
945 return ToTemplateEllipsisLocOrErr.takeError();
947 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
948 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
949 }
950
951 return TemplateArgumentLoc(Arg, ToInfo);
952}
953
954template <>
955Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
956 if (DG.isNull())
957 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
958 size_t NumDecls = DG.end() - DG.begin();
960 ToDecls.reserve(NumDecls);
961 for (Decl *FromD : DG) {
962 if (auto ToDOrErr = import(FromD))
963 ToDecls.push_back(*ToDOrErr);
964 else
965 return ToDOrErr.takeError();
966 }
967 return DeclGroupRef::Create(Importer.getToContext(),
968 ToDecls.begin(),
969 NumDecls);
970}
971
972template <>
974ASTNodeImporter::import(const Designator &D) {
975 if (D.isFieldDesignator()) {
976 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
977
978 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
979 if (!ToDotLocOrErr)
980 return ToDotLocOrErr.takeError();
981
982 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
983 if (!ToFieldLocOrErr)
984 return ToFieldLocOrErr.takeError();
985
987 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
988 }
989
990 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
991 if (!ToLBracketLocOrErr)
992 return ToLBracketLocOrErr.takeError();
993
994 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
995 if (!ToRBracketLocOrErr)
996 return ToRBracketLocOrErr.takeError();
997
998 if (D.isArrayDesignator())
999 return Designator::CreateArrayDesignator(D.getArrayIndex(),
1000 *ToLBracketLocOrErr,
1001 *ToRBracketLocOrErr);
1002
1003 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1004 if (!ToEllipsisLocOrErr)
1005 return ToEllipsisLocOrErr.takeError();
1006
1007 assert(D.isArrayRangeDesignator());
1009 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1010 *ToRBracketLocOrErr);
1011}
1012
1013template <>
1014Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1015 Error Err = Error::success();
1016 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1017 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1018 auto ToConceptNameLoc =
1019 importChecked(Err, From->getConceptNameInfo().getLoc());
1020 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1021 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1022 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1023 if (Err)
1024 return std::move(Err);
1025 TemplateArgumentListInfo ToTAInfo;
1026 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1027 if (ASTTemplateArgs)
1028 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1029 return std::move(Err);
1030 auto *ConceptRef = ConceptReference::Create(
1031 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1032 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1033 ToNamedConcept,
1034 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1035 Importer.getToContext(), ToTAInfo)
1036 : nullptr);
1037 return ConceptRef;
1038}
1039
1040template <>
1041Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1042 ValueDecl *Var = nullptr;
1043 if (From.capturesVariable()) {
1044 if (auto VarOrErr = import(From.getCapturedVar()))
1045 Var = *VarOrErr;
1046 else
1047 return VarOrErr.takeError();
1048 }
1049
1050 auto LocationOrErr = import(From.getLocation());
1051 if (!LocationOrErr)
1052 return LocationOrErr.takeError();
1053
1054 SourceLocation EllipsisLoc;
1055 if (From.isPackExpansion())
1056 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1057 return std::move(Err);
1058
1059 return LambdaCapture(
1060 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1061 EllipsisLoc);
1062}
1063
1064template <typename T>
1066 if (Found->getLinkageInternal() != From->getLinkageInternal())
1067 return false;
1068
1069 if (From->hasExternalFormalLinkage())
1070 return Found->hasExternalFormalLinkage();
1071 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1072 return false;
1073 if (From->isInAnonymousNamespace())
1074 return Found->isInAnonymousNamespace();
1075 else
1076 return !Found->isInAnonymousNamespace() &&
1077 !Found->hasExternalFormalLinkage();
1078}
1079
1080template <>
1082 TypedefNameDecl *From) {
1083 if (Found->getLinkageInternal() != From->getLinkageInternal())
1084 return false;
1085
1086 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1087 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1088 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1089}
1090
1091} // namespace clang
1092
1093//----------------------------------------------------------------------------
1094// Import Types
1095//----------------------------------------------------------------------------
1096
1097using namespace clang;
1098
1100 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1101 << T->getTypeClassName();
1102 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1103}
1104
1105ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1106 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1107 if (!UnderlyingTypeOrErr)
1108 return UnderlyingTypeOrErr.takeError();
1109
1110 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1111}
1112
1113ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1114 switch (T->getKind()) {
1115#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1116 case BuiltinType::Id: \
1117 return Importer.getToContext().SingletonId;
1118#include "clang/Basic/OpenCLImageTypes.def"
1119#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1120 case BuiltinType::Id: \
1121 return Importer.getToContext().Id##Ty;
1122#include "clang/Basic/OpenCLExtensionTypes.def"
1123#define SVE_TYPE(Name, Id, SingletonId) \
1124 case BuiltinType::Id: \
1125 return Importer.getToContext().SingletonId;
1126#include "clang/Basic/AArch64SVEACLETypes.def"
1127#define PPC_VECTOR_TYPE(Name, Id, Size) \
1128 case BuiltinType::Id: \
1129 return Importer.getToContext().Id##Ty;
1130#include "clang/Basic/PPCTypes.def"
1131#define RVV_TYPE(Name, Id, SingletonId) \
1132 case BuiltinType::Id: \
1133 return Importer.getToContext().SingletonId;
1134#include "clang/Basic/RISCVVTypes.def"
1135#define WASM_TYPE(Name, Id, SingletonId) \
1136 case BuiltinType::Id: \
1137 return Importer.getToContext().SingletonId;
1138#include "clang/Basic/WebAssemblyReferenceTypes.def"
1139#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1140 case BuiltinType::Id: \
1141 return Importer.getToContext().SingletonId;
1142#include "clang/Basic/AMDGPUTypes.def"
1143#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1144 case BuiltinType::Id: \
1145 return Importer.getToContext().SingletonId;
1146#include "clang/Basic/HLSLIntangibleTypes.def"
1147#define SHARED_SINGLETON_TYPE(Expansion)
1148#define BUILTIN_TYPE(Id, SingletonId) \
1149 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1150#include "clang/AST/BuiltinTypes.def"
1151
1152 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1153 // context supports C++.
1154
1155 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1156 // context supports ObjC.
1157
1158 case BuiltinType::Char_U:
1159 // The context we're importing from has an unsigned 'char'. If we're
1160 // importing into a context with a signed 'char', translate to
1161 // 'unsigned char' instead.
1162 if (Importer.getToContext().getLangOpts().CharIsSigned)
1163 return Importer.getToContext().UnsignedCharTy;
1164
1165 return Importer.getToContext().CharTy;
1166
1167 case BuiltinType::Char_S:
1168 // The context we're importing from has an unsigned 'char'. If we're
1169 // importing into a context with a signed 'char', translate to
1170 // 'unsigned char' instead.
1171 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1172 return Importer.getToContext().SignedCharTy;
1173
1174 return Importer.getToContext().CharTy;
1175
1176 case BuiltinType::WChar_S:
1177 case BuiltinType::WChar_U:
1178 // FIXME: If not in C++, shall we translate to the C equivalent of
1179 // wchar_t?
1180 return Importer.getToContext().WCharTy;
1181 }
1182
1183 llvm_unreachable("Invalid BuiltinType Kind!");
1184}
1185
1186ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1187 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1188 if (!ToOriginalTypeOrErr)
1189 return ToOriginalTypeOrErr.takeError();
1190
1191 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1192}
1193
1194ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1195 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1196 if (!ToElementTypeOrErr)
1197 return ToElementTypeOrErr.takeError();
1198
1199 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1200}
1201
1202ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1203 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1204 if (!ToPointeeTypeOrErr)
1205 return ToPointeeTypeOrErr.takeError();
1206
1207 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1208}
1209
1210ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1211 // FIXME: Check for blocks support in "to" context.
1212 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1213 if (!ToPointeeTypeOrErr)
1214 return ToPointeeTypeOrErr.takeError();
1215
1216 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1217}
1218
1220ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1221 // FIXME: Check for C++ support in "to" context.
1222 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1223 if (!ToPointeeTypeOrErr)
1224 return ToPointeeTypeOrErr.takeError();
1225
1226 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1227}
1228
1230ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1231 // FIXME: Check for C++0x support in "to" context.
1232 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1233 if (!ToPointeeTypeOrErr)
1234 return ToPointeeTypeOrErr.takeError();
1235
1236 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1237}
1238
1240ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1241 // FIXME: Check for C++ support in "to" context.
1242 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1243 if (!ToPointeeTypeOrErr)
1244 return ToPointeeTypeOrErr.takeError();
1245
1246 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1247 if (!ClassTypeOrErr)
1248 return ClassTypeOrErr.takeError();
1249
1250 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1251 *ClassTypeOrErr);
1252}
1253
1255ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1256 Error Err = Error::success();
1257 auto ToElementType = importChecked(Err, T->getElementType());
1258 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1259 if (Err)
1260 return std::move(Err);
1261
1262 return Importer.getToContext().getConstantArrayType(
1263 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1264 T->getIndexTypeCVRQualifiers());
1265}
1266
1268ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1269 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1270 if (!ToArrayTypeOrErr)
1271 return ToArrayTypeOrErr.takeError();
1272
1273 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1274}
1275
1277ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1278 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1279 if (!ToElementTypeOrErr)
1280 return ToElementTypeOrErr.takeError();
1281
1282 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1283 T->getSizeModifier(),
1284 T->getIndexTypeCVRQualifiers());
1285}
1286
1288ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1289 Error Err = Error::success();
1290 QualType ToElementType = importChecked(Err, T->getElementType());
1291 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1292 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1293 if (Err)
1294 return std::move(Err);
1295 return Importer.getToContext().getVariableArrayType(
1296 ToElementType, ToSizeExpr, T->getSizeModifier(),
1297 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1298}
1299
1300ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1301 const DependentSizedArrayType *T) {
1302 Error Err = Error::success();
1303 QualType ToElementType = importChecked(Err, T->getElementType());
1304 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1305 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1306 if (Err)
1307 return std::move(Err);
1308 // SizeExpr may be null if size is not specified directly.
1309 // For example, 'int a[]'.
1310
1311 return Importer.getToContext().getDependentSizedArrayType(
1312 ToElementType, ToSizeExpr, T->getSizeModifier(),
1313 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1314}
1315
1316ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1318 Error Err = Error::success();
1319 QualType ToElementType = importChecked(Err, T->getElementType());
1320 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1321 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1322 if (Err)
1323 return std::move(Err);
1325 ToElementType, ToSizeExpr, ToAttrLoc);
1326}
1327
1328ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1329 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1330 if (!ToElementTypeOrErr)
1331 return ToElementTypeOrErr.takeError();
1332
1333 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1334 T->getNumElements(),
1335 T->getVectorKind());
1336}
1337
1338ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1339 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1340 if (!ToElementTypeOrErr)
1341 return ToElementTypeOrErr.takeError();
1342
1343 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1344 T->getNumElements());
1345}
1346
1348ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1349 // FIXME: What happens if we're importing a function without a prototype
1350 // into C++? Should we make it variadic?
1351 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1352 if (!ToReturnTypeOrErr)
1353 return ToReturnTypeOrErr.takeError();
1354
1355 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1356 T->getExtInfo());
1357}
1358
1360ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1361 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1362 if (!ToReturnTypeOrErr)
1363 return ToReturnTypeOrErr.takeError();
1364
1365 // Import argument types
1366 SmallVector<QualType, 4> ArgTypes;
1367 for (const auto &A : T->param_types()) {
1368 ExpectedType TyOrErr = import(A);
1369 if (!TyOrErr)
1370 return TyOrErr.takeError();
1371 ArgTypes.push_back(*TyOrErr);
1372 }
1373
1374 // Import exception types
1375 SmallVector<QualType, 4> ExceptionTypes;
1376 for (const auto &E : T->exceptions()) {
1377 ExpectedType TyOrErr = import(E);
1378 if (!TyOrErr)
1379 return TyOrErr.takeError();
1380 ExceptionTypes.push_back(*TyOrErr);
1381 }
1382
1384 Error Err = Error::success();
1386 ToEPI.ExtInfo = FromEPI.ExtInfo;
1387 ToEPI.Variadic = FromEPI.Variadic;
1388 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1389 ToEPI.TypeQuals = FromEPI.TypeQuals;
1390 ToEPI.RefQualifier = FromEPI.RefQualifier;
1391 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1398 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1399
1400 if (Err)
1401 return std::move(Err);
1402
1403 return Importer.getToContext().getFunctionType(
1404 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1405}
1406
1407ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1408 const UnresolvedUsingType *T) {
1409 Error Err = Error::success();
1410 auto ToD = importChecked(Err, T->getDecl());
1411 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1412 if (Err)
1413 return std::move(Err);
1414
1415 return Importer.getToContext().getTypeDeclType(
1416 ToD, cast_or_null<TypeDecl>(ToPrevD));
1417}
1418
1419ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1420 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1421 if (!ToInnerTypeOrErr)
1422 return ToInnerTypeOrErr.takeError();
1423
1424 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1425}
1426
1428ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1429
1430 ExpectedType Pattern = import(T->getPattern());
1431 if (!Pattern)
1432 return Pattern.takeError();
1433 ExpectedExpr Index = import(T->getIndexExpr());
1434 if (!Index)
1435 return Index.takeError();
1436 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1437}
1438
1439ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1440 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1441 if (!ToDeclOrErr)
1442 return ToDeclOrErr.takeError();
1443
1444 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1445 if (ToDecl->getTypeForDecl())
1446 return QualType(ToDecl->getTypeForDecl(), 0);
1447
1448 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1449 if (!ToUnderlyingTypeOrErr)
1450 return ToUnderlyingTypeOrErr.takeError();
1451
1452 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1453}
1454
1455ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1456 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1457 if (!ToExprOrErr)
1458 return ToExprOrErr.takeError();
1459 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1460}
1461
1462ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1463 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1464 if (!ToUnderlyingTypeOrErr)
1465 return ToUnderlyingTypeOrErr.takeError();
1466 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1467 T->getKind());
1468}
1469
1470ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1471 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1472 if (!FoundOrErr)
1473 return FoundOrErr.takeError();
1474 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1475 if (!UnderlyingOrErr)
1476 return UnderlyingOrErr.takeError();
1477
1478 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1479}
1480
1481ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1482 // FIXME: Make sure that the "to" context supports C++0x!
1483 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1484 if (!ToExprOrErr)
1485 return ToExprOrErr.takeError();
1486
1487 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1488 if (!ToUnderlyingTypeOrErr)
1489 return ToUnderlyingTypeOrErr.takeError();
1490
1491 return Importer.getToContext().getDecltypeType(
1492 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1493}
1494
1496ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1497 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1498 if (!ToBaseTypeOrErr)
1499 return ToBaseTypeOrErr.takeError();
1500
1501 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1502 if (!ToUnderlyingTypeOrErr)
1503 return ToUnderlyingTypeOrErr.takeError();
1504
1505 return Importer.getToContext().getUnaryTransformType(
1506 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1507}
1508
1509ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1510 // FIXME: Make sure that the "to" context supports C++11!
1511 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1512 if (!ToDeducedTypeOrErr)
1513 return ToDeducedTypeOrErr.takeError();
1514
1515 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1516 if (!ToTypeConstraintConcept)
1517 return ToTypeConstraintConcept.takeError();
1518
1519 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1520 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1521 ToTemplateArgs))
1522 return std::move(Err);
1523
1524 return Importer.getToContext().getAutoType(
1525 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1526 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1527 ToTemplateArgs);
1528}
1529
1530ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1532 // FIXME: Make sure that the "to" context supports C++17!
1533 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1534 if (!ToTemplateNameOrErr)
1535 return ToTemplateNameOrErr.takeError();
1536 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1537 if (!ToDeducedTypeOrErr)
1538 return ToDeducedTypeOrErr.takeError();
1539
1541 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1542}
1543
1544ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1545 const InjectedClassNameType *T) {
1546 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1547 if (!ToDeclOrErr)
1548 return ToDeclOrErr.takeError();
1549
1550 // The InjectedClassNameType is created in VisitRecordDecl when the
1551 // T->getDecl() is imported. Here we can return the existing type.
1552 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1553 assert(isa_and_nonnull<InjectedClassNameType>(Ty));
1554 return QualType(Ty, 0);
1555}
1556
1557ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1558 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1559 if (!ToDeclOrErr)
1560 return ToDeclOrErr.takeError();
1561
1562 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1563}
1564
1565ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1566 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1567 if (!ToDeclOrErr)
1568 return ToDeclOrErr.takeError();
1569
1570 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1571}
1572
1573ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1574 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1575 if (!ToModifiedTypeOrErr)
1576 return ToModifiedTypeOrErr.takeError();
1577 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1578 if (!ToEquivalentTypeOrErr)
1579 return ToEquivalentTypeOrErr.takeError();
1580
1581 return Importer.getToContext().getAttributedType(
1582 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1583 T->getAttr());
1584}
1585
1587ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1588 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1589 if (!ToWrappedTypeOrErr)
1590 return ToWrappedTypeOrErr.takeError();
1591
1592 Error Err = Error::success();
1593 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1594
1596 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1597 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1598 if (!ToDeclOrErr)
1599 return ToDeclOrErr.takeError();
1600 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1601 }
1602
1603 return Importer.getToContext().getCountAttributedType(
1604 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1605 ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1606}
1607
1608ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1609 const TemplateTypeParmType *T) {
1610 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1611 if (!ToDeclOrErr)
1612 return ToDeclOrErr.takeError();
1613
1614 return Importer.getToContext().getTemplateTypeParmType(
1615 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1616}
1617
1618ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1620 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1621 if (!ReplacedOrErr)
1622 return ReplacedOrErr.takeError();
1623
1624 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1625 if (!ToReplacementTypeOrErr)
1626 return ToReplacementTypeOrErr.takeError();
1627
1629 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1630 T->getSubstitutionFlag());
1631}
1632
1633ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1635 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1636 if (!ReplacedOrErr)
1637 return ReplacedOrErr.takeError();
1638
1639 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1640 if (!ToArgumentPack)
1641 return ToArgumentPack.takeError();
1642
1644 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1645}
1646
1647ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1649 auto ToTemplateOrErr = import(T->getTemplateName());
1650 if (!ToTemplateOrErr)
1651 return ToTemplateOrErr.takeError();
1652
1653 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1654 if (Error Err =
1655 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1656 return std::move(Err);
1657
1658 QualType ToCanonType;
1659 if (!T->isCanonicalUnqualified()) {
1660 QualType FromCanonType
1661 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1662 if (ExpectedType TyOrErr = import(FromCanonType))
1663 ToCanonType = *TyOrErr;
1664 else
1665 return TyOrErr.takeError();
1666 }
1667 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1668 ToTemplateArgs,
1669 ToCanonType);
1670}
1671
1672ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1673 // Note: the qualifier in an ElaboratedType is optional.
1674 auto ToQualifierOrErr = import(T->getQualifier());
1675 if (!ToQualifierOrErr)
1676 return ToQualifierOrErr.takeError();
1677
1678 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1679 if (!ToNamedTypeOrErr)
1680 return ToNamedTypeOrErr.takeError();
1681
1682 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1683 if (!ToOwnedTagDeclOrErr)
1684 return ToOwnedTagDeclOrErr.takeError();
1685
1686 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1687 *ToQualifierOrErr,
1688 *ToNamedTypeOrErr,
1689 *ToOwnedTagDeclOrErr);
1690}
1691
1693ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1694 ExpectedType ToPatternOrErr = import(T->getPattern());
1695 if (!ToPatternOrErr)
1696 return ToPatternOrErr.takeError();
1697
1698 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1699 T->getNumExpansions(),
1700 /*ExpactPack=*/false);
1701}
1702
1703ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1705 auto ToQualifierOrErr = import(T->getQualifier());
1706 if (!ToQualifierOrErr)
1707 return ToQualifierOrErr.takeError();
1708
1709 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1710
1712 ToPack.reserve(T->template_arguments().size());
1713 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1714 return std::move(Err);
1715
1717 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1718}
1719
1721ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1722 auto ToQualifierOrErr = import(T->getQualifier());
1723 if (!ToQualifierOrErr)
1724 return ToQualifierOrErr.takeError();
1725
1726 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1727
1728 QualType Canon;
1729 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1730 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1731 Canon = (*TyOrErr).getCanonicalType();
1732 else
1733 return TyOrErr.takeError();
1734 }
1735
1736 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1737 *ToQualifierOrErr,
1738 Name, Canon);
1739}
1740
1742ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1743 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1744 if (!ToDeclOrErr)
1745 return ToDeclOrErr.takeError();
1746
1747 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1748}
1749
1750ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1751 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1752 if (!ToBaseTypeOrErr)
1753 return ToBaseTypeOrErr.takeError();
1754
1755 SmallVector<QualType, 4> TypeArgs;
1756 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1757 if (ExpectedType TyOrErr = import(TypeArg))
1758 TypeArgs.push_back(*TyOrErr);
1759 else
1760 return TyOrErr.takeError();
1761 }
1762
1764 for (auto *P : T->quals()) {
1765 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1766 Protocols.push_back(*ProtocolOrErr);
1767 else
1768 return ProtocolOrErr.takeError();
1769
1770 }
1771
1772 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1773 Protocols,
1774 T->isKindOfTypeAsWritten());
1775}
1776
1778ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1779 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1780 if (!ToPointeeTypeOrErr)
1781 return ToPointeeTypeOrErr.takeError();
1782
1783 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1784}
1785
1787ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1788 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1789 if (!ToUnderlyingTypeOrErr)
1790 return ToUnderlyingTypeOrErr.takeError();
1791
1792 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1793 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1794 ToIdentifier);
1795}
1796
1797ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1798 Error Err = Error::success();
1799 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1800 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1801 if (Err)
1802 return std::move(Err);
1803
1804 return Importer.getToContext().getAdjustedType(ToOriginalType,
1805 ToAdjustedType);
1806}
1807
1808ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1809 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1810 T->getNumBits());
1811}
1812
1813ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1815 Error Err = Error::success();
1816 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1817 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1818 if (Err)
1819 return std::move(Err);
1820
1821 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1822 ToWrappedType);
1823}
1824
1825ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
1827 Error Err = Error::success();
1828 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
1829 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1830 QualType ToContainedType = importChecked(Err, T->getContainedType());
1831 if (Err)
1832 return std::move(Err);
1833
1834 return Importer.getToContext().getHLSLAttributedResourceType(
1835 ToWrappedType, ToContainedType, ToAttrs);
1836}
1837
1838ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1840 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1841 if (!ToElementTypeOrErr)
1842 return ToElementTypeOrErr.takeError();
1843
1844 return Importer.getToContext().getConstantMatrixType(
1845 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1846}
1847
1848ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1850 Error Err = Error::success();
1851 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1852 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1853 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1854 if (Err)
1855 return std::move(Err);
1856
1857 return Importer.getToContext().getDependentAddressSpaceType(
1858 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1859}
1860
1861ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1863 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1864 if (!ToNumBitsExprOrErr)
1865 return ToNumBitsExprOrErr.takeError();
1866 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1867 *ToNumBitsExprOrErr);
1868}
1869
1870ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1872 Error Err = Error::success();
1873 QualType ToElementType = importChecked(Err, T->getElementType());
1874 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1875 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1876 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1877 if (Err)
1878 return std::move(Err);
1879
1880 return Importer.getToContext().getDependentSizedMatrixType(
1881 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1882}
1883
1884ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1886 Error Err = Error::success();
1887 QualType ToElementType = importChecked(Err, T->getElementType());
1888 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1889 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1890 if (Err)
1891 return std::move(Err);
1892
1893 return Importer.getToContext().getDependentVectorType(
1894 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1895}
1896
1897ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1898 const clang::ObjCTypeParamType *T) {
1899 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1900 if (!ToDeclOrErr)
1901 return ToDeclOrErr.takeError();
1902
1904 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1905 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1906 if (!ToProtocolOrErr)
1907 return ToProtocolOrErr.takeError();
1908 ToProtocols.push_back(*ToProtocolOrErr);
1909 }
1910
1911 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1912 ToProtocols);
1913}
1914
1915ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1916 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1917 if (!ToElementTypeOrErr)
1918 return ToElementTypeOrErr.takeError();
1919
1920 ASTContext &ToCtx = Importer.getToContext();
1921 if (T->isReadOnly())
1922 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1923 else
1924 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1925}
1926
1927//----------------------------------------------------------------------------
1928// Import Declarations
1929//----------------------------------------------------------------------------
1931 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1933 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1934 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1935 // FIXME: We could support these constructs by importing a different type of
1936 // this parameter and by importing the original type of the parameter only
1937 // after the FunctionDecl is created. See
1938 // VisitFunctionDecl::UsedDifferentProtoType.
1939 DeclContext *OrigDC = D->getDeclContext();
1940 FunctionDecl *FunDecl;
1941 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1942 FunDecl->hasBody()) {
1943 auto getLeafPointeeType = [](const Type *T) {
1944 while (T->isPointerType() || T->isArrayType()) {
1946 }
1947 return T;
1948 };
1949 for (const ParmVarDecl *P : FunDecl->parameters()) {
1950 const Type *LeafT =
1951 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1952 auto *RT = dyn_cast<RecordType>(LeafT);
1953 if (RT && RT->getDecl() == D) {
1954 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1955 << D->getDeclKindName();
1956 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1957 }
1958 }
1959 }
1960
1961 // Import the context of this declaration.
1962 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1963 return Err;
1964
1965 // Import the name of this declaration.
1966 if (Error Err = importInto(Name, D->getDeclName()))
1967 return Err;
1968
1969 // Import the location of this declaration.
1970 if (Error Err = importInto(Loc, D->getLocation()))
1971 return Err;
1972
1973 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1974 if (ToD)
1975 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1976 return Err;
1977
1978 return Error::success();
1979}
1980
1982 NamedDecl *&ToD, SourceLocation &Loc) {
1983
1984 // Import the name of this declaration.
1985 if (Error Err = importInto(Name, D->getDeclName()))
1986 return Err;
1987
1988 // Import the location of this declaration.
1989 if (Error Err = importInto(Loc, D->getLocation()))
1990 return Err;
1991
1992 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1993 if (ToD)
1994 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1995 return Err;
1996
1997 return Error::success();
1998}
1999
2001 if (!FromD)
2002 return Error::success();
2003
2004 if (!ToD)
2005 if (Error Err = importInto(ToD, FromD))
2006 return Err;
2007
2008 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2009 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2010 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2011 !ToRecord->getDefinition()) {
2012 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2013 return Err;
2014 }
2015 }
2016 return Error::success();
2017 }
2018
2019 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2020 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2021 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2022 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2023 return Err;
2024 }
2025 }
2026 return Error::success();
2027 }
2028
2029 return Error::success();
2030}
2031
2032Error
2034 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2035 // NOTE: To.Name and To.Loc are already imported.
2036 // We only have to import To.LocInfo.
2037 switch (To.getName().getNameKind()) {
2044 return Error::success();
2045
2047 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2048 To.setCXXOperatorNameRange(*ToRangeOrErr);
2049 else
2050 return ToRangeOrErr.takeError();
2051 return Error::success();
2052 }
2054 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2055 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2056 else
2057 return LocOrErr.takeError();
2058 return Error::success();
2059 }
2063 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2064 To.setNamedTypeInfo(*ToTInfoOrErr);
2065 else
2066 return ToTInfoOrErr.takeError();
2067 return Error::success();
2068 }
2069 }
2070 llvm_unreachable("Unknown name kind.");
2071}
2072
2073Error
2075 if (Importer.isMinimalImport() && !ForceImport) {
2076 auto ToDCOrErr = Importer.ImportContext(FromDC);
2077 return ToDCOrErr.takeError();
2078 }
2079
2080 // We use strict error handling in case of records and enums, but not
2081 // with e.g. namespaces.
2082 //
2083 // FIXME Clients of the ASTImporter should be able to choose an
2084 // appropriate error handling strategy for their needs. For instance,
2085 // they may not want to mark an entire namespace as erroneous merely
2086 // because there is an ODR error with two typedefs. As another example,
2087 // the client may allow EnumConstantDecls with same names but with
2088 // different values in two distinct translation units.
2089 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2090
2091 auto MightNeedReordering = [](const Decl *D) {
2092 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2093 };
2094
2095 // Import everything that might need reordering first.
2096 Error ChildErrors = Error::success();
2097 for (auto *From : FromDC->decls()) {
2098 if (!MightNeedReordering(From))
2099 continue;
2100
2101 ExpectedDecl ImportedOrErr = import(From);
2102
2103 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2104 // want to make sure that we are also completing each FieldDecl. There
2105 // are currently cases where this does not happen and this is correctness
2106 // fix since operations such as code generation will expect this to be so.
2107 if (!ImportedOrErr) {
2108 HandleChildErrors.handleChildImportResult(ChildErrors,
2109 ImportedOrErr.takeError());
2110 continue;
2111 }
2112 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2113 Decl *ImportedDecl = *ImportedOrErr;
2114 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2115 if (FieldFrom && FieldTo) {
2116 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2117 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2118 }
2119 }
2120
2121 // We reorder declarations in RecordDecls because they may have another order
2122 // in the "to" context than they have in the "from" context. This may happen
2123 // e.g when we import a class like this:
2124 // struct declToImport {
2125 // int a = c + b;
2126 // int b = 1;
2127 // int c = 2;
2128 // };
2129 // During the import of `a` we import first the dependencies in sequence,
2130 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2131 // first removing the already imported members and then adding them in the
2132 // order as they appear in the "from" context.
2133 //
2134 // Keeping field order is vital because it determines structure layout.
2135 //
2136 // Here and below, we cannot call field_begin() method and its callers on
2137 // ToDC if it has an external storage. Calling field_begin() will
2138 // automatically load all the fields by calling
2139 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2140 // call ASTImporter::Import(). This is because the ExternalASTSource
2141 // interface in LLDB is implemented by the means of the ASTImporter. However,
2142 // calling an import at this point would result in an uncontrolled import, we
2143 // must avoid that.
2144
2145 auto ToDCOrErr = Importer.ImportContext(FromDC);
2146 if (!ToDCOrErr) {
2147 consumeError(std::move(ChildErrors));
2148 return ToDCOrErr.takeError();
2149 }
2150
2151 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2152 DeclContext *ToDC = *ToDCOrErr;
2153 // Remove all declarations, which may be in wrong order in the
2154 // lexical DeclContext and then add them in the proper order.
2155 for (auto *D : FromRD->decls()) {
2156 if (!MightNeedReordering(D))
2157 continue;
2158
2159 assert(D && "DC contains a null decl");
2160 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2161 // Remove only the decls which we successfully imported.
2162 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2163 // Remove the decl from its wrong place in the linked list.
2164 ToDC->removeDecl(ToD);
2165 // Add the decl to the end of the linked list.
2166 // This time it will be at the proper place because the enclosing for
2167 // loop iterates in the original (good) order of the decls.
2168 ToDC->addDeclInternal(ToD);
2169 }
2170 }
2171 }
2172
2173 // Import everything else.
2174 for (auto *From : FromDC->decls()) {
2175 if (MightNeedReordering(From))
2176 continue;
2177
2178 ExpectedDecl ImportedOrErr = import(From);
2179 if (!ImportedOrErr)
2180 HandleChildErrors.handleChildImportResult(ChildErrors,
2181 ImportedOrErr.takeError());
2182 }
2183
2184 return ChildErrors;
2185}
2186
2188 const FieldDecl *To) {
2189 RecordDecl *FromRecordDecl = nullptr;
2190 RecordDecl *ToRecordDecl = nullptr;
2191 // If we have a field that is an ArrayType we need to check if the array
2192 // element is a RecordDecl and if so we need to import the definition.
2193 QualType FromType = From->getType();
2194 QualType ToType = To->getType();
2195 if (FromType->isArrayType()) {
2196 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2197 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2198 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2199 }
2200
2201 if (!FromRecordDecl || !ToRecordDecl) {
2202 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2203 const RecordType *RecordTo = ToType->getAs<RecordType>();
2204
2205 if (RecordFrom && RecordTo) {
2206 FromRecordDecl = RecordFrom->getDecl();
2207 ToRecordDecl = RecordTo->getDecl();
2208 }
2209 }
2210
2211 if (FromRecordDecl && ToRecordDecl) {
2212 if (FromRecordDecl->isCompleteDefinition() &&
2213 !ToRecordDecl->isCompleteDefinition())
2214 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2215 }
2216
2217 return Error::success();
2218}
2219
2221 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2222 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2223 if (!ToDCOrErr)
2224 return ToDCOrErr.takeError();
2225 ToDC = *ToDCOrErr;
2226
2227 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2228 auto ToLexicalDCOrErr = Importer.ImportContext(
2229 FromD->getLexicalDeclContext());
2230 if (!ToLexicalDCOrErr)
2231 return ToLexicalDCOrErr.takeError();
2232 ToLexicalDC = *ToLexicalDCOrErr;
2233 } else
2234 ToLexicalDC = ToDC;
2235
2236 return Error::success();
2237}
2238
2240 const CXXRecordDecl *From, CXXRecordDecl *To) {
2241 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2242 "Import implicit methods to or from non-definition");
2243
2244 for (CXXMethodDecl *FromM : From->methods())
2245 if (FromM->isImplicit()) {
2246 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2247 if (!ToMOrErr)
2248 return ToMOrErr.takeError();
2249 }
2250
2251 return Error::success();
2252}
2253
2255 ASTImporter &Importer) {
2256 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2257 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2258 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2259 else
2260 return ToTypedefOrErr.takeError();
2261 }
2262 return Error::success();
2263}
2264
2266 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2267 auto DefinitionCompleter = [To]() {
2268 // There are cases in LLDB when we first import a class without its
2269 // members. The class will have DefinitionData, but no members. Then,
2270 // importDefinition is called from LLDB, which tries to get the members, so
2271 // when we get here, the class already has the DefinitionData set, so we
2272 // must unset the CompleteDefinition here to be able to complete again the
2273 // definition.
2274 To->setCompleteDefinition(false);
2275 To->completeDefinition();
2276 };
2277
2278 if (To->getDefinition() || To->isBeingDefined()) {
2279 if (Kind == IDK_Everything ||
2280 // In case of lambdas, the class already has a definition ptr set, but
2281 // the contained decls are not imported yet. Also, isBeingDefined was
2282 // set in CXXRecordDecl::CreateLambda. We must import the contained
2283 // decls here and finish the definition.
2284 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2285 if (To->isLambda()) {
2286 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2288 ToCaptures.reserve(FromCXXRD->capture_size());
2289 for (const auto &FromCapture : FromCXXRD->captures()) {
2290 if (auto ToCaptureOrErr = import(FromCapture))
2291 ToCaptures.push_back(*ToCaptureOrErr);
2292 else
2293 return ToCaptureOrErr.takeError();
2294 }
2295 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2296 ToCaptures);
2297 }
2298
2299 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2300 // Finish the definition of the lambda, set isBeingDefined to false.
2301 if (To->isLambda())
2302 DefinitionCompleter();
2303 return Result;
2304 }
2305
2306 return Error::success();
2307 }
2308
2309 To->startDefinition();
2310 // Set the definition to complete even if it is really not complete during
2311 // import. Some AST constructs (expressions) require the record layout
2312 // to be calculated (see 'clang::computeDependence') at the time they are
2313 // constructed. Import of such AST node is possible during import of the
2314 // same record, there is no way to have a completely defined record (all
2315 // fields imported) at that time without multiple AST import passes.
2316 if (!Importer.isMinimalImport())
2317 To->setCompleteDefinition(true);
2318 // Complete the definition even if error is returned.
2319 // The RecordDecl may be already part of the AST so it is better to
2320 // have it in complete state even if something is wrong with it.
2321 auto DefinitionCompleterScopeExit =
2322 llvm::make_scope_exit(DefinitionCompleter);
2323
2324 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2325 return Err;
2326
2327 // Add base classes.
2328 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2329 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2330 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2331
2332 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2333 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2334
2335 #define FIELD(Name, Width, Merge) \
2336 ToData.Name = FromData.Name;
2337 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2338
2339 // Copy over the data stored in RecordDeclBits
2340 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2341
2343 for (const auto &Base1 : FromCXX->bases()) {
2344 ExpectedType TyOrErr = import(Base1.getType());
2345 if (!TyOrErr)
2346 return TyOrErr.takeError();
2347
2348 SourceLocation EllipsisLoc;
2349 if (Base1.isPackExpansion()) {
2350 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2351 EllipsisLoc = *LocOrErr;
2352 else
2353 return LocOrErr.takeError();
2354 }
2355
2356 // Ensure that we have a definition for the base.
2357 if (Error Err =
2358 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2359 return Err;
2360
2361 auto RangeOrErr = import(Base1.getSourceRange());
2362 if (!RangeOrErr)
2363 return RangeOrErr.takeError();
2364
2365 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2366 if (!TSIOrErr)
2367 return TSIOrErr.takeError();
2368
2369 Bases.push_back(
2370 new (Importer.getToContext()) CXXBaseSpecifier(
2371 *RangeOrErr,
2372 Base1.isVirtual(),
2373 Base1.isBaseOfClass(),
2374 Base1.getAccessSpecifierAsWritten(),
2375 *TSIOrErr,
2376 EllipsisLoc));
2377 }
2378 if (!Bases.empty())
2379 ToCXX->setBases(Bases.data(), Bases.size());
2380 }
2381
2383 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2384 return Err;
2385 }
2386
2387 return Error::success();
2388}
2389
2391 if (To->getAnyInitializer())
2392 return Error::success();
2393
2394 Expr *FromInit = From->getInit();
2395 if (!FromInit)
2396 return Error::success();
2397
2398 ExpectedExpr ToInitOrErr = import(FromInit);
2399 if (!ToInitOrErr)
2400 return ToInitOrErr.takeError();
2401
2402 To->setInit(*ToInitOrErr);
2403 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2404 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2405 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2406 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2407 // FIXME: Also import the initializer value.
2408 }
2409
2410 // FIXME: Other bits to merge?
2411 return Error::success();
2412}
2413
2416 if (To->getDefinition() || To->isBeingDefined()) {
2417 if (Kind == IDK_Everything)
2418 return ImportDeclContext(From, /*ForceImport=*/true);
2419 return Error::success();
2420 }
2421
2422 To->startDefinition();
2423
2424 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2425 return Err;
2426
2427 ExpectedType ToTypeOrErr =
2428 import(Importer.getFromContext().getTypeDeclType(From));
2429 if (!ToTypeOrErr)
2430 return ToTypeOrErr.takeError();
2431
2432 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2433 if (!ToPromotionTypeOrErr)
2434 return ToPromotionTypeOrErr.takeError();
2435
2437 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2438 return Err;
2439
2440 // FIXME: we might need to merge the number of positive or negative bits
2441 // if the enumerator lists don't match.
2442 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2443 From->getNumPositiveBits(),
2444 From->getNumNegativeBits());
2445 return Error::success();
2446}
2447
2451 for (const auto &Arg : FromArgs) {
2452 if (auto ToOrErr = import(Arg))
2453 ToArgs.push_back(*ToOrErr);
2454 else
2455 return ToOrErr.takeError();
2456 }
2457
2458 return Error::success();
2459}
2460
2461// FIXME: Do not forget to remove this and use only 'import'.
2464 return import(From);
2465}
2466
2467template <typename InContainerTy>
2469 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2470 for (const auto &FromLoc : Container) {
2471 if (auto ToLocOrErr = import(FromLoc))
2472 ToTAInfo.addArgument(*ToLocOrErr);
2473 else
2474 return ToLocOrErr.takeError();
2475 }
2476 return Error::success();
2477}
2478
2483}
2484
2485bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2486 bool IgnoreTemplateParmDepth) {
2487 // Eliminate a potential failure point where we attempt to re-import
2488 // something we're trying to import while completing ToRecord.
2489 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2490 if (ToOrigin) {
2491 To = ToOrigin;
2492 }
2493
2495 Importer.getFromContext(), Importer.getToContext(),
2497 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2498 IgnoreTemplateParmDepth);
2499 return Ctx.IsEquivalent(From, To);
2500}
2501
2503 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2504 << D->getDeclKindName();
2505 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2506}
2507
2509 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2510 << D->getDeclKindName();
2511 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2512}
2513
2515 // Import the context of this declaration.
2516 DeclContext *DC, *LexicalDC;
2517 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2518 return std::move(Err);
2519
2520 // Import the location of this declaration.
2521 ExpectedSLoc LocOrErr = import(D->getLocation());
2522 if (!LocOrErr)
2523 return LocOrErr.takeError();
2524
2525 EmptyDecl *ToD;
2526 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2527 return ToD;
2528
2529 ToD->setLexicalDeclContext(LexicalDC);
2530 LexicalDC->addDeclInternal(ToD);
2531 return ToD;
2532}
2533
2535 TranslationUnitDecl *ToD =
2537
2538 Importer.MapImported(D, ToD);
2539
2540 return ToD;
2541}
2542
2544 DeclContext *DC, *LexicalDC;
2545 DeclarationName Name;
2547 NamedDecl *ToND;
2548 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2549 return std::move(Err);
2550 if (ToND)
2551 return ToND;
2552
2553 BindingDecl *ToD;
2554 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2555 Name.getAsIdentifierInfo()))
2556 return ToD;
2557
2558 Error Err = Error::success();
2559 QualType ToType = importChecked(Err, D->getType());
2560 Expr *ToBinding = importChecked(Err, D->getBinding());
2561 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2562 if (Err)
2563 return std::move(Err);
2564
2565 ToD->setBinding(ToType, ToBinding);
2566 ToD->setDecomposedDecl(ToDecomposedDecl);
2567 addDeclToContexts(D, ToD);
2568
2569 return ToD;
2570}
2571
2573 ExpectedSLoc LocOrErr = import(D->getLocation());
2574 if (!LocOrErr)
2575 return LocOrErr.takeError();
2576 auto ColonLocOrErr = import(D->getColonLoc());
2577 if (!ColonLocOrErr)
2578 return ColonLocOrErr.takeError();
2579
2580 // Import the context of this declaration.
2581 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2582 if (!DCOrErr)
2583 return DCOrErr.takeError();
2584 DeclContext *DC = *DCOrErr;
2585
2586 AccessSpecDecl *ToD;
2587 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2588 DC, *LocOrErr, *ColonLocOrErr))
2589 return ToD;
2590
2591 // Lexical DeclContext and Semantic DeclContext
2592 // is always the same for the accessSpec.
2593 ToD->setLexicalDeclContext(DC);
2594 DC->addDeclInternal(ToD);
2595
2596 return ToD;
2597}
2598
2600 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2601 if (!DCOrErr)
2602 return DCOrErr.takeError();
2603 DeclContext *DC = *DCOrErr;
2604 DeclContext *LexicalDC = DC;
2605
2606 Error Err = Error::success();
2607 auto ToLocation = importChecked(Err, D->getLocation());
2608 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2609 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2610 auto ToMessage = importChecked(Err, D->getMessage());
2611 if (Err)
2612 return std::move(Err);
2613
2614 StaticAssertDecl *ToD;
2615 if (GetImportedOrCreateDecl(
2616 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2617 ToRParenLoc, D->isFailed()))
2618 return ToD;
2619
2620 ToD->setLexicalDeclContext(LexicalDC);
2621 LexicalDC->addDeclInternal(ToD);
2622 return ToD;
2623}
2624
2626 // Import the major distinguishing characteristics of this namespace.
2627 DeclContext *DC, *LexicalDC;
2628 DeclarationName Name;
2630 NamedDecl *ToD;
2631 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2632 return std::move(Err);
2633 if (ToD)
2634 return ToD;
2635
2636 NamespaceDecl *MergeWithNamespace = nullptr;
2637 if (!Name) {
2638 // This is an anonymous namespace. Adopt an existing anonymous
2639 // namespace if we can.
2640 // FIXME: Not testable.
2641 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2642 MergeWithNamespace = TU->getAnonymousNamespace();
2643 else
2644 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2645 } else {
2646 SmallVector<NamedDecl *, 4> ConflictingDecls;
2647 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2648 for (auto *FoundDecl : FoundDecls) {
2650 continue;
2651
2652 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2653 MergeWithNamespace = FoundNS;
2654 ConflictingDecls.clear();
2655 break;
2656 }
2657
2658 ConflictingDecls.push_back(FoundDecl);
2659 }
2660
2661 if (!ConflictingDecls.empty()) {
2662 ExpectedName NameOrErr = Importer.HandleNameConflict(
2663 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2664 ConflictingDecls.size());
2665 if (NameOrErr)
2666 Name = NameOrErr.get();
2667 else
2668 return NameOrErr.takeError();
2669 }
2670 }
2671
2672 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2673 if (!BeginLocOrErr)
2674 return BeginLocOrErr.takeError();
2675 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2676 if (!RBraceLocOrErr)
2677 return RBraceLocOrErr.takeError();
2678
2679 // Create the "to" namespace, if needed.
2680 NamespaceDecl *ToNamespace = MergeWithNamespace;
2681 if (!ToNamespace) {
2682 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2683 D->isInline(), *BeginLocOrErr, Loc,
2684 Name.getAsIdentifierInfo(),
2685 /*PrevDecl=*/nullptr, D->isNested()))
2686 return ToNamespace;
2687 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2688 ToNamespace->setLexicalDeclContext(LexicalDC);
2689 LexicalDC->addDeclInternal(ToNamespace);
2690
2691 // If this is an anonymous namespace, register it as the anonymous
2692 // namespace within its context.
2693 if (!Name) {
2694 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2695 TU->setAnonymousNamespace(ToNamespace);
2696 else
2697 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2698 }
2699 }
2700 Importer.MapImported(D, ToNamespace);
2701
2702 if (Error Err = ImportDeclContext(D))
2703 return std::move(Err);
2704
2705 return ToNamespace;
2706}
2707
2709 // Import the major distinguishing characteristics of this namespace.
2710 DeclContext *DC, *LexicalDC;
2711 DeclarationName Name;
2713 NamedDecl *LookupD;
2714 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2715 return std::move(Err);
2716 if (LookupD)
2717 return LookupD;
2718
2719 // NOTE: No conflict resolution is done for namespace aliases now.
2720
2721 Error Err = Error::success();
2722 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2723 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2724 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2725 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2726 auto ToNamespace = importChecked(Err, D->getNamespace());
2727 if (Err)
2728 return std::move(Err);
2729
2730 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2731
2732 NamespaceAliasDecl *ToD;
2733 if (GetImportedOrCreateDecl(
2734 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2735 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2736 return ToD;
2737
2738 ToD->setLexicalDeclContext(LexicalDC);
2739 LexicalDC->addDeclInternal(ToD);
2740
2741 return ToD;
2742}
2743
2746 // Import the major distinguishing characteristics of this typedef.
2747 DeclarationName Name;
2749 NamedDecl *ToD;
2750 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2751 // is created.
2752 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2753 return std::move(Err);
2754 if (ToD)
2755 return ToD;
2756
2757 DeclContext *DC = cast_or_null<DeclContext>(
2758 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2759 DeclContext *LexicalDC =
2760 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2761 cast<Decl>(D->getLexicalDeclContext())));
2762
2763 // If this typedef is not in block scope, determine whether we've
2764 // seen a typedef with the same name (that we can merge with) or any
2765 // other entity by that name (which name lookup could conflict with).
2766 // Note: Repeated typedefs are not valid in C99:
2767 // 'typedef int T; typedef int T;' is invalid
2768 // We do not care about this now.
2769 if (DC && !DC->isFunctionOrMethod()) {
2770 SmallVector<NamedDecl *, 4> ConflictingDecls;
2771 unsigned IDNS = Decl::IDNS_Ordinary;
2772 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2773 for (auto *FoundDecl : FoundDecls) {
2774 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2775 continue;
2776 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2777 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2778 continue;
2779
2780 QualType FromUT = D->getUnderlyingType();
2781 QualType FoundUT = FoundTypedef->getUnderlyingType();
2782 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2783 // If the underlying declarations are unnamed records these can be
2784 // imported as different types. We should create a distinct typedef
2785 // node in this case.
2786 // If we found an existing underlying type with a record in a
2787 // different context (than the imported), this is already reason for
2788 // having distinct typedef nodes for these.
2789 // Again this can create situation like
2790 // 'typedef int T; typedef int T;' but this is hard to avoid without
2791 // a rename strategy at import.
2792 if (!FromUT.isNull() && !FoundUT.isNull()) {
2793 RecordDecl *FromR = FromUT->getAsRecordDecl();
2794 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2795 if (FromR && FoundR &&
2796 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2797 continue;
2798 }
2799 // If the "From" context has a complete underlying type but we
2800 // already have a complete underlying type then return with that.
2801 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2802 return Importer.MapImported(D, FoundTypedef);
2803 // FIXME Handle redecl chain. When you do that make consistent changes
2804 // in ASTImporterLookupTable too.
2805 } else {
2806 ConflictingDecls.push_back(FoundDecl);
2807 }
2808 }
2809 }
2810
2811 if (!ConflictingDecls.empty()) {
2812 ExpectedName NameOrErr = Importer.HandleNameConflict(
2813 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2814 if (NameOrErr)
2815 Name = NameOrErr.get();
2816 else
2817 return NameOrErr.takeError();
2818 }
2819 }
2820
2821 Error Err = Error::success();
2822 auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType());
2823 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2824 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2825 if (Err)
2826 return std::move(Err);
2827
2828 // Create the new typedef node.
2829 // FIXME: ToUnderlyingType is not used.
2830 (void)ToUnderlyingType;
2831 TypedefNameDecl *ToTypedef;
2832 if (IsAlias) {
2833 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2834 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2835 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2836 return ToTypedef;
2837 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2838 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2839 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2840 return ToTypedef;
2841
2842 // Import the DeclContext and set it to the Typedef.
2843 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2844 return std::move(Err);
2845 ToTypedef->setDeclContext(DC);
2846 ToTypedef->setLexicalDeclContext(LexicalDC);
2847 // Add to the lookupTable because we could not do that in MapImported.
2848 Importer.AddToLookupTable(ToTypedef);
2849
2850 ToTypedef->setAccess(D->getAccess());
2851
2852 // Templated declarations should not appear in DeclContext.
2853 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2854 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2855 LexicalDC->addDeclInternal(ToTypedef);
2856
2857 return ToTypedef;
2858}
2859
2861 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2862}
2863
2865 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2866}
2867
2870 // Import the major distinguishing characteristics of this typedef.
2871 DeclContext *DC, *LexicalDC;
2872 DeclarationName Name;
2874 NamedDecl *FoundD;
2875 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2876 return std::move(Err);
2877 if (FoundD)
2878 return FoundD;
2879
2880 // If this typedef is not in block scope, determine whether we've
2881 // seen a typedef with the same name (that we can merge with) or any
2882 // other entity by that name (which name lookup could conflict with).
2883 if (!DC->isFunctionOrMethod()) {
2884 SmallVector<NamedDecl *, 4> ConflictingDecls;
2885 unsigned IDNS = Decl::IDNS_Ordinary;
2886 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2887 for (auto *FoundDecl : FoundDecls) {
2888 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2889 continue;
2890 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2891 if (IsStructuralMatch(D, FoundAlias))
2892 return Importer.MapImported(D, FoundAlias);
2893 ConflictingDecls.push_back(FoundDecl);
2894 }
2895 }
2896
2897 if (!ConflictingDecls.empty()) {
2898 ExpectedName NameOrErr = Importer.HandleNameConflict(
2899 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2900 if (NameOrErr)
2901 Name = NameOrErr.get();
2902 else
2903 return NameOrErr.takeError();
2904 }
2905 }
2906
2907 Error Err = Error::success();
2908 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2909 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2910 if (Err)
2911 return std::move(Err);
2912
2913 TypeAliasTemplateDecl *ToAlias;
2914 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2915 Name, ToTemplateParameters, ToTemplatedDecl))
2916 return ToAlias;
2917
2918 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2919
2920 ToAlias->setAccess(D->getAccess());
2921 ToAlias->setLexicalDeclContext(LexicalDC);
2922 LexicalDC->addDeclInternal(ToAlias);
2923 if (DC != Importer.getToContext().getTranslationUnitDecl())
2924 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2925 return ToAlias;
2926}
2927
2929 // Import the major distinguishing characteristics of this label.
2930 DeclContext *DC, *LexicalDC;
2931 DeclarationName Name;
2933 NamedDecl *ToD;
2934 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2935 return std::move(Err);
2936 if (ToD)
2937 return ToD;
2938
2939 assert(LexicalDC->isFunctionOrMethod());
2940
2941 LabelDecl *ToLabel;
2942 if (D->isGnuLocal()) {
2943 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2944 if (!BeginLocOrErr)
2945 return BeginLocOrErr.takeError();
2946 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2947 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2948 return ToLabel;
2949
2950 } else {
2951 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2952 Name.getAsIdentifierInfo()))
2953 return ToLabel;
2954
2955 }
2956
2957 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2958 if (!ToStmtOrErr)
2959 return ToStmtOrErr.takeError();
2960
2961 ToLabel->setStmt(*ToStmtOrErr);
2962 ToLabel->setLexicalDeclContext(LexicalDC);
2963 LexicalDC->addDeclInternal(ToLabel);
2964 return ToLabel;
2965}
2966
2968 // Import the major distinguishing characteristics of this enum.
2969 DeclContext *DC, *LexicalDC;
2970 DeclarationName Name;
2972 NamedDecl *ToD;
2973 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2974 return std::move(Err);
2975 if (ToD)
2976 return ToD;
2977
2978 // Figure out what enum name we're looking for.
2979 unsigned IDNS = Decl::IDNS_Tag;
2980 DeclarationName SearchName = Name;
2981 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2982 if (Error Err = importInto(
2983 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2984 return std::move(Err);
2985 IDNS = Decl::IDNS_Ordinary;
2986 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2987 IDNS |= Decl::IDNS_Ordinary;
2988
2989 // We may already have an enum of the same name; try to find and match it.
2990 EnumDecl *PrevDecl = nullptr;
2991 if (!DC->isFunctionOrMethod()) {
2992 SmallVector<NamedDecl *, 4> ConflictingDecls;
2993 auto FoundDecls =
2994 Importer.findDeclsInToCtx(DC, SearchName);
2995 for (auto *FoundDecl : FoundDecls) {
2996 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2997 continue;
2998
2999 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3000 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3001 FoundDecl = Tag->getDecl();
3002 }
3003
3004 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3005 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3006 continue;
3007 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3008 EnumDecl *FoundDef = FoundEnum->getDefinition();
3009 if (D->isThisDeclarationADefinition() && FoundDef)
3010 return Importer.MapImported(D, FoundDef);
3011 PrevDecl = FoundEnum->getMostRecentDecl();
3012 break;
3013 }
3014 ConflictingDecls.push_back(FoundDecl);
3015 }
3016 }
3017
3018 // In case of unnamed enums, we try to find an existing similar one, if none
3019 // was found, perform the import always.
3020 // Structural in-equivalence is not detected in this way here, but it may
3021 // be found when the parent decl is imported (if the enum is part of a
3022 // class). To make this totally exact a more difficult solution is needed.
3023 if (SearchName && !ConflictingDecls.empty()) {
3024 ExpectedName NameOrErr = Importer.HandleNameConflict(
3025 SearchName, DC, IDNS, ConflictingDecls.data(),
3026 ConflictingDecls.size());
3027 if (NameOrErr)
3028 Name = NameOrErr.get();
3029 else
3030 return NameOrErr.takeError();
3031 }
3032 }
3033
3034 Error Err = Error::success();
3035 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3036 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3037 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3038 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3039 if (Err)
3040 return std::move(Err);
3041
3042 // Create the enum declaration.
3043 EnumDecl *D2;
3044 if (GetImportedOrCreateDecl(
3045 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3046 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3047 D->isScopedUsingClassTag(), D->isFixed()))
3048 return D2;
3049
3050 D2->setQualifierInfo(ToQualifierLoc);
3051 D2->setIntegerType(ToIntegerType);
3052 D2->setBraceRange(ToBraceRange);
3053 D2->setAccess(D->getAccess());
3054 D2->setLexicalDeclContext(LexicalDC);
3055 addDeclToContexts(D, D2);
3056
3057 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3058 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3059 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3060 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3061 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3062 else
3063 return ToInstOrErr.takeError();
3064 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3066 else
3067 return POIOrErr.takeError();
3068 }
3069
3070 // Import the definition
3071 if (D->isCompleteDefinition())
3072 if (Error Err = ImportDefinition(D, D2))
3073 return std::move(Err);
3074
3075 return D2;
3076}
3077
3079 bool IsFriendTemplate = false;
3080 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3081 IsFriendTemplate =
3082 DCXX->getDescribedClassTemplate() &&
3083 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3085 }
3086
3087 // Import the major distinguishing characteristics of this record.
3088 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3089 DeclarationName Name;
3091 NamedDecl *ToD = nullptr;
3092 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3093 return std::move(Err);
3094 if (ToD)
3095 return ToD;
3096
3097 // Figure out what structure name we're looking for.
3098 unsigned IDNS = Decl::IDNS_Tag;
3099 DeclarationName SearchName = Name;
3100 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3101 if (Error Err = importInto(
3102 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3103 return std::move(Err);
3104 IDNS = Decl::IDNS_Ordinary;
3105 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3107
3108 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3109 : DC->isDependentContext();
3110 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3111
3112 // We may already have a record of the same name; try to find and match it.
3113 RecordDecl *PrevDecl = nullptr;
3114 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3115 SmallVector<NamedDecl *, 4> ConflictingDecls;
3116 auto FoundDecls =
3117 Importer.findDeclsInToCtx(DC, SearchName);
3118 if (!FoundDecls.empty()) {
3119 // We're going to have to compare D against potentially conflicting Decls,
3120 // so complete it.
3121 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
3123 }
3124
3125 for (auto *FoundDecl : FoundDecls) {
3126 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3127 continue;
3128
3129 Decl *Found = FoundDecl;
3130 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3131 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3132 Found = Tag->getDecl();
3133 }
3134
3135 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3136 // Do not emit false positive diagnostic in case of unnamed
3137 // struct/union and in case of anonymous structs. Would be false
3138 // because there may be several anonymous/unnamed structs in a class.
3139 // E.g. these are both valid:
3140 // struct A { // unnamed structs
3141 // struct { struct A *next; } entry0;
3142 // struct { struct A *next; } entry1;
3143 // };
3144 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3145 if (!SearchName)
3146 if (!IsStructuralMatch(D, FoundRecord, false))
3147 continue;
3148
3149 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3150 continue;
3151
3152 if (IsStructuralMatch(D, FoundRecord)) {
3153 RecordDecl *FoundDef = FoundRecord->getDefinition();
3154 if (D->isThisDeclarationADefinition() && FoundDef) {
3155 // FIXME: Structural equivalence check should check for same
3156 // user-defined methods.
3157 Importer.MapImported(D, FoundDef);
3158 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3159 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3160 assert(FoundCXX && "Record type mismatch");
3161
3162 if (!Importer.isMinimalImport())
3163 // FoundDef may not have every implicit method that D has
3164 // because implicit methods are created only if they are used.
3165 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3166 return std::move(Err);
3167 }
3168 // FIXME: We can return FoundDef here.
3169 }
3170 PrevDecl = FoundRecord->getMostRecentDecl();
3171 break;
3172 }
3173 ConflictingDecls.push_back(FoundDecl);
3174 } // kind is RecordDecl
3175 } // for
3176
3177 if (!ConflictingDecls.empty() && SearchName) {
3178 ExpectedName NameOrErr = Importer.HandleNameConflict(
3179 SearchName, DC, IDNS, ConflictingDecls.data(),
3180 ConflictingDecls.size());
3181 if (NameOrErr)
3182 Name = NameOrErr.get();
3183 else
3184 return NameOrErr.takeError();
3185 }
3186 }
3187
3188 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3189 if (!BeginLocOrErr)
3190 return BeginLocOrErr.takeError();
3191
3192 // Create the record declaration.
3193 RecordDecl *D2 = nullptr;
3194 CXXRecordDecl *D2CXX = nullptr;
3195 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3196 if (DCXX->isLambda()) {
3197 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3198 if (!TInfoOrErr)
3199 return TInfoOrErr.takeError();
3200 if (GetImportedOrCreateSpecialDecl(
3201 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3202 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3203 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3204 return D2CXX;
3205 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3206 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3207 if (!CDeclOrErr)
3208 return CDeclOrErr.takeError();
3209 Numbering.ContextDecl = *CDeclOrErr;
3210 D2CXX->setLambdaNumbering(Numbering);
3211 } else if (DCXX->isInjectedClassName()) {
3212 // We have to be careful to do a similar dance to the one in
3213 // Sema::ActOnStartCXXMemberDeclarations
3214 const bool DelayTypeCreation = true;
3215 if (GetImportedOrCreateDecl(
3216 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3217 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3218 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3219 return D2CXX;
3220 Importer.getToContext().getTypeDeclType(
3221 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3222 } else {
3223 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3224 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3225 Name.getAsIdentifierInfo(),
3226 cast_or_null<CXXRecordDecl>(PrevDecl)))
3227 return D2CXX;
3228 }
3229
3230 D2 = D2CXX;
3231 D2->setAccess(D->getAccess());
3232 D2->setLexicalDeclContext(LexicalDC);
3233 addDeclToContexts(D, D2);
3234
3235 if (ClassTemplateDecl *FromDescribed =
3236 DCXX->getDescribedClassTemplate()) {
3237 ClassTemplateDecl *ToDescribed;
3238 if (Error Err = importInto(ToDescribed, FromDescribed))
3239 return std::move(Err);
3240 D2CXX->setDescribedClassTemplate(ToDescribed);
3241 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3242 // In a record describing a template the type should be an
3243 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3244 // previously set type to the correct value here (ToDescribed is not
3245 // available at record create).
3246 CXXRecordDecl *Injected = nullptr;
3247 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3248 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3249 if (Record && Record->isInjectedClassName()) {
3250 Injected = Record;
3251 break;
3252 }
3253 }
3254 // Create an injected type for the whole redecl chain.
3255 // The chain may contain an already existing injected type at the start,
3256 // if yes this should be reused. We must ensure that only one type
3257 // object exists for the injected type (including the injected record
3258 // declaration), ASTContext does not check it.
3259 SmallVector<Decl *, 2> Redecls =
3261 const Type *FrontTy =
3262 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3263 QualType InjSpec;
3264 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3265 InjSpec = InjTy->getInjectedSpecializationType();
3266 else
3267 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3268 for (auto *R : Redecls) {
3269 auto *RI = cast<CXXRecordDecl>(R);
3270 if (R != Redecls.front() ||
3271 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3272 RI->setTypeForDecl(nullptr);
3273 // This function tries to get the injected type from getTypeForDecl,
3274 // then from the previous declaration if possible. If not, it creates
3275 // a new type.
3276 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3277 }
3278 // Set the new type for the injected decl too.
3279 if (Injected) {
3280 Injected->setTypeForDecl(nullptr);
3281 // This function will copy the injected type from D2CXX into Injected.
3282 // The injected decl does not have a previous decl to copy from.
3283 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3284 }
3285 }
3286 } else if (MemberSpecializationInfo *MemberInfo =
3287 DCXX->getMemberSpecializationInfo()) {
3289 MemberInfo->getTemplateSpecializationKind();
3291
3292 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3293 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3294 else
3295 return ToInstOrErr.takeError();
3296
3297 if (ExpectedSLoc POIOrErr =
3298 import(MemberInfo->getPointOfInstantiation()))
3300 *POIOrErr);
3301 else
3302 return POIOrErr.takeError();
3303 }
3304
3305 } else {
3306 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3307 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3308 Name.getAsIdentifierInfo(), PrevDecl))
3309 return D2;
3310 D2->setLexicalDeclContext(LexicalDC);
3311 addDeclToContexts(D, D2);
3312 }
3313
3314 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3315 D2->setBraceRange(*BraceRangeOrErr);
3316 else
3317 return BraceRangeOrErr.takeError();
3318 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3319 D2->setQualifierInfo(*QualifierLocOrErr);
3320 else
3321 return QualifierLocOrErr.takeError();
3322
3323 if (D->isAnonymousStructOrUnion())
3324 D2->setAnonymousStructOrUnion(true);
3325
3326 if (D->isCompleteDefinition())
3327 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3328 return std::move(Err);
3329
3330 return D2;
3331}
3332
3334 // Import the major distinguishing characteristics of this enumerator.
3335 DeclContext *DC, *LexicalDC;
3336 DeclarationName Name;
3338 NamedDecl *ToD;
3339 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3340 return std::move(Err);
3341 if (ToD)
3342 return ToD;
3343
3344 // Determine whether there are any other declarations with the same name and
3345 // in the same context.
3346 if (!LexicalDC->isFunctionOrMethod()) {
3347 SmallVector<NamedDecl *, 4> ConflictingDecls;
3348 unsigned IDNS = Decl::IDNS_Ordinary;
3349 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3350 for (auto *FoundDecl : FoundDecls) {
3351 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3352 continue;
3353
3354 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3355 if (IsStructuralMatch(D, FoundEnumConstant))
3356 return Importer.MapImported(D, FoundEnumConstant);
3357 ConflictingDecls.push_back(FoundDecl);
3358 }
3359 }
3360
3361 if (!ConflictingDecls.empty()) {
3362 ExpectedName NameOrErr = Importer.HandleNameConflict(
3363 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3364 if (NameOrErr)
3365 Name = NameOrErr.get();
3366 else
3367 return NameOrErr.takeError();
3368 }
3369 }
3370
3371 ExpectedType TypeOrErr = import(D->getType());
3372 if (!TypeOrErr)
3373 return TypeOrErr.takeError();
3374
3375 ExpectedExpr InitOrErr = import(D->getInitExpr());
3376 if (!InitOrErr)
3377 return InitOrErr.takeError();
3378
3379 EnumConstantDecl *ToEnumerator;
3380 if (GetImportedOrCreateDecl(
3381 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3382 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3383 return ToEnumerator;
3384
3385 ToEnumerator->setAccess(D->getAccess());
3386 ToEnumerator->setLexicalDeclContext(LexicalDC);
3387 LexicalDC->addDeclInternal(ToEnumerator);
3388 return ToEnumerator;
3389}
3390
3391template <typename DeclTy>
3393 DeclTy *ToD) {
3394 unsigned int Num = FromD->getNumTemplateParameterLists();
3395 if (Num == 0)
3396 return Error::success();
3398 for (unsigned int I = 0; I < Num; ++I)
3399 if (Expected<TemplateParameterList *> ToTPListOrErr =
3400 import(FromD->getTemplateParameterList(I)))
3401 ToTPLists[I] = *ToTPListOrErr;
3402 else
3403 return ToTPListOrErr.takeError();
3404 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3405 return Error::success();
3406}
3407
3409 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3410 switch (FromFD->getTemplatedKind()) {
3413 return Error::success();
3414
3416 if (Expected<FunctionDecl *> InstFDOrErr =
3417 import(FromFD->getInstantiatedFromDecl()))
3418 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3419 return Error::success();
3422
3423 if (Expected<FunctionDecl *> InstFDOrErr =
3424 import(FromFD->getInstantiatedFromMemberFunction()))
3425 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3426 else
3427 return InstFDOrErr.takeError();
3428
3429 if (ExpectedSLoc POIOrErr = import(
3432 else
3433 return POIOrErr.takeError();
3434
3435 return Error::success();
3436 }
3437
3439 auto FunctionAndArgsOrErr =
3441 if (!FunctionAndArgsOrErr)
3442 return FunctionAndArgsOrErr.takeError();
3443
3445 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3446
3447 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3448 TemplateArgumentListInfo ToTAInfo;
3449 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3450 if (FromTAArgsAsWritten)
3451 if (Error Err = ImportTemplateArgumentListInfo(
3452 *FromTAArgsAsWritten, ToTAInfo))
3453 return Err;
3454
3455 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3456 if (!POIOrErr)
3457 return POIOrErr.takeError();
3458
3459 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3460 return Err;
3461
3462 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3463 ToFD->setFunctionTemplateSpecialization(
3464 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3465 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3466 return Error::success();
3467 }
3468
3470 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3471 UnresolvedSet<8> Candidates;
3472 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3473 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3474 Candidates.addDecl(*ToFTDOrErr);
3475 else
3476 return ToFTDOrErr.takeError();
3477 }
3478
3479 // Import TemplateArgumentListInfo.
3480 TemplateArgumentListInfo ToTAInfo;
3481 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3482 if (FromTAArgsAsWritten)
3483 if (Error Err =
3484 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3485 return Err;
3486
3488 Importer.getToContext(), Candidates,
3489 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3490 return Error::success();
3491 }
3492 }
3493 llvm_unreachable("All cases should be covered!");
3494}
3495
3498 auto FunctionAndArgsOrErr =
3500 if (!FunctionAndArgsOrErr)
3501 return FunctionAndArgsOrErr.takeError();
3502
3503 FunctionTemplateDecl *Template;
3504 TemplateArgsTy ToTemplArgs;
3505 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3506 void *InsertPos = nullptr;
3507 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3508 return FoundSpec;
3509}
3510
3512 FunctionDecl *ToFD) {
3513 if (Stmt *FromBody = FromFD->getBody()) {
3514 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3515 ToFD->setBody(*ToBodyOrErr);
3516 else
3517 return ToBodyOrErr.takeError();
3518 }
3519 return Error::success();
3520}
3521
3522// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3523// which is equal to the given DC, or D is equal to DC.
3524static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3525 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3526 if (!DCi)
3527 DCi = D->getDeclContext();
3528 assert(DCi && "Declaration should have a context");
3529 while (DCi != D->getTranslationUnitDecl()) {
3530 if (DCi == DC)
3531 return true;
3532 DCi = DCi->getParent();
3533 }
3534 return false;
3535}
3536
3537// Check if there is a declaration that has 'DC' as parent context and is
3538// referenced from statement 'S' or one of its children. The search is done in
3539// BFS order through children of 'S'.
3540static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3541 SmallVector<const Stmt *> ToProcess;
3542 ToProcess.push_back(S);
3543 while (!ToProcess.empty()) {
3544 const Stmt *CurrentS = ToProcess.pop_back_val();
3545 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3546 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3547 if (const Decl *D = DeclRef->getDecl())
3548 if (isAncestorDeclContextOf(DC, D))
3549 return true;
3550 } else if (const auto *E =
3551 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3552 if (const Decl *D = E->getAssociatedDecl())
3553 if (isAncestorDeclContextOf(DC, D))
3554 return true;
3555 }
3556 }
3557 return false;
3558}
3559
3560namespace {
3561/// Check if a type has any reference to a declaration that is inside the body
3562/// of a function.
3563/// The \c CheckType(QualType) function should be used to determine
3564/// this property.
3565///
3566/// The type visitor visits one type object only (not recursive).
3567/// To find all referenced declarations we must discover all type objects until
3568/// the canonical type is reached (walk over typedef and similar objects). This
3569/// is done by loop over all "sugar" type objects. For every such type we must
3570/// check all declarations that are referenced from it. For this check the
3571/// visitor is used. In the visit functions all referenced declarations except
3572/// the one that follows in the sugar chain (if any) must be checked. For this
3573/// check the same visitor is re-used (it has no state-dependent data).
3574///
3575/// The visit functions have 3 possible return values:
3576/// - True, found a declaration inside \c ParentDC.
3577/// - False, found declarations only outside \c ParentDC and it is not possible
3578/// to find more declarations (the "sugar" chain does not continue).
3579/// - Empty optional value, found no declarations or only outside \c ParentDC,
3580/// but it is possible to find more declarations in the type "sugar" chain.
3581/// The loop over the "sugar" types can be implemented by using type visit
3582/// functions only (call \c CheckType with the desugared type). With the current
3583/// solution no visit function is needed if the type has only a desugared type
3584/// as data.
3585class IsTypeDeclaredInsideVisitor
3586 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3587public:
3588 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3589 : ParentDC(ParentDC) {}
3590
3591 bool CheckType(QualType T) {
3592 // Check the chain of "sugar" types.
3593 // The "sugar" types are typedef or similar types that have the same
3594 // canonical type.
3595 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3596 return *Res;
3597 QualType DsT =
3598 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3599 while (DsT != T) {
3600 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3601 return *Res;
3602 T = DsT;
3603 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3604 }
3605 return false;
3606 }
3607
3608 std::optional<bool> VisitTagType(const TagType *T) {
3609 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3610 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3611 if (checkTemplateArgument(Arg))
3612 return true;
3613 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3614 }
3615
3616 std::optional<bool> VisitPointerType(const PointerType *T) {
3617 return CheckType(T->getPointeeType());
3618 }
3619
3620 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3621 return CheckType(T->getPointeeTypeAsWritten());
3622 }
3623
3624 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3625 const TypedefNameDecl *TD = T->getDecl();
3626 assert(TD);
3627 return isAncestorDeclContextOf(ParentDC, TD);
3628 }
3629
3630 std::optional<bool> VisitUsingType(const UsingType *T) {
3631 if (T->getFoundDecl() &&
3632 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3633 return true;
3634
3635 return {};
3636 }
3637
3638 std::optional<bool>
3639 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3640 for (const auto &Arg : T->template_arguments())
3641 if (checkTemplateArgument(Arg))
3642 return true;
3643 // This type is a "sugar" to a record type, it can have a desugared type.
3644 return {};
3645 }
3646
3647 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3648 return CheckType(T->getBaseType());
3649 }
3650
3651 std::optional<bool>
3652 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3653 // The "associated declaration" can be the same as ParentDC.
3654 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3655 return true;
3656 return {};
3657 }
3658
3659 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3660 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3661 return true;
3662
3663 return CheckType(T->getElementType());
3664 }
3665
3666 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3667 llvm_unreachable(
3668 "Variable array should not occur in deduced return type of a function");
3669 }
3670
3671 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3672 llvm_unreachable("Incomplete array should not occur in deduced return type "
3673 "of a function");
3674 }
3675
3676 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3677 llvm_unreachable("Dependent array should not occur in deduced return type "
3678 "of a function");
3679 }
3680
3681private:
3682 const DeclContext *const ParentDC;
3683
3684 bool checkTemplateArgument(const TemplateArgument &Arg) {
3685 switch (Arg.getKind()) {
3687 return false;
3689 return CheckType(Arg.getIntegralType());
3691 return CheckType(Arg.getAsType());
3693 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3695 // FIXME: The declaration in this case is not allowed to be in a function?
3696 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3698 // FIXME: The type is not allowed to be in the function?
3699 return CheckType(Arg.getNullPtrType());
3701 return CheckType(Arg.getStructuralValueType());
3703 for (const auto &PackArg : Arg.getPackAsArray())
3704 if (checkTemplateArgument(PackArg))
3705 return true;
3706 return false;
3708 // Templates can not be defined locally in functions.
3709 // A template passed as argument can be not in ParentDC.
3710 return false;
3712 // Templates can not be defined locally in functions.
3713 // A template passed as argument can be not in ParentDC.
3714 return false;
3715 }
3716 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3717 };
3718};
3719} // namespace
3720
3721/// This function checks if the given function has a return type that contains
3722/// a reference (in any way) to a declaration inside the same function.
3724 QualType FromTy = D->getType();
3725 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3726 assert(FromFPT && "Must be called on FunctionProtoType");
3727
3728 auto IsCXX11Lambda = [&]() {
3729 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3730 return false;
3731
3732 if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3733 return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
3734
3735 return false;
3736 };
3737
3738 QualType RetT = FromFPT->getReturnType();
3739 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3740 FunctionDecl *Def = D->getDefinition();
3741 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3742 return Visitor.CheckType(RetT);
3743 }
3744
3745 return false;
3746}
3747
3749ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3750 Expr *ExplicitExpr = ESpec.getExpr();
3751 if (ExplicitExpr)
3752 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3753 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3754}
3755
3757
3759 auto RedeclIt = Redecls.begin();
3760 // Import the first part of the decl chain. I.e. import all previous
3761 // declarations starting from the canonical decl.
3762 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3763 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3764 if (!ToRedeclOrErr)
3765 return ToRedeclOrErr.takeError();
3766 }
3767 assert(*RedeclIt == D);
3768
3769 // Import the major distinguishing characteristics of this function.
3770 DeclContext *DC, *LexicalDC;
3771 DeclarationName Name;
3773 NamedDecl *ToD;
3774 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3775 return std::move(Err);
3776 if (ToD)
3777 return ToD;
3778
3779 FunctionDecl *FoundByLookup = nullptr;
3780 FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate();
3781
3782 // If this is a function template specialization, then try to find the same
3783 // existing specialization in the "to" context. The lookup below will not
3784 // find any specialization, but would find the primary template; thus, we
3785 // have to skip normal lookup in case of specializations.
3786 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3787 if (D->getTemplatedKind() ==
3789 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3790 if (!FoundFunctionOrErr)
3791 return FoundFunctionOrErr.takeError();
3792 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3793 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3794 return Def;
3795 FoundByLookup = FoundFunction;
3796 }
3797 }
3798 // Try to find a function in our own ("to") context with the same name, same
3799 // type, and in the same context as the function we're importing.
3800 else if (!LexicalDC->isFunctionOrMethod()) {
3801 SmallVector<NamedDecl *, 4> ConflictingDecls;
3803 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3804 for (auto *FoundDecl : FoundDecls) {
3805 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3806 continue;
3807
3808 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3809 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3810 continue;
3811
3812 if (IsStructuralMatch(D, FoundFunction)) {
3813 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3814 return Def;
3815 FoundByLookup = FoundFunction;
3816 break;
3817 }
3818 // FIXME: Check for overloading more carefully, e.g., by boosting
3819 // Sema::IsOverload out to the AST library.
3820
3821 // Function overloading is okay in C++.
3822 if (Importer.getToContext().getLangOpts().CPlusPlus)
3823 continue;
3824
3825 // Complain about inconsistent function types.
3826 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3827 << Name << D->getType() << FoundFunction->getType();
3828 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3829 << FoundFunction->getType();
3830 ConflictingDecls.push_back(FoundDecl);
3831 }
3832 }
3833
3834 if (!ConflictingDecls.empty()) {
3835 ExpectedName NameOrErr = Importer.HandleNameConflict(
3836 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3837 if (NameOrErr)
3838 Name = NameOrErr.get();
3839 else
3840 return NameOrErr.takeError();
3841 }
3842 }
3843
3844 // We do not allow more than one in-class declaration of a function. This is
3845 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3846 // assumes there is only one in-class declaration. Building a redecl
3847 // chain would result in more than one in-class declaration for
3848 // overrides (even if they are part of the same redecl chain inside the
3849 // derived class.)
3850 if (FoundByLookup) {
3851 if (isa<CXXMethodDecl>(FoundByLookup)) {
3852 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3853 if (!D->doesThisDeclarationHaveABody()) {
3854 if (FunctionTemplateDecl *DescribedD =
3855 D->getDescribedFunctionTemplate()) {
3856 // Handle a "templated" function together with its described
3857 // template. This avoids need for a similar check at import of the
3858 // described template.
3859 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3860 "Templated function mapped to non-templated?");
3861 Importer.MapImported(DescribedD,
3862 FoundByLookup->getDescribedFunctionTemplate());
3863 }
3864 return Importer.MapImported(D, FoundByLookup);
3865 } else {
3866 // Let's continue and build up the redecl chain in this case.
3867 // FIXME Merge the functions into one decl.
3868 }
3869 }
3870 }
3871 }
3872
3873 DeclarationNameInfo NameInfo(Name, Loc);
3874 // Import additional name location/type info.
3875 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3876 return std::move(Err);
3877
3878 QualType FromTy = D->getType();
3879 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3880 // Set to true if we do not import the type of the function as is. There are
3881 // cases when the original type would result in an infinite recursion during
3882 // the import. To avoid an infinite recursion when importing, we create the
3883 // FunctionDecl with a simplified function type and update it only after the
3884 // relevant AST nodes are already imported.
3885 // The type is related to TypeSourceInfo (it references the type), so we must
3886 // do the same with TypeSourceInfo.
3887 bool UsedDifferentProtoType = false;
3888 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3889 QualType FromReturnTy = FromFPT->getReturnType();
3890 // Functions with auto return type may define a struct inside their body
3891 // and the return type could refer to that struct.
3892 // E.g.: auto foo() { struct X{}; return X(); }
3893 // To avoid an infinite recursion when importing, create the FunctionDecl
3894 // with a simplified return type.
3896 FromReturnTy = Importer.getFromContext().VoidTy;
3897 UsedDifferentProtoType = true;
3898 }
3899 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3900 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3901 // FunctionDecl that we are importing the FunctionProtoType for.
3902 // To avoid an infinite recursion when importing, create the FunctionDecl
3903 // with a simplified function type.
3904 if (FromEPI.ExceptionSpec.SourceDecl ||
3905 FromEPI.ExceptionSpec.SourceTemplate ||
3906 FromEPI.ExceptionSpec.NoexceptExpr) {
3908 FromEPI = DefaultEPI;
3909 UsedDifferentProtoType = true;
3910 }
3911 FromTy = Importer.getFromContext().getFunctionType(
3912 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3913 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3914 FromTy, D->getBeginLoc());
3915 }
3916
3917 Error Err = Error::success();
3918 auto T = importChecked(Err, FromTy);
3919 auto TInfo = importChecked(Err, FromTSI);
3920 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3921 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3922 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3923 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3924 auto TrailingRequiresClause =
3925 importChecked(Err, D->getTrailingRequiresClause());
3926 if (Err)
3927 return std::move(Err);
3928
3929 // Import the function parameters.
3931 for (auto *P : D->parameters()) {
3932 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3933 Parameters.push_back(*ToPOrErr);
3934 else
3935 return ToPOrErr.takeError();
3936 }
3937
3938 // Create the imported function.
3939 FunctionDecl *ToFunction = nullptr;
3940 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3941 ExplicitSpecifier ESpec =
3942 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3943 if (Err)
3944 return std::move(Err);
3945 auto ToInheritedConstructor = InheritedConstructor();
3946 if (FromConstructor->isInheritingConstructor()) {
3947 Expected<InheritedConstructor> ImportedInheritedCtor =
3948 import(FromConstructor->getInheritedConstructor());
3949 if (!ImportedInheritedCtor)
3950 return ImportedInheritedCtor.takeError();
3951 ToInheritedConstructor = *ImportedInheritedCtor;
3952 }
3953 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3954 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3955 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3956 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3957 ToInheritedConstructor, TrailingRequiresClause))
3958 return ToFunction;
3959 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3960
3961 Error Err = Error::success();
3962 auto ToOperatorDelete = importChecked(
3963 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3964 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3965 if (Err)
3966 return std::move(Err);
3967
3968 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3969 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3970 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3971 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3972 TrailingRequiresClause))
3973 return ToFunction;
3974
3975 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3976
3977 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3978 } else if (CXXConversionDecl *FromConversion =
3979 dyn_cast<CXXConversionDecl>(D)) {
3980 ExplicitSpecifier ESpec =
3981 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3982 if (Err)
3983 return std::move(Err);
3984 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3985 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3986 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3987 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3988 SourceLocation(), TrailingRequiresClause))
3989 return ToFunction;
3990 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3991 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3992 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3993 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3994 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3995 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3996 return ToFunction;
3997 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3998 ExplicitSpecifier ESpec =
3999 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
4000 CXXConstructorDecl *Ctor =
4001 importChecked(Err, Guide->getCorrespondingConstructor());
4002 if (Err)
4003 return std::move(Err);
4004 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4005 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4006 NameInfo, T, TInfo, ToEndLoc, Ctor))
4007 return ToFunction;
4008 cast<CXXDeductionGuideDecl>(ToFunction)
4009 ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
4010 } else {
4011 if (GetImportedOrCreateDecl(
4012 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4013 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4014 D->isInlineSpecified(), D->hasWrittenPrototype(),
4015 D->getConstexprKind(), TrailingRequiresClause))
4016 return ToFunction;
4017 }
4018
4019 // Connect the redecl chain.
4020 if (FoundByLookup) {
4021 auto *Recent = const_cast<FunctionDecl *>(
4022 FoundByLookup->getMostRecentDecl());
4023 ToFunction->setPreviousDecl(Recent);
4024 // FIXME Probably we should merge exception specifications. E.g. In the
4025 // "To" context the existing function may have exception specification with
4026 // noexcept-unevaluated, while the newly imported function may have an
4027 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4028 // decl and its redeclarations may be required.
4029 }
4030
4031 StringLiteral *Msg = D->getDeletedMessage();
4032 if (Msg) {
4033 auto Imported = import(Msg);
4034 if (!Imported)
4035 return Imported.takeError();
4036 Msg = *Imported;
4037 }
4038
4039 ToFunction->setQualifierInfo(ToQualifierLoc);
4040 ToFunction->setAccess(D->getAccess());
4041 ToFunction->setLexicalDeclContext(LexicalDC);
4042 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4043 ToFunction->setTrivial(D->isTrivial());
4044 ToFunction->setIsPureVirtual(D->isPureVirtual());
4045 ToFunction->setDefaulted(D->isDefaulted());
4046 ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
4047 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4049 D->FriendConstraintRefersToEnclosingTemplate());
4050 ToFunction->setRangeEnd(ToEndLoc);
4051 ToFunction->setDefaultLoc(ToDefaultLoc);
4052
4053 if (Msg)
4054 ToFunction->setDefaultedOrDeletedInfo(
4056 Importer.getToContext(), {}, Msg));
4057
4058 // Set the parameters.
4059 for (auto *Param : Parameters) {
4060 Param->setOwningFunction(ToFunction);
4061 ToFunction->addDeclInternal(Param);
4062 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4063 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4064 }
4065 ToFunction->setParams(Parameters);
4066
4067 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4068 // params it refers to.
4069 if (TInfo) {
4070 if (auto ProtoLoc =
4071 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4072 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4073 ProtoLoc.setParam(I, Parameters[I]);
4074 }
4075 }
4076
4077 // Import the describing template function, if any.
4078 if (FromFT) {
4079 auto ToFTOrErr = import(FromFT);
4080 if (!ToFTOrErr)
4081 return ToFTOrErr.takeError();
4082 }
4083
4084 // Import Ctor initializers.
4085 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4086 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4087 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4088 // Import first, then allocate memory and copy if there was no error.
4089 if (Error Err = ImportContainerChecked(
4090 FromConstructor->inits(), CtorInitializers))
4091 return std::move(Err);
4092 auto **Memory =
4093 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4094 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4095 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4096 ToCtor->setCtorInitializers(Memory);
4097 ToCtor->setNumCtorInitializers(NumInitializers);
4098 }
4099 }
4100
4101 // If it is a template, import all related things.
4102 if (Error Err = ImportTemplateInformation(D, ToFunction))
4103 return std::move(Err);
4104
4105 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4106 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4107 FromCXXMethod))
4108 return std::move(Err);
4109
4110 if (D->doesThisDeclarationHaveABody()) {
4111 Error Err = ImportFunctionDeclBody(D, ToFunction);
4112
4113 if (Err)
4114 return std::move(Err);
4115 }
4116
4117 // Import and set the original type in case we used another type.
4118 if (UsedDifferentProtoType) {
4119 if (ExpectedType TyOrErr = import(D->getType()))
4120 ToFunction->setType(*TyOrErr);
4121 else
4122 return TyOrErr.takeError();
4123 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4124 ToFunction->setTypeSourceInfo(*TSIOrErr);
4125 else
4126 return TSIOrErr.takeError();
4127 }
4128
4129 // FIXME: Other bits to merge?
4130
4131 addDeclToContexts(D, ToFunction);
4132
4133 // Import the rest of the chain. I.e. import all subsequent declarations.
4134 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4135 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4136 if (!ToRedeclOrErr)
4137 return ToRedeclOrErr.takeError();
4138 }
4139
4140 return ToFunction;
4141}
4142
4144 return VisitFunctionDecl(D);
4145}
4146
4148 return VisitCXXMethodDecl(D);
4149}
4150
4152 return VisitCXXMethodDecl(D);
4153}
4154
4156 return VisitCXXMethodDecl(D);
4157}
4158
4161 return VisitFunctionDecl(D);
4162}
4163
4165 // Import the major distinguishing characteristics of a variable.
4166 DeclContext *DC, *LexicalDC;
4167 DeclarationName Name;
4169 NamedDecl *ToD;
4170 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4171 return std::move(Err);
4172 if (ToD)
4173 return ToD;
4174
4175 // Determine whether we've already imported this field.
4176 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4177 for (auto *FoundDecl : FoundDecls) {
4178 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4179 // For anonymous fields, match up by index.
4180 if (!Name &&
4182 ASTImporter::getFieldIndex(FoundField))
4183 continue;
4184
4185 if (Importer.IsStructurallyEquivalent(D->getType(),
4186 FoundField->getType())) {
4187 Importer.MapImported(D, FoundField);
4188 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4189 // initializer of a FieldDecl might not had been instantiated in the
4190 // "To" context. However, the "From" context might instantiated that,
4191 // thus we have to merge that.
4192 // Note: `hasInClassInitializer()` is not the same as non-null
4193 // `getInClassInitializer()` value.
4194 if (Expr *FromInitializer = D->getInClassInitializer()) {
4195 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4196 // Import of the FromInitializer may result in the setting of
4197 // InClassInitializer. If not, set it here.
4198 assert(FoundField->hasInClassInitializer() &&
4199 "Field should have an in-class initializer if it has an "
4200 "expression for it.");
4201 if (!FoundField->getInClassInitializer())
4202 FoundField->setInClassInitializer(*ToInitializerOrErr);
4203 } else {
4204 return ToInitializerOrErr.takeError();
4205 }
4206 }
4207 return FoundField;
4208 }
4209
4210 // FIXME: Why is this case not handled with calling HandleNameConflict?
4211 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4212 << Name << D->getType() << FoundField->getType();
4213 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4214 << FoundField->getType();
4215
4216 return make_error<ASTImportError>(ASTImportError::NameConflict);
4217 }
4218 }
4219
4220 Error Err = Error::success();
4221 auto ToType = importChecked(Err, D->getType());
4222 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4223 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4224 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4225 if (Err)
4226 return std::move(Err);
4227 const Type *ToCapturedVLAType = nullptr;
4228 if (Error Err = Importer.importInto(
4229 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4230 return std::move(Err);
4231
4232 FieldDecl *ToField;
4233 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4234 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4235 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4236 D->getInClassInitStyle()))
4237 return ToField;
4238
4239 ToField->setAccess(D->getAccess());
4240 ToField->setLexicalDeclContext(LexicalDC);
4241 ToField->setImplicit(D->isImplicit());
4242 if (ToCapturedVLAType)
4243 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4244 LexicalDC->addDeclInternal(ToField);
4245 // Import initializer only after the field was created, it may have recursive
4246 // reference to the field.
4247 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4248 if (Err)
4249 return std::move(Err);
4250 if (ToInitializer) {
4251 auto *AlreadyImported = ToField->getInClassInitializer();
4252 if (AlreadyImported)
4253 assert(ToInitializer == AlreadyImported &&
4254 "Duplicate import of in-class initializer.");
4255 else
4256 ToField->setInClassInitializer(ToInitializer);
4257 }
4258
4259 return ToField;
4260}
4261
4263 // Import the major distinguishing characteristics of a variable.
4264 DeclContext *DC, *LexicalDC;
4265 DeclarationName Name;
4267 NamedDecl *ToD;
4268 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4269 return std::move(Err);
4270 if (ToD)
4271 return ToD;
4272
4273 // Determine whether we've already imported this field.
4274 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4275 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4276 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4277 // For anonymous indirect fields, match up by index.
4278 if (!Name &&
4280 ASTImporter::getFieldIndex(FoundField))
4281 continue;
4282
4283 if (Importer.IsStructurallyEquivalent(D->getType(),
4284 FoundField->getType(),
4285 !Name.isEmpty())) {
4286 Importer.MapImported(D, FoundField);
4287 return FoundField;
4288 }
4289
4290 // If there are more anonymous fields to check, continue.
4291 if (!Name && I < N-1)
4292 continue;
4293
4294 // FIXME: Why is this case not handled with calling HandleNameConflict?
4295 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4296 << Name << D->getType() << FoundField->getType();
4297 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4298 << FoundField->getType();
4299
4300 return make_error<ASTImportError>(ASTImportError::NameConflict);
4301 }
4302 }
4303
4304 // Import the type.
4305 auto TypeOrErr = import(D->getType());
4306 if (!TypeOrErr)
4307 return TypeOrErr.takeError();
4308
4309 auto **NamedChain =
4310 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4311
4312 unsigned i = 0;
4313 for (auto *PI : D->chain())
4314 if (Expected<NamedDecl *> ToD = import(PI))
4315 NamedChain[i++] = *ToD;
4316 else
4317 return ToD.takeError();
4318
4319 llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4320 IndirectFieldDecl *ToIndirectField;
4321 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4322 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4323 // FIXME here we leak `NamedChain` which is allocated before
4324 return ToIndirectField;
4325
4326 ToIndirectField->setAccess(D->getAccess());
4327 ToIndirectField->setLexicalDeclContext(LexicalDC);
4328 LexicalDC->addDeclInternal(ToIndirectField);
4329 return ToIndirectField;
4330}
4331
4332/// Used as return type of getFriendCountAndPosition.
4334 /// Number of similar looking friends.
4335 unsigned int TotalCount;
4336 /// Index of the specific FriendDecl.
4337 unsigned int IndexOfDecl;
4338};
4339
4340static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4341 FriendDecl *FD2) {
4342 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4343 return false;
4344
4345 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4346 return Importer.IsStructurallyEquivalent(
4347 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4348
4349 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4351 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4353 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4354 return Ctx.IsEquivalent(FD1, FD2);
4355}
4356
4358 FriendDecl *FD) {
4359 unsigned int FriendCount = 0;
4360 std::optional<unsigned int> FriendPosition;
4361 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4362
4363 for (FriendDecl *FoundFriend : RD->friends()) {
4364 if (FoundFriend == FD) {
4365 FriendPosition = FriendCount;
4366 ++FriendCount;
4367 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4368 ++FriendCount;
4369 }
4370 }
4371
4372 assert(FriendPosition && "Friend decl not found in own parent.");
4373
4374 return {FriendCount, *FriendPosition};
4375}
4376
4378 // Import the major distinguishing characteristics of a declaration.
4379 DeclContext *DC, *LexicalDC;
4380 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4381 return std::move(Err);
4382
4383 // Determine whether we've already imported this decl.
4384 // FriendDecl is not a NamedDecl so we cannot use lookup.
4385 // We try to maintain order and count of redundant friend declarations.
4386 const auto *RD = cast<CXXRecordDecl>(DC);
4387 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4388 for (FriendDecl *ImportedFriend : RD->friends())
4389 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4390 ImportedEquivalentFriends.push_back(ImportedFriend);
4391
4392 FriendCountAndPosition CountAndPosition =
4393 getFriendCountAndPosition(Importer, D);
4394
4395 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4396 "Class with non-matching friends is imported, ODR check wrong?");
4397 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4398 return Importer.MapImported(
4399 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4400
4401 // Not found. Create it.
4402 // The declarations will be put into order later by ImportDeclContext.
4404 if (NamedDecl *FriendD = D->getFriendDecl()) {
4405 NamedDecl *ToFriendD;
4406 if (Error Err = importInto(ToFriendD, FriendD))
4407 return std::move(Err);
4408
4409 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4410 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4411 ToFriendD->setObjectOfFriendDecl(false);
4412
4413 ToFU = ToFriendD;
4414 } else { // The friend is a type, not a decl.
4415 if (auto TSIOrErr = import(D->getFriendType()))
4416 ToFU = *TSIOrErr;
4417 else
4418 return TSIOrErr.takeError();
4419 }
4420
4421 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4422 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4423 for (unsigned I = 0; I < D->NumTPLists; I++) {
4424 if (auto ListOrErr = import(FromTPLists[I]))
4425 ToTPLists[I] = *ListOrErr;
4426 else
4427 return ListOrErr.takeError();
4428 }
4429
4430 auto LocationOrErr = import(D->getLocation());
4431 if (!LocationOrErr)
4432 return LocationOrErr.takeError();
4433 auto FriendLocOrErr = import(D->getFriendLoc());
4434 if (!FriendLocOrErr)
4435 return FriendLocOrErr.takeError();
4436 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4437 if (!EllipsisLocOrErr)
4438 return EllipsisLocOrErr.takeError();
4439
4440 FriendDecl *FrD;
4441 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4442 *LocationOrErr, ToFU, *FriendLocOrErr,
4443 *EllipsisLocOrErr, ToTPLists))
4444 return FrD;
4445
4446 FrD->setAccess(D->getAccess());
4447 FrD->setLexicalDeclContext(LexicalDC);
4448 LexicalDC->addDeclInternal(FrD);
4449 return FrD;
4450}
4451
4453 // Import the major distinguishing characteristics of an ivar.
4454 DeclContext *DC, *LexicalDC;
4455 DeclarationName Name;
4457 NamedDecl *ToD;
4458 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4459 return std::move(Err);
4460 if (ToD)
4461 return ToD;
4462
4463 // Determine whether we've already imported this ivar
4464 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4465 for (auto *FoundDecl : FoundDecls) {
4466 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4467 if (Importer.IsStructurallyEquivalent(D->getType(),
4468 FoundIvar->getType())) {
4469 Importer.MapImported(D, FoundIvar);
4470 return FoundIvar;
4471 }
4472
4473 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4474 << Name << D->getType() << FoundIvar->getType();
4475 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4476 << FoundIvar->getType();
4477
4478 return make_error<ASTImportError>(ASTImportError::NameConflict);
4479 }
4480 }
4481
4482 Error Err = Error::success();
4483 auto ToType = importChecked(Err, D->getType());
4484 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4485 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4486 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4487 if (Err)
4488 return std::move(Err);
4489
4490 ObjCIvarDecl *ToIvar;
4491 if (GetImportedOrCreateDecl(
4492 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4493 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4494 ToType, ToTypeSourceInfo,
4495 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4496 return ToIvar;
4497
4498 ToIvar->setLexicalDeclContext(LexicalDC);
4499 LexicalDC->addDeclInternal(ToIvar);
4500 return ToIvar;
4501}
4502
4504
4506 auto RedeclIt = Redecls.begin();
4507 // Import the first part of the decl chain. I.e. import all previous
4508 // declarations starting from the canonical decl.
4509 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4510 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4511 if (!RedeclOrErr)
4512 return RedeclOrErr.takeError();
4513 }
4514 assert(*RedeclIt == D);
4515
4516 // Import the major distinguishing characteristics of a variable.
4517 DeclContext *DC, *LexicalDC;
4518 DeclarationName Name;
4520 NamedDecl *ToD;
4521 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4522 return std::move(Err);
4523 if (ToD)
4524 return ToD;
4525
4526 // Try to find a variable in our own ("to") context with the same name and
4527 // in the same context as the variable we're importing.
4528 VarDecl *FoundByLookup = nullptr;
4529 if (D->isFileVarDecl()) {
4530 SmallVector<NamedDecl *, 4> ConflictingDecls;
4531 unsigned IDNS = Decl::IDNS_Ordinary;
4532 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4533 for (auto *FoundDecl : FoundDecls) {
4534 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4535 continue;
4536
4537 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4538 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4539 continue;
4540 if (Importer.IsStructurallyEquivalent(D->getType(),
4541 FoundVar->getType())) {
4542
4543 // The VarDecl in the "From" context has a definition, but in the
4544 // "To" context we already have a definition.
4545 VarDecl *FoundDef = FoundVar->getDefinition();
4546 if (D->isThisDeclarationADefinition() && FoundDef)
4547 // FIXME Check for ODR error if the two definitions have
4548 // different initializers?
4549 return Importer.MapImported(D, FoundDef);
4550
4551 // The VarDecl in the "From" context has an initializer, but in the
4552 // "To" context we already have an initializer.
4553 const VarDecl *FoundDInit = nullptr;
4554 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4555 // FIXME Diagnose ODR error if the two initializers are different?
4556 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4557
4558 FoundByLookup = FoundVar;
4559 break;
4560 }
4561
4562 const ArrayType *FoundArray
4563 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4564 const ArrayType *TArray
4565 = Importer.getToContext().getAsArrayType(D->getType());
4566 if (FoundArray && TArray) {
4567 if (isa<IncompleteArrayType>(FoundArray) &&
4568 isa<ConstantArrayType>(TArray)) {
4569 // Import the type.
4570 if (auto TyOrErr = import(D->getType()))
4571 FoundVar->setType(*TyOrErr);
4572 else
4573 return TyOrErr.takeError();
4574
4575 FoundByLookup = FoundVar;
4576 break;
4577 } else if (isa<IncompleteArrayType>(TArray) &&
4578 isa<ConstantArrayType>(FoundArray)) {
4579 FoundByLookup = FoundVar;
4580 break;
4581 }
4582 }
4583
4584 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4585 << Name << D->getType() << FoundVar->getType();
4586 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4587 << FoundVar->getType();
4588 ConflictingDecls.push_back(FoundDecl);
4589 }
4590 }
4591
4592 if (!ConflictingDecls.empty()) {
4593 ExpectedName NameOrErr = Importer.HandleNameConflict(
4594 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4595 if (NameOrErr)
4596 Name = NameOrErr.get();
4597 else
4598 return NameOrErr.takeError();
4599 }
4600 }
4601
4602 Error Err = Error::success();
4603 auto ToType = importChecked(Err, D->getType());
4604 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4605 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4606 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4607 if (Err)
4608 return std::move(Err);
4609
4610 VarDecl *ToVar;
4611 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4612 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4613 if (Error Err =
4614 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4615 return std::move(Err);
4616 DecompositionDecl *ToDecomp;
4617 if (GetImportedOrCreateDecl(
4618 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4619 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4620 return ToDecomp;
4621 ToVar = ToDecomp;
4622 } else {
4623 // Create the imported variable.
4624 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4625 ToInnerLocStart, Loc,
4626 Name.getAsIdentifierInfo(), ToType,
4627 ToTypeSourceInfo, D->getStorageClass()))
4628 return ToVar;
4629 }
4630
4631 ToVar->setTSCSpec(D->getTSCSpec());
4632 ToVar->setQualifierInfo(ToQualifierLoc);
4633 ToVar->setAccess(D->getAccess());
4634 ToVar->setLexicalDeclContext(LexicalDC);
4635 if (D->isInlineSpecified())
4636 ToVar->setInlineSpecified();
4637 if (D->isInline())
4638 ToVar->setImplicitlyInline();
4639
4640 if (FoundByLookup) {
4641 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4642 ToVar->setPreviousDecl(Recent);
4643 }
4644
4645 // Import the described template, if any.
4646 if (D->getDescribedVarTemplate()) {
4647 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4648 if (!ToVTOrErr)
4649 return ToVTOrErr.takeError();
4650 } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4651 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4652 VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
4653 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4654 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4655 else
4656 return ToInstOrErr.takeError();
4657 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4659 else
4660 return POIOrErr.takeError();
4661 }
4662
4663 if (Error Err = ImportInitializer(D, ToVar))
4664 return std::move(Err);
4665
4666 if (D->isConstexpr())
4667 ToVar->setConstexpr(true);
4668
4669 addDeclToContexts(D, ToVar);
4670
4671 // Import the rest of the chain. I.e. import all subsequent declarations.
4672 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4673 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4674 if (!RedeclOrErr)
4675 return RedeclOrErr.takeError();
4676 }
4677
4678 return ToVar;
4679}
4680
4682 // Parameters are created in the translation unit's context, then moved
4683 // into the function declaration's context afterward.
4685
4686 Error Err = Error::success();
4687 auto ToDeclName = importChecked(Err, D->getDeclName());
4688 auto ToLocation = importChecked(Err, D->getLocation());
4689 auto ToType = importChecked(Err, D->getType());
4690 if (Err)
4691 return std::move(Err);
4692
4693 // Create the imported parameter.
4694 ImplicitParamDecl *ToParm = nullptr;
4695 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4696 ToLocation, ToDeclName.getAsIdentifierInfo(),
4697 ToType, D->getParameterKind()))
4698 return ToParm;
4699 return ToParm;
4700}
4701
4703 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4704
4705 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4706 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4707 else
4708 return LocOrErr.takeError();
4709
4711 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4712
4713 if (FromParam->hasUninstantiatedDefaultArg()) {
4714 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4715 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4716 else
4717 return ToDefArgOrErr.takeError();
4718 } else if (FromParam->hasUnparsedDefaultArg()) {
4719 ToParam->setUnparsedDefaultArg();
4720 } else if (FromParam->hasDefaultArg()) {
4721 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4722 ToParam->setDefaultArg(*ToDefArgOrErr);
4723 else
4724 return ToDefArgOrErr.takeError();
4725 }
4726
4727 return Error::success();
4728}
4729
4732 Error Err = Error::success();
4733 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4734 ConstructorUsingShadowDecl *ToShadow =
4735 importChecked(Err, From.getShadowDecl());
4736 if (Err)
4737 return std::move(Err);
4738 return InheritedConstructor(ToShadow, ToBaseCtor);
4739}
4740
4742 // Parameters are created in the translation unit's context, then moved
4743 // into the function declaration's context afterward.
4745
4746 Error Err = Error::success();
4747 auto ToDeclName = importChecked(Err, D->getDeclName());
4748 auto ToLocation = importChecked(Err, D->getLocation());
4749 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4750 auto ToType = importChecked(Err, D->getType());
4751 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4752 if (Err)
4753 return std::move(Err);
4754
4755 ParmVarDecl *ToParm;
4756 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4757 ToInnerLocStart, ToLocation,
4758 ToDeclName.getAsIdentifierInfo(), ToType,
4759 ToTypeSourceInfo, D->getStorageClass(),
4760 /*DefaultArg*/ nullptr))
4761 return ToParm;
4762
4763 // Set the default argument. It should be no problem if it was already done.
4764 // Do not import the default expression before GetImportedOrCreateDecl call
4765 // to avoid possible infinite import loop because circular dependency.
4766 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4767 return std::move(Err);
4768
4769 if (D->isObjCMethodParameter()) {
4770 ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex());
4771 ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier());
4772 } else {
4773 ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4774 D->getFunctionScopeIndex());
4775 }
4776
4777 return ToParm;
4778}
4779
4781 // Import the major distinguishing characteristics of a method.
4782 DeclContext *DC, *LexicalDC;
4783 DeclarationName Name;
4785 NamedDecl *ToD;
4786 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4787 return std::move(Err);
4788 if (ToD)
4789 return ToD;
4790
4791 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4792 for (auto *FoundDecl : FoundDecls) {
4793 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4794 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4795 continue;
4796
4797 // Check return types.
4798 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4799 FoundMethod->getReturnType())) {
4800 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4801 << D->isInstanceMethod() << Name << D->getReturnType()
4802 << FoundMethod->getReturnType();
4803 Importer.ToDiag(FoundMethod->getLocation(),
4804 diag::note_odr_objc_method_here)
4805 << D->isInstanceMethod() << Name;
4806
4807 return make_error<ASTImportError>(ASTImportError::NameConflict);
4808 }
4809
4810 // Check the number of parameters.
4811 if (D->param_size() != FoundMethod->param_size()) {
4812 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4813 << D->isInstanceMethod() << Name
4814 << D->param_size() << FoundMethod->param_size();
4815 Importer.ToDiag(FoundMethod->getLocation(),
4816 diag::note_odr_objc_method_here)
4817 << D->isInstanceMethod() << Name;
4818
4819 return make_error<ASTImportError>(ASTImportError::NameConflict);
4820 }
4821
4822 // Check parameter types.
4823 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
4824 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4825 P != PEnd; ++P, ++FoundP) {
4826 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4827 (*FoundP)->getType())) {
4828 Importer.FromDiag((*P)->getLocation(),
4829 diag::warn_odr_objc_method_param_type_inconsistent)
4830 << D->isInstanceMethod() << Name
4831 << (*P)->getType() << (*FoundP)->getType();
4832 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4833 << (*FoundP)->getType();
4834
4835 return make_error<ASTImportError>(ASTImportError::NameConflict);
4836 }
4837 }
4838
4839 // Check variadic/non-variadic.
4840 // Check the number of parameters.
4841 if (D->isVariadic() != FoundMethod->isVariadic()) {
4842 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4843 << D->isInstanceMethod() << Name;
4844 Importer.ToDiag(FoundMethod->getLocation(),
4845 diag::note_odr_objc_method_here)
4846 << D->isInstanceMethod() << Name;
4847
4848 return make_error<ASTImportError>(ASTImportError::NameConflict);
4849 }
4850
4851 // FIXME: Any other bits we need to merge?
4852 return Importer.MapImported(D, FoundMethod);
4853 }
4854 }
4855
4856 Error Err = Error::success();
4857 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4858 auto ToReturnType = importChecked(Err, D->getReturnType());
4859 auto ToReturnTypeSourceInfo =
4860 importChecked(Err, D->getReturnTypeSourceInfo());
4861 if (Err)
4862 return std::move(Err);
4863
4864 ObjCMethodDecl *ToMethod;
4865 if (GetImportedOrCreateDecl(
4866 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4867 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4868 D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(),
4869 D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(),
4870 D->getImplementationControl(), D->hasRelatedResultType()))
4871 return ToMethod;
4872
4873 // FIXME: When we decide to merge method definitions, we'll need to
4874 // deal with implicit parameters.
4875
4876 // Import the parameters
4878 for (auto *FromP : D->parameters()) {
4879 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4880 ToParams.push_back(*ToPOrErr);
4881 else
4882 return ToPOrErr.takeError();
4883 }
4884
4885 // Set the parameters.
4886 for (auto *ToParam : ToParams) {
4887 ToParam->setOwningFunction(ToMethod);
4888 ToMethod->addDeclInternal(ToParam);
4889 }
4890
4892 D->getSelectorLocs(FromSelLocs);
4893 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4894 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4895 return std::move(Err);
4896
4897 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4898
4899 ToMethod->setLexicalDeclContext(LexicalDC);
4900 LexicalDC->addDeclInternal(ToMethod);
4901
4902 // Implicit params are declared when Sema encounters the definition but this
4903 // never happens when the method is imported. Manually declare the implicit
4904 // params now that the MethodDecl knows its class interface.
4905 if (D->getSelfDecl())
4906 ToMethod->createImplicitParams(Importer.getToContext(),
4907 ToMethod->getClassInterface());
4908
4909 return ToMethod;
4910}
4911
4913 // Import the major distinguishing characteristics of a category.
4914 DeclContext *DC, *LexicalDC;
4915 DeclarationName Name;
4917 NamedDecl *ToD;
4918 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4919 return std::move(Err);
4920 if (ToD)
4921 return ToD;
4922
4923 Error Err = Error::success();
4924 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4925 auto ToLocation = importChecked(Err, D->getLocation());
4926 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4927 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4928 if (Err)
4929 return std::move(Err);
4930
4932 if (GetImportedOrCreateDecl(
4933 Result, D, Importer.getToContext(), DC, D->getVariance(),
4934 ToVarianceLoc, D->getIndex(),
4935 ToLocation, Name.getAsIdentifierInfo(),
4936 ToColonLoc, ToTypeSourceInfo))
4937 return Result;
4938
4939 // Only import 'ObjCTypeParamType' after the decl is created.
4940 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4941 if (Err)
4942 return std::move(Err);
4943 Result->setTypeForDecl(ToTypeForDecl);
4944 Result->setLexicalDeclContext(LexicalDC);
4945 return Result;
4946}
4947
4949 // Import the major distinguishing characteristics of a category.
4950 DeclContext *DC, *LexicalDC;
4951 DeclarationName Name;
4953 NamedDecl *ToD;
4954 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4955 return std::move(Err);
4956 if (ToD)
4957 return ToD;
4958
4959 ObjCInterfaceDecl *ToInterface;
4960 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4961 return std::move(Err);
4962
4963 // Determine if we've already encountered this category.
4964 ObjCCategoryDecl *MergeWithCategory
4965 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4966 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4967 if (!ToCategory) {
4968
4969 Error Err = Error::success();
4970 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4971 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4972 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4973 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4974 if (Err)
4975 return std::move(Err);
4976
4977 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4978 ToAtStartLoc, Loc,
4979 ToCategoryNameLoc,
4980 Name.getAsIdentifierInfo(), ToInterface,
4981 /*TypeParamList=*/nullptr,
4982 ToIvarLBraceLoc,
4983 ToIvarRBraceLoc))
4984 return ToCategory;
4985
4986 ToCategory->setLexicalDeclContext(LexicalDC);
4987 LexicalDC->addDeclInternal(ToCategory);
4988 // Import the type parameter list after MapImported, to avoid
4989 // loops when bringing in their DeclContext.
4990 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4991 ToCategory->setTypeParamList(*PListOrErr);
4992 else
4993 return PListOrErr.takeError();
4994
4995 // Import protocols
4997 SmallVector<SourceLocation, 4> ProtocolLocs;
4999 = D->protocol_loc_begin();
5000 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
5001 FromProtoEnd = D->protocol_end();
5002 FromProto != FromProtoEnd;
5003 ++FromProto, ++FromProtoLoc) {
5004 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5005 Protocols.push_back(*ToProtoOrErr);
5006 else
5007 return ToProtoOrErr.takeError();
5008
5009 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5010 ProtocolLocs.push_back(*ToProtoLocOrErr);
5011 else
5012 return ToProtoLocOrErr.takeError();
5013 }
5014
5015 // FIXME: If we're merging, make sure that the protocol list is the same.
5016 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5017 ProtocolLocs.data(), Importer.getToContext());
5018
5019 } else {
5020 Importer.MapImported(D, ToCategory);
5021 }
5022
5023 // Import all of the members of this category.
5024 if (Error Err = ImportDeclContext(D))
5025 return std::move(Err);
5026
5027 // If we have an implementation, import it as well.
5028 if (D->getImplementation()) {
5029 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5030 import(D->getImplementation()))
5031 ToCategory->setImplementation(*ToImplOrErr);
5032 else
5033 return ToImplOrErr.takeError();
5034 }
5035
5036 return ToCategory;
5037}
5038
5041 if (To->getDefinition()) {
5043 if (Error Err = ImportDeclContext(From))
5044 return Err;
5045 return Error::success();
5046 }
5047
5048 // Start the protocol definition
5049 To->startDefinition();
5050
5051 // Import protocols
5053 SmallVector<SourceLocation, 4> ProtocolLocs;
5055 From->protocol_loc_begin();
5056 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5057 FromProtoEnd = From->protocol_end();
5058 FromProto != FromProtoEnd;
5059 ++FromProto, ++FromProtoLoc) {
5060 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5061 Protocols.push_back(*ToProtoOrErr);
5062 else
5063 return ToProtoOrErr.takeError();
5064
5065 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5066 ProtocolLocs.push_back(*ToProtoLocOrErr);
5067 else
5068 return ToProtoLocOrErr.takeError();
5069
5070 }
5071
5072 // FIXME: If we're merging, make sure that the protocol list is the same.
5073 To->setProtocolList(Protocols.data(), Protocols.size(),
5074 ProtocolLocs.data(), Importer.getToContext());
5075
5076 if (shouldForceImportDeclContext(Kind)) {
5077 // Import all of the members of this protocol.
5078 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5079 return Err;
5080 }
5081 return Error::success();
5082}
5083
5085 // If this protocol has a definition in the translation unit we're coming
5086 // from, but this particular declaration is not that definition, import the
5087 // definition and map to that.
5088 ObjCProtocolDecl *Definition = D->getDefinition();
5089 if (Definition && Definition != D) {
5090 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5091 return Importer.MapImported(D, *ImportedDefOrErr);
5092 else
5093 return ImportedDefOrErr.takeError();
5094 }
5095
5096 // Import the major distinguishing characteristics of a protocol.
5097 DeclContext *DC, *LexicalDC;
5098 DeclarationName Name;
5100 NamedDecl *ToD;
5101 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5102 return std::move(Err);
5103 if (ToD)
5104 return ToD;
5105
5106 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5107 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5108 for (auto *FoundDecl : FoundDecls) {
5110 continue;
5111
5112 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5113 break;
5114 }
5115
5116 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5117 if (!ToProto) {
5118 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5119 if (!ToAtBeginLocOrErr)
5120 return ToAtBeginLocOrErr.takeError();
5121
5122 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5123 Name.getAsIdentifierInfo(), Loc,
5124 *ToAtBeginLocOrErr,
5125 /*PrevDecl=*/nullptr))
5126 return ToProto;
5127 ToProto->setLexicalDeclContext(LexicalDC);
5128 LexicalDC->addDeclInternal(ToProto);
5129 }
5130
5131 Importer.MapImported(D, ToProto);
5132
5133 if (D->isThisDeclarationADefinition())
5134 if (Error Err = ImportDefinition(D, ToProto))
5135 return std::move(Err);
5136
5137 return ToProto;
5138}
5139
5141 DeclContext *DC, *LexicalDC;
5142 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5143 return std::move(Err);
5144
5145 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5146 if (!ExternLocOrErr)
5147 return ExternLocOrErr.takeError();
5148
5149 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5150 if (!LangLocOrErr)
5151 return LangLocOrErr.takeError();
5152
5153 bool HasBraces = D->hasBraces();
5154
5155 LinkageSpecDecl *ToLinkageSpec;
5156 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5157 *ExternLocOrErr, *LangLocOrErr,
5158 D->getLanguage(), HasBraces))
5159 return ToLinkageSpec;
5160
5161 if (HasBraces) {
5162 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5163 if (!RBraceLocOrErr)
5164 return RBraceLocOrErr.takeError();
5165 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5166 }
5167
5168 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5169 LexicalDC->addDeclInternal(ToLinkageSpec);
5170
5171 return ToLinkageSpec;
5172}
5173
5175 BaseUsingDecl *ToSI) {
5176 for (UsingShadowDecl *FromShadow : D->shadows()) {
5177 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5178 ToSI->addShadowDecl(*ToShadowOrErr);
5179 else
5180 // FIXME: We return error here but the definition is already created
5181 // and available with lookups. How to fix this?..
5182 return ToShadowOrErr.takeError();
5183 }
5184 return ToSI;
5185}
5186
5188 DeclContext *DC, *LexicalDC;
5189 DeclarationName Name;
5191 NamedDecl *ToD = nullptr;
5192 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5193 return std::move(Err);
5194 if (ToD)
5195 return ToD;
5196
5197 Error Err = Error::success();
5198 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5199 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5200 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5201 if (Err)
5202 return std::move(Err);
5203
5204 DeclarationNameInfo NameInfo(Name, ToLoc);
5205 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5206 return std::move(Err);
5207
5208 UsingDecl *ToUsing;
5209 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5210 ToUsingLoc, ToQualifierLoc, NameInfo,
5211 D->hasTypename()))
5212 return ToUsing;
5213
5214 ToUsing->setLexicalDeclContext(LexicalDC);
5215 LexicalDC->addDeclInternal(ToUsing);
5216
5217 if (NamedDecl *FromPattern =
5219 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5221 ToUsing, *ToPatternOrErr);
5222 else
5223 return ToPatternOrErr.takeError();
5224 }
5225
5226 return ImportUsingShadowDecls(D, ToUsing);
5227}
5228
5230 DeclContext *DC, *LexicalDC;
5231 DeclarationName Name;
5233 NamedDecl *ToD = nullptr;
5234 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5235 return std::move(Err);
5236 if (ToD)
5237 return ToD;
5238
5239 Error Err = Error::success();
5240 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5241 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5242 auto ToNameLoc = importChecked(Err, D->getLocation());
5243 auto *ToEnumType = importChecked(Err, D->getEnumType());
5244 if (Err)
5245 return std::move(Err);
5246
5247 UsingEnumDecl *ToUsingEnum;
5248 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5249 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5250 return ToUsingEnum;
5251
5252 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5253 LexicalDC->addDeclInternal(ToUsingEnum);
5254
5255 if (UsingEnumDecl *FromPattern =
5257 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5258 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5259 *ToPatternOrErr);
5260 else
5261 return ToPatternOrErr.takeError();
5262 }
5263
5264 return ImportUsingShadowDecls(D, ToUsingEnum);
5265}
5266
5268 DeclContext *DC, *LexicalDC;
5269 DeclarationName Name;
5271 NamedDecl *ToD = nullptr;
5272 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5273 return std::move(Err);
5274 if (ToD)
5275 return ToD;
5276
5277 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5278 if (!ToIntroducerOrErr)
5279 return ToIntroducerOrErr.takeError();
5280
5281 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5282 if (!ToTargetOrErr)
5283 return ToTargetOrErr.takeError();
5284
5285 UsingShadowDecl *ToShadow;
5286 if (auto *FromConstructorUsingShadow =
5287 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5288 Error Err = Error::success();
5290 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5291 if (Err)
5292 return std::move(Err);
5293 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5294 // is really the "NominatedBaseClassShadowDecl" value if it exists
5295 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5296 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5297 // get the correct values.
5298 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5299 ToShadow, D, Importer.getToContext(), DC, Loc,
5300 cast<UsingDecl>(*ToIntroducerOrErr),
5301 Nominated ? Nominated : *ToTargetOrErr,
5302 FromConstructorUsingShadow->constructsVirtualBase()))
5303 return ToShadow;
5304 } else {
5305 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5306 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5307 return ToShadow;
5308 }
5309
5310 ToShadow->setLexicalDeclContext(LexicalDC);
5311 ToShadow->setAccess(D->getAccess());
5312
5313 if (UsingShadowDecl *FromPattern =
5315 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5317 ToShadow, *ToPatternOrErr);
5318 else
5319 // FIXME: We return error here but the definition is already created
5320 // and available with lookups. How to fix this?..
5321 return ToPatternOrErr.takeError();
5322 }
5323
5324 LexicalDC->addDeclInternal(ToShadow);
5325
5326 return ToShadow;
5327}
5328
5330 DeclContext *DC, *LexicalDC;
5331 DeclarationName Name;
5333 NamedDecl *ToD = nullptr;
5334 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5335 return std::move(Err);
5336 if (ToD)
5337 return ToD;
5338
5339 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5340 if (!ToComAncestorOrErr)
5341 return ToComAncestorOrErr.takeError();
5342
5343 Error Err = Error::success();
5344 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5345 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5346 auto ToNamespaceKeyLocation =
5347 importChecked(Err, D->getNamespaceKeyLocation());
5348 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5349 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5350 if (Err)
5351 return std::move(Err);
5352
5353 UsingDirectiveDecl *ToUsingDir;
5354 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5355 ToUsingLoc,
5356 ToNamespaceKeyLocation,
5357 ToQualifierLoc,
5358 ToIdentLocation,
5359 ToNominatedNamespace, *ToComAncestorOrErr))
5360 return ToUsingDir;
5361
5362 ToUsingDir->setLexicalDeclContext(LexicalDC);
5363 LexicalDC->addDeclInternal(ToUsingDir);
5364
5365 return ToUsingDir;
5366}
5367
5369 DeclContext *DC, *LexicalDC;
5370 DeclarationName Name;
5372 NamedDecl *ToD = nullptr;
5373 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5374 return std::move(Err);
5375 if (ToD)
5376 return ToD;
5377
5378 auto ToInstantiatedFromUsingOrErr =
5379 Importer.Import(D->getInstantiatedFromUsingDecl());
5380 if (!ToInstantiatedFromUsingOrErr)
5381 return ToInstantiatedFromUsingOrErr.takeError();
5382 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5383 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5384 return std::move(Err);
5385
5386 UsingPackDecl *ToUsingPack;
5387 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5388 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5389 Expansions))
5390 return ToUsingPack;
5391
5392 addDeclToContexts(D, ToUsingPack);
5393
5394 return ToUsingPack;
5395}
5396
5399 DeclContext *DC, *LexicalDC;
5400 DeclarationName Name;
5402 NamedDecl *ToD = nullptr;
5403 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5404 return std::move(Err);
5405 if (ToD)
5406 return ToD;
5407
5408 Error Err = Error::success();
5409 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5410 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5411 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5412 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5413 if (Err)
5414 return std::move(Err);
5415
5416 DeclarationNameInfo NameInfo(Name, ToLoc);
5417 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5418 return std::move(Err);
5419
5420 UnresolvedUsingValueDecl *ToUsingValue;
5421 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5422 ToUsingLoc, ToQualifierLoc, NameInfo,
5423 ToEllipsisLoc))
5424 return ToUsingValue;
5425
5426 ToUsingValue->setAccess(D->getAccess());
5427 ToUsingValue->setLexicalDeclContext(LexicalDC);
5428 LexicalDC->addDeclInternal(ToUsingValue);
5429
5430 return ToUsingValue;
5431}
5432
5435 DeclContext *DC, *LexicalDC;
5436 DeclarationName Name;
5438 NamedDecl *ToD = nullptr;
5439 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5440 return std::move(Err);
5441 if (ToD)
5442 return ToD;
5443
5444 Error Err = Error::success();
5445 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5446 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5447 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5448 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5449 if (Err)
5450 return std::move(Err);
5451
5453 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5454 ToUsingLoc, ToTypenameLoc,
5455 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5456 return ToUsing;
5457
5458 ToUsing->setAccess(D->getAccess());
5459 ToUsing->setLexicalDeclContext(LexicalDC);
5460 LexicalDC->addDeclInternal(ToUsing);
5461
5462 return ToUsing;
5463}
5464
5466 Decl* ToD = nullptr;
5467 switch (D->getBuiltinTemplateKind()) {
5469 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5470 break;
5472 ToD = Importer.getToContext().getTypePackElementDecl();
5473 break;
5475 ToD = Importer.getToContext().getBuiltinCommonTypeDecl();
5476 break;
5477 }
5478 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5479 Importer.MapImported(D, ToD);
5480 return ToD;
5481}
5482
5485 if (To->getDefinition()) {
5486 // Check consistency of superclass.
5487 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5488 if (FromSuper) {
5489 if (auto FromSuperOrErr = import(FromSuper))
5490 FromSuper = *FromSuperOrErr;
5491 else
5492 return FromSuperOrErr.takeError();
5493 }
5494
5495 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5496 if ((bool)FromSuper != (bool)ToSuper ||
5497 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5498 Importer.ToDiag(To->getLocation(),
5499 diag::warn_odr_objc_superclass_inconsistent)
5500 << To->getDeclName();
5501 if (ToSuper)
5502 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5503 << To->getSuperClass()->getDeclName();
5504 else
5505 Importer.ToDiag(To->getLocation(),
5506 diag::note_odr_objc_missing_superclass);
5507 if (From->getSuperClass())
5508 Importer.FromDiag(From->getSuperClassLoc(),
5509 diag::note_odr_objc_superclass)
5510 << From->getSuperClass()->getDeclName();
5511 else
5512 Importer.FromDiag(From->getLocation(),
5513 diag::note_odr_objc_missing_superclass);
5514 }
5515
5517 if (Error Err = ImportDeclContext(From))
5518 return Err;
5519 return Error::success();
5520 }
5521
5522 // Start the definition.
5523 To->startDefinition();
5524
5525 // If this class has a superclass, import it.
5526 if (From->getSuperClass()) {
5527 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5528 To->setSuperClass(*SuperTInfoOrErr);
5529 else
5530 return SuperTInfoOrErr.takeError();
5531 }
5532
5533 // Import protocols
5535 SmallVector<SourceLocation, 4> ProtocolLocs;
5537 From->protocol_loc_begin();
5538
5540 FromProtoEnd = From->protocol_end();
5541 FromProto != FromProtoEnd;
5542 ++FromProto, ++FromProtoLoc) {
5543 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5544 Protocols.push_back(*ToProtoOrErr);
5545 else
5546 return ToProtoOrErr.takeError();
5547
5548 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5549 ProtocolLocs.push_back(*ToProtoLocOrErr);
5550 else
5551 return ToProtoLocOrErr.takeError();
5552
5553 }
5554
5555 // FIXME: If we're merging, make sure that the protocol list is the same.
5556 To->setProtocolList(Protocols.data(), Protocols.size(),
5557 ProtocolLocs.data(), Importer.getToContext());
5558
5559 // Import categories. When the categories themselves are imported, they'll
5560 // hook themselves into this interface.
5561 for (auto *Cat : From->known_categories()) {
5562 auto ToCatOrErr = import(Cat);
5563 if (!ToCatOrErr)
5564 return ToCatOrErr.takeError();
5565 }
5566
5567 // If we have an @implementation, import it as well.
5568 if (From->getImplementation()) {
5569 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5570 import(From->getImplementation()))
5571 To->setImplementation(*ToImplOrErr);
5572 else
5573 return ToImplOrErr.takeError();
5574 }
5575
5576 // Import all of the members of this class.
5577 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5578 return Err;
5579
5580 return Error::success();
5581}
5582
5585 if (!list)
5586 return nullptr;
5587
5589 for (auto *fromTypeParam : *list) {
5590 if (auto toTypeParamOrErr = import(fromTypeParam))
5591 toTypeParams.push_back(*toTypeParamOrErr);
5592 else
5593 return toTypeParamOrErr.takeError();
5594 }
5595
5596 auto LAngleLocOrErr = import(list->getLAngleLoc());
5597 if (!LAngleLocOrErr)
5598 return LAngleLocOrErr.takeError();
5599
5600 auto RAngleLocOrErr = import(list->getRAngleLoc());
5601 if (!RAngleLocOrErr)
5602 return RAngleLocOrErr.takeError();
5603
5604 return ObjCTypeParamList::create(Importer.getToContext(),
5605 *LAngleLocOrErr,
5606 toTypeParams,
5607 *RAngleLocOrErr);
5608}
5609
5611 // If this class has a definition in the translation unit we're coming from,
5612 // but this particular declaration is not that definition, import the
5613 // definition and map to that.
5614 ObjCInterfaceDecl *Definition = D->getDefinition();
5615 if (Definition && Definition != D) {
5616 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5617 return Importer.MapImported(D, *ImportedDefOrErr);
5618 else
5619 return ImportedDefOrErr.takeError();
5620 }
5621
5622 // Import the major distinguishing characteristics of an @interface.
5623 DeclContext *DC, *LexicalDC;
5624 DeclarationName Name;
5626 NamedDecl *ToD;
5627 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5628 return std::move(Err);
5629 if (ToD)
5630 return ToD;
5631
5632 // Look for an existing interface with the same name.
5633 ObjCInterfaceDecl *MergeWithIface = nullptr;
5634 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5635 for (auto *FoundDecl : FoundDecls) {
5637 continue;
5638
5639 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5640 break;
5641 }
5642
5643 // Create an interface declaration, if one does not already exist.
5644 ObjCInterfaceDecl *ToIface = MergeWithIface;
5645 if (!ToIface) {
5646 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5647 if (!AtBeginLocOrErr)
5648 return AtBeginLocOrErr.takeError();
5649
5650 if (GetImportedOrCreateDecl(
5651 ToIface, D, Importer.getToContext(), DC,
5652 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5653 /*TypeParamList=*/nullptr,
5654 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5655 return ToIface;
5656 ToIface->setLexicalDeclContext(LexicalDC);
5657 LexicalDC->addDeclInternal(ToIface);
5658 }
5659 Importer.MapImported(D, ToIface);
5660 // Import the type parameter list after MapImported, to avoid
5661 // loops when bringing in their DeclContext.
5662 if (auto ToPListOrErr =
5663 ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
5664 ToIface->setTypeParamList(*ToPListOrErr);
5665 else
5666 return ToPListOrErr.takeError();
5667
5668 if (D->isThisDeclarationADefinition())
5669 if (Error Err = ImportDefinition(D, ToIface))
5670 return std::move(Err);
5671
5672 return ToIface;
5673}
5674
5678 if (Error Err = importInto(Category, D->getCategoryDecl()))
5679 return std::move(Err);
5680
5681 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5682 if (!ToImpl) {
5683 DeclContext *DC, *LexicalDC;
5684 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5685 return std::move(Err);
5686
5687 Error Err = Error::success();
5688 auto ToLocation = importChecked(Err, D->getLocation());
5689 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5690 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5691 if (Err)
5692 return std::move(Err);
5693
5694 if (GetImportedOrCreateDecl(
5695 ToImpl, D, Importer.getToContext(), DC,
5696 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5697 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5698 return ToImpl;
5699
5700 ToImpl->setLexicalDeclContext(LexicalDC);
5701 LexicalDC->addDeclInternal(ToImpl);
5702 Category->setImplementation(ToImpl);
5703 }
5704
5705 Importer.MapImported(D, ToImpl);
5706 if (Error Err = ImportDeclContext(D))
5707 return std::move(Err);
5708
5709 return ToImpl;
5710}
5711
5714 // Find the corresponding interface.
5715 ObjCInterfaceDecl *Iface;
5716 if (Error Err = importInto(Iface, D->getClassInterface()))
5717 return std::move(Err);
5718
5719 // Import the superclass, if any.
5720 ObjCInterfaceDecl *Super;
5721 if (Error Err = importInto(Super, D->getSuperClass()))
5722 return std::move(Err);
5723
5725 if (!Impl) {
5726 // We haven't imported an implementation yet. Create a new @implementation
5727 // now.
5728 DeclContext *DC, *LexicalDC;
5729 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5730 return std::move(Err);
5731
5732 Error Err = Error::success();
5733 auto ToLocation = importChecked(Err, D->getLocation());
5734 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5735 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5736 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5737 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5738 if (Err)
5739 return std::move(Err);
5740
5741 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5742 DC, Iface, Super,
5743 ToLocation,
5744 ToAtStartLoc,
5745 ToSuperClassLoc,
5746 ToIvarLBraceLoc,
5747 ToIvarRBraceLoc))
5748 return Impl;
5749
5750 Impl->setLexicalDeclContext(LexicalDC);
5751
5752 // Associate the implementation with the class it implements.
5753 Iface->setImplementation(Impl);
5754 Importer.MapImported(D, Iface->getImplementation());
5755 } else {
5756 Importer.MapImported(D, Iface->getImplementation());
5757
5758 // Verify that the existing @implementation has the same superclass.
5759 if ((Super && !Impl->getSuperClass()) ||
5760 (!Super && Impl->getSuperClass()) ||
5761 (Super && Impl->getSuperClass() &&
5763 Impl->getSuperClass()))) {
5764 Importer.ToDiag(Impl->getLocation(),
5765 diag::warn_odr_objc_superclass_inconsistent)
5766 << Iface->getDeclName();
5767 // FIXME: It would be nice to have the location of the superclass
5768 // below.
5769 if (Impl->getSuperClass())
5770 Importer.ToDiag(Impl->getLocation(),
5771 diag::note_odr_objc_superclass)
5772 << Impl->getSuperClass()->getDeclName();
5773 else
5774 Importer.ToDiag(Impl->getLocation(),
5775 diag::note_odr_objc_missing_superclass);
5776 if (D->getSuperClass())
5777 Importer.FromDiag(D->getLocation(),
5778 diag::note_odr_objc_superclass)
5779 << D->getSuperClass()->getDeclName();
5780 else
5781 Importer.FromDiag(D->getLocation(),
5782 diag::note_odr_objc_missing_superclass);
5783
5784 return make_error<ASTImportError>(ASTImportError::NameConflict);
5785 }
5786 }
5787
5788 // Import all of the members of this @implementation.
5789 if (Error Err = ImportDeclContext(D))
5790 return std::move(Err);
5791
5792 return Impl;
5793}
5794
5796 // Import the major distinguishing characteristics of an @property.
5797 DeclContext *DC, *LexicalDC;
5798 DeclarationName Name;
5800 NamedDecl *ToD;
5801 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5802 return std::move(Err);
5803 if (ToD)
5804 return ToD;
5805
5806 // Check whether we have already imported this property.
5807 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5808 for (auto *FoundDecl : FoundDecls) {
5809 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5810 // Instance and class properties can share the same name but are different
5811 // declarations.
5812 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5813 continue;
5814
5815 // Check property types.
5816 if (!Importer.IsStructurallyEquivalent(D->getType(),
5817 FoundProp->getType())) {
5818 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5819 << Name << D->getType() << FoundProp->getType();
5820 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5821 << FoundProp->getType();
5822
5823 return make_error<ASTImportError>(ASTImportError::NameConflict);
5824 }
5825
5826 // FIXME: Check property attributes, getters, setters, etc.?
5827
5828 // Consider these properties to be equivalent.
5829 Importer.MapImported(D, FoundProp);
5830 return FoundProp;
5831 }
5832 }
5833
5834 Error Err = Error::success();
5835 auto ToType = importChecked(Err, D->getType());
5836 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5837 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5838 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5839 if (Err)
5840 return std::move(Err);
5841
5842 // Create the new property.
5843 ObjCPropertyDecl *ToProperty;
5844 if (GetImportedOrCreateDecl(
5845 ToProperty, D, Importer.getToContext(), DC, Loc,
5846 Name.getAsIdentifierInfo(), ToAtLoc,
5847 ToLParenLoc, ToType,
5848 ToTypeSourceInfo, D->getPropertyImplementation()))
5849 return ToProperty;
5850
5851 auto ToGetterName = importChecked(Err, D->getGetterName());
5852 auto ToSetterName = importChecked(Err, D->getSetterName());
5853 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5854 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5855 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5856 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5857 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5858 if (Err)
5859 return std::move(Err);
5860
5861 ToProperty->setLexicalDeclContext(LexicalDC);
5862 LexicalDC->addDeclInternal(ToProperty);
5863
5864 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
5866 D->getPropertyAttributesAsWritten());
5867 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5868 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5869 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5870 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5871 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5872 return ToProperty;
5873}
5874
5878 if (Error Err = importInto(Property, D->getPropertyDecl()))
5879 return std::move(Err);
5880
5881 DeclContext *DC, *LexicalDC;
5882 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5883 return std::move(Err);
5884
5885 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5886
5887 // Import the ivar (for an @synthesize).
5888 ObjCIvarDecl *Ivar = nullptr;
5889 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5890 return std::move(Err);
5891
5892 ObjCPropertyImplDecl *ToImpl
5893 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5894 Property->getQueryKind());
5895 if (!ToImpl) {
5896
5897 Error Err = Error::success();
5898 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5899 auto ToLocation = importChecked(Err, D->getLocation());
5900 auto ToPropertyIvarDeclLoc =
5901 importChecked(Err, D->getPropertyIvarDeclLoc());
5902 if (Err)
5903 return std::move(Err);
5904
5905 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5906 ToBeginLoc,
5907 ToLocation, Property,
5908 D->getPropertyImplementation(), Ivar,
5909 ToPropertyIvarDeclLoc))
5910 return ToImpl;
5911
5912 ToImpl->setLexicalDeclContext(LexicalDC);
5913 LexicalDC->addDeclInternal(ToImpl);
5914 } else {
5915 // Check that we have the same kind of property implementation (@synthesize
5916 // vs. @dynamic).
5917 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
5918 Importer.ToDiag(ToImpl->getLocation(),
5919 diag::warn_odr_objc_property_impl_kind_inconsistent)
5920 << Property->getDeclName()
5921 << (ToImpl->getPropertyImplementation()
5923 Importer.FromDiag(D->getLocation(),
5924 diag::note_odr_objc_property_impl_kind)
5925 << D->getPropertyDecl()->getDeclName()
5926 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
5927
5928 return make_error<ASTImportError>(ASTImportError::NameConflict);
5929 }
5930
5931 // For @synthesize, check that we have the same
5932 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
5933 Ivar != ToImpl->getPropertyIvarDecl()) {
5934 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5935 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5936 << Property->getDeclName()
5937 << ToImpl->getPropertyIvarDecl()->getDeclName()
5938 << Ivar->getDeclName();
5939 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5940 diag::note_odr_objc_synthesize_ivar_here)
5941 << D->getPropertyIvarDecl()->getDeclName();
5942
5943 return make_error<ASTImportError>(ASTImportError::NameConflict);
5944 }
5945
5946 // Merge the existing implementation with the new implementation.
5947 Importer.MapImported(D, ToImpl);
5948 }
5949
5950 return ToImpl;
5951}
5952
5955 // For template arguments, we adopt the translation unit as our declaration
5956 // context. This context will be fixed when (during) the actual template
5957 // declaration is created.
5958
5959 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5960 if (!BeginLocOrErr)
5961 return BeginLocOrErr.takeError();
5962
5963 ExpectedSLoc LocationOrErr = import(D->getLocation());
5964 if (!LocationOrErr)
5965 return LocationOrErr.takeError();
5966
5967 TemplateTypeParmDecl *ToD = nullptr;
5968 if (GetImportedOrCreateDecl(
5969 ToD, D, Importer.getToContext(),
5971 *BeginLocOrErr, *LocationOrErr,
5972 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5973 D->wasDeclaredWithTypename(), D->isParameterPack(),
5974 D->hasTypeConstraint()))
5975 return ToD;
5976
5977 // Import the type-constraint
5978 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5979
5980 Error Err = Error::success();
5981 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5982 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5983 if (Err)
5984 return std::move(Err);
5985
5986 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5987 }
5988
5989 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
5990 return Err;
5991
5992 return ToD;
5993}
5994
5997
5998 Error Err = Error::success();
5999 auto ToDeclName = importChecked(Err, D->getDeclName());
6000 auto ToLocation = importChecked(Err, D->getLocation());
6001 auto ToType = importChecked(Err, D->getType());
6002 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6003 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6004 if (Err)
6005 return std::move(Err);
6006
6007 NonTypeTemplateParmDecl *ToD = nullptr;
6008 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6010 ToInnerLocStart, ToLocation, D->getDepth(),
6011 D->getPosition(),
6012 ToDeclName.getAsIdentifierInfo(), ToType,
6013 D->isParameterPack(), ToTypeSourceInfo))
6014 return ToD;
6015
6016 Err = importTemplateParameterDefaultArgument(D, ToD);
6017 if (Err)
6018 return Err;
6019
6020 return ToD;
6021}
6022
6025 // Import the name of this declaration.
6026 auto NameOrErr = import(D->getDeclName());
6027 if (!NameOrErr)
6028 return NameOrErr.takeError();
6029
6030 // Import the location of this declaration.
6031 ExpectedSLoc LocationOrErr = import(D->getLocation());
6032 if (!LocationOrErr)
6033 return LocationOrErr.takeError();
6034
6035 // Import template parameters.
6036 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6037 if (!TemplateParamsOrErr)
6038 return TemplateParamsOrErr.takeError();
6039
6040 TemplateTemplateParmDecl *ToD = nullptr;
6041 if (GetImportedOrCreateDecl(
6042 ToD, D, Importer.getToContext(),
6043 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6044 D->getDepth(), D->getPosition(), D->isParameterPack(),
6045 (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
6046 *TemplateParamsOrErr))
6047 return ToD;
6048
6049 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6050 return Err;
6051
6052 return ToD;
6053}
6054
6055// Returns the definition for a (forward) declaration of a TemplateDecl, if
6056// it has any definition in the redecl chain.
6057template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6058 assert(D->getTemplatedDecl() && "Should be called on templates only");
6059 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6060 if (!ToTemplatedDef)
6061 return nullptr;
6062 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6063 return cast_or_null<T>(TemplateWithDef);
6064}
6065
6067
6068 // Import the major distinguishing characteristics of this class template.
6069 DeclContext *DC, *LexicalDC;
6070 DeclarationName Name;
6072 NamedDecl *ToD;
6073 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6074 return std::move(Err);
6075 if (ToD)
6076 return ToD;
6077
6078 // Should check if a declaration is friend in a dependent context.
6079 // Such templates are not linked together in a declaration chain.
6080 // The ASTImporter strategy is to map existing forward declarations to
6081 // imported ones only if strictly necessary, otherwise import these as new
6082 // forward declarations. In case of the "dependent friend" declarations, new
6083 // declarations are created, but not linked in a declaration chain.
6084 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6085 return TD->getFriendObjectKind() != Decl::FOK_None &&
6087 };
6088 bool DependentFriend = IsDependentFriend(D);
6089
6090 ClassTemplateDecl *FoundByLookup = nullptr;
6091
6092 // We may already have a template of the same name; try to find and match it.
6093 if (!DC->isFunctionOrMethod()) {
6094 SmallVector<NamedDecl *, 4> ConflictingDecls;
6095 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6096 for (auto *FoundDecl : FoundDecls) {
6099 continue;
6100
6101 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6102 if (FoundTemplate) {
6103 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6104 continue;
6105
6106 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6107 bool IgnoreTemplateParmDepth =
6108 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6110 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6111 IgnoreTemplateParmDepth)) {
6112 if (DependentFriend || IsDependentFriend(FoundTemplate))
6113 continue;
6114
6115 ClassTemplateDecl *TemplateWithDef =
6116 getTemplateDefinition(FoundTemplate);
6117 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6118 return Importer.MapImported(D, TemplateWithDef);
6119 if (!FoundByLookup)
6120 FoundByLookup = FoundTemplate;
6121 // Search in all matches because there may be multiple decl chains,
6122 // see ASTTests test ImportExistingFriendClassTemplateDef.
6123 continue;
6124 }
6125 // When importing a friend, it is possible that multiple declarations
6126 // with same name can co-exist in specific cases (if a template contains
6127 // a friend template and has a specialization). For this case the
6128 // declarations should match, except that the "template depth" is
6129 // different. No linking of previous declaration is needed in this case.
6130 // FIXME: This condition may need refinement.
6132 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6133 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6134 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6135 /*IgnoreTemplateParmDepth=*/true))
6136 continue;
6137
6138 ConflictingDecls.push_back(FoundDecl);
6139 }
6140 }
6141
6142 if (!ConflictingDecls.empty()) {
6143 ExpectedName NameOrErr = Importer.HandleNameConflict(
6144 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6145 ConflictingDecls.size());
6146 if (NameOrErr)
6147 Name = NameOrErr.get();
6148 else
6149 return NameOrErr.takeError();
6150 }
6151 }
6152
6153 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6154
6155 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6156 if (!TemplateParamsOrErr)
6157 return TemplateParamsOrErr.takeError();
6158
6159 // Create the declaration that is being templated.
6160 CXXRecordDecl *ToTemplated;
6161 if (Error Err = importInto(ToTemplated, FromTemplated))
6162 return std::move(Err);
6163
6164 // Create the class template declaration itself.
6166 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6167 *TemplateParamsOrErr, ToTemplated))
6168 return D2;
6169
6170 ToTemplated->setDescribedClassTemplate(D2);
6171
6172 D2->setAccess(D->getAccess());
6173 D2->setLexicalDeclContext(LexicalDC);
6174
6175 addDeclToContexts(D, D2);
6176 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6177
6178 if (FoundByLookup) {
6179 auto *Recent =
6180 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6181
6182 // It is possible that during the import of the class template definition
6183 // we start the import of a fwd friend decl of the very same class template
6184 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6185 // had been created earlier and by that time the lookup could not find
6186 // anything existing, so it has no previous decl. Later, (still during the
6187 // import of the fwd friend decl) we start to import the definition again
6188 // and this time the lookup finds the previous fwd friend class template.
6189 // In this case we must set up the previous decl for the templated decl.
6190 if (!ToTemplated->getPreviousDecl()) {
6191 assert(FoundByLookup->getTemplatedDecl() &&
6192 "Found decl must have its templated decl set");
6193 CXXRecordDecl *PrevTemplated =
6194 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6195 if (ToTemplated != PrevTemplated)
6196 ToTemplated->setPreviousDecl(PrevTemplated);
6197 }
6198
6199 D2->setPreviousDecl(Recent);
6200 }
6201
6202 return D2;
6203}
6204
6207 ClassTemplateDecl *ClassTemplate;
6208 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6209 return std::move(Err);
6210
6211 // Import the context of this declaration.
6212 DeclContext *DC, *LexicalDC;
6213 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6214 return std::move(Err);
6215
6216 // Import template arguments.
6218 if (Error Err =
6219 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6220 return std::move(Err);
6221 // Try to find an existing specialization with these template arguments and
6222 // template parameter list.
6223 void *InsertPos = nullptr;
6224 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6226 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6227
6228 // Import template parameters.
6229 TemplateParameterList *ToTPList = nullptr;
6230
6231 if (PartialSpec) {
6232 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6233 if (!ToTPListOrErr)
6234 return ToTPListOrErr.takeError();
6235 ToTPList = *ToTPListOrErr;
6236 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6237 *ToTPListOrErr,
6238 InsertPos);
6239 } else
6240 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6241
6242 if (PrevDecl) {
6243 if (IsStructuralMatch(D, PrevDecl)) {
6244 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6245 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6246 Importer.MapImported(D, PrevDefinition);
6247 // Import those default field initializers which have been
6248 // instantiated in the "From" context, but not in the "To" context.
6249 for (auto *FromField : D->fields()) {
6250 auto ToOrErr = import(FromField);
6251 if (!ToOrErr)
6252 return ToOrErr.takeError();
6253 }
6254
6255 // Import those methods which have been instantiated in the
6256 // "From" context, but not in the "To" context.
6257 for (CXXMethodDecl *FromM : D->methods()) {
6258 auto ToOrErr = import(FromM);
6259 if (!ToOrErr)
6260 return ToOrErr.takeError();
6261 }
6262
6263 // TODO Import instantiated default arguments.
6264 // TODO Import instantiated exception specifications.
6265 //
6266 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6267 // what else could be fused during an AST merge.
6268 return PrevDefinition;
6269 }
6270 } else { // ODR violation.
6271 // FIXME HandleNameConflict
6272 return make_error<ASTImportError>(ASTImportError::NameConflict);
6273 }
6274 }
6275
6276 // Import the location of this declaration.
6277 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6278 if (!BeginLocOrErr)
6279 return BeginLocOrErr.takeError();
6280 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6281 if (!IdLocOrErr)
6282 return IdLocOrErr.takeError();
6283
6284 // Import TemplateArgumentListInfo.
6285 TemplateArgumentListInfo ToTAInfo;
6286 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6287 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6288 return std::move(Err);
6289 }
6290
6291 // Create the specialization.
6292 ClassTemplateSpecializationDecl *D2 = nullptr;
6293 if (PartialSpec) {
6294 QualType CanonInjType;
6295 if (Error Err = importInto(
6296 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6297 return std::move(Err);
6298 CanonInjType = CanonInjType.getCanonicalType();
6299
6300 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6301 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6302 *IdLocOrErr, ToTPList, ClassTemplate,
6303 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()),
6304 CanonInjType,
6305 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6306 return D2;
6307
6308 // Update InsertPos, because preceding import calls may have invalidated
6309 // it by adding new specializations.
6310 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6311 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6312 InsertPos))
6313 // Add this partial specialization to the class template.
6314 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6316 import(PartialSpec->getInstantiatedFromMember()))
6317 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6318 else
6319 return ToInstOrErr.takeError();
6320
6321 updateLookupTableForTemplateParameters(*ToTPList);
6322 } else { // Not a partial specialization.
6323 if (GetImportedOrCreateDecl(
6324 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6325 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6326 PrevDecl))
6327 return D2;
6328
6329 // Update InsertPos, because preceding import calls may have invalidated
6330 // it by adding new specializations.
6331 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6332 // Add this specialization to the class template.
6333 ClassTemplate->AddSpecialization(D2, InsertPos);
6334 }
6335
6336 D2->setSpecializationKind(D->getSpecializationKind());
6337
6338 // Set the context of this specialization/instantiation.
6339 D2->setLexicalDeclContext(LexicalDC);
6340
6341 // Add to the DC only if it was an explicit specialization/instantiation.
6343 LexicalDC->addDeclInternal(D2);
6344 }
6345
6346 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6347 D2->setBraceRange(*BraceRangeOrErr);
6348 else
6349 return BraceRangeOrErr.takeError();
6350
6351 if (Error Err = ImportTemplateParameterLists(D, D2))
6352 return std::move(Err);
6353
6354 // Import the qualifier, if any.
6355 if (auto LocOrErr = import(D->getQualifierLoc()))
6356 D2->setQualifierInfo(*LocOrErr);
6357 else
6358 return LocOrErr.takeError();
6359
6360 if (D->getTemplateArgsAsWritten())
6361 D2->setTemplateArgsAsWritten(ToTAInfo);
6362
6363 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6364 D2->setTemplateKeywordLoc(*LocOrErr);
6365 else
6366 return LocOrErr.takeError();
6367
6368 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6369 D2->setExternKeywordLoc(*LocOrErr);
6370 else
6371 return LocOrErr.takeError();
6372
6373 if (D->getPointOfInstantiation().isValid()) {
6374 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6375 D2->setPointOfInstantiation(*POIOrErr);
6376 else
6377 return POIOrErr.takeError();
6378 }
6379
6380 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
6381
6382 if (auto P = D->getInstantiatedFrom()) {
6383 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6384 if (auto CTDorErr = import(CTD))
6385 D2->setInstantiationOf(*CTDorErr);
6386 } else {
6387 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6388 auto CTPSDOrErr = import(CTPSD);
6389 if (!CTPSDOrErr)
6390 return CTPSDOrErr.takeError();
6391 const TemplateArgumentList &DArgs = D->getTemplateInstantiationArgs();
6392 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6393 for (unsigned I = 0; I < DArgs.size(); ++I) {
6394 const TemplateArgument &DArg = DArgs[I];
6395 if (auto ArgOrErr = import(DArg))
6396 D2ArgsVec[I] = *ArgOrErr;
6397 else
6398 return ArgOrErr.takeError();
6399 }
6401 *CTPSDOrErr,
6402 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6403 }
6404 }
6405
6406 if (D->isCompleteDefinition())
6407 if (Error Err = ImportDefinition(D, D2))
6408 return std::move(Err);
6409
6410 return D2;
6411}
6412
6414 // Import the major distinguishing characteristics of this variable template.
6415 DeclContext *DC, *LexicalDC;
6416 DeclarationName Name;
6418 NamedDecl *ToD;
6419 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6420 return std::move(Err);
6421 if (ToD)
6422 return ToD;
6423
6424 // We may already have a template of the same name; try to find and match it.
6425 assert(!DC->isFunctionOrMethod() &&
6426 "Variable templates cannot be declared at function scope");
6427
6428 SmallVector<NamedDecl *, 4> ConflictingDecls;
6429 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6430 VarTemplateDecl *FoundByLookup = nullptr;
6431 for (auto *FoundDecl : FoundDecls) {
6433 continue;
6434
6435 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6436 // Use the templated decl, some linkage flags are set only there.
6437 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6438 D->getTemplatedDecl()))
6439 continue;
6440 if (IsStructuralMatch(D, FoundTemplate)) {
6441 // FIXME Check for ODR error if the two definitions have
6442 // different initializers?
6443 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6444 if (D->getDeclContext()->isRecord()) {
6445 assert(FoundTemplate->getDeclContext()->isRecord() &&
6446 "Member variable template imported as non-member, "
6447 "inconsistent imported AST?");
6448 if (FoundDef)
6449 return Importer.MapImported(D, FoundDef);
6450 if (!D->isThisDeclarationADefinition())
6451 return Importer.MapImported(D, FoundTemplate);
6452 } else {
6453 if (FoundDef && D->isThisDeclarationADefinition())
6454 return Importer.MapImported(D, FoundDef);
6455 }
6456 FoundByLookup = FoundTemplate;
6457 break;
6458 }
6459 ConflictingDecls.push_back(FoundDecl);
6460 }
6461 }
6462
6463 if (!ConflictingDecls.empty()) {
6464 ExpectedName NameOrErr = Importer.HandleNameConflict(
6465 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6466 ConflictingDecls.size());
6467 if (NameOrErr)
6468 Name = NameOrErr.get();
6469 else
6470 return NameOrErr.takeError();
6471 }
6472
6473 VarDecl *DTemplated = D->getTemplatedDecl();
6474
6475 // Import the type.
6476 // FIXME: Value not used?
6477 ExpectedType TypeOrErr = import(DTemplated->getType());
6478 if (!TypeOrErr)
6479 return TypeOrErr.takeError();
6480
6481 // Create the declaration that is being templated.
6482 VarDecl *ToTemplated;
6483 if (Error Err = importInto(ToTemplated, DTemplated))
6484 return std::move(Err);
6485
6486 // Create the variable template declaration itself.
6487 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6488 if (!TemplateParamsOrErr)
6489 return TemplateParamsOrErr.takeError();
6490
6491 VarTemplateDecl *ToVarTD;
6492 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6493 Name, *TemplateParamsOrErr, ToTemplated))
6494 return ToVarTD;
6495
6496 ToTemplated->setDescribedVarTemplate(ToVarTD);
6497
6498 ToVarTD->setAccess(D->getAccess());
6499 ToVarTD->setLexicalDeclContext(LexicalDC);
6500 LexicalDC->addDeclInternal(ToVarTD);
6501 if (DC != Importer.getToContext().getTranslationUnitDecl())
6502 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6503
6504 if (FoundByLookup) {
6505 auto *Recent =
6506 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6507 if (!ToTemplated->getPreviousDecl()) {
6508 auto *PrevTemplated =
6509 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6510 if (ToTemplated != PrevTemplated)
6511 ToTemplated->setPreviousDecl(PrevTemplated);
6512 }
6513 ToVarTD->setPreviousDecl(Recent);
6514 }
6515
6516 return ToVarTD;
6517}
6518
6521 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6522 // in an analog way (but specialized for this case).
6523
6525 auto RedeclIt = Redecls.begin();
6526 // Import the first part of the decl chain. I.e. import all previous
6527 // declarations starting from the canonical decl.
6528 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6529 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6530 if (!RedeclOrErr)
6531 return RedeclOrErr.takeError();
6532 }
6533 assert(*RedeclIt == D);
6534
6535 VarTemplateDecl *VarTemplate = nullptr;
6536 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6537 return std::move(Err);
6538
6539 // Import the context of this declaration.
6540 DeclContext *DC, *LexicalDC;
6541 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6542 return std::move(Err);
6543
6544 // Import the location of this declaration.
6545 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6546 if (!BeginLocOrErr)
6547 return BeginLocOrErr.takeError();
6548
6549 auto IdLocOrErr = import(D->getLocation());
6550 if (!IdLocOrErr)
6551 return IdLocOrErr.takeError();
6552
6553 // Import template arguments.
6555 if (Error Err =
6556 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6557 return std::move(Err);
6558
6559 // Try to find an existing specialization with these template arguments.
6560 void *InsertPos = nullptr;
6561 VarTemplateSpecializationDecl *FoundSpecialization =
6562 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6563 if (FoundSpecialization) {
6564 if (IsStructuralMatch(D, FoundSpecialization)) {
6565 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6566 if (D->getDeclContext()->isRecord()) {
6567 // In a record, it is allowed only to have one optional declaration and
6568 // one definition of the (static or constexpr) variable template.
6569 assert(
6570 FoundSpecialization->getDeclContext()->isRecord() &&
6571 "Member variable template specialization imported as non-member, "
6572 "inconsistent imported AST?");
6573 if (FoundDef)
6574 return Importer.MapImported(D, FoundDef);
6575 if (!D->isThisDeclarationADefinition())
6576 return Importer.MapImported(D, FoundSpecialization);
6577 } else {
6578 // If definition is imported and there is already one, map to it.
6579 // Otherwise create a new variable and link it to the existing.
6580 if (FoundDef && D->isThisDeclarationADefinition())
6581 return Importer.MapImported(D, FoundDef);
6582 }
6583 } else {
6584 return make_error<ASTImportError>(ASTImportError::NameConflict);
6585 }
6586 }
6587
6588 VarTemplateSpecializationDecl *D2 = nullptr;
6589
6590 TemplateArgumentListInfo ToTAInfo;
6591 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6592 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6593 return std::move(Err);
6594 }
6595
6596 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6597 // Create a new specialization.
6598 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6599 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6600 if (!ToTPListOrErr)
6601 return ToTPListOrErr.takeError();
6602
6603 PartVarSpecDecl *ToPartial;
6604 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6605 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6606 VarTemplate, QualType(), nullptr,
6607 D->getStorageClass(), TemplateArgs))
6608 return ToPartial;
6609
6610 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6611 import(FromPartial->getInstantiatedFromMember()))
6612 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6613 else
6614 return ToInstOrErr.takeError();
6615
6616 if (FromPartial->isMemberSpecialization())
6617 ToPartial->setMemberSpecialization();
6618
6619 D2 = ToPartial;
6620
6621 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6622 // to adopt template parameters.
6623 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6624 } else { // Full specialization
6625 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6626 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6627 QualType(), nullptr, D->getStorageClass(),
6628 TemplateArgs))
6629 return D2;
6630 }
6631
6632 // Update InsertPos, because preceding import calls may have invalidated
6633 // it by adding new specializations.
6634 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6635 VarTemplate->AddSpecialization(D2, InsertPos);
6636
6637 QualType T;
6638 if (Error Err = importInto(T, D->getType()))
6639 return std::move(Err);
6640 D2->setType(T);
6641
6642 auto TInfoOrErr = import(D->getTypeSourceInfo());
6643 if (!TInfoOrErr)
6644 return TInfoOrErr.takeError();
6645 D2->setTypeSourceInfo(*TInfoOrErr);
6646
6647 if (D->getPointOfInstantiation().isValid()) {
6648 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6649 D2->setPointOfInstantiation(*POIOrErr);
6650 else
6651 return POIOrErr.takeError();
6652 }
6653
6654 D2->setSpecializationKind(D->getSpecializationKind());
6655
6656 if (D->getTemplateArgsAsWritten())
6657 D2->setTemplateArgsAsWritten(ToTAInfo);
6658
6659 if (auto LocOrErr = import(D->getQualifierLoc()))
6660 D2->setQualifierInfo(*LocOrErr);
6661 else
6662 return LocOrErr.takeError();
6663
6664 if (D->isConstexpr())
6665 D2->setConstexpr(true);
6666
6667 D2->setAccess(D->getAccess());
6668
6669 if (Error Err = ImportInitializer(D, D2))
6670 return std::move(Err);
6671
6672 if (FoundSpecialization)
6673 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6674
6675 addDeclToContexts(D, D2);
6676
6677 // Import the rest of the chain. I.e. import all subsequent declarations.
6678 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6679 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6680 if (!RedeclOrErr)
6681 return RedeclOrErr.takeError();
6682 }
6683
6684 return D2;
6685}
6686
6689 DeclContext *DC, *LexicalDC;
6690 DeclarationName Name;
6692 NamedDecl *ToD;
6693
6694 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6695 return std::move(Err);
6696
6697 if (ToD)
6698 return ToD;
6699
6700 const FunctionTemplateDecl *FoundByLookup = nullptr;
6701
6702 // Try to find a function in our own ("to") context with the same name, same
6703 // type, and in the same context as the function we're importing.
6704 // FIXME Split this into a separate function.
6705 if (!LexicalDC->isFunctionOrMethod()) {
6707 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6708 for (auto *FoundDecl : FoundDecls) {
6709 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6710 continue;
6711
6712 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6713 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6714 continue;
6715 if (IsStructuralMatch(D, FoundTemplate)) {
6716 FunctionTemplateDecl *TemplateWithDef =
6717 getTemplateDefinition(FoundTemplate);
6718 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6719 return Importer.MapImported(D, TemplateWithDef);
6720
6721 FoundByLookup = FoundTemplate;
6722 break;
6723 // TODO: handle conflicting names
6724 }
6725 }
6726 }
6727 }
6728
6729 auto ParamsOrErr = import(D->getTemplateParameters());
6730 if (!ParamsOrErr)
6731 return ParamsOrErr.takeError();
6732 TemplateParameterList *Params = *ParamsOrErr;
6733
6734 FunctionDecl *TemplatedFD;
6735 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6736 return std::move(Err);
6737
6738 // At creation of the template the template parameters are "adopted"
6739 // (DeclContext is changed). After this possible change the lookup table
6740 // must be updated.
6741 // At deduction guides the DeclContext of the template parameters may be
6742 // different from what we would expect, it may be the class template, or a
6743 // probably different CXXDeductionGuideDecl. This may come from the fact that
6744 // the template parameter objects may be shared between deduction guides or
6745 // the class template, and at creation of multiple FunctionTemplateDecl
6746 // objects (for deduction guides) the same parameters are re-used. The
6747 // "adoption" happens multiple times with different parent, even recursively
6748 // for TemplateTemplateParmDecl. The same happens at import when the
6749 // FunctionTemplateDecl objects are created, but in different order.
6750 // In this way the DeclContext of these template parameters is not necessarily
6751 // the same as in the "from" context.
6753 OldParamDC.reserve(Params->size());
6754 llvm::transform(*Params, std::back_inserter(OldParamDC),
6755 [](NamedDecl *ND) { return ND->getDeclContext(); });
6756
6757 FunctionTemplateDecl *ToFunc;
6758 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6759 Params, TemplatedFD))
6760 return ToFunc;
6761
6762 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6763
6764 ToFunc->setAccess(D->getAccess());
6765 ToFunc->setLexicalDeclContext(LexicalDC);
6766 addDeclToContexts(D, ToFunc);
6767
6768 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6769 if (LT && !OldParamDC.empty()) {
6770 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6771 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6772 }
6773
6774 if (FoundByLookup) {
6775 auto *Recent =
6776 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6777 if (!TemplatedFD->getPreviousDecl()) {
6778 assert(FoundByLookup->getTemplatedDecl() &&
6779 "Found decl must have its templated decl set");
6780 auto *PrevTemplated =
6781 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6782 if (TemplatedFD != PrevTemplated)
6783 TemplatedFD->setPreviousDecl(PrevTemplated);
6784 }
6785 ToFunc->setPreviousDecl(Recent);
6786 }
6787
6788 return ToFunc;
6789}
6790
6791//----------------------------------------------------------------------------
6792// Import Statements
6793//----------------------------------------------------------------------------
6794
6796 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6797 << S->getStmtClassName();
6798 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6799}
6800
6801
6803 if (Importer.returnWithErrorInTest())
6804 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6806 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6807 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6808 // ToII is nullptr when no symbolic name is given for output operand
6809 // see ParseStmtAsm::ParseAsmOperandsOpt
6810 Names.push_back(ToII);
6811 }
6812
6813 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6814 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6815 // ToII is nullptr when no symbolic name is given for input operand
6816 // see ParseStmtAsm::ParseAsmOperandsOpt
6817 Names.push_back(ToII);
6818 }
6819
6821 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6822 if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6823 Clobbers.push_back(*ClobberOrErr);
6824 else
6825 return ClobberOrErr.takeError();
6826
6827 }
6828
6830 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6831 if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6832 Constraints.push_back(*OutputOrErr);
6833 else
6834 return OutputOrErr.takeError();
6835 }
6836
6837 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6838 if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6839 Constraints.push_back(*InputOrErr);
6840 else
6841 return InputOrErr.takeError();
6842 }
6843
6844 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6845 S->getNumLabels());
6846 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6847 return std::move(Err);
6848
6849 if (Error Err =
6850 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6851 return std::move(Err);
6852
6853 if (Error Err = ImportArrayChecked(
6854 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6855 return std::move(Err);
6856
6857 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6858 if (!AsmLocOrErr)
6859 return AsmLocOrErr.takeError();
6860 auto AsmStrOrErr = import(S->getAsmString());
6861 if (!AsmStrOrErr)
6862 return AsmStrOrErr.takeError();
6863 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6864 if (!RParenLocOrErr)
6865 return RParenLocOrErr.takeError();
6866
6867 return new (Importer.getToContext()) GCCAsmStmt(
6868 Importer.getToContext(),
6869 *AsmLocOrErr,
6870 S->isSimple(),
6871 S->isVolatile(),
6872 S->getNumOutputs(),
6873 S->getNumInputs(),
6874 Names.data(),
6875 Constraints.data(),
6876 Exprs.data(),
6877 *AsmStrOrErr,
6878 S->getNumClobbers(),
6879 Clobbers.data(),
6880 S->getNumLabels(),
6881 *RParenLocOrErr);
6882}
6883
6885
6886 Error Err = Error::success();
6887 auto ToDG = importChecked(Err, S->getDeclGroup());
6888 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6889 auto ToEndLoc = importChecked(Err, S->getEndLoc());
6890 if (Err)
6891 return std::move(Err);
6892 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6893}
6894
6896 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6897 if (!ToSemiLocOrErr)
6898 return ToSemiLocOrErr.takeError();
6899 return new (Importer.getToContext()) NullStmt(
6900 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6901}
6902
6904 SmallVector<Stmt *, 8> ToStmts(S->size());
6905
6906 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6907 return std::move(Err);
6908
6909 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6910 if (!ToLBracLocOrErr)
6911 return ToLBracLocOrErr.takeError();
6912
6913 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6914 if (!ToRBracLocOrErr)
6915 return ToRBracLocOrErr.takeError();
6916
6917 FPOptionsOverride FPO =
6918 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6919 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6920 *ToLBracLocOrErr, *ToRBracLocOrErr);
6921}
6922
6924
6925 Error Err = Error::success();
6926 auto ToLHS = importChecked(Err, S->getLHS());
6927 auto ToRHS = importChecked(Err, S->getRHS());
6928 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6929 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6930 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6931 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6932 if (Err)
6933 return std::move(Err);
6934
6935 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6936 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6937 ToStmt->setSubStmt(ToSubStmt);
6938
6939 return ToStmt;
6940}
6941
6943
6944 Error Err = Error::success();
6945 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6946 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6947 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6948 if (Err)
6949 return std::move(Err);
6950
6951 return new (Importer.getToContext()) DefaultStmt(
6952 ToDefaultLoc, ToColonLoc, ToSubStmt);
6953}
6954
6956
6957 Error Err = Error::success();
6958 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6959 auto ToLabelDecl = importChecked(Err, S->getDecl());
6960 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6961 if (Err)
6962 return std::move(Err);
6963
6964 return new (Importer.getToContext()) LabelStmt(
6965 ToIdentLoc, ToLabelDecl, ToSubStmt);
6966}
6967
6969 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6970 if (!ToAttrLocOrErr)
6971 return ToAttrLocOrErr.takeError();
6972 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6973 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6974 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6975 return std::move(Err);
6976 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6977 if (!ToSubStmtOrErr)
6978 return ToSubStmtOrErr.takeError();
6979
6981 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6982}
6983
6985
6986 Error Err = Error::success();
6987 auto ToIfLoc = importChecked(Err, S->getIfLoc());
6988 auto ToInit = importChecked(Err, S->getInit());
6989 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6990 auto ToCond = importChecked(Err, S->getCond());
6991 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
6992 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
6993 auto ToThen = importChecked(Err, S->getThen());
6994 auto ToElseLoc = importChecked(Err, S->getElseLoc());
6995 auto ToElse = importChecked(Err, S->getElse());
6996 if (Err)
6997 return std::move(Err);
6998
6999 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7000 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7001 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7002}
7003
7005
7006 Error Err = Error::success();
7007 auto ToInit = importChecked(Err, S->getInit());
7008 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7009 auto ToCond = importChecked(Err, S->getCond());
7010 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7011 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7012 auto ToBody = importChecked(Err, S->getBody());
7013 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7014 if (Err)
7015 return std::move(Err);
7016
7017 auto *ToStmt =
7018 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7019 ToCond, ToLParenLoc, ToRParenLoc);
7020 ToStmt->setBody(ToBody);
7021 ToStmt->setSwitchLoc(ToSwitchLoc);
7022
7023 // Now we have to re-chain the cases.
7024 SwitchCase *LastChainedSwitchCase = nullptr;
7025 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7026 SC = SC->getNextSwitchCase()) {
7027 Expected<SwitchCase *> ToSCOrErr = import(SC);
7028 if (!ToSCOrErr)
7029 return ToSCOrErr.takeError();
7030 if (LastChainedSwitchCase)
7031 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7032 else
7033 ToStmt->setSwitchCaseList(*ToSCOrErr);
7034 LastChainedSwitchCase = *ToSCOrErr;
7035 }
7036
7037 return ToStmt;
7038}
7039
7041
7042 Error Err = Error::success();
7043 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7044 auto ToCond = importChecked(Err, S->getCond());
7045 auto ToBody = importChecked(Err, S->getBody());
7046 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7047 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7048 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7049 if (Err)
7050 return std::move(Err);
7051
7052 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7053 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7054}
7055
7057
7058 Error Err = Error::success();
7059 auto ToBody = importChecked(Err, S->getBody());
7060 auto ToCond = importChecked(Err, S->getCond());
7061 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7062 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7063 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7064 if (Err)
7065 return std::move(Err);
7066
7067 return new (Importer.getToContext()) DoStmt(
7068 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7069}
7070
7072
7073 Error Err = Error::success();
7074 auto ToInit = importChecked(Err, S->getInit());
7075 auto ToCond = importChecked(Err, S->getCond());
7076 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7077 auto ToInc = importChecked(Err, S->getInc());
7078 auto ToBody = importChecked(Err, S->getBody());
7079 auto ToForLoc = importChecked(Err, S->getForLoc());
7080 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7081 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7082 if (Err)
7083 return std::move(Err);
7084
7085 return new (Importer.getToContext()) ForStmt(
7086 Importer.getToContext(),
7087 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7088 ToRParenLoc);
7089}
7090
7092
7093 Error Err = Error::success();
7094 auto ToLabel = importChecked(Err, S->getLabel());
7095 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7096 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7097 if (Err)
7098 return std::move(Err);
7099
7100 return new (Importer.getToContext()) GotoStmt(
7101 ToLabel, ToGotoLoc, ToLabelLoc);
7102}
7103
7105
7106 Error Err = Error::success();
7107 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7108 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7109 auto ToTarget = importChecked(Err, S->getTarget());
7110 if (Err)
7111 return std::move(Err);
7112
7113 return new (Importer.getToContext()) IndirectGotoStmt(
7114 ToGotoLoc, ToStarLoc, ToTarget);
7115}
7116
7118 ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
7119 if (!ToContinueLocOrErr)
7120 return ToContinueLocOrErr.takeError();
7121 return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
7122}
7123
7125 auto ToBreakLocOrErr = import(S->getBreakLoc());
7126 if (!ToBreakLocOrErr)
7127 return ToBreakLocOrErr.takeError();
7128 return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
7129}
7130
7132
7133 Error Err = Error::success();
7134 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7135 auto ToRetValue = importChecked(Err, S->getRetValue());
7136 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7137 if (Err)
7138 return std::move(Err);
7139
7140 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7141 ToNRVOCandidate);
7142}
7143
7145
7146 Error Err = Error::success();
7147 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7148 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7149 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7150 if (Err)
7151 return std::move(Err);
7152
7153 return new (Importer.getToContext()) CXXCatchStmt (
7154 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7155}
7156
7158 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7159 if (!ToTryLocOrErr)
7160 return ToTryLocOrErr.takeError();
7161
7162 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7163 if (!ToTryBlockOrErr)
7164 return ToTryBlockOrErr.takeError();
7165
7166 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7167 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7168 CXXCatchStmt *FromHandler = S->getHandler(HI);
7169 if (auto ToHandlerOrErr = import(FromHandler))
7170 ToHandlers[HI] = *ToHandlerOrErr;
7171 else
7172 return ToHandlerOrErr.takeError();
7173 }
7174
7175 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7176 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7177}
7178
7180
7181 Error Err = Error::success();
7182 auto ToInit = importChecked(Err, S->getInit());
7183 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7184 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7185 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7186 auto ToCond = importChecked(Err, S->getCond());
7187 auto ToInc = importChecked(Err, S->getInc());
7188 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7189 auto ToBody = importChecked(Err, S->getBody());
7190 auto ToForLoc = importChecked(Err, S->getForLoc());
7191 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7192 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7193 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7194 if (Err)
7195 return std::move(Err);
7196
7197 return new (Importer.getToContext()) CXXForRangeStmt(
7198 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7199 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7200}
7201
7204 Error Err = Error::success();
7205 auto ToElement = importChecked(Err, S->getElement());
7206 auto ToCollection = importChecked(Err, S->getCollection());
7207 auto ToBody = importChecked(Err, S->getBody());
7208 auto ToForLoc = importChecked(Err, S->getForLoc());
7209 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7210 if (Err)
7211 return std::move(Err);
7212
7213 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7214 ToCollection,
7215 ToBody,
7216 ToForLoc,
7217 ToRParenLoc);
7218}
7219
7221
7222 Error Err = Error::success();
7223 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7224 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7225 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7226 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7227 if (Err)
7228 return std::move(Err);
7229
7230 return new (Importer.getToContext()) ObjCAtCatchStmt (
7231 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7232}
7233
7235 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7236 if (!ToAtFinallyLocOrErr)
7237 return ToAtFinallyLocOrErr.takeError();
7238 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7239 if (!ToAtFinallyStmtOrErr)
7240 return ToAtFinallyStmtOrErr.takeError();
7241 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7242 *ToAtFinallyStmtOrErr);
7243}
7244
7246
7247 Error Err = Error::success();
7248 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7249 auto ToTryBody = importChecked(Err, S->getTryBody());
7250 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7251 if (Err)
7252 return std::move(Err);
7253
7254 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7255 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7256 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7257 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7258 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7259 else
7260 return ToCatchStmtOrErr.takeError();
7261 }
7262
7263 return ObjCAtTryStmt::Create(Importer.getToContext(),
7264 ToAtTryLoc, ToTryBody,
7265 ToCatchStmts.begin(), ToCatchStmts.size(),
7266 ToFinallyStmt);
7267}
7268
7271
7272 Error Err = Error::success();
7273 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7274 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7275 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7276 if (Err)
7277 return std::move(Err);
7278
7279 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7280 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7281}
7282
7284 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7285 if (!ToThrowLocOrErr)
7286 return ToThrowLocOrErr.takeError();
7287 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7288 if (!ToThrowExprOrErr)
7289 return ToThrowExprOrErr.takeError();
7290 return new (Importer.getToContext()) ObjCAtThrowStmt(
7291 *ToThrowLocOrErr, *ToThrowExprOrErr);
7292}
7293
7296 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7297 if (!ToAtLocOrErr)
7298 return ToAtLocOrErr.takeError();
7299 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7300 if (!ToSubStmtOrErr)
7301 return ToSubStmtOrErr.takeError();
7302 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7303 *ToSubStmtOrErr);
7304}
7305
7306//----------------------------------------------------------------------------
7307// Import Expressions
7308//----------------------------------------------------------------------------
7310 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7311 << E->getStmtClassName();
7312 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7313}
7314
7316 Error Err = Error::success();
7317 auto ToType = importChecked(Err, E->getType());
7318 auto BLoc = importChecked(Err, E->getBeginLoc());
7319 auto RParenLoc = importChecked(Err, E->getEndLoc());
7320 if (Err)
7321 return std::move(Err);
7322 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7323 if (!ParentContextOrErr)
7324 return ParentContextOrErr.takeError();
7325
7326 return new (Importer.getToContext())
7327 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7328 RParenLoc, *ParentContextOrErr);
7329}
7330
7332
7333 Error Err = Error::success();
7334 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7335 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7336 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7337 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7338 auto ToType = importChecked(Err, E->getType());
7339 if (Err)
7340 return std::move(Err);
7341
7342 return new (Importer.getToContext()) VAArgExpr(
7343 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7344 E->isMicrosoftABI());
7345}
7346
7348
7349 Error Err = Error::success();
7350 auto ToCond = importChecked(Err, E->getCond());
7351 auto ToLHS = importChecked(Err, E->getLHS());
7352 auto ToRHS = importChecked(Err, E->getRHS());
7353 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7354 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7355 auto ToType = importChecked(Err, E->getType());
7356 if (Err)
7357 return std::move(Err);
7358
7361
7362 // The value of CondIsTrue only matters if the value is not
7363 // condition-dependent.
7364 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7365
7366 return new (Importer.getToContext())
7367 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7368 ToRParenLoc, CondIsTrue);
7369}
7370
7372 Error Err = Error::success();
7373 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7374 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7375 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7376 auto ToType = importChecked(Err, E->getType());
7377 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7378 if (Err)
7379 return std::move(Err);
7380
7381 return new (Importer.getToContext())
7382 ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7383 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7384}
7385
7387 Error Err = Error::success();
7388 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7389 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7390 auto ToType = importChecked(Err, E->getType());
7391 const unsigned NumSubExprs = E->getNumSubExprs();
7392
7394 llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7395 ToSubExprs.resize(NumSubExprs);
7396
7397 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7398 return std::move(Err);
7399
7400 return new (Importer.getToContext()) ShuffleVectorExpr(
7401 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7402}
7403
7405 ExpectedType TypeOrErr = import(E->getType());
7406 if (!TypeOrErr)
7407 return TypeOrErr.takeError();
7408
7409 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7410 if (!BeginLocOrErr)
7411 return BeginLocOrErr.takeError();
7412
7413 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7414}
7415
7418 Error Err = Error::success();
7419 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7420 Expr *ToControllingExpr = nullptr;
7421 TypeSourceInfo *ToControllingType = nullptr;
7422 if (E->isExprPredicate())
7423 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7424 else
7425 ToControllingType = importChecked(Err, E->getControllingType());
7426 assert((ToControllingExpr || ToControllingType) &&
7427 "Either the controlling expr or type must be nonnull");
7428 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7429 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7430 if (Err)
7431 return std::move(Err);
7432
7433 ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos());
7434 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7435 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7436 return std::move(Err);
7437
7438 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7439 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7440 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7441 return std::move(Err);
7442
7443 const ASTContext &ToCtx = Importer.getToContext();
7444 if (E->isResultDependent()) {
7445 if (ToControllingExpr) {
7447 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7448 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7450 }
7452 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7453 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7455 }
7456
7457 if (ToControllingExpr) {
7459 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7460 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7461 E->containsUnexpandedParameterPack(), E->getResultIndex());
7462 }
7464 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7465 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7466 E->containsUnexpandedParameterPack(), E->getResultIndex());
7467}
7468
7470
7471 Error Err = Error::success();
7472 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7473 auto ToType = importChecked(Err, E->getType());
7474 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7475 if (Err)
7476 return std::move(Err);
7477
7478 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7479 E->getIdentKind(), E->isTransparent(),
7480 ToFunctionName);
7481}
7482
7484
7485 Error Err = Error::success();
7486 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7487 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7488 auto ToDecl = importChecked(Err, E->getDecl());
7489 auto ToLocation = importChecked(Err, E->getLocation());
7490 auto ToType = importChecked(Err, E->getType());
7491 if (Err)
7492 return std::move(Err);
7493
7494 NamedDecl *ToFoundD = nullptr;
7495 if (E->getDecl() != E->getFoundDecl()) {
7496 auto FoundDOrErr = import(E->getFoundDecl());
7497 if (!FoundDOrErr)
7498 return FoundDOrErr.takeError();
7499 ToFoundD = *FoundDOrErr;
7500 }
7501
7502 TemplateArgumentListInfo ToTAInfo;
7503 TemplateArgumentListInfo *ToResInfo = nullptr;
7504 if (E->hasExplicitTemplateArgs()) {
7505 if (Error Err =
7506 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
7507 E->template_arguments(), ToTAInfo))
7508 return std::move(Err);
7509 ToResInfo = &ToTAInfo;
7510 }
7511
7512 auto *ToE = DeclRefExpr::Create(
7513 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7514 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7515 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7516 if (E->hadMultipleCandidates())
7517 ToE->setHadMultipleCandidates(true);
7518 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7519 return ToE;
7520}
7521
7523 ExpectedType TypeOrErr = import(E->getType());
7524 if (!TypeOrErr)
7525 return TypeOrErr.takeError();
7526
7527 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7528}
7529
7531 ExpectedExpr ToInitOrErr = import(E->getInit());
7532 if (!ToInitOrErr)
7533 return ToInitOrErr.takeError();
7534
7535 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7536 if (!ToEqualOrColonLocOrErr)
7537 return ToEqualOrColonLocOrErr.takeError();
7538
7539 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7540 // List elements from the second, the first is Init itself
7541 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7542 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7543 ToIndexExprs[I - 1] = *ToArgOrErr;
7544 else
7545 return ToArgOrErr.takeError();
7546 }
7547
7548 SmallVector<Designator, 4> ToDesignators(E->size());
7549 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7550 return std::move(Err);
7551
7553 Importer.getToContext(), ToDesignators,
7554 ToIndexExprs, *ToEqualOrColonLocOrErr,
7555 E->usesGNUSyntax(), *ToInitOrErr);
7556}
7557
7560 ExpectedType ToTypeOrErr = import(E->getType());
7561 if (!ToTypeOrErr)
7562 return ToTypeOrErr.takeError();
7563
7564 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7565 if (!ToLocationOrErr)
7566 return ToLocationOrErr.takeError();
7567
7568 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7569 *ToTypeOrErr, *ToLocationOrErr);
7570}
7571
7573 ExpectedType ToTypeOrErr = import(E->getType());
7574 if (!ToTypeOrErr)
7575 return ToTypeOrErr.takeError();
7576
7577 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7578 if (!ToLocationOrErr)
7579 return ToLocationOrErr.takeError();
7580
7582 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7583}
7584
7585
7587 ExpectedType ToTypeOrErr = import(E->getType());
7588 if (!ToTypeOrErr)
7589 return ToTypeOrErr.takeError();
7590
7591 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7592 if (!ToLocationOrErr)
7593 return ToLocationOrErr.takeError();
7594
7596 Importer.getToContext(), E->getValue(), E->isExact(),
7597 *ToTypeOrErr, *ToLocationOrErr);
7598}
7599
7601 auto ToTypeOrErr = import(E->getType());
7602 if (!ToTypeOrErr)
7603 return ToTypeOrErr.takeError();
7604
7605 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7606 if (!ToSubExprOrErr)
7607 return ToSubExprOrErr.takeError();
7608
7609 return new (Importer.getToContext()) ImaginaryLiteral(
7610 *ToSubExprOrErr, *ToTypeOrErr);
7611}
7612
7614 auto ToTypeOrErr = import(E->getType());
7615 if (!ToTypeOrErr)
7616 return ToTypeOrErr.takeError();
7617
7618 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7619 if (!ToLocationOrErr)
7620 return ToLocationOrErr.takeError();
7621
7622 return new (Importer.getToContext()) FixedPointLiteral(
7623 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7624 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7625}
7626
7628 ExpectedType ToTypeOrErr = import(E->getType());
7629 if (!ToTypeOrErr)
7630 return ToTypeOrErr.takeError();
7631
7632 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7633 if (!ToLocationOrErr)
7634 return ToLocationOrErr.takeError();
7635
7636 return new (Importer.getToContext()) CharacterLiteral(
7637 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7638}
7639
7641 ExpectedType ToTypeOrErr = import(E->getType());
7642 if (!ToTypeOrErr)
7643 return ToTypeOrErr.takeError();
7644
7645 SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated());
7646 if (Error Err = ImportArrayChecked(
7647 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7648 return std::move(Err);
7649
7650 return StringLiteral::Create(
7651 Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7652 *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7653}
7654
7656
7657 Error Err = Error::success();
7658 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7659 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7660 auto ToType = importChecked(Err, E->getType());
7661 auto ToInitializer = importChecked(Err, E->getInitializer());
7662 if (Err)
7663 return std::move(Err);
7664
7665 return new (Importer.getToContext()) CompoundLiteralExpr(
7666 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7667 ToInitializer, E->isFileScope());
7668}
7669
7671
7672 Error Err = Error::success();
7673 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7674 auto ToType = importChecked(Err, E->getType());
7675 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7676 if (Err)
7677 return std::move(Err);
7678
7679 SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
7680 if (Error Err = ImportArrayChecked(
7681 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7682 ToExprs.begin()))
7683 return std::move(Err);
7684
7685 return new (Importer.getToContext()) AtomicExpr(
7686
7687 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7688}
7689
7691 Error Err = Error::success();
7692 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7693 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7694 auto ToLabel = importChecked(Err, E->getLabel());
7695 auto ToType = importChecked(Err, E->getType());
7696 if (Err)
7697 return std::move(Err);
7698
7699 return new (Importer.getToContext()) AddrLabelExpr(
7700 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7701}
7703 Error Err = Error::success();
7704 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7705 auto ToResult = importChecked(Err, E->getAPValueResult());
7706 if (Err)
7707 return std::move(Err);
7708
7709 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7710}
7712 Error Err = Error::success();
7713 auto ToLParen = importChecked(Err, E->getLParen());
7714 auto ToRParen = importChecked(Err, E->getRParen());
7715 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7716 if (Err)
7717 return std::move(Err);
7718
7719 return new (Importer.getToContext())
7720 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7721}
7722
7724 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7725 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7726 return std::move(Err);
7727
7728 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7729 if (!ToLParenLocOrErr)
7730 return ToLParenLocOrErr.takeError();
7731
7732 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7733 if (!ToRParenLocOrErr)
7734 return ToRParenLocOrErr.takeError();
7735
7736 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7737 ToExprs, *ToRParenLocOrErr);
7738}
7739
7741 Error Err = Error::success();
7742 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7743 auto ToType = importChecked(Err, E->getType());
7744 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7745 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7746 if (Err)
7747 return std::move(Err);
7748
7749 return new (Importer.getToContext())
7750 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7751 E->getTemplateDepth());
7752}
7753
7755 Error Err = Error::success();
7756 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7757 auto ToType = importChecked(Err, E->getType());
7758 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7759 if (Err)
7760 return std::move(Err);
7761
7762 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7763 E->hasStoredFPFeatures());
7764 UO->setType(ToType);
7765 UO->setSubExpr(ToSubExpr);
7766 UO->setOpcode(E->getOpcode());
7767 UO->setOperatorLoc(ToOperatorLoc);
7768 UO->setCanOverflow(E->canOverflow());
7769 if (E->hasStoredFPFeatures())
7770 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7771
7772 return UO;
7773}
7774
7776
7778 Error Err = Error::success();
7779 auto ToType = importChecked(Err, E->getType());
7780 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7781 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7782 if (Err)
7783 return std::move(Err);
7784
7785 if (E->isArgumentType()) {
7786 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7787 import(E->getArgumentTypeInfo());
7788 if (!ToArgumentTypeInfoOrErr)
7789 return ToArgumentTypeInfoOrErr.takeError();
7790
7791 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7792 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7793 ToRParenLoc);
7794 }
7795
7796 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7797 if (!ToArgumentExprOrErr)
7798 return ToArgumentExprOrErr.takeError();
7799
7800 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7801 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7802}
7803
7805 Error Err = Error::success();
7806 auto ToLHS = importChecked(Err, E->getLHS());
7807 auto ToRHS = importChecked(Err, E->getRHS());
7808 auto ToType = importChecked(Err, E->getType());
7809 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7810 if (Err)
7811 return std::move(Err);
7812
7814 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7815 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7816 E->getFPFeatures());
7817}
7818
7820 Error Err = Error::success();
7821 auto ToCond = importChecked(Err, E->getCond());
7822 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7823 auto ToLHS = importChecked(Err, E->getLHS());
7824 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7825 auto ToRHS = importChecked(Err, E->getRHS());
7826 auto ToType = importChecked(Err, E->getType());
7827 if (Err)
7828 return std::move(Err);
7829
7830 return new (Importer.getToContext()) ConditionalOperator(
7831 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7832 E->getValueKind(), E->getObjectKind());
7833}
7834
7837 Error Err = Error::success();
7838 auto ToCommon = importChecked(Err, E->getCommon());
7839 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7840 auto ToCond = importChecked(Err, E->getCond());
7841 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7842 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7843 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7844 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7845 auto ToType = importChecked(Err, E->getType());
7846 if (Err)
7847 return std::move(Err);
7848
7849 return new (Importer.getToContext()) BinaryConditionalOperator(
7850 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7851 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7852 E->getObjectKind());
7853}
7854
7857 Error Err = Error::success();
7858 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7859 if (Err)
7860 return std::move(Err);
7861
7862 return new (Importer.getToContext())
7863 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7864}
7865
7867 Error Err = Error::success();
7868 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7869 auto ToQueriedTypeSourceInfo =
7870 importChecked(Err, E->getQueriedTypeSourceInfo());
7871 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7872 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7873 auto ToType = importChecked(Err, E->getType());
7874 if (Err)
7875 return std::move(Err);
7876
7877 return new (Importer.getToContext()) ArrayTypeTraitExpr(
7878 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7879 ToDimensionExpression, ToEndLoc, ToType);
7880}
7881
7883 Error Err = Error::success();
7884 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7885 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7886 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7887 auto ToType = importChecked(Err, E->getType());
7888 if (Err)
7889 return std::move(Err);
7890
7891 return new (Importer.getToContext()) ExpressionTraitExpr(
7892 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7893 ToEndLoc, ToType);
7894}
7895
7897 Error Err = Error::success();
7898 auto ToLocation = importChecked(Err, E->getLocation());
7899 auto ToType = importChecked(Err, E->getType());
7900 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7901 if (Err)
7902 return std::move(Err);
7903
7904 return new (Importer.getToContext()) OpaqueValueExpr(
7905 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7906}
7907
7909 Error Err = Error::success();
7910 auto ToLHS = importChecked(Err, E->getLHS());
7911 auto ToRHS = importChecked(Err, E->getRHS());
7912 auto ToType = importChecked(Err, E->getType());
7913 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7914 if (Err)
7915 return std::move(Err);
7916
7917 return new (Importer.getToContext()) ArraySubscriptExpr(
7918 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7919 ToRBracketLoc);
7920}
7921
7924 Error Err = Error::success();
7925 auto ToLHS = importChecked(Err, E->getLHS());
7926 auto ToRHS = importChecked(Err, E->getRHS());
7927 auto ToType = importChecked(Err, E->getType());
7928 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7929 auto ToComputationResultType =
7930 importChecked(Err, E->getComputationResultType());
7931 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7932 if (Err)
7933 return std::move(Err);
7934
7936 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7937 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7938 E->getFPFeatures(),
7939 ToComputationLHSType, ToComputationResultType);
7940}
7941
7945 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7946 if (auto SpecOrErr = import(*I))
7947 Path.push_back(*SpecOrErr);
7948 else
7949 return SpecOrErr.takeError();
7950 }
7951 return Path;
7952}
7953
7955 ExpectedType ToTypeOrErr = import(E->getType());
7956 if (!ToTypeOrErr)
7957 return ToTypeOrErr.takeError();
7958
7959 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7960 if (!ToSubExprOrErr)
7961 return ToSubExprOrErr.takeError();
7962
7963 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7964 if (!ToBasePathOrErr)
7965 return ToBasePathOrErr.takeError();
7966
7968 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7969 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7970}
7971
7973 Error Err = Error::success();
7974 auto ToType = importChecked(Err, E->getType());
7975 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7976 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7977 if (Err)
7978 return std::move(Err);
7979
7980 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7981 if (!ToBasePathOrErr)
7982 return ToBasePathOrErr.takeError();
7983 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7984
7985 switch (E->getStmtClass()) {
7986 case Stmt::CStyleCastExprClass: {
7987 auto *CCE = cast<CStyleCastExpr>(E);
7988 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7989 if (!ToLParenLocOrErr)
7990 return ToLParenLocOrErr.takeError();
7991 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
7992 if (!ToRParenLocOrErr)
7993 return ToRParenLocOrErr.takeError();
7995 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
7996 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
7997 *ToLParenLocOrErr, *ToRParenLocOrErr);
7998 }
7999
8000 case Stmt::CXXFunctionalCastExprClass: {
8001 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8002 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8003 if (!ToLParenLocOrErr)
8004 return ToLParenLocOrErr.takeError();
8005 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8006 if (!ToRParenLocOrErr)
8007 return ToRParenLocOrErr.takeError();
8009 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8010 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8011 *ToLParenLocOrErr, *ToRParenLocOrErr);
8012 }
8013
8014 case Stmt::ObjCBridgedCastExprClass: {
8015 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8016 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8017 if (!ToLParenLocOrErr)
8018 return ToLParenLocOrErr.takeError();
8019 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8020 if (!ToBridgeKeywordLocOrErr)
8021 return ToBridgeKeywordLocOrErr.takeError();
8022 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8023 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8024 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8025 }
8026 case Stmt::BuiltinBitCastExprClass: {
8027 auto *BBC = cast<BuiltinBitCastExpr>(E);
8028 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8029 if (!ToKWLocOrErr)
8030 return ToKWLocOrErr.takeError();
8031 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8032 if (!ToRParenLocOrErr)
8033 return ToRParenLocOrErr.takeError();
8034 return new (Importer.getToContext()) BuiltinBitCastExpr(
8035 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8036 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8037 }
8038 default:
8039 llvm_unreachable("Cast expression of unsupported type!");
8040 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8041 }
8042}
8043
8046 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8047 const OffsetOfNode &FromNode = E->getComponent(I);
8048
8049 SourceLocation ToBeginLoc, ToEndLoc;
8050
8051 if (FromNode.getKind() != OffsetOfNode::Base) {
8052 Error Err = Error::success();
8053 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8054 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8055 if (Err)
8056 return std::move(Err);
8057 }
8058
8059 switch (FromNode.getKind()) {
8061 ToNodes.push_back(
8062 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8063 break;
8064 case OffsetOfNode::Base: {
8065 auto ToBSOrErr = import(FromNode.getBase());
8066 if (!ToBSOrErr)
8067 return ToBSOrErr.takeError();
8068 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8069 break;
8070 }
8071 case OffsetOfNode::Field: {
8072 auto ToFieldOrErr = import(FromNode.getField());
8073 if (!ToFieldOrErr)
8074 return ToFieldOrErr.takeError();
8075 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8076 break;
8077 }
8079 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8080 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8081 break;
8082 }
8083 }
8084 }
8085
8086 SmallVector<Expr *, 4> ToExprs(E->getNumExpressions());
8087 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8088 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8089 if (!ToIndexExprOrErr)
8090 return ToIndexExprOrErr.takeError();
8091 ToExprs[I] = *ToIndexExprOrErr;
8092 }
8093
8094 Error Err = Error::success();
8095 auto ToType = importChecked(Err, E->getType());
8096 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8097 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8098 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8099 if (Err)
8100 return std::move(Err);
8101
8102 return OffsetOfExpr::Create(
8103 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8104 ToExprs, ToRParenLoc);
8105}
8106
8108 Error Err = Error::success();
8109 auto ToType = importChecked(Err, E->getType());
8110 auto ToOperand = importChecked(Err, E->getOperand());
8111 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8112 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8113 if (Err)
8114 return std::move(Err);
8115
8116 CanThrowResult ToCanThrow;
8117 if (E->isValueDependent())
8118 ToCanThrow = CT_Dependent;
8119 else
8120 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8121
8122 return new (Importer.getToContext()) CXXNoexceptExpr(
8123 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8124}
8125
8127 Error Err = Error::success();
8128 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8129 auto ToType = importChecked(Err, E->getType());
8130 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8131 if (Err)
8132 return std::move(Err);
8133
8134 return new (Importer.getToContext()) CXXThrowExpr(
8135 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8136}
8137
8139 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8140 if (!ToUsedLocOrErr)
8141 return ToUsedLocOrErr.takeError();
8142
8143 auto ToParamOrErr = import(E->getParam());
8144 if (!ToParamOrErr)
8145 return ToParamOrErr.takeError();
8146
8147 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8148 if (!UsedContextOrErr)
8149 return UsedContextOrErr.takeError();
8150
8151 // Import the default arg if it was not imported yet.
8152 // This is needed because it can happen that during the import of the
8153 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8154 // encountered here. The default argument for a ParmVarDecl is set in the
8155 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8156 // see VisitParmVarDecl).
8157 ParmVarDecl *ToParam = *ToParamOrErr;
8158 if (!ToParam->getDefaultArg()) {
8159 std::optional<ParmVarDecl *> FromParam =
8160 Importer.getImportedFromDecl(ToParam);
8161 assert(FromParam && "ParmVarDecl was not imported?");
8162
8163 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8164 return std::move(Err);
8165 }
8166 Expr *RewrittenInit = nullptr;
8167 if (E->hasRewrittenInit()) {
8168 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8169 if (!ExprOrErr)
8170 return ExprOrErr.takeError();
8171 RewrittenInit = ExprOrErr.get();
8172 }
8173 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8174 *ToParamOrErr, RewrittenInit,
8175 *UsedContextOrErr);
8176}
8177
8180 Error Err = Error::success();
8181 auto ToType = importChecked(Err, E->getType());
8182 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8183 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8184 if (Err)
8185 return std::move(Err);
8186
8187 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8188 ToType, ToTypeSourceInfo, ToRParenLoc);
8189}
8190
8193 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8194 if (!ToSubExprOrErr)
8195 return ToSubExprOrErr.takeError();
8196
8197 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8198 if (!ToDtorOrErr)
8199 return ToDtorOrErr.takeError();
8200
8201 ASTContext &ToCtx = Importer.getToContext();
8202 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8203 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8204}
8205
8207
8209 Error Err = Error::success();
8210 auto ToConstructor = importChecked(Err, E->getConstructor());
8211 auto ToType = importChecked(Err, E->getType());
8212 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8213 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8214 if (Err)
8215 return std::move(Err);
8216
8217 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8218 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8219 return std::move(Err);
8220
8222 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8223 ToParenOrBraceRange, E->hadMultipleCandidates(),
8224 E->isListInitialization(), E->isStdInitListInitialization(),
8225 E->requiresZeroInitialization());
8226}
8227
8230 DeclContext *DC, *LexicalDC;
8231 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8232 return std::move(Err);
8233
8234 Error Err = Error::success();
8235 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8236 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8237 if (Err)
8238 return std::move(Err);
8239 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8240
8242 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8243 D->getManglingNumber()))
8244 return To;
8245
8246 To->setLexicalDeclContext(LexicalDC);
8247 LexicalDC->addDeclInternal(To);
8248 return To;
8249}
8250
8253 Error Err = Error::success();
8254 auto ToType = importChecked(Err, E->getType());
8255 Expr *ToTemporaryExpr = importChecked(
8256 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8257 auto ToMaterializedDecl =
8258 importChecked(Err, E->getLifetimeExtendedTemporaryDecl());
8259 if (Err)
8260 return std::move(Err);
8261
8262 if (!ToTemporaryExpr)
8263 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8264
8265 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8266 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8267 ToMaterializedDecl);
8268
8269 return ToMTE;
8270}
8271
8273 Error Err = Error::success();
8274 auto ToType = importChecked(Err, E->getType());
8275 auto ToPattern = importChecked(Err, E->getPattern());
8276 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8277 if (Err)
8278 return std::move(Err);
8279
8280 return new (Importer.getToContext()) PackExpansionExpr(
8281 ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8282}
8283
8285 Error Err = Error::success();
8286 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8287 auto ToPack = importChecked(Err, E->getPack());
8288 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8289 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8290 if (Err)
8291 return std::move(Err);
8292
8293 std::optional<unsigned> Length;
8294 if (!E->isValueDependent())
8295 Length = E->getPackLength();
8296
8297 SmallVector<TemplateArgument, 8> ToPartialArguments;
8298 if (E->isPartiallySubstituted()) {
8299 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8300 ToPartialArguments))
8301 return std::move(Err);
8302 }
8303
8305 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8306 Length, ToPartialArguments);
8307}
8308
8309
8311 Error Err = Error::success();
8312 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8313 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8314 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8315 auto ToArraySize = importChecked(Err, E->getArraySize());
8316 auto ToInitializer = importChecked(Err, E->getInitializer());
8317 auto ToType = importChecked(Err, E->getType());
8318 auto ToAllocatedTypeSourceInfo =
8319 importChecked(Err, E->getAllocatedTypeSourceInfo());
8320 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8321 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8322 if (Err)
8323 return std::move(Err);
8324
8325 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8326 if (Error Err =
8327 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8328 return std::move(Err);
8329
8330 return CXXNewExpr::Create(
8331 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8332 ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8333 ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8334 ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8335 ToDirectInitRange);
8336}
8337
8339 Error Err = Error::success();
8340 auto ToType = importChecked(Err, E->getType());
8341 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8342 auto ToArgument = importChecked(Err, E->getArgument());
8343 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8344 if (Err)
8345 return std::move(Err);
8346
8347 return new (Importer.getToContext()) CXXDeleteExpr(
8348 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8349 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8350 ToBeginLoc);
8351}
8352
8354 Error Err = Error::success();
8355 auto ToType = importChecked(Err, E->getType());
8356 auto ToLocation = importChecked(Err, E->getLocation());
8357 auto ToConstructor = importChecked(Err, E->getConstructor());
8358 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8359 if (Err)
8360 return std::move(Err);
8361
8362 SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
8363 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8364 return std::move(Err);
8365
8367 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8368 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8369 E->isListInitialization(), E->isStdInitListInitialization(),
8370 E->requiresZeroInitialization(), E->getConstructionKind(),
8371 ToParenOrBraceRange);
8372 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
8373 return ToE;
8374}
8375
8377 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8378 if (!ToSubExprOrErr)
8379 return ToSubExprOrErr.takeError();
8380
8381 SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects());
8382 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8383 return std::move(Err);
8384
8386 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8387 ToObjects);
8388}
8389
8391 Error Err = Error::success();
8392 auto ToCallee = importChecked(Err, E->getCallee());
8393 auto ToType = importChecked(Err, E->getType());
8394 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8395 if (Err)
8396 return std::move(Err);
8397
8398 SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
8399 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8400 return std::move(Err);
8401
8402 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8403 ToType, E->getValueKind(), ToRParenLoc,
8404 E->getFPFeatures());
8405}
8406
8408 ExpectedType ToTypeOrErr = import(E->getType());
8409 if (!ToTypeOrErr)
8410 return ToTypeOrErr.takeError();
8411
8412 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8413 if (!ToLocationOrErr)
8414 return ToLocationOrErr.takeError();
8415
8416 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8417 *ToTypeOrErr, E->isImplicit());
8418}
8419
8421 ExpectedType ToTypeOrErr = import(E->getType());
8422 if (!ToTypeOrErr)
8423 return ToTypeOrErr.takeError();
8424
8425 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8426 if (!ToLocationOrErr)
8427 return ToLocationOrErr.takeError();
8428
8429 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8430 *ToTypeOrErr, *ToLocationOrErr);
8431}
8432
8434 Error Err = Error::success();
8435 auto ToBase = importChecked(Err, E->getBase());
8436 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8437 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8438 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8439 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8440 auto ToType = importChecked(Err, E->getType());
8441 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8442 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8443 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8444 if (Err)
8445 return std::move(Err);
8446
8447 DeclAccessPair ToFoundDecl =
8448 DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess());
8449
8450 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8451
8452 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8453 if (E->hasExplicitTemplateArgs()) {
8454 if (Error Err =
8455 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8456 E->template_arguments(), ToTAInfo))
8457 return std::move(Err);
8458 ResInfo = &ToTAInfo;
8459 }
8460
8461 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8462 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8463 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8464 ResInfo, ToType, E->getValueKind(),
8465 E->getObjectKind(), E->isNonOdrUse());
8466}
8467
8470 Error Err = Error::success();
8471 auto ToBase = importChecked(Err, E->getBase());
8472 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8473 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8474 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8475 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8476 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8477 if (Err)
8478 return std::move(Err);
8479
8481 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8482 const IdentifierInfo *ToII = Importer.Import(FromII);
8483 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8484 if (!ToDestroyedTypeLocOrErr)
8485 return ToDestroyedTypeLocOrErr.takeError();
8486 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8487 } else {
8488 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8489 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8490 else
8491 return ToTIOrErr.takeError();
8492 }
8493
8494 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8495 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8496 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8497}
8498
8501 Error Err = Error::success();
8502 auto ToType = importChecked(Err, E->getType());
8503 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8504 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8505 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8506 auto ToFirstQualifierFoundInScope =
8507 importChecked(Err, E->getFirstQualifierFoundInScope());
8508 if (Err)
8509 return std::move(Err);
8510
8511 Expr *ToBase = nullptr;
8512 if (!E->isImplicitAccess()) {
8513 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8514 ToBase = *ToBaseOrErr;
8515 else
8516 return ToBaseOrErr.takeError();
8517 }
8518
8519 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8520
8521 if (E->hasExplicitTemplateArgs()) {
8522 if (Error Err =
8523 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8524 E->template_arguments(), ToTAInfo))
8525 return std::move(Err);
8526 ResInfo = &ToTAInfo;
8527 }
8528 auto ToMember = importChecked(Err, E->getMember());
8529 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8530 if (Err)
8531 return std::move(Err);
8532 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8533
8534 // Import additional name location/type info.
8535 if (Error Err =
8536 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8537 return std::move(Err);
8538
8540 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8541 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8542 ToMemberNameInfo, ResInfo);
8543}
8544
8547 Error Err = Error::success();
8548 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8549 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8550 auto ToDeclName = importChecked(Err, E->getDeclName());
8551 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8552 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8553 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8554 if (Err)
8555 return std::move(Err);
8556
8557 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8558 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8559 return std::move(Err);
8560
8561 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8562 TemplateArgumentListInfo *ResInfo = nullptr;
8563 if (E->hasExplicitTemplateArgs()) {
8564 if (Error Err =
8565 ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
8566 return std::move(Err);
8567 ResInfo = &ToTAInfo;
8568 }
8569
8571 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8572 ToNameInfo, ResInfo);
8573}
8574
8577 Error Err = Error::success();
8578 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8579 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8580 auto ToType = importChecked(Err, E->getType());
8581 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8582 if (Err)
8583 return std::move(Err);
8584
8585 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8586 if (Error Err =
8587 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8588 return std::move(Err);
8589
8591 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8592 llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8593}
8594
8597 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8598 if (!ToNamingClassOrErr)
8599 return ToNamingClassOrErr.takeError();
8600
8601 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8602 if (!ToQualifierLocOrErr)
8603 return ToQualifierLocOrErr.takeError();
8604
8605 Error Err = Error::success();
8606 auto ToName = importChecked(Err, E->getName());
8607 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8608 if (Err)
8609 return std::move(Err);
8610 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8611
8612 // Import additional name location/type info.
8613 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8614 return std::move(Err);
8615
8616 UnresolvedSet<8> ToDecls;
8617 for (auto *D : E->decls())
8618 if (auto ToDOrErr = import(D))
8619 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8620 else
8621 return ToDOrErr.takeError();
8622
8623 if (E->hasExplicitTemplateArgs()) {
8624 TemplateArgumentListInfo ToTAInfo;
8625 if (Error Err = ImportTemplateArgumentListInfo(
8626 E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
8627 ToTAInfo))
8628 return std::move(Err);
8629
8630 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8631 if (!ToTemplateKeywordLocOrErr)
8632 return ToTemplateKeywordLocOrErr.takeError();
8633
8634 const bool KnownDependent =
8635 (E->getDependence() & ExprDependence::TypeValue) ==
8636 ExprDependence::TypeValue;
8638 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8639 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8640 ToDecls.begin(), ToDecls.end(), KnownDependent,
8641 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8642 }
8643
8645 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8646 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8647 /*KnownDependent=*/E->isTypeDependent(),
8648 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8649}
8650
8653 Error Err = Error::success();
8654 auto ToType = importChecked(Err, E->getType());
8655 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8656 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8657 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8658 auto ToName = importChecked(Err, E->getName());
8659 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8660 if (Err)
8661 return std::move(Err);
8662
8663 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8664 // Import additional name location/type info.
8665 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8666 return std::move(Err);
8667
8668 UnresolvedSet<8> ToDecls;
8669 for (Decl *D : E->decls())
8670 if (auto ToDOrErr = import(D))
8671 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8672 else
8673 return ToDOrErr.takeError();
8674
8675 TemplateArgumentListInfo ToTAInfo;
8676 TemplateArgumentListInfo *ResInfo = nullptr;
8677 if (E->hasExplicitTemplateArgs()) {
8678 TemplateArgumentListInfo FromTAInfo;
8679 E->copyTemplateArgumentsInto(FromTAInfo);
8680 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8681 return std::move(Err);
8682 ResInfo = &ToTAInfo;
8683 }
8684
8685 Expr *ToBase = nullptr;
8686 if (!E->isImplicitAccess()) {
8687 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8688 ToBase = *ToBaseOrErr;
8689 else
8690 return ToBaseOrErr.takeError();
8691 }
8692
8694 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8695 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8696 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8697}
8698
8700 Error Err = Error::success();
8701 auto ToCallee = importChecked(Err, E->getCallee());
8702 auto ToType = importChecked(Err, E->getType());
8703 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8704 if (Err)
8705 return std::move(Err);
8706
8707 unsigned NumArgs = E->getNumArgs();
8708 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8709 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8710 return std::move(Err);
8711
8712 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8714 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8715 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8716 OCE->getADLCallKind());
8717 }
8718
8719 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8720 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8721 /*MinNumArgs=*/0, E->getADLCallKind());
8722}
8723
8725 CXXRecordDecl *FromClass = E->getLambdaClass();
8726 auto ToClassOrErr = import(FromClass);
8727 if (!ToClassOrErr)
8728 return ToClassOrErr.takeError();
8729 CXXRecordDecl *ToClass = *ToClassOrErr;
8730
8731 auto ToCallOpOrErr = import(E->getCallOperator());
8732 if (!ToCallOpOrErr)
8733 return ToCallOpOrErr.takeError();
8734
8735 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8736 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8737 return std::move(Err);
8738
8739 Error Err = Error::success();
8740 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8741 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8742 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8743 if (Err)
8744 return std::move(Err);
8745
8746 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8747 E->getCaptureDefault(), ToCaptureDefaultLoc,
8748 E->hasExplicitParameters(),
8749 E->hasExplicitResultType(), ToCaptureInits,
8750 ToEndLoc, E->containsUnexpandedParameterPack());
8751}
8752
8753
8755 Error Err = Error::success();
8756 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8757 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8758 auto ToType = importChecked(Err, E->getType());
8759 if (Err)
8760 return std::move(Err);
8761
8762 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8763 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8764 return std::move(Err);
8765
8766 ASTContext &ToCtx = Importer.getToContext();
8767 InitListExpr *To = new (ToCtx) InitListExpr(
8768 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8769 To->setType(ToType);
8770
8771 if (E->hasArrayFiller()) {
8772 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8773 To->setArrayFiller(*ToFillerOrErr);
8774 else
8775 return ToFillerOrErr.takeError();
8776 }
8777
8778 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8779 if (auto ToFDOrErr = import(FromFD))
8780 To->setInitializedFieldInUnion(*ToFDOrErr);
8781 else
8782 return ToFDOrErr.takeError();
8783 }
8784
8785 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8786 if (auto ToSyntFormOrErr = import(SyntForm))
8787 To->setSyntacticForm(*ToSyntFormOrErr);
8788 else
8789 return ToSyntFormOrErr.takeError();
8790 }
8791
8792 // Copy InitListExprBitfields, which are not handled in the ctor of
8793 // InitListExpr.
8794 To->sawArrayRangeDesignator(E->hadArrayRangeDesignator());
8795
8796 return To;
8797}
8798
8801 ExpectedType ToTypeOrErr = import(E->getType());
8802 if (!ToTypeOrErr)
8803 return ToTypeOrErr.takeError();
8804
8805 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8806 if (!ToSubExprOrErr)
8807 return ToSubExprOrErr.takeError();
8808
8809 return new (Importer.getToContext()) CXXStdInitializerListExpr(
8810 *ToTypeOrErr, *ToSubExprOrErr);
8811}
8812
8815 Error Err = Error::success();
8816 auto ToLocation = importChecked(Err, E->getLocation());
8817 auto ToType = importChecked(Err, E->getType());
8818 auto ToConstructor = importChecked(Err, E->getConstructor());
8819 if (Err)
8820 return std::move(Err);
8821
8822 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8823 ToLocation, ToType, ToConstructor, E->constructsVBase(),
8824 E->inheritedFromVBase());
8825}
8826
8828 Error Err = Error::success();
8829 auto ToType = importChecked(Err, E->getType());
8830 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8831 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8832 if (Err)
8833 return std::move(Err);
8834
8835 return new (Importer.getToContext()) ArrayInitLoopExpr(
8836 ToType, ToCommonExpr, ToSubExpr);
8837}
8838
8840 ExpectedType ToTypeOrErr = import(E->getType());
8841 if (!ToTypeOrErr)
8842 return ToTypeOrErr.takeError();
8843 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8844}
8845
8847 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8848 if (!ToBeginLocOrErr)
8849 return ToBeginLocOrErr.takeError();
8850
8851 auto ToFieldOrErr = import(E->getField());
8852 if (!ToFieldOrErr)
8853 return ToFieldOrErr.takeError();
8854
8855 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8856 if (!UsedContextOrErr)
8857 return UsedContextOrErr.takeError();
8858
8859 FieldDecl *ToField = *ToFieldOrErr;
8860 assert(ToField->hasInClassInitializer() &&
8861 "Field should have in-class initializer if there is a default init "
8862 "expression that uses it.");
8863 if (!ToField->getInClassInitializer()) {
8864 // The in-class initializer may be not yet set in "To" AST even if the
8865 // field is already there. This must be set here to make construction of
8866 // CXXDefaultInitExpr work.
8867 auto ToInClassInitializerOrErr =
8868 import(E->getField()->getInClassInitializer());
8869 if (!ToInClassInitializerOrErr)
8870 return ToInClassInitializerOrErr.takeError();
8871 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8872 }
8873
8874 Expr *RewrittenInit = nullptr;
8875 if (E->hasRewrittenInit()) {
8876 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8877 if (!ExprOrErr)
8878 return ExprOrErr.takeError();
8879 RewrittenInit = ExprOrErr.get();
8880 }
8881
8882 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8883 ToField, *UsedContextOrErr, RewrittenInit);
8884}
8885
8887 Error Err = Error::success();
8888 auto ToType = importChecked(Err, E->getType());
8889 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8890 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8891 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8892 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8893 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8894 if (Err)
8895 return std::move(Err);
8896
8898 CastKind CK = E->getCastKind();
8899 auto ToBasePathOrErr = ImportCastPath(E);
8900 if (!ToBasePathOrErr)
8901 return ToBasePathOrErr.takeError();
8902
8903 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8905 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8906 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8907 ToAngleBrackets);
8908 } else if (isa<CXXDynamicCastExpr>(E)) {
8910 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8911 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8912 } else if (isa<CXXReinterpretCastExpr>(E)) {
8914 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8915 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8916 } else if (isa<CXXConstCastExpr>(E)) {
8918 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8919 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8920 } else {
8921 llvm_unreachable("Unknown cast type");
8922 return make_error<ASTImportError>();
8923 }
8924}
8925
8928 Error Err = Error::success();
8929 auto ToType = importChecked(Err, E->getType());
8930 auto ToExprLoc = importChecked(Err, E->getExprLoc());
8931 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8932 auto ToReplacement = importChecked(Err, E->getReplacement());
8933 if (Err)
8934 return std::move(Err);
8935
8936 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8937 ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8938 E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8939}
8940
8942 Error Err = Error::success();
8943 auto ToType = importChecked(Err, E->getType());
8944 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8945 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8946 if (Err)
8947 return std::move(Err);
8948
8949 SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs());
8950 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8951 return std::move(Err);
8952
8953 // According to Sema::BuildTypeTrait(), if E is value-dependent,
8954 // Value is always false.
8955 bool ToValue = (E->isValueDependent() ? false : E->getValue());
8956
8957 return TypeTraitExpr::Create(
8958 Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8959 ToEndLoc, ToValue);
8960}
8961
8963 ExpectedType ToTypeOrErr = import(E->getType());
8964 if (!ToTypeOrErr)
8965 return ToTypeOrErr.takeError();
8966
8967 auto ToSourceRangeOrErr = import(E->getSourceRange());
8968 if (!ToSourceRangeOrErr)
8969 return ToSourceRangeOrErr.takeError();
8970
8971 if (E->isTypeOperand()) {
8972 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8973 return new (Importer.getToContext()) CXXTypeidExpr(
8974 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8975 else
8976 return ToTSIOrErr.takeError();
8977 }
8978
8979 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8980 if (!ToExprOperandOrErr)
8981 return ToExprOperandOrErr.takeError();
8982
8983 return new (Importer.getToContext()) CXXTypeidExpr(
8984 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8985}
8986
8988 Error Err = Error::success();
8989
8990 QualType ToType = importChecked(Err, E->getType());
8991 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
8992 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
8993 Expr *ToLHS = importChecked(Err, E->getLHS());
8994 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8995 Expr *ToRHS = importChecked(Err, E->getRHS());
8996 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
8997
8998 if (Err)
8999 return std::move(Err);
9000
9001 return new (Importer.getToContext())
9002 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9003 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9004}
9005
9007 CXXMethodDecl *FromMethod) {
9008 Error ImportErrors = Error::success();
9009 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9010 if (auto ImportedOrErr = import(FromOverriddenMethod))
9011 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
9012 (*ImportedOrErr)->getCanonicalDecl()));
9013 else
9014 ImportErrors =
9015 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9016 }
9017 return ImportErrors;
9018}
9019
9021 ASTContext &FromContext, FileManager &FromFileManager,
9022 bool MinimalImport,
9023 std::shared_ptr<ASTImporterSharedState> SharedState)
9024 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9025 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9026 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9027
9028 // Create a default state without the lookup table: LLDB case.
9029 if (!SharedState) {
9030 this->SharedState = std::make_shared<ASTImporterSharedState>();
9031 }
9032
9033 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9034 ToContext.getTranslationUnitDecl();
9035}
9036
9037ASTImporter::~ASTImporter() = default;
9038
9039std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
9040 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9041 "Try to get field index for non-field.");
9042
9043 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9044 if (!Owner)
9045 return std::nullopt;
9046
9047 unsigned Index = 0;
9048 for (const auto *D : Owner->decls()) {
9049 if (D == F)
9050 return Index;
9051
9052 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
9053 ++Index;
9054 }
9055
9056 llvm_unreachable("Field was not found in its parent context.");
9057
9058 return std::nullopt;
9059}
9060
9062ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9063 // We search in the redecl context because of transparent contexts.
9064 // E.g. a simple C language enum is a transparent context:
9065 // enum E { A, B };
9066 // Now if we had a global variable in the TU
9067 // int A;
9068 // then the enum constant 'A' and the variable 'A' violates ODR.
9069 // We can diagnose this only if we search in the redecl context.
9070 DeclContext *ReDC = DC->getRedeclContext();
9071 if (SharedState->getLookupTable()) {
9072 if (ReDC->isNamespace()) {
9073 // Namespaces can be reopened.
9074 // Lookup table does not handle this, we must search here in all linked
9075 // namespaces.
9076 FoundDeclsTy Result;
9077 SmallVector<Decl *, 2> NSChain =
9078 getCanonicalForwardRedeclChain<NamespaceDecl>(
9079 dyn_cast<NamespaceDecl>(ReDC));
9080 for (auto *D : NSChain) {
9082 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9083 Name);
9085 }
9086 return Result;
9087 } else {
9089 SharedState->getLookupTable()->lookup(ReDC, Name);
9090 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9091 }
9092 } else {
9093 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9094 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9095 // We must search by the slow case of localUncachedLookup because that is
9096 // working even if there is no LookupPtr for the DC. We could use
9097 // DC::buildLookup() to create the LookupPtr, but that would load external
9098 // decls again, we must avoid that case.
9099 // Also, even if we had the LookupPtr, we must find Decls which are not
9100 // in the LookupPtr, so we need the slow case.
9101 // These cases are handled in ASTImporterLookupTable, but we cannot use
9102 // that with LLDB since that traverses through the AST which initiates the
9103 // load of external decls again via DC::decls(). And again, we must avoid
9104 // loading external decls during the import.
9105 if (Result.empty())
9106 ReDC->localUncachedLookup(Name, Result);
9107 return Result;
9108 }
9109}
9110
9111void ASTImporter::AddToLookupTable(Decl *ToD) {
9112 SharedState->addDeclToLookup(ToD);
9113}
9114
9116 // Import the decl using ASTNodeImporter.
9117 ASTNodeImporter Importer(*this);
9118 return Importer.Visit(FromD);
9119}
9120
9122 MapImported(FromD, ToD);
9123}
9124
9127 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9128 if (Expected<Expr *> R = Import(CLE))
9129 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9130 }
9131
9132 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9133 // ASTNodeImporter.
9134 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9135}
9136
9138 if (!FromT)
9139 return FromT;
9140
9141 // Check whether we've already imported this type.
9142 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9143 ImportedTypes.find(FromT);
9144 if (Pos != ImportedTypes.end())
9145 return Pos->second;
9146
9147 // Import the type.
9148 ASTNodeImporter Importer(*this);
9149 ExpectedType ToTOrErr = Importer.Visit(FromT);
9150 if (!ToTOrErr)
9151 return ToTOrErr.takeError();
9152
9153 // Record the imported type.
9154 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9155
9156 return ToTOrErr->getTypePtr();
9157}
9158
9160 if (FromT.isNull())
9161 return QualType{};
9162
9163 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9164 if (!ToTyOrErr)
9165 return ToTyOrErr.takeError();
9166
9167 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9168}
9169
9171 if (!FromTSI)
9172 return FromTSI;
9173
9174 // FIXME: For now we just create a "trivial" type source info based
9175 // on the type and a single location. Implement a real version of this.
9176 ExpectedType TOrErr = Import(FromTSI->getType());
9177 if (!TOrErr)
9178 return TOrErr.takeError();
9179 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9180 if (!BeginLocOrErr)
9181 return BeginLocOrErr.takeError();
9182
9183 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9184}
9185
9186namespace {
9187// To use this object, it should be created before the new attribute is created,
9188// and destructed after it is created. The construction already performs the
9189// import of the data.
9190template <typename T> struct AttrArgImporter {
9191 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9192 AttrArgImporter(AttrArgImporter<T> &&) = default;
9193 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9194 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9195
9196 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9197 : To(I.importChecked(Err, From)) {}
9198
9199 const T &value() { return To; }
9200
9201private:
9202 T To;
9203};
9204
9205// To use this object, it should be created before the new attribute is created,
9206// and destructed after it is created. The construction already performs the
9207// import of the data. The array data is accessible in a pointer form, this form
9208// is used by the attribute classes. This object should be created once for the
9209// array data to be imported (the array size is not imported, just copied).
9210template <typename T> struct AttrArgArrayImporter {
9211 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9212 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9213 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9214 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9215
9216 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9217 const llvm::iterator_range<T *> &From,
9218 unsigned ArraySize) {
9219 if (Err)
9220 return;
9221 To.reserve(ArraySize);
9222 Err = I.ImportContainerChecked(From, To);
9223 }
9224
9225 T *value() { return To.data(); }
9226
9227private:
9229};
9230
9231class AttrImporter {
9232 Error Err{Error::success()};
9233 Attr *ToAttr = nullptr;
9234 ASTImporter &Importer;
9235 ASTNodeImporter NImporter;
9236
9237public:
9238 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9239
9240 // Useful for accessing the imported attribute.
9241 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9242 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9243
9244 // Create an "importer" for an attribute parameter.
9245 // Result of the 'value()' of that object is to be passed to the function
9246 // 'importAttr', in the order that is expected by the attribute class.
9247 template <class T> AttrArgImporter<T> importArg(const T &From) {
9248 return AttrArgImporter<T>(NImporter, Err, From);
9249 }
9250
9251 // Create an "importer" for an attribute parameter that has array type.
9252 // Result of the 'value()' of that object is to be passed to the function
9253 // 'importAttr', then the size of the array as next argument.
9254 template <typename T>
9255 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9256 unsigned ArraySize) {
9257 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9258 }
9259
9260 // Create an attribute object with the specified arguments.
9261 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9262 // should be values that are passed to the 'Create' function of the attribute.
9263 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9264 // used here.) As much data is copied or imported from the old attribute
9265 // as possible. The passed arguments should be already imported.
9266 // If an import error happens, the internal error is set to it, and any
9267 // further import attempt is ignored.
9268 template <typename T, typename... Arg>
9269 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9270 static_assert(std::is_base_of<Attr, T>::value,
9271 "T should be subclass of Attr.");
9272 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9273
9274 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9275 const IdentifierInfo *ToScopeName =
9276 Importer.Import(FromAttr->getScopeName());
9277 SourceRange ToAttrRange =
9278 NImporter.importChecked(Err, FromAttr->getRange());
9279 SourceLocation ToScopeLoc =
9280 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9281
9282 if (Err)
9283 return;
9284
9285 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9286 FromAttr->getParsedKind(), FromAttr->getForm());
9287 // The "SemanticSpelling" is not needed to be passed to the constructor.
9288 // That value is recalculated from the SpellingListIndex if needed.
9289 ToAttr = T::Create(Importer.getToContext(),
9290 std::forward<Arg>(ImportedArg)..., ToI);
9291
9292 ToAttr->setImplicit(FromAttr->isImplicit());
9293 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9294 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9295 ToInheritableAttr->setInherited(FromAttr->isInherited());
9296 }
9297
9298 // Create a clone of the 'FromAttr' and import its source range only.
9299 // This causes objects with invalid references to be created if the 'FromAttr'
9300 // contains other data that should be imported.
9301 void cloneAttr(const Attr *FromAttr) {
9302 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9303
9304 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9305 if (Err)
9306 return;
9307
9308 ToAttr = FromAttr->clone(Importer.getToContext());
9309 ToAttr->setRange(ToRange);
9310 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9311 }
9312
9313 // Get the result of the previous import attempt (can be used only once).
9314 llvm::Expected<Attr *> getResult() && {
9315 if (Err)
9316 return std::move(Err);
9317 assert(ToAttr && "Attribute should be created.");
9318 return ToAttr;
9319 }
9320};
9321} // namespace
9322
9324 AttrImporter AI(*this);
9325
9326 // FIXME: Is there some kind of AttrVisitor to use here?
9327 switch (FromAttr->getKind()) {
9328 case attr::Aligned: {
9329 auto *From = cast<AlignedAttr>(FromAttr);
9330 if (From->isAlignmentExpr())
9331 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9332 else
9333 AI.importAttr(From, false,
9334 AI.importArg(From->getAlignmentType()).value());
9335 break;
9336 }
9337
9338 case attr::AlignValue: {
9339 auto *From = cast<AlignValueAttr>(FromAttr);
9340 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9341 break;
9342 }
9343
9344 case attr::Format: {
9345 const auto *From = cast<FormatAttr>(FromAttr);
9346 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9347 From->getFirstArg());
9348 break;
9349 }
9350
9351 case attr::EnableIf: {
9352 const auto *From = cast<EnableIfAttr>(FromAttr);
9353 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9354 From->getMessage());
9355 break;
9356 }
9357
9358 case attr::AssertCapability: {
9359 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9360 AI.importAttr(From,
9361 AI.importArrayArg(From->args(), From->args_size()).value(),
9362 From->args_size());
9363 break;
9364 }
9365 case attr::AcquireCapability: {
9366 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9367 AI.importAttr(From,
9368 AI.importArrayArg(From->args(), From->args_size()).value(),
9369 From->args_size());
9370 break;
9371 }
9372 case attr::TryAcquireCapability: {
9373 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9374 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9375 AI.importArrayArg(From->args(), From->args_size()).value(),
9376 From->args_size());
9377 break;
9378 }
9379 case attr::ReleaseCapability: {
9380 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9381 AI.importAttr(From,
9382 AI.importArrayArg(From->args(), From->args_size()).value(),
9383 From->args_size());
9384 break;
9385 }
9386 case attr::RequiresCapability: {
9387 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9388 AI.importAttr(From,
9389 AI.importArrayArg(From->args(), From->args_size()).value(),
9390 From->args_size());
9391 break;
9392 }
9393 case attr::GuardedBy: {
9394 const auto *From = cast<GuardedByAttr>(FromAttr);
9395 AI.importAttr(From, AI.importArg(From->getArg()).value());
9396 break;
9397 }
9398 case attr::PtGuardedBy: {
9399 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9400 AI.importAttr(From, AI.importArg(From->getArg()).value());
9401 break;
9402 }
9403 case attr::AcquiredAfter: {
9404 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9405 AI.importAttr(From,
9406 AI.importArrayArg(From->args(), From->args_size()).value(),
9407 From->args_size());
9408 break;
9409 }
9410 case attr::AcquiredBefore: {
9411 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9412 AI.importAttr(From,
9413 AI.importArrayArg(From->args(), From->args_size()).value(),
9414 From->args_size());
9415 break;
9416 }
9417 case attr::AssertExclusiveLock: {
9418 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9419 AI.importAttr(From,
9420 AI.importArrayArg(From->args(), From->args_size()).value(),
9421 From->args_size());
9422 break;
9423 }
9424 case attr::AssertSharedLock: {
9425 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9426 AI.importAttr(From,
9427 AI.importArrayArg(From->args(), From->args_size()).value(),
9428 From->args_size());
9429 break;
9430 }
9431 case attr::ExclusiveTrylockFunction: {
9432 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9433 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9434 AI.importArrayArg(From->args(), From->args_size()).value(),
9435 From->args_size());
9436 break;
9437 }
9438 case attr::SharedTrylockFunction: {
9439 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9440 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9441 AI.importArrayArg(From->args(), From->args_size()).value(),
9442 From->args_size());
9443 break;
9444 }
9445 case attr::LockReturned: {
9446 const auto *From = cast<LockReturnedAttr>(FromAttr);
9447 AI.importAttr(From, AI.importArg(From->getArg()).value());
9448 break;
9449 }
9450 case attr::LocksExcluded: {
9451 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9452 AI.importAttr(From,
9453 AI.importArrayArg(From->args(), From->args_size()).value(),
9454 From->args_size());
9455 break;
9456 }
9457 default: {
9458 // The default branch works for attributes that have no arguments to import.
9459 // FIXME: Handle every attribute type that has arguments of type to import
9460 // (most often Expr* or Decl* or type) in the switch above.
9461 AI.cloneAttr(FromAttr);
9462 break;
9463 }
9464 }
9465
9466 return std::move(AI).getResult();
9467}
9468
9470 return ImportedDecls.lookup(FromD);
9471}
9472
9474 auto FromDPos = ImportedFromDecls.find(ToD);
9475 if (FromDPos == ImportedFromDecls.end())
9476 return nullptr;
9477 return FromDPos->second->getTranslationUnitDecl();
9478}
9479
9481 if (!FromD)
9482 return nullptr;
9483
9484 // Push FromD to the stack, and remove that when we return.
9485 ImportPath.push(FromD);
9486 auto ImportPathBuilder =
9487 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9488
9489 // Check whether there was a previous failed import.
9490 // If yes return the existing error.
9491 if (auto Error = getImportDeclErrorIfAny(FromD))
9492 return make_error<ASTImportError>(*Error);
9493
9494 // Check whether we've already imported this declaration.
9495 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9496 if (ToD) {
9497 // Already imported (possibly from another TU) and with an error.
9498 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9499 setImportDeclError(FromD, *Error);
9500 return make_error<ASTImportError>(*Error);
9501 }
9502
9503 // If FromD has some updated flags after last import, apply it.
9504 updateFlags(FromD, ToD);
9505 // If we encounter a cycle during an import then we save the relevant part
9506 // of the import path associated to the Decl.
9507 if (ImportPath.hasCycleAtBack())
9508 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9509 return ToD;
9510 }
9511
9512 // Import the declaration.
9513 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9514 if (!ToDOrErr) {
9515 // Failed to import.
9516
9517 auto Pos = ImportedDecls.find(FromD);
9518 if (Pos != ImportedDecls.end()) {
9519 // Import failed after the object was created.
9520 // Remove all references to it.
9521 auto *ToD = Pos->second;
9522 ImportedDecls.erase(Pos);
9523
9524 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9525 // (e.g. with namespaces) that several decls from the 'from' context are
9526 // mapped to the same decl in the 'to' context. If we removed entries
9527 // from the LookupTable here then we may end up removing them multiple
9528 // times.
9529
9530 // The Lookuptable contains decls only which are in the 'to' context.
9531 // Remove from the Lookuptable only if it is *imported* into the 'to'
9532 // context (and do not remove it if it was added during the initial
9533 // traverse of the 'to' context).
9534 auto PosF = ImportedFromDecls.find(ToD);
9535 if (PosF != ImportedFromDecls.end()) {
9536 // In the case of TypedefNameDecl we create the Decl first and only
9537 // then we import and set its DeclContext. So, the DC might not be set
9538 // when we reach here.
9539 if (ToD->getDeclContext())
9540 SharedState->removeDeclFromLookup(ToD);
9541 ImportedFromDecls.erase(PosF);
9542 }
9543
9544 // FIXME: AST may contain remaining references to the failed object.
9545 // However, the ImportDeclErrors in the shared state contains all the
9546 // failed objects together with their error.
9547 }
9548
9549 // Error encountered for the first time.
9550 // After takeError the error is not usable any more in ToDOrErr.
9551 // Get a copy of the error object (any more simple solution for this?).
9552 ASTImportError ErrOut;
9553 handleAllErrors(ToDOrErr.takeError(),
9554 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9555 setImportDeclError(FromD, ErrOut);
9556 // Set the error for the mapped to Decl, which is in the "to" context.
9557 if (Pos != ImportedDecls.end())
9558 SharedState->setImportDeclError(Pos->second, ErrOut);
9559
9560 // Set the error for all nodes which have been created before we
9561 // recognized the error.
9562 for (const auto &Path : SavedImportPaths[FromD]) {
9563 // The import path contains import-dependency nodes first.
9564 // Save the node that was imported as dependency of the current node.
9565 Decl *PrevFromDi = FromD;
9566 for (Decl *FromDi : Path) {
9567 // Begin and end of the path equals 'FromD', skip it.
9568 if (FromDi == FromD)
9569 continue;
9570 // We should not set import error on a node and all following nodes in
9571 // the path if child import errors are ignored.
9572 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9573 PrevFromDi))
9574 break;
9575 PrevFromDi = FromDi;
9576 setImportDeclError(FromDi, ErrOut);
9577 //FIXME Should we remove these Decls from ImportedDecls?
9578 // Set the error for the mapped to Decl, which is in the "to" context.
9579 auto Ii = ImportedDecls.find(FromDi);
9580 if (Ii != ImportedDecls.end())
9581 SharedState->setImportDeclError(Ii->second, ErrOut);
9582 // FIXME Should we remove these Decls from the LookupTable,
9583 // and from ImportedFromDecls?
9584 }
9585 }
9586 SavedImportPaths.erase(FromD);
9587
9588 // Do not return ToDOrErr, error was taken out of it.
9589 return make_error<ASTImportError>(ErrOut);
9590 }
9591
9592 ToD = *ToDOrErr;
9593
9594 // FIXME: Handle the "already imported with error" case. We can get here
9595 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9596 // previously failed create was requested).
9597 // Later GetImportedOrCreateDecl can be updated to return the error.
9598 if (!ToD) {
9599 auto Err = getImportDeclErrorIfAny(FromD);
9600 assert(Err);
9601 return make_error<ASTImportError>(*Err);
9602 }
9603
9604 // We could import from the current TU without error. But previously we
9605 // already had imported a Decl as `ToD` from another TU (with another
9606 // ASTImporter object) and with an error.
9607 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9608 setImportDeclError(FromD, *Error);
9609 return make_error<ASTImportError>(*Error);
9610 }
9611 // Make sure that ImportImpl registered the imported decl.
9612 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9613
9614 if (FromD->hasAttrs())
9615 for (const Attr *FromAttr : FromD->getAttrs()) {
9616 auto ToAttrOrErr = Import(FromAttr);
9617 if (ToAttrOrErr)
9618 ToD->addAttr(*ToAttrOrErr);
9619 else
9620 return ToAttrOrErr.takeError();
9621 }
9622
9623 // Notify subclasses.
9624 Imported(FromD, ToD);
9625
9626 updateFlags(FromD, ToD);
9627 SavedImportPaths.erase(FromD);
9628 return ToDOrErr;
9629}
9630
9633 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9634}
9635
9637 if (!FromDC)
9638 return FromDC;
9639
9640 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9641 if (!ToDCOrErr)
9642 return ToDCOrErr.takeError();
9643 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9644
9645 // When we're using a record/enum/Objective-C class/protocol as a context, we
9646 // need it to have a definition.
9647 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9648 auto *FromRecord = cast<RecordDecl>(FromDC);
9649 if (ToRecord->isCompleteDefinition())
9650 return ToDC;
9651
9652 // If FromRecord is not defined we need to force it to be.
9653 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9654 // it will start the definition but we never finish it.
9655 // If there are base classes they won't be imported and we will
9656 // be missing anything that we inherit from those bases.
9657 if (FromRecord->getASTContext().getExternalSource() &&
9658 !FromRecord->isCompleteDefinition())
9659 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9660
9661 if (FromRecord->isCompleteDefinition())
9662 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9663 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9664 return std::move(Err);
9665 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9666 auto *FromEnum = cast<EnumDecl>(FromDC);
9667 if (ToEnum->isCompleteDefinition()) {
9668 // Do nothing.
9669 } else if (FromEnum->isCompleteDefinition()) {
9670 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9671 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9672 return std::move(Err);
9673 } else {
9674 CompleteDecl(ToEnum);
9675 }
9676 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9677 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9678 if (ToClass->getDefinition()) {
9679 // Do nothing.
9680 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9681 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9682 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9683 return std::move(Err);
9684 } else {
9685 CompleteDecl(ToClass);
9686 }
9687 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9688 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9689 if (ToProto->getDefinition()) {
9690 // Do nothing.
9691 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9692 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9693 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9694 return std::move(Err);
9695 } else {
9696 CompleteDecl(ToProto);
9697 }
9698 }
9699
9700 return ToDC;
9701}
9702
9704 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9705 return cast_or_null<Expr>(*ToSOrErr);
9706 else
9707 return ToSOrErr.takeError();
9708}
9709
9711 if (!FromS)
9712 return nullptr;
9713
9714 // Check whether we've already imported this statement.
9715 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9716 if (Pos != ImportedStmts.end())
9717 return Pos->second;
9718
9719 // Import the statement.
9720 ASTNodeImporter Importer(*this);
9721 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9722 if (!ToSOrErr)
9723 return ToSOrErr;
9724
9725 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9726 auto *FromE = cast<Expr>(FromS);
9727 // Copy ExprBitfields, which may not be handled in Expr subclasses
9728 // constructors.
9729 ToE->setValueKind(FromE->getValueKind());
9730 ToE->setObjectKind(FromE->getObjectKind());
9731 ToE->setDependence(FromE->getDependence());
9732 }
9733
9734 // Record the imported statement object.
9735 ImportedStmts[FromS] = *ToSOrErr;
9736 return ToSOrErr;
9737}
9738
9741 if (!FromNNS)
9742 return nullptr;
9743
9744 NestedNameSpecifier *Prefix = nullptr;
9745 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9746 return std::move(Err);
9747
9748 switch (FromNNS->getKind()) {
9750 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9751 return NestedNameSpecifier::Create(ToContext, Prefix,
9752 Import(FromNNS->getAsIdentifier()));
9753
9755 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9756 return NestedNameSpecifier::Create(ToContext, Prefix,
9757 cast<NamespaceDecl>(*NSOrErr));
9758 } else
9759 return NSOrErr.takeError();
9760
9762 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9763 return NestedNameSpecifier::Create(ToContext, Prefix,
9764 cast<NamespaceAliasDecl>(*NSADOrErr));
9765 else
9766 return NSADOrErr.takeError();
9767
9769 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9770
9772 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9773 return NestedNameSpecifier::SuperSpecifier(ToContext,
9774 cast<CXXRecordDecl>(*RDOrErr));
9775 else
9776 return RDOrErr.takeError();
9777
9780 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9781 bool TSTemplate =
9783 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9784 *TyOrErr);
9785 } else {
9786 return TyOrErr.takeError();
9787 }
9788 }
9789
9790 llvm_unreachable("Invalid nested name specifier kind");
9791}
9792
9795 // Copied from NestedNameSpecifier mostly.
9797 NestedNameSpecifierLoc NNS = FromNNS;
9798
9799 // Push each of the nested-name-specifiers's onto a stack for
9800 // serialization in reverse order.
9801 while (NNS) {
9802 NestedNames.push_back(NNS);
9803 NNS = NNS.getPrefix();
9804 }
9805
9807
9808 while (!NestedNames.empty()) {
9809 NNS = NestedNames.pop_back_val();
9810 NestedNameSpecifier *Spec = nullptr;
9811 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9812 return std::move(Err);
9813
9815
9816 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9817 if (Kind != NestedNameSpecifier::Super) {
9818 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9819 return std::move(Err);
9820
9821 if (Kind != NestedNameSpecifier::Global)
9822 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9823 return std::move(Err);
9824 }
9825
9826 switch (Kind) {
9828 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9829 ToLocalEndLoc);
9830 break;
9831
9833 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9834 ToLocalEndLoc);
9835 break;
9836
9838 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9839 ToLocalBeginLoc, ToLocalEndLoc);
9840 break;
9841
9844 SourceLocation ToTLoc;
9845 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9846 return std::move(Err);
9848 QualType(Spec->getAsType(), 0), ToTLoc);
9850 // ToLocalBeginLoc is here the location of the 'template' keyword.
9851 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9852 ToLocalEndLoc);
9853 else
9854 // No location for 'template' keyword here.
9855 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9856 ToLocalEndLoc);
9857 break;
9858 }
9859
9861 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9862 break;
9863
9865 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9866 if (!ToSourceRangeOrErr)
9867 return ToSourceRangeOrErr.takeError();
9868
9869 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9870 ToSourceRangeOrErr->getBegin(),
9871 ToSourceRangeOrErr->getEnd());
9872 }
9873 }
9874 }
9875
9876 return Builder.getWithLocInContext(getToContext());
9877}
9878
9880 switch (From.getKind()) {
9882 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9883 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9884 else
9885 return ToTemplateOrErr.takeError();
9886
9889 UnresolvedSet<2> ToTemplates;
9890 for (auto *I : *FromStorage) {
9891 if (auto ToOrErr = Import(I))
9892 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9893 else
9894 return ToOrErr.takeError();
9895 }
9896 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9897 ToTemplates.end());
9898 }
9899
9902 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9903 if (!DeclNameOrErr)
9904 return DeclNameOrErr.takeError();
9905 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9906 }
9907
9910 auto QualifierOrErr = Import(QTN->getQualifier());
9911 if (!QualifierOrErr)
9912 return QualifierOrErr.takeError();
9913 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9914 if (!TNOrErr)
9915 return TNOrErr.takeError();
9916 return ToContext.getQualifiedTemplateName(
9917 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9918 }
9919
9922 auto QualifierOrErr = Import(DTN->getQualifier());
9923 if (!QualifierOrErr)
9924 return QualifierOrErr.takeError();
9925
9926 if (DTN->isIdentifier()) {
9927 return ToContext.getDependentTemplateName(*QualifierOrErr,
9928 Import(DTN->getIdentifier()));
9929 }
9930
9931 return ToContext.getDependentTemplateName(*QualifierOrErr,
9932 DTN->getOperator());
9933 }
9934
9938 auto ReplacementOrErr = Import(Subst->getReplacement());
9939 if (!ReplacementOrErr)
9940 return ReplacementOrErr.takeError();
9941
9942 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9943 if (!AssociatedDeclOrErr)
9944 return AssociatedDeclOrErr.takeError();
9945
9946 return ToContext.getSubstTemplateTemplateParm(
9947 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9948 Subst->getPackIndex());
9949 }
9950
9954 ASTNodeImporter Importer(*this);
9955 auto ArgPackOrErr =
9956 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9957 if (!ArgPackOrErr)
9958 return ArgPackOrErr.takeError();
9959
9960 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9961 if (!AssociatedDeclOrErr)
9962 return AssociatedDeclOrErr.takeError();
9963
9964 return ToContext.getSubstTemplateTemplateParmPack(
9965 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9966 SubstPack->getFinal());
9967 }
9969 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9970 if (!UsingOrError)
9971 return UsingOrError.takeError();
9972 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9973 }
9975 llvm_unreachable("Unexpected DeducedTemplate");
9976 }
9977
9978 llvm_unreachable("Invalid template name kind");
9979}
9980
9982 if (FromLoc.isInvalid())
9983 return SourceLocation{};
9984
9985 SourceManager &FromSM = FromContext.getSourceManager();
9986 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9987
9988 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9989 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9990 if (!ToFileIDOrErr)
9991 return ToFileIDOrErr.takeError();
9992 SourceManager &ToSM = ToContext.getSourceManager();
9993 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9994}
9995
9997 SourceLocation ToBegin, ToEnd;
9998 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9999 return std::move(Err);
10000 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10001 return std::move(Err);
10002
10003 return SourceRange(ToBegin, ToEnd);
10004}
10005
10007 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10008 if (Pos != ImportedFileIDs.end())
10009 return Pos->second;
10010
10011 SourceManager &FromSM = FromContext.getSourceManager();
10012 SourceManager &ToSM = ToContext.getSourceManager();
10013 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10014
10015 // Map the FromID to the "to" source manager.
10016 FileID ToID;
10017 if (FromSLoc.isExpansion()) {
10018 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10019 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10020 if (!ToSpLoc)
10021 return ToSpLoc.takeError();
10022 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10023 if (!ToExLocS)
10024 return ToExLocS.takeError();
10025 unsigned ExLength = FromSM.getFileIDSize(FromID);
10026 SourceLocation MLoc;
10027 if (FromEx.isMacroArgExpansion()) {
10028 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10029 } else {
10030 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10031 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10032 FromEx.isExpansionTokenRange());
10033 else
10034 return ToExLocE.takeError();
10035 }
10036 ToID = ToSM.getFileID(MLoc);
10037 } else {
10038 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10039
10040 if (!IsBuiltin && !Cache->BufferOverridden) {
10041 // Include location of this file.
10042 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10043 if (!ToIncludeLoc)
10044 return ToIncludeLoc.takeError();
10045
10046 // Every FileID that is not the main FileID needs to have a valid include
10047 // location so that the include chain points to the main FileID. When
10048 // importing the main FileID (which has no include location), we need to
10049 // create a fake include location in the main file to keep this property
10050 // intact.
10051 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10052 if (FromID == FromSM.getMainFileID())
10053 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10054
10055 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10056 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10057 // the disk again
10058 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10059 // than mmap the files several times.
10060 auto Entry =
10061 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10062 // FIXME: The filename may be a virtual name that does probably not
10063 // point to a valid file and we get no Entry here. In this case try with
10064 // the memory buffer below.
10065 if (Entry)
10066 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10067 FromSLoc.getFile().getFileCharacteristic());
10068 }
10069 }
10070
10071 if (ToID.isInvalid() || IsBuiltin) {
10072 // FIXME: We want to re-use the existing MemoryBuffer!
10073 std::optional<llvm::MemoryBufferRef> FromBuf =
10074 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10075 FromSM.getFileManager(), SourceLocation{});
10076 if (!FromBuf)
10077 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10078
10079 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10080 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10081 FromBuf->getBufferIdentifier());
10082 ToID = ToSM.createFileID(std::move(ToBuf),
10083 FromSLoc.getFile().getFileCharacteristic());
10084 }
10085 }
10086
10087 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10088
10089 ImportedFileIDs[FromID] = ToID;
10090 return ToID;
10091}
10092
10094 ExpectedExpr ToExprOrErr = Import(From->getInit());
10095 if (!ToExprOrErr)
10096 return ToExprOrErr.takeError();
10097
10098 auto LParenLocOrErr = Import(From->getLParenLoc());
10099 if (!LParenLocOrErr)
10100 return LParenLocOrErr.takeError();
10101
10102 auto RParenLocOrErr = Import(From->getRParenLoc());
10103 if (!RParenLocOrErr)
10104 return RParenLocOrErr.takeError();
10105
10106 if (From->isBaseInitializer()) {
10107 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10108 if (!ToTInfoOrErr)
10109 return ToTInfoOrErr.takeError();
10110
10111 SourceLocation EllipsisLoc;
10112 if (From->isPackExpansion())
10113 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10114 return std::move(Err);
10115
10116 return new (ToContext) CXXCtorInitializer(
10117 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10118 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10119 } else if (From->isMemberInitializer()) {
10120 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10121 if (!ToFieldOrErr)
10122 return ToFieldOrErr.takeError();
10123
10124 auto MemberLocOrErr = Import(From->getMemberLocation());
10125 if (!MemberLocOrErr)
10126 return MemberLocOrErr.takeError();
10127
10128 return new (ToContext) CXXCtorInitializer(
10129 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10130 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10131 } else if (From->isIndirectMemberInitializer()) {
10132 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10133 if (!ToIFieldOrErr)
10134 return ToIFieldOrErr.takeError();
10135
10136 auto MemberLocOrErr = Import(From->getMemberLocation());
10137 if (!MemberLocOrErr)
10138 return MemberLocOrErr.takeError();
10139
10140 return new (ToContext) CXXCtorInitializer(
10141 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10142 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10143 } else if (From->isDelegatingInitializer()) {
10144 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10145 if (!ToTInfoOrErr)
10146 return ToTInfoOrErr.takeError();
10147
10148 return new (ToContext)
10149 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10150 *ToExprOrErr, *RParenLocOrErr);
10151 } else {
10152 // FIXME: assert?
10153 return make_error<ASTImportError>();
10154 }
10155}
10156
10159 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10160 if (Pos != ImportedCXXBaseSpecifiers.end())
10161 return Pos->second;
10162
10163 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10164 if (!ToSourceRange)
10165 return ToSourceRange.takeError();
10167 if (!ToTSI)
10168 return ToTSI.takeError();
10169 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10170 if (!ToEllipsisLoc)
10171 return ToEllipsisLoc.takeError();
10172 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10173 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10174 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10175 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10176 return Imported;
10177}
10178
10180 ASTNodeImporter Importer(*this);
10181 return Importer.ImportAPValue(FromValue);
10182}
10183
10185 ExpectedDecl ToOrErr = Import(From);
10186 if (!ToOrErr)
10187 return ToOrErr.takeError();
10188 Decl *To = *ToOrErr;
10189
10190 auto *FromDC = cast<DeclContext>(From);
10191 ASTNodeImporter Importer(*this);
10192
10193 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10194 if (!ToRecord->getDefinition()) {
10195 return Importer.ImportDefinition(
10196 cast<RecordDecl>(FromDC), ToRecord,
10198 }
10199 }
10200
10201 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10202 if (!ToEnum->getDefinition()) {
10203 return Importer.ImportDefinition(
10204 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10205 }
10206 }
10207
10208 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10209 if (!ToIFace->getDefinition()) {
10210 return Importer.ImportDefinition(
10211 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10213 }
10214 }
10215
10216 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10217 if (!ToProto->getDefinition()) {
10218 return Importer.ImportDefinition(
10219 cast<ObjCProtocolDecl>(FromDC), ToProto,
10221 }
10222 }
10223
10224 return Importer.ImportDeclContext(FromDC, true);
10225}
10226
10228 if (!FromName)
10229 return DeclarationName{};
10230
10231 switch (FromName.getNameKind()) {
10233 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10234
10238 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10239 return DeclarationName(*ToSelOrErr);
10240 else
10241 return ToSelOrErr.takeError();
10242
10244 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10245 return ToContext.DeclarationNames.getCXXConstructorName(
10246 ToContext.getCanonicalType(*ToTyOrErr));
10247 else
10248 return ToTyOrErr.takeError();
10249 }
10250
10252 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10253 return ToContext.DeclarationNames.getCXXDestructorName(
10254 ToContext.getCanonicalType(*ToTyOrErr));
10255 else
10256 return ToTyOrErr.takeError();
10257 }
10258
10260 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10262 cast<TemplateDecl>(*ToTemplateOrErr));
10263 else
10264 return ToTemplateOrErr.takeError();
10265 }
10266
10268 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10270 ToContext.getCanonicalType(*ToTyOrErr));
10271 else
10272 return ToTyOrErr.takeError();
10273 }
10274
10276 return ToContext.DeclarationNames.getCXXOperatorName(
10277 FromName.getCXXOverloadedOperator());
10278
10281 Import(FromName.getCXXLiteralIdentifier()));
10282
10284 // FIXME: STATICS!
10286 }
10287
10288 llvm_unreachable("Invalid DeclarationName Kind!");
10289}
10290
10292 if (!FromId)
10293 return nullptr;
10294
10295 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10296
10297 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10298 ToId->setBuiltinID(FromId->getBuiltinID());
10299
10300 return ToId;
10301}
10302
10304 if (FromSel.isNull())
10305 return Selector{};
10306
10308 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10309 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10310 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10311 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10312}
10313
10317 llvm::Error Err = llvm::Error::success();
10318 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10319 for (unsigned Idx = 0; Idx < Size; Idx++) {
10320 APValue Tmp = importChecked(Err, From[Idx]);
10321 To[Idx] = Tmp;
10322 }
10323 };
10324 switch (FromValue.getKind()) {
10325 case APValue::None:
10327 case APValue::Int:
10328 case APValue::Float:
10332 Result = FromValue;
10333 break;
10334 case APValue::Vector: {
10335 Result.MakeVector();
10337 Result.setVectorUninit(FromValue.getVectorLength());
10338 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10339 Elts.data(), FromValue.getVectorLength());
10340 break;
10341 }
10342 case APValue::Array:
10343 Result.MakeArray(FromValue.getArrayInitializedElts(),
10344 FromValue.getArraySize());
10345 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10346 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10347 FromValue.getArrayInitializedElts());
10348 break;
10349 case APValue::Struct:
10350 Result.MakeStruct(FromValue.getStructNumBases(),
10351 FromValue.getStructNumFields());
10352 ImportLoop(
10353 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10354 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10355 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10356 break;
10357 case APValue::Union: {
10358 Result.MakeUnion();
10359 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10360 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10361 if (Err)
10362 return std::move(Err);
10363 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10364 break;
10365 }
10367 Result.MakeAddrLabelDiff();
10368 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10369 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10370 if (Err)
10371 return std::move(Err);
10372 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10373 cast<AddrLabelExpr>(ImpRHS));
10374 break;
10375 }
10377 const Decl *ImpMemPtrDecl =
10378 importChecked(Err, FromValue.getMemberPointerDecl());
10379 if (Err)
10380 return std::move(Err);
10382 Result.setMemberPointerUninit(
10383 cast<const ValueDecl>(ImpMemPtrDecl),
10385 FromValue.getMemberPointerPath().size());
10387 Result.getMemberPointerPath();
10388 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10389 Idx++) {
10390 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10391 if (Err)
10392 return std::move(Err);
10393 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10394 }
10395 break;
10396 }
10397 case APValue::LValue:
10399 QualType FromElemTy;
10400 if (FromValue.getLValueBase()) {
10401 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10402 "in C++20 dynamic allocation are transient so they shouldn't "
10403 "appear in the AST");
10404 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10405 if (const auto *E =
10406 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10407 FromElemTy = E->getType();
10408 const Expr *ImpExpr = importChecked(Err, E);
10409 if (Err)
10410 return std::move(Err);
10411 Base = APValue::LValueBase(ImpExpr,
10412 FromValue.getLValueBase().getCallIndex(),
10413 FromValue.getLValueBase().getVersion());
10414 } else {
10415 FromElemTy =
10416 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10417 const Decl *ImpDecl = importChecked(
10418 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10419 if (Err)
10420 return std::move(Err);
10421 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10422 FromValue.getLValueBase().getCallIndex(),
10423 FromValue.getLValueBase().getVersion());
10424 }
10425 } else {
10426 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10427 const Type *ImpTypeInfo = importChecked(
10428 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10429 QualType ImpType =
10430 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10431 if (Err)
10432 return std::move(Err);
10434 ImpType);
10435 }
10436 }
10437 CharUnits Offset = FromValue.getLValueOffset();
10438 unsigned PathLength = FromValue.getLValuePath().size();
10439 Result.MakeLValue();
10440 if (FromValue.hasLValuePath()) {
10441 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10442 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10443 FromValue.isNullPointer());
10445 FromValue.getLValuePath();
10446 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10447 if (FromElemTy->isRecordType()) {
10448 const Decl *FromDecl =
10449 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10450 const Decl *ImpDecl = importChecked(Err, FromDecl);
10451 if (Err)
10452 return std::move(Err);
10453 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10454 FromElemTy = Importer.FromContext.getRecordType(RD);
10455 else
10456 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10458 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10459 } else {
10460 FromElemTy =
10461 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10462 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10463 FromPath[LoopIdx].getAsArrayIndex());
10464 }
10465 }
10466 } else
10467 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10468 FromValue.isNullPointer());
10469 }
10470 if (Err)
10471 return std::move(Err);
10472 return Result;
10473}
10474
10476 DeclContext *DC,
10477 unsigned IDNS,
10478 NamedDecl **Decls,
10479 unsigned NumDecls) {
10480 if (ODRHandling == ODRHandlingType::Conservative)
10481 // Report error at any name conflict.
10482 return make_error<ASTImportError>(ASTImportError::NameConflict);
10483 else
10484 // Allow to create the new Decl with the same name.
10485 return Name;
10486}
10487
10489 if (LastDiagFromFrom)
10491 FromContext.getDiagnostics());
10492 LastDiagFromFrom = false;
10493 return ToContext.getDiagnostics().Report(Loc, DiagID);
10494}
10495
10497 if (!LastDiagFromFrom)
10499 ToContext.getDiagnostics());
10500 LastDiagFromFrom = true;
10501 return FromContext.getDiagnostics().Report(Loc, DiagID);
10502}
10503
10505 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10506 if (!ID->getDefinition())
10507 ID->startDefinition();
10508 }
10509 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10510 if (!PD->getDefinition())
10511 PD->startDefinition();
10512 }
10513 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10514 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10515 TD->startDefinition();
10516 TD->setCompleteDefinition(true);
10517 }
10518 }
10519 else {
10520 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10521 }
10522}
10523
10525 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10526 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10527 "Try to import an already imported Decl");
10528 if (Pos != ImportedDecls.end())
10529 return Pos->second;
10530 ImportedDecls[From] = To;
10531 // This mapping should be maintained only in this function. Therefore do not
10532 // check for additional consistency.
10533 ImportedFromDecls[To] = From;
10534 // In the case of TypedefNameDecl we create the Decl first and only then we
10535 // import and set its DeclContext. So, the DC is still not set when we reach
10536 // here from GetImportedOrCreateDecl.
10537 if (To->getDeclContext())
10538 AddToLookupTable(To);
10539 return To;
10540}
10541
10542std::optional<ASTImportError>
10544 auto Pos = ImportDeclErrors.find(FromD);
10545 if (Pos != ImportDeclErrors.end())
10546 return Pos->second;
10547 else
10548 return std::nullopt;
10549}
10550
10552 auto InsertRes = ImportDeclErrors.insert({From, Error});
10553 (void)InsertRes;
10554 // Either we set the error for the first time, or we already had set one and
10555 // now we want to set the same error.
10556 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10557}
10558
10560 bool Complain) {
10561 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10562 ImportedTypes.find(From.getTypePtr());
10563 if (Pos != ImportedTypes.end()) {
10564 if (ExpectedType ToFromOrErr = Import(From)) {
10565 if (ToContext.hasSameType(*ToFromOrErr, To))
10566 return true;
10567 } else {
10568 llvm::consumeError(ToFromOrErr.takeError());
10569 }
10570 }
10571
10572 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10573 getStructuralEquivalenceKind(*this), false,
10574 Complain);
10575 return Ctx.IsEquivalent(From, To);
10576}
Defines the clang::ASTContext interface.
ASTImporterLookupTable & LT
static FriendCountAndPosition getFriendCountAndPosition(ASTImporter &Importer, FriendDecl *FD)
static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1, FriendDecl *FD2)
static auto getTemplateDefinition(T *D) -> T *
static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D)
static Error setTypedefNameForAnonDecl(TagDecl *From, TagDecl *To, ASTImporter &Importer)
static StructuralEquivalenceKind getStructuralEquivalenceKind(const ASTImporter &Importer)
Defines enum values for all the target-independent builtin functions.
const Decl * D
IndirectLocalPath & Path
enum clang::sema::@1727::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:3056
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:759
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:984
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:1004
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:989
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1074
unsigned getArrayInitializedElts() const
Definition: APValue.h:595
unsigned getStructNumBases() const
Definition: APValue.h:604
bool hasLValuePath() const
Definition: APValue.cpp:999
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1067
APValue & getUnionValue()
Definition: APValue.h:633
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:649
CharUnits & getLValueOffset()
Definition: APValue.cpp:994
unsigned getVectorLength() const
Definition: APValue.h:571
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1081
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:1020
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
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:741
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
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.
BuiltinTemplateDecl * getBuiltinCommonTypeDecl() const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2723
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2739
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag=SubstTemplateTypeParmTypeFlag::None) 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 getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1703
IdentifierTable & Idents
Definition: ASTContext.h:680
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
SelectorTable & Selectors
Definition: ASTContext.h:681
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
Retrieve a.
CanQualType CharTy
Definition: ASTContext.h:1162
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2296
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1169
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1160
CanQualType UnsignedCharTy
Definition: ASTContext.h:1170
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1681
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, int Index=-1) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
DiagnosticsEngine & getDiagnostics() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1274
BuiltinTemplateDecl * getTypePackElementDecl() const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
CanQualType WCharTy
Definition: ASTContext.h:1163
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
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:98
std::string toString() const
Definition: ASTImporter.cpp:84
@ 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:528
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:543
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:525
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
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:270
std::optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
Definition: ASTImporter.h:371
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition: ASTImporter.h:63
static std::optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:308
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:568
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:553
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:298
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4421
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3358
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5805
Represents a loop initializing the elements of an array.
Definition: Expr.h:5752
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3748
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3578
QualType getElementType() const
Definition: Type.h:3590
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:6678
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
void setPackExpansion(bool PE)
Definition: Attr.h:105
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:103
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2107
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:433
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:6133
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6562
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3440
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3274
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4324
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
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:4902
A binding in a decomposition declaration.
Definition: DeclCXX.h:4130
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:4167
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4173
A fixed int type of a specified bitwidth.
Definition: Type.h:7820
Pointer to a block type.
Definition: Type.h:3409
BreakStmt - This represents a break.
Definition: Stmt.h:3007
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5296
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: Type.h:3035
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:2120
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:1491
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1097
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:732
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:875
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1708
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:1159
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2553
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2885
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2318
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2458
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2418
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2520
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2517
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2428
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2516
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2423
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2452
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2396
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2390
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2402
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2478
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2472
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2444
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1967
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1268
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1018
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1375
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:1072
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
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:1533
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2817
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:3003
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:787
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4844
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:901
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:675
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2644
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2667
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2174
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:291
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4126
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
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:611
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2617
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:541
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:1982
method_range methods() const
Definition: DeclCXX.h:662
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:565
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1995
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:2008
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1797
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1989
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:2023
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:532
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:852
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
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:761
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1885
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:1125
Represents a C++ temporary.
Definition: ExprCXX.h:1457
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1092
Represents the this expression in C++.
Definition: ExprCXX.h:1152
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1568
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1206
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1471
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
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:1499
CaseStmt - Represent a case statement.
Definition: Stmt.h:1828
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1228
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3547
path_iterator path_begin()
Definition: Expr.h:3617
path_iterator path_end()
Definition: Expr.h:3618
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:4641
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
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: Type.h:3146
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4171
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:4924
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1628
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:391
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:163
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:195
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:167
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:199
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:203
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:173
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4262
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3616
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1077
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:349
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4233
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3621
ContinueStmt - This represents a continue.
Definition: Stmt.h:2977
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4582
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3307
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3392
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:1372
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1439
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2104
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:2065
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1345
bool isNamespace() const
Definition: DeclBase.h:2193
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1866
bool isRecord() const
Definition: DeclBase.h:2184
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2010
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1788
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1654
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1699
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:1939
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1649
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2364
bool isFunctionOrMethod() const
Definition: DeclBase.h:2156
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:1971
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:68
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
bool isNull() const
Definition: DeclGroup.h:79
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
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:487
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1519
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:266
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1219
bool hasAttrs() const
Definition: DeclBase.h:521
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:528
void addAttr(Attr *A)
Definition: DeclBase.cpp:1019
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:247
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:886
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1210
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:1173
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:505
SourceLocation getLocation() const
Definition: DeclBase.h:442
const char * getDeclKindName() const
Definition: DeclBase.cpp:150
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:597
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1042
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:611
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:557
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:420
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:513
AttrVec & getAttrs()
Definition: DeclBase.h:527
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:363
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:911
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:367
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:971
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:769
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1989
Represents the type decltype(expr) (C++11).
Definition: Type.h:5880
A decomposition declaration.
Definition: DeclCXX.h:4189
Represents a C++17 deduced template specialization type.
Definition: Type.h:6610
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3921
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:7030
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:531
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3863
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3961
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4292
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:620
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:607
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:604
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:610
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7082
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4087
Represents a single C99 designator.
Definition: Expr.h:5376
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5503
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5457
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5493
Represents a C99 designated initializer expression.
Definition: Expr.h:5333
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4634
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1220
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1493
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:919
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2752
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6949
Represents an empty-declaration.
Definition: Decl.h:5011
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3291
Represents an enum.
Definition: Decl.h:3861
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4120
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4058
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4030
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3957
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4921
EnumDecl * getDefinition() const
Definition: Decl.h:3964
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4047
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4013
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6104
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3799
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1912
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1920
const Expr * getExpr() const
Definition: DeclCXX.h:1921
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3474
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3480
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1446
This represents one expression.
Definition: Expr.h:110
void setType(QualType t)
Definition: Expr.h:143
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:276
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2924
ExtVectorType - Extended vector type.
Definition: Type.h:4127
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:979
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4598
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3208
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4608
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4705
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:245
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1081
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2808
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:126
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3103
Represents a function declaration or definition.
Definition: Decl.h:1935
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3243
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4072
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4067
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3262
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3124
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2577
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4046
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4197
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2330
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4263
@ TK_MemberSpecialization
Definition: Decl.h:1947
@ TK_DependentNonTemplate
Definition: Decl.h:1956
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1951
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1954
void setTrivial(bool IT)
Definition: Decl.h:2306
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:4018
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4085
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:4252
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2284
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2153
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4091
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4292
void setDefaulted(bool D=true)
Definition: Decl.h:2314
void setBody(Stmt *B)
Definition: Decl.cpp:3255
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3133
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2322
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4039
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3163
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4687
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5108
QualType desugar() const
Definition: Type.h:5652
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5372
ArrayRef< QualType > exceptions() const
Definition: Type.h:5531
ArrayRef< QualType > param_types() const
Definition: Type.h:5517
Declaration of a template function.
Definition: DeclTemplate.h:958
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: Type.h:4661
QualType getReturnType() const
Definition: Type.h:4649
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3286
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4716
Represents a C11 generic selection.
Definition: Expr.h:5966
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:4522
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2889
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:2165
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:966
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1717
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2089
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4885
Represents a C array with an unspecified size.
Definition: Type.h:3765
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3335
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2928
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2524
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2537
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2536
Describes an C or C++ initializer list.
Definition: Expr.h:5088
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5258
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2443
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5213
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5268
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6799
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:980
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3484
Represents the declaration of a label.
Definition: Decl.h:503
void setStmt(LabelStmt *T)
Definition: Decl.h:528
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2058
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:1245
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:1954
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:1293
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3252
Represents a linkage specification.
Definition: DeclCXX.h:2957
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2999
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:359
iterator begin() const
Definition: Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5771
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4732
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
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:1769
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3520
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:619
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:659
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:664
This represents a decl that may have a name.
Definition: Decl.h:253
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1176
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:319
Represents a C++ namespace alias.
Definition: DeclCXX.h:3143
Represent a C++ namespace.
Definition: Decl.h:551
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition: Decl.h:634
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:653
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1591
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:1632
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2165
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:2390
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2161
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2399
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2544
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:2596
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2734
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1484
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1746
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1640
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:370
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:341
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1627
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:614
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1914
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:350
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7530
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
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:942
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1188
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1209
Represents a pointer to an Objective C object.
Definition: Type.h:7586
Represents a class type in Objective C.
Definition: Type.h:7332
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:895
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:818
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:830
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:919
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:904
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:887
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2804
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2878
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2881
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2874
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
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:2208
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2249
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2021
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2157
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2164
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2171
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2185
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:659
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1518
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:7258
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1672
Helper class for OffsetOfExpr.
Definition: Expr.h:2413
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2471
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2477
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1707
@ Array
An index into an array.
Definition: Expr.h:2418
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2422
@ Field
A field.
Definition: Expr.h:2420
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2499
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2467
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2500
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2487
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:116
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
Represents a pack expansion of types.
Definition: Type.h:7147
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4774
Sugar for parentheses used when specifying types.
Definition: Type.h:3173
Represents a parameter to a function.
Definition: Decl.h:1725
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1806
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1793
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2987
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1821
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1866
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1854
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3012
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1858
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1753
bool hasInheritedDefaultArg() const
Definition: Decl.h:1870
void setKNRPromoted(bool promoted)
Definition: Decl.h:1809
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1817
Expr * getDefaultArg()
Definition: Decl.cpp:2975
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3017
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3023
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1874
PipeType - OpenCL20.
Definition: Type.h:7786
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3199
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1991
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:637
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7937
QualType getCanonicalType() const
Definition: Type.h:7989
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7969
Represents a template name as written in source code.
Definition: TemplateName.h:491
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:526
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:519
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:523
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3502
Represents a struct/union/class.
Definition: Decl.h:4162
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5084
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4218
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4188
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5125
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4361
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6078
RecordDecl * getDecl() const
Definition: Type.h:6088
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:203
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:225
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:5080
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3440
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3046
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1212
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:4412
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4514
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4258
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4810
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4081
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4466
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:186
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:358
child_iterator child_begin()
Definition: Stmt.h:1479
StmtClass getStmtClass() const
Definition: Stmt.h:1380
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:1480
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:1778
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:1194
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4488
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
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:164
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:408
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:432
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:430
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:426
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6470
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:6389
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1803
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2415
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1089
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3578
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3701
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3681
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3806
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4780
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4771
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4826
void setBraceRange(SourceRange R)
Definition: Decl.h:3658
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3684
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h: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:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:377
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:393
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
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:265
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:240
@ Template
A single template declaration.
Definition: TemplateName.h:237
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:252
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:256
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:261
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
Definition: TemplateName.h:269
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:248
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:244
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:147
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:183
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: Type.h:6667
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3549
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3567
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:227
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: Type.h:3227
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3410
const Type * getTypeForDecl() const
Definition: Decl.h:3409
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
const Type * getType() const
Definition: APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5803
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5853
The type-property cache.
Definition: Type.cpp:4499
A container of type source information.
Definition: Type.h:7908
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7919
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2768
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:1876
An operation on a type.
Definition: TypeVisitor.h:64
ExpectedType Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:68
The base class of the type hierarchy.
Definition: Type.h:1828
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8698
bool isArrayType() const
Definition: Type.h:8264
bool isPointerType() const
Definition: Type.h:8192
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2707
QualType getCanonicalTypeInternal() const
Definition: Type.h:2990
const char * getTypeClassName() const
Definition: Type.cpp:3316
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8691
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2396
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2367
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8741
bool isRecordType() const
Definition: Type.h:8292
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1920
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3528
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3427
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4938
A unary type transform, which is a type constructed from another.
Definition: Type.h:5995
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
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:419
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3943
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:1635
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5673
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3982
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3885
Represents a C++ using-declaration.
Definition: DeclCXX.h:3535
Represents C++ using-directive.
Definition: DeclCXX.h:3038
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3736
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3817
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3343
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4750
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
void setType(QualType newType)
Definition: Decl.h:683
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2911
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2355
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2543
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2529
void setInlineSpecified()
Definition: Decl.h:1502
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1124
const Expr * getInit() const
Definition: Decl.h:1319
void setConstexpr(bool IC)
Definition: Decl.h:1516
void setInit(Expr *I)
Definition: Decl.cpp:2449
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2791
void setImplicitlyInline()
Definition: Decl.h:1507
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1309
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2874
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplateDecl * getMostRecentDecl()
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Represents a variable template specialization, which refers to a variable template with a given set o...
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: Type.h:3809
Represents a GCC generic vector type.
Definition: Type.h:4035
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2611
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:1151
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:328
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
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ BTK__type_pack_element
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:313
@ BTK__builtin_common_type
This names the __builtin_common_type BuiltinTemplateDecl.
Definition: Builtins.h:316
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:310
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:1278
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
static void updateFlags(const Decl *From, Decl *To)
#define false
Definition: stdbool.h:26
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1813
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:847
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:865
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:858
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:5177
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5181
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5167
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5170
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5173
Extra information about a function prototype.
Definition: Type.h:5193
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5200
FunctionType::ExtInfo ExtInfo
Definition: Type.h:5194
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513