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/APSInt.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/Casting.h"
63#include "llvm/Support/ErrorHandling.h"
64#include "llvm/Support/MemoryBuffer.h"
65#include <algorithm>
66#include <cassert>
67#include <cstddef>
68#include <memory>
69#include <optional>
70#include <type_traits>
71#include <utility>
72
73namespace clang {
74
75 using llvm::make_error;
76 using llvm::Error;
77 using llvm::Expected;
85
86 std::string ASTImportError::toString() const {
87 // FIXME: Improve error texts.
88 switch (Error) {
89 case NameConflict:
90 return "NameConflict";
92 return "UnsupportedConstruct";
93 case Unknown:
94 return "Unknown error";
95 }
96 llvm_unreachable("Invalid error code.");
97 return "Invalid error code.";
98 }
99
100 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
101
102 std::error_code ASTImportError::convertToErrorCode() const {
103 llvm_unreachable("Function not implemented.");
104 }
105
107
108 template <class T>
112 for (auto *R : D->getFirstDecl()->redecls()) {
113 if (R != D->getFirstDecl())
114 Redecls.push_back(R);
115 }
116 Redecls.push_back(D->getFirstDecl());
117 std::reverse(Redecls.begin(), Redecls.end());
118 return Redecls;
119 }
120
122 if (auto *FD = dyn_cast<FunctionDecl>(D))
123 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
124 if (auto *VD = dyn_cast<VarDecl>(D))
125 return getCanonicalForwardRedeclChain<VarDecl>(VD);
126 if (auto *TD = dyn_cast<TagDecl>(D))
127 return getCanonicalForwardRedeclChain<TagDecl>(TD);
128 llvm_unreachable("Bad declaration kind");
129 }
130
131 void updateFlags(const Decl *From, Decl *To) {
132 // Check if some flags or attrs are new in 'From' and copy into 'To'.
133 // FIXME: Other flags or attrs?
134 if (From->isUsed(false) && !To->isUsed(false))
135 To->setIsUsed();
136 }
137
138 /// How to handle import errors that occur when import of a child declaration
139 /// of a DeclContext fails.
141 /// This context is imported (in the 'from' domain).
142 /// It is nullptr if a non-DeclContext is imported.
143 const DeclContext *const FromDC;
144 /// Ignore import errors of the children.
145 /// If true, the context can be imported successfully if a child
146 /// of it failed to import. Otherwise the import errors of the child nodes
147 /// are accumulated (joined) into the import error object of the parent.
148 /// (Import of a parent can fail in other ways.)
149 bool const IgnoreChildErrors;
150
151 public:
153 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
155 : FromDC(dyn_cast<DeclContext>(FromD)),
156 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
157
158 /// Process the import result of a child (of the current declaration).
159 /// \param ResultErr The import error that can be used as result of
160 /// importing the parent. This may be changed by the function.
161 /// \param ChildErr Result of importing a child. Can be success or error.
162 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
163 if (ChildErr && !IgnoreChildErrors)
164 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
165 else
166 consumeError(std::move(ChildErr));
167 }
168
169 /// Determine if import failure of a child does not cause import failure of
170 /// its parent.
171 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
172 if (!IgnoreChildErrors || !FromDC)
173 return false;
174 return FromDC->containsDecl(FromChildD);
175 }
176 };
177
178 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
179 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
180 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
181 ASTImporter &Importer;
182
183 // Use this instead of Importer.importInto .
184 template <typename ImportT>
185 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
186 return Importer.importInto(To, From);
187 }
188
189 // Use this to import pointers of specific type.
190 template <typename ImportT>
191 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
192 auto ToOrErr = Importer.Import(From);
193 if (ToOrErr)
194 To = cast_or_null<ImportT>(*ToOrErr);
195 return ToOrErr.takeError();
196 }
197
198 // Call the import function of ASTImporter for a baseclass of type `T` and
199 // cast the return value to `T`.
200 template <typename T>
201 auto import(T *From)
202 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
204 auto ToOrErr = Importer.Import(From);
205 if (!ToOrErr)
206 return ToOrErr.takeError();
207 return cast_or_null<T>(*ToOrErr);
208 }
209
210 template <typename T>
211 auto import(const T *From) {
212 return import(const_cast<T *>(From));
213 }
214
215 // Call the import function of ASTImporter for type `T`.
216 template <typename T>
217 Expected<T> import(const T &From) {
218 return Importer.Import(From);
219 }
220
221 // Import an std::optional<T> by importing the contained T, if any.
222 template <typename T>
223 Expected<std::optional<T>> import(std::optional<T> From) {
224 if (!From)
225 return std::nullopt;
226 return import(*From);
227 }
228
229 ExplicitSpecifier importExplicitSpecifier(Error &Err,
230 ExplicitSpecifier ESpec);
231
232 // Wrapper for an overload set.
233 template <typename ToDeclT> struct CallOverloadedCreateFun {
234 template <typename... Args> decltype(auto) operator()(Args &&... args) {
235 return ToDeclT::Create(std::forward<Args>(args)...);
236 }
237 };
238
239 // Always use these functions to create a Decl during import. There are
240 // certain tasks which must be done after the Decl was created, e.g. we
241 // must immediately register that as an imported Decl. The parameter `ToD`
242 // will be set to the newly created Decl or if had been imported before
243 // then to the already imported Decl. Returns a bool value set to true if
244 // the `FromD` had been imported before.
245 template <typename ToDeclT, typename FromDeclT, typename... Args>
246 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
247 Args &&...args) {
248 // There may be several overloads of ToDeclT::Create. We must make sure
249 // to call the one which would be chosen by the arguments, thus we use a
250 // wrapper for the overload set.
251 CallOverloadedCreateFun<ToDeclT> OC;
252 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
253 std::forward<Args>(args)...);
254 }
255 // Use this overload if a special Type is needed to be created. E.g if we
256 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
257 // then:
258 // TypedefNameDecl *ToTypedef;
259 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
260 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
261 typename... Args>
262 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
263 Args &&...args) {
264 CallOverloadedCreateFun<NewDeclT> OC;
265 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
266 std::forward<Args>(args)...);
267 }
268 // Use this version if a special create function must be
269 // used, e.g. CXXRecordDecl::CreateLambda .
270 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
271 typename... Args>
272 [[nodiscard]] bool
273 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
274 FromDeclT *FromD, Args &&...args) {
275 if (Importer.getImportDeclErrorIfAny(FromD)) {
276 ToD = nullptr;
277 return true; // Already imported but with error.
278 }
279 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
280 if (ToD)
281 return true; // Already imported.
282 ToD = CreateFun(std::forward<Args>(args)...);
283 // Keep track of imported Decls.
284 Importer.RegisterImportedDecl(FromD, ToD);
285 Importer.SharedState->markAsNewDecl(ToD);
286 InitializeImportedDecl(FromD, ToD);
287 return false; // A new Decl is created.
288 }
289
290 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
291 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
292 if (FromD->isUsed())
293 ToD->setIsUsed();
294 if (FromD->isImplicit())
295 ToD->setImplicit();
296 }
297
298 // Check if we have found an existing definition. Returns with that
299 // definition if yes, otherwise returns null.
300 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
301 const FunctionDecl *Definition = nullptr;
302 if (D->doesThisDeclarationHaveABody() &&
303 FoundFunction->hasBody(Definition))
304 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
305 return nullptr;
306 }
307
308 void addDeclToContexts(Decl *FromD, Decl *ToD) {
309 if (Importer.isMinimalImport()) {
310 // In minimal import case the decl must be added even if it is not
311 // contained in original context, for LLDB compatibility.
312 // FIXME: Check if a better solution is possible.
313 if (!FromD->getDescribedTemplate() &&
314 FromD->getFriendObjectKind() == Decl::FOK_None)
316 return;
317 }
318
319 DeclContext *FromDC = FromD->getDeclContext();
320 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
321 DeclContext *ToDC = ToD->getDeclContext();
322 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
323
324 bool Visible = false;
325 if (FromDC->containsDeclAndLoad(FromD)) {
326 ToDC->addDeclInternal(ToD);
327 Visible = true;
328 }
329 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
330 ToLexicalDC->addDeclInternal(ToD);
331 Visible = true;
332 }
333
334 // If the Decl was added to any context, it was made already visible.
335 // Otherwise it is still possible that it should be visible.
336 if (!Visible) {
337 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
338 auto *ToNamed = cast<NamedDecl>(ToD);
339 DeclContextLookupResult FromLookup =
340 FromDC->lookup(FromNamed->getDeclName());
341 if (llvm::is_contained(FromLookup, FromNamed))
342 ToDC->makeDeclVisibleInContext(ToNamed);
343 }
344 }
345 }
346
347 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
348 DeclContext *OldDC) {
349 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
350 if (!LT)
351 return;
352
353 for (NamedDecl *TP : Params)
354 LT->update(TP, OldDC);
355 }
356
357 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
358 updateLookupTableForTemplateParameters(
359 Params, Importer.getToContext().getTranslationUnitDecl());
360 }
361
362 template <typename TemplateParmDeclT>
363 void tryUpdateTemplateParmDeclInheritedFrom(NamedDecl *RecentParm,
364 NamedDecl *NewParm) {
365 if (auto *ParmT = dyn_cast<TemplateParmDeclT>(RecentParm)) {
366 if (ParmT->hasDefaultArgument()) {
367 auto *P = cast<TemplateParmDeclT>(NewParm);
368 P->removeDefaultArgument();
369 P->setInheritedDefaultArgument(Importer.ToContext, ParmT);
370 }
371 }
372 }
373
374 // Update the parameter list `NewParams` of a template declaration
375 // by "inheriting" default argument values from `RecentParams`,
376 // which is the parameter list of an earlier declaration of the
377 // same template. (Note that "inheriting" default argument values
378 // is not related to object-oriented inheritance.)
379 //
380 // In the clang AST template parameters (NonTypeTemplateParmDec,
381 // TemplateTypeParmDecl, TemplateTemplateParmDecl) have a reference to the
382 // default value, if one is specified at the first declaration. The default
383 // value can be specified only once. The template parameters of the
384 // following declarations have a reference to the original default value
385 // through the "inherited" value. This value should be set for all imported
386 // template parameters that have a previous declaration (also a previous
387 // template declaration).
388 //
389 // In the `Visit*ParmDecl` functions the default value of these template
390 // arguments is always imported. At that location the previous declaration
391 // is not easily accessible, it is not possible to call
392 // `setInheritedDefaultArgument` at that place.
393 // `updateTemplateParametersInheritedFrom` is called later when the already
394 // imported default value is erased and changed to "inherited".
395 // It is important to change the mode to "inherited" otherwise false
396 // structural in-equivalences could be detected.
397 void updateTemplateParametersInheritedFrom(
398 const TemplateParameterList &RecentParams,
399 TemplateParameterList &NewParams) {
400 for (auto [Idx, Param] : enumerate(RecentParams)) {
401 tryUpdateTemplateParmDeclInheritedFrom<NonTypeTemplateParmDecl>(
402 Param, NewParams.getParam(Idx));
403 tryUpdateTemplateParmDeclInheritedFrom<TemplateTypeParmDecl>(
404 Param, NewParams.getParam(Idx));
405 tryUpdateTemplateParmDeclInheritedFrom<TemplateTemplateParmDecl>(
406 Param, NewParams.getParam(Idx));
407 }
408 }
409
410 public:
411 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
412
416
417 // Importing types
419#define TYPE(Class, Base) \
420 ExpectedType Visit##Class##Type(const Class##Type *T);
421#include "clang/AST/TypeNodes.inc"
422
423 // Importing declarations
426 Error ImportDeclParts(
427 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
429 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
432 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
433 Error ImportDeclContext(
434 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
435 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
436
437 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
439 Expected<APValue> ImportAPValue(const APValue &FromValue);
440
442
443 /// What we should import from the definition.
445 /// Import the default subset of the definition, which might be
446 /// nothing (if minimal import is set) or might be everything (if minimal
447 /// import is not set).
449 /// Import everything.
451 /// Import only the bare bones needed to establish a valid
452 /// DeclContext.
454 };
455
457 return IDK == IDK_Everything ||
458 (IDK == IDK_Default && !Importer.isMinimalImport());
459 }
460
461 Error ImportInitializer(VarDecl *From, VarDecl *To);
462 Error ImportDefinition(
463 RecordDecl *From, RecordDecl *To,
465 Error ImportDefinition(
466 EnumDecl *From, EnumDecl *To,
468 Error ImportDefinition(
471 Error ImportDefinition(
478
479 template <typename InContainerTy>
481 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
482
483 template<typename InContainerTy>
485 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
486 const InContainerTy &Container, TemplateArgumentListInfo &Result);
487
490 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
493 FunctionDecl *FromFD);
494
495 template <typename DeclTy>
496 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
497
499
501
502 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
503 ParmVarDecl *ToParam);
504
507
508 template <typename T>
510
511 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
512 bool IgnoreTemplateParmDepth = false);
559
562
577
578 // Importing statements
598 // FIXME: MSAsmStmt
599 // FIXME: SEHExceptStmt
600 // FIXME: SEHFinallyStmt
601 // FIXME: SEHTryStmt
602 // FIXME: SEHLeaveStmt
603 // FIXME: CapturedStmt
607 // FIXME: MSDependentExistsStmt
615
616 // Importing expressions
693
694 // Helper for chaining together multiple imports. If an error is detected,
695 // subsequent imports will return default constructed nodes, so that failure
696 // can be detected with a single conditional branch after a sequence of
697 // imports.
698 template <typename T> T importChecked(Error &Err, const T &From) {
699 // Don't attempt to import nodes if we hit an error earlier.
700 if (Err)
701 return T{};
702 Expected<T> MaybeVal = import(From);
703 if (!MaybeVal) {
704 Err = MaybeVal.takeError();
705 return T{};
706 }
707 return *MaybeVal;
708 }
709
710 template<typename IIter, typename OIter>
711 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
712 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
713 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
714 Expected<ItemT> ToOrErr = import(*Ibegin);
715 if (!ToOrErr)
716 return ToOrErr.takeError();
717 *Obegin = *ToOrErr;
718 }
719 return Error::success();
720 }
721
722 // Import every item from a container structure into an output container.
723 // If error occurs, stops at first error and returns the error.
724 // The output container should have space for all needed elements (it is not
725 // expanded, new items are put into from the beginning).
726 template<typename InContainerTy, typename OutContainerTy>
728 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
729 return ImportArrayChecked(
730 InContainer.begin(), InContainer.end(), OutContainer.begin());
731 }
732
733 template<typename InContainerTy, typename OIter>
734 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
735 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
736 }
737
739 CXXMethodDecl *FromMethod);
740
742 FunctionDecl *FromFD);
743
744 // Returns true if the given function has a placeholder return type and
745 // that type is declared inside the body of the function.
746 // E.g. auto f() { struct X{}; return X(); }
748 };
749
750template <typename InContainerTy>
752 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
753 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
754 auto ToLAngleLocOrErr = import(FromLAngleLoc);
755 if (!ToLAngleLocOrErr)
756 return ToLAngleLocOrErr.takeError();
757 auto ToRAngleLocOrErr = import(FromRAngleLoc);
758 if (!ToRAngleLocOrErr)
759 return ToRAngleLocOrErr.takeError();
760
761 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
762 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
763 return Err;
764 Result = ToTAInfo;
765 return Error::success();
766}
767
768template <>
769Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
772 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
773}
774
775template <>
778 const ASTTemplateArgumentListInfo &From,
780 return ImportTemplateArgumentListInfo(
781 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
782}
783
786 FunctionDecl *FromFD) {
787 assert(FromFD->getTemplatedKind() ==
789
791
792 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
793 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
794 return std::move(Err);
795
796 // Import template arguments.
797 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
798 std::get<1>(Result)))
799 return std::move(Err);
800
801 return Result;
802}
803
804template <>
806ASTNodeImporter::import(TemplateParameterList *From) {
808 if (Error Err = ImportContainerChecked(*From, To))
809 return std::move(Err);
810
811 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
812 if (!ToRequiresClause)
813 return ToRequiresClause.takeError();
814
815 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
816 if (!ToTemplateLocOrErr)
817 return ToTemplateLocOrErr.takeError();
818 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
819 if (!ToLAngleLocOrErr)
820 return ToLAngleLocOrErr.takeError();
821 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
822 if (!ToRAngleLocOrErr)
823 return ToRAngleLocOrErr.takeError();
824
826 Importer.getToContext(),
827 *ToTemplateLocOrErr,
828 *ToLAngleLocOrErr,
829 To,
830 *ToRAngleLocOrErr,
831 *ToRequiresClause);
832}
833
834template <>
836ASTNodeImporter::import(const TemplateArgument &From) {
837 switch (From.getKind()) {
839 return TemplateArgument();
840
842 ExpectedType ToTypeOrErr = import(From.getAsType());
843 if (!ToTypeOrErr)
844 return ToTypeOrErr.takeError();
845 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
846 From.getIsDefaulted());
847 }
848
850 ExpectedType ToTypeOrErr = import(From.getIntegralType());
851 if (!ToTypeOrErr)
852 return ToTypeOrErr.takeError();
853 return TemplateArgument(From, *ToTypeOrErr);
854 }
855
857 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
858 if (!ToOrErr)
859 return ToOrErr.takeError();
860 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
861 if (!ToTypeOrErr)
862 return ToTypeOrErr.takeError();
863 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
864 *ToTypeOrErr, From.getIsDefaulted());
865 }
866
868 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
869 if (!ToTypeOrErr)
870 return ToTypeOrErr.takeError();
871 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
872 From.getIsDefaulted());
873 }
874
876 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
877 if (!ToTypeOrErr)
878 return ToTypeOrErr.takeError();
879 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
880 if (!ToValueOrErr)
881 return ToValueOrErr.takeError();
882 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
883 *ToValueOrErr);
884 }
885
887 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
888 if (!ToTemplateOrErr)
889 return ToTemplateOrErr.takeError();
890
891 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
892 }
893
895 Expected<TemplateName> ToTemplateOrErr =
896 import(From.getAsTemplateOrTemplatePattern());
897 if (!ToTemplateOrErr)
898 return ToTemplateOrErr.takeError();
899
900 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
901 From.getIsDefaulted());
902 }
903
905 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
906 return TemplateArgument(*ToExpr, From.getIsDefaulted());
907 else
908 return ToExpr.takeError();
909
912 ToPack.reserve(From.pack_size());
913 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
914 return std::move(Err);
915
916 return TemplateArgument(
917 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
918 }
919 }
920
921 llvm_unreachable("Invalid template argument kind");
922}
923
924template <>
926ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
927 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
928 if (!ArgOrErr)
929 return ArgOrErr.takeError();
930 TemplateArgument Arg = *ArgOrErr;
931
932 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
933
936 ExpectedExpr E = import(FromInfo.getAsExpr());
937 if (!E)
938 return E.takeError();
939 ToInfo = TemplateArgumentLocInfo(*E);
940 } else if (Arg.getKind() == TemplateArgument::Type) {
941 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
942 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
943 else
944 return TSIOrErr.takeError();
945 } else {
946 auto ToTemplateQualifierLocOrErr =
947 import(FromInfo.getTemplateQualifierLoc());
948 if (!ToTemplateQualifierLocOrErr)
949 return ToTemplateQualifierLocOrErr.takeError();
950 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
951 if (!ToTemplateNameLocOrErr)
952 return ToTemplateNameLocOrErr.takeError();
953 auto ToTemplateEllipsisLocOrErr =
954 import(FromInfo.getTemplateEllipsisLoc());
955 if (!ToTemplateEllipsisLocOrErr)
956 return ToTemplateEllipsisLocOrErr.takeError();
958 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
959 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
960 }
961
962 return TemplateArgumentLoc(Arg, ToInfo);
963}
964
965template <>
966Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
967 if (DG.isNull())
968 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
969 size_t NumDecls = DG.end() - DG.begin();
971 ToDecls.reserve(NumDecls);
972 for (Decl *FromD : DG) {
973 if (auto ToDOrErr = import(FromD))
974 ToDecls.push_back(*ToDOrErr);
975 else
976 return ToDOrErr.takeError();
977 }
978 return DeclGroupRef::Create(Importer.getToContext(),
979 ToDecls.begin(),
980 NumDecls);
981}
982
983template <>
985ASTNodeImporter::import(const Designator &D) {
986 if (D.isFieldDesignator()) {
987 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
988
989 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
990 if (!ToDotLocOrErr)
991 return ToDotLocOrErr.takeError();
992
993 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
994 if (!ToFieldLocOrErr)
995 return ToFieldLocOrErr.takeError();
996
998 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
999 }
1000
1001 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
1002 if (!ToLBracketLocOrErr)
1003 return ToLBracketLocOrErr.takeError();
1004
1005 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
1006 if (!ToRBracketLocOrErr)
1007 return ToRBracketLocOrErr.takeError();
1008
1009 if (D.isArrayDesignator())
1010 return Designator::CreateArrayDesignator(D.getArrayIndex(),
1011 *ToLBracketLocOrErr,
1012 *ToRBracketLocOrErr);
1013
1014 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1015 if (!ToEllipsisLocOrErr)
1016 return ToEllipsisLocOrErr.takeError();
1017
1018 assert(D.isArrayRangeDesignator());
1020 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1021 *ToRBracketLocOrErr);
1022}
1023
1024template <>
1025Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1026 Error Err = Error::success();
1027 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1028 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1029 auto ToConceptNameLoc =
1030 importChecked(Err, From->getConceptNameInfo().getLoc());
1031 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1032 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1033 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1034 if (Err)
1035 return std::move(Err);
1036 TemplateArgumentListInfo ToTAInfo;
1037 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1038 if (ASTTemplateArgs)
1039 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1040 return std::move(Err);
1041 auto *ConceptRef = ConceptReference::Create(
1042 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1043 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1044 ToNamedConcept,
1045 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1046 Importer.getToContext(), ToTAInfo)
1047 : nullptr);
1048 return ConceptRef;
1049}
1050
1051template <>
1052Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1053 ValueDecl *Var = nullptr;
1054 if (From.capturesVariable()) {
1055 if (auto VarOrErr = import(From.getCapturedVar()))
1056 Var = *VarOrErr;
1057 else
1058 return VarOrErr.takeError();
1059 }
1060
1061 auto LocationOrErr = import(From.getLocation());
1062 if (!LocationOrErr)
1063 return LocationOrErr.takeError();
1064
1065 SourceLocation EllipsisLoc;
1066 if (From.isPackExpansion())
1067 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1068 return std::move(Err);
1069
1070 return LambdaCapture(
1071 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1072 EllipsisLoc);
1073}
1074
1075template <typename T>
1077 if (Found->getLinkageInternal() != From->getLinkageInternal())
1078 return false;
1079
1080 if (From->hasExternalFormalLinkage())
1081 return Found->hasExternalFormalLinkage();
1082 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1083 return false;
1084 if (From->isInAnonymousNamespace())
1085 return Found->isInAnonymousNamespace();
1086 else
1087 return !Found->isInAnonymousNamespace() &&
1088 !Found->hasExternalFormalLinkage();
1089}
1090
1091template <>
1093 TypedefNameDecl *From) {
1094 if (Found->getLinkageInternal() != From->getLinkageInternal())
1095 return false;
1096
1097 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1098 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1099 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1100}
1101
1102} // namespace clang
1103
1104//----------------------------------------------------------------------------
1105// Import Types
1106//----------------------------------------------------------------------------
1107
1108using namespace clang;
1109
1111 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1112 << T->getTypeClassName();
1113 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1114}
1115
1116ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1117 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1118 if (!UnderlyingTypeOrErr)
1119 return UnderlyingTypeOrErr.takeError();
1120
1121 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1122}
1123
1124ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1125 switch (T->getKind()) {
1126#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1127 case BuiltinType::Id: \
1128 return Importer.getToContext().SingletonId;
1129#include "clang/Basic/OpenCLImageTypes.def"
1130#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1131 case BuiltinType::Id: \
1132 return Importer.getToContext().Id##Ty;
1133#include "clang/Basic/OpenCLExtensionTypes.def"
1134#define SVE_TYPE(Name, Id, SingletonId) \
1135 case BuiltinType::Id: \
1136 return Importer.getToContext().SingletonId;
1137#include "clang/Basic/AArch64SVEACLETypes.def"
1138#define PPC_VECTOR_TYPE(Name, Id, Size) \
1139 case BuiltinType::Id: \
1140 return Importer.getToContext().Id##Ty;
1141#include "clang/Basic/PPCTypes.def"
1142#define RVV_TYPE(Name, Id, SingletonId) \
1143 case BuiltinType::Id: \
1144 return Importer.getToContext().SingletonId;
1145#include "clang/Basic/RISCVVTypes.def"
1146#define WASM_TYPE(Name, Id, SingletonId) \
1147 case BuiltinType::Id: \
1148 return Importer.getToContext().SingletonId;
1149#include "clang/Basic/WebAssemblyReferenceTypes.def"
1150#define AMDGPU_TYPE(Name, Id, SingletonId) \
1151 case BuiltinType::Id: \
1152 return Importer.getToContext().SingletonId;
1153#include "clang/Basic/AMDGPUTypes.def"
1154#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1155 case BuiltinType::Id: \
1156 return Importer.getToContext().SingletonId;
1157#include "clang/Basic/HLSLIntangibleTypes.def"
1158#define SHARED_SINGLETON_TYPE(Expansion)
1159#define BUILTIN_TYPE(Id, SingletonId) \
1160 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1161#include "clang/AST/BuiltinTypes.def"
1162
1163 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1164 // context supports C++.
1165
1166 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1167 // context supports ObjC.
1168
1169 case BuiltinType::Char_U:
1170 // The context we're importing from has an unsigned 'char'. If we're
1171 // importing into a context with a signed 'char', translate to
1172 // 'unsigned char' instead.
1173 if (Importer.getToContext().getLangOpts().CharIsSigned)
1174 return Importer.getToContext().UnsignedCharTy;
1175
1176 return Importer.getToContext().CharTy;
1177
1178 case BuiltinType::Char_S:
1179 // The context we're importing from has an unsigned 'char'. If we're
1180 // importing into a context with a signed 'char', translate to
1181 // 'unsigned char' instead.
1182 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1183 return Importer.getToContext().SignedCharTy;
1184
1185 return Importer.getToContext().CharTy;
1186
1187 case BuiltinType::WChar_S:
1188 case BuiltinType::WChar_U:
1189 // FIXME: If not in C++, shall we translate to the C equivalent of
1190 // wchar_t?
1191 return Importer.getToContext().WCharTy;
1192 }
1193
1194 llvm_unreachable("Invalid BuiltinType Kind!");
1195}
1196
1197ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1198 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1199 if (!ToOriginalTypeOrErr)
1200 return ToOriginalTypeOrErr.takeError();
1201
1202 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1203}
1204
1205ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1206 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1207 if (!ToElementTypeOrErr)
1208 return ToElementTypeOrErr.takeError();
1209
1210 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1211}
1212
1213ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1214 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1215 if (!ToPointeeTypeOrErr)
1216 return ToPointeeTypeOrErr.takeError();
1217
1218 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1219}
1220
1221ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1222 // FIXME: Check for blocks support in "to" context.
1223 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1224 if (!ToPointeeTypeOrErr)
1225 return ToPointeeTypeOrErr.takeError();
1226
1227 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1228}
1229
1231ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1232 // FIXME: Check for C++ support in "to" context.
1233 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1234 if (!ToPointeeTypeOrErr)
1235 return ToPointeeTypeOrErr.takeError();
1236
1237 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1238}
1239
1241ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1242 // FIXME: Check for C++0x support in "to" context.
1243 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1244 if (!ToPointeeTypeOrErr)
1245 return ToPointeeTypeOrErr.takeError();
1246
1247 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1248}
1249
1251ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1252 // FIXME: Check for C++ support in "to" context.
1253 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1254 if (!ToPointeeTypeOrErr)
1255 return ToPointeeTypeOrErr.takeError();
1256
1257 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1258 if (!ClassTypeOrErr)
1259 return ClassTypeOrErr.takeError();
1260
1261 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1262 *ClassTypeOrErr);
1263}
1264
1266ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1267 Error Err = Error::success();
1268 auto ToElementType = importChecked(Err, T->getElementType());
1269 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1270 if (Err)
1271 return std::move(Err);
1272
1273 return Importer.getToContext().getConstantArrayType(
1274 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1275 T->getIndexTypeCVRQualifiers());
1276}
1277
1279ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1280 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1281 if (!ToArrayTypeOrErr)
1282 return ToArrayTypeOrErr.takeError();
1283
1284 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1285}
1286
1288ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1289 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1290 if (!ToElementTypeOrErr)
1291 return ToElementTypeOrErr.takeError();
1292
1293 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1294 T->getSizeModifier(),
1295 T->getIndexTypeCVRQualifiers());
1296}
1297
1299ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1300 Error Err = Error::success();
1301 QualType ToElementType = importChecked(Err, T->getElementType());
1302 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1303 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1304 if (Err)
1305 return std::move(Err);
1306 return Importer.getToContext().getVariableArrayType(
1307 ToElementType, ToSizeExpr, T->getSizeModifier(),
1308 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1309}
1310
1311ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1312 const DependentSizedArrayType *T) {
1313 Error Err = Error::success();
1314 QualType ToElementType = importChecked(Err, T->getElementType());
1315 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1316 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1317 if (Err)
1318 return std::move(Err);
1319 // SizeExpr may be null if size is not specified directly.
1320 // For example, 'int a[]'.
1321
1322 return Importer.getToContext().getDependentSizedArrayType(
1323 ToElementType, ToSizeExpr, T->getSizeModifier(),
1324 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1325}
1326
1327ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1329 Error Err = Error::success();
1330 QualType ToElementType = importChecked(Err, T->getElementType());
1331 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1332 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1333 if (Err)
1334 return std::move(Err);
1336 ToElementType, ToSizeExpr, ToAttrLoc);
1337}
1338
1339ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1340 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1341 if (!ToElementTypeOrErr)
1342 return ToElementTypeOrErr.takeError();
1343
1344 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1345 T->getNumElements(),
1346 T->getVectorKind());
1347}
1348
1349ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1350 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1351 if (!ToElementTypeOrErr)
1352 return ToElementTypeOrErr.takeError();
1353
1354 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1355 T->getNumElements());
1356}
1357
1359ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1360 // FIXME: What happens if we're importing a function without a prototype
1361 // into C++? Should we make it variadic?
1362 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1363 if (!ToReturnTypeOrErr)
1364 return ToReturnTypeOrErr.takeError();
1365
1366 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1367 T->getExtInfo());
1368}
1369
1371ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1372 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1373 if (!ToReturnTypeOrErr)
1374 return ToReturnTypeOrErr.takeError();
1375
1376 // Import argument types
1377 SmallVector<QualType, 4> ArgTypes;
1378 for (const auto &A : T->param_types()) {
1379 ExpectedType TyOrErr = import(A);
1380 if (!TyOrErr)
1381 return TyOrErr.takeError();
1382 ArgTypes.push_back(*TyOrErr);
1383 }
1384
1385 // Import exception types
1386 SmallVector<QualType, 4> ExceptionTypes;
1387 for (const auto &E : T->exceptions()) {
1388 ExpectedType TyOrErr = import(E);
1389 if (!TyOrErr)
1390 return TyOrErr.takeError();
1391 ExceptionTypes.push_back(*TyOrErr);
1392 }
1393
1395 Error Err = Error::success();
1397 ToEPI.ExtInfo = FromEPI.ExtInfo;
1398 ToEPI.Variadic = FromEPI.Variadic;
1399 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1400 ToEPI.TypeQuals = FromEPI.TypeQuals;
1401 ToEPI.RefQualifier = FromEPI.RefQualifier;
1402 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1409 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1410
1411 if (Err)
1412 return std::move(Err);
1413
1414 return Importer.getToContext().getFunctionType(
1415 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1416}
1417
1418ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1419 const UnresolvedUsingType *T) {
1420 Error Err = Error::success();
1421 auto ToD = importChecked(Err, T->getDecl());
1422 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1423 if (Err)
1424 return std::move(Err);
1425
1426 return Importer.getToContext().getTypeDeclType(
1427 ToD, cast_or_null<TypeDecl>(ToPrevD));
1428}
1429
1430ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1431 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1432 if (!ToInnerTypeOrErr)
1433 return ToInnerTypeOrErr.takeError();
1434
1435 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1436}
1437
1439ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1440
1441 ExpectedType Pattern = import(T->getPattern());
1442 if (!Pattern)
1443 return Pattern.takeError();
1444 ExpectedExpr Index = import(T->getIndexExpr());
1445 if (!Index)
1446 return Index.takeError();
1447 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1448}
1449
1450ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1451 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1452 if (!ToDeclOrErr)
1453 return ToDeclOrErr.takeError();
1454
1455 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1456 if (ToDecl->getTypeForDecl())
1457 return QualType(ToDecl->getTypeForDecl(), 0);
1458
1459 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1460 if (!ToUnderlyingTypeOrErr)
1461 return ToUnderlyingTypeOrErr.takeError();
1462
1463 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1464}
1465
1466ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1467 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1468 if (!ToExprOrErr)
1469 return ToExprOrErr.takeError();
1470 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1471}
1472
1473ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1474 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1475 if (!ToUnderlyingTypeOrErr)
1476 return ToUnderlyingTypeOrErr.takeError();
1477 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1478 T->getKind());
1479}
1480
1481ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1482 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1483 if (!FoundOrErr)
1484 return FoundOrErr.takeError();
1485 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1486 if (!UnderlyingOrErr)
1487 return UnderlyingOrErr.takeError();
1488
1489 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1490}
1491
1492ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1493 // FIXME: Make sure that the "to" context supports C++0x!
1494 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1495 if (!ToExprOrErr)
1496 return ToExprOrErr.takeError();
1497
1498 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1499 if (!ToUnderlyingTypeOrErr)
1500 return ToUnderlyingTypeOrErr.takeError();
1501
1502 return Importer.getToContext().getDecltypeType(
1503 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1504}
1505
1507ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1508 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1509 if (!ToBaseTypeOrErr)
1510 return ToBaseTypeOrErr.takeError();
1511
1512 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1513 if (!ToUnderlyingTypeOrErr)
1514 return ToUnderlyingTypeOrErr.takeError();
1515
1516 return Importer.getToContext().getUnaryTransformType(
1517 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1518}
1519
1520ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1521 // FIXME: Make sure that the "to" context supports C++11!
1522 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1523 if (!ToDeducedTypeOrErr)
1524 return ToDeducedTypeOrErr.takeError();
1525
1526 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1527 if (!ToTypeConstraintConcept)
1528 return ToTypeConstraintConcept.takeError();
1529
1530 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1531 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1532 ToTemplateArgs))
1533 return std::move(Err);
1534
1535 return Importer.getToContext().getAutoType(
1536 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1537 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1538 ToTemplateArgs);
1539}
1540
1541ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1543 // FIXME: Make sure that the "to" context supports C++17!
1544 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1545 if (!ToTemplateNameOrErr)
1546 return ToTemplateNameOrErr.takeError();
1547 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1548 if (!ToDeducedTypeOrErr)
1549 return ToDeducedTypeOrErr.takeError();
1550
1552 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1553}
1554
1555ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1556 const InjectedClassNameType *T) {
1557 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1558 if (!ToDeclOrErr)
1559 return ToDeclOrErr.takeError();
1560
1561 // The InjectedClassNameType is created in VisitRecordDecl when the
1562 // T->getDecl() is imported. Here we can return the existing type.
1563 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1564 assert(isa_and_nonnull<InjectedClassNameType>(Ty));
1565 return QualType(Ty, 0);
1566}
1567
1568ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1569 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1570 if (!ToDeclOrErr)
1571 return ToDeclOrErr.takeError();
1572
1573 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1574}
1575
1576ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1577 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1578 if (!ToDeclOrErr)
1579 return ToDeclOrErr.takeError();
1580
1581 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1582}
1583
1584ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1585 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1586 if (!ToModifiedTypeOrErr)
1587 return ToModifiedTypeOrErr.takeError();
1588 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1589 if (!ToEquivalentTypeOrErr)
1590 return ToEquivalentTypeOrErr.takeError();
1591
1592 return Importer.getToContext().getAttributedType(T->getAttrKind(),
1593 *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr);
1594}
1595
1597ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1598 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1599 if (!ToWrappedTypeOrErr)
1600 return ToWrappedTypeOrErr.takeError();
1601
1602 Error Err = Error::success();
1603 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1604
1606 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1607 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1608 if (!ToDeclOrErr)
1609 return ToDeclOrErr.takeError();
1610 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1611 }
1612
1613 return Importer.getToContext().getCountAttributedType(
1614 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1615 ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1616}
1617
1618ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1619 const TemplateTypeParmType *T) {
1620 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1621 if (!ToDeclOrErr)
1622 return ToDeclOrErr.takeError();
1623
1624 return Importer.getToContext().getTemplateTypeParmType(
1625 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1626}
1627
1628ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1630 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1631 if (!ReplacedOrErr)
1632 return ReplacedOrErr.takeError();
1633
1634 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1635 if (!ToReplacementTypeOrErr)
1636 return ToReplacementTypeOrErr.takeError();
1637
1639 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(),
1640 T->getPackIndex());
1641}
1642
1643ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1645 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1646 if (!ReplacedOrErr)
1647 return ReplacedOrErr.takeError();
1648
1649 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1650 if (!ToArgumentPack)
1651 return ToArgumentPack.takeError();
1652
1654 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1655}
1656
1657ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1659 auto ToTemplateOrErr = import(T->getTemplateName());
1660 if (!ToTemplateOrErr)
1661 return ToTemplateOrErr.takeError();
1662
1663 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1664 if (Error Err =
1665 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1666 return std::move(Err);
1667
1668 QualType ToCanonType;
1669 if (!T->isCanonicalUnqualified()) {
1670 QualType FromCanonType
1671 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1672 if (ExpectedType TyOrErr = import(FromCanonType))
1673 ToCanonType = *TyOrErr;
1674 else
1675 return TyOrErr.takeError();
1676 }
1677 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1678 ToTemplateArgs,
1679 ToCanonType);
1680}
1681
1682ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1683 // Note: the qualifier in an ElaboratedType is optional.
1684 auto ToQualifierOrErr = import(T->getQualifier());
1685 if (!ToQualifierOrErr)
1686 return ToQualifierOrErr.takeError();
1687
1688 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1689 if (!ToNamedTypeOrErr)
1690 return ToNamedTypeOrErr.takeError();
1691
1692 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1693 if (!ToOwnedTagDeclOrErr)
1694 return ToOwnedTagDeclOrErr.takeError();
1695
1696 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1697 *ToQualifierOrErr,
1698 *ToNamedTypeOrErr,
1699 *ToOwnedTagDeclOrErr);
1700}
1701
1703ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1704 ExpectedType ToPatternOrErr = import(T->getPattern());
1705 if (!ToPatternOrErr)
1706 return ToPatternOrErr.takeError();
1707
1708 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1709 T->getNumExpansions(),
1710 /*ExpactPack=*/false);
1711}
1712
1713ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1715 auto ToQualifierOrErr = import(T->getQualifier());
1716 if (!ToQualifierOrErr)
1717 return ToQualifierOrErr.takeError();
1718
1719 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1720
1722 ToPack.reserve(T->template_arguments().size());
1723 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1724 return std::move(Err);
1725
1727 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1728}
1729
1731ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1732 auto ToQualifierOrErr = import(T->getQualifier());
1733 if (!ToQualifierOrErr)
1734 return ToQualifierOrErr.takeError();
1735
1736 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1737
1738 QualType Canon;
1739 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1740 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1741 Canon = (*TyOrErr).getCanonicalType();
1742 else
1743 return TyOrErr.takeError();
1744 }
1745
1746 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1747 *ToQualifierOrErr,
1748 Name, Canon);
1749}
1750
1752ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1753 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1754 if (!ToDeclOrErr)
1755 return ToDeclOrErr.takeError();
1756
1757 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1758}
1759
1760ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1761 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1762 if (!ToBaseTypeOrErr)
1763 return ToBaseTypeOrErr.takeError();
1764
1765 SmallVector<QualType, 4> TypeArgs;
1766 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1767 if (ExpectedType TyOrErr = import(TypeArg))
1768 TypeArgs.push_back(*TyOrErr);
1769 else
1770 return TyOrErr.takeError();
1771 }
1772
1774 for (auto *P : T->quals()) {
1775 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1776 Protocols.push_back(*ProtocolOrErr);
1777 else
1778 return ProtocolOrErr.takeError();
1779
1780 }
1781
1782 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1783 Protocols,
1784 T->isKindOfTypeAsWritten());
1785}
1786
1788ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1789 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1790 if (!ToPointeeTypeOrErr)
1791 return ToPointeeTypeOrErr.takeError();
1792
1793 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1794}
1795
1797ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1798 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1799 if (!ToUnderlyingTypeOrErr)
1800 return ToUnderlyingTypeOrErr.takeError();
1801
1802 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1803 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1804 ToIdentifier);
1805}
1806
1807ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1808 Error Err = Error::success();
1809 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1810 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1811 if (Err)
1812 return std::move(Err);
1813
1814 return Importer.getToContext().getAdjustedType(ToOriginalType,
1815 ToAdjustedType);
1816}
1817
1818ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1819 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1820 T->getNumBits());
1821}
1822
1823ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1825 Error Err = Error::success();
1826 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1827 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1828 if (Err)
1829 return std::move(Err);
1830
1831 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1832 ToWrappedType);
1833}
1834
1835ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1837 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1838 if (!ToElementTypeOrErr)
1839 return ToElementTypeOrErr.takeError();
1840
1841 return Importer.getToContext().getConstantMatrixType(
1842 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1843}
1844
1845ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1847 Error Err = Error::success();
1848 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1849 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1850 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1851 if (Err)
1852 return std::move(Err);
1853
1854 return Importer.getToContext().getDependentAddressSpaceType(
1855 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1856}
1857
1858ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1860 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1861 if (!ToNumBitsExprOrErr)
1862 return ToNumBitsExprOrErr.takeError();
1863 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1864 *ToNumBitsExprOrErr);
1865}
1866
1867ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1869 Error Err = Error::success();
1870 QualType ToElementType = importChecked(Err, T->getElementType());
1871 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1872 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1873 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1874 if (Err)
1875 return std::move(Err);
1876
1877 return Importer.getToContext().getDependentSizedMatrixType(
1878 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1879}
1880
1881ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1883 Error Err = Error::success();
1884 QualType ToElementType = importChecked(Err, T->getElementType());
1885 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1886 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1887 if (Err)
1888 return std::move(Err);
1889
1890 return Importer.getToContext().getDependentVectorType(
1891 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1892}
1893
1894ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1895 const clang::ObjCTypeParamType *T) {
1896 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1897 if (!ToDeclOrErr)
1898 return ToDeclOrErr.takeError();
1899
1901 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1902 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1903 if (!ToProtocolOrErr)
1904 return ToProtocolOrErr.takeError();
1905 ToProtocols.push_back(*ToProtocolOrErr);
1906 }
1907
1908 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1909 ToProtocols);
1910}
1911
1912ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1913 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1914 if (!ToElementTypeOrErr)
1915 return ToElementTypeOrErr.takeError();
1916
1917 ASTContext &ToCtx = Importer.getToContext();
1918 if (T->isReadOnly())
1919 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1920 else
1921 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1922}
1923
1924//----------------------------------------------------------------------------
1925// Import Declarations
1926//----------------------------------------------------------------------------
1928 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1930 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1931 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1932 // FIXME: We could support these constructs by importing a different type of
1933 // this parameter and by importing the original type of the parameter only
1934 // after the FunctionDecl is created. See
1935 // VisitFunctionDecl::UsedDifferentProtoType.
1936 DeclContext *OrigDC = D->getDeclContext();
1937 FunctionDecl *FunDecl;
1938 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1939 FunDecl->hasBody()) {
1940 auto getLeafPointeeType = [](const Type *T) {
1941 while (T->isPointerType() || T->isArrayType()) {
1943 }
1944 return T;
1945 };
1946 for (const ParmVarDecl *P : FunDecl->parameters()) {
1947 const Type *LeafT =
1948 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1949 auto *RT = dyn_cast<RecordType>(LeafT);
1950 if (RT && RT->getDecl() == D) {
1951 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1952 << D->getDeclKindName();
1953 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1954 }
1955 }
1956 }
1957
1958 // Import the context of this declaration.
1959 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1960 return Err;
1961
1962 // Import the name of this declaration.
1963 if (Error Err = importInto(Name, D->getDeclName()))
1964 return Err;
1965
1966 // Import the location of this declaration.
1967 if (Error Err = importInto(Loc, D->getLocation()))
1968 return Err;
1969
1970 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1971 if (ToD)
1972 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1973 return Err;
1974
1975 return Error::success();
1976}
1977
1979 NamedDecl *&ToD, SourceLocation &Loc) {
1980
1981 // Import the name of this declaration.
1982 if (Error Err = importInto(Name, D->getDeclName()))
1983 return Err;
1984
1985 // Import the location of this declaration.
1986 if (Error Err = importInto(Loc, D->getLocation()))
1987 return Err;
1988
1989 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1990 if (ToD)
1991 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1992 return Err;
1993
1994 return Error::success();
1995}
1996
1998 if (!FromD)
1999 return Error::success();
2000
2001 if (!ToD)
2002 if (Error Err = importInto(ToD, FromD))
2003 return Err;
2004
2005 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2006 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2007 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2008 !ToRecord->getDefinition()) {
2009 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2010 return Err;
2011 }
2012 }
2013 return Error::success();
2014 }
2015
2016 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2017 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2018 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2019 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2020 return Err;
2021 }
2022 }
2023 return Error::success();
2024 }
2025
2026 return Error::success();
2027}
2028
2029Error
2031 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2032 // NOTE: To.Name and To.Loc are already imported.
2033 // We only have to import To.LocInfo.
2034 switch (To.getName().getNameKind()) {
2041 return Error::success();
2042
2044 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2045 To.setCXXOperatorNameRange(*ToRangeOrErr);
2046 else
2047 return ToRangeOrErr.takeError();
2048 return Error::success();
2049 }
2051 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2052 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2053 else
2054 return LocOrErr.takeError();
2055 return Error::success();
2056 }
2060 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2061 To.setNamedTypeInfo(*ToTInfoOrErr);
2062 else
2063 return ToTInfoOrErr.takeError();
2064 return Error::success();
2065 }
2066 }
2067 llvm_unreachable("Unknown name kind.");
2068}
2069
2070Error
2072 if (Importer.isMinimalImport() && !ForceImport) {
2073 auto ToDCOrErr = Importer.ImportContext(FromDC);
2074 return ToDCOrErr.takeError();
2075 }
2076
2077 // We use strict error handling in case of records and enums, but not
2078 // with e.g. namespaces.
2079 //
2080 // FIXME Clients of the ASTImporter should be able to choose an
2081 // appropriate error handling strategy for their needs. For instance,
2082 // they may not want to mark an entire namespace as erroneous merely
2083 // because there is an ODR error with two typedefs. As another example,
2084 // the client may allow EnumConstantDecls with same names but with
2085 // different values in two distinct translation units.
2086 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2087
2088 auto MightNeedReordering = [](const Decl *D) {
2089 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2090 };
2091
2092 // Import everything that might need reordering first.
2093 Error ChildErrors = Error::success();
2094 for (auto *From : FromDC->decls()) {
2095 if (!MightNeedReordering(From))
2096 continue;
2097
2098 ExpectedDecl ImportedOrErr = import(From);
2099
2100 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2101 // want to make sure that we are also completing each FieldDecl. There
2102 // are currently cases where this does not happen and this is correctness
2103 // fix since operations such as code generation will expect this to be so.
2104 if (!ImportedOrErr) {
2105 HandleChildErrors.handleChildImportResult(ChildErrors,
2106 ImportedOrErr.takeError());
2107 continue;
2108 }
2109 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2110 Decl *ImportedDecl = *ImportedOrErr;
2111 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2112 if (FieldFrom && FieldTo) {
2113 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2114 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2115 }
2116 }
2117
2118 // We reorder declarations in RecordDecls because they may have another order
2119 // in the "to" context than they have in the "from" context. This may happen
2120 // e.g when we import a class like this:
2121 // struct declToImport {
2122 // int a = c + b;
2123 // int b = 1;
2124 // int c = 2;
2125 // };
2126 // During the import of `a` we import first the dependencies in sequence,
2127 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2128 // first removing the already imported members and then adding them in the
2129 // order as they appear in the "from" context.
2130 //
2131 // Keeping field order is vital because it determines structure layout.
2132 //
2133 // Here and below, we cannot call field_begin() method and its callers on
2134 // ToDC if it has an external storage. Calling field_begin() will
2135 // automatically load all the fields by calling
2136 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2137 // call ASTImporter::Import(). This is because the ExternalASTSource
2138 // interface in LLDB is implemented by the means of the ASTImporter. However,
2139 // calling an import at this point would result in an uncontrolled import, we
2140 // must avoid that.
2141
2142 auto ToDCOrErr = Importer.ImportContext(FromDC);
2143 if (!ToDCOrErr) {
2144 consumeError(std::move(ChildErrors));
2145 return ToDCOrErr.takeError();
2146 }
2147
2148 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2149 DeclContext *ToDC = *ToDCOrErr;
2150 // Remove all declarations, which may be in wrong order in the
2151 // lexical DeclContext and then add them in the proper order.
2152 for (auto *D : FromRD->decls()) {
2153 if (!MightNeedReordering(D))
2154 continue;
2155
2156 assert(D && "DC contains a null decl");
2157 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2158 // Remove only the decls which we successfully imported.
2159 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2160 // Remove the decl from its wrong place in the linked list.
2161 ToDC->removeDecl(ToD);
2162 // Add the decl to the end of the linked list.
2163 // This time it will be at the proper place because the enclosing for
2164 // loop iterates in the original (good) order of the decls.
2165 ToDC->addDeclInternal(ToD);
2166 }
2167 }
2168 }
2169
2170 // Import everything else.
2171 for (auto *From : FromDC->decls()) {
2172 if (MightNeedReordering(From))
2173 continue;
2174
2175 ExpectedDecl ImportedOrErr = import(From);
2176 if (!ImportedOrErr)
2177 HandleChildErrors.handleChildImportResult(ChildErrors,
2178 ImportedOrErr.takeError());
2179 }
2180
2181 return ChildErrors;
2182}
2183
2185 const FieldDecl *To) {
2186 RecordDecl *FromRecordDecl = nullptr;
2187 RecordDecl *ToRecordDecl = nullptr;
2188 // If we have a field that is an ArrayType we need to check if the array
2189 // element is a RecordDecl and if so we need to import the definition.
2190 QualType FromType = From->getType();
2191 QualType ToType = To->getType();
2192 if (FromType->isArrayType()) {
2193 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2194 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2195 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2196 }
2197
2198 if (!FromRecordDecl || !ToRecordDecl) {
2199 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2200 const RecordType *RecordTo = ToType->getAs<RecordType>();
2201
2202 if (RecordFrom && RecordTo) {
2203 FromRecordDecl = RecordFrom->getDecl();
2204 ToRecordDecl = RecordTo->getDecl();
2205 }
2206 }
2207
2208 if (FromRecordDecl && ToRecordDecl) {
2209 if (FromRecordDecl->isCompleteDefinition() &&
2210 !ToRecordDecl->isCompleteDefinition())
2211 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2212 }
2213
2214 return Error::success();
2215}
2216
2218 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2219 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2220 if (!ToDCOrErr)
2221 return ToDCOrErr.takeError();
2222 ToDC = *ToDCOrErr;
2223
2224 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2225 auto ToLexicalDCOrErr = Importer.ImportContext(
2226 FromD->getLexicalDeclContext());
2227 if (!ToLexicalDCOrErr)
2228 return ToLexicalDCOrErr.takeError();
2229 ToLexicalDC = *ToLexicalDCOrErr;
2230 } else
2231 ToLexicalDC = ToDC;
2232
2233 return Error::success();
2234}
2235
2237 const CXXRecordDecl *From, CXXRecordDecl *To) {
2238 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2239 "Import implicit methods to or from non-definition");
2240
2241 for (CXXMethodDecl *FromM : From->methods())
2242 if (FromM->isImplicit()) {
2243 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2244 if (!ToMOrErr)
2245 return ToMOrErr.takeError();
2246 }
2247
2248 return Error::success();
2249}
2250
2252 ASTImporter &Importer) {
2253 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2254 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2255 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2256 else
2257 return ToTypedefOrErr.takeError();
2258 }
2259 return Error::success();
2260}
2261
2263 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2264 auto DefinitionCompleter = [To]() {
2265 // There are cases in LLDB when we first import a class without its
2266 // members. The class will have DefinitionData, but no members. Then,
2267 // importDefinition is called from LLDB, which tries to get the members, so
2268 // when we get here, the class already has the DefinitionData set, so we
2269 // must unset the CompleteDefinition here to be able to complete again the
2270 // definition.
2271 To->setCompleteDefinition(false);
2272 To->completeDefinition();
2273 };
2274
2275 if (To->getDefinition() || To->isBeingDefined()) {
2276 if (Kind == IDK_Everything ||
2277 // In case of lambdas, the class already has a definition ptr set, but
2278 // the contained decls are not imported yet. Also, isBeingDefined was
2279 // set in CXXRecordDecl::CreateLambda. We must import the contained
2280 // decls here and finish the definition.
2281 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2282 if (To->isLambda()) {
2283 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2285 ToCaptures.reserve(FromCXXRD->capture_size());
2286 for (const auto &FromCapture : FromCXXRD->captures()) {
2287 if (auto ToCaptureOrErr = import(FromCapture))
2288 ToCaptures.push_back(*ToCaptureOrErr);
2289 else
2290 return ToCaptureOrErr.takeError();
2291 }
2292 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2293 ToCaptures);
2294 }
2295
2296 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2297 // Finish the definition of the lambda, set isBeingDefined to false.
2298 if (To->isLambda())
2299 DefinitionCompleter();
2300 return Result;
2301 }
2302
2303 return Error::success();
2304 }
2305
2306 To->startDefinition();
2307 // Set the definition to complete even if it is really not complete during
2308 // import. Some AST constructs (expressions) require the record layout
2309 // to be calculated (see 'clang::computeDependence') at the time they are
2310 // constructed. Import of such AST node is possible during import of the
2311 // same record, there is no way to have a completely defined record (all
2312 // fields imported) at that time without multiple AST import passes.
2313 if (!Importer.isMinimalImport())
2314 To->setCompleteDefinition(true);
2315 // Complete the definition even if error is returned.
2316 // The RecordDecl may be already part of the AST so it is better to
2317 // have it in complete state even if something is wrong with it.
2318 auto DefinitionCompleterScopeExit =
2319 llvm::make_scope_exit(DefinitionCompleter);
2320
2321 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2322 return Err;
2323
2324 // Add base classes.
2325 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2326 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2327 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2328
2329 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2330 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2331
2332 #define FIELD(Name, Width, Merge) \
2333 ToData.Name = FromData.Name;
2334 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2335
2336 // Copy over the data stored in RecordDeclBits
2337 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2338
2340 for (const auto &Base1 : FromCXX->bases()) {
2341 ExpectedType TyOrErr = import(Base1.getType());
2342 if (!TyOrErr)
2343 return TyOrErr.takeError();
2344
2345 SourceLocation EllipsisLoc;
2346 if (Base1.isPackExpansion()) {
2347 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2348 EllipsisLoc = *LocOrErr;
2349 else
2350 return LocOrErr.takeError();
2351 }
2352
2353 // Ensure that we have a definition for the base.
2354 if (Error Err =
2355 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2356 return Err;
2357
2358 auto RangeOrErr = import(Base1.getSourceRange());
2359 if (!RangeOrErr)
2360 return RangeOrErr.takeError();
2361
2362 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2363 if (!TSIOrErr)
2364 return TSIOrErr.takeError();
2365
2366 Bases.push_back(
2367 new (Importer.getToContext()) CXXBaseSpecifier(
2368 *RangeOrErr,
2369 Base1.isVirtual(),
2370 Base1.isBaseOfClass(),
2371 Base1.getAccessSpecifierAsWritten(),
2372 *TSIOrErr,
2373 EllipsisLoc));
2374 }
2375 if (!Bases.empty())
2376 ToCXX->setBases(Bases.data(), Bases.size());
2377 }
2378
2380 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2381 return Err;
2382 }
2383
2384 return Error::success();
2385}
2386
2388 if (To->getAnyInitializer())
2389 return Error::success();
2390
2391 Expr *FromInit = From->getInit();
2392 if (!FromInit)
2393 return Error::success();
2394
2395 ExpectedExpr ToInitOrErr = import(FromInit);
2396 if (!ToInitOrErr)
2397 return ToInitOrErr.takeError();
2398
2399 To->setInit(*ToInitOrErr);
2400 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2401 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2402 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2403 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2404 // FIXME: Also import the initializer value.
2405 }
2406
2407 // FIXME: Other bits to merge?
2408 return Error::success();
2409}
2410
2413 if (To->getDefinition() || To->isBeingDefined()) {
2414 if (Kind == IDK_Everything)
2415 return ImportDeclContext(From, /*ForceImport=*/true);
2416 return Error::success();
2417 }
2418
2419 To->startDefinition();
2420
2421 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2422 return Err;
2423
2424 ExpectedType ToTypeOrErr =
2425 import(Importer.getFromContext().getTypeDeclType(From));
2426 if (!ToTypeOrErr)
2427 return ToTypeOrErr.takeError();
2428
2429 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2430 if (!ToPromotionTypeOrErr)
2431 return ToPromotionTypeOrErr.takeError();
2432
2434 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2435 return Err;
2436
2437 // FIXME: we might need to merge the number of positive or negative bits
2438 // if the enumerator lists don't match.
2439 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2440 From->getNumPositiveBits(),
2441 From->getNumNegativeBits());
2442 return Error::success();
2443}
2444
2448 for (const auto &Arg : FromArgs) {
2449 if (auto ToOrErr = import(Arg))
2450 ToArgs.push_back(*ToOrErr);
2451 else
2452 return ToOrErr.takeError();
2453 }
2454
2455 return Error::success();
2456}
2457
2458// FIXME: Do not forget to remove this and use only 'import'.
2461 return import(From);
2462}
2463
2464template <typename InContainerTy>
2466 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2467 for (const auto &FromLoc : Container) {
2468 if (auto ToLocOrErr = import(FromLoc))
2469 ToTAInfo.addArgument(*ToLocOrErr);
2470 else
2471 return ToLocOrErr.takeError();
2472 }
2473 return Error::success();
2474}
2475
2480}
2481
2482bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2483 bool IgnoreTemplateParmDepth) {
2484 // Eliminate a potential failure point where we attempt to re-import
2485 // something we're trying to import while completing ToRecord.
2486 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2487 if (ToOrigin) {
2488 To = ToOrigin;
2489 }
2490
2492 Importer.getFromContext(), Importer.getToContext(),
2494 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2495 IgnoreTemplateParmDepth);
2496 return Ctx.IsEquivalent(From, To);
2497}
2498
2500 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2501 << D->getDeclKindName();
2502 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2503}
2504
2506 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2507 << D->getDeclKindName();
2508 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2509}
2510
2512 // Import the context of this declaration.
2513 DeclContext *DC, *LexicalDC;
2514 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2515 return std::move(Err);
2516
2517 // Import the location of this declaration.
2518 ExpectedSLoc LocOrErr = import(D->getLocation());
2519 if (!LocOrErr)
2520 return LocOrErr.takeError();
2521
2522 EmptyDecl *ToD;
2523 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2524 return ToD;
2525
2526 ToD->setLexicalDeclContext(LexicalDC);
2527 LexicalDC->addDeclInternal(ToD);
2528 return ToD;
2529}
2530
2532 TranslationUnitDecl *ToD =
2534
2535 Importer.MapImported(D, ToD);
2536
2537 return ToD;
2538}
2539
2541 DeclContext *DC, *LexicalDC;
2542 DeclarationName Name;
2544 NamedDecl *ToND;
2545 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2546 return std::move(Err);
2547 if (ToND)
2548 return ToND;
2549
2550 BindingDecl *ToD;
2551 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2552 Name.getAsIdentifierInfo()))
2553 return ToD;
2554
2555 Error Err = Error::success();
2556 QualType ToType = importChecked(Err, D->getType());
2557 Expr *ToBinding = importChecked(Err, D->getBinding());
2558 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2559 if (Err)
2560 return std::move(Err);
2561
2562 ToD->setBinding(ToType, ToBinding);
2563 ToD->setDecomposedDecl(ToDecomposedDecl);
2564 addDeclToContexts(D, ToD);
2565
2566 return ToD;
2567}
2568
2570 ExpectedSLoc LocOrErr = import(D->getLocation());
2571 if (!LocOrErr)
2572 return LocOrErr.takeError();
2573 auto ColonLocOrErr = import(D->getColonLoc());
2574 if (!ColonLocOrErr)
2575 return ColonLocOrErr.takeError();
2576
2577 // Import the context of this declaration.
2578 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2579 if (!DCOrErr)
2580 return DCOrErr.takeError();
2581 DeclContext *DC = *DCOrErr;
2582
2583 AccessSpecDecl *ToD;
2584 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2585 DC, *LocOrErr, *ColonLocOrErr))
2586 return ToD;
2587
2588 // Lexical DeclContext and Semantic DeclContext
2589 // is always the same for the accessSpec.
2590 ToD->setLexicalDeclContext(DC);
2591 DC->addDeclInternal(ToD);
2592
2593 return ToD;
2594}
2595
2597 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2598 if (!DCOrErr)
2599 return DCOrErr.takeError();
2600 DeclContext *DC = *DCOrErr;
2601 DeclContext *LexicalDC = DC;
2602
2603 Error Err = Error::success();
2604 auto ToLocation = importChecked(Err, D->getLocation());
2605 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2606 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2607 auto ToMessage = importChecked(Err, D->getMessage());
2608 if (Err)
2609 return std::move(Err);
2610
2611 StaticAssertDecl *ToD;
2612 if (GetImportedOrCreateDecl(
2613 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2614 ToRParenLoc, D->isFailed()))
2615 return ToD;
2616
2617 ToD->setLexicalDeclContext(LexicalDC);
2618 LexicalDC->addDeclInternal(ToD);
2619 return ToD;
2620}
2621
2623 // Import the major distinguishing characteristics of this namespace.
2624 DeclContext *DC, *LexicalDC;
2625 DeclarationName Name;
2627 NamedDecl *ToD;
2628 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2629 return std::move(Err);
2630 if (ToD)
2631 return ToD;
2632
2633 NamespaceDecl *MergeWithNamespace = nullptr;
2634 if (!Name) {
2635 // This is an anonymous namespace. Adopt an existing anonymous
2636 // namespace if we can.
2637 // FIXME: Not testable.
2638 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2639 MergeWithNamespace = TU->getAnonymousNamespace();
2640 else
2641 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2642 } else {
2643 SmallVector<NamedDecl *, 4> ConflictingDecls;
2644 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2645 for (auto *FoundDecl : FoundDecls) {
2647 continue;
2648
2649 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2650 MergeWithNamespace = FoundNS;
2651 ConflictingDecls.clear();
2652 break;
2653 }
2654
2655 ConflictingDecls.push_back(FoundDecl);
2656 }
2657
2658 if (!ConflictingDecls.empty()) {
2659 ExpectedName NameOrErr = Importer.HandleNameConflict(
2660 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2661 ConflictingDecls.size());
2662 if (NameOrErr)
2663 Name = NameOrErr.get();
2664 else
2665 return NameOrErr.takeError();
2666 }
2667 }
2668
2669 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2670 if (!BeginLocOrErr)
2671 return BeginLocOrErr.takeError();
2672 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2673 if (!RBraceLocOrErr)
2674 return RBraceLocOrErr.takeError();
2675
2676 // Create the "to" namespace, if needed.
2677 NamespaceDecl *ToNamespace = MergeWithNamespace;
2678 if (!ToNamespace) {
2679 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2680 D->isInline(), *BeginLocOrErr, Loc,
2681 Name.getAsIdentifierInfo(),
2682 /*PrevDecl=*/nullptr, D->isNested()))
2683 return ToNamespace;
2684 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2685 ToNamespace->setLexicalDeclContext(LexicalDC);
2686 LexicalDC->addDeclInternal(ToNamespace);
2687
2688 // If this is an anonymous namespace, register it as the anonymous
2689 // namespace within its context.
2690 if (!Name) {
2691 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2692 TU->setAnonymousNamespace(ToNamespace);
2693 else
2694 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2695 }
2696 }
2697 Importer.MapImported(D, ToNamespace);
2698
2699 if (Error Err = ImportDeclContext(D))
2700 return std::move(Err);
2701
2702 return ToNamespace;
2703}
2704
2706 // Import the major distinguishing characteristics of this namespace.
2707 DeclContext *DC, *LexicalDC;
2708 DeclarationName Name;
2710 NamedDecl *LookupD;
2711 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2712 return std::move(Err);
2713 if (LookupD)
2714 return LookupD;
2715
2716 // NOTE: No conflict resolution is done for namespace aliases now.
2717
2718 Error Err = Error::success();
2719 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2720 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2721 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2722 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2723 auto ToNamespace = importChecked(Err, D->getNamespace());
2724 if (Err)
2725 return std::move(Err);
2726
2727 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2728
2729 NamespaceAliasDecl *ToD;
2730 if (GetImportedOrCreateDecl(
2731 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2732 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2733 return ToD;
2734
2735 ToD->setLexicalDeclContext(LexicalDC);
2736 LexicalDC->addDeclInternal(ToD);
2737
2738 return ToD;
2739}
2740
2743 // Import the major distinguishing characteristics of this typedef.
2744 DeclarationName Name;
2746 NamedDecl *ToD;
2747 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2748 // is created.
2749 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2750 return std::move(Err);
2751 if (ToD)
2752 return ToD;
2753
2754 DeclContext *DC = cast_or_null<DeclContext>(
2755 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2756 DeclContext *LexicalDC =
2757 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2758 cast<Decl>(D->getLexicalDeclContext())));
2759
2760 // If this typedef is not in block scope, determine whether we've
2761 // seen a typedef with the same name (that we can merge with) or any
2762 // other entity by that name (which name lookup could conflict with).
2763 // Note: Repeated typedefs are not valid in C99:
2764 // 'typedef int T; typedef int T;' is invalid
2765 // We do not care about this now.
2766 if (DC && !DC->isFunctionOrMethod()) {
2767 SmallVector<NamedDecl *, 4> ConflictingDecls;
2768 unsigned IDNS = Decl::IDNS_Ordinary;
2769 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2770 for (auto *FoundDecl : FoundDecls) {
2771 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2772 continue;
2773 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2774 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2775 continue;
2776
2777 QualType FromUT = D->getUnderlyingType();
2778 QualType FoundUT = FoundTypedef->getUnderlyingType();
2779 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2780 // If the underlying declarations are unnamed records these can be
2781 // imported as different types. We should create a distinct typedef
2782 // node in this case.
2783 // If we found an existing underlying type with a record in a
2784 // different context (than the imported), this is already reason for
2785 // having distinct typedef nodes for these.
2786 // Again this can create situation like
2787 // 'typedef int T; typedef int T;' but this is hard to avoid without
2788 // a rename strategy at import.
2789 if (!FromUT.isNull() && !FoundUT.isNull()) {
2790 RecordDecl *FromR = FromUT->getAsRecordDecl();
2791 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2792 if (FromR && FoundR &&
2793 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2794 continue;
2795 }
2796 // If the "From" context has a complete underlying type but we
2797 // already have a complete underlying type then return with that.
2798 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2799 return Importer.MapImported(D, FoundTypedef);
2800 // FIXME Handle redecl chain. When you do that make consistent changes
2801 // in ASTImporterLookupTable too.
2802 } else {
2803 ConflictingDecls.push_back(FoundDecl);
2804 }
2805 }
2806 }
2807
2808 if (!ConflictingDecls.empty()) {
2809 ExpectedName NameOrErr = Importer.HandleNameConflict(
2810 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2811 if (NameOrErr)
2812 Name = NameOrErr.get();
2813 else
2814 return NameOrErr.takeError();
2815 }
2816 }
2817
2818 Error Err = Error::success();
2819 auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType());
2820 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2821 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2822 if (Err)
2823 return std::move(Err);
2824
2825 // Create the new typedef node.
2826 // FIXME: ToUnderlyingType is not used.
2827 (void)ToUnderlyingType;
2828 TypedefNameDecl *ToTypedef;
2829 if (IsAlias) {
2830 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2831 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2832 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2833 return ToTypedef;
2834 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2835 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2836 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2837 return ToTypedef;
2838
2839 // Import the DeclContext and set it to the Typedef.
2840 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2841 return std::move(Err);
2842 ToTypedef->setDeclContext(DC);
2843 ToTypedef->setLexicalDeclContext(LexicalDC);
2844 // Add to the lookupTable because we could not do that in MapImported.
2845 Importer.AddToLookupTable(ToTypedef);
2846
2847 ToTypedef->setAccess(D->getAccess());
2848
2849 // Templated declarations should not appear in DeclContext.
2850 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2851 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2852 LexicalDC->addDeclInternal(ToTypedef);
2853
2854 return ToTypedef;
2855}
2856
2858 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2859}
2860
2862 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2863}
2864
2867 // Import the major distinguishing characteristics of this typedef.
2868 DeclContext *DC, *LexicalDC;
2869 DeclarationName Name;
2871 NamedDecl *FoundD;
2872 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2873 return std::move(Err);
2874 if (FoundD)
2875 return FoundD;
2876
2877 // If this typedef is not in block scope, determine whether we've
2878 // seen a typedef with the same name (that we can merge with) or any
2879 // other entity by that name (which name lookup could conflict with).
2880 if (!DC->isFunctionOrMethod()) {
2881 SmallVector<NamedDecl *, 4> ConflictingDecls;
2882 unsigned IDNS = Decl::IDNS_Ordinary;
2883 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2884 for (auto *FoundDecl : FoundDecls) {
2885 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2886 continue;
2887 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2888 if (IsStructuralMatch(D, FoundAlias))
2889 return Importer.MapImported(D, FoundAlias);
2890 ConflictingDecls.push_back(FoundDecl);
2891 }
2892 }
2893
2894 if (!ConflictingDecls.empty()) {
2895 ExpectedName NameOrErr = Importer.HandleNameConflict(
2896 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2897 if (NameOrErr)
2898 Name = NameOrErr.get();
2899 else
2900 return NameOrErr.takeError();
2901 }
2902 }
2903
2904 Error Err = Error::success();
2905 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2906 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2907 if (Err)
2908 return std::move(Err);
2909
2910 TypeAliasTemplateDecl *ToAlias;
2911 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2912 Name, ToTemplateParameters, ToTemplatedDecl))
2913 return ToAlias;
2914
2915 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2916
2917 ToAlias->setAccess(D->getAccess());
2918 ToAlias->setLexicalDeclContext(LexicalDC);
2919 LexicalDC->addDeclInternal(ToAlias);
2920 if (DC != Importer.getToContext().getTranslationUnitDecl())
2921 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2922 return ToAlias;
2923}
2924
2926 // Import the major distinguishing characteristics of this label.
2927 DeclContext *DC, *LexicalDC;
2928 DeclarationName Name;
2930 NamedDecl *ToD;
2931 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2932 return std::move(Err);
2933 if (ToD)
2934 return ToD;
2935
2936 assert(LexicalDC->isFunctionOrMethod());
2937
2938 LabelDecl *ToLabel;
2939 if (D->isGnuLocal()) {
2940 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2941 if (!BeginLocOrErr)
2942 return BeginLocOrErr.takeError();
2943 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2944 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2945 return ToLabel;
2946
2947 } else {
2948 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2949 Name.getAsIdentifierInfo()))
2950 return ToLabel;
2951
2952 }
2953
2954 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2955 if (!ToStmtOrErr)
2956 return ToStmtOrErr.takeError();
2957
2958 ToLabel->setStmt(*ToStmtOrErr);
2959 ToLabel->setLexicalDeclContext(LexicalDC);
2960 LexicalDC->addDeclInternal(ToLabel);
2961 return ToLabel;
2962}
2963
2965 // Import the major distinguishing characteristics of this enum.
2966 DeclContext *DC, *LexicalDC;
2967 DeclarationName Name;
2969 NamedDecl *ToD;
2970 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2971 return std::move(Err);
2972 if (ToD)
2973 return ToD;
2974
2975 // Figure out what enum name we're looking for.
2976 unsigned IDNS = Decl::IDNS_Tag;
2977 DeclarationName SearchName = Name;
2978 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2979 if (Error Err = importInto(
2980 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2981 return std::move(Err);
2982 IDNS = Decl::IDNS_Ordinary;
2983 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2984 IDNS |= Decl::IDNS_Ordinary;
2985
2986 // We may already have an enum of the same name; try to find and match it.
2987 EnumDecl *PrevDecl = nullptr;
2988 if (!DC->isFunctionOrMethod()) {
2989 SmallVector<NamedDecl *, 4> ConflictingDecls;
2990 auto FoundDecls =
2991 Importer.findDeclsInToCtx(DC, SearchName);
2992 for (auto *FoundDecl : FoundDecls) {
2993 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2994 continue;
2995
2996 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2997 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
2998 FoundDecl = Tag->getDecl();
2999 }
3000
3001 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3002 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3003 continue;
3004 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3005 EnumDecl *FoundDef = FoundEnum->getDefinition();
3006 if (D->isThisDeclarationADefinition() && FoundDef)
3007 return Importer.MapImported(D, FoundDef);
3008 PrevDecl = FoundEnum->getMostRecentDecl();
3009 break;
3010 }
3011 ConflictingDecls.push_back(FoundDecl);
3012 }
3013 }
3014
3015 // In case of unnamed enums, we try to find an existing similar one, if none
3016 // was found, perform the import always.
3017 // Structural in-equivalence is not detected in this way here, but it may
3018 // be found when the parent decl is imported (if the enum is part of a
3019 // class). To make this totally exact a more difficult solution is needed.
3020 if (SearchName && !ConflictingDecls.empty()) {
3021 ExpectedName NameOrErr = Importer.HandleNameConflict(
3022 SearchName, DC, IDNS, ConflictingDecls.data(),
3023 ConflictingDecls.size());
3024 if (NameOrErr)
3025 Name = NameOrErr.get();
3026 else
3027 return NameOrErr.takeError();
3028 }
3029 }
3030
3031 Error Err = Error::success();
3032 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3033 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3034 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3035 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3036 if (Err)
3037 return std::move(Err);
3038
3039 // Create the enum declaration.
3040 EnumDecl *D2;
3041 if (GetImportedOrCreateDecl(
3042 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3043 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3044 D->isScopedUsingClassTag(), D->isFixed()))
3045 return D2;
3046
3047 D2->setQualifierInfo(ToQualifierLoc);
3048 D2->setIntegerType(ToIntegerType);
3049 D2->setBraceRange(ToBraceRange);
3050 D2->setAccess(D->getAccess());
3051 D2->setLexicalDeclContext(LexicalDC);
3052 addDeclToContexts(D, D2);
3053
3054 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3055 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3056 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3057 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3058 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3059 else
3060 return ToInstOrErr.takeError();
3061 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3063 else
3064 return POIOrErr.takeError();
3065 }
3066
3067 // Import the definition
3068 if (D->isCompleteDefinition())
3069 if (Error Err = ImportDefinition(D, D2))
3070 return std::move(Err);
3071
3072 return D2;
3073}
3074
3076 bool IsFriendTemplate = false;
3077 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3078 IsFriendTemplate =
3079 DCXX->getDescribedClassTemplate() &&
3080 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3082 }
3083
3084 // Import the major distinguishing characteristics of this record.
3085 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3086 DeclarationName Name;
3088 NamedDecl *ToD = nullptr;
3089 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3090 return std::move(Err);
3091 if (ToD)
3092 return ToD;
3093
3094 // Figure out what structure name we're looking for.
3095 unsigned IDNS = Decl::IDNS_Tag;
3096 DeclarationName SearchName = Name;
3097 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3098 if (Error Err = importInto(
3099 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3100 return std::move(Err);
3101 IDNS = Decl::IDNS_Ordinary;
3102 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3104
3105 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3106 : DC->isDependentContext();
3107 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3108
3109 // We may already have a record of the same name; try to find and match it.
3110 RecordDecl *PrevDecl = nullptr;
3111 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3112 SmallVector<NamedDecl *, 4> ConflictingDecls;
3113 auto FoundDecls =
3114 Importer.findDeclsInToCtx(DC, SearchName);
3115 if (!FoundDecls.empty()) {
3116 // We're going to have to compare D against potentially conflicting Decls,
3117 // so complete it.
3118 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
3120 }
3121
3122 for (auto *FoundDecl : FoundDecls) {
3123 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3124 continue;
3125
3126 Decl *Found = FoundDecl;
3127 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3128 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3129 Found = Tag->getDecl();
3130 }
3131
3132 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3133 // Do not emit false positive diagnostic in case of unnamed
3134 // struct/union and in case of anonymous structs. Would be false
3135 // because there may be several anonymous/unnamed structs in a class.
3136 // E.g. these are both valid:
3137 // struct A { // unnamed structs
3138 // struct { struct A *next; } entry0;
3139 // struct { struct A *next; } entry1;
3140 // };
3141 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3142 if (!SearchName)
3143 if (!IsStructuralMatch(D, FoundRecord, false))
3144 continue;
3145
3146 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3147 continue;
3148
3149 if (IsStructuralMatch(D, FoundRecord)) {
3150 RecordDecl *FoundDef = FoundRecord->getDefinition();
3151 if (D->isThisDeclarationADefinition() && FoundDef) {
3152 // FIXME: Structural equivalence check should check for same
3153 // user-defined methods.
3154 Importer.MapImported(D, FoundDef);
3155 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3156 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3157 assert(FoundCXX && "Record type mismatch");
3158
3159 if (!Importer.isMinimalImport())
3160 // FoundDef may not have every implicit method that D has
3161 // because implicit methods are created only if they are used.
3162 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3163 return std::move(Err);
3164 }
3165 }
3166 PrevDecl = FoundRecord->getMostRecentDecl();
3167 break;
3168 }
3169 ConflictingDecls.push_back(FoundDecl);
3170 } // kind is RecordDecl
3171 } // for
3172
3173 if (!ConflictingDecls.empty() && SearchName) {
3174 ExpectedName NameOrErr = Importer.HandleNameConflict(
3175 SearchName, DC, IDNS, ConflictingDecls.data(),
3176 ConflictingDecls.size());
3177 if (NameOrErr)
3178 Name = NameOrErr.get();
3179 else
3180 return NameOrErr.takeError();
3181 }
3182 }
3183
3184 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3185 if (!BeginLocOrErr)
3186 return BeginLocOrErr.takeError();
3187
3188 // Create the record declaration.
3189 RecordDecl *D2 = nullptr;
3190 CXXRecordDecl *D2CXX = nullptr;
3191 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3192 if (DCXX->isLambda()) {
3193 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3194 if (!TInfoOrErr)
3195 return TInfoOrErr.takeError();
3196 if (GetImportedOrCreateSpecialDecl(
3197 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3198 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3199 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3200 return D2CXX;
3201 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3202 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3203 if (!CDeclOrErr)
3204 return CDeclOrErr.takeError();
3205 Numbering.ContextDecl = *CDeclOrErr;
3206 D2CXX->setLambdaNumbering(Numbering);
3207 } else if (DCXX->isInjectedClassName()) {
3208 // We have to be careful to do a similar dance to the one in
3209 // Sema::ActOnStartCXXMemberDeclarations
3210 const bool DelayTypeCreation = true;
3211 if (GetImportedOrCreateDecl(
3212 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3213 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3214 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3215 return D2CXX;
3216 Importer.getToContext().getTypeDeclType(
3217 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3218 } else {
3219 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3220 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3221 Name.getAsIdentifierInfo(),
3222 cast_or_null<CXXRecordDecl>(PrevDecl)))
3223 return D2CXX;
3224 }
3225
3226 D2 = D2CXX;
3227 D2->setAccess(D->getAccess());
3228 D2->setLexicalDeclContext(LexicalDC);
3229 addDeclToContexts(D, D2);
3230
3231 if (ClassTemplateDecl *FromDescribed =
3232 DCXX->getDescribedClassTemplate()) {
3233 ClassTemplateDecl *ToDescribed;
3234 if (Error Err = importInto(ToDescribed, FromDescribed))
3235 return std::move(Err);
3236 D2CXX->setDescribedClassTemplate(ToDescribed);
3237 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3238 // In a record describing a template the type should be an
3239 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3240 // previously set type to the correct value here (ToDescribed is not
3241 // available at record create).
3242 CXXRecordDecl *Injected = nullptr;
3243 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3244 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3245 if (Record && Record->isInjectedClassName()) {
3246 Injected = Record;
3247 break;
3248 }
3249 }
3250 // Create an injected type for the whole redecl chain.
3251 // The chain may contain an already existing injected type at the start,
3252 // if yes this should be reused. We must ensure that only one type
3253 // object exists for the injected type (including the injected record
3254 // declaration), ASTContext does not check it.
3255 SmallVector<Decl *, 2> Redecls =
3257 const Type *FrontTy =
3258 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3259 QualType InjSpec;
3260 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3261 InjSpec = InjTy->getInjectedSpecializationType();
3262 else
3263 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3264 for (auto *R : Redecls) {
3265 auto *RI = cast<CXXRecordDecl>(R);
3266 if (R != Redecls.front() ||
3267 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3268 RI->setTypeForDecl(nullptr);
3269 // This function tries to get the injected type from getTypeForDecl,
3270 // then from the previous declaration if possible. If not, it creates
3271 // a new type.
3272 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3273 }
3274 // Set the new type for the injected decl too.
3275 if (Injected) {
3276 Injected->setTypeForDecl(nullptr);
3277 // This function will copy the injected type from D2CXX into Injected.
3278 // The injected decl does not have a previous decl to copy from.
3279 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3280 }
3281 }
3282 } else if (MemberSpecializationInfo *MemberInfo =
3283 DCXX->getMemberSpecializationInfo()) {
3285 MemberInfo->getTemplateSpecializationKind();
3287
3288 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3289 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3290 else
3291 return ToInstOrErr.takeError();
3292
3293 if (ExpectedSLoc POIOrErr =
3294 import(MemberInfo->getPointOfInstantiation()))
3296 *POIOrErr);
3297 else
3298 return POIOrErr.takeError();
3299 }
3300
3301 } else {
3302 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3303 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3304 Name.getAsIdentifierInfo(), PrevDecl))
3305 return D2;
3306 D2->setLexicalDeclContext(LexicalDC);
3307 addDeclToContexts(D, D2);
3308 }
3309
3310 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3311 D2->setBraceRange(*BraceRangeOrErr);
3312 else
3313 return BraceRangeOrErr.takeError();
3314 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3315 D2->setQualifierInfo(*QualifierLocOrErr);
3316 else
3317 return QualifierLocOrErr.takeError();
3318
3319 if (D->isAnonymousStructOrUnion())
3320 D2->setAnonymousStructOrUnion(true);
3321
3322 if (D->isCompleteDefinition())
3323 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3324 return std::move(Err);
3325
3326 return D2;
3327}
3328
3330 // Import the major distinguishing characteristics of this enumerator.
3331 DeclContext *DC, *LexicalDC;
3332 DeclarationName Name;
3334 NamedDecl *ToD;
3335 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3336 return std::move(Err);
3337 if (ToD)
3338 return ToD;
3339
3340 // Determine whether there are any other declarations with the same name and
3341 // in the same context.
3342 if (!LexicalDC->isFunctionOrMethod()) {
3343 SmallVector<NamedDecl *, 4> ConflictingDecls;
3344 unsigned IDNS = Decl::IDNS_Ordinary;
3345 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3346 for (auto *FoundDecl : FoundDecls) {
3347 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3348 continue;
3349
3350 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3351 if (IsStructuralMatch(D, FoundEnumConstant))
3352 return Importer.MapImported(D, FoundEnumConstant);
3353 ConflictingDecls.push_back(FoundDecl);
3354 }
3355 }
3356
3357 if (!ConflictingDecls.empty()) {
3358 ExpectedName NameOrErr = Importer.HandleNameConflict(
3359 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3360 if (NameOrErr)
3361 Name = NameOrErr.get();
3362 else
3363 return NameOrErr.takeError();
3364 }
3365 }
3366
3367 ExpectedType TypeOrErr = import(D->getType());
3368 if (!TypeOrErr)
3369 return TypeOrErr.takeError();
3370
3371 ExpectedExpr InitOrErr = import(D->getInitExpr());
3372 if (!InitOrErr)
3373 return InitOrErr.takeError();
3374
3375 EnumConstantDecl *ToEnumerator;
3376 if (GetImportedOrCreateDecl(
3377 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3378 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3379 return ToEnumerator;
3380
3381 ToEnumerator->setAccess(D->getAccess());
3382 ToEnumerator->setLexicalDeclContext(LexicalDC);
3383 LexicalDC->addDeclInternal(ToEnumerator);
3384 return ToEnumerator;
3385}
3386
3387template <typename DeclTy>
3389 DeclTy *ToD) {
3390 unsigned int Num = FromD->getNumTemplateParameterLists();
3391 if (Num == 0)
3392 return Error::success();
3394 for (unsigned int I = 0; I < Num; ++I)
3395 if (Expected<TemplateParameterList *> ToTPListOrErr =
3396 import(FromD->getTemplateParameterList(I)))
3397 ToTPLists[I] = *ToTPListOrErr;
3398 else
3399 return ToTPListOrErr.takeError();
3400 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3401 return Error::success();
3402}
3403
3405 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3406 switch (FromFD->getTemplatedKind()) {
3409 return Error::success();
3410
3412 if (Expected<FunctionDecl *> InstFDOrErr =
3413 import(FromFD->getInstantiatedFromDecl()))
3414 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3415 return Error::success();
3418
3419 if (Expected<FunctionDecl *> InstFDOrErr =
3420 import(FromFD->getInstantiatedFromMemberFunction()))
3421 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3422 else
3423 return InstFDOrErr.takeError();
3424
3425 if (ExpectedSLoc POIOrErr = import(
3428 else
3429 return POIOrErr.takeError();
3430
3431 return Error::success();
3432 }
3433
3435 auto FunctionAndArgsOrErr =
3437 if (!FunctionAndArgsOrErr)
3438 return FunctionAndArgsOrErr.takeError();
3439
3441 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3442
3443 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3444 TemplateArgumentListInfo ToTAInfo;
3445 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3446 if (FromTAArgsAsWritten)
3447 if (Error Err = ImportTemplateArgumentListInfo(
3448 *FromTAArgsAsWritten, ToTAInfo))
3449 return Err;
3450
3451 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3452 if (!POIOrErr)
3453 return POIOrErr.takeError();
3454
3455 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3456 return Err;
3457
3458 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3459 ToFD->setFunctionTemplateSpecialization(
3460 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3461 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3462 return Error::success();
3463 }
3464
3466 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3467 UnresolvedSet<8> Candidates;
3468 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3469 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3470 Candidates.addDecl(*ToFTDOrErr);
3471 else
3472 return ToFTDOrErr.takeError();
3473 }
3474
3475 // Import TemplateArgumentListInfo.
3476 TemplateArgumentListInfo ToTAInfo;
3477 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3478 if (FromTAArgsAsWritten)
3479 if (Error Err =
3480 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3481 return Err;
3482
3484 Importer.getToContext(), Candidates,
3485 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3486 return Error::success();
3487 }
3488 }
3489 llvm_unreachable("All cases should be covered!");
3490}
3491
3494 auto FunctionAndArgsOrErr =
3496 if (!FunctionAndArgsOrErr)
3497 return FunctionAndArgsOrErr.takeError();
3498
3499 FunctionTemplateDecl *Template;
3500 TemplateArgsTy ToTemplArgs;
3501 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3502 void *InsertPos = nullptr;
3503 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3504 return FoundSpec;
3505}
3506
3508 FunctionDecl *ToFD) {
3509 if (Stmt *FromBody = FromFD->getBody()) {
3510 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3511 ToFD->setBody(*ToBodyOrErr);
3512 else
3513 return ToBodyOrErr.takeError();
3514 }
3515 return Error::success();
3516}
3517
3518// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3519// which is equal to the given DC, or D is equal to DC.
3520static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3521 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3522 if (!DCi)
3523 DCi = D->getDeclContext();
3524 assert(DCi && "Declaration should have a context");
3525 while (DCi != D->getTranslationUnitDecl()) {
3526 if (DCi == DC)
3527 return true;
3528 DCi = DCi->getParent();
3529 }
3530 return false;
3531}
3532
3533// Check if there is a declaration that has 'DC' as parent context and is
3534// referenced from statement 'S' or one of its children. The search is done in
3535// BFS order through children of 'S'.
3536static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3537 SmallVector<const Stmt *> ToProcess;
3538 ToProcess.push_back(S);
3539 while (!ToProcess.empty()) {
3540 const Stmt *CurrentS = ToProcess.pop_back_val();
3541 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3542 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3543 if (const Decl *D = DeclRef->getDecl())
3544 if (isAncestorDeclContextOf(DC, D))
3545 return true;
3546 } else if (const auto *E =
3547 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3548 if (const Decl *D = E->getAssociatedDecl())
3549 if (isAncestorDeclContextOf(DC, D))
3550 return true;
3551 }
3552 }
3553 return false;
3554}
3555
3556namespace {
3557/// Check if a type has any reference to a declaration that is inside the body
3558/// of a function.
3559/// The \c CheckType(QualType) function should be used to determine
3560/// this property.
3561///
3562/// The type visitor visits one type object only (not recursive).
3563/// To find all referenced declarations we must discover all type objects until
3564/// the canonical type is reached (walk over typedef and similar objects). This
3565/// is done by loop over all "sugar" type objects. For every such type we must
3566/// check all declarations that are referenced from it. For this check the
3567/// visitor is used. In the visit functions all referenced declarations except
3568/// the one that follows in the sugar chain (if any) must be checked. For this
3569/// check the same visitor is re-used (it has no state-dependent data).
3570///
3571/// The visit functions have 3 possible return values:
3572/// - True, found a declaration inside \c ParentDC.
3573/// - False, found declarations only outside \c ParentDC and it is not possible
3574/// to find more declarations (the "sugar" chain does not continue).
3575/// - Empty optional value, found no declarations or only outside \c ParentDC,
3576/// but it is possible to find more declarations in the type "sugar" chain.
3577/// The loop over the "sugar" types can be implemented by using type visit
3578/// functions only (call \c CheckType with the desugared type). With the current
3579/// solution no visit function is needed if the type has only a desugared type
3580/// as data.
3581class IsTypeDeclaredInsideVisitor
3582 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3583public:
3584 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3585 : ParentDC(ParentDC) {}
3586
3587 bool CheckType(QualType T) {
3588 // Check the chain of "sugar" types.
3589 // The "sugar" types are typedef or similar types that have the same
3590 // canonical type.
3591 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3592 return *Res;
3593 QualType DsT =
3594 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3595 while (DsT != T) {
3596 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3597 return *Res;
3598 T = DsT;
3599 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3600 }
3601 return false;
3602 }
3603
3604 std::optional<bool> VisitTagType(const TagType *T) {
3605 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3606 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3607 if (checkTemplateArgument(Arg))
3608 return true;
3609 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3610 }
3611
3612 std::optional<bool> VisitPointerType(const PointerType *T) {
3613 return CheckType(T->getPointeeType());
3614 }
3615
3616 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3617 return CheckType(T->getPointeeTypeAsWritten());
3618 }
3619
3620 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3621 const TypedefNameDecl *TD = T->getDecl();
3622 assert(TD);
3623 return isAncestorDeclContextOf(ParentDC, TD);
3624 }
3625
3626 std::optional<bool> VisitUsingType(const UsingType *T) {
3627 if (T->getFoundDecl() &&
3628 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3629 return true;
3630
3631 return {};
3632 }
3633
3634 std::optional<bool>
3635 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3636 for (const auto &Arg : T->template_arguments())
3637 if (checkTemplateArgument(Arg))
3638 return true;
3639 // This type is a "sugar" to a record type, it can have a desugared type.
3640 return {};
3641 }
3642
3643 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3644 return CheckType(T->getBaseType());
3645 }
3646
3647 std::optional<bool>
3648 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3649 // The "associated declaration" can be the same as ParentDC.
3650 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3651 return true;
3652 return {};
3653 }
3654
3655 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3656 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3657 return true;
3658
3659 return CheckType(T->getElementType());
3660 }
3661
3662 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3663 llvm_unreachable(
3664 "Variable array should not occur in deduced return type of a function");
3665 }
3666
3667 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3668 llvm_unreachable("Incomplete array should not occur in deduced return type "
3669 "of a function");
3670 }
3671
3672 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3673 llvm_unreachable("Dependent array should not occur in deduced return type "
3674 "of a function");
3675 }
3676
3677private:
3678 const DeclContext *const ParentDC;
3679
3680 bool checkTemplateArgument(const TemplateArgument &Arg) {
3681 switch (Arg.getKind()) {
3683 return false;
3685 return CheckType(Arg.getIntegralType());
3687 return CheckType(Arg.getAsType());
3689 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3691 // FIXME: The declaration in this case is not allowed to be in a function?
3692 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3694 // FIXME: The type is not allowed to be in the function?
3695 return CheckType(Arg.getNullPtrType());
3697 return CheckType(Arg.getStructuralValueType());
3699 for (const auto &PackArg : Arg.getPackAsArray())
3700 if (checkTemplateArgument(PackArg))
3701 return true;
3702 return false;
3704 // Templates can not be defined locally in functions.
3705 // A template passed as argument can be not in ParentDC.
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;
3711 }
3712 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3713 };
3714};
3715} // namespace
3716
3717/// This function checks if the given function has a return type that contains
3718/// a reference (in any way) to a declaration inside the same function.
3720 QualType FromTy = D->getType();
3721 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3722 assert(FromFPT && "Must be called on FunctionProtoType");
3723
3724 auto IsCXX11Lambda = [&]() {
3725 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3726 return false;
3727
3728 if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3729 return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda();
3730
3731 return false;
3732 };
3733
3734 QualType RetT = FromFPT->getReturnType();
3735 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3736 FunctionDecl *Def = D->getDefinition();
3737 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3738 return Visitor.CheckType(RetT);
3739 }
3740
3741 return false;
3742}
3743
3745ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3746 Expr *ExplicitExpr = ESpec.getExpr();
3747 if (ExplicitExpr)
3748 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3749 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3750}
3751
3753
3755 auto RedeclIt = Redecls.begin();
3756 // Import the first part of the decl chain. I.e. import all previous
3757 // declarations starting from the canonical decl.
3758 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3759 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3760 if (!ToRedeclOrErr)
3761 return ToRedeclOrErr.takeError();
3762 }
3763 assert(*RedeclIt == D);
3764
3765 // Import the major distinguishing characteristics of this function.
3766 DeclContext *DC, *LexicalDC;
3767 DeclarationName Name;
3769 NamedDecl *ToD;
3770 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3771 return std::move(Err);
3772 if (ToD)
3773 return ToD;
3774
3775 FunctionDecl *FoundByLookup = nullptr;
3776 FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate();
3777
3778 // If this is a function template specialization, then try to find the same
3779 // existing specialization in the "to" context. The lookup below will not
3780 // find any specialization, but would find the primary template; thus, we
3781 // have to skip normal lookup in case of specializations.
3782 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3783 if (D->getTemplatedKind() ==
3785 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3786 if (!FoundFunctionOrErr)
3787 return FoundFunctionOrErr.takeError();
3788 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3789 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3790 return Def;
3791 FoundByLookup = FoundFunction;
3792 }
3793 }
3794 // Try to find a function in our own ("to") context with the same name, same
3795 // type, and in the same context as the function we're importing.
3796 else if (!LexicalDC->isFunctionOrMethod()) {
3797 SmallVector<NamedDecl *, 4> ConflictingDecls;
3799 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3800 for (auto *FoundDecl : FoundDecls) {
3801 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3802 continue;
3803
3804 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3805 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3806 continue;
3807
3808 if (IsStructuralMatch(D, FoundFunction)) {
3809 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3810 return Def;
3811 FoundByLookup = FoundFunction;
3812 break;
3813 }
3814 // FIXME: Check for overloading more carefully, e.g., by boosting
3815 // Sema::IsOverload out to the AST library.
3816
3817 // Function overloading is okay in C++.
3818 if (Importer.getToContext().getLangOpts().CPlusPlus)
3819 continue;
3820
3821 // Complain about inconsistent function types.
3822 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3823 << Name << D->getType() << FoundFunction->getType();
3824 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3825 << FoundFunction->getType();
3826 ConflictingDecls.push_back(FoundDecl);
3827 }
3828 }
3829
3830 if (!ConflictingDecls.empty()) {
3831 ExpectedName NameOrErr = Importer.HandleNameConflict(
3832 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3833 if (NameOrErr)
3834 Name = NameOrErr.get();
3835 else
3836 return NameOrErr.takeError();
3837 }
3838 }
3839
3840 // We do not allow more than one in-class declaration of a function. This is
3841 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3842 // assumes there is only one in-class declaration. Building a redecl
3843 // chain would result in more than one in-class declaration for
3844 // overrides (even if they are part of the same redecl chain inside the
3845 // derived class.)
3846 if (FoundByLookup) {
3847 if (isa<CXXMethodDecl>(FoundByLookup)) {
3848 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3849 if (!D->doesThisDeclarationHaveABody()) {
3850 if (FunctionTemplateDecl *DescribedD =
3851 D->getDescribedFunctionTemplate()) {
3852 // Handle a "templated" function together with its described
3853 // template. This avoids need for a similar check at import of the
3854 // described template.
3855 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3856 "Templated function mapped to non-templated?");
3857 Importer.MapImported(DescribedD,
3858 FoundByLookup->getDescribedFunctionTemplate());
3859 }
3860 return Importer.MapImported(D, FoundByLookup);
3861 } else {
3862 // Let's continue and build up the redecl chain in this case.
3863 // FIXME Merge the functions into one decl.
3864 }
3865 }
3866 }
3867 }
3868
3869 DeclarationNameInfo NameInfo(Name, Loc);
3870 // Import additional name location/type info.
3871 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3872 return std::move(Err);
3873
3874 QualType FromTy = D->getType();
3875 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3876 // Set to true if we do not import the type of the function as is. There are
3877 // cases when the original type would result in an infinite recursion during
3878 // the import. To avoid an infinite recursion when importing, we create the
3879 // FunctionDecl with a simplified function type and update it only after the
3880 // relevant AST nodes are already imported.
3881 // The type is related to TypeSourceInfo (it references the type), so we must
3882 // do the same with TypeSourceInfo.
3883 bool UsedDifferentProtoType = false;
3884 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3885 QualType FromReturnTy = FromFPT->getReturnType();
3886 // Functions with auto return type may define a struct inside their body
3887 // and the return type could refer to that struct.
3888 // E.g.: auto foo() { struct X{}; return X(); }
3889 // To avoid an infinite recursion when importing, create the FunctionDecl
3890 // with a simplified return type.
3892 FromReturnTy = Importer.getFromContext().VoidTy;
3893 UsedDifferentProtoType = true;
3894 }
3895 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3896 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3897 // FunctionDecl that we are importing the FunctionProtoType for.
3898 // To avoid an infinite recursion when importing, create the FunctionDecl
3899 // with a simplified function type.
3900 if (FromEPI.ExceptionSpec.SourceDecl ||
3901 FromEPI.ExceptionSpec.SourceTemplate ||
3902 FromEPI.ExceptionSpec.NoexceptExpr) {
3904 FromEPI = DefaultEPI;
3905 UsedDifferentProtoType = true;
3906 }
3907 FromTy = Importer.getFromContext().getFunctionType(
3908 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3909 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3910 FromTy, D->getBeginLoc());
3911 }
3912
3913 Error Err = Error::success();
3914 auto T = importChecked(Err, FromTy);
3915 auto TInfo = importChecked(Err, FromTSI);
3916 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3917 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3918 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3919 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3920 auto TrailingRequiresClause =
3921 importChecked(Err, D->getTrailingRequiresClause());
3922 if (Err)
3923 return std::move(Err);
3924
3925 // Import the function parameters.
3927 for (auto *P : D->parameters()) {
3928 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3929 Parameters.push_back(*ToPOrErr);
3930 else
3931 return ToPOrErr.takeError();
3932 }
3933
3934 // Create the imported function.
3935 FunctionDecl *ToFunction = nullptr;
3936 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3937 ExplicitSpecifier ESpec =
3938 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3939 if (Err)
3940 return std::move(Err);
3941 auto ToInheritedConstructor = InheritedConstructor();
3942 if (FromConstructor->isInheritingConstructor()) {
3943 Expected<InheritedConstructor> ImportedInheritedCtor =
3944 import(FromConstructor->getInheritedConstructor());
3945 if (!ImportedInheritedCtor)
3946 return ImportedInheritedCtor.takeError();
3947 ToInheritedConstructor = *ImportedInheritedCtor;
3948 }
3949 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3950 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3951 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3952 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3953 ToInheritedConstructor, TrailingRequiresClause))
3954 return ToFunction;
3955 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3956
3957 Error Err = Error::success();
3958 auto ToOperatorDelete = importChecked(
3959 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3960 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3961 if (Err)
3962 return std::move(Err);
3963
3964 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3965 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3966 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3967 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3968 TrailingRequiresClause))
3969 return ToFunction;
3970
3971 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3972
3973 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3974 } else if (CXXConversionDecl *FromConversion =
3975 dyn_cast<CXXConversionDecl>(D)) {
3976 ExplicitSpecifier ESpec =
3977 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3978 if (Err)
3979 return std::move(Err);
3980 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3981 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3982 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3983 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3984 SourceLocation(), TrailingRequiresClause))
3985 return ToFunction;
3986 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3987 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3988 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3989 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3990 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3991 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3992 return ToFunction;
3993 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3994 ExplicitSpecifier ESpec =
3995 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3996 CXXConstructorDecl *Ctor =
3997 importChecked(Err, Guide->getCorrespondingConstructor());
3998 if (Err)
3999 return std::move(Err);
4000 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4001 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4002 NameInfo, T, TInfo, ToEndLoc, Ctor))
4003 return ToFunction;
4004 cast<CXXDeductionGuideDecl>(ToFunction)
4005 ->setDeductionCandidateKind(Guide->getDeductionCandidateKind());
4006 } else {
4007 if (GetImportedOrCreateDecl(
4008 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4009 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4010 D->isInlineSpecified(), D->hasWrittenPrototype(),
4011 D->getConstexprKind(), TrailingRequiresClause))
4012 return ToFunction;
4013 }
4014
4015 // Connect the redecl chain.
4016 if (FoundByLookup) {
4017 auto *Recent = const_cast<FunctionDecl *>(
4018 FoundByLookup->getMostRecentDecl());
4019 ToFunction->setPreviousDecl(Recent);
4020 // FIXME Probably we should merge exception specifications. E.g. In the
4021 // "To" context the existing function may have exception specification with
4022 // noexcept-unevaluated, while the newly imported function may have an
4023 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4024 // decl and its redeclarations may be required.
4025 }
4026
4027 StringLiteral *Msg = D->getDeletedMessage();
4028 if (Msg) {
4029 auto Imported = import(Msg);
4030 if (!Imported)
4031 return Imported.takeError();
4032 Msg = *Imported;
4033 }
4034
4035 ToFunction->setQualifierInfo(ToQualifierLoc);
4036 ToFunction->setAccess(D->getAccess());
4037 ToFunction->setLexicalDeclContext(LexicalDC);
4038 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4039 ToFunction->setTrivial(D->isTrivial());
4040 ToFunction->setIsPureVirtual(D->isPureVirtual());
4041 ToFunction->setDefaulted(D->isDefaulted());
4042 ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
4043 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4045 D->FriendConstraintRefersToEnclosingTemplate());
4046 ToFunction->setRangeEnd(ToEndLoc);
4047 ToFunction->setDefaultLoc(ToDefaultLoc);
4048
4049 if (Msg)
4050 ToFunction->setDefaultedOrDeletedInfo(
4052 Importer.getToContext(), {}, Msg));
4053
4054 // Set the parameters.
4055 for (auto *Param : Parameters) {
4056 Param->setOwningFunction(ToFunction);
4057 ToFunction->addDeclInternal(Param);
4058 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4059 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4060 }
4061 ToFunction->setParams(Parameters);
4062
4063 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4064 // params it refers to.
4065 if (TInfo) {
4066 if (auto ProtoLoc =
4067 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4068 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4069 ProtoLoc.setParam(I, Parameters[I]);
4070 }
4071 }
4072
4073 // Import the describing template function, if any.
4074 if (FromFT) {
4075 auto ToFTOrErr = import(FromFT);
4076 if (!ToFTOrErr)
4077 return ToFTOrErr.takeError();
4078 }
4079
4080 // Import Ctor initializers.
4081 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4082 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4083 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4084 // Import first, then allocate memory and copy if there was no error.
4085 if (Error Err = ImportContainerChecked(
4086 FromConstructor->inits(), CtorInitializers))
4087 return std::move(Err);
4088 auto **Memory =
4089 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4090 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4091 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4092 ToCtor->setCtorInitializers(Memory);
4093 ToCtor->setNumCtorInitializers(NumInitializers);
4094 }
4095 }
4096
4097 // If it is a template, import all related things.
4098 if (Error Err = ImportTemplateInformation(D, ToFunction))
4099 return std::move(Err);
4100
4101 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4102 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4103 FromCXXMethod))
4104 return std::move(Err);
4105
4106 if (D->doesThisDeclarationHaveABody()) {
4107 Error Err = ImportFunctionDeclBody(D, ToFunction);
4108
4109 if (Err)
4110 return std::move(Err);
4111 }
4112
4113 // Import and set the original type in case we used another type.
4114 if (UsedDifferentProtoType) {
4115 if (ExpectedType TyOrErr = import(D->getType()))
4116 ToFunction->setType(*TyOrErr);
4117 else
4118 return TyOrErr.takeError();
4119 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4120 ToFunction->setTypeSourceInfo(*TSIOrErr);
4121 else
4122 return TSIOrErr.takeError();
4123 }
4124
4125 // FIXME: Other bits to merge?
4126
4127 addDeclToContexts(D, ToFunction);
4128
4129 // Import the rest of the chain. I.e. import all subsequent declarations.
4130 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4131 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4132 if (!ToRedeclOrErr)
4133 return ToRedeclOrErr.takeError();
4134 }
4135
4136 return ToFunction;
4137}
4138
4140 return VisitFunctionDecl(D);
4141}
4142
4144 return VisitCXXMethodDecl(D);
4145}
4146
4148 return VisitCXXMethodDecl(D);
4149}
4150
4152 return VisitCXXMethodDecl(D);
4153}
4154
4157 return VisitFunctionDecl(D);
4158}
4159
4161 // Import the major distinguishing characteristics of a variable.
4162 DeclContext *DC, *LexicalDC;
4163 DeclarationName Name;
4165 NamedDecl *ToD;
4166 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4167 return std::move(Err);
4168 if (ToD)
4169 return ToD;
4170
4171 // Determine whether we've already imported this field.
4172 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4173 for (auto *FoundDecl : FoundDecls) {
4174 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4175 // For anonymous fields, match up by index.
4176 if (!Name &&
4178 ASTImporter::getFieldIndex(FoundField))
4179 continue;
4180
4181 if (Importer.IsStructurallyEquivalent(D->getType(),
4182 FoundField->getType())) {
4183 Importer.MapImported(D, FoundField);
4184 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4185 // initializer of a FieldDecl might not had been instantiated in the
4186 // "To" context. However, the "From" context might instantiated that,
4187 // thus we have to merge that.
4188 // Note: `hasInClassInitializer()` is not the same as non-null
4189 // `getInClassInitializer()` value.
4190 if (Expr *FromInitializer = D->getInClassInitializer()) {
4191 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4192 // Import of the FromInitializer may result in the setting of
4193 // InClassInitializer. If not, set it here.
4194 assert(FoundField->hasInClassInitializer() &&
4195 "Field should have an in-class initializer if it has an "
4196 "expression for it.");
4197 if (!FoundField->getInClassInitializer())
4198 FoundField->setInClassInitializer(*ToInitializerOrErr);
4199 } else {
4200 return ToInitializerOrErr.takeError();
4201 }
4202 }
4203 return FoundField;
4204 }
4205
4206 // FIXME: Why is this case not handled with calling HandleNameConflict?
4207 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4208 << Name << D->getType() << FoundField->getType();
4209 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4210 << FoundField->getType();
4211
4212 return make_error<ASTImportError>(ASTImportError::NameConflict);
4213 }
4214 }
4215
4216 Error Err = Error::success();
4217 auto ToType = importChecked(Err, D->getType());
4218 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4219 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4220 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4221 if (Err)
4222 return std::move(Err);
4223 const Type *ToCapturedVLAType = nullptr;
4224 if (Error Err = Importer.importInto(
4225 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4226 return std::move(Err);
4227
4228 FieldDecl *ToField;
4229 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4230 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4231 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4232 D->getInClassInitStyle()))
4233 return ToField;
4234
4235 ToField->setAccess(D->getAccess());
4236 ToField->setLexicalDeclContext(LexicalDC);
4237 ToField->setImplicit(D->isImplicit());
4238 if (ToCapturedVLAType)
4239 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4240 LexicalDC->addDeclInternal(ToField);
4241 // Import initializer only after the field was created, it may have recursive
4242 // reference to the field.
4243 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4244 if (Err)
4245 return std::move(Err);
4246 if (ToInitializer) {
4247 auto *AlreadyImported = ToField->getInClassInitializer();
4248 if (AlreadyImported)
4249 assert(ToInitializer == AlreadyImported &&
4250 "Duplicate import of in-class initializer.");
4251 else
4252 ToField->setInClassInitializer(ToInitializer);
4253 }
4254
4255 return ToField;
4256}
4257
4259 // Import the major distinguishing characteristics of a variable.
4260 DeclContext *DC, *LexicalDC;
4261 DeclarationName Name;
4263 NamedDecl *ToD;
4264 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4265 return std::move(Err);
4266 if (ToD)
4267 return ToD;
4268
4269 // Determine whether we've already imported this field.
4270 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4271 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4272 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4273 // For anonymous indirect fields, match up by index.
4274 if (!Name &&
4276 ASTImporter::getFieldIndex(FoundField))
4277 continue;
4278
4279 if (Importer.IsStructurallyEquivalent(D->getType(),
4280 FoundField->getType(),
4281 !Name.isEmpty())) {
4282 Importer.MapImported(D, FoundField);
4283 return FoundField;
4284 }
4285
4286 // If there are more anonymous fields to check, continue.
4287 if (!Name && I < N-1)
4288 continue;
4289
4290 // FIXME: Why is this case not handled with calling HandleNameConflict?
4291 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4292 << Name << D->getType() << FoundField->getType();
4293 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4294 << FoundField->getType();
4295
4296 return make_error<ASTImportError>(ASTImportError::NameConflict);
4297 }
4298 }
4299
4300 // Import the type.
4301 auto TypeOrErr = import(D->getType());
4302 if (!TypeOrErr)
4303 return TypeOrErr.takeError();
4304
4305 auto **NamedChain =
4306 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4307
4308 unsigned i = 0;
4309 for (auto *PI : D->chain())
4310 if (Expected<NamedDecl *> ToD = import(PI))
4311 NamedChain[i++] = *ToD;
4312 else
4313 return ToD.takeError();
4314
4315 llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4316 IndirectFieldDecl *ToIndirectField;
4317 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4318 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4319 // FIXME here we leak `NamedChain` which is allocated before
4320 return ToIndirectField;
4321
4322 ToIndirectField->setAccess(D->getAccess());
4323 ToIndirectField->setLexicalDeclContext(LexicalDC);
4324 LexicalDC->addDeclInternal(ToIndirectField);
4325 return ToIndirectField;
4326}
4327
4328/// Used as return type of getFriendCountAndPosition.
4330 /// Number of similar looking friends.
4331 unsigned int TotalCount;
4332 /// Index of the specific FriendDecl.
4333 unsigned int IndexOfDecl;
4334};
4335
4336static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4337 FriendDecl *FD2) {
4338 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4339 return false;
4340
4341 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4342 return Importer.IsStructurallyEquivalent(
4343 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4344
4345 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4347 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4349 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4350 return Ctx.IsEquivalent(FD1, FD2);
4351}
4352
4354 FriendDecl *FD) {
4355 unsigned int FriendCount = 0;
4356 std::optional<unsigned int> FriendPosition;
4357 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4358
4359 for (FriendDecl *FoundFriend : RD->friends()) {
4360 if (FoundFriend == FD) {
4361 FriendPosition = FriendCount;
4362 ++FriendCount;
4363 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4364 ++FriendCount;
4365 }
4366 }
4367
4368 assert(FriendPosition && "Friend decl not found in own parent.");
4369
4370 return {FriendCount, *FriendPosition};
4371}
4372
4374 // Import the major distinguishing characteristics of a declaration.
4375 DeclContext *DC, *LexicalDC;
4376 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4377 return std::move(Err);
4378
4379 // Determine whether we've already imported this decl.
4380 // FriendDecl is not a NamedDecl so we cannot use lookup.
4381 // We try to maintain order and count of redundant friend declarations.
4382 const auto *RD = cast<CXXRecordDecl>(DC);
4383 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4384 for (FriendDecl *ImportedFriend : RD->friends())
4385 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4386 ImportedEquivalentFriends.push_back(ImportedFriend);
4387
4388 FriendCountAndPosition CountAndPosition =
4389 getFriendCountAndPosition(Importer, D);
4390
4391 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4392 "Class with non-matching friends is imported, ODR check wrong?");
4393 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4394 return Importer.MapImported(
4395 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4396
4397 // Not found. Create it.
4398 // The declarations will be put into order later by ImportDeclContext.
4400 if (NamedDecl *FriendD = D->getFriendDecl()) {
4401 NamedDecl *ToFriendD;
4402 if (Error Err = importInto(ToFriendD, FriendD))
4403 return std::move(Err);
4404
4405 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4406 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4407 ToFriendD->setObjectOfFriendDecl(false);
4408
4409 ToFU = ToFriendD;
4410 } else { // The friend is a type, not a decl.
4411 if (auto TSIOrErr = import(D->getFriendType()))
4412 ToFU = *TSIOrErr;
4413 else
4414 return TSIOrErr.takeError();
4415 }
4416
4417 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4418 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4419 for (unsigned I = 0; I < D->NumTPLists; I++) {
4420 if (auto ListOrErr = import(FromTPLists[I]))
4421 ToTPLists[I] = *ListOrErr;
4422 else
4423 return ListOrErr.takeError();
4424 }
4425
4426 auto LocationOrErr = import(D->getLocation());
4427 if (!LocationOrErr)
4428 return LocationOrErr.takeError();
4429 auto FriendLocOrErr = import(D->getFriendLoc());
4430 if (!FriendLocOrErr)
4431 return FriendLocOrErr.takeError();
4432 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4433 if (!EllipsisLocOrErr)
4434 return EllipsisLocOrErr.takeError();
4435
4436 FriendDecl *FrD;
4437 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4438 *LocationOrErr, ToFU, *FriendLocOrErr,
4439 *EllipsisLocOrErr, ToTPLists))
4440 return FrD;
4441
4442 FrD->setAccess(D->getAccess());
4443 FrD->setLexicalDeclContext(LexicalDC);
4444 LexicalDC->addDeclInternal(FrD);
4445 return FrD;
4446}
4447
4449 // Import the major distinguishing characteristics of an ivar.
4450 DeclContext *DC, *LexicalDC;
4451 DeclarationName Name;
4453 NamedDecl *ToD;
4454 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4455 return std::move(Err);
4456 if (ToD)
4457 return ToD;
4458
4459 // Determine whether we've already imported this ivar
4460 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4461 for (auto *FoundDecl : FoundDecls) {
4462 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4463 if (Importer.IsStructurallyEquivalent(D->getType(),
4464 FoundIvar->getType())) {
4465 Importer.MapImported(D, FoundIvar);
4466 return FoundIvar;
4467 }
4468
4469 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4470 << Name << D->getType() << FoundIvar->getType();
4471 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4472 << FoundIvar->getType();
4473
4474 return make_error<ASTImportError>(ASTImportError::NameConflict);
4475 }
4476 }
4477
4478 Error Err = Error::success();
4479 auto ToType = importChecked(Err, D->getType());
4480 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4481 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4482 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4483 if (Err)
4484 return std::move(Err);
4485
4486 ObjCIvarDecl *ToIvar;
4487 if (GetImportedOrCreateDecl(
4488 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4489 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4490 ToType, ToTypeSourceInfo,
4491 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4492 return ToIvar;
4493
4494 ToIvar->setLexicalDeclContext(LexicalDC);
4495 LexicalDC->addDeclInternal(ToIvar);
4496 return ToIvar;
4497}
4498
4500
4502 auto RedeclIt = Redecls.begin();
4503 // Import the first part of the decl chain. I.e. import all previous
4504 // declarations starting from the canonical decl.
4505 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4506 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4507 if (!RedeclOrErr)
4508 return RedeclOrErr.takeError();
4509 }
4510 assert(*RedeclIt == D);
4511
4512 // Import the major distinguishing characteristics of a variable.
4513 DeclContext *DC, *LexicalDC;
4514 DeclarationName Name;
4516 NamedDecl *ToD;
4517 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4518 return std::move(Err);
4519 if (ToD)
4520 return ToD;
4521
4522 // Try to find a variable in our own ("to") context with the same name and
4523 // in the same context as the variable we're importing.
4524 VarDecl *FoundByLookup = nullptr;
4525 if (D->isFileVarDecl()) {
4526 SmallVector<NamedDecl *, 4> ConflictingDecls;
4527 unsigned IDNS = Decl::IDNS_Ordinary;
4528 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4529 for (auto *FoundDecl : FoundDecls) {
4530 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4531 continue;
4532
4533 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4534 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4535 continue;
4536 if (Importer.IsStructurallyEquivalent(D->getType(),
4537 FoundVar->getType())) {
4538
4539 // The VarDecl in the "From" context has a definition, but in the
4540 // "To" context we already have a definition.
4541 VarDecl *FoundDef = FoundVar->getDefinition();
4542 if (D->isThisDeclarationADefinition() && FoundDef)
4543 // FIXME Check for ODR error if the two definitions have
4544 // different initializers?
4545 return Importer.MapImported(D, FoundDef);
4546
4547 // The VarDecl in the "From" context has an initializer, but in the
4548 // "To" context we already have an initializer.
4549 const VarDecl *FoundDInit = nullptr;
4550 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4551 // FIXME Diagnose ODR error if the two initializers are different?
4552 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4553
4554 FoundByLookup = FoundVar;
4555 break;
4556 }
4557
4558 const ArrayType *FoundArray
4559 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4560 const ArrayType *TArray
4561 = Importer.getToContext().getAsArrayType(D->getType());
4562 if (FoundArray && TArray) {
4563 if (isa<IncompleteArrayType>(FoundArray) &&
4564 isa<ConstantArrayType>(TArray)) {
4565 // Import the type.
4566 if (auto TyOrErr = import(D->getType()))
4567 FoundVar->setType(*TyOrErr);
4568 else
4569 return TyOrErr.takeError();
4570
4571 FoundByLookup = FoundVar;
4572 break;
4573 } else if (isa<IncompleteArrayType>(TArray) &&
4574 isa<ConstantArrayType>(FoundArray)) {
4575 FoundByLookup = FoundVar;
4576 break;
4577 }
4578 }
4579
4580 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4581 << Name << D->getType() << FoundVar->getType();
4582 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4583 << FoundVar->getType();
4584 ConflictingDecls.push_back(FoundDecl);
4585 }
4586 }
4587
4588 if (!ConflictingDecls.empty()) {
4589 ExpectedName NameOrErr = Importer.HandleNameConflict(
4590 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4591 if (NameOrErr)
4592 Name = NameOrErr.get();
4593 else
4594 return NameOrErr.takeError();
4595 }
4596 }
4597
4598 Error Err = Error::success();
4599 auto ToType = importChecked(Err, D->getType());
4600 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4601 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4602 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4603 if (Err)
4604 return std::move(Err);
4605
4606 VarDecl *ToVar;
4607 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4608 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4609 if (Error Err =
4610 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4611 return std::move(Err);
4612 DecompositionDecl *ToDecomp;
4613 if (GetImportedOrCreateDecl(
4614 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4615 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4616 return ToDecomp;
4617 ToVar = ToDecomp;
4618 } else {
4619 // Create the imported variable.
4620 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4621 ToInnerLocStart, Loc,
4622 Name.getAsIdentifierInfo(), ToType,
4623 ToTypeSourceInfo, D->getStorageClass()))
4624 return ToVar;
4625 }
4626
4627 ToVar->setTSCSpec(D->getTSCSpec());
4628 ToVar->setQualifierInfo(ToQualifierLoc);
4629 ToVar->setAccess(D->getAccess());
4630 ToVar->setLexicalDeclContext(LexicalDC);
4631 if (D->isInlineSpecified())
4632 ToVar->setInlineSpecified();
4633 if (D->isInline())
4634 ToVar->setImplicitlyInline();
4635
4636 if (FoundByLookup) {
4637 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4638 ToVar->setPreviousDecl(Recent);
4639 }
4640
4641 // Import the described template, if any.
4642 if (D->getDescribedVarTemplate()) {
4643 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4644 if (!ToVTOrErr)
4645 return ToVTOrErr.takeError();
4646 } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4647 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4648 VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
4649 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4650 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4651 else
4652 return ToInstOrErr.takeError();
4653 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4655 else
4656 return POIOrErr.takeError();
4657 }
4658
4659 if (Error Err = ImportInitializer(D, ToVar))
4660 return std::move(Err);
4661
4662 if (D->isConstexpr())
4663 ToVar->setConstexpr(true);
4664
4665 addDeclToContexts(D, ToVar);
4666
4667 // Import the rest of the chain. I.e. import all subsequent declarations.
4668 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4669 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4670 if (!RedeclOrErr)
4671 return RedeclOrErr.takeError();
4672 }
4673
4674 return ToVar;
4675}
4676
4678 // Parameters are created in the translation unit's context, then moved
4679 // into the function declaration's context afterward.
4681
4682 Error Err = Error::success();
4683 auto ToDeclName = importChecked(Err, D->getDeclName());
4684 auto ToLocation = importChecked(Err, D->getLocation());
4685 auto ToType = importChecked(Err, D->getType());
4686 if (Err)
4687 return std::move(Err);
4688
4689 // Create the imported parameter.
4690 ImplicitParamDecl *ToParm = nullptr;
4691 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4692 ToLocation, ToDeclName.getAsIdentifierInfo(),
4693 ToType, D->getParameterKind()))
4694 return ToParm;
4695 return ToParm;
4696}
4697
4699 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4702 FromParam->getExplicitObjectParamThisLoc());
4703 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4704
4705 if (FromParam->hasUninstantiatedDefaultArg()) {
4706 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4707 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4708 else
4709 return ToDefArgOrErr.takeError();
4710 } else if (FromParam->hasUnparsedDefaultArg()) {
4711 ToParam->setUnparsedDefaultArg();
4712 } else if (FromParam->hasDefaultArg()) {
4713 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4714 ToParam->setDefaultArg(*ToDefArgOrErr);
4715 else
4716 return ToDefArgOrErr.takeError();
4717 }
4718
4719 return Error::success();
4720}
4721
4724 Error Err = Error::success();
4725 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4726 ConstructorUsingShadowDecl *ToShadow =
4727 importChecked(Err, From.getShadowDecl());
4728 if (Err)
4729 return std::move(Err);
4730 return InheritedConstructor(ToShadow, ToBaseCtor);
4731}
4732
4734 // Parameters are created in the translation unit's context, then moved
4735 // into the function declaration's context afterward.
4737
4738 Error Err = Error::success();
4739 auto ToDeclName = importChecked(Err, D->getDeclName());
4740 auto ToLocation = importChecked(Err, D->getLocation());
4741 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4742 auto ToType = importChecked(Err, D->getType());
4743 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4744 if (Err)
4745 return std::move(Err);
4746
4747 ParmVarDecl *ToParm;
4748 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4749 ToInnerLocStart, ToLocation,
4750 ToDeclName.getAsIdentifierInfo(), ToType,
4751 ToTypeSourceInfo, D->getStorageClass(),
4752 /*DefaultArg*/ nullptr))
4753 return ToParm;
4754
4755 // Set the default argument. It should be no problem if it was already done.
4756 // Do not import the default expression before GetImportedOrCreateDecl call
4757 // to avoid possible infinite import loop because circular dependency.
4758 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4759 return std::move(Err);
4760
4761 if (D->isObjCMethodParameter()) {
4762 ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex());
4763 ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier());
4764 } else {
4765 ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4766 D->getFunctionScopeIndex());
4767 }
4768
4769 return ToParm;
4770}
4771
4773 // Import the major distinguishing characteristics of a method.
4774 DeclContext *DC, *LexicalDC;
4775 DeclarationName Name;
4777 NamedDecl *ToD;
4778 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4779 return std::move(Err);
4780 if (ToD)
4781 return ToD;
4782
4783 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4784 for (auto *FoundDecl : FoundDecls) {
4785 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4786 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4787 continue;
4788
4789 // Check return types.
4790 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4791 FoundMethod->getReturnType())) {
4792 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4793 << D->isInstanceMethod() << Name << D->getReturnType()
4794 << FoundMethod->getReturnType();
4795 Importer.ToDiag(FoundMethod->getLocation(),
4796 diag::note_odr_objc_method_here)
4797 << D->isInstanceMethod() << Name;
4798
4799 return make_error<ASTImportError>(ASTImportError::NameConflict);
4800 }
4801
4802 // Check the number of parameters.
4803 if (D->param_size() != FoundMethod->param_size()) {
4804 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4805 << D->isInstanceMethod() << Name
4806 << D->param_size() << FoundMethod->param_size();
4807 Importer.ToDiag(FoundMethod->getLocation(),
4808 diag::note_odr_objc_method_here)
4809 << D->isInstanceMethod() << Name;
4810
4811 return make_error<ASTImportError>(ASTImportError::NameConflict);
4812 }
4813
4814 // Check parameter types.
4815 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
4816 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4817 P != PEnd; ++P, ++FoundP) {
4818 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4819 (*FoundP)->getType())) {
4820 Importer.FromDiag((*P)->getLocation(),
4821 diag::warn_odr_objc_method_param_type_inconsistent)
4822 << D->isInstanceMethod() << Name
4823 << (*P)->getType() << (*FoundP)->getType();
4824 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4825 << (*FoundP)->getType();
4826
4827 return make_error<ASTImportError>(ASTImportError::NameConflict);
4828 }
4829 }
4830
4831 // Check variadic/non-variadic.
4832 // Check the number of parameters.
4833 if (D->isVariadic() != FoundMethod->isVariadic()) {
4834 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4835 << D->isInstanceMethod() << Name;
4836 Importer.ToDiag(FoundMethod->getLocation(),
4837 diag::note_odr_objc_method_here)
4838 << D->isInstanceMethod() << Name;
4839
4840 return make_error<ASTImportError>(ASTImportError::NameConflict);
4841 }
4842
4843 // FIXME: Any other bits we need to merge?
4844 return Importer.MapImported(D, FoundMethod);
4845 }
4846 }
4847
4848 Error Err = Error::success();
4849 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4850 auto ToReturnType = importChecked(Err, D->getReturnType());
4851 auto ToReturnTypeSourceInfo =
4852 importChecked(Err, D->getReturnTypeSourceInfo());
4853 if (Err)
4854 return std::move(Err);
4855
4856 ObjCMethodDecl *ToMethod;
4857 if (GetImportedOrCreateDecl(
4858 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4859 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4860 D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(),
4861 D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(),
4862 D->getImplementationControl(), D->hasRelatedResultType()))
4863 return ToMethod;
4864
4865 // FIXME: When we decide to merge method definitions, we'll need to
4866 // deal with implicit parameters.
4867
4868 // Import the parameters
4870 for (auto *FromP : D->parameters()) {
4871 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4872 ToParams.push_back(*ToPOrErr);
4873 else
4874 return ToPOrErr.takeError();
4875 }
4876
4877 // Set the parameters.
4878 for (auto *ToParam : ToParams) {
4879 ToParam->setOwningFunction(ToMethod);
4880 ToMethod->addDeclInternal(ToParam);
4881 }
4882
4884 D->getSelectorLocs(FromSelLocs);
4885 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4886 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4887 return std::move(Err);
4888
4889 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4890
4891 ToMethod->setLexicalDeclContext(LexicalDC);
4892 LexicalDC->addDeclInternal(ToMethod);
4893
4894 // Implicit params are declared when Sema encounters the definition but this
4895 // never happens when the method is imported. Manually declare the implicit
4896 // params now that the MethodDecl knows its class interface.
4897 if (D->getSelfDecl())
4898 ToMethod->createImplicitParams(Importer.getToContext(),
4899 ToMethod->getClassInterface());
4900
4901 return ToMethod;
4902}
4903
4905 // Import the major distinguishing characteristics of a category.
4906 DeclContext *DC, *LexicalDC;
4907 DeclarationName Name;
4909 NamedDecl *ToD;
4910 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4911 return std::move(Err);
4912 if (ToD)
4913 return ToD;
4914
4915 Error Err = Error::success();
4916 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4917 auto ToLocation = importChecked(Err, D->getLocation());
4918 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4919 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4920 if (Err)
4921 return std::move(Err);
4922
4924 if (GetImportedOrCreateDecl(
4925 Result, D, Importer.getToContext(), DC, D->getVariance(),
4926 ToVarianceLoc, D->getIndex(),
4927 ToLocation, Name.getAsIdentifierInfo(),
4928 ToColonLoc, ToTypeSourceInfo))
4929 return Result;
4930
4931 // Only import 'ObjCTypeParamType' after the decl is created.
4932 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4933 if (Err)
4934 return std::move(Err);
4935 Result->setTypeForDecl(ToTypeForDecl);
4936 Result->setLexicalDeclContext(LexicalDC);
4937 return Result;
4938}
4939
4941 // Import the major distinguishing characteristics of a category.
4942 DeclContext *DC, *LexicalDC;
4943 DeclarationName Name;
4945 NamedDecl *ToD;
4946 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4947 return std::move(Err);
4948 if (ToD)
4949 return ToD;
4950
4951 ObjCInterfaceDecl *ToInterface;
4952 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4953 return std::move(Err);
4954
4955 // Determine if we've already encountered this category.
4956 ObjCCategoryDecl *MergeWithCategory
4957 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4958 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4959 if (!ToCategory) {
4960
4961 Error Err = Error::success();
4962 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4963 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4964 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4965 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4966 if (Err)
4967 return std::move(Err);
4968
4969 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4970 ToAtStartLoc, Loc,
4971 ToCategoryNameLoc,
4972 Name.getAsIdentifierInfo(), ToInterface,
4973 /*TypeParamList=*/nullptr,
4974 ToIvarLBraceLoc,
4975 ToIvarRBraceLoc))
4976 return ToCategory;
4977
4978 ToCategory->setLexicalDeclContext(LexicalDC);
4979 LexicalDC->addDeclInternal(ToCategory);
4980 // Import the type parameter list after MapImported, to avoid
4981 // loops when bringing in their DeclContext.
4982 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4983 ToCategory->setTypeParamList(*PListOrErr);
4984 else
4985 return PListOrErr.takeError();
4986
4987 // Import protocols
4989 SmallVector<SourceLocation, 4> ProtocolLocs;
4991 = D->protocol_loc_begin();
4992 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
4993 FromProtoEnd = D->protocol_end();
4994 FromProto != FromProtoEnd;
4995 ++FromProto, ++FromProtoLoc) {
4996 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
4997 Protocols.push_back(*ToProtoOrErr);
4998 else
4999 return ToProtoOrErr.takeError();
5000
5001 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5002 ProtocolLocs.push_back(*ToProtoLocOrErr);
5003 else
5004 return ToProtoLocOrErr.takeError();
5005 }
5006
5007 // FIXME: If we're merging, make sure that the protocol list is the same.
5008 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5009 ProtocolLocs.data(), Importer.getToContext());
5010
5011 } else {
5012 Importer.MapImported(D, ToCategory);
5013 }
5014
5015 // Import all of the members of this category.
5016 if (Error Err = ImportDeclContext(D))
5017 return std::move(Err);
5018
5019 // If we have an implementation, import it as well.
5020 if (D->getImplementation()) {
5021 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5022 import(D->getImplementation()))
5023 ToCategory->setImplementation(*ToImplOrErr);
5024 else
5025 return ToImplOrErr.takeError();
5026 }
5027
5028 return ToCategory;
5029}
5030
5033 if (To->getDefinition()) {
5035 if (Error Err = ImportDeclContext(From))
5036 return Err;
5037 return Error::success();
5038 }
5039
5040 // Start the protocol definition
5041 To->startDefinition();
5042
5043 // Import protocols
5045 SmallVector<SourceLocation, 4> ProtocolLocs;
5047 From->protocol_loc_begin();
5048 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5049 FromProtoEnd = From->protocol_end();
5050 FromProto != FromProtoEnd;
5051 ++FromProto, ++FromProtoLoc) {
5052 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5053 Protocols.push_back(*ToProtoOrErr);
5054 else
5055 return ToProtoOrErr.takeError();
5056
5057 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5058 ProtocolLocs.push_back(*ToProtoLocOrErr);
5059 else
5060 return ToProtoLocOrErr.takeError();
5061
5062 }
5063
5064 // FIXME: If we're merging, make sure that the protocol list is the same.
5065 To->setProtocolList(Protocols.data(), Protocols.size(),
5066 ProtocolLocs.data(), Importer.getToContext());
5067
5068 if (shouldForceImportDeclContext(Kind)) {
5069 // Import all of the members of this protocol.
5070 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5071 return Err;
5072 }
5073 return Error::success();
5074}
5075
5077 // If this protocol has a definition in the translation unit we're coming
5078 // from, but this particular declaration is not that definition, import the
5079 // definition and map to that.
5080 ObjCProtocolDecl *Definition = D->getDefinition();
5081 if (Definition && Definition != D) {
5082 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5083 return Importer.MapImported(D, *ImportedDefOrErr);
5084 else
5085 return ImportedDefOrErr.takeError();
5086 }
5087
5088 // Import the major distinguishing characteristics of a protocol.
5089 DeclContext *DC, *LexicalDC;
5090 DeclarationName Name;
5092 NamedDecl *ToD;
5093 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5094 return std::move(Err);
5095 if (ToD)
5096 return ToD;
5097
5098 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5099 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5100 for (auto *FoundDecl : FoundDecls) {
5102 continue;
5103
5104 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5105 break;
5106 }
5107
5108 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5109 if (!ToProto) {
5110 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5111 if (!ToAtBeginLocOrErr)
5112 return ToAtBeginLocOrErr.takeError();
5113
5114 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5115 Name.getAsIdentifierInfo(), Loc,
5116 *ToAtBeginLocOrErr,
5117 /*PrevDecl=*/nullptr))
5118 return ToProto;
5119 ToProto->setLexicalDeclContext(LexicalDC);
5120 LexicalDC->addDeclInternal(ToProto);
5121 }
5122
5123 Importer.MapImported(D, ToProto);
5124
5125 if (D->isThisDeclarationADefinition())
5126 if (Error Err = ImportDefinition(D, ToProto))
5127 return std::move(Err);
5128
5129 return ToProto;
5130}
5131
5133 DeclContext *DC, *LexicalDC;
5134 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5135 return std::move(Err);
5136
5137 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5138 if (!ExternLocOrErr)
5139 return ExternLocOrErr.takeError();
5140
5141 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5142 if (!LangLocOrErr)
5143 return LangLocOrErr.takeError();
5144
5145 bool HasBraces = D->hasBraces();
5146
5147 LinkageSpecDecl *ToLinkageSpec;
5148 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5149 *ExternLocOrErr, *LangLocOrErr,
5150 D->getLanguage(), HasBraces))
5151 return ToLinkageSpec;
5152
5153 if (HasBraces) {
5154 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5155 if (!RBraceLocOrErr)
5156 return RBraceLocOrErr.takeError();
5157 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5158 }
5159
5160 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5161 LexicalDC->addDeclInternal(ToLinkageSpec);
5162
5163 return ToLinkageSpec;
5164}
5165
5167 BaseUsingDecl *ToSI) {
5168 for (UsingShadowDecl *FromShadow : D->shadows()) {
5169 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5170 ToSI->addShadowDecl(*ToShadowOrErr);
5171 else
5172 // FIXME: We return error here but the definition is already created
5173 // and available with lookups. How to fix this?..
5174 return ToShadowOrErr.takeError();
5175 }
5176 return ToSI;
5177}
5178
5180 DeclContext *DC, *LexicalDC;
5181 DeclarationName Name;
5183 NamedDecl *ToD = nullptr;
5184 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5185 return std::move(Err);
5186 if (ToD)
5187 return ToD;
5188
5189 Error Err = Error::success();
5190 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5191 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5192 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5193 if (Err)
5194 return std::move(Err);
5195
5196 DeclarationNameInfo NameInfo(Name, ToLoc);
5197 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5198 return std::move(Err);
5199
5200 UsingDecl *ToUsing;
5201 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5202 ToUsingLoc, ToQualifierLoc, NameInfo,
5203 D->hasTypename()))
5204 return ToUsing;
5205
5206 ToUsing->setLexicalDeclContext(LexicalDC);
5207 LexicalDC->addDeclInternal(ToUsing);
5208
5209 if (NamedDecl *FromPattern =
5211 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5213 ToUsing, *ToPatternOrErr);
5214 else
5215 return ToPatternOrErr.takeError();
5216 }
5217
5218 return ImportUsingShadowDecls(D, ToUsing);
5219}
5220
5222 DeclContext *DC, *LexicalDC;
5223 DeclarationName Name;
5225 NamedDecl *ToD = nullptr;
5226 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5227 return std::move(Err);
5228 if (ToD)
5229 return ToD;
5230
5231 Error Err = Error::success();
5232 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5233 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5234 auto ToNameLoc = importChecked(Err, D->getLocation());
5235 auto *ToEnumType = importChecked(Err, D->getEnumType());
5236 if (Err)
5237 return std::move(Err);
5238
5239 UsingEnumDecl *ToUsingEnum;
5240 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5241 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5242 return ToUsingEnum;
5243
5244 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5245 LexicalDC->addDeclInternal(ToUsingEnum);
5246
5247 if (UsingEnumDecl *FromPattern =
5249 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5250 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5251 *ToPatternOrErr);
5252 else
5253 return ToPatternOrErr.takeError();
5254 }
5255
5256 return ImportUsingShadowDecls(D, ToUsingEnum);
5257}
5258
5260 DeclContext *DC, *LexicalDC;
5261 DeclarationName Name;
5263 NamedDecl *ToD = nullptr;
5264 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5265 return std::move(Err);
5266 if (ToD)
5267 return ToD;
5268
5269 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5270 if (!ToIntroducerOrErr)
5271 return ToIntroducerOrErr.takeError();
5272
5273 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5274 if (!ToTargetOrErr)
5275 return ToTargetOrErr.takeError();
5276
5277 UsingShadowDecl *ToShadow;
5278 if (auto *FromConstructorUsingShadow =
5279 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5280 Error Err = Error::success();
5282 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5283 if (Err)
5284 return std::move(Err);
5285 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5286 // is really the "NominatedBaseClassShadowDecl" value if it exists
5287 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5288 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5289 // get the correct values.
5290 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5291 ToShadow, D, Importer.getToContext(), DC, Loc,
5292 cast<UsingDecl>(*ToIntroducerOrErr),
5293 Nominated ? Nominated : *ToTargetOrErr,
5294 FromConstructorUsingShadow->constructsVirtualBase()))
5295 return ToShadow;
5296 } else {
5297 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5298 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5299 return ToShadow;
5300 }
5301
5302 ToShadow->setLexicalDeclContext(LexicalDC);
5303 ToShadow->setAccess(D->getAccess());
5304
5305 if (UsingShadowDecl *FromPattern =
5307 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5309 ToShadow, *ToPatternOrErr);
5310 else
5311 // FIXME: We return error here but the definition is already created
5312 // and available with lookups. How to fix this?..
5313 return ToPatternOrErr.takeError();
5314 }
5315
5316 LexicalDC->addDeclInternal(ToShadow);
5317
5318 return ToShadow;
5319}
5320
5322 DeclContext *DC, *LexicalDC;
5323 DeclarationName Name;
5325 NamedDecl *ToD = nullptr;
5326 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5327 return std::move(Err);
5328 if (ToD)
5329 return ToD;
5330
5331 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5332 if (!ToComAncestorOrErr)
5333 return ToComAncestorOrErr.takeError();
5334
5335 Error Err = Error::success();
5336 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5337 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5338 auto ToNamespaceKeyLocation =
5339 importChecked(Err, D->getNamespaceKeyLocation());
5340 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5341 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5342 if (Err)
5343 return std::move(Err);
5344
5345 UsingDirectiveDecl *ToUsingDir;
5346 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5347 ToUsingLoc,
5348 ToNamespaceKeyLocation,
5349 ToQualifierLoc,
5350 ToIdentLocation,
5351 ToNominatedNamespace, *ToComAncestorOrErr))
5352 return ToUsingDir;
5353
5354 ToUsingDir->setLexicalDeclContext(LexicalDC);
5355 LexicalDC->addDeclInternal(ToUsingDir);
5356
5357 return ToUsingDir;
5358}
5359
5361 DeclContext *DC, *LexicalDC;
5362 DeclarationName Name;
5364 NamedDecl *ToD = nullptr;
5365 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5366 return std::move(Err);
5367 if (ToD)
5368 return ToD;
5369
5370 auto ToInstantiatedFromUsingOrErr =
5371 Importer.Import(D->getInstantiatedFromUsingDecl());
5372 if (!ToInstantiatedFromUsingOrErr)
5373 return ToInstantiatedFromUsingOrErr.takeError();
5374 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5375 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5376 return std::move(Err);
5377
5378 UsingPackDecl *ToUsingPack;
5379 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5380 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5381 Expansions))
5382 return ToUsingPack;
5383
5384 addDeclToContexts(D, ToUsingPack);
5385
5386 return ToUsingPack;
5387}
5388
5391 DeclContext *DC, *LexicalDC;
5392 DeclarationName Name;
5394 NamedDecl *ToD = nullptr;
5395 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5396 return std::move(Err);
5397 if (ToD)
5398 return ToD;
5399
5400 Error Err = Error::success();
5401 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5402 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5403 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5404 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5405 if (Err)
5406 return std::move(Err);
5407
5408 DeclarationNameInfo NameInfo(Name, ToLoc);
5409 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5410 return std::move(Err);
5411
5412 UnresolvedUsingValueDecl *ToUsingValue;
5413 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5414 ToUsingLoc, ToQualifierLoc, NameInfo,
5415 ToEllipsisLoc))
5416 return ToUsingValue;
5417
5418 ToUsingValue->setAccess(D->getAccess());
5419 ToUsingValue->setLexicalDeclContext(LexicalDC);
5420 LexicalDC->addDeclInternal(ToUsingValue);
5421
5422 return ToUsingValue;
5423}
5424
5427 DeclContext *DC, *LexicalDC;
5428 DeclarationName Name;
5430 NamedDecl *ToD = nullptr;
5431 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5432 return std::move(Err);
5433 if (ToD)
5434 return ToD;
5435
5436 Error Err = Error::success();
5437 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5438 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5439 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5440 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5441 if (Err)
5442 return std::move(Err);
5443
5445 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5446 ToUsingLoc, ToTypenameLoc,
5447 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5448 return ToUsing;
5449
5450 ToUsing->setAccess(D->getAccess());
5451 ToUsing->setLexicalDeclContext(LexicalDC);
5452 LexicalDC->addDeclInternal(ToUsing);
5453
5454 return ToUsing;
5455}
5456
5458 Decl* ToD = nullptr;
5459 switch (D->getBuiltinTemplateKind()) {
5461 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5462 break;
5464 ToD = Importer.getToContext().getTypePackElementDecl();
5465 break;
5466 }
5467 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5468 Importer.MapImported(D, ToD);
5469 return ToD;
5470}
5471
5474 if (To->getDefinition()) {
5475 // Check consistency of superclass.
5476 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5477 if (FromSuper) {
5478 if (auto FromSuperOrErr = import(FromSuper))
5479 FromSuper = *FromSuperOrErr;
5480 else
5481 return FromSuperOrErr.takeError();
5482 }
5483
5484 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5485 if ((bool)FromSuper != (bool)ToSuper ||
5486 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5487 Importer.ToDiag(To->getLocation(),
5488 diag::warn_odr_objc_superclass_inconsistent)
5489 << To->getDeclName();
5490 if (ToSuper)
5491 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5492 << To->getSuperClass()->getDeclName();
5493 else
5494 Importer.ToDiag(To->getLocation(),
5495 diag::note_odr_objc_missing_superclass);
5496 if (From->getSuperClass())
5497 Importer.FromDiag(From->getSuperClassLoc(),
5498 diag::note_odr_objc_superclass)
5499 << From->getSuperClass()->getDeclName();
5500 else
5501 Importer.FromDiag(From->getLocation(),
5502 diag::note_odr_objc_missing_superclass);
5503 }
5504
5506 if (Error Err = ImportDeclContext(From))
5507 return Err;
5508 return Error::success();
5509 }
5510
5511 // Start the definition.
5512 To->startDefinition();
5513
5514 // If this class has a superclass, import it.
5515 if (From->getSuperClass()) {
5516 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5517 To->setSuperClass(*SuperTInfoOrErr);
5518 else
5519 return SuperTInfoOrErr.takeError();
5520 }
5521
5522 // Import protocols
5524 SmallVector<SourceLocation, 4> ProtocolLocs;
5526 From->protocol_loc_begin();
5527
5529 FromProtoEnd = From->protocol_end();
5530 FromProto != FromProtoEnd;
5531 ++FromProto, ++FromProtoLoc) {
5532 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5533 Protocols.push_back(*ToProtoOrErr);
5534 else
5535 return ToProtoOrErr.takeError();
5536
5537 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5538 ProtocolLocs.push_back(*ToProtoLocOrErr);
5539 else
5540 return ToProtoLocOrErr.takeError();
5541
5542 }
5543
5544 // FIXME: If we're merging, make sure that the protocol list is the same.
5545 To->setProtocolList(Protocols.data(), Protocols.size(),
5546 ProtocolLocs.data(), Importer.getToContext());
5547
5548 // Import categories. When the categories themselves are imported, they'll
5549 // hook themselves into this interface.
5550 for (auto *Cat : From->known_categories()) {
5551 auto ToCatOrErr = import(Cat);
5552 if (!ToCatOrErr)
5553 return ToCatOrErr.takeError();
5554 }
5555
5556 // If we have an @implementation, import it as well.
5557 if (From->getImplementation()) {
5558 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5559 import(From->getImplementation()))
5560 To->setImplementation(*ToImplOrErr);
5561 else
5562 return ToImplOrErr.takeError();
5563 }
5564
5565 // Import all of the members of this class.
5566 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5567 return Err;
5568
5569 return Error::success();
5570}
5571
5574 if (!list)
5575 return nullptr;
5576
5578 for (auto *fromTypeParam : *list) {
5579 if (auto toTypeParamOrErr = import(fromTypeParam))
5580 toTypeParams.push_back(*toTypeParamOrErr);
5581 else
5582 return toTypeParamOrErr.takeError();
5583 }
5584
5585 auto LAngleLocOrErr = import(list->getLAngleLoc());
5586 if (!LAngleLocOrErr)
5587 return LAngleLocOrErr.takeError();
5588
5589 auto RAngleLocOrErr = import(list->getRAngleLoc());
5590 if (!RAngleLocOrErr)
5591 return RAngleLocOrErr.takeError();
5592
5593 return ObjCTypeParamList::create(Importer.getToContext(),
5594 *LAngleLocOrErr,
5595 toTypeParams,
5596 *RAngleLocOrErr);
5597}
5598
5600 // If this class has a definition in the translation unit we're coming from,
5601 // but this particular declaration is not that definition, import the
5602 // definition and map to that.
5603 ObjCInterfaceDecl *Definition = D->getDefinition();
5604 if (Definition && Definition != D) {
5605 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5606 return Importer.MapImported(D, *ImportedDefOrErr);
5607 else
5608 return ImportedDefOrErr.takeError();
5609 }
5610
5611 // Import the major distinguishing characteristics of an @interface.
5612 DeclContext *DC, *LexicalDC;
5613 DeclarationName Name;
5615 NamedDecl *ToD;
5616 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5617 return std::move(Err);
5618 if (ToD)
5619 return ToD;
5620
5621 // Look for an existing interface with the same name.
5622 ObjCInterfaceDecl *MergeWithIface = nullptr;
5623 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5624 for (auto *FoundDecl : FoundDecls) {
5626 continue;
5627
5628 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5629 break;
5630 }
5631
5632 // Create an interface declaration, if one does not already exist.
5633 ObjCInterfaceDecl *ToIface = MergeWithIface;
5634 if (!ToIface) {
5635 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5636 if (!AtBeginLocOrErr)
5637 return AtBeginLocOrErr.takeError();
5638
5639 if (GetImportedOrCreateDecl(
5640 ToIface, D, Importer.getToContext(), DC,
5641 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5642 /*TypeParamList=*/nullptr,
5643 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5644 return ToIface;
5645 ToIface->setLexicalDeclContext(LexicalDC);
5646 LexicalDC->addDeclInternal(ToIface);
5647 }
5648 Importer.MapImported(D, ToIface);
5649 // Import the type parameter list after MapImported, to avoid
5650 // loops when bringing in their DeclContext.
5651 if (auto ToPListOrErr =
5652 ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
5653 ToIface->setTypeParamList(*ToPListOrErr);
5654 else
5655 return ToPListOrErr.takeError();
5656
5657 if (D->isThisDeclarationADefinition())
5658 if (Error Err = ImportDefinition(D, ToIface))
5659 return std::move(Err);
5660
5661 return ToIface;
5662}
5663
5667 if (Error Err = importInto(Category, D->getCategoryDecl()))
5668 return std::move(Err);
5669
5670 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5671 if (!ToImpl) {
5672 DeclContext *DC, *LexicalDC;
5673 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5674 return std::move(Err);
5675
5676 Error Err = Error::success();
5677 auto ToLocation = importChecked(Err, D->getLocation());
5678 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5679 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5680 if (Err)
5681 return std::move(Err);
5682
5683 if (GetImportedOrCreateDecl(
5684 ToImpl, D, Importer.getToContext(), DC,
5685 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5686 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5687 return ToImpl;
5688
5689 ToImpl->setLexicalDeclContext(LexicalDC);
5690 LexicalDC->addDeclInternal(ToImpl);
5691 Category->setImplementation(ToImpl);
5692 }
5693
5694 Importer.MapImported(D, ToImpl);
5695 if (Error Err = ImportDeclContext(D))
5696 return std::move(Err);
5697
5698 return ToImpl;
5699}
5700
5703 // Find the corresponding interface.
5704 ObjCInterfaceDecl *Iface;
5705 if (Error Err = importInto(Iface, D->getClassInterface()))
5706 return std::move(Err);
5707
5708 // Import the superclass, if any.
5709 ObjCInterfaceDecl *Super;
5710 if (Error Err = importInto(Super, D->getSuperClass()))
5711 return std::move(Err);
5712
5714 if (!Impl) {
5715 // We haven't imported an implementation yet. Create a new @implementation
5716 // now.
5717 DeclContext *DC, *LexicalDC;
5718 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5719 return std::move(Err);
5720
5721 Error Err = Error::success();
5722 auto ToLocation = importChecked(Err, D->getLocation());
5723 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5724 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5725 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5726 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5727 if (Err)
5728 return std::move(Err);
5729
5730 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5731 DC, Iface, Super,
5732 ToLocation,
5733 ToAtStartLoc,
5734 ToSuperClassLoc,
5735 ToIvarLBraceLoc,
5736 ToIvarRBraceLoc))
5737 return Impl;
5738
5739 Impl->setLexicalDeclContext(LexicalDC);
5740
5741 // Associate the implementation with the class it implements.
5742 Iface->setImplementation(Impl);
5743 Importer.MapImported(D, Iface->getImplementation());
5744 } else {
5745 Importer.MapImported(D, Iface->getImplementation());
5746
5747 // Verify that the existing @implementation has the same superclass.
5748 if ((Super && !Impl->getSuperClass()) ||
5749 (!Super && Impl->getSuperClass()) ||
5750 (Super && Impl->getSuperClass() &&
5752 Impl->getSuperClass()))) {
5753 Importer.ToDiag(Impl->getLocation(),
5754 diag::warn_odr_objc_superclass_inconsistent)
5755 << Iface->getDeclName();
5756 // FIXME: It would be nice to have the location of the superclass
5757 // below.
5758 if (Impl->getSuperClass())
5759 Importer.ToDiag(Impl->getLocation(),
5760 diag::note_odr_objc_superclass)
5761 << Impl->getSuperClass()->getDeclName();
5762 else
5763 Importer.ToDiag(Impl->getLocation(),
5764 diag::note_odr_objc_missing_superclass);
5765 if (D->getSuperClass())
5766 Importer.FromDiag(D->getLocation(),
5767 diag::note_odr_objc_superclass)
5768 << D->getSuperClass()->getDeclName();
5769 else
5770 Importer.FromDiag(D->getLocation(),
5771 diag::note_odr_objc_missing_superclass);
5772
5773 return make_error<ASTImportError>(ASTImportError::NameConflict);
5774 }
5775 }
5776
5777 // Import all of the members of this @implementation.
5778 if (Error Err = ImportDeclContext(D))
5779 return std::move(Err);
5780
5781 return Impl;
5782}
5783
5785 // Import the major distinguishing characteristics of an @property.
5786 DeclContext *DC, *LexicalDC;
5787 DeclarationName Name;
5789 NamedDecl *ToD;
5790 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5791 return std::move(Err);
5792 if (ToD)
5793 return ToD;
5794
5795 // Check whether we have already imported this property.
5796 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5797 for (auto *FoundDecl : FoundDecls) {
5798 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5799 // Instance and class properties can share the same name but are different
5800 // declarations.
5801 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5802 continue;
5803
5804 // Check property types.
5805 if (!Importer.IsStructurallyEquivalent(D->getType(),
5806 FoundProp->getType())) {
5807 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5808 << Name << D->getType() << FoundProp->getType();
5809 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5810 << FoundProp->getType();
5811
5812 return make_error<ASTImportError>(ASTImportError::NameConflict);
5813 }
5814
5815 // FIXME: Check property attributes, getters, setters, etc.?
5816
5817 // Consider these properties to be equivalent.
5818 Importer.MapImported(D, FoundProp);
5819 return FoundProp;
5820 }
5821 }
5822
5823 Error Err = Error::success();
5824 auto ToType = importChecked(Err, D->getType());
5825 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5826 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5827 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5828 if (Err)
5829 return std::move(Err);
5830
5831 // Create the new property.
5832 ObjCPropertyDecl *ToProperty;
5833 if (GetImportedOrCreateDecl(
5834 ToProperty, D, Importer.getToContext(), DC, Loc,
5835 Name.getAsIdentifierInfo(), ToAtLoc,
5836 ToLParenLoc, ToType,
5837 ToTypeSourceInfo, D->getPropertyImplementation()))
5838 return ToProperty;
5839
5840 auto ToGetterName = importChecked(Err, D->getGetterName());
5841 auto ToSetterName = importChecked(Err, D->getSetterName());
5842 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5843 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5844 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5845 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5846 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5847 if (Err)
5848 return std::move(Err);
5849
5850 ToProperty->setLexicalDeclContext(LexicalDC);
5851 LexicalDC->addDeclInternal(ToProperty);
5852
5853 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
5855 D->getPropertyAttributesAsWritten());
5856 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5857 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5858 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5859 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5860 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5861 return ToProperty;
5862}
5863
5867 if (Error Err = importInto(Property, D->getPropertyDecl()))
5868 return std::move(Err);
5869
5870 DeclContext *DC, *LexicalDC;
5871 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5872 return std::move(Err);
5873
5874 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5875
5876 // Import the ivar (for an @synthesize).
5877 ObjCIvarDecl *Ivar = nullptr;
5878 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5879 return std::move(Err);
5880
5881 ObjCPropertyImplDecl *ToImpl
5882 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5883 Property->getQueryKind());
5884 if (!ToImpl) {
5885
5886 Error Err = Error::success();
5887 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5888 auto ToLocation = importChecked(Err, D->getLocation());
5889 auto ToPropertyIvarDeclLoc =
5890 importChecked(Err, D->getPropertyIvarDeclLoc());
5891 if (Err)
5892 return std::move(Err);
5893
5894 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5895 ToBeginLoc,
5896 ToLocation, Property,
5897 D->getPropertyImplementation(), Ivar,
5898 ToPropertyIvarDeclLoc))
5899 return ToImpl;
5900
5901 ToImpl->setLexicalDeclContext(LexicalDC);
5902 LexicalDC->addDeclInternal(ToImpl);
5903 } else {
5904 // Check that we have the same kind of property implementation (@synthesize
5905 // vs. @dynamic).
5906 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
5907 Importer.ToDiag(ToImpl->getLocation(),
5908 diag::warn_odr_objc_property_impl_kind_inconsistent)
5909 << Property->getDeclName()
5910 << (ToImpl->getPropertyImplementation()
5912 Importer.FromDiag(D->getLocation(),
5913 diag::note_odr_objc_property_impl_kind)
5914 << D->getPropertyDecl()->getDeclName()
5915 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
5916
5917 return make_error<ASTImportError>(ASTImportError::NameConflict);
5918 }
5919
5920 // For @synthesize, check that we have the same
5921 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
5922 Ivar != ToImpl->getPropertyIvarDecl()) {
5923 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5924 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5925 << Property->getDeclName()
5926 << ToImpl->getPropertyIvarDecl()->getDeclName()
5927 << Ivar->getDeclName();
5928 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5929 diag::note_odr_objc_synthesize_ivar_here)
5930 << D->getPropertyIvarDecl()->getDeclName();
5931
5932 return make_error<ASTImportError>(ASTImportError::NameConflict);
5933 }
5934
5935 // Merge the existing implementation with the new implementation.
5936 Importer.MapImported(D, ToImpl);
5937 }
5938
5939 return ToImpl;
5940}
5941
5944 // For template arguments, we adopt the translation unit as our declaration
5945 // context. This context will be fixed when the actual template declaration
5946 // is created.
5947
5948 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5949 if (!BeginLocOrErr)
5950 return BeginLocOrErr.takeError();
5951
5952 ExpectedSLoc LocationOrErr = import(D->getLocation());
5953 if (!LocationOrErr)
5954 return LocationOrErr.takeError();
5955
5956 TemplateTypeParmDecl *ToD = nullptr;
5957 if (GetImportedOrCreateDecl(
5958 ToD, D, Importer.getToContext(),
5960 *BeginLocOrErr, *LocationOrErr,
5961 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5962 D->wasDeclaredWithTypename(), D->isParameterPack(),
5963 D->hasTypeConstraint()))
5964 return ToD;
5965
5966 // Import the type-constraint
5967 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5968
5969 Error Err = Error::success();
5970 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5971 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5972 if (Err)
5973 return std::move(Err);
5974
5975 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5976 }
5977
5978 if (D->hasDefaultArgument()) {
5979 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
5980 import(D->getDefaultArgument());
5981 if (!ToDefaultArgOrErr)
5982 return ToDefaultArgOrErr.takeError();
5983 ToD->setDefaultArgument(ToD->getASTContext(), *ToDefaultArgOrErr);
5984 }
5985
5986 return ToD;
5987}
5988
5991
5992 Error Err = Error::success();
5993 auto ToDeclName = importChecked(Err, D->getDeclName());
5994 auto ToLocation = importChecked(Err, D->getLocation());
5995 auto ToType = importChecked(Err, D->getType());
5996 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5997 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
5998 if (Err)
5999 return std::move(Err);
6000
6001 NonTypeTemplateParmDecl *ToD = nullptr;
6002 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6004 ToInnerLocStart, ToLocation, D->getDepth(),
6005 D->getPosition(),
6006 ToDeclName.getAsIdentifierInfo(), ToType,
6007 D->isParameterPack(), ToTypeSourceInfo))
6008 return ToD;
6009
6010 if (D->hasDefaultArgument()) {
6011 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
6012 import(D->getDefaultArgument());
6013 if (!ToDefaultArgOrErr)
6014 return ToDefaultArgOrErr.takeError();
6015 ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
6016 }
6017
6018 return ToD;
6019}
6020
6023 // Import the name of this declaration.
6024 auto NameOrErr = import(D->getDeclName());
6025 if (!NameOrErr)
6026 return NameOrErr.takeError();
6027
6028 // Import the location of this declaration.
6029 ExpectedSLoc LocationOrErr = import(D->getLocation());
6030 if (!LocationOrErr)
6031 return LocationOrErr.takeError();
6032
6033 // Import template parameters.
6034 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6035 if (!TemplateParamsOrErr)
6036 return TemplateParamsOrErr.takeError();
6037
6038 TemplateTemplateParmDecl *ToD = nullptr;
6039 if (GetImportedOrCreateDecl(
6040 ToD, D, Importer.getToContext(),
6041 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6042 D->getDepth(), D->getPosition(), D->isParameterPack(),
6043 (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
6044 *TemplateParamsOrErr))
6045 return ToD;
6046
6047 if (D->hasDefaultArgument()) {
6048 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
6049 import(D->getDefaultArgument());
6050 if (!ToDefaultArgOrErr)
6051 return ToDefaultArgOrErr.takeError();
6052 ToD->setDefaultArgument(Importer.getToContext(), *ToDefaultArgOrErr);
6053 }
6054
6055 return ToD;
6056}
6057
6058// Returns the definition for a (forward) declaration of a TemplateDecl, if
6059// it has any definition in the redecl chain.
6060template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6061 assert(D->getTemplatedDecl() && "Should be called on templates only");
6062 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6063 if (!ToTemplatedDef)
6064 return nullptr;
6065 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6066 return cast_or_null<T>(TemplateWithDef);
6067}
6068
6070
6071 // Import the major distinguishing characteristics of this class template.
6072 DeclContext *DC, *LexicalDC;
6073 DeclarationName Name;
6075 NamedDecl *ToD;
6076 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6077 return std::move(Err);
6078 if (ToD)
6079 return ToD;
6080
6081 // Should check if a declaration is friend in a dependent context.
6082 // Such templates are not linked together in a declaration chain.
6083 // The ASTImporter strategy is to map existing forward declarations to
6084 // imported ones only if strictly necessary, otherwise import these as new
6085 // forward declarations. In case of the "dependent friend" declarations, new
6086 // declarations are created, but not linked in a declaration chain.
6087 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6088 return TD->getFriendObjectKind() != Decl::FOK_None &&
6090 };
6091 bool DependentFriend = IsDependentFriend(D);
6092
6093 ClassTemplateDecl *FoundByLookup = nullptr;
6094
6095 // We may already have a template of the same name; try to find and match it.
6096 if (!DC->isFunctionOrMethod()) {
6097 SmallVector<NamedDecl *, 4> ConflictingDecls;
6098 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6099 for (auto *FoundDecl : FoundDecls) {
6102 continue;
6103
6104 Decl *Found = FoundDecl;
6105 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(Found);
6106 if (FoundTemplate) {
6107 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6108 continue;
6109
6110 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6111 bool IgnoreTemplateParmDepth =
6112 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6114 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6115 IgnoreTemplateParmDepth)) {
6116 if (DependentFriend || IsDependentFriend(FoundTemplate))
6117 continue;
6118
6119 ClassTemplateDecl *TemplateWithDef =
6120 getTemplateDefinition(FoundTemplate);
6121 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6122 return Importer.MapImported(D, TemplateWithDef);
6123 if (!FoundByLookup)
6124 FoundByLookup = FoundTemplate;
6125 // Search in all matches because there may be multiple decl chains,
6126 // see ASTTests test ImportExistingFriendClassTemplateDef.
6127 continue;
6128 }
6129 ConflictingDecls.push_back(FoundDecl);
6130 }
6131 }
6132
6133 if (!ConflictingDecls.empty()) {
6134 ExpectedName NameOrErr = Importer.HandleNameConflict(
6135 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6136 ConflictingDecls.size());
6137 if (NameOrErr)
6138 Name = NameOrErr.get();
6139 else
6140 return NameOrErr.takeError();
6141 }
6142 }
6143
6144 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6145
6146 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6147 if (!TemplateParamsOrErr)
6148 return TemplateParamsOrErr.takeError();
6149
6150 // Create the declaration that is being templated.
6151 CXXRecordDecl *ToTemplated;
6152 if (Error Err = importInto(ToTemplated, FromTemplated))
6153 return std::move(Err);
6154
6155 // Create the class template declaration itself.
6157 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6158 *TemplateParamsOrErr, ToTemplated))
6159 return D2;
6160
6161 ToTemplated->setDescribedClassTemplate(D2);
6162
6163 D2->setAccess(D->getAccess());
6164 D2->setLexicalDeclContext(LexicalDC);
6165
6166 addDeclToContexts(D, D2);
6167 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6168
6169 if (FoundByLookup) {
6170 auto *Recent =
6171 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6172
6173 // It is possible that during the import of the class template definition
6174 // we start the import of a fwd friend decl of the very same class template
6175 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6176 // had been created earlier and by that time the lookup could not find
6177 // anything existing, so it has no previous decl. Later, (still during the
6178 // import of the fwd friend decl) we start to import the definition again
6179 // and this time the lookup finds the previous fwd friend class template.
6180 // In this case we must set up the previous decl for the templated decl.
6181 if (!ToTemplated->getPreviousDecl()) {
6182 assert(FoundByLookup->getTemplatedDecl() &&
6183 "Found decl must have its templated decl set");
6184 CXXRecordDecl *PrevTemplated =
6185 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6186 if (ToTemplated != PrevTemplated)
6187 ToTemplated->setPreviousDecl(PrevTemplated);
6188 }
6189
6190 D2->setPreviousDecl(Recent);
6191
6192 updateTemplateParametersInheritedFrom(*(Recent->getTemplateParameters()),
6193 **TemplateParamsOrErr);
6194 }
6195
6196 return D2;
6197}
6198
6201 ClassTemplateDecl *ClassTemplate;
6202 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6203 return std::move(Err);
6204
6205 // Import the context of this declaration.
6206 DeclContext *DC, *LexicalDC;
6207 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6208 return std::move(Err);
6209
6210 // Import template arguments.
6212 if (Error Err =
6213 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6214 return std::move(Err);
6215 // Try to find an existing specialization with these template arguments and
6216 // template parameter list.
6217 void *InsertPos = nullptr;
6218 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6220 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6221
6222 // Import template parameters.
6223 TemplateParameterList *ToTPList = nullptr;
6224
6225 if (PartialSpec) {
6226 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6227 if (!ToTPListOrErr)
6228 return ToTPListOrErr.takeError();
6229 ToTPList = *ToTPListOrErr;
6230 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6231 *ToTPListOrErr,
6232 InsertPos);
6233 } else
6234 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6235
6236 if (PrevDecl) {
6237 if (IsStructuralMatch(D, PrevDecl)) {
6238 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6239 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6240 Importer.MapImported(D, PrevDefinition);
6241 // Import those default field initializers which have been
6242 // instantiated in the "From" context, but not in the "To" context.
6243 for (auto *FromField : D->fields()) {
6244 auto ToOrErr = import(FromField);
6245 if (!ToOrErr)
6246 return ToOrErr.takeError();
6247 }
6248
6249 // Import those methods which have been instantiated in the
6250 // "From" context, but not in the "To" context.
6251 for (CXXMethodDecl *FromM : D->methods()) {
6252 auto ToOrErr = import(FromM);
6253 if (!ToOrErr)
6254 return ToOrErr.takeError();
6255 }
6256
6257 // TODO Import instantiated default arguments.
6258 // TODO Import instantiated exception specifications.
6259 //
6260 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6261 // what else could be fused during an AST merge.
6262 return PrevDefinition;
6263 }
6264 } else { // ODR violation.
6265 // FIXME HandleNameConflict
6266 return make_error<ASTImportError>(ASTImportError::NameConflict);
6267 }
6268 }
6269
6270 // Import the location of this declaration.
6271 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6272 if (!BeginLocOrErr)
6273 return BeginLocOrErr.takeError();
6274 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6275 if (!IdLocOrErr)
6276 return IdLocOrErr.takeError();
6277
6278 // Import TemplateArgumentListInfo.
6279 TemplateArgumentListInfo ToTAInfo;
6280 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6281 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6282 return std::move(Err);
6283 }
6284
6285 // Create the specialization.
6286 ClassTemplateSpecializationDecl *D2 = nullptr;
6287 if (PartialSpec) {
6288 QualType CanonInjType;
6289 if (Error Err = importInto(
6290 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6291 return std::move(Err);
6292 CanonInjType = CanonInjType.getCanonicalType();
6293
6294 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6295 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6296 *IdLocOrErr, ToTPList, ClassTemplate,
6297 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()),
6298 CanonInjType,
6299 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6300 return D2;
6301
6302 // Update InsertPos, because preceding import calls may have invalidated
6303 // it by adding new specializations.
6304 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6305 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6306 InsertPos))
6307 // Add this partial specialization to the class template.
6308 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6310 import(PartialSpec->getInstantiatedFromMember()))
6311 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6312 else
6313 return ToInstOrErr.takeError();
6314
6315 updateLookupTableForTemplateParameters(*ToTPList);
6316 } else { // Not a partial specialization.
6317 if (GetImportedOrCreateDecl(
6318 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6319 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6320 PrevDecl))
6321 return D2;
6322
6323 // Update InsertPos, because preceding import calls may have invalidated
6324 // it by adding new specializations.
6325 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6326 // Add this specialization to the class template.
6327 ClassTemplate->AddSpecialization(D2, InsertPos);
6328 }
6329
6330 D2->setSpecializationKind(D->getSpecializationKind());
6331
6332 // Set the context of this specialization/instantiation.
6333 D2->setLexicalDeclContext(LexicalDC);
6334
6335 // Add to the DC only if it was an explicit specialization/instantiation.
6337 LexicalDC->addDeclInternal(D2);
6338 }
6339
6340 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6341 D2->setBraceRange(*BraceRangeOrErr);
6342 else
6343 return BraceRangeOrErr.takeError();
6344
6345 if (Error Err = ImportTemplateParameterLists(D, D2))
6346 return std::move(Err);
6347
6348 // Import the qualifier, if any.
6349 if (auto LocOrErr = import(D->getQualifierLoc()))
6350 D2->setQualifierInfo(*LocOrErr);
6351 else
6352 return LocOrErr.takeError();
6353
6354 if (D->getTemplateArgsAsWritten())
6355 D2->setTemplateArgsAsWritten(ToTAInfo);
6356
6357 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6358 D2->setTemplateKeywordLoc(*LocOrErr);
6359 else
6360 return LocOrErr.takeError();
6361
6362 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6363 D2->setExternKeywordLoc(*LocOrErr);
6364 else
6365 return LocOrErr.takeError();
6366
6367 if (D->getPointOfInstantiation().isValid()) {
6368 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6369 D2->setPointOfInstantiation(*POIOrErr);
6370 else
6371 return POIOrErr.takeError();
6372 }
6373
6374 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
6375
6376 if (auto P = D->getInstantiatedFrom()) {
6377 if (auto *CTD = P.dyn_cast<ClassTemplateDecl *>()) {
6378 if (auto CTDorErr = import(CTD))
6379 D2->setInstantiationOf(*CTDorErr);
6380 } else {
6381 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6382 auto CTPSDOrErr = import(CTPSD);
6383 if (!CTPSDOrErr)
6384 return CTPSDOrErr.takeError();
6385 const TemplateArgumentList &DArgs = D->getTemplateInstantiationArgs();
6386 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6387 for (unsigned I = 0; I < DArgs.size(); ++I) {
6388 const TemplateArgument &DArg = DArgs[I];
6389 if (auto ArgOrErr = import(DArg))
6390 D2ArgsVec[I] = *ArgOrErr;
6391 else
6392 return ArgOrErr.takeError();
6393 }
6395 *CTPSDOrErr,
6396 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6397 }
6398 }
6399
6400 if (D->isCompleteDefinition())
6401 if (Error Err = ImportDefinition(D, D2))
6402 return std::move(Err);
6403
6404 return D2;
6405}
6406
6408 // Import the major distinguishing characteristics of this variable template.
6409 DeclContext *DC, *LexicalDC;
6410 DeclarationName Name;
6412 NamedDecl *ToD;
6413 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6414 return std::move(Err);
6415 if (ToD)
6416 return ToD;
6417
6418 // We may already have a template of the same name; try to find and match it.
6419 assert(!DC->isFunctionOrMethod() &&
6420 "Variable templates cannot be declared at function scope");
6421
6422 SmallVector<NamedDecl *, 4> ConflictingDecls;
6423 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6424 VarTemplateDecl *FoundByLookup = nullptr;
6425 for (auto *FoundDecl : FoundDecls) {
6427 continue;
6428
6429 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6430 // Use the templated decl, some linkage flags are set only there.
6431 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6432 D->getTemplatedDecl()))
6433 continue;
6434 if (IsStructuralMatch(D, FoundTemplate)) {
6435 // FIXME Check for ODR error if the two definitions have
6436 // different initializers?
6437 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6438 if (D->getDeclContext()->isRecord()) {
6439 assert(FoundTemplate->getDeclContext()->isRecord() &&
6440 "Member variable template imported as non-member, "
6441 "inconsistent imported AST?");
6442 if (FoundDef)
6443 return Importer.MapImported(D, FoundDef);
6444 if (!D->isThisDeclarationADefinition())
6445 return Importer.MapImported(D, FoundTemplate);
6446 } else {
6447 if (FoundDef && D->isThisDeclarationADefinition())
6448 return Importer.MapImported(D, FoundDef);
6449 }
6450 FoundByLookup = FoundTemplate;
6451 break;
6452 }
6453 ConflictingDecls.push_back(FoundDecl);
6454 }
6455 }
6456
6457 if (!ConflictingDecls.empty()) {
6458 ExpectedName NameOrErr = Importer.HandleNameConflict(
6459 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6460 ConflictingDecls.size());
6461 if (NameOrErr)
6462 Name = NameOrErr.get();
6463 else
6464 return NameOrErr.takeError();
6465 }
6466
6467 VarDecl *DTemplated = D->getTemplatedDecl();
6468
6469 // Import the type.
6470 // FIXME: Value not used?
6471 ExpectedType TypeOrErr = import(DTemplated->getType());
6472 if (!TypeOrErr)
6473 return TypeOrErr.takeError();
6474
6475 // Create the declaration that is being templated.
6476 VarDecl *ToTemplated;
6477 if (Error Err = importInto(ToTemplated, DTemplated))
6478 return std::move(Err);
6479
6480 // Create the variable template declaration itself.
6481 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6482 if (!TemplateParamsOrErr)
6483 return TemplateParamsOrErr.takeError();
6484
6485 VarTemplateDecl *ToVarTD;
6486 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6487 Name, *TemplateParamsOrErr, ToTemplated))
6488 return ToVarTD;
6489
6490 ToTemplated->setDescribedVarTemplate(ToVarTD);
6491
6492 ToVarTD->setAccess(D->getAccess());
6493 ToVarTD->setLexicalDeclContext(LexicalDC);
6494 LexicalDC->addDeclInternal(ToVarTD);
6495 if (DC != Importer.getToContext().getTranslationUnitDecl())
6496 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6497
6498 if (FoundByLookup) {
6499 auto *Recent =
6500 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6501 if (!ToTemplated->getPreviousDecl()) {
6502 auto *PrevTemplated =
6503 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6504 if (ToTemplated != PrevTemplated)
6505 ToTemplated->setPreviousDecl(PrevTemplated);
6506 }
6507 ToVarTD->setPreviousDecl(Recent);
6508
6509 updateTemplateParametersInheritedFrom(*(Recent->getTemplateParameters()),
6510 **TemplateParamsOrErr);
6511 }
6512
6513 return ToVarTD;
6514}
6515
6518 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6519 // in an analog way (but specialized for this case).
6520
6522 auto RedeclIt = Redecls.begin();
6523 // Import the first part of the decl chain. I.e. import all previous
6524 // declarations starting from the canonical decl.
6525 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6526 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6527 if (!RedeclOrErr)
6528 return RedeclOrErr.takeError();
6529 }
6530 assert(*RedeclIt == D);
6531
6532 VarTemplateDecl *VarTemplate = nullptr;
6533 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6534 return std::move(Err);
6535
6536 // Import the context of this declaration.
6537 DeclContext *DC, *LexicalDC;
6538 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6539 return std::move(Err);
6540
6541 // Import the location of this declaration.
6542 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6543 if (!BeginLocOrErr)
6544 return BeginLocOrErr.takeError();
6545
6546 auto IdLocOrErr = import(D->getLocation());
6547 if (!IdLocOrErr)
6548 return IdLocOrErr.takeError();
6549
6550 // Import template arguments.
6552 if (Error Err =
6553 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6554 return std::move(Err);
6555
6556 // Try to find an existing specialization with these template arguments.
6557 void *InsertPos = nullptr;
6558 VarTemplateSpecializationDecl *FoundSpecialization =
6559 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6560 if (FoundSpecialization) {
6561 if (IsStructuralMatch(D, FoundSpecialization)) {
6562 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6563 if (D->getDeclContext()->isRecord()) {
6564 // In a record, it is allowed only to have one optional declaration and
6565 // one definition of the (static or constexpr) variable template.
6566 assert(
6567 FoundSpecialization->getDeclContext()->isRecord() &&
6568 "Member variable template specialization imported as non-member, "
6569 "inconsistent imported AST?");
6570 if (FoundDef)
6571 return Importer.MapImported(D, FoundDef);
6572 if (!D->isThisDeclarationADefinition())
6573 return Importer.MapImported(D, FoundSpecialization);
6574 } else {
6575 // If definition is imported and there is already one, map to it.
6576 // Otherwise create a new variable and link it to the existing.
6577 if (FoundDef && D->isThisDeclarationADefinition())
6578 return Importer.MapImported(D, FoundDef);
6579 }
6580 } else {
6581 return make_error<ASTImportError>(ASTImportError::NameConflict);
6582 }
6583 }
6584
6585 VarTemplateSpecializationDecl *D2 = nullptr;
6586
6587 TemplateArgumentListInfo ToTAInfo;
6588 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6589 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6590 return std::move(Err);
6591 }
6592
6593 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6594 // Create a new specialization.
6595 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6596 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6597 if (!ToTPListOrErr)
6598 return ToTPListOrErr.takeError();
6599
6600 PartVarSpecDecl *ToPartial;
6601 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6602 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6603 VarTemplate, QualType(), nullptr,
6604 D->getStorageClass(), TemplateArgs))
6605 return ToPartial;
6606
6607 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6608 import(FromPartial->getInstantiatedFromMember()))
6609 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6610 else
6611 return ToInstOrErr.takeError();
6612
6613 if (FromPartial->isMemberSpecialization())
6614 ToPartial->setMemberSpecialization();
6615
6616 D2 = ToPartial;
6617
6618 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6619 // to adopt template parameters.
6620 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6621 } else { // Full specialization
6622 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6623 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6624 QualType(), nullptr, D->getStorageClass(),
6625 TemplateArgs))
6626 return D2;
6627 }
6628
6629 // Update InsertPos, because preceding import calls may have invalidated
6630 // it by adding new specializations.
6631 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6632 VarTemplate->AddSpecialization(D2, InsertPos);
6633
6634 QualType T;
6635 if (Error Err = importInto(T, D->getType()))
6636 return std::move(Err);
6637 D2->setType(T);
6638
6639 auto TInfoOrErr = import(D->getTypeSourceInfo());
6640 if (!TInfoOrErr)
6641 return TInfoOrErr.takeError();
6642 D2->setTypeSourceInfo(*TInfoOrErr);
6643
6644 if (D->getPointOfInstantiation().isValid()) {
6645 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6646 D2->setPointOfInstantiation(*POIOrErr);
6647 else
6648 return POIOrErr.takeError();
6649 }
6650
6651 D2->setSpecializationKind(D->getSpecializationKind());
6652
6653 if (D->getTemplateArgsAsWritten())
6654 D2->setTemplateArgsAsWritten(ToTAInfo);
6655
6656 if (auto LocOrErr = import(D->getQualifierLoc()))
6657 D2->setQualifierInfo(*LocOrErr);
6658 else
6659 return LocOrErr.takeError();
6660
6661 if (D->isConstexpr())
6662 D2->setConstexpr(true);
6663
6664 D2->setAccess(D->getAccess());
6665
6666 if (Error Err = ImportInitializer(D, D2))
6667 return std::move(Err);
6668
6669 if (FoundSpecialization)
6670 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6671
6672 addDeclToContexts(D, D2);
6673
6674 // Import the rest of the chain. I.e. import all subsequent declarations.
6675 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6676 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6677 if (!RedeclOrErr)
6678 return RedeclOrErr.takeError();
6679 }
6680
6681 return D2;
6682}
6683
6686 DeclContext *DC, *LexicalDC;
6687 DeclarationName Name;
6689 NamedDecl *ToD;
6690
6691 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6692 return std::move(Err);
6693
6694 if (ToD)
6695 return ToD;
6696
6697 const FunctionTemplateDecl *FoundByLookup = nullptr;
6698
6699 // Try to find a function in our own ("to") context with the same name, same
6700 // type, and in the same context as the function we're importing.
6701 // FIXME Split this into a separate function.
6702 if (!LexicalDC->isFunctionOrMethod()) {
6704 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6705 for (auto *FoundDecl : FoundDecls) {
6706 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6707 continue;
6708
6709 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6710 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6711 continue;
6712 if (IsStructuralMatch(D, FoundTemplate)) {
6713 FunctionTemplateDecl *TemplateWithDef =
6714 getTemplateDefinition(FoundTemplate);
6715 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6716 return Importer.MapImported(D, TemplateWithDef);
6717
6718 FoundByLookup = FoundTemplate;
6719 break;
6720 // TODO: handle conflicting names
6721 }
6722 }
6723 }
6724 }
6725
6726 auto ParamsOrErr = import(D->getTemplateParameters());
6727 if (!ParamsOrErr)
6728 return ParamsOrErr.takeError();
6729 TemplateParameterList *Params = *ParamsOrErr;
6730
6731 FunctionDecl *TemplatedFD;
6732 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6733 return std::move(Err);
6734
6735 // At creation of the template the template parameters are "adopted"
6736 // (DeclContext is changed). After this possible change the lookup table
6737 // must be updated.
6738 // At deduction guides the DeclContext of the template parameters may be
6739 // different from what we would expect, it may be the class template, or a
6740 // probably different CXXDeductionGuideDecl. This may come from the fact that
6741 // the template parameter objects may be shared between deduction guides or
6742 // the class template, and at creation of multiple FunctionTemplateDecl
6743 // objects (for deduction guides) the same parameters are re-used. The
6744 // "adoption" happens multiple times with different parent, even recursively
6745 // for TemplateTemplateParmDecl. The same happens at import when the
6746 // FunctionTemplateDecl objects are created, but in different order.
6747 // In this way the DeclContext of these template parameters is not necessarily
6748 // the same as in the "from" context.
6750 OldParamDC.reserve(Params->size());
6751 llvm::transform(*Params, std::back_inserter(OldParamDC),
6752 [](NamedDecl *ND) { return ND->getDeclContext(); });
6753
6754 FunctionTemplateDecl *ToFunc;
6755 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6756 Params, TemplatedFD))
6757 return ToFunc;
6758
6759 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6760
6761 ToFunc->setAccess(D->getAccess());
6762 ToFunc->setLexicalDeclContext(LexicalDC);
6763 addDeclToContexts(D, ToFunc);
6764
6765 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6766 if (LT && !OldParamDC.empty()) {
6767 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6768 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6769 }
6770
6771 if (FoundByLookup) {
6772 auto *Recent =
6773 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6774 if (!TemplatedFD->getPreviousDecl()) {
6775 assert(FoundByLookup->getTemplatedDecl() &&
6776 "Found decl must have its templated decl set");
6777 auto *PrevTemplated =
6778 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6779 if (TemplatedFD != PrevTemplated)
6780 TemplatedFD->setPreviousDecl(PrevTemplated);
6781 }
6782 ToFunc->setPreviousDecl(Recent);
6783
6784 updateTemplateParametersInheritedFrom(*(Recent->getTemplateParameters()),
6785 *Params);
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()) {
9073 SharedState->getLookupTable()->lookup(ReDC, Name);
9074 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9075 } else {
9076 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9077 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9078 // We must search by the slow case of localUncachedLookup because that is
9079 // working even if there is no LookupPtr for the DC. We could use
9080 // DC::buildLookup() to create the LookupPtr, but that would load external
9081 // decls again, we must avoid that case.
9082 // Also, even if we had the LookupPtr, we must find Decls which are not
9083 // in the LookupPtr, so we need the slow case.
9084 // These cases are handled in ASTImporterLookupTable, but we cannot use
9085 // that with LLDB since that traverses through the AST which initiates the
9086 // load of external decls again via DC::decls(). And again, we must avoid
9087 // loading external decls during the import.
9088 if (Result.empty())
9089 ReDC->localUncachedLookup(Name, Result);
9090 return Result;
9091 }
9092}
9093
9094void ASTImporter::AddToLookupTable(Decl *ToD) {
9095 SharedState->addDeclToLookup(ToD);
9096}
9097
9099 // Import the decl using ASTNodeImporter.
9100 ASTNodeImporter Importer(*this);
9101 return Importer.Visit(FromD);
9102}
9103
9105 MapImported(FromD, ToD);
9106}
9107
9110 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9111 if (Expected<Expr *> R = Import(CLE))
9112 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9113 }
9114
9115 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9116 // ASTNodeImporter.
9117 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9118}
9119
9121 if (!FromT)
9122 return FromT;
9123
9124 // Check whether we've already imported this type.
9125 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9126 ImportedTypes.find(FromT);
9127 if (Pos != ImportedTypes.end())
9128 return Pos->second;
9129
9130 // Import the type.
9131 ASTNodeImporter Importer(*this);
9132 ExpectedType ToTOrErr = Importer.Visit(FromT);
9133 if (!ToTOrErr)
9134 return ToTOrErr.takeError();
9135
9136 // Record the imported type.
9137 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9138
9139 return ToTOrErr->getTypePtr();
9140}
9141
9143 if (FromT.isNull())
9144 return QualType{};
9145
9146 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9147 if (!ToTyOrErr)
9148 return ToTyOrErr.takeError();
9149
9150 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9151}
9152
9154 if (!FromTSI)
9155 return FromTSI;
9156
9157 // FIXME: For now we just create a "trivial" type source info based
9158 // on the type and a single location. Implement a real version of this.
9159 ExpectedType TOrErr = Import(FromTSI->getType());
9160 if (!TOrErr)
9161 return TOrErr.takeError();
9162 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9163 if (!BeginLocOrErr)
9164 return BeginLocOrErr.takeError();
9165
9166 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9167}
9168
9169namespace {
9170// To use this object, it should be created before the new attribute is created,
9171// and destructed after it is created. The construction already performs the
9172// import of the data.
9173template <typename T> struct AttrArgImporter {
9174 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9175 AttrArgImporter(AttrArgImporter<T> &&) = default;
9176 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9177 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9178
9179 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9180 : To(I.importChecked(Err, From)) {}
9181
9182 const T &value() { return To; }
9183
9184private:
9185 T To;
9186};
9187
9188// To use this object, it should be created before the new attribute is created,
9189// and destructed after it is created. The construction already performs the
9190// import of the data. The array data is accessible in a pointer form, this form
9191// is used by the attribute classes. This object should be created once for the
9192// array data to be imported (the array size is not imported, just copied).
9193template <typename T> struct AttrArgArrayImporter {
9194 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9195 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9196 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9197 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9198
9199 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9200 const llvm::iterator_range<T *> &From,
9201 unsigned ArraySize) {
9202 if (Err)
9203 return;
9204 To.reserve(ArraySize);
9205 Err = I.ImportContainerChecked(From, To);
9206 }
9207
9208 T *value() { return To.data(); }
9209
9210private:
9212};
9213
9214class AttrImporter {
9215 Error Err{Error::success()};
9216 Attr *ToAttr = nullptr;
9217 ASTImporter &Importer;
9218 ASTNodeImporter NImporter;
9219
9220public:
9221 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9222
9223 // Useful for accessing the imported attribute.
9224 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9225 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9226
9227 // Create an "importer" for an attribute parameter.
9228 // Result of the 'value()' of that object is to be passed to the function
9229 // 'importAttr', in the order that is expected by the attribute class.
9230 template <class T> AttrArgImporter<T> importArg(const T &From) {
9231 return AttrArgImporter<T>(NImporter, Err, From);
9232 }
9233
9234 // Create an "importer" for an attribute parameter that has array type.
9235 // Result of the 'value()' of that object is to be passed to the function
9236 // 'importAttr', then the size of the array as next argument.
9237 template <typename T>
9238 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9239 unsigned ArraySize) {
9240 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9241 }
9242
9243 // Create an attribute object with the specified arguments.
9244 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9245 // should be values that are passed to the 'Create' function of the attribute.
9246 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9247 // used here.) As much data is copied or imported from the old attribute
9248 // as possible. The passed arguments should be already imported.
9249 // If an import error happens, the internal error is set to it, and any
9250 // further import attempt is ignored.
9251 template <typename T, typename... Arg>
9252 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9253 static_assert(std::is_base_of<Attr, T>::value,
9254 "T should be subclass of Attr.");
9255 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9256
9257 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9258 const IdentifierInfo *ToScopeName =
9259 Importer.Import(FromAttr->getScopeName());
9260 SourceRange ToAttrRange =
9261 NImporter.importChecked(Err, FromAttr->getRange());
9262 SourceLocation ToScopeLoc =
9263 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9264
9265 if (Err)
9266 return;
9267
9268 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9269 FromAttr->getParsedKind(), FromAttr->getForm());
9270 // The "SemanticSpelling" is not needed to be passed to the constructor.
9271 // That value is recalculated from the SpellingListIndex if needed.
9272 ToAttr = T::Create(Importer.getToContext(),
9273 std::forward<Arg>(ImportedArg)..., ToI);
9274
9275 ToAttr->setImplicit(FromAttr->isImplicit());
9276 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9277 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9278 ToInheritableAttr->setInherited(FromAttr->isInherited());
9279 }
9280
9281 // Create a clone of the 'FromAttr' and import its source range only.
9282 // This causes objects with invalid references to be created if the 'FromAttr'
9283 // contains other data that should be imported.
9284 void cloneAttr(const Attr *FromAttr) {
9285 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9286
9287 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9288 if (Err)
9289 return;
9290
9291 ToAttr = FromAttr->clone(Importer.getToContext());
9292 ToAttr->setRange(ToRange);
9293 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9294 }
9295
9296 // Get the result of the previous import attempt (can be used only once).
9297 llvm::Expected<Attr *> getResult() && {
9298 if (Err)
9299 return std::move(Err);
9300 assert(ToAttr && "Attribute should be created.");
9301 return ToAttr;
9302 }
9303};
9304} // namespace
9305
9307 AttrImporter AI(*this);
9308
9309 // FIXME: Is there some kind of AttrVisitor to use here?
9310 switch (FromAttr->getKind()) {
9311 case attr::Aligned: {
9312 auto *From = cast<AlignedAttr>(FromAttr);
9313 if (From->isAlignmentExpr())
9314 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9315 else
9316 AI.importAttr(From, false,
9317 AI.importArg(From->getAlignmentType()).value());
9318 break;
9319 }
9320
9321 case attr::AlignValue: {
9322 auto *From = cast<AlignValueAttr>(FromAttr);
9323 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9324 break;
9325 }
9326
9327 case attr::Format: {
9328 const auto *From = cast<FormatAttr>(FromAttr);
9329 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9330 From->getFirstArg());
9331 break;
9332 }
9333
9334 case attr::EnableIf: {
9335 const auto *From = cast<EnableIfAttr>(FromAttr);
9336 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9337 From->getMessage());
9338 break;
9339 }
9340
9341 case attr::AssertCapability: {
9342 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9343 AI.importAttr(From,
9344 AI.importArrayArg(From->args(), From->args_size()).value(),
9345 From->args_size());
9346 break;
9347 }
9348 case attr::AcquireCapability: {
9349 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9350 AI.importAttr(From,
9351 AI.importArrayArg(From->args(), From->args_size()).value(),
9352 From->args_size());
9353 break;
9354 }
9355 case attr::TryAcquireCapability: {
9356 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9357 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9358 AI.importArrayArg(From->args(), From->args_size()).value(),
9359 From->args_size());
9360 break;
9361 }
9362 case attr::ReleaseCapability: {
9363 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9364 AI.importAttr(From,
9365 AI.importArrayArg(From->args(), From->args_size()).value(),
9366 From->args_size());
9367 break;
9368 }
9369 case attr::RequiresCapability: {
9370 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9371 AI.importAttr(From,
9372 AI.importArrayArg(From->args(), From->args_size()).value(),
9373 From->args_size());
9374 break;
9375 }
9376 case attr::GuardedBy: {
9377 const auto *From = cast<GuardedByAttr>(FromAttr);
9378 AI.importAttr(From, AI.importArg(From->getArg()).value());
9379 break;
9380 }
9381 case attr::PtGuardedBy: {
9382 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9383 AI.importAttr(From, AI.importArg(From->getArg()).value());
9384 break;
9385 }
9386 case attr::AcquiredAfter: {
9387 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9388 AI.importAttr(From,
9389 AI.importArrayArg(From->args(), From->args_size()).value(),
9390 From->args_size());
9391 break;
9392 }
9393 case attr::AcquiredBefore: {
9394 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9395 AI.importAttr(From,
9396 AI.importArrayArg(From->args(), From->args_size()).value(),
9397 From->args_size());
9398 break;
9399 }
9400 case attr::AssertExclusiveLock: {
9401 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9402 AI.importAttr(From,
9403 AI.importArrayArg(From->args(), From->args_size()).value(),
9404 From->args_size());
9405 break;
9406 }
9407 case attr::AssertSharedLock: {
9408 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9409 AI.importAttr(From,
9410 AI.importArrayArg(From->args(), From->args_size()).value(),
9411 From->args_size());
9412 break;
9413 }
9414 case attr::ExclusiveTrylockFunction: {
9415 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9416 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9417 AI.importArrayArg(From->args(), From->args_size()).value(),
9418 From->args_size());
9419 break;
9420 }
9421 case attr::SharedTrylockFunction: {
9422 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9423 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9424 AI.importArrayArg(From->args(), From->args_size()).value(),
9425 From->args_size());
9426 break;
9427 }
9428 case attr::LockReturned: {
9429 const auto *From = cast<LockReturnedAttr>(FromAttr);
9430 AI.importAttr(From, AI.importArg(From->getArg()).value());
9431 break;
9432 }
9433 case attr::LocksExcluded: {
9434 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9435 AI.importAttr(From,
9436 AI.importArrayArg(From->args(), From->args_size()).value(),
9437 From->args_size());
9438 break;
9439 }
9440 default: {
9441 // The default branch works for attributes that have no arguments to import.
9442 // FIXME: Handle every attribute type that has arguments of type to import
9443 // (most often Expr* or Decl* or type) in the switch above.
9444 AI.cloneAttr(FromAttr);
9445 break;
9446 }
9447 }
9448
9449 return std::move(AI).getResult();
9450}
9451
9453 return ImportedDecls.lookup(FromD);
9454}
9455
9457 auto FromDPos = ImportedFromDecls.find(ToD);
9458 if (FromDPos == ImportedFromDecls.end())
9459 return nullptr;
9460 return FromDPos->second->getTranslationUnitDecl();
9461}
9462
9464 if (!FromD)
9465 return nullptr;
9466
9467 // Push FromD to the stack, and remove that when we return.
9468 ImportPath.push(FromD);
9469 auto ImportPathBuilder =
9470 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9471
9472 // Check whether there was a previous failed import.
9473 // If yes return the existing error.
9474 if (auto Error = getImportDeclErrorIfAny(FromD))
9475 return make_error<ASTImportError>(*Error);
9476
9477 // Check whether we've already imported this declaration.
9478 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9479 if (ToD) {
9480 // Already imported (possibly from another TU) and with an error.
9481 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9482 setImportDeclError(FromD, *Error);
9483 return make_error<ASTImportError>(*Error);
9484 }
9485
9486 // If FromD has some updated flags after last import, apply it.
9487 updateFlags(FromD, ToD);
9488 // If we encounter a cycle during an import then we save the relevant part
9489 // of the import path associated to the Decl.
9490 if (ImportPath.hasCycleAtBack())
9491 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9492 return ToD;
9493 }
9494
9495 // Import the declaration.
9496 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9497 if (!ToDOrErr) {
9498 // Failed to import.
9499
9500 auto Pos = ImportedDecls.find(FromD);
9501 if (Pos != ImportedDecls.end()) {
9502 // Import failed after the object was created.
9503 // Remove all references to it.
9504 auto *ToD = Pos->second;
9505 ImportedDecls.erase(Pos);
9506
9507 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9508 // (e.g. with namespaces) that several decls from the 'from' context are
9509 // mapped to the same decl in the 'to' context. If we removed entries
9510 // from the LookupTable here then we may end up removing them multiple
9511 // times.
9512
9513 // The Lookuptable contains decls only which are in the 'to' context.
9514 // Remove from the Lookuptable only if it is *imported* into the 'to'
9515 // context (and do not remove it if it was added during the initial
9516 // traverse of the 'to' context).
9517 auto PosF = ImportedFromDecls.find(ToD);
9518 if (PosF != ImportedFromDecls.end()) {
9519 // In the case of TypedefNameDecl we create the Decl first and only
9520 // then we import and set its DeclContext. So, the DC might not be set
9521 // when we reach here.
9522 if (ToD->getDeclContext())
9523 SharedState->removeDeclFromLookup(ToD);
9524 ImportedFromDecls.erase(PosF);
9525 }
9526
9527 // FIXME: AST may contain remaining references to the failed object.
9528 // However, the ImportDeclErrors in the shared state contains all the
9529 // failed objects together with their error.
9530 }
9531
9532 // Error encountered for the first time.
9533 // After takeError the error is not usable any more in ToDOrErr.
9534 // Get a copy of the error object (any more simple solution for this?).
9535 ASTImportError ErrOut;
9536 handleAllErrors(ToDOrErr.takeError(),
9537 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9538 setImportDeclError(FromD, ErrOut);
9539 // Set the error for the mapped to Decl, which is in the "to" context.
9540 if (Pos != ImportedDecls.end())
9541 SharedState->setImportDeclError(Pos->second, ErrOut);
9542
9543 // Set the error for all nodes which have been created before we
9544 // recognized the error.
9545 for (const auto &Path : SavedImportPaths[FromD]) {
9546 // The import path contains import-dependency nodes first.
9547 // Save the node that was imported as dependency of the current node.
9548 Decl *PrevFromDi = FromD;
9549 for (Decl *FromDi : Path) {
9550 // Begin and end of the path equals 'FromD', skip it.
9551 if (FromDi == FromD)
9552 continue;
9553 // We should not set import error on a node and all following nodes in
9554 // the path if child import errors are ignored.
9555 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9556 PrevFromDi))
9557 break;
9558 PrevFromDi = FromDi;
9559 setImportDeclError(FromDi, ErrOut);
9560 //FIXME Should we remove these Decls from ImportedDecls?
9561 // Set the error for the mapped to Decl, which is in the "to" context.
9562 auto Ii = ImportedDecls.find(FromDi);
9563 if (Ii != ImportedDecls.end())
9564 SharedState->setImportDeclError(Ii->second, ErrOut);
9565 // FIXME Should we remove these Decls from the LookupTable,
9566 // and from ImportedFromDecls?
9567 }
9568 }
9569 SavedImportPaths.erase(FromD);
9570
9571 // Do not return ToDOrErr, error was taken out of it.
9572 return make_error<ASTImportError>(ErrOut);
9573 }
9574
9575 ToD = *ToDOrErr;
9576
9577 // FIXME: Handle the "already imported with error" case. We can get here
9578 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9579 // previously failed create was requested).
9580 // Later GetImportedOrCreateDecl can be updated to return the error.
9581 if (!ToD) {
9582 auto Err = getImportDeclErrorIfAny(FromD);
9583 assert(Err);
9584 return make_error<ASTImportError>(*Err);
9585 }
9586
9587 // We could import from the current TU without error. But previously we
9588 // already had imported a Decl as `ToD` from another TU (with another
9589 // ASTImporter object) and with an error.
9590 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9591 setImportDeclError(FromD, *Error);
9592 return make_error<ASTImportError>(*Error);
9593 }
9594 // Make sure that ImportImpl registered the imported decl.
9595 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9596
9597 if (FromD->hasAttrs())
9598 for (const Attr *FromAttr : FromD->getAttrs()) {
9599 auto ToAttrOrErr = Import(FromAttr);
9600 if (ToAttrOrErr)
9601 ToD->addAttr(*ToAttrOrErr);
9602 else
9603 return ToAttrOrErr.takeError();
9604 }
9605
9606 // Notify subclasses.
9607 Imported(FromD, ToD);
9608
9609 updateFlags(FromD, ToD);
9610 SavedImportPaths.erase(FromD);
9611 return ToDOrErr;
9612}
9613
9616 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9617}
9618
9620 if (!FromDC)
9621 return FromDC;
9622
9623 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9624 if (!ToDCOrErr)
9625 return ToDCOrErr.takeError();
9626 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9627
9628 // When we're using a record/enum/Objective-C class/protocol as a context, we
9629 // need it to have a definition.
9630 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9631 auto *FromRecord = cast<RecordDecl>(FromDC);
9632 if (ToRecord->isCompleteDefinition())
9633 return ToDC;
9634
9635 // If FromRecord is not defined we need to force it to be.
9636 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9637 // it will start the definition but we never finish it.
9638 // If there are base classes they won't be imported and we will
9639 // be missing anything that we inherit from those bases.
9640 if (FromRecord->getASTContext().getExternalSource() &&
9641 !FromRecord->isCompleteDefinition())
9642 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9643
9644 if (FromRecord->isCompleteDefinition())
9645 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9646 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9647 return std::move(Err);
9648 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9649 auto *FromEnum = cast<EnumDecl>(FromDC);
9650 if (ToEnum->isCompleteDefinition()) {
9651 // Do nothing.
9652 } else if (FromEnum->isCompleteDefinition()) {
9653 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9654 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9655 return std::move(Err);
9656 } else {
9657 CompleteDecl(ToEnum);
9658 }
9659 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9660 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9661 if (ToClass->getDefinition()) {
9662 // Do nothing.
9663 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9664 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9665 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9666 return std::move(Err);
9667 } else {
9668 CompleteDecl(ToClass);
9669 }
9670 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9671 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9672 if (ToProto->getDefinition()) {
9673 // Do nothing.
9674 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9675 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9676 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9677 return std::move(Err);
9678 } else {
9679 CompleteDecl(ToProto);
9680 }
9681 }
9682
9683 return ToDC;
9684}
9685
9687 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9688 return cast_or_null<Expr>(*ToSOrErr);
9689 else
9690 return ToSOrErr.takeError();
9691}
9692
9694 if (!FromS)
9695 return nullptr;
9696
9697 // Check whether we've already imported this statement.
9698 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9699 if (Pos != ImportedStmts.end())
9700 return Pos->second;
9701
9702 // Import the statement.
9703 ASTNodeImporter Importer(*this);
9704 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9705 if (!ToSOrErr)
9706 return ToSOrErr;
9707
9708 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9709 auto *FromE = cast<Expr>(FromS);
9710 // Copy ExprBitfields, which may not be handled in Expr subclasses
9711 // constructors.
9712 ToE->setValueKind(FromE->getValueKind());
9713 ToE->setObjectKind(FromE->getObjectKind());
9714 ToE->setDependence(FromE->getDependence());
9715 }
9716
9717 // Record the imported statement object.
9718 ImportedStmts[FromS] = *ToSOrErr;
9719 return ToSOrErr;
9720}
9721
9724 if (!FromNNS)
9725 return nullptr;
9726
9727 NestedNameSpecifier *Prefix = nullptr;
9728 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9729 return std::move(Err);
9730
9731 switch (FromNNS->getKind()) {
9733 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9734 return NestedNameSpecifier::Create(ToContext, Prefix,
9735 Import(FromNNS->getAsIdentifier()));
9736
9738 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9739 return NestedNameSpecifier::Create(ToContext, Prefix,
9740 cast<NamespaceDecl>(*NSOrErr));
9741 } else
9742 return NSOrErr.takeError();
9743
9745 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9746 return NestedNameSpecifier::Create(ToContext, Prefix,
9747 cast<NamespaceAliasDecl>(*NSADOrErr));
9748 else
9749 return NSADOrErr.takeError();
9750
9752 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9753
9755 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9756 return NestedNameSpecifier::SuperSpecifier(ToContext,
9757 cast<CXXRecordDecl>(*RDOrErr));
9758 else
9759 return RDOrErr.takeError();
9760
9763 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9764 bool TSTemplate =
9766 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9767 *TyOrErr);
9768 } else {
9769 return TyOrErr.takeError();
9770 }
9771 }
9772
9773 llvm_unreachable("Invalid nested name specifier kind");
9774}
9775
9778 // Copied from NestedNameSpecifier mostly.
9780 NestedNameSpecifierLoc NNS = FromNNS;
9781
9782 // Push each of the nested-name-specifiers's onto a stack for
9783 // serialization in reverse order.
9784 while (NNS) {
9785 NestedNames.push_back(NNS);
9786 NNS = NNS.getPrefix();
9787 }
9788
9790
9791 while (!NestedNames.empty()) {
9792 NNS = NestedNames.pop_back_val();
9793 NestedNameSpecifier *Spec = nullptr;
9794 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9795 return std::move(Err);
9796
9798
9799 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9800 if (Kind != NestedNameSpecifier::Super) {
9801 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9802 return std::move(Err);
9803
9804 if (Kind != NestedNameSpecifier::Global)
9805 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9806 return std::move(Err);
9807 }
9808
9809 switch (Kind) {
9811 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9812 ToLocalEndLoc);
9813 break;
9814
9816 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9817 ToLocalEndLoc);
9818 break;
9819
9821 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9822 ToLocalBeginLoc, ToLocalEndLoc);
9823 break;
9824
9827 SourceLocation ToTLoc;
9828 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9829 return std::move(Err);
9831 QualType(Spec->getAsType(), 0), ToTLoc);
9833 // ToLocalBeginLoc is here the location of the 'template' keyword.
9834 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9835 ToLocalEndLoc);
9836 else
9837 // No location for 'template' keyword here.
9838 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9839 ToLocalEndLoc);
9840 break;
9841 }
9842
9844 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9845 break;
9846
9848 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9849 if (!ToSourceRangeOrErr)
9850 return ToSourceRangeOrErr.takeError();
9851
9852 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9853 ToSourceRangeOrErr->getBegin(),
9854 ToSourceRangeOrErr->getEnd());
9855 }
9856 }
9857 }
9858
9859 return Builder.getWithLocInContext(getToContext());
9860}
9861
9863 switch (From.getKind()) {
9865 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9866 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9867 else
9868 return ToTemplateOrErr.takeError();
9869
9872 UnresolvedSet<2> ToTemplates;
9873 for (auto *I : *FromStorage) {
9874 if (auto ToOrErr = Import(I))
9875 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9876 else
9877 return ToOrErr.takeError();
9878 }
9879 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9880 ToTemplates.end());
9881 }
9882
9885 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9886 if (!DeclNameOrErr)
9887 return DeclNameOrErr.takeError();
9888 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9889 }
9890
9893 auto QualifierOrErr = Import(QTN->getQualifier());
9894 if (!QualifierOrErr)
9895 return QualifierOrErr.takeError();
9896 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9897 if (!TNOrErr)
9898 return TNOrErr.takeError();
9899 return ToContext.getQualifiedTemplateName(
9900 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9901 }
9902
9905 auto QualifierOrErr = Import(DTN->getQualifier());
9906 if (!QualifierOrErr)
9907 return QualifierOrErr.takeError();
9908
9909 if (DTN->isIdentifier()) {
9910 return ToContext.getDependentTemplateName(*QualifierOrErr,
9911 Import(DTN->getIdentifier()));
9912 }
9913
9914 return ToContext.getDependentTemplateName(*QualifierOrErr,
9915 DTN->getOperator());
9916 }
9917
9921 auto ReplacementOrErr = Import(Subst->getReplacement());
9922 if (!ReplacementOrErr)
9923 return ReplacementOrErr.takeError();
9924
9925 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9926 if (!AssociatedDeclOrErr)
9927 return AssociatedDeclOrErr.takeError();
9928
9929 return ToContext.getSubstTemplateTemplateParm(
9930 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9931 Subst->getPackIndex());
9932 }
9933
9937 ASTNodeImporter Importer(*this);
9938 auto ArgPackOrErr =
9939 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9940 if (!ArgPackOrErr)
9941 return ArgPackOrErr.takeError();
9942
9943 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9944 if (!AssociatedDeclOrErr)
9945 return AssociatedDeclOrErr.takeError();
9946
9947 return ToContext.getSubstTemplateTemplateParmPack(
9948 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9949 SubstPack->getFinal());
9950 }
9952 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9953 if (!UsingOrError)
9954 return UsingOrError.takeError();
9955 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9956 }
9957 }
9958
9959 llvm_unreachable("Invalid template name kind");
9960}
9961
9963 if (FromLoc.isInvalid())
9964 return SourceLocation{};
9965
9966 SourceManager &FromSM = FromContext.getSourceManager();
9967 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9968
9969 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9970 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9971 if (!ToFileIDOrErr)
9972 return ToFileIDOrErr.takeError();
9973 SourceManager &ToSM = ToContext.getSourceManager();
9974 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
9975}
9976
9978 SourceLocation ToBegin, ToEnd;
9979 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
9980 return std::move(Err);
9981 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
9982 return std::move(Err);
9983
9984 return SourceRange(ToBegin, ToEnd);
9985}
9986
9988 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
9989 if (Pos != ImportedFileIDs.end())
9990 return Pos->second;
9991
9992 SourceManager &FromSM = FromContext.getSourceManager();
9993 SourceManager &ToSM = ToContext.getSourceManager();
9994 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
9995
9996 // Map the FromID to the "to" source manager.
9997 FileID ToID;
9998 if (FromSLoc.isExpansion()) {
9999 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10000 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10001 if (!ToSpLoc)
10002 return ToSpLoc.takeError();
10003 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10004 if (!ToExLocS)
10005 return ToExLocS.takeError();
10006 unsigned ExLength = FromSM.getFileIDSize(FromID);
10007 SourceLocation MLoc;
10008 if (FromEx.isMacroArgExpansion()) {
10009 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10010 } else {
10011 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10012 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10013 FromEx.isExpansionTokenRange());
10014 else
10015 return ToExLocE.takeError();
10016 }
10017 ToID = ToSM.getFileID(MLoc);
10018 } else {
10019 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10020
10021 if (!IsBuiltin && !Cache->BufferOverridden) {
10022 // Include location of this file.
10023 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10024 if (!ToIncludeLoc)
10025 return ToIncludeLoc.takeError();
10026
10027 // Every FileID that is not the main FileID needs to have a valid include
10028 // location so that the include chain points to the main FileID. When
10029 // importing the main FileID (which has no include location), we need to
10030 // create a fake include location in the main file to keep this property
10031 // intact.
10032 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10033 if (FromID == FromSM.getMainFileID())
10034 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10035
10036 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10037 // FIXME: We probably want to use getVirtualFile(), so we don't hit the
10038 // disk again
10039 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10040 // than mmap the files several times.
10041 auto Entry =
10042 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10043 // FIXME: The filename may be a virtual name that does probably not
10044 // point to a valid file and we get no Entry here. In this case try with
10045 // the memory buffer below.
10046 if (Entry)
10047 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10048 FromSLoc.getFile().getFileCharacteristic());
10049 }
10050 }
10051
10052 if (ToID.isInvalid() || IsBuiltin) {
10053 // FIXME: We want to re-use the existing MemoryBuffer!
10054 std::optional<llvm::MemoryBufferRef> FromBuf =
10055 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10056 FromSM.getFileManager(), SourceLocation{});
10057 if (!FromBuf)
10058 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10059
10060 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10061 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10062 FromBuf->getBufferIdentifier());
10063 ToID = ToSM.createFileID(std::move(ToBuf),
10064 FromSLoc.getFile().getFileCharacteristic());
10065 }
10066 }
10067
10068 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10069
10070 ImportedFileIDs[FromID] = ToID;
10071 return ToID;
10072}
10073
10075 ExpectedExpr ToExprOrErr = Import(From->getInit());
10076 if (!ToExprOrErr)
10077 return ToExprOrErr.takeError();
10078
10079 auto LParenLocOrErr = Import(From->getLParenLoc());
10080 if (!LParenLocOrErr)
10081 return LParenLocOrErr.takeError();
10082
10083 auto RParenLocOrErr = Import(From->getRParenLoc());
10084 if (!RParenLocOrErr)
10085 return RParenLocOrErr.takeError();
10086
10087 if (From->isBaseInitializer()) {
10088 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10089 if (!ToTInfoOrErr)
10090 return ToTInfoOrErr.takeError();
10091
10092 SourceLocation EllipsisLoc;
10093 if (From->isPackExpansion())
10094 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10095 return std::move(Err);
10096
10097 return new (ToContext) CXXCtorInitializer(
10098 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10099 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10100 } else if (From->isMemberInitializer()) {
10101 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10102 if (!ToFieldOrErr)
10103 return ToFieldOrErr.takeError();
10104
10105 auto MemberLocOrErr = Import(From->getMemberLocation());
10106 if (!MemberLocOrErr)
10107 return MemberLocOrErr.takeError();
10108
10109 return new (ToContext) CXXCtorInitializer(
10110 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10111 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10112 } else if (From->isIndirectMemberInitializer()) {
10113 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10114 if (!ToIFieldOrErr)
10115 return ToIFieldOrErr.takeError();
10116
10117 auto MemberLocOrErr = Import(From->getMemberLocation());
10118 if (!MemberLocOrErr)
10119 return MemberLocOrErr.takeError();
10120
10121 return new (ToContext) CXXCtorInitializer(
10122 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10123 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10124 } else if (From->isDelegatingInitializer()) {
10125 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10126 if (!ToTInfoOrErr)
10127 return ToTInfoOrErr.takeError();
10128
10129 return new (ToContext)
10130 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10131 *ToExprOrErr, *RParenLocOrErr);
10132 } else {
10133 // FIXME: assert?
10134 return make_error<ASTImportError>();
10135 }
10136}
10137
10140 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10141 if (Pos != ImportedCXXBaseSpecifiers.end())
10142 return Pos->second;
10143
10144 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10145 if (!ToSourceRange)
10146 return ToSourceRange.takeError();
10148 if (!ToTSI)
10149 return ToTSI.takeError();
10150 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10151 if (!ToEllipsisLoc)
10152 return ToEllipsisLoc.takeError();
10153 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10154 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10155 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10156 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10157 return Imported;
10158}
10159
10161 ASTNodeImporter Importer(*this);
10162 return Importer.ImportAPValue(FromValue);
10163}
10164
10166 ExpectedDecl ToOrErr = Import(From);
10167 if (!ToOrErr)
10168 return ToOrErr.takeError();
10169 Decl *To = *ToOrErr;
10170
10171 auto *FromDC = cast<DeclContext>(From);
10172 ASTNodeImporter Importer(*this);
10173
10174 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10175 if (!ToRecord->getDefinition()) {
10176 return Importer.ImportDefinition(
10177 cast<RecordDecl>(FromDC), ToRecord,
10179 }
10180 }
10181
10182 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10183 if (!ToEnum->getDefinition()) {
10184 return Importer.ImportDefinition(
10185 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10186 }
10187 }
10188
10189 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10190 if (!ToIFace->getDefinition()) {
10191 return Importer.ImportDefinition(
10192 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10194 }
10195 }
10196
10197 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10198 if (!ToProto->getDefinition()) {
10199 return Importer.ImportDefinition(
10200 cast<ObjCProtocolDecl>(FromDC), ToProto,
10202 }
10203 }
10204
10205 return Importer.ImportDeclContext(FromDC, true);
10206}
10207
10209 if (!FromName)
10210 return DeclarationName{};
10211
10212 switch (FromName.getNameKind()) {
10214 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10215
10219 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10220 return DeclarationName(*ToSelOrErr);
10221 else
10222 return ToSelOrErr.takeError();
10223
10225 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10226 return ToContext.DeclarationNames.getCXXConstructorName(
10227 ToContext.getCanonicalType(*ToTyOrErr));
10228 else
10229 return ToTyOrErr.takeError();
10230 }
10231
10233 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10234 return ToContext.DeclarationNames.getCXXDestructorName(
10235 ToContext.getCanonicalType(*ToTyOrErr));
10236 else
10237 return ToTyOrErr.takeError();
10238 }
10239
10241 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10243 cast<TemplateDecl>(*ToTemplateOrErr));
10244 else
10245 return ToTemplateOrErr.takeError();
10246 }
10247
10249 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10251 ToContext.getCanonicalType(*ToTyOrErr));
10252 else
10253 return ToTyOrErr.takeError();
10254 }
10255
10257 return ToContext.DeclarationNames.getCXXOperatorName(
10258 FromName.getCXXOverloadedOperator());
10259
10262 Import(FromName.getCXXLiteralIdentifier()));
10263
10265 // FIXME: STATICS!
10267 }
10268
10269 llvm_unreachable("Invalid DeclarationName Kind!");
10270}
10271
10273 if (!FromId)
10274 return nullptr;
10275
10276 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10277
10278 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10279 ToId->setBuiltinID(FromId->getBuiltinID());
10280
10281 return ToId;
10282}
10283
10285 if (FromSel.isNull())
10286 return Selector{};
10287
10289 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10290 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10291 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10292 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10293}
10294
10298 llvm::Error Err = llvm::Error::success();
10299 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10300 for (unsigned Idx = 0; Idx < Size; Idx++) {
10301 APValue Tmp = importChecked(Err, From[Idx]);
10302 To[Idx] = Tmp;
10303 }
10304 };
10305 switch (FromValue.getKind()) {
10306 case APValue::None:
10308 case APValue::Int:
10309 case APValue::Float:
10313 Result = FromValue;
10314 break;
10315 case APValue::Vector: {
10316 Result.MakeVector();
10318 Result.setVectorUninit(FromValue.getVectorLength());
10319 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10320 Elts.data(), FromValue.getVectorLength());
10321 break;
10322 }
10323 case APValue::Array:
10324 Result.MakeArray(FromValue.getArrayInitializedElts(),
10325 FromValue.getArraySize());
10326 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10327 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10328 FromValue.getArrayInitializedElts());
10329 break;
10330 case APValue::Struct:
10331 Result.MakeStruct(FromValue.getStructNumBases(),
10332 FromValue.getStructNumFields());
10333 ImportLoop(
10334 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10335 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10336 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10337 break;
10338 case APValue::Union: {
10339 Result.MakeUnion();
10340 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10341 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10342 if (Err)
10343 return std::move(Err);
10344 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10345 break;
10346 }
10348 Result.MakeAddrLabelDiff();
10349 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10350 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10351 if (Err)
10352 return std::move(Err);
10353 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10354 cast<AddrLabelExpr>(ImpRHS));
10355 break;
10356 }
10358 const Decl *ImpMemPtrDecl =
10359 importChecked(Err, FromValue.getMemberPointerDecl());
10360 if (Err)
10361 return std::move(Err);
10363 Result.setMemberPointerUninit(
10364 cast<const ValueDecl>(ImpMemPtrDecl),
10366 FromValue.getMemberPointerPath().size());
10368 Result.getMemberPointerPath();
10369 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10370 Idx++) {
10371 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10372 if (Err)
10373 return std::move(Err);
10374 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10375 }
10376 break;
10377 }
10378 case APValue::LValue:
10380 QualType FromElemTy;
10381 if (FromValue.getLValueBase()) {
10382 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10383 "in C++20 dynamic allocation are transient so they shouldn't "
10384 "appear in the AST");
10385 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10386 if (const auto *E =
10387 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10388 FromElemTy = E->getType();
10389 const Expr *ImpExpr = importChecked(Err, E);
10390 if (Err)
10391 return std::move(Err);
10392 Base = APValue::LValueBase(ImpExpr,
10393 FromValue.getLValueBase().getCallIndex(),
10394 FromValue.getLValueBase().getVersion());
10395 } else {
10396 FromElemTy =
10397 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10398 const Decl *ImpDecl = importChecked(
10399 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10400 if (Err)
10401 return std::move(Err);
10402 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10403 FromValue.getLValueBase().getCallIndex(),
10404 FromValue.getLValueBase().getVersion());
10405 }
10406 } else {
10407 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10408 const Type *ImpTypeInfo = importChecked(
10409 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10410 QualType ImpType =
10411 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10412 if (Err)
10413 return std::move(Err);
10415 ImpType);
10416 }
10417 }
10418 CharUnits Offset = FromValue.getLValueOffset();
10419 unsigned PathLength = FromValue.getLValuePath().size();
10420 Result.MakeLValue();
10421 if (FromValue.hasLValuePath()) {
10422 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10423 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10424 FromValue.isNullPointer());
10426 FromValue.getLValuePath();
10427 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10428 if (FromElemTy->isRecordType()) {
10429 const Decl *FromDecl =
10430 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10431 const Decl *ImpDecl = importChecked(Err, FromDecl);
10432 if (Err)
10433 return std::move(Err);
10434 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10435 FromElemTy = Importer.FromContext.getRecordType(RD);
10436 else
10437 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10439 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10440 } else {
10441 FromElemTy =
10442 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10443 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10444 FromPath[LoopIdx].getAsArrayIndex());
10445 }
10446 }
10447 } else
10448 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10449 FromValue.isNullPointer());
10450 }
10451 if (Err)
10452 return std::move(Err);
10453 return Result;
10454}
10455
10457 DeclContext *DC,
10458 unsigned IDNS,
10459 NamedDecl **Decls,
10460 unsigned NumDecls) {
10461 if (ODRHandling == ODRHandlingType::Conservative)
10462 // Report error at any name conflict.
10463 return make_error<ASTImportError>(ASTImportError::NameConflict);
10464 else
10465 // Allow to create the new Decl with the same name.
10466 return Name;
10467}
10468
10470 if (LastDiagFromFrom)
10472 FromContext.getDiagnostics());
10473 LastDiagFromFrom = false;
10474 return ToContext.getDiagnostics().Report(Loc, DiagID);
10475}
10476
10478 if (!LastDiagFromFrom)
10480 ToContext.getDiagnostics());
10481 LastDiagFromFrom = true;
10482 return FromContext.getDiagnostics().Report(Loc, DiagID);
10483}
10484
10486 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10487 if (!ID->getDefinition())
10488 ID->startDefinition();
10489 }
10490 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10491 if (!PD->getDefinition())
10492 PD->startDefinition();
10493 }
10494 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10495 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10496 TD->startDefinition();
10497 TD->setCompleteDefinition(true);
10498 }
10499 }
10500 else {
10501 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10502 }
10503}
10504
10506 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10507 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10508 "Try to import an already imported Decl");
10509 if (Pos != ImportedDecls.end())
10510 return Pos->second;
10511 ImportedDecls[From] = To;
10512 // This mapping should be maintained only in this function. Therefore do not
10513 // check for additional consistency.
10514 ImportedFromDecls[To] = From;
10515 // In the case of TypedefNameDecl we create the Decl first and only then we
10516 // import and set its DeclContext. So, the DC is still not set when we reach
10517 // here from GetImportedOrCreateDecl.
10518 if (To->getDeclContext())
10519 AddToLookupTable(To);
10520 return To;
10521}
10522
10523std::optional<ASTImportError>
10525 auto Pos = ImportDeclErrors.find(FromD);
10526 if (Pos != ImportDeclErrors.end())
10527 return Pos->second;
10528 else
10529 return std::nullopt;
10530}
10531
10533 auto InsertRes = ImportDeclErrors.insert({From, Error});
10534 (void)InsertRes;
10535 // Either we set the error for the first time, or we already had set one and
10536 // now we want to set the same error.
10537 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10538}
10539
10541 bool Complain) {
10542 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10543 ImportedTypes.find(From.getTypePtr());
10544 if (Pos != ImportedTypes.end()) {
10545 if (ExpectedType ToFromOrErr = Import(From)) {
10546 if (ToContext.hasSameType(*ToFromOrErr, To))
10547 return true;
10548 } else {
10549 llvm::consumeError(ToFromOrErr.takeError());
10550 }
10551 }
10552
10553 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10554 getStructuralEquivalenceKind(*this), false,
10555 Complain);
10556 return Ctx.IsEquivalent(From, To);
10557}
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
enum clang::sema::@1655::IndirectLocalPathEntry::EntryKind Kind
IndirectLocalPath & Path
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:3004
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:208
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:216
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:974
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:994
const FieldDecl * getUnionField() const
Definition: APValue.h:563
unsigned getStructNumFields() const
Definition: APValue.h:542
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition: APValue.h:205
ValueKind getKind() const
Definition: APValue.h:395
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:979
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1064
unsigned getArrayInitializedElts() const
Definition: APValue.h:529
unsigned getStructNumBases() const
Definition: APValue.h:538
bool hasLValuePath() const
Definition: APValue.cpp:989
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1057
APValue & getUnionValue()
Definition: APValue.h:567
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:583
CharUnits & getLValueOffset()
Definition: APValue.cpp:984
unsigned getVectorLength() const
Definition: APValue.h:505
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1071
unsigned getArraySize() const
Definition: APValue.h:533
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
bool isNullPointer() const
Definition: APValue.cpp:1010
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:579
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:187
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:721
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1101
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType) const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:664
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true)
Form a pack expansion type with the given pattern.
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2628
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2644
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1637
IdentifierTable & Idents
Definition: ASTContext.h:660
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:797
SelectorTable & Selectors
Definition: ASTContext.h:661
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:1121
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2210
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1128
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1119
CanQualType UnsignedCharTy
Definition: ASTContext.h:1129
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:1615
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:1227
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:1122
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
Retrieve a substitution-result type.
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
std::string toString() const
Definition: ASTImporter.cpp:86
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
void update(NamedDecl *ND, DeclContext *OldDC)
void updateForced(NamedDecl *ND, DeclContext *OldDC)
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
Definition: ASTImporter.h:164
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:178
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:522
llvm::DenseSet< std::pair< Decl *, Decl * > > NonEquivalentDeclSet
Definition: ASTImporter.h:65
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:537
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:519
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:269
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:370
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:307
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:562
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:547
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:297
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:4372
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3346
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5756
Represents a loop initializing the elements of an array.
Definition: Expr.h:5703
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3736
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2674
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2852
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3566
QualType getElementType() const
Definition: Type.h:3578
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:6629
Attr - This represents one attribute.
Definition: Attr.h:42
attr::Kind getKind() const
Definition: Attr.h:88
void setPackExpansion(bool PE)
Definition: Attr.h:104
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:102
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2090
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:425
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:6020
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6375
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3421
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3157
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4275
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3860
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:4859
A binding in a decomposition declaration.
Definition: DeclCXX.h:4111
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:4148
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4154
A fixed int type of a specified bitwidth.
Definition: Type.h:7633
Pointer to a block type.
Definition: Type.h:3397
BreakStmt - This represents a break.
Definition: Stmt.h:2990
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5291
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:3023
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:2105
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:203
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:254
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition: DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:193
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1098
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:876
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:1160
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2539
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2866
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2304
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2444
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2404
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2506
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2503
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2414
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2502
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2409
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2438
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2382
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2376
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2388
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2464
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2458
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2430
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1956
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:1019
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:1073
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2497
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3682
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:1534
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2803
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:2908
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:788
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4839
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:902
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:676
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2064
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2547
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2572
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2160
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:2240
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:292
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4125
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:612
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2616
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:1915
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:1927
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:1940
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1730
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1922
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:1955
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:853
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2181
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:762
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:1126
Represents a C++ temporary.
Definition: ExprCXX.h:1457
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1093
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:1569
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:3556
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1472
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2830
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1494
CaseStmt - Represent a case statement.
Definition: Stmt.h:1811
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1220
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3498
path_iterator path_begin()
Definition: Expr.h:3568
path_iterator path_end()
Definition: Expr.h:3569
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:4592
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:3134
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4122
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4881
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3428
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1611
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:383
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h: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:88
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:203
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:173
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4213
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3604
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:350
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4219
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3602
ContinueStmt - This represents a continue.
Definition: Stmt.h:2960
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4533
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3295
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3380
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:1369
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2090
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:2043
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1333
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1852
bool isRecord() const
Definition: DeclBase.h:2170
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1988
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1774
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1640
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1685
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:1917
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1635
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2350
bool isFunctionOrMethod() const
Definition: DeclBase.h:2142
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:1949
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:488
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1502
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:442
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:261
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1216
bool hasAttrs() const
Definition: DeclBase.h:525
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:523
void addAttr(Attr *A)
Definition: DeclBase.cpp:1013
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:600
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:242
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:883
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1207
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition: DeclBase.h:1170
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:509
SourceLocation getLocation() const
Definition: DeclBase.h:446
const char * getDeclKindName() const
Definition: DeclBase.cpp:145
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:601
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1039
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:615
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:552
DeclContext * getDeclContext()
Definition: DeclBase.h:455
AccessSpecifier getAccess() const
Definition: DeclBase.h:514
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:415
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:438
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:508
AttrVec & getAttrs()
Definition: DeclBase.h:531
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:358
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:908
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:362
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:766
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1982
Represents the type decltype(expr) (C++11).
Definition: Type.h:5774
A decomposition declaration.
Definition: DeclCXX.h:4170
Represents a C++17 deduced template specialization type.
Definition: Type.h:6423
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3907
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:6843
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3322
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:532
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3849
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3947
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4278
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:491
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:563
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:550
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:547
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:553
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:6895
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4073
Represents a single C99 designator.
Definition: Expr.h:5327
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5454
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5408
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5444
Represents a C99 designated initializer expression.
Definition: Expr.h:5284
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4605
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1271
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1547
void notePriorDiagnosticFrom(const DiagnosticsEngine &Other)
Note that the prior diagnostic was emitted by some other DiagnosticsEngine, and we may be attaching a...
Definition: Diagnostic.h:896
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2735
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:6762
Represents an empty-declaration.
Definition: Decl.h:4909
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3274
Represents an enum.
Definition: Decl.h:3844
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4103
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4041
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4013
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3940
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4877
EnumDecl * getDefinition() const
Definition: Decl.h:3947
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4030
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:3996
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5991
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3750
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1901
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1909
const Expr * getExpr() const
Definition: DeclCXX.h:1910
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3473
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3479
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1447
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:277
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2923
ExtVectorType - Extended vector type.
Definition: Type.h:4113
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:947
Represents a member of a struct/union/class.
Definition: Decl.h:3030
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4556
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3191
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4566
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4661
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:240
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1078
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2791
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:3084
Represents a function declaration or definition.
Definition: Decl.h:1932
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3224
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4033
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4028
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3243
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3105
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2574
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2646
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4007
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4158
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2327
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4223
@ TK_MemberSpecialization
Definition: Decl.h:1944
@ TK_DependentNonTemplate
Definition: Decl.h:1953
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1948
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1951
void setTrivial(bool IT)
Definition: Decl.h:2303
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:3979
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4046
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:4212
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2281
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2150
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4052
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4252
void setDefaulted(bool D=true)
Definition: Decl.h:2311
void setBody(Stmt *B)
Definition: Decl.cpp:3236
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3114
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2319
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4000
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3144
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4668
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5002
QualType desugar() const
Definition: Type.h:5546
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5266
ArrayRef< QualType > exceptions() const
Definition: Type.h:5425
ArrayRef< QualType > param_types() const
Definition: Type.h:5411
Declaration of a template function.
Definition: DeclTemplate.h:957
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:4642
QualType getReturnType() const
Definition: Type.h:4630
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3269
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4667
Represents a C11 generic selection.
Definition: Expr.h:5917
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:4493
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2872
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:2148
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:958
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1717
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3675
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2074
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5792
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4783
Represents a C array with an unspecified size.
Definition: Type.h:3751
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3318
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2911
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2510
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2523
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2522
Describes an C or C++ initializer list.
Definition: Expr.h:5039
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5209
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2419
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5164
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5219
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6612
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:977
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3472
Represents the declaration of a label.
Definition: Decl.h:499
void setStmt(LabelStmt *T)
Definition: Decl.h:524
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2041
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:1246
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:1294
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3233
Represents a linkage specification.
Definition: DeclCXX.h:2938
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:2980
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:5665
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4727
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3187
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1754
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3508
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:615
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:655
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:660
This represents a decl that may have a name.
Definition: Decl.h:249
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1176
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:315
Represents a C++ namespace alias.
Definition: DeclCXX.h:3124
Represent a C++ namespace.
Definition: Decl.h:547
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition: Decl.h:630
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:649
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.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1574
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1636
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2167
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2390
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2163
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:1748
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1642
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:372
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:343
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1629
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:616
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1914
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:352
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7343
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=std::nullopt)
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:944
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1190
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1211
Represents a pointer to an Objective C object.
Definition: Type.h:7399
Represents a class type in Objective C.
Definition: Type.h:7145
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:2023
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:1520
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:7071
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2475
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1657
Helper class for OffsetOfExpr.
Definition: Expr.h:2369
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2427
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2433
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1692
@ Array
An index into an array.
Definition: Expr.h:2374
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2378
@ Field
A field.
Definition: Expr.h:2376
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2381
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2455
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2423
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2456
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2443
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:108
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4179
Represents a pack expansion of types.
Definition: Type.h:6960
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2135
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4746
Sugar for parentheses used when specifying types.
Definition: Type.h:3161
Represents a parameter to a function.
Definition: Decl.h:1722
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1803
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1790
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2968
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1818
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1863
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1851
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:2993
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1755
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1855
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1750
bool hasInheritedDefaultArg() const
Definition: Decl.h:1867
void setKNRPromoted(bool promoted)
Definition: Decl.h:1806
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1814
Expr * getDefaultArg()
Definition: Decl.cpp:2956
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:2998
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3004
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1871
PipeType - OpenCL20.
Definition: Type.h:7599
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3187
[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:638
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2565
A (possibly-)qualified type.
Definition: Type.h:941
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:1008
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7750
QualType getCanonicalType() const
Definition: Type.h:7802
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7782
Represents a template name as written in source code.
Definition: TemplateName.h:434
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:469
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:462
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:466
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3490
Represents a struct/union/class.
Definition: Decl.h:4145
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5039
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4201
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4171
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5080
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4336
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5965
RecordDecl * getDecl() const
Definition: Type.h:5975
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:205
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:227
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:4978
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3428
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3029
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1204
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
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:4423
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4465
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4257
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs=std::nullopt)
Definition: ExprCXX.cpp:1694
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4761
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:4062
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4417
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:185
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:350
child_iterator child_begin()
Definition: Stmt.h:1462
StmtClass getStmtClass() const
Definition: Stmt.h:1363
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:326
child_iterator child_end()
Definition: Stmt.h:1463
const char * getStmtClassName() const
Definition: Stmt.cpp:79
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:338
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h: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:1191
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4483
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:141
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:156
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:375
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:399
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:397
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:393
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6283
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:6213
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1786
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2398
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1081
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3561
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3684
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3664
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3789
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4736
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4727
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4782
void setBraceRange(SourceRange R)
Definition: Decl.h:3641
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3667
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h:244
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:280
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:203
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:248
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:223
@ Template
A single template declaration.
Definition: TemplateName.h:220
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:235
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:239
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:244
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:231
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:227
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:144
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:180
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:201
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:200
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:199
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6480
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter, and whether that default argument was inherited...
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
void setDefaultArgument(const ASTContext &C, const TemplateArgumentLoc &DefArg)
Set the default argument for this template parameter.
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3532
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3550
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:3215
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3392
const Type * getTypeForDecl() const
Definition: Decl.h:3391
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:5697
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5747
The type-property cache.
Definition: Type.cpp:4437
A container of type source information.
Definition: Type.h:7721
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:7732
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2767
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:1877
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:1829
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8497
bool isArrayType() const
Definition: Type.h:8075
bool isPointerType() const
Definition: Type.h:8003
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:705
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2695
QualType getCanonicalTypeInternal() const
Definition: Type.h:2978
const char * getTypeClassName() const
Definition: Type.cpp:3273
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8490
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2362
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2360
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8540
bool isRecordType() const
Definition: Type.h:8103
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1886
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3511
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3409
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2578
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2188
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4895
A unary type transform, which is a type constructed from another.
Definition: Type.h:5882
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3202
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:420
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3942
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:1636
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:92
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5567
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:3963
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3866
Represents a C++ using-declaration.
Definition: DeclCXX.h:3516
Represents C++ using-directive.
Definition: DeclCXX.h:3019
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3717
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3798
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3324
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4701
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:667
void setType(QualType newType)
Definition: Decl.h:679
QualType getType() const
Definition: Decl.h:678
Represents a variable declaration or definition.
Definition: Decl.h:879
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2892
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2348
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2535
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2521
void setInlineSpecified()
Definition: Decl.h:1499
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1121
const Expr * getInit() const
Definition: Decl.h:1316
void setConstexpr(bool IC)
Definition: Decl.h:1513
void setInit(Expr *I)
Definition: Decl.cpp:2442
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2780
void setImplicitlyInline()
Definition: Decl.h:1504
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1306
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2855
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:3795
Represents a GCC generic vector type.
Definition: Type.h:4021
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2594
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition: Stmt.cpp:1143
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:328
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
void updateFlags(const Decl *From, Decl *To)
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h: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:312
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:309
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:1275
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
#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:1802
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:844
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:862
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:855
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:5071
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5075
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5061
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5064
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5067
Extra information about a function prototype.
Definition: Type.h:5087
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5094
FunctionType::ExtInfo ExtInfo
Definition: Type.h:5088
bool IsEquivalent(Decl *D1, Decl *D2)
Determine whether the two declarations are structurally equivalent.
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513