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
18#include "clang/AST/ASTLambda.h"
20#include "clang/AST/Attr.h"
21#include "clang/AST/Decl.h"
23#include "clang/AST/DeclBase.h"
24#include "clang/AST/DeclCXX.h"
26#include "clang/AST/DeclGroup.h"
27#include "clang/AST/DeclObjC.h"
31#include "clang/AST/Expr.h"
32#include "clang/AST/ExprCXX.h"
33#include "clang/AST/ExprObjC.h"
38#include "clang/AST/Stmt.h"
39#include "clang/AST/StmtCXX.h"
40#include "clang/AST/StmtObjC.h"
44#include "clang/AST/Type.h"
45#include "clang/AST/TypeLoc.h"
52#include "clang/Basic/LLVM.h"
57#include "llvm/ADT/ArrayRef.h"
58#include "llvm/ADT/DenseMap.h"
59#include "llvm/ADT/STLExtras.h"
60#include "llvm/ADT/ScopeExit.h"
61#include "llvm/ADT/SmallVector.h"
62#include "llvm/Support/ErrorHandling.h"
63#include "llvm/Support/MemoryBuffer.h"
64#include <algorithm>
65#include <cassert>
66#include <cstddef>
67#include <memory>
68#include <optional>
69#include <type_traits>
70#include <utility>
71
72namespace clang {
73
74 using llvm::make_error;
75 using llvm::Error;
76 using llvm::Expected;
84
85 std::string ASTImportError::toString() const {
86 // FIXME: Improve error texts.
87 switch (Error) {
88 case NameConflict:
89 return "NameConflict";
91 return "UnsupportedConstruct";
92 case Unknown:
93 return "Unknown error";
94 }
95 llvm_unreachable("Invalid error code.");
96 return "Invalid error code.";
97 }
98
99 void ASTImportError::log(raw_ostream &OS) const { OS << toString(); }
100
101 std::error_code ASTImportError::convertToErrorCode() const {
102 llvm_unreachable("Function not implemented.");
103 }
104
106
107 template <class T>
111 for (auto *R : D->getFirstDecl()->redecls()) {
112 if (R != D->getFirstDecl())
113 Redecls.push_back(R);
114 }
115 Redecls.push_back(D->getFirstDecl());
116 std::reverse(Redecls.begin(), Redecls.end());
117 return Redecls;
118 }
119
121 if (auto *FD = dyn_cast<FunctionDecl>(D))
122 return getCanonicalForwardRedeclChain<FunctionDecl>(FD);
123 if (auto *VD = dyn_cast<VarDecl>(D))
124 return getCanonicalForwardRedeclChain<VarDecl>(VD);
125 if (auto *TD = dyn_cast<TagDecl>(D))
126 return getCanonicalForwardRedeclChain<TagDecl>(TD);
127 llvm_unreachable("Bad declaration kind");
128 }
129
130 static void updateFlags(const Decl *From, Decl *To) {
131 // Check if some flags or attrs are new in 'From' and copy into 'To'.
132 // FIXME: Other flags or attrs?
133 if (From->isUsed(false) && !To->isUsed(false))
134 To->setIsUsed();
135 }
136
137 /// How to handle import errors that occur when import of a child declaration
138 /// of a DeclContext fails.
140 /// This context is imported (in the 'from' domain).
141 /// It is nullptr if a non-DeclContext is imported.
142 const DeclContext *const FromDC;
143 /// Ignore import errors of the children.
144 /// If true, the context can be imported successfully if a child
145 /// of it failed to import. Otherwise the import errors of the child nodes
146 /// are accumulated (joined) into the import error object of the parent.
147 /// (Import of a parent can fail in other ways.)
148 bool const IgnoreChildErrors;
149
150 public:
152 : FromDC(FromDC), IgnoreChildErrors(!isa<TagDecl>(FromDC)) {}
154 : FromDC(dyn_cast<DeclContext>(FromD)),
155 IgnoreChildErrors(!isa<TagDecl>(FromD)) {}
156
157 /// Process the import result of a child (of the current declaration).
158 /// \param ResultErr The import error that can be used as result of
159 /// importing the parent. This may be changed by the function.
160 /// \param ChildErr Result of importing a child. Can be success or error.
161 void handleChildImportResult(Error &ResultErr, Error &&ChildErr) {
162 if (ChildErr && !IgnoreChildErrors)
163 ResultErr = joinErrors(std::move(ResultErr), std::move(ChildErr));
164 else
165 consumeError(std::move(ChildErr));
166 }
167
168 /// Determine if import failure of a child does not cause import failure of
169 /// its parent.
170 bool ignoreChildErrorOnParent(Decl *FromChildD) const {
171 if (!IgnoreChildErrors || !FromDC)
172 return false;
173 return FromDC->containsDecl(FromChildD);
174 }
175 };
176
177 class ASTNodeImporter : public TypeVisitor<ASTNodeImporter, ExpectedType>,
178 public DeclVisitor<ASTNodeImporter, ExpectedDecl>,
179 public StmtVisitor<ASTNodeImporter, ExpectedStmt> {
180 ASTImporter &Importer;
181
182 // Use this instead of Importer.importInto .
183 template <typename ImportT>
184 [[nodiscard]] Error importInto(ImportT &To, const ImportT &From) {
185 return Importer.importInto(To, From);
186 }
187
188 // Use this to import pointers of specific type.
189 template <typename ImportT>
190 [[nodiscard]] Error importInto(ImportT *&To, ImportT *From) {
191 auto ToOrErr = Importer.Import(From);
192 if (ToOrErr)
193 To = cast_or_null<ImportT>(*ToOrErr);
194 return ToOrErr.takeError();
195 }
196
197 // Call the import function of ASTImporter for a baseclass of type `T` and
198 // cast the return value to `T`.
199 template <typename T>
200 auto import(T *From)
201 -> std::conditional_t<std::is_base_of_v<Type, T>, Expected<const T *>,
203 auto ToOrErr = Importer.Import(From);
204 if (!ToOrErr)
205 return ToOrErr.takeError();
206 return cast_or_null<T>(*ToOrErr);
207 }
208
209 template <typename T>
210 auto import(const T *From) {
211 return import(const_cast<T *>(From));
212 }
213
214 // Call the import function of ASTImporter for type `T`.
215 template <typename T>
216 Expected<T> import(const T &From) {
217 return Importer.Import(From);
218 }
219
220 // Import an std::optional<T> by importing the contained T, if any.
221 template <typename T>
222 Expected<std::optional<T>> import(std::optional<T> From) {
223 if (!From)
224 return std::nullopt;
225 return import(*From);
226 }
227
228 ExplicitSpecifier importExplicitSpecifier(Error &Err,
229 ExplicitSpecifier ESpec);
230
231 // Wrapper for an overload set.
232 template <typename ToDeclT> struct CallOverloadedCreateFun {
233 template <typename... Args> decltype(auto) operator()(Args &&... args) {
234 return ToDeclT::Create(std::forward<Args>(args)...);
235 }
236 };
237
238 // Always use these functions to create a Decl during import. There are
239 // certain tasks which must be done after the Decl was created, e.g. we
240 // must immediately register that as an imported Decl. The parameter `ToD`
241 // will be set to the newly created Decl or if had been imported before
242 // then to the already imported Decl. Returns a bool value set to true if
243 // the `FromD` had been imported before.
244 template <typename ToDeclT, typename FromDeclT, typename... Args>
245 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
246 Args &&...args) {
247 // There may be several overloads of ToDeclT::Create. We must make sure
248 // to call the one which would be chosen by the arguments, thus we use a
249 // wrapper for the overload set.
250 CallOverloadedCreateFun<ToDeclT> OC;
251 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
252 std::forward<Args>(args)...);
253 }
254 // Use this overload if a special Type is needed to be created. E.g if we
255 // want to create a `TypeAliasDecl` and assign that to a `TypedefNameDecl`
256 // then:
257 // TypedefNameDecl *ToTypedef;
258 // GetImportedOrCreateDecl<TypeAliasDecl>(ToTypedef, FromD, ...);
259 template <typename NewDeclT, typename ToDeclT, typename FromDeclT,
260 typename... Args>
261 [[nodiscard]] bool GetImportedOrCreateDecl(ToDeclT *&ToD, FromDeclT *FromD,
262 Args &&...args) {
263 CallOverloadedCreateFun<NewDeclT> OC;
264 return GetImportedOrCreateSpecialDecl(ToD, OC, FromD,
265 std::forward<Args>(args)...);
266 }
267 // Use this version if a special create function must be
268 // used, e.g. CXXRecordDecl::CreateLambda .
269 template <typename ToDeclT, typename CreateFunT, typename FromDeclT,
270 typename... Args>
271 [[nodiscard]] bool
272 GetImportedOrCreateSpecialDecl(ToDeclT *&ToD, CreateFunT CreateFun,
273 FromDeclT *FromD, Args &&...args) {
274 if (Importer.getImportDeclErrorIfAny(FromD)) {
275 ToD = nullptr;
276 return true; // Already imported but with error.
277 }
278 ToD = cast_or_null<ToDeclT>(Importer.GetAlreadyImportedOrNull(FromD));
279 if (ToD)
280 return true; // Already imported.
281 ToD = CreateFun(std::forward<Args>(args)...);
282 // Keep track of imported Decls.
283 Importer.RegisterImportedDecl(FromD, ToD);
284 Importer.SharedState->markAsNewDecl(ToD);
285 InitializeImportedDecl(FromD, ToD);
286 return false; // A new Decl is created.
287 }
288
289 void InitializeImportedDecl(Decl *FromD, Decl *ToD) {
290 ToD->IdentifierNamespace = FromD->IdentifierNamespace;
291 if (FromD->isUsed())
292 ToD->setIsUsed();
293 if (FromD->isImplicit())
294 ToD->setImplicit();
295 }
296
297 // Check if we have found an existing definition. Returns with that
298 // definition if yes, otherwise returns null.
299 Decl *FindAndMapDefinition(FunctionDecl *D, FunctionDecl *FoundFunction) {
300 const FunctionDecl *Definition = nullptr;
301 if (D->doesThisDeclarationHaveABody() &&
302 FoundFunction->hasBody(Definition))
303 return Importer.MapImported(D, const_cast<FunctionDecl *>(Definition));
304 return nullptr;
305 }
306
307 void addDeclToContexts(Decl *FromD, Decl *ToD) {
308 if (Importer.isMinimalImport()) {
309 // In minimal import case the decl must be added even if it is not
310 // contained in original context, for LLDB compatibility.
311 // FIXME: Check if a better solution is possible.
312 if (!FromD->getDescribedTemplate() &&
313 FromD->getFriendObjectKind() == Decl::FOK_None)
315 return;
316 }
317
318 DeclContext *FromDC = FromD->getDeclContext();
319 DeclContext *FromLexicalDC = FromD->getLexicalDeclContext();
320 DeclContext *ToDC = ToD->getDeclContext();
321 DeclContext *ToLexicalDC = ToD->getLexicalDeclContext();
322
323 bool Visible = false;
324 if (FromDC->containsDeclAndLoad(FromD)) {
325 ToDC->addDeclInternal(ToD);
326 Visible = true;
327 }
328 if (ToDC != ToLexicalDC && FromLexicalDC->containsDeclAndLoad(FromD)) {
329 ToLexicalDC->addDeclInternal(ToD);
330 Visible = true;
331 }
332
333 // If the Decl was added to any context, it was made already visible.
334 // Otherwise it is still possible that it should be visible.
335 if (!Visible) {
336 if (auto *FromNamed = dyn_cast<NamedDecl>(FromD)) {
337 auto *ToNamed = cast<NamedDecl>(ToD);
338 DeclContextLookupResult FromLookup =
339 FromDC->lookup(FromNamed->getDeclName());
340 if (llvm::is_contained(FromLookup, FromNamed))
341 ToDC->makeDeclVisibleInContext(ToNamed);
342 }
343 }
344 }
345
346 void updateLookupTableForTemplateParameters(TemplateParameterList &Params,
347 DeclContext *OldDC) {
348 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
349 if (!LT)
350 return;
351
352 for (NamedDecl *TP : Params)
353 LT->update(TP, OldDC);
354 }
355
356 void updateLookupTableForTemplateParameters(TemplateParameterList &Params) {
357 updateLookupTableForTemplateParameters(
358 Params, Importer.getToContext().getTranslationUnitDecl());
359 }
360
361 template <typename TemplateParmDeclT>
362 Error importTemplateParameterDefaultArgument(const TemplateParmDeclT *D,
363 TemplateParmDeclT *ToD) {
364 if (D->hasDefaultArgument()) {
365 if (D->defaultArgumentWasInherited()) {
366 Expected<TemplateParmDeclT *> ToInheritedFromOrErr =
367 import(D->getDefaultArgStorage().getInheritedFrom());
368 if (!ToInheritedFromOrErr)
369 return ToInheritedFromOrErr.takeError();
370 TemplateParmDeclT *ToInheritedFrom = *ToInheritedFromOrErr;
371 if (!ToInheritedFrom->hasDefaultArgument()) {
372 // Resolve possible circular dependency between default value of the
373 // template argument and the template declaration.
374 Expected<TemplateArgumentLoc> ToInheritedDefaultArgOrErr =
375 import(D->getDefaultArgStorage()
376 .getInheritedFrom()
377 ->getDefaultArgument());
378 if (!ToInheritedDefaultArgOrErr)
379 return ToInheritedDefaultArgOrErr.takeError();
380 ToInheritedFrom->setDefaultArgument(Importer.getToContext(),
381 *ToInheritedDefaultArgOrErr);
382 }
383 ToD->setInheritedDefaultArgument(ToD->getASTContext(),
384 ToInheritedFrom);
385 } else {
386 Expected<TemplateArgumentLoc> ToDefaultArgOrErr =
387 import(D->getDefaultArgument());
388 if (!ToDefaultArgOrErr)
389 return ToDefaultArgOrErr.takeError();
390 // Default argument could have been set in the
391 // '!ToInheritedFrom->hasDefaultArgument()' branch above.
392 if (!ToD->hasDefaultArgument())
393 ToD->setDefaultArgument(Importer.getToContext(),
394 *ToDefaultArgOrErr);
395 }
396 }
397 return Error::success();
398 }
399
400 public:
401 explicit ASTNodeImporter(ASTImporter &Importer) : Importer(Importer) {}
402
406
407 // Importing types
409#define TYPE(Class, Base) \
410 ExpectedType Visit##Class##Type(const Class##Type *T);
411#include "clang/AST/TypeNodes.inc"
412
413 // Importing declarations
416 Error ImportDeclParts(
417 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
419 Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD = nullptr);
422 Error ImportDeclContext(DeclContext *FromDC, bool ForceImport = false);
423 Error ImportDeclContext(
424 Decl *From, DeclContext *&ToDC, DeclContext *&ToLexicalDC);
425 Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To);
426
427 Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To);
429 Expected<APValue> ImportAPValue(const APValue &FromValue);
430
432
433 /// What we should import from the definition.
435 /// Import the default subset of the definition, which might be
436 /// nothing (if minimal import is set) or might be everything (if minimal
437 /// import is not set).
439 /// Import everything.
441 /// Import only the bare bones needed to establish a valid
442 /// DeclContext.
444 };
445
447 return IDK == IDK_Everything ||
448 (IDK == IDK_Default && !Importer.isMinimalImport());
449 }
450
451 Error ImportInitializer(VarDecl *From, VarDecl *To);
452 Error ImportDefinition(
453 RecordDecl *From, RecordDecl *To,
455 Error ImportDefinition(
456 EnumDecl *From, EnumDecl *To,
458 Error ImportDefinition(
461 Error ImportDefinition(
468
469 template <typename InContainerTy>
471 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo);
472
473 template<typename InContainerTy>
475 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
476 const InContainerTy &Container, TemplateArgumentListInfo &Result);
477
480 std::tuple<FunctionTemplateDecl *, TemplateArgsTy>;
483 FunctionDecl *FromFD);
484
485 template <typename DeclTy>
486 Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD);
487
489
491
492 Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam,
493 ParmVarDecl *ToParam);
494
497
498 template <typename T>
500
501 bool IsStructuralMatch(Decl *From, Decl *To, bool Complain = true,
502 bool IgnoreTemplateParmDepth = false);
549
552
567
568 // Importing statements
588 // FIXME: MSAsmStmt
589 // FIXME: SEHExceptStmt
590 // FIXME: SEHFinallyStmt
591 // FIXME: SEHTryStmt
592 // FIXME: SEHLeaveStmt
593 // FIXME: CapturedStmt
597 // FIXME: MSDependentExistsStmt
605
606 // Importing expressions
683
684 // Helper for chaining together multiple imports. If an error is detected,
685 // subsequent imports will return default constructed nodes, so that failure
686 // can be detected with a single conditional branch after a sequence of
687 // imports.
688 template <typename T> T importChecked(Error &Err, const T &From) {
689 // Don't attempt to import nodes if we hit an error earlier.
690 if (Err)
691 return T{};
692 Expected<T> MaybeVal = import(From);
693 if (!MaybeVal) {
694 Err = MaybeVal.takeError();
695 return T{};
696 }
697 return *MaybeVal;
698 }
699
700 template<typename IIter, typename OIter>
701 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
702 using ItemT = std::remove_reference_t<decltype(*Obegin)>;
703 for (; Ibegin != Iend; ++Ibegin, ++Obegin) {
704 Expected<ItemT> ToOrErr = import(*Ibegin);
705 if (!ToOrErr)
706 return ToOrErr.takeError();
707 *Obegin = *ToOrErr;
708 }
709 return Error::success();
710 }
711
712 // Import every item from a container structure into an output container.
713 // If error occurs, stops at first error and returns the error.
714 // The output container should have space for all needed elements (it is not
715 // expanded, new items are put into from the beginning).
716 template<typename InContainerTy, typename OutContainerTy>
718 const InContainerTy &InContainer, OutContainerTy &OutContainer) {
719 return ImportArrayChecked(
720 InContainer.begin(), InContainer.end(), OutContainer.begin());
721 }
722
723 template<typename InContainerTy, typename OIter>
724 Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin) {
725 return ImportArrayChecked(InContainer.begin(), InContainer.end(), Obegin);
726 }
727
729 CXXMethodDecl *FromMethod);
730
732 FunctionDecl *FromFD);
733
734 // Returns true if the given function has a placeholder return type and
735 // that type is declared inside the body of the function.
736 // E.g. auto f() { struct X{}; return X(); }
738 };
739
740template <typename InContainerTy>
742 SourceLocation FromLAngleLoc, SourceLocation FromRAngleLoc,
743 const InContainerTy &Container, TemplateArgumentListInfo &Result) {
744 auto ToLAngleLocOrErr = import(FromLAngleLoc);
745 if (!ToLAngleLocOrErr)
746 return ToLAngleLocOrErr.takeError();
747 auto ToRAngleLocOrErr = import(FromRAngleLoc);
748 if (!ToRAngleLocOrErr)
749 return ToRAngleLocOrErr.takeError();
750
751 TemplateArgumentListInfo ToTAInfo(*ToLAngleLocOrErr, *ToRAngleLocOrErr);
752 if (auto Err = ImportTemplateArgumentListInfo(Container, ToTAInfo))
753 return Err;
754 Result = ToTAInfo;
755 return Error::success();
756}
757
758template <>
759Error ASTNodeImporter::ImportTemplateArgumentListInfo<TemplateArgumentListInfo>(
762 From.getLAngleLoc(), From.getRAngleLoc(), From.arguments(), Result);
763}
764
765template <>
768 const ASTTemplateArgumentListInfo &From,
770 return ImportTemplateArgumentListInfo(
771 From.LAngleLoc, From.RAngleLoc, From.arguments(), Result);
772}
773
776 FunctionDecl *FromFD) {
777 assert(FromFD->getTemplatedKind() ==
779
781
782 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
783 if (Error Err = importInto(std::get<0>(Result), FTSInfo->getTemplate()))
784 return std::move(Err);
785
786 // Import template arguments.
787 if (Error Err = ImportTemplateArguments(FTSInfo->TemplateArguments->asArray(),
788 std::get<1>(Result)))
789 return std::move(Err);
790
791 return Result;
792}
793
794template <>
796ASTNodeImporter::import(TemplateParameterList *From) {
798 if (Error Err = ImportContainerChecked(*From, To))
799 return std::move(Err);
800
801 ExpectedExpr ToRequiresClause = import(From->getRequiresClause());
802 if (!ToRequiresClause)
803 return ToRequiresClause.takeError();
804
805 auto ToTemplateLocOrErr = import(From->getTemplateLoc());
806 if (!ToTemplateLocOrErr)
807 return ToTemplateLocOrErr.takeError();
808 auto ToLAngleLocOrErr = import(From->getLAngleLoc());
809 if (!ToLAngleLocOrErr)
810 return ToLAngleLocOrErr.takeError();
811 auto ToRAngleLocOrErr = import(From->getRAngleLoc());
812 if (!ToRAngleLocOrErr)
813 return ToRAngleLocOrErr.takeError();
814
816 Importer.getToContext(),
817 *ToTemplateLocOrErr,
818 *ToLAngleLocOrErr,
819 To,
820 *ToRAngleLocOrErr,
821 *ToRequiresClause);
822}
823
824template <>
826ASTNodeImporter::import(const TemplateArgument &From) {
827 switch (From.getKind()) {
829 return TemplateArgument();
830
832 ExpectedType ToTypeOrErr = import(From.getAsType());
833 if (!ToTypeOrErr)
834 return ToTypeOrErr.takeError();
835 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ false,
836 From.getIsDefaulted());
837 }
838
840 ExpectedType ToTypeOrErr = import(From.getIntegralType());
841 if (!ToTypeOrErr)
842 return ToTypeOrErr.takeError();
843 return TemplateArgument(From, *ToTypeOrErr);
844 }
845
847 Expected<ValueDecl *> ToOrErr = import(From.getAsDecl());
848 if (!ToOrErr)
849 return ToOrErr.takeError();
850 ExpectedType ToTypeOrErr = import(From.getParamTypeForDecl());
851 if (!ToTypeOrErr)
852 return ToTypeOrErr.takeError();
853 return TemplateArgument(dyn_cast<ValueDecl>((*ToOrErr)->getCanonicalDecl()),
854 *ToTypeOrErr, From.getIsDefaulted());
855 }
856
858 ExpectedType ToTypeOrErr = import(From.getNullPtrType());
859 if (!ToTypeOrErr)
860 return ToTypeOrErr.takeError();
861 return TemplateArgument(*ToTypeOrErr, /*isNullPtr*/ true,
862 From.getIsDefaulted());
863 }
864
866 ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
867 if (!ToTypeOrErr)
868 return ToTypeOrErr.takeError();
869 Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
870 if (!ToValueOrErr)
871 return ToValueOrErr.takeError();
872 return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
873 *ToValueOrErr);
874 }
875
877 Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
878 if (!ToTemplateOrErr)
879 return ToTemplateOrErr.takeError();
880
881 return TemplateArgument(*ToTemplateOrErr, From.getIsDefaulted());
882 }
883
885 Expected<TemplateName> ToTemplateOrErr =
886 import(From.getAsTemplateOrTemplatePattern());
887 if (!ToTemplateOrErr)
888 return ToTemplateOrErr.takeError();
889
890 return TemplateArgument(*ToTemplateOrErr, From.getNumTemplateExpansions(),
891 From.getIsDefaulted());
892 }
893
895 if (ExpectedExpr ToExpr = import(From.getAsExpr()))
896 return TemplateArgument(*ToExpr, From.getIsDefaulted());
897 else
898 return ToExpr.takeError();
899
902 ToPack.reserve(From.pack_size());
903 if (Error Err = ImportTemplateArguments(From.pack_elements(), ToPack))
904 return std::move(Err);
905
906 return TemplateArgument(
907 llvm::ArrayRef(ToPack).copy(Importer.getToContext()));
908 }
909 }
910
911 llvm_unreachable("Invalid template argument kind");
912}
913
914template <>
916ASTNodeImporter::import(const TemplateArgumentLoc &TALoc) {
917 Expected<TemplateArgument> ArgOrErr = import(TALoc.getArgument());
918 if (!ArgOrErr)
919 return ArgOrErr.takeError();
920 TemplateArgument Arg = *ArgOrErr;
921
922 TemplateArgumentLocInfo FromInfo = TALoc.getLocInfo();
923
926 ExpectedExpr E = import(FromInfo.getAsExpr());
927 if (!E)
928 return E.takeError();
929 ToInfo = TemplateArgumentLocInfo(*E);
930 } else if (Arg.getKind() == TemplateArgument::Type) {
931 if (auto TSIOrErr = import(FromInfo.getAsTypeSourceInfo()))
932 ToInfo = TemplateArgumentLocInfo(*TSIOrErr);
933 else
934 return TSIOrErr.takeError();
935 } else {
936 auto ToTemplateQualifierLocOrErr =
937 import(FromInfo.getTemplateQualifierLoc());
938 if (!ToTemplateQualifierLocOrErr)
939 return ToTemplateQualifierLocOrErr.takeError();
940 auto ToTemplateNameLocOrErr = import(FromInfo.getTemplateNameLoc());
941 if (!ToTemplateNameLocOrErr)
942 return ToTemplateNameLocOrErr.takeError();
943 auto ToTemplateEllipsisLocOrErr =
944 import(FromInfo.getTemplateEllipsisLoc());
945 if (!ToTemplateEllipsisLocOrErr)
946 return ToTemplateEllipsisLocOrErr.takeError();
948 Importer.getToContext(), *ToTemplateQualifierLocOrErr,
949 *ToTemplateNameLocOrErr, *ToTemplateEllipsisLocOrErr);
950 }
951
952 return TemplateArgumentLoc(Arg, ToInfo);
953}
954
955template <>
956Expected<DeclGroupRef> ASTNodeImporter::import(const DeclGroupRef &DG) {
957 if (DG.isNull())
958 return DeclGroupRef::Create(Importer.getToContext(), nullptr, 0);
959 size_t NumDecls = DG.end() - DG.begin();
961 ToDecls.reserve(NumDecls);
962 for (Decl *FromD : DG) {
963 if (auto ToDOrErr = import(FromD))
964 ToDecls.push_back(*ToDOrErr);
965 else
966 return ToDOrErr.takeError();
967 }
968 return DeclGroupRef::Create(Importer.getToContext(),
969 ToDecls.begin(),
970 NumDecls);
971}
972
973template <>
975ASTNodeImporter::import(const Designator &D) {
976 if (D.isFieldDesignator()) {
977 IdentifierInfo *ToFieldName = Importer.Import(D.getFieldName());
978
979 ExpectedSLoc ToDotLocOrErr = import(D.getDotLoc());
980 if (!ToDotLocOrErr)
981 return ToDotLocOrErr.takeError();
982
983 ExpectedSLoc ToFieldLocOrErr = import(D.getFieldLoc());
984 if (!ToFieldLocOrErr)
985 return ToFieldLocOrErr.takeError();
986
988 ToFieldName, *ToDotLocOrErr, *ToFieldLocOrErr);
989 }
990
991 ExpectedSLoc ToLBracketLocOrErr = import(D.getLBracketLoc());
992 if (!ToLBracketLocOrErr)
993 return ToLBracketLocOrErr.takeError();
994
995 ExpectedSLoc ToRBracketLocOrErr = import(D.getRBracketLoc());
996 if (!ToRBracketLocOrErr)
997 return ToRBracketLocOrErr.takeError();
998
999 if (D.isArrayDesignator())
1000 return Designator::CreateArrayDesignator(D.getArrayIndex(),
1001 *ToLBracketLocOrErr,
1002 *ToRBracketLocOrErr);
1003
1004 ExpectedSLoc ToEllipsisLocOrErr = import(D.getEllipsisLoc());
1005 if (!ToEllipsisLocOrErr)
1006 return ToEllipsisLocOrErr.takeError();
1007
1008 assert(D.isArrayRangeDesignator());
1010 D.getArrayIndex(), *ToLBracketLocOrErr, *ToEllipsisLocOrErr,
1011 *ToRBracketLocOrErr);
1012}
1013
1014template <>
1015Expected<ConceptReference *> ASTNodeImporter::import(ConceptReference *From) {
1016 Error Err = Error::success();
1017 auto ToNNS = importChecked(Err, From->getNestedNameSpecifierLoc());
1018 auto ToTemplateKWLoc = importChecked(Err, From->getTemplateKWLoc());
1019 auto ToConceptNameLoc =
1020 importChecked(Err, From->getConceptNameInfo().getLoc());
1021 auto ToConceptName = importChecked(Err, From->getConceptNameInfo().getName());
1022 auto ToFoundDecl = importChecked(Err, From->getFoundDecl());
1023 auto ToNamedConcept = importChecked(Err, From->getNamedConcept());
1024 if (Err)
1025 return std::move(Err);
1026 TemplateArgumentListInfo ToTAInfo;
1027 const auto *ASTTemplateArgs = From->getTemplateArgsAsWritten();
1028 if (ASTTemplateArgs)
1029 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
1030 return std::move(Err);
1031 auto *ConceptRef = ConceptReference::Create(
1032 Importer.getToContext(), ToNNS, ToTemplateKWLoc,
1033 DeclarationNameInfo(ToConceptName, ToConceptNameLoc), ToFoundDecl,
1034 ToNamedConcept,
1035 ASTTemplateArgs ? ASTTemplateArgumentListInfo::Create(
1036 Importer.getToContext(), ToTAInfo)
1037 : nullptr);
1038 return ConceptRef;
1039}
1040
1041template <>
1042Expected<LambdaCapture> ASTNodeImporter::import(const LambdaCapture &From) {
1043 ValueDecl *Var = nullptr;
1044 if (From.capturesVariable()) {
1045 if (auto VarOrErr = import(From.getCapturedVar()))
1046 Var = *VarOrErr;
1047 else
1048 return VarOrErr.takeError();
1049 }
1050
1051 auto LocationOrErr = import(From.getLocation());
1052 if (!LocationOrErr)
1053 return LocationOrErr.takeError();
1054
1055 SourceLocation EllipsisLoc;
1056 if (From.isPackExpansion())
1057 if (Error Err = importInto(EllipsisLoc, From.getEllipsisLoc()))
1058 return std::move(Err);
1059
1060 return LambdaCapture(
1061 *LocationOrErr, From.isImplicit(), From.getCaptureKind(), Var,
1062 EllipsisLoc);
1063}
1064
1065template <typename T>
1067 if (Found->getLinkageInternal() != From->getLinkageInternal())
1068 return false;
1069
1070 if (From->hasExternalFormalLinkage())
1071 return Found->hasExternalFormalLinkage();
1072 if (Importer.GetFromTU(Found) != From->getTranslationUnitDecl())
1073 return false;
1074 if (From->isInAnonymousNamespace())
1075 return Found->isInAnonymousNamespace();
1076 else
1077 return !Found->isInAnonymousNamespace() &&
1078 !Found->hasExternalFormalLinkage();
1079}
1080
1081template <>
1083 TypedefNameDecl *From) {
1084 if (Found->getLinkageInternal() != From->getLinkageInternal())
1085 return false;
1086
1087 if (From->isInAnonymousNamespace() && Found->isInAnonymousNamespace())
1088 return Importer.GetFromTU(Found) == From->getTranslationUnitDecl();
1089 return From->isInAnonymousNamespace() == Found->isInAnonymousNamespace();
1090}
1091
1092} // namespace clang
1093
1094//----------------------------------------------------------------------------
1095// Import Types
1096//----------------------------------------------------------------------------
1097
1098using namespace clang;
1099
1101 Importer.FromDiag(SourceLocation(), diag::err_unsupported_ast_node)
1102 << T->getTypeClassName();
1103 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1104}
1105
1106ExpectedType ASTNodeImporter::VisitAtomicType(const AtomicType *T){
1107 ExpectedType UnderlyingTypeOrErr = import(T->getValueType());
1108 if (!UnderlyingTypeOrErr)
1109 return UnderlyingTypeOrErr.takeError();
1110
1111 return Importer.getToContext().getAtomicType(*UnderlyingTypeOrErr);
1112}
1113
1114ExpectedType ASTNodeImporter::VisitBuiltinType(const BuiltinType *T) {
1115 switch (T->getKind()) {
1116#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1117 case BuiltinType::Id: \
1118 return Importer.getToContext().SingletonId;
1119#include "clang/Basic/OpenCLImageTypes.def"
1120#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1121 case BuiltinType::Id: \
1122 return Importer.getToContext().Id##Ty;
1123#include "clang/Basic/OpenCLExtensionTypes.def"
1124#define SVE_TYPE(Name, Id, SingletonId) \
1125 case BuiltinType::Id: \
1126 return Importer.getToContext().SingletonId;
1127#include "clang/Basic/AArch64SVEACLETypes.def"
1128#define PPC_VECTOR_TYPE(Name, Id, Size) \
1129 case BuiltinType::Id: \
1130 return Importer.getToContext().Id##Ty;
1131#include "clang/Basic/PPCTypes.def"
1132#define RVV_TYPE(Name, Id, SingletonId) \
1133 case BuiltinType::Id: \
1134 return Importer.getToContext().SingletonId;
1135#include "clang/Basic/RISCVVTypes.def"
1136#define WASM_TYPE(Name, Id, SingletonId) \
1137 case BuiltinType::Id: \
1138 return Importer.getToContext().SingletonId;
1139#include "clang/Basic/WebAssemblyReferenceTypes.def"
1140#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
1141 case BuiltinType::Id: \
1142 return Importer.getToContext().SingletonId;
1143#include "clang/Basic/AMDGPUTypes.def"
1144#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1145 case BuiltinType::Id: \
1146 return Importer.getToContext().SingletonId;
1147#include "clang/Basic/HLSLIntangibleTypes.def"
1148#define SHARED_SINGLETON_TYPE(Expansion)
1149#define BUILTIN_TYPE(Id, SingletonId) \
1150 case BuiltinType::Id: return Importer.getToContext().SingletonId;
1151#include "clang/AST/BuiltinTypes.def"
1152
1153 // FIXME: for Char16, Char32, and NullPtr, make sure that the "to"
1154 // context supports C++.
1155
1156 // FIXME: for ObjCId, ObjCClass, and ObjCSel, make sure that the "to"
1157 // context supports ObjC.
1158
1159 case BuiltinType::Char_U:
1160 // The context we're importing from has an unsigned 'char'. If we're
1161 // importing into a context with a signed 'char', translate to
1162 // 'unsigned char' instead.
1163 if (Importer.getToContext().getLangOpts().CharIsSigned)
1164 return Importer.getToContext().UnsignedCharTy;
1165
1166 return Importer.getToContext().CharTy;
1167
1168 case BuiltinType::Char_S:
1169 // The context we're importing from has an unsigned 'char'. If we're
1170 // importing into a context with a signed 'char', translate to
1171 // 'unsigned char' instead.
1172 if (!Importer.getToContext().getLangOpts().CharIsSigned)
1173 return Importer.getToContext().SignedCharTy;
1174
1175 return Importer.getToContext().CharTy;
1176
1177 case BuiltinType::WChar_S:
1178 case BuiltinType::WChar_U:
1179 // FIXME: If not in C++, shall we translate to the C equivalent of
1180 // wchar_t?
1181 return Importer.getToContext().WCharTy;
1182 }
1183
1184 llvm_unreachable("Invalid BuiltinType Kind!");
1185}
1186
1187ExpectedType ASTNodeImporter::VisitDecayedType(const DecayedType *T) {
1188 ExpectedType ToOriginalTypeOrErr = import(T->getOriginalType());
1189 if (!ToOriginalTypeOrErr)
1190 return ToOriginalTypeOrErr.takeError();
1191
1192 return Importer.getToContext().getDecayedType(*ToOriginalTypeOrErr);
1193}
1194
1195ExpectedType ASTNodeImporter::VisitComplexType(const ComplexType *T) {
1196 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1197 if (!ToElementTypeOrErr)
1198 return ToElementTypeOrErr.takeError();
1199
1200 return Importer.getToContext().getComplexType(*ToElementTypeOrErr);
1201}
1202
1203ExpectedType ASTNodeImporter::VisitPointerType(const PointerType *T) {
1204 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1205 if (!ToPointeeTypeOrErr)
1206 return ToPointeeTypeOrErr.takeError();
1207
1208 return Importer.getToContext().getPointerType(*ToPointeeTypeOrErr);
1209}
1210
1211ExpectedType ASTNodeImporter::VisitBlockPointerType(const BlockPointerType *T) {
1212 // FIXME: Check for blocks support in "to" context.
1213 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1214 if (!ToPointeeTypeOrErr)
1215 return ToPointeeTypeOrErr.takeError();
1216
1217 return Importer.getToContext().getBlockPointerType(*ToPointeeTypeOrErr);
1218}
1219
1221ASTNodeImporter::VisitLValueReferenceType(const LValueReferenceType *T) {
1222 // FIXME: Check for C++ support in "to" context.
1223 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1224 if (!ToPointeeTypeOrErr)
1225 return ToPointeeTypeOrErr.takeError();
1226
1227 return Importer.getToContext().getLValueReferenceType(*ToPointeeTypeOrErr);
1228}
1229
1231ASTNodeImporter::VisitRValueReferenceType(const RValueReferenceType *T) {
1232 // FIXME: Check for C++0x support in "to" context.
1233 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeTypeAsWritten());
1234 if (!ToPointeeTypeOrErr)
1235 return ToPointeeTypeOrErr.takeError();
1236
1237 return Importer.getToContext().getRValueReferenceType(*ToPointeeTypeOrErr);
1238}
1239
1241ASTNodeImporter::VisitMemberPointerType(const MemberPointerType *T) {
1242 // FIXME: Check for C++ support in "to" context.
1243 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1244 if (!ToPointeeTypeOrErr)
1245 return ToPointeeTypeOrErr.takeError();
1246
1247 ExpectedTypePtr ClassTypeOrErr = import(T->getClass());
1248 if (!ClassTypeOrErr)
1249 return ClassTypeOrErr.takeError();
1250
1251 return Importer.getToContext().getMemberPointerType(*ToPointeeTypeOrErr,
1252 *ClassTypeOrErr);
1253}
1254
1256ASTNodeImporter::VisitConstantArrayType(const ConstantArrayType *T) {
1257 Error Err = Error::success();
1258 auto ToElementType = importChecked(Err, T->getElementType());
1259 auto ToSizeExpr = importChecked(Err, T->getSizeExpr());
1260 if (Err)
1261 return std::move(Err);
1262
1263 return Importer.getToContext().getConstantArrayType(
1264 ToElementType, T->getSize(), ToSizeExpr, T->getSizeModifier(),
1265 T->getIndexTypeCVRQualifiers());
1266}
1267
1269ASTNodeImporter::VisitArrayParameterType(const ArrayParameterType *T) {
1270 ExpectedType ToArrayTypeOrErr = VisitConstantArrayType(T);
1271 if (!ToArrayTypeOrErr)
1272 return ToArrayTypeOrErr.takeError();
1273
1274 return Importer.getToContext().getArrayParameterType(*ToArrayTypeOrErr);
1275}
1276
1278ASTNodeImporter::VisitIncompleteArrayType(const IncompleteArrayType *T) {
1279 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1280 if (!ToElementTypeOrErr)
1281 return ToElementTypeOrErr.takeError();
1282
1283 return Importer.getToContext().getIncompleteArrayType(*ToElementTypeOrErr,
1284 T->getSizeModifier(),
1285 T->getIndexTypeCVRQualifiers());
1286}
1287
1289ASTNodeImporter::VisitVariableArrayType(const VariableArrayType *T) {
1290 Error Err = Error::success();
1291 QualType ToElementType = importChecked(Err, T->getElementType());
1292 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1293 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1294 if (Err)
1295 return std::move(Err);
1296 return Importer.getToContext().getVariableArrayType(
1297 ToElementType, ToSizeExpr, T->getSizeModifier(),
1298 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1299}
1300
1301ExpectedType ASTNodeImporter::VisitDependentSizedArrayType(
1302 const DependentSizedArrayType *T) {
1303 Error Err = Error::success();
1304 QualType ToElementType = importChecked(Err, T->getElementType());
1305 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1306 SourceRange ToBracketsRange = importChecked(Err, T->getBracketsRange());
1307 if (Err)
1308 return std::move(Err);
1309 // SizeExpr may be null if size is not specified directly.
1310 // For example, 'int a[]'.
1311
1312 return Importer.getToContext().getDependentSizedArrayType(
1313 ToElementType, ToSizeExpr, T->getSizeModifier(),
1314 T->getIndexTypeCVRQualifiers(), ToBracketsRange);
1315}
1316
1317ExpectedType ASTNodeImporter::VisitDependentSizedExtVectorType(
1319 Error Err = Error::success();
1320 QualType ToElementType = importChecked(Err, T->getElementType());
1321 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1322 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1323 if (Err)
1324 return std::move(Err);
1326 ToElementType, ToSizeExpr, ToAttrLoc);
1327}
1328
1329ExpectedType ASTNodeImporter::VisitVectorType(const VectorType *T) {
1330 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1331 if (!ToElementTypeOrErr)
1332 return ToElementTypeOrErr.takeError();
1333
1334 return Importer.getToContext().getVectorType(*ToElementTypeOrErr,
1335 T->getNumElements(),
1336 T->getVectorKind());
1337}
1338
1339ExpectedType ASTNodeImporter::VisitExtVectorType(const ExtVectorType *T) {
1340 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1341 if (!ToElementTypeOrErr)
1342 return ToElementTypeOrErr.takeError();
1343
1344 return Importer.getToContext().getExtVectorType(*ToElementTypeOrErr,
1345 T->getNumElements());
1346}
1347
1349ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
1350 // FIXME: What happens if we're importing a function without a prototype
1351 // into C++? Should we make it variadic?
1352 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1353 if (!ToReturnTypeOrErr)
1354 return ToReturnTypeOrErr.takeError();
1355
1356 return Importer.getToContext().getFunctionNoProtoType(*ToReturnTypeOrErr,
1357 T->getExtInfo());
1358}
1359
1361ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
1362 ExpectedType ToReturnTypeOrErr = import(T->getReturnType());
1363 if (!ToReturnTypeOrErr)
1364 return ToReturnTypeOrErr.takeError();
1365
1366 // Import argument types
1367 SmallVector<QualType, 4> ArgTypes;
1368 for (const auto &A : T->param_types()) {
1369 ExpectedType TyOrErr = import(A);
1370 if (!TyOrErr)
1371 return TyOrErr.takeError();
1372 ArgTypes.push_back(*TyOrErr);
1373 }
1374
1375 // Import exception types
1376 SmallVector<QualType, 4> ExceptionTypes;
1377 for (const auto &E : T->exceptions()) {
1378 ExpectedType TyOrErr = import(E);
1379 if (!TyOrErr)
1380 return TyOrErr.takeError();
1381 ExceptionTypes.push_back(*TyOrErr);
1382 }
1383
1385 Error Err = Error::success();
1387 ToEPI.ExtInfo = FromEPI.ExtInfo;
1388 ToEPI.Variadic = FromEPI.Variadic;
1389 ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
1390 ToEPI.TypeQuals = FromEPI.TypeQuals;
1391 ToEPI.RefQualifier = FromEPI.RefQualifier;
1392 ToEPI.ExceptionSpec.Type = FromEPI.ExceptionSpec.Type;
1399 ToEPI.ExceptionSpec.Exceptions = ExceptionTypes;
1400
1401 if (Err)
1402 return std::move(Err);
1403
1404 return Importer.getToContext().getFunctionType(
1405 *ToReturnTypeOrErr, ArgTypes, ToEPI);
1406}
1407
1408ExpectedType ASTNodeImporter::VisitUnresolvedUsingType(
1409 const UnresolvedUsingType *T) {
1410 Error Err = Error::success();
1411 auto ToD = importChecked(Err, T->getDecl());
1412 auto ToPrevD = importChecked(Err, T->getDecl()->getPreviousDecl());
1413 if (Err)
1414 return std::move(Err);
1415
1416 return Importer.getToContext().getTypeDeclType(
1417 ToD, cast_or_null<TypeDecl>(ToPrevD));
1418}
1419
1420ExpectedType ASTNodeImporter::VisitParenType(const ParenType *T) {
1421 ExpectedType ToInnerTypeOrErr = import(T->getInnerType());
1422 if (!ToInnerTypeOrErr)
1423 return ToInnerTypeOrErr.takeError();
1424
1425 return Importer.getToContext().getParenType(*ToInnerTypeOrErr);
1426}
1427
1429ASTNodeImporter::VisitPackIndexingType(clang::PackIndexingType const *T) {
1430
1431 ExpectedType Pattern = import(T->getPattern());
1432 if (!Pattern)
1433 return Pattern.takeError();
1434 ExpectedExpr Index = import(T->getIndexExpr());
1435 if (!Index)
1436 return Index.takeError();
1437 return Importer.getToContext().getPackIndexingType(*Pattern, *Index);
1438}
1439
1440ExpectedType ASTNodeImporter::VisitTypedefType(const TypedefType *T) {
1441 Expected<TypedefNameDecl *> ToDeclOrErr = import(T->getDecl());
1442 if (!ToDeclOrErr)
1443 return ToDeclOrErr.takeError();
1444
1445 TypedefNameDecl *ToDecl = *ToDeclOrErr;
1446 if (ToDecl->getTypeForDecl())
1447 return QualType(ToDecl->getTypeForDecl(), 0);
1448
1449 ExpectedType ToUnderlyingTypeOrErr = import(T->desugar());
1450 if (!ToUnderlyingTypeOrErr)
1451 return ToUnderlyingTypeOrErr.takeError();
1452
1453 return Importer.getToContext().getTypedefType(ToDecl, *ToUnderlyingTypeOrErr);
1454}
1455
1456ExpectedType ASTNodeImporter::VisitTypeOfExprType(const TypeOfExprType *T) {
1457 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1458 if (!ToExprOrErr)
1459 return ToExprOrErr.takeError();
1460 return Importer.getToContext().getTypeOfExprType(*ToExprOrErr, T->getKind());
1461}
1462
1463ExpectedType ASTNodeImporter::VisitTypeOfType(const TypeOfType *T) {
1464 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnmodifiedType());
1465 if (!ToUnderlyingTypeOrErr)
1466 return ToUnderlyingTypeOrErr.takeError();
1467 return Importer.getToContext().getTypeOfType(*ToUnderlyingTypeOrErr,
1468 T->getKind());
1469}
1470
1471ExpectedType ASTNodeImporter::VisitUsingType(const UsingType *T) {
1472 Expected<UsingShadowDecl *> FoundOrErr = import(T->getFoundDecl());
1473 if (!FoundOrErr)
1474 return FoundOrErr.takeError();
1475 Expected<QualType> UnderlyingOrErr = import(T->getUnderlyingType());
1476 if (!UnderlyingOrErr)
1477 return UnderlyingOrErr.takeError();
1478
1479 return Importer.getToContext().getUsingType(*FoundOrErr, *UnderlyingOrErr);
1480}
1481
1482ExpectedType ASTNodeImporter::VisitDecltypeType(const DecltypeType *T) {
1483 // FIXME: Make sure that the "to" context supports C++0x!
1484 ExpectedExpr ToExprOrErr = import(T->getUnderlyingExpr());
1485 if (!ToExprOrErr)
1486 return ToExprOrErr.takeError();
1487
1488 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1489 if (!ToUnderlyingTypeOrErr)
1490 return ToUnderlyingTypeOrErr.takeError();
1491
1492 return Importer.getToContext().getDecltypeType(
1493 *ToExprOrErr, *ToUnderlyingTypeOrErr);
1494}
1495
1497ASTNodeImporter::VisitUnaryTransformType(const UnaryTransformType *T) {
1498 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1499 if (!ToBaseTypeOrErr)
1500 return ToBaseTypeOrErr.takeError();
1501
1502 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1503 if (!ToUnderlyingTypeOrErr)
1504 return ToUnderlyingTypeOrErr.takeError();
1505
1506 return Importer.getToContext().getUnaryTransformType(
1507 *ToBaseTypeOrErr, *ToUnderlyingTypeOrErr, T->getUTTKind());
1508}
1509
1510ExpectedType ASTNodeImporter::VisitAutoType(const AutoType *T) {
1511 // FIXME: Make sure that the "to" context supports C++11!
1512 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1513 if (!ToDeducedTypeOrErr)
1514 return ToDeducedTypeOrErr.takeError();
1515
1516 ExpectedDecl ToTypeConstraintConcept = import(T->getTypeConstraintConcept());
1517 if (!ToTypeConstraintConcept)
1518 return ToTypeConstraintConcept.takeError();
1519
1520 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1521 if (Error Err = ImportTemplateArguments(T->getTypeConstraintArguments(),
1522 ToTemplateArgs))
1523 return std::move(Err);
1524
1525 return Importer.getToContext().getAutoType(
1526 *ToDeducedTypeOrErr, T->getKeyword(), /*IsDependent*/false,
1527 /*IsPack=*/false, cast_or_null<ConceptDecl>(*ToTypeConstraintConcept),
1528 ToTemplateArgs);
1529}
1530
1531ExpectedType ASTNodeImporter::VisitDeducedTemplateSpecializationType(
1533 // FIXME: Make sure that the "to" context supports C++17!
1534 Expected<TemplateName> ToTemplateNameOrErr = import(T->getTemplateName());
1535 if (!ToTemplateNameOrErr)
1536 return ToTemplateNameOrErr.takeError();
1537 ExpectedType ToDeducedTypeOrErr = import(T->getDeducedType());
1538 if (!ToDeducedTypeOrErr)
1539 return ToDeducedTypeOrErr.takeError();
1540
1542 *ToTemplateNameOrErr, *ToDeducedTypeOrErr, T->isDependentType());
1543}
1544
1545ExpectedType ASTNodeImporter::VisitInjectedClassNameType(
1546 const InjectedClassNameType *T) {
1547 Expected<CXXRecordDecl *> ToDeclOrErr = import(T->getDecl());
1548 if (!ToDeclOrErr)
1549 return ToDeclOrErr.takeError();
1550
1551 // The InjectedClassNameType is created in VisitRecordDecl when the
1552 // T->getDecl() is imported. Here we can return the existing type.
1553 const Type *Ty = (*ToDeclOrErr)->getTypeForDecl();
1554 assert(isa_and_nonnull<InjectedClassNameType>(Ty));
1555 return QualType(Ty, 0);
1556}
1557
1558ExpectedType ASTNodeImporter::VisitRecordType(const RecordType *T) {
1559 Expected<RecordDecl *> ToDeclOrErr = import(T->getDecl());
1560 if (!ToDeclOrErr)
1561 return ToDeclOrErr.takeError();
1562
1563 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1564}
1565
1566ExpectedType ASTNodeImporter::VisitEnumType(const EnumType *T) {
1567 Expected<EnumDecl *> ToDeclOrErr = import(T->getDecl());
1568 if (!ToDeclOrErr)
1569 return ToDeclOrErr.takeError();
1570
1571 return Importer.getToContext().getTagDeclType(*ToDeclOrErr);
1572}
1573
1574ExpectedType ASTNodeImporter::VisitAttributedType(const AttributedType *T) {
1575 ExpectedType ToModifiedTypeOrErr = import(T->getModifiedType());
1576 if (!ToModifiedTypeOrErr)
1577 return ToModifiedTypeOrErr.takeError();
1578 ExpectedType ToEquivalentTypeOrErr = import(T->getEquivalentType());
1579 if (!ToEquivalentTypeOrErr)
1580 return ToEquivalentTypeOrErr.takeError();
1581
1582 return Importer.getToContext().getAttributedType(
1583 T->getAttrKind(), *ToModifiedTypeOrErr, *ToEquivalentTypeOrErr,
1584 T->getAttr());
1585}
1586
1588ASTNodeImporter::VisitCountAttributedType(const CountAttributedType *T) {
1589 ExpectedType ToWrappedTypeOrErr = import(T->desugar());
1590 if (!ToWrappedTypeOrErr)
1591 return ToWrappedTypeOrErr.takeError();
1592
1593 Error Err = Error::success();
1594 Expr *CountExpr = importChecked(Err, T->getCountExpr());
1595
1597 for (const TypeCoupledDeclRefInfo &TI : T->dependent_decls()) {
1598 Expected<ValueDecl *> ToDeclOrErr = import(TI.getDecl());
1599 if (!ToDeclOrErr)
1600 return ToDeclOrErr.takeError();
1601 CoupledDecls.emplace_back(*ToDeclOrErr, TI.isDeref());
1602 }
1603
1604 return Importer.getToContext().getCountAttributedType(
1605 *ToWrappedTypeOrErr, CountExpr, T->isCountInBytes(), T->isOrNull(),
1606 ArrayRef(CoupledDecls.data(), CoupledDecls.size()));
1607}
1608
1609ExpectedType ASTNodeImporter::VisitTemplateTypeParmType(
1610 const TemplateTypeParmType *T) {
1611 Expected<TemplateTypeParmDecl *> ToDeclOrErr = import(T->getDecl());
1612 if (!ToDeclOrErr)
1613 return ToDeclOrErr.takeError();
1614
1615 return Importer.getToContext().getTemplateTypeParmType(
1616 T->getDepth(), T->getIndex(), T->isParameterPack(), *ToDeclOrErr);
1617}
1618
1619ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmType(
1621 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1622 if (!ReplacedOrErr)
1623 return ReplacedOrErr.takeError();
1624
1625 ExpectedType ToReplacementTypeOrErr = import(T->getReplacementType());
1626 if (!ToReplacementTypeOrErr)
1627 return ToReplacementTypeOrErr.takeError();
1628
1630 *ToReplacementTypeOrErr, *ReplacedOrErr, T->getIndex(), T->getPackIndex(),
1631 T->getSubstitutionFlag());
1632}
1633
1634ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
1636 Expected<Decl *> ReplacedOrErr = import(T->getAssociatedDecl());
1637 if (!ReplacedOrErr)
1638 return ReplacedOrErr.takeError();
1639
1640 Expected<TemplateArgument> ToArgumentPack = import(T->getArgumentPack());
1641 if (!ToArgumentPack)
1642 return ToArgumentPack.takeError();
1643
1645 *ReplacedOrErr, T->getIndex(), T->getFinal(), *ToArgumentPack);
1646}
1647
1648ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
1650 auto ToTemplateOrErr = import(T->getTemplateName());
1651 if (!ToTemplateOrErr)
1652 return ToTemplateOrErr.takeError();
1653
1654 SmallVector<TemplateArgument, 2> ToTemplateArgs;
1655 if (Error Err =
1656 ImportTemplateArguments(T->template_arguments(), ToTemplateArgs))
1657 return std::move(Err);
1658
1659 QualType ToCanonType;
1660 if (!T->isCanonicalUnqualified()) {
1661 QualType FromCanonType
1662 = Importer.getFromContext().getCanonicalType(QualType(T, 0));
1663 if (ExpectedType TyOrErr = import(FromCanonType))
1664 ToCanonType = *TyOrErr;
1665 else
1666 return TyOrErr.takeError();
1667 }
1668 return Importer.getToContext().getTemplateSpecializationType(*ToTemplateOrErr,
1669 ToTemplateArgs,
1670 ToCanonType);
1671}
1672
1673ExpectedType ASTNodeImporter::VisitElaboratedType(const ElaboratedType *T) {
1674 // Note: the qualifier in an ElaboratedType is optional.
1675 auto ToQualifierOrErr = import(T->getQualifier());
1676 if (!ToQualifierOrErr)
1677 return ToQualifierOrErr.takeError();
1678
1679 ExpectedType ToNamedTypeOrErr = import(T->getNamedType());
1680 if (!ToNamedTypeOrErr)
1681 return ToNamedTypeOrErr.takeError();
1682
1683 Expected<TagDecl *> ToOwnedTagDeclOrErr = import(T->getOwnedTagDecl());
1684 if (!ToOwnedTagDeclOrErr)
1685 return ToOwnedTagDeclOrErr.takeError();
1686
1687 return Importer.getToContext().getElaboratedType(T->getKeyword(),
1688 *ToQualifierOrErr,
1689 *ToNamedTypeOrErr,
1690 *ToOwnedTagDeclOrErr);
1691}
1692
1694ASTNodeImporter::VisitPackExpansionType(const PackExpansionType *T) {
1695 ExpectedType ToPatternOrErr = import(T->getPattern());
1696 if (!ToPatternOrErr)
1697 return ToPatternOrErr.takeError();
1698
1699 return Importer.getToContext().getPackExpansionType(*ToPatternOrErr,
1700 T->getNumExpansions(),
1701 /*ExpactPack=*/false);
1702}
1703
1704ExpectedType ASTNodeImporter::VisitDependentTemplateSpecializationType(
1706 auto ToQualifierOrErr = import(T->getQualifier());
1707 if (!ToQualifierOrErr)
1708 return ToQualifierOrErr.takeError();
1709
1710 IdentifierInfo *ToName = Importer.Import(T->getIdentifier());
1711
1713 ToPack.reserve(T->template_arguments().size());
1714 if (Error Err = ImportTemplateArguments(T->template_arguments(), ToPack))
1715 return std::move(Err);
1716
1718 T->getKeyword(), *ToQualifierOrErr, ToName, ToPack);
1719}
1720
1722ASTNodeImporter::VisitDependentNameType(const DependentNameType *T) {
1723 auto ToQualifierOrErr = import(T->getQualifier());
1724 if (!ToQualifierOrErr)
1725 return ToQualifierOrErr.takeError();
1726
1727 IdentifierInfo *Name = Importer.Import(T->getIdentifier());
1728
1729 QualType Canon;
1730 if (T != T->getCanonicalTypeInternal().getTypePtr()) {
1731 if (ExpectedType TyOrErr = import(T->getCanonicalTypeInternal()))
1732 Canon = (*TyOrErr).getCanonicalType();
1733 else
1734 return TyOrErr.takeError();
1735 }
1736
1737 return Importer.getToContext().getDependentNameType(T->getKeyword(),
1738 *ToQualifierOrErr,
1739 Name, Canon);
1740}
1741
1743ASTNodeImporter::VisitObjCInterfaceType(const ObjCInterfaceType *T) {
1744 Expected<ObjCInterfaceDecl *> ToDeclOrErr = import(T->getDecl());
1745 if (!ToDeclOrErr)
1746 return ToDeclOrErr.takeError();
1747
1748 return Importer.getToContext().getObjCInterfaceType(*ToDeclOrErr);
1749}
1750
1751ExpectedType ASTNodeImporter::VisitObjCObjectType(const ObjCObjectType *T) {
1752 ExpectedType ToBaseTypeOrErr = import(T->getBaseType());
1753 if (!ToBaseTypeOrErr)
1754 return ToBaseTypeOrErr.takeError();
1755
1756 SmallVector<QualType, 4> TypeArgs;
1757 for (auto TypeArg : T->getTypeArgsAsWritten()) {
1758 if (ExpectedType TyOrErr = import(TypeArg))
1759 TypeArgs.push_back(*TyOrErr);
1760 else
1761 return TyOrErr.takeError();
1762 }
1763
1765 for (auto *P : T->quals()) {
1766 if (Expected<ObjCProtocolDecl *> ProtocolOrErr = import(P))
1767 Protocols.push_back(*ProtocolOrErr);
1768 else
1769 return ProtocolOrErr.takeError();
1770
1771 }
1772
1773 return Importer.getToContext().getObjCObjectType(*ToBaseTypeOrErr, TypeArgs,
1774 Protocols,
1775 T->isKindOfTypeAsWritten());
1776}
1777
1779ASTNodeImporter::VisitObjCObjectPointerType(const ObjCObjectPointerType *T) {
1780 ExpectedType ToPointeeTypeOrErr = import(T->getPointeeType());
1781 if (!ToPointeeTypeOrErr)
1782 return ToPointeeTypeOrErr.takeError();
1783
1784 return Importer.getToContext().getObjCObjectPointerType(*ToPointeeTypeOrErr);
1785}
1786
1788ASTNodeImporter::VisitMacroQualifiedType(const MacroQualifiedType *T) {
1789 ExpectedType ToUnderlyingTypeOrErr = import(T->getUnderlyingType());
1790 if (!ToUnderlyingTypeOrErr)
1791 return ToUnderlyingTypeOrErr.takeError();
1792
1793 IdentifierInfo *ToIdentifier = Importer.Import(T->getMacroIdentifier());
1794 return Importer.getToContext().getMacroQualifiedType(*ToUnderlyingTypeOrErr,
1795 ToIdentifier);
1796}
1797
1798ExpectedType clang::ASTNodeImporter::VisitAdjustedType(const AdjustedType *T) {
1799 Error Err = Error::success();
1800 QualType ToOriginalType = importChecked(Err, T->getOriginalType());
1801 QualType ToAdjustedType = importChecked(Err, T->getAdjustedType());
1802 if (Err)
1803 return std::move(Err);
1804
1805 return Importer.getToContext().getAdjustedType(ToOriginalType,
1806 ToAdjustedType);
1807}
1808
1809ExpectedType clang::ASTNodeImporter::VisitBitIntType(const BitIntType *T) {
1810 return Importer.getToContext().getBitIntType(T->isUnsigned(),
1811 T->getNumBits());
1812}
1813
1814ExpectedType clang::ASTNodeImporter::VisitBTFTagAttributedType(
1816 Error Err = Error::success();
1817 const BTFTypeTagAttr *ToBTFAttr = importChecked(Err, T->getAttr());
1818 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1819 if (Err)
1820 return std::move(Err);
1821
1822 return Importer.getToContext().getBTFTagAttributedType(ToBTFAttr,
1823 ToWrappedType);
1824}
1825
1826ExpectedType clang::ASTNodeImporter::VisitHLSLAttributedResourceType(
1828 Error Err = Error::success();
1829 const HLSLAttributedResourceType::Attributes &ToAttrs = T->getAttrs();
1830 QualType ToWrappedType = importChecked(Err, T->getWrappedType());
1831 QualType ToContainedType = importChecked(Err, T->getContainedType());
1832 if (Err)
1833 return std::move(Err);
1834
1835 return Importer.getToContext().getHLSLAttributedResourceType(
1836 ToWrappedType, ToContainedType, ToAttrs);
1837}
1838
1839ExpectedType clang::ASTNodeImporter::VisitConstantMatrixType(
1841 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1842 if (!ToElementTypeOrErr)
1843 return ToElementTypeOrErr.takeError();
1844
1845 return Importer.getToContext().getConstantMatrixType(
1846 *ToElementTypeOrErr, T->getNumRows(), T->getNumColumns());
1847}
1848
1849ExpectedType clang::ASTNodeImporter::VisitDependentAddressSpaceType(
1851 Error Err = Error::success();
1852 QualType ToPointeeType = importChecked(Err, T->getPointeeType());
1853 Expr *ToAddrSpaceExpr = importChecked(Err, T->getAddrSpaceExpr());
1854 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1855 if (Err)
1856 return std::move(Err);
1857
1858 return Importer.getToContext().getDependentAddressSpaceType(
1859 ToPointeeType, ToAddrSpaceExpr, ToAttrLoc);
1860}
1861
1862ExpectedType clang::ASTNodeImporter::VisitDependentBitIntType(
1864 ExpectedExpr ToNumBitsExprOrErr = import(T->getNumBitsExpr());
1865 if (!ToNumBitsExprOrErr)
1866 return ToNumBitsExprOrErr.takeError();
1867 return Importer.getToContext().getDependentBitIntType(T->isUnsigned(),
1868 *ToNumBitsExprOrErr);
1869}
1870
1871ExpectedType clang::ASTNodeImporter::VisitDependentSizedMatrixType(
1873 Error Err = Error::success();
1874 QualType ToElementType = importChecked(Err, T->getElementType());
1875 Expr *ToRowExpr = importChecked(Err, T->getRowExpr());
1876 Expr *ToColumnExpr = importChecked(Err, T->getColumnExpr());
1877 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1878 if (Err)
1879 return std::move(Err);
1880
1881 return Importer.getToContext().getDependentSizedMatrixType(
1882 ToElementType, ToRowExpr, ToColumnExpr, ToAttrLoc);
1883}
1884
1885ExpectedType clang::ASTNodeImporter::VisitDependentVectorType(
1887 Error Err = Error::success();
1888 QualType ToElementType = importChecked(Err, T->getElementType());
1889 Expr *ToSizeExpr = importChecked(Err, T->getSizeExpr());
1890 SourceLocation ToAttrLoc = importChecked(Err, T->getAttributeLoc());
1891 if (Err)
1892 return std::move(Err);
1893
1894 return Importer.getToContext().getDependentVectorType(
1895 ToElementType, ToSizeExpr, ToAttrLoc, T->getVectorKind());
1896}
1897
1898ExpectedType clang::ASTNodeImporter::VisitObjCTypeParamType(
1899 const clang::ObjCTypeParamType *T) {
1900 Expected<ObjCTypeParamDecl *> ToDeclOrErr = import(T->getDecl());
1901 if (!ToDeclOrErr)
1902 return ToDeclOrErr.takeError();
1903
1905 for (ObjCProtocolDecl *FromProtocol : T->getProtocols()) {
1906 Expected<ObjCProtocolDecl *> ToProtocolOrErr = import(FromProtocol);
1907 if (!ToProtocolOrErr)
1908 return ToProtocolOrErr.takeError();
1909 ToProtocols.push_back(*ToProtocolOrErr);
1910 }
1911
1912 return Importer.getToContext().getObjCTypeParamType(*ToDeclOrErr,
1913 ToProtocols);
1914}
1915
1916ExpectedType clang::ASTNodeImporter::VisitPipeType(const clang::PipeType *T) {
1917 ExpectedType ToElementTypeOrErr = import(T->getElementType());
1918 if (!ToElementTypeOrErr)
1919 return ToElementTypeOrErr.takeError();
1920
1921 ASTContext &ToCtx = Importer.getToContext();
1922 if (T->isReadOnly())
1923 return ToCtx.getReadPipeType(*ToElementTypeOrErr);
1924 else
1925 return ToCtx.getWritePipeType(*ToElementTypeOrErr);
1926}
1927
1928//----------------------------------------------------------------------------
1929// Import Declarations
1930//----------------------------------------------------------------------------
1932 NamedDecl *D, DeclContext *&DC, DeclContext *&LexicalDC,
1934 // Check if RecordDecl is in FunctionDecl parameters to avoid infinite loop.
1935 // example: int struct_in_proto(struct data_t{int a;int b;} *d);
1936 // FIXME: We could support these constructs by importing a different type of
1937 // this parameter and by importing the original type of the parameter only
1938 // after the FunctionDecl is created. See
1939 // VisitFunctionDecl::UsedDifferentProtoType.
1940 DeclContext *OrigDC = D->getDeclContext();
1941 FunctionDecl *FunDecl;
1942 if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
1943 FunDecl->hasBody()) {
1944 auto getLeafPointeeType = [](const Type *T) {
1945 while (T->isPointerType() || T->isArrayType()) {
1947 }
1948 return T;
1949 };
1950 for (const ParmVarDecl *P : FunDecl->parameters()) {
1951 const Type *LeafT =
1952 getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
1953 auto *RT = dyn_cast<RecordType>(LeafT);
1954 if (RT && RT->getDecl() == D) {
1955 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
1956 << D->getDeclKindName();
1957 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
1958 }
1959 }
1960 }
1961
1962 // Import the context of this declaration.
1963 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
1964 return Err;
1965
1966 // Import the name of this declaration.
1967 if (Error Err = importInto(Name, D->getDeclName()))
1968 return Err;
1969
1970 // Import the location of this declaration.
1971 if (Error Err = importInto(Loc, D->getLocation()))
1972 return Err;
1973
1974 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1975 if (ToD)
1976 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1977 return Err;
1978
1979 return Error::success();
1980}
1981
1983 NamedDecl *&ToD, SourceLocation &Loc) {
1984
1985 // Import the name of this declaration.
1986 if (Error Err = importInto(Name, D->getDeclName()))
1987 return Err;
1988
1989 // Import the location of this declaration.
1990 if (Error Err = importInto(Loc, D->getLocation()))
1991 return Err;
1992
1993 ToD = cast_or_null<NamedDecl>(Importer.GetAlreadyImportedOrNull(D));
1994 if (ToD)
1995 if (Error Err = ASTNodeImporter(*this).ImportDefinitionIfNeeded(D, ToD))
1996 return Err;
1997
1998 return Error::success();
1999}
2000
2002 if (!FromD)
2003 return Error::success();
2004
2005 if (!ToD)
2006 if (Error Err = importInto(ToD, FromD))
2007 return Err;
2008
2009 if (RecordDecl *FromRecord = dyn_cast<RecordDecl>(FromD)) {
2010 if (RecordDecl *ToRecord = cast<RecordDecl>(ToD)) {
2011 if (FromRecord->getDefinition() && FromRecord->isCompleteDefinition() &&
2012 !ToRecord->getDefinition()) {
2013 if (Error Err = ImportDefinition(FromRecord, ToRecord))
2014 return Err;
2015 }
2016 }
2017 return Error::success();
2018 }
2019
2020 if (EnumDecl *FromEnum = dyn_cast<EnumDecl>(FromD)) {
2021 if (EnumDecl *ToEnum = cast<EnumDecl>(ToD)) {
2022 if (FromEnum->getDefinition() && !ToEnum->getDefinition()) {
2023 if (Error Err = ImportDefinition(FromEnum, ToEnum))
2024 return Err;
2025 }
2026 }
2027 return Error::success();
2028 }
2029
2030 return Error::success();
2031}
2032
2033Error
2035 const DeclarationNameInfo &From, DeclarationNameInfo& To) {
2036 // NOTE: To.Name and To.Loc are already imported.
2037 // We only have to import To.LocInfo.
2038 switch (To.getName().getNameKind()) {
2045 return Error::success();
2046
2048 if (auto ToRangeOrErr = import(From.getCXXOperatorNameRange()))
2049 To.setCXXOperatorNameRange(*ToRangeOrErr);
2050 else
2051 return ToRangeOrErr.takeError();
2052 return Error::success();
2053 }
2055 if (ExpectedSLoc LocOrErr = import(From.getCXXLiteralOperatorNameLoc()))
2056 To.setCXXLiteralOperatorNameLoc(*LocOrErr);
2057 else
2058 return LocOrErr.takeError();
2059 return Error::success();
2060 }
2064 if (auto ToTInfoOrErr = import(From.getNamedTypeInfo()))
2065 To.setNamedTypeInfo(*ToTInfoOrErr);
2066 else
2067 return ToTInfoOrErr.takeError();
2068 return Error::success();
2069 }
2070 }
2071 llvm_unreachable("Unknown name kind.");
2072}
2073
2074Error
2076 if (Importer.isMinimalImport() && !ForceImport) {
2077 auto ToDCOrErr = Importer.ImportContext(FromDC);
2078 return ToDCOrErr.takeError();
2079 }
2080
2081 // We use strict error handling in case of records and enums, but not
2082 // with e.g. namespaces.
2083 //
2084 // FIXME Clients of the ASTImporter should be able to choose an
2085 // appropriate error handling strategy for their needs. For instance,
2086 // they may not want to mark an entire namespace as erroneous merely
2087 // because there is an ODR error with two typedefs. As another example,
2088 // the client may allow EnumConstantDecls with same names but with
2089 // different values in two distinct translation units.
2090 ChildErrorHandlingStrategy HandleChildErrors(FromDC);
2091
2092 auto MightNeedReordering = [](const Decl *D) {
2093 return isa<FieldDecl>(D) || isa<IndirectFieldDecl>(D) || isa<FriendDecl>(D);
2094 };
2095
2096 // Import everything that might need reordering first.
2097 Error ChildErrors = Error::success();
2098 for (auto *From : FromDC->decls()) {
2099 if (!MightNeedReordering(From))
2100 continue;
2101
2102 ExpectedDecl ImportedOrErr = import(From);
2103
2104 // If we are in the process of ImportDefinition(...) for a RecordDecl we
2105 // want to make sure that we are also completing each FieldDecl. There
2106 // are currently cases where this does not happen and this is correctness
2107 // fix since operations such as code generation will expect this to be so.
2108 if (!ImportedOrErr) {
2109 HandleChildErrors.handleChildImportResult(ChildErrors,
2110 ImportedOrErr.takeError());
2111 continue;
2112 }
2113 FieldDecl *FieldFrom = dyn_cast_or_null<FieldDecl>(From);
2114 Decl *ImportedDecl = *ImportedOrErr;
2115 FieldDecl *FieldTo = dyn_cast_or_null<FieldDecl>(ImportedDecl);
2116 if (FieldFrom && FieldTo) {
2117 Error Err = ImportFieldDeclDefinition(FieldFrom, FieldTo);
2118 HandleChildErrors.handleChildImportResult(ChildErrors, std::move(Err));
2119 }
2120 }
2121
2122 // We reorder declarations in RecordDecls because they may have another order
2123 // in the "to" context than they have in the "from" context. This may happen
2124 // e.g when we import a class like this:
2125 // struct declToImport {
2126 // int a = c + b;
2127 // int b = 1;
2128 // int c = 2;
2129 // };
2130 // During the import of `a` we import first the dependencies in sequence,
2131 // thus the order would be `c`, `b`, `a`. We will get the normal order by
2132 // first removing the already imported members and then adding them in the
2133 // order as they appear in the "from" context.
2134 //
2135 // Keeping field order is vital because it determines structure layout.
2136 //
2137 // Here and below, we cannot call field_begin() method and its callers on
2138 // ToDC if it has an external storage. Calling field_begin() will
2139 // automatically load all the fields by calling
2140 // LoadFieldsFromExternalStorage(). LoadFieldsFromExternalStorage() would
2141 // call ASTImporter::Import(). This is because the ExternalASTSource
2142 // interface in LLDB is implemented by the means of the ASTImporter. However,
2143 // calling an import at this point would result in an uncontrolled import, we
2144 // must avoid that.
2145
2146 auto ToDCOrErr = Importer.ImportContext(FromDC);
2147 if (!ToDCOrErr) {
2148 consumeError(std::move(ChildErrors));
2149 return ToDCOrErr.takeError();
2150 }
2151
2152 if (const auto *FromRD = dyn_cast<RecordDecl>(FromDC)) {
2153 DeclContext *ToDC = *ToDCOrErr;
2154 // Remove all declarations, which may be in wrong order in the
2155 // lexical DeclContext and then add them in the proper order.
2156 for (auto *D : FromRD->decls()) {
2157 if (!MightNeedReordering(D))
2158 continue;
2159
2160 assert(D && "DC contains a null decl");
2161 if (Decl *ToD = Importer.GetAlreadyImportedOrNull(D)) {
2162 // Remove only the decls which we successfully imported.
2163 assert(ToDC == ToD->getLexicalDeclContext() && ToDC->containsDecl(ToD));
2164 // Remove the decl from its wrong place in the linked list.
2165 ToDC->removeDecl(ToD);
2166 // Add the decl to the end of the linked list.
2167 // This time it will be at the proper place because the enclosing for
2168 // loop iterates in the original (good) order of the decls.
2169 ToDC->addDeclInternal(ToD);
2170 }
2171 }
2172 }
2173
2174 // Import everything else.
2175 for (auto *From : FromDC->decls()) {
2176 if (MightNeedReordering(From))
2177 continue;
2178
2179 ExpectedDecl ImportedOrErr = import(From);
2180 if (!ImportedOrErr)
2181 HandleChildErrors.handleChildImportResult(ChildErrors,
2182 ImportedOrErr.takeError());
2183 }
2184
2185 return ChildErrors;
2186}
2187
2189 const FieldDecl *To) {
2190 RecordDecl *FromRecordDecl = nullptr;
2191 RecordDecl *ToRecordDecl = nullptr;
2192 // If we have a field that is an ArrayType we need to check if the array
2193 // element is a RecordDecl and if so we need to import the definition.
2194 QualType FromType = From->getType();
2195 QualType ToType = To->getType();
2196 if (FromType->isArrayType()) {
2197 // getBaseElementTypeUnsafe(...) handles multi-dimensonal arrays for us.
2198 FromRecordDecl = FromType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2199 ToRecordDecl = ToType->getBaseElementTypeUnsafe()->getAsRecordDecl();
2200 }
2201
2202 if (!FromRecordDecl || !ToRecordDecl) {
2203 const RecordType *RecordFrom = FromType->getAs<RecordType>();
2204 const RecordType *RecordTo = ToType->getAs<RecordType>();
2205
2206 if (RecordFrom && RecordTo) {
2207 FromRecordDecl = RecordFrom->getDecl();
2208 ToRecordDecl = RecordTo->getDecl();
2209 }
2210 }
2211
2212 if (FromRecordDecl && ToRecordDecl) {
2213 if (FromRecordDecl->isCompleteDefinition() &&
2214 !ToRecordDecl->isCompleteDefinition())
2215 return ImportDefinition(FromRecordDecl, ToRecordDecl);
2216 }
2217
2218 return Error::success();
2219}
2220
2222 Decl *FromD, DeclContext *&ToDC, DeclContext *&ToLexicalDC) {
2223 auto ToDCOrErr = Importer.ImportContext(FromD->getDeclContext());
2224 if (!ToDCOrErr)
2225 return ToDCOrErr.takeError();
2226 ToDC = *ToDCOrErr;
2227
2228 if (FromD->getDeclContext() != FromD->getLexicalDeclContext()) {
2229 auto ToLexicalDCOrErr = Importer.ImportContext(
2230 FromD->getLexicalDeclContext());
2231 if (!ToLexicalDCOrErr)
2232 return ToLexicalDCOrErr.takeError();
2233 ToLexicalDC = *ToLexicalDCOrErr;
2234 } else
2235 ToLexicalDC = ToDC;
2236
2237 return Error::success();
2238}
2239
2241 const CXXRecordDecl *From, CXXRecordDecl *To) {
2242 assert(From->isCompleteDefinition() && To->getDefinition() == To &&
2243 "Import implicit methods to or from non-definition");
2244
2245 for (CXXMethodDecl *FromM : From->methods())
2246 if (FromM->isImplicit()) {
2247 Expected<CXXMethodDecl *> ToMOrErr = import(FromM);
2248 if (!ToMOrErr)
2249 return ToMOrErr.takeError();
2250 }
2251
2252 return Error::success();
2253}
2254
2256 ASTImporter &Importer) {
2257 if (TypedefNameDecl *FromTypedef = From->getTypedefNameForAnonDecl()) {
2258 if (ExpectedDecl ToTypedefOrErr = Importer.Import(FromTypedef))
2259 To->setTypedefNameForAnonDecl(cast<TypedefNameDecl>(*ToTypedefOrErr));
2260 else
2261 return ToTypedefOrErr.takeError();
2262 }
2263 return Error::success();
2264}
2265
2267 RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind) {
2268 auto DefinitionCompleter = [To]() {
2269 // There are cases in LLDB when we first import a class without its
2270 // members. The class will have DefinitionData, but no members. Then,
2271 // importDefinition is called from LLDB, which tries to get the members, so
2272 // when we get here, the class already has the DefinitionData set, so we
2273 // must unset the CompleteDefinition here to be able to complete again the
2274 // definition.
2275 To->setCompleteDefinition(false);
2276 To->completeDefinition();
2277 };
2278
2279 if (To->getDefinition() || To->isBeingDefined()) {
2280 if (Kind == IDK_Everything ||
2281 // In case of lambdas, the class already has a definition ptr set, but
2282 // the contained decls are not imported yet. Also, isBeingDefined was
2283 // set in CXXRecordDecl::CreateLambda. We must import the contained
2284 // decls here and finish the definition.
2285 (To->isLambda() && shouldForceImportDeclContext(Kind))) {
2286 if (To->isLambda()) {
2287 auto *FromCXXRD = cast<CXXRecordDecl>(From);
2289 ToCaptures.reserve(FromCXXRD->capture_size());
2290 for (const auto &FromCapture : FromCXXRD->captures()) {
2291 if (auto ToCaptureOrErr = import(FromCapture))
2292 ToCaptures.push_back(*ToCaptureOrErr);
2293 else
2294 return ToCaptureOrErr.takeError();
2295 }
2296 cast<CXXRecordDecl>(To)->setCaptures(Importer.getToContext(),
2297 ToCaptures);
2298 }
2299
2300 Error Result = ImportDeclContext(From, /*ForceImport=*/true);
2301 // Finish the definition of the lambda, set isBeingDefined to false.
2302 if (To->isLambda())
2303 DefinitionCompleter();
2304 return Result;
2305 }
2306
2307 return Error::success();
2308 }
2309
2310 To->startDefinition();
2311 // Set the definition to complete even if it is really not complete during
2312 // import. Some AST constructs (expressions) require the record layout
2313 // to be calculated (see 'clang::computeDependence') at the time they are
2314 // constructed. Import of such AST node is possible during import of the
2315 // same record, there is no way to have a completely defined record (all
2316 // fields imported) at that time without multiple AST import passes.
2317 if (!Importer.isMinimalImport())
2318 To->setCompleteDefinition(true);
2319 // Complete the definition even if error is returned.
2320 // The RecordDecl may be already part of the AST so it is better to
2321 // have it in complete state even if something is wrong with it.
2322 auto DefinitionCompleterScopeExit =
2323 llvm::make_scope_exit(DefinitionCompleter);
2324
2325 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2326 return Err;
2327
2328 // Add base classes.
2329 auto *ToCXX = dyn_cast<CXXRecordDecl>(To);
2330 auto *FromCXX = dyn_cast<CXXRecordDecl>(From);
2331 if (ToCXX && FromCXX && ToCXX->dataPtr() && FromCXX->dataPtr()) {
2332
2333 struct CXXRecordDecl::DefinitionData &ToData = ToCXX->data();
2334 struct CXXRecordDecl::DefinitionData &FromData = FromCXX->data();
2335
2336 #define FIELD(Name, Width, Merge) \
2337 ToData.Name = FromData.Name;
2338 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
2339
2340 // Copy over the data stored in RecordDeclBits
2341 ToCXX->setArgPassingRestrictions(FromCXX->getArgPassingRestrictions());
2342
2344 for (const auto &Base1 : FromCXX->bases()) {
2345 ExpectedType TyOrErr = import(Base1.getType());
2346 if (!TyOrErr)
2347 return TyOrErr.takeError();
2348
2349 SourceLocation EllipsisLoc;
2350 if (Base1.isPackExpansion()) {
2351 if (ExpectedSLoc LocOrErr = import(Base1.getEllipsisLoc()))
2352 EllipsisLoc = *LocOrErr;
2353 else
2354 return LocOrErr.takeError();
2355 }
2356
2357 // Ensure that we have a definition for the base.
2358 if (Error Err =
2359 ImportDefinitionIfNeeded(Base1.getType()->getAsCXXRecordDecl()))
2360 return Err;
2361
2362 auto RangeOrErr = import(Base1.getSourceRange());
2363 if (!RangeOrErr)
2364 return RangeOrErr.takeError();
2365
2366 auto TSIOrErr = import(Base1.getTypeSourceInfo());
2367 if (!TSIOrErr)
2368 return TSIOrErr.takeError();
2369
2370 Bases.push_back(
2371 new (Importer.getToContext()) CXXBaseSpecifier(
2372 *RangeOrErr,
2373 Base1.isVirtual(),
2374 Base1.isBaseOfClass(),
2375 Base1.getAccessSpecifierAsWritten(),
2376 *TSIOrErr,
2377 EllipsisLoc));
2378 }
2379 if (!Bases.empty())
2380 ToCXX->setBases(Bases.data(), Bases.size());
2381 }
2382
2384 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2385 return Err;
2386 }
2387
2388 return Error::success();
2389}
2390
2392 if (To->getAnyInitializer())
2393 return Error::success();
2394
2395 Expr *FromInit = From->getInit();
2396 if (!FromInit)
2397 return Error::success();
2398
2399 ExpectedExpr ToInitOrErr = import(FromInit);
2400 if (!ToInitOrErr)
2401 return ToInitOrErr.takeError();
2402
2403 To->setInit(*ToInitOrErr);
2404 if (EvaluatedStmt *FromEval = From->getEvaluatedStmt()) {
2405 EvaluatedStmt *ToEval = To->ensureEvaluatedStmt();
2406 ToEval->HasConstantInitialization = FromEval->HasConstantInitialization;
2407 ToEval->HasConstantDestruction = FromEval->HasConstantDestruction;
2408 // FIXME: Also import the initializer value.
2409 }
2410
2411 // FIXME: Other bits to merge?
2412 return Error::success();
2413}
2414
2417 if (To->getDefinition() || To->isBeingDefined()) {
2418 if (Kind == IDK_Everything)
2419 return ImportDeclContext(From, /*ForceImport=*/true);
2420 return Error::success();
2421 }
2422
2423 To->startDefinition();
2424
2425 if (Error Err = setTypedefNameForAnonDecl(From, To, Importer))
2426 return Err;
2427
2428 ExpectedType ToTypeOrErr =
2429 import(Importer.getFromContext().getTypeDeclType(From));
2430 if (!ToTypeOrErr)
2431 return ToTypeOrErr.takeError();
2432
2433 ExpectedType ToPromotionTypeOrErr = import(From->getPromotionType());
2434 if (!ToPromotionTypeOrErr)
2435 return ToPromotionTypeOrErr.takeError();
2436
2438 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
2439 return Err;
2440
2441 // FIXME: we might need to merge the number of positive or negative bits
2442 // if the enumerator lists don't match.
2443 To->completeDefinition(*ToTypeOrErr, *ToPromotionTypeOrErr,
2444 From->getNumPositiveBits(),
2445 From->getNumNegativeBits());
2446 return Error::success();
2447}
2448
2452 for (const auto &Arg : FromArgs) {
2453 if (auto ToOrErr = import(Arg))
2454 ToArgs.push_back(*ToOrErr);
2455 else
2456 return ToOrErr.takeError();
2457 }
2458
2459 return Error::success();
2460}
2461
2462// FIXME: Do not forget to remove this and use only 'import'.
2465 return import(From);
2466}
2467
2468template <typename InContainerTy>
2470 const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo) {
2471 for (const auto &FromLoc : Container) {
2472 if (auto ToLocOrErr = import(FromLoc))
2473 ToTAInfo.addArgument(*ToLocOrErr);
2474 else
2475 return ToLocOrErr.takeError();
2476 }
2477 return Error::success();
2478}
2479
2484}
2485
2486bool ASTNodeImporter::IsStructuralMatch(Decl *From, Decl *To, bool Complain,
2487 bool IgnoreTemplateParmDepth) {
2488 // Eliminate a potential failure point where we attempt to re-import
2489 // something we're trying to import while completing ToRecord.
2490 Decl *ToOrigin = Importer.GetOriginalDecl(To);
2491 if (ToOrigin) {
2492 To = ToOrigin;
2493 }
2494
2496 Importer.getFromContext(), Importer.getToContext(),
2498 /*StrictTypeSpelling=*/false, Complain, /*ErrorOnTagTypeMismatch=*/false,
2499 IgnoreTemplateParmDepth);
2500 return Ctx.IsEquivalent(From, To);
2501}
2502
2504 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2505 << D->getDeclKindName();
2506 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2507}
2508
2510 Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
2511 << D->getDeclKindName();
2512 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
2513}
2514
2516 // Import the context of this declaration.
2517 DeclContext *DC, *LexicalDC;
2518 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
2519 return std::move(Err);
2520
2521 // Import the location of this declaration.
2522 ExpectedSLoc LocOrErr = import(D->getLocation());
2523 if (!LocOrErr)
2524 return LocOrErr.takeError();
2525
2526 EmptyDecl *ToD;
2527 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, *LocOrErr))
2528 return ToD;
2529
2530 ToD->setLexicalDeclContext(LexicalDC);
2531 LexicalDC->addDeclInternal(ToD);
2532 return ToD;
2533}
2534
2536 TranslationUnitDecl *ToD =
2538
2539 Importer.MapImported(D, ToD);
2540
2541 return ToD;
2542}
2543
2545 DeclContext *DC, *LexicalDC;
2546 DeclarationName Name;
2548 NamedDecl *ToND;
2549 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToND, Loc))
2550 return std::move(Err);
2551 if (ToND)
2552 return ToND;
2553
2554 BindingDecl *ToD;
2555 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, Loc,
2556 Name.getAsIdentifierInfo()))
2557 return ToD;
2558
2559 Error Err = Error::success();
2560 QualType ToType = importChecked(Err, D->getType());
2561 Expr *ToBinding = importChecked(Err, D->getBinding());
2562 ValueDecl *ToDecomposedDecl = importChecked(Err, D->getDecomposedDecl());
2563 if (Err)
2564 return std::move(Err);
2565
2566 ToD->setBinding(ToType, ToBinding);
2567 ToD->setDecomposedDecl(ToDecomposedDecl);
2568 addDeclToContexts(D, ToD);
2569
2570 return ToD;
2571}
2572
2574 ExpectedSLoc LocOrErr = import(D->getLocation());
2575 if (!LocOrErr)
2576 return LocOrErr.takeError();
2577 auto ColonLocOrErr = import(D->getColonLoc());
2578 if (!ColonLocOrErr)
2579 return ColonLocOrErr.takeError();
2580
2581 // Import the context of this declaration.
2582 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2583 if (!DCOrErr)
2584 return DCOrErr.takeError();
2585 DeclContext *DC = *DCOrErr;
2586
2587 AccessSpecDecl *ToD;
2588 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), D->getAccess(),
2589 DC, *LocOrErr, *ColonLocOrErr))
2590 return ToD;
2591
2592 // Lexical DeclContext and Semantic DeclContext
2593 // is always the same for the accessSpec.
2594 ToD->setLexicalDeclContext(DC);
2595 DC->addDeclInternal(ToD);
2596
2597 return ToD;
2598}
2599
2601 auto DCOrErr = Importer.ImportContext(D->getDeclContext());
2602 if (!DCOrErr)
2603 return DCOrErr.takeError();
2604 DeclContext *DC = *DCOrErr;
2605 DeclContext *LexicalDC = DC;
2606
2607 Error Err = Error::success();
2608 auto ToLocation = importChecked(Err, D->getLocation());
2609 auto ToRParenLoc = importChecked(Err, D->getRParenLoc());
2610 auto ToAssertExpr = importChecked(Err, D->getAssertExpr());
2611 auto ToMessage = importChecked(Err, D->getMessage());
2612 if (Err)
2613 return std::move(Err);
2614
2615 StaticAssertDecl *ToD;
2616 if (GetImportedOrCreateDecl(
2617 ToD, D, Importer.getToContext(), DC, ToLocation, ToAssertExpr, ToMessage,
2618 ToRParenLoc, D->isFailed()))
2619 return ToD;
2620
2621 ToD->setLexicalDeclContext(LexicalDC);
2622 LexicalDC->addDeclInternal(ToD);
2623 return ToD;
2624}
2625
2627 // Import the major distinguishing characteristics of this namespace.
2628 DeclContext *DC, *LexicalDC;
2629 DeclarationName Name;
2631 NamedDecl *ToD;
2632 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2633 return std::move(Err);
2634 if (ToD)
2635 return ToD;
2636
2637 NamespaceDecl *MergeWithNamespace = nullptr;
2638 if (!Name) {
2639 // This is an anonymous namespace. Adopt an existing anonymous
2640 // namespace if we can.
2641 // FIXME: Not testable.
2642 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2643 MergeWithNamespace = TU->getAnonymousNamespace();
2644 else
2645 MergeWithNamespace = cast<NamespaceDecl>(DC)->getAnonymousNamespace();
2646 } else {
2647 SmallVector<NamedDecl *, 4> ConflictingDecls;
2648 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2649 for (auto *FoundDecl : FoundDecls) {
2651 continue;
2652
2653 if (auto *FoundNS = dyn_cast<NamespaceDecl>(FoundDecl)) {
2654 MergeWithNamespace = FoundNS;
2655 ConflictingDecls.clear();
2656 break;
2657 }
2658
2659 ConflictingDecls.push_back(FoundDecl);
2660 }
2661
2662 if (!ConflictingDecls.empty()) {
2663 ExpectedName NameOrErr = Importer.HandleNameConflict(
2664 Name, DC, Decl::IDNS_Namespace, ConflictingDecls.data(),
2665 ConflictingDecls.size());
2666 if (NameOrErr)
2667 Name = NameOrErr.get();
2668 else
2669 return NameOrErr.takeError();
2670 }
2671 }
2672
2673 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2674 if (!BeginLocOrErr)
2675 return BeginLocOrErr.takeError();
2676 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
2677 if (!RBraceLocOrErr)
2678 return RBraceLocOrErr.takeError();
2679
2680 // Create the "to" namespace, if needed.
2681 NamespaceDecl *ToNamespace = MergeWithNamespace;
2682 if (!ToNamespace) {
2683 if (GetImportedOrCreateDecl(ToNamespace, D, Importer.getToContext(), DC,
2684 D->isInline(), *BeginLocOrErr, Loc,
2685 Name.getAsIdentifierInfo(),
2686 /*PrevDecl=*/nullptr, D->isNested()))
2687 return ToNamespace;
2688 ToNamespace->setRBraceLoc(*RBraceLocOrErr);
2689 ToNamespace->setLexicalDeclContext(LexicalDC);
2690 LexicalDC->addDeclInternal(ToNamespace);
2691
2692 // If this is an anonymous namespace, register it as the anonymous
2693 // namespace within its context.
2694 if (!Name) {
2695 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2696 TU->setAnonymousNamespace(ToNamespace);
2697 else
2698 cast<NamespaceDecl>(DC)->setAnonymousNamespace(ToNamespace);
2699 }
2700 }
2701 Importer.MapImported(D, ToNamespace);
2702
2703 if (Error Err = ImportDeclContext(D))
2704 return std::move(Err);
2705
2706 return ToNamespace;
2707}
2708
2710 // Import the major distinguishing characteristics of this namespace.
2711 DeclContext *DC, *LexicalDC;
2712 DeclarationName Name;
2714 NamedDecl *LookupD;
2715 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, LookupD, Loc))
2716 return std::move(Err);
2717 if (LookupD)
2718 return LookupD;
2719
2720 // NOTE: No conflict resolution is done for namespace aliases now.
2721
2722 Error Err = Error::success();
2723 auto ToNamespaceLoc = importChecked(Err, D->getNamespaceLoc());
2724 auto ToAliasLoc = importChecked(Err, D->getAliasLoc());
2725 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
2726 auto ToTargetNameLoc = importChecked(Err, D->getTargetNameLoc());
2727 auto ToNamespace = importChecked(Err, D->getNamespace());
2728 if (Err)
2729 return std::move(Err);
2730
2731 IdentifierInfo *ToIdentifier = Importer.Import(D->getIdentifier());
2732
2733 NamespaceAliasDecl *ToD;
2734 if (GetImportedOrCreateDecl(
2735 ToD, D, Importer.getToContext(), DC, ToNamespaceLoc, ToAliasLoc,
2736 ToIdentifier, ToQualifierLoc, ToTargetNameLoc, ToNamespace))
2737 return ToD;
2738
2739 ToD->setLexicalDeclContext(LexicalDC);
2740 LexicalDC->addDeclInternal(ToD);
2741
2742 return ToD;
2743}
2744
2747 // Import the major distinguishing characteristics of this typedef.
2748 DeclarationName Name;
2750 NamedDecl *ToD;
2751 // Do not import the DeclContext, we will import it once the TypedefNameDecl
2752 // is created.
2753 if (Error Err = ImportDeclParts(D, Name, ToD, Loc))
2754 return std::move(Err);
2755 if (ToD)
2756 return ToD;
2757
2758 DeclContext *DC = cast_or_null<DeclContext>(
2759 Importer.GetAlreadyImportedOrNull(cast<Decl>(D->getDeclContext())));
2760 DeclContext *LexicalDC =
2761 cast_or_null<DeclContext>(Importer.GetAlreadyImportedOrNull(
2762 cast<Decl>(D->getLexicalDeclContext())));
2763
2764 // If this typedef is not in block scope, determine whether we've
2765 // seen a typedef with the same name (that we can merge with) or any
2766 // other entity by that name (which name lookup could conflict with).
2767 // Note: Repeated typedefs are not valid in C99:
2768 // 'typedef int T; typedef int T;' is invalid
2769 // We do not care about this now.
2770 if (DC && !DC->isFunctionOrMethod()) {
2771 SmallVector<NamedDecl *, 4> ConflictingDecls;
2772 unsigned IDNS = Decl::IDNS_Ordinary;
2773 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2774 for (auto *FoundDecl : FoundDecls) {
2775 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2776 continue;
2777 if (auto *FoundTypedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
2778 if (!hasSameVisibilityContextAndLinkage(FoundTypedef, D))
2779 continue;
2780
2781 QualType FromUT = D->getUnderlyingType();
2782 QualType FoundUT = FoundTypedef->getUnderlyingType();
2783 if (Importer.IsStructurallyEquivalent(FromUT, FoundUT)) {
2784 // If the underlying declarations are unnamed records these can be
2785 // imported as different types. We should create a distinct typedef
2786 // node in this case.
2787 // If we found an existing underlying type with a record in a
2788 // different context (than the imported), this is already reason for
2789 // having distinct typedef nodes for these.
2790 // Again this can create situation like
2791 // 'typedef int T; typedef int T;' but this is hard to avoid without
2792 // a rename strategy at import.
2793 if (!FromUT.isNull() && !FoundUT.isNull()) {
2794 RecordDecl *FromR = FromUT->getAsRecordDecl();
2795 RecordDecl *FoundR = FoundUT->getAsRecordDecl();
2796 if (FromR && FoundR &&
2797 !hasSameVisibilityContextAndLinkage(FoundR, FromR))
2798 continue;
2799 }
2800 // If the "From" context has a complete underlying type but we
2801 // already have a complete underlying type then return with that.
2802 if (!FromUT->isIncompleteType() && !FoundUT->isIncompleteType())
2803 return Importer.MapImported(D, FoundTypedef);
2804 // FIXME Handle redecl chain. When you do that make consistent changes
2805 // in ASTImporterLookupTable too.
2806 } else {
2807 ConflictingDecls.push_back(FoundDecl);
2808 }
2809 }
2810 }
2811
2812 if (!ConflictingDecls.empty()) {
2813 ExpectedName NameOrErr = Importer.HandleNameConflict(
2814 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2815 if (NameOrErr)
2816 Name = NameOrErr.get();
2817 else
2818 return NameOrErr.takeError();
2819 }
2820 }
2821
2822 Error Err = Error::success();
2823 auto ToUnderlyingType = importChecked(Err, D->getUnderlyingType());
2824 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
2825 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
2826 if (Err)
2827 return std::move(Err);
2828
2829 // Create the new typedef node.
2830 // FIXME: ToUnderlyingType is not used.
2831 (void)ToUnderlyingType;
2832 TypedefNameDecl *ToTypedef;
2833 if (IsAlias) {
2834 if (GetImportedOrCreateDecl<TypeAliasDecl>(
2835 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2836 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2837 return ToTypedef;
2838 } else if (GetImportedOrCreateDecl<TypedefDecl>(
2839 ToTypedef, D, Importer.getToContext(), DC, ToBeginLoc, Loc,
2840 Name.getAsIdentifierInfo(), ToTypeSourceInfo))
2841 return ToTypedef;
2842
2843 // Import the DeclContext and set it to the Typedef.
2844 if ((Err = ImportDeclContext(D, DC, LexicalDC)))
2845 return std::move(Err);
2846 ToTypedef->setDeclContext(DC);
2847 ToTypedef->setLexicalDeclContext(LexicalDC);
2848 // Add to the lookupTable because we could not do that in MapImported.
2849 Importer.AddToLookupTable(ToTypedef);
2850
2851 ToTypedef->setAccess(D->getAccess());
2852
2853 // Templated declarations should not appear in DeclContext.
2854 TypeAliasDecl *FromAlias = IsAlias ? cast<TypeAliasDecl>(D) : nullptr;
2855 if (!FromAlias || !FromAlias->getDescribedAliasTemplate())
2856 LexicalDC->addDeclInternal(ToTypedef);
2857
2858 return ToTypedef;
2859}
2860
2862 return VisitTypedefNameDecl(D, /*IsAlias=*/false);
2863}
2864
2866 return VisitTypedefNameDecl(D, /*IsAlias=*/true);
2867}
2868
2871 // Import the major distinguishing characteristics of this typedef.
2872 DeclContext *DC, *LexicalDC;
2873 DeclarationName Name;
2875 NamedDecl *FoundD;
2876 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, FoundD, Loc))
2877 return std::move(Err);
2878 if (FoundD)
2879 return FoundD;
2880
2881 // If this typedef is not in block scope, determine whether we've
2882 // seen a typedef with the same name (that we can merge with) or any
2883 // other entity by that name (which name lookup could conflict with).
2884 if (!DC->isFunctionOrMethod()) {
2885 SmallVector<NamedDecl *, 4> ConflictingDecls;
2886 unsigned IDNS = Decl::IDNS_Ordinary;
2887 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
2888 for (auto *FoundDecl : FoundDecls) {
2889 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2890 continue;
2891 if (auto *FoundAlias = dyn_cast<TypeAliasTemplateDecl>(FoundDecl)) {
2892 if (IsStructuralMatch(D, FoundAlias))
2893 return Importer.MapImported(D, FoundAlias);
2894 ConflictingDecls.push_back(FoundDecl);
2895 }
2896 }
2897
2898 if (!ConflictingDecls.empty()) {
2899 ExpectedName NameOrErr = Importer.HandleNameConflict(
2900 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
2901 if (NameOrErr)
2902 Name = NameOrErr.get();
2903 else
2904 return NameOrErr.takeError();
2905 }
2906 }
2907
2908 Error Err = Error::success();
2909 auto ToTemplateParameters = importChecked(Err, D->getTemplateParameters());
2910 auto ToTemplatedDecl = importChecked(Err, D->getTemplatedDecl());
2911 if (Err)
2912 return std::move(Err);
2913
2914 TypeAliasTemplateDecl *ToAlias;
2915 if (GetImportedOrCreateDecl(ToAlias, D, Importer.getToContext(), DC, Loc,
2916 Name, ToTemplateParameters, ToTemplatedDecl))
2917 return ToAlias;
2918
2919 ToTemplatedDecl->setDescribedAliasTemplate(ToAlias);
2920
2921 ToAlias->setAccess(D->getAccess());
2922 ToAlias->setLexicalDeclContext(LexicalDC);
2923 LexicalDC->addDeclInternal(ToAlias);
2924 if (DC != Importer.getToContext().getTranslationUnitDecl())
2925 updateLookupTableForTemplateParameters(*ToTemplateParameters);
2926 return ToAlias;
2927}
2928
2930 // Import the major distinguishing characteristics of this label.
2931 DeclContext *DC, *LexicalDC;
2932 DeclarationName Name;
2934 NamedDecl *ToD;
2935 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2936 return std::move(Err);
2937 if (ToD)
2938 return ToD;
2939
2940 assert(LexicalDC->isFunctionOrMethod());
2941
2942 LabelDecl *ToLabel;
2943 if (D->isGnuLocal()) {
2944 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
2945 if (!BeginLocOrErr)
2946 return BeginLocOrErr.takeError();
2947 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2948 Name.getAsIdentifierInfo(), *BeginLocOrErr))
2949 return ToLabel;
2950
2951 } else {
2952 if (GetImportedOrCreateDecl(ToLabel, D, Importer.getToContext(), DC, Loc,
2953 Name.getAsIdentifierInfo()))
2954 return ToLabel;
2955
2956 }
2957
2958 Expected<LabelStmt *> ToStmtOrErr = import(D->getStmt());
2959 if (!ToStmtOrErr)
2960 return ToStmtOrErr.takeError();
2961
2962 ToLabel->setStmt(*ToStmtOrErr);
2963 ToLabel->setLexicalDeclContext(LexicalDC);
2964 LexicalDC->addDeclInternal(ToLabel);
2965 return ToLabel;
2966}
2967
2969 // Import the major distinguishing characteristics of this enum.
2970 DeclContext *DC, *LexicalDC;
2971 DeclarationName Name;
2973 NamedDecl *ToD;
2974 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
2975 return std::move(Err);
2976 if (ToD)
2977 return ToD;
2978
2979 // Figure out what enum name we're looking for.
2980 unsigned IDNS = Decl::IDNS_Tag;
2981 DeclarationName SearchName = Name;
2982 if (!SearchName && D->getTypedefNameForAnonDecl()) {
2983 if (Error Err = importInto(
2984 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
2985 return std::move(Err);
2986 IDNS = Decl::IDNS_Ordinary;
2987 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
2988 IDNS |= Decl::IDNS_Ordinary;
2989
2990 // We may already have an enum of the same name; try to find and match it.
2991 EnumDecl *PrevDecl = nullptr;
2992 if (!DC->isFunctionOrMethod()) {
2993 SmallVector<NamedDecl *, 4> ConflictingDecls;
2994 auto FoundDecls =
2995 Importer.findDeclsInToCtx(DC, SearchName);
2996 for (auto *FoundDecl : FoundDecls) {
2997 if (!FoundDecl->isInIdentifierNamespace(IDNS))
2998 continue;
2999
3000 if (auto *Typedef = dyn_cast<TypedefNameDecl>(FoundDecl)) {
3001 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3002 FoundDecl = Tag->getDecl();
3003 }
3004
3005 if (auto *FoundEnum = dyn_cast<EnumDecl>(FoundDecl)) {
3006 if (!hasSameVisibilityContextAndLinkage(FoundEnum, D))
3007 continue;
3008 if (IsStructuralMatch(D, FoundEnum, !SearchName.isEmpty())) {
3009 EnumDecl *FoundDef = FoundEnum->getDefinition();
3010 if (D->isThisDeclarationADefinition() && FoundDef)
3011 return Importer.MapImported(D, FoundDef);
3012 PrevDecl = FoundEnum->getMostRecentDecl();
3013 break;
3014 }
3015 ConflictingDecls.push_back(FoundDecl);
3016 }
3017 }
3018
3019 // In case of unnamed enums, we try to find an existing similar one, if none
3020 // was found, perform the import always.
3021 // Structural in-equivalence is not detected in this way here, but it may
3022 // be found when the parent decl is imported (if the enum is part of a
3023 // class). To make this totally exact a more difficult solution is needed.
3024 if (SearchName && !ConflictingDecls.empty()) {
3025 ExpectedName NameOrErr = Importer.HandleNameConflict(
3026 SearchName, DC, IDNS, ConflictingDecls.data(),
3027 ConflictingDecls.size());
3028 if (NameOrErr)
3029 Name = NameOrErr.get();
3030 else
3031 return NameOrErr.takeError();
3032 }
3033 }
3034
3035 Error Err = Error::success();
3036 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
3037 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3038 auto ToIntegerType = importChecked(Err, D->getIntegerType());
3039 auto ToBraceRange = importChecked(Err, D->getBraceRange());
3040 if (Err)
3041 return std::move(Err);
3042
3043 // Create the enum declaration.
3044 EnumDecl *D2;
3045 if (GetImportedOrCreateDecl(
3046 D2, D, Importer.getToContext(), DC, ToBeginLoc,
3047 Loc, Name.getAsIdentifierInfo(), PrevDecl, D->isScoped(),
3048 D->isScopedUsingClassTag(), D->isFixed()))
3049 return D2;
3050
3051 D2->setQualifierInfo(ToQualifierLoc);
3052 D2->setIntegerType(ToIntegerType);
3053 D2->setBraceRange(ToBraceRange);
3054 D2->setAccess(D->getAccess());
3055 D2->setLexicalDeclContext(LexicalDC);
3056 addDeclToContexts(D, D2);
3057
3058 if (MemberSpecializationInfo *MemberInfo = D->getMemberSpecializationInfo()) {
3059 TemplateSpecializationKind SK = MemberInfo->getTemplateSpecializationKind();
3060 EnumDecl *FromInst = D->getInstantiatedFromMemberEnum();
3061 if (Expected<EnumDecl *> ToInstOrErr = import(FromInst))
3062 D2->setInstantiationOfMemberEnum(*ToInstOrErr, SK);
3063 else
3064 return ToInstOrErr.takeError();
3065 if (ExpectedSLoc POIOrErr = import(MemberInfo->getPointOfInstantiation()))
3067 else
3068 return POIOrErr.takeError();
3069 }
3070
3071 // Import the definition
3072 if (D->isCompleteDefinition())
3073 if (Error Err = ImportDefinition(D, D2))
3074 return std::move(Err);
3075
3076 return D2;
3077}
3078
3080 bool IsFriendTemplate = false;
3081 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3082 IsFriendTemplate =
3083 DCXX->getDescribedClassTemplate() &&
3084 DCXX->getDescribedClassTemplate()->getFriendObjectKind() !=
3086 }
3087
3088 // Import the major distinguishing characteristics of this record.
3089 DeclContext *DC = nullptr, *LexicalDC = nullptr;
3090 DeclarationName Name;
3092 NamedDecl *ToD = nullptr;
3093 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3094 return std::move(Err);
3095 if (ToD)
3096 return ToD;
3097
3098 // Figure out what structure name we're looking for.
3099 unsigned IDNS = Decl::IDNS_Tag;
3100 DeclarationName SearchName = Name;
3101 if (!SearchName && D->getTypedefNameForAnonDecl()) {
3102 if (Error Err = importInto(
3103 SearchName, D->getTypedefNameForAnonDecl()->getDeclName()))
3104 return std::move(Err);
3105 IDNS = Decl::IDNS_Ordinary;
3106 } else if (Importer.getToContext().getLangOpts().CPlusPlus)
3108
3109 bool IsDependentContext = DC != LexicalDC ? LexicalDC->isDependentContext()
3110 : DC->isDependentContext();
3111 bool DependentFriend = IsFriendTemplate && IsDependentContext;
3112
3113 // We may already have a record of the same name; try to find and match it.
3114 RecordDecl *PrevDecl = nullptr;
3115 if (!DependentFriend && !DC->isFunctionOrMethod() && !D->isLambda()) {
3116 SmallVector<NamedDecl *, 4> ConflictingDecls;
3117 auto FoundDecls =
3118 Importer.findDeclsInToCtx(DC, SearchName);
3119 if (!FoundDecls.empty()) {
3120 // We're going to have to compare D against potentially conflicting Decls,
3121 // so complete it.
3122 if (D->hasExternalLexicalStorage() && !D->isCompleteDefinition())
3124 }
3125
3126 for (auto *FoundDecl : FoundDecls) {
3127 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3128 continue;
3129
3130 Decl *Found = FoundDecl;
3131 if (auto *Typedef = dyn_cast<TypedefNameDecl>(Found)) {
3132 if (const auto *Tag = Typedef->getUnderlyingType()->getAs<TagType>())
3133 Found = Tag->getDecl();
3134 }
3135
3136 if (auto *FoundRecord = dyn_cast<RecordDecl>(Found)) {
3137 // Do not emit false positive diagnostic in case of unnamed
3138 // struct/union and in case of anonymous structs. Would be false
3139 // because there may be several anonymous/unnamed structs in a class.
3140 // E.g. these are both valid:
3141 // struct A { // unnamed structs
3142 // struct { struct A *next; } entry0;
3143 // struct { struct A *next; } entry1;
3144 // };
3145 // struct X { struct { int a; }; struct { int b; }; }; // anon structs
3146 if (!SearchName)
3147 if (!IsStructuralMatch(D, FoundRecord, false))
3148 continue;
3149
3150 if (!hasSameVisibilityContextAndLinkage(FoundRecord, D))
3151 continue;
3152
3153 if (IsStructuralMatch(D, FoundRecord)) {
3154 RecordDecl *FoundDef = FoundRecord->getDefinition();
3155 if (D->isThisDeclarationADefinition() && FoundDef) {
3156 // FIXME: Structural equivalence check should check for same
3157 // user-defined methods.
3158 Importer.MapImported(D, FoundDef);
3159 if (const auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3160 auto *FoundCXX = dyn_cast<CXXRecordDecl>(FoundDef);
3161 assert(FoundCXX && "Record type mismatch");
3162
3163 if (!Importer.isMinimalImport())
3164 // FoundDef may not have every implicit method that D has
3165 // because implicit methods are created only if they are used.
3166 if (Error Err = ImportImplicitMethods(DCXX, FoundCXX))
3167 return std::move(Err);
3168 }
3169 // FIXME: We can return FoundDef here.
3170 }
3171 PrevDecl = FoundRecord->getMostRecentDecl();
3172 break;
3173 }
3174 ConflictingDecls.push_back(FoundDecl);
3175 } // kind is RecordDecl
3176 } // for
3177
3178 if (!ConflictingDecls.empty() && SearchName) {
3179 ExpectedName NameOrErr = Importer.HandleNameConflict(
3180 SearchName, DC, IDNS, ConflictingDecls.data(),
3181 ConflictingDecls.size());
3182 if (NameOrErr)
3183 Name = NameOrErr.get();
3184 else
3185 return NameOrErr.takeError();
3186 }
3187 }
3188
3189 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
3190 if (!BeginLocOrErr)
3191 return BeginLocOrErr.takeError();
3192
3193 // Create the record declaration.
3194 RecordDecl *D2 = nullptr;
3195 CXXRecordDecl *D2CXX = nullptr;
3196 if (auto *DCXX = dyn_cast<CXXRecordDecl>(D)) {
3197 if (DCXX->isLambda()) {
3198 auto TInfoOrErr = import(DCXX->getLambdaTypeInfo());
3199 if (!TInfoOrErr)
3200 return TInfoOrErr.takeError();
3201 if (GetImportedOrCreateSpecialDecl(
3202 D2CXX, CXXRecordDecl::CreateLambda, D, Importer.getToContext(),
3203 DC, *TInfoOrErr, Loc, DCXX->getLambdaDependencyKind(),
3204 DCXX->isGenericLambda(), DCXX->getLambdaCaptureDefault()))
3205 return D2CXX;
3206 CXXRecordDecl::LambdaNumbering Numbering = DCXX->getLambdaNumbering();
3207 ExpectedDecl CDeclOrErr = import(Numbering.ContextDecl);
3208 if (!CDeclOrErr)
3209 return CDeclOrErr.takeError();
3210 Numbering.ContextDecl = *CDeclOrErr;
3211 D2CXX->setLambdaNumbering(Numbering);
3212 } else if (DCXX->isInjectedClassName()) {
3213 // We have to be careful to do a similar dance to the one in
3214 // Sema::ActOnStartCXXMemberDeclarations
3215 const bool DelayTypeCreation = true;
3216 if (GetImportedOrCreateDecl(
3217 D2CXX, D, Importer.getToContext(), D->getTagKind(), DC,
3218 *BeginLocOrErr, Loc, Name.getAsIdentifierInfo(),
3219 cast_or_null<CXXRecordDecl>(PrevDecl), DelayTypeCreation))
3220 return D2CXX;
3221 Importer.getToContext().getTypeDeclType(
3222 D2CXX, dyn_cast<CXXRecordDecl>(DC));
3223 } else {
3224 if (GetImportedOrCreateDecl(D2CXX, D, Importer.getToContext(),
3225 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3226 Name.getAsIdentifierInfo(),
3227 cast_or_null<CXXRecordDecl>(PrevDecl)))
3228 return D2CXX;
3229 }
3230
3231 D2 = D2CXX;
3232 D2->setAccess(D->getAccess());
3233 D2->setLexicalDeclContext(LexicalDC);
3234 addDeclToContexts(D, D2);
3235
3236 if (ClassTemplateDecl *FromDescribed =
3237 DCXX->getDescribedClassTemplate()) {
3238 ClassTemplateDecl *ToDescribed;
3239 if (Error Err = importInto(ToDescribed, FromDescribed))
3240 return std::move(Err);
3241 D2CXX->setDescribedClassTemplate(ToDescribed);
3242 if (!DCXX->isInjectedClassName() && !IsFriendTemplate) {
3243 // In a record describing a template the type should be an
3244 // InjectedClassNameType (see Sema::CheckClassTemplate). Update the
3245 // previously set type to the correct value here (ToDescribed is not
3246 // available at record create).
3247 CXXRecordDecl *Injected = nullptr;
3248 for (NamedDecl *Found : D2CXX->noload_lookup(Name)) {
3249 auto *Record = dyn_cast<CXXRecordDecl>(Found);
3250 if (Record && Record->isInjectedClassName()) {
3251 Injected = Record;
3252 break;
3253 }
3254 }
3255 // Create an injected type for the whole redecl chain.
3256 // The chain may contain an already existing injected type at the start,
3257 // if yes this should be reused. We must ensure that only one type
3258 // object exists for the injected type (including the injected record
3259 // declaration), ASTContext does not check it.
3260 SmallVector<Decl *, 2> Redecls =
3262 const Type *FrontTy =
3263 cast<CXXRecordDecl>(Redecls.front())->getTypeForDecl();
3264 QualType InjSpec;
3265 if (auto *InjTy = FrontTy->getAs<InjectedClassNameType>())
3266 InjSpec = InjTy->getInjectedSpecializationType();
3267 else
3268 InjSpec = ToDescribed->getInjectedClassNameSpecialization();
3269 for (auto *R : Redecls) {
3270 auto *RI = cast<CXXRecordDecl>(R);
3271 if (R != Redecls.front() ||
3272 !isa<InjectedClassNameType>(RI->getTypeForDecl()))
3273 RI->setTypeForDecl(nullptr);
3274 // This function tries to get the injected type from getTypeForDecl,
3275 // then from the previous declaration if possible. If not, it creates
3276 // a new type.
3277 Importer.getToContext().getInjectedClassNameType(RI, InjSpec);
3278 }
3279 // Set the new type for the injected decl too.
3280 if (Injected) {
3281 Injected->setTypeForDecl(nullptr);
3282 // This function will copy the injected type from D2CXX into Injected.
3283 // The injected decl does not have a previous decl to copy from.
3284 Importer.getToContext().getTypeDeclType(Injected, D2CXX);
3285 }
3286 }
3287 } else if (MemberSpecializationInfo *MemberInfo =
3288 DCXX->getMemberSpecializationInfo()) {
3290 MemberInfo->getTemplateSpecializationKind();
3292
3293 if (Expected<CXXRecordDecl *> ToInstOrErr = import(FromInst))
3294 D2CXX->setInstantiationOfMemberClass(*ToInstOrErr, SK);
3295 else
3296 return ToInstOrErr.takeError();
3297
3298 if (ExpectedSLoc POIOrErr =
3299 import(MemberInfo->getPointOfInstantiation()))
3301 *POIOrErr);
3302 else
3303 return POIOrErr.takeError();
3304 }
3305
3306 } else {
3307 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(),
3308 D->getTagKind(), DC, *BeginLocOrErr, Loc,
3309 Name.getAsIdentifierInfo(), PrevDecl))
3310 return D2;
3311 D2->setLexicalDeclContext(LexicalDC);
3312 addDeclToContexts(D, D2);
3313 }
3314
3315 if (auto BraceRangeOrErr = import(D->getBraceRange()))
3316 D2->setBraceRange(*BraceRangeOrErr);
3317 else
3318 return BraceRangeOrErr.takeError();
3319 if (auto QualifierLocOrErr = import(D->getQualifierLoc()))
3320 D2->setQualifierInfo(*QualifierLocOrErr);
3321 else
3322 return QualifierLocOrErr.takeError();
3323
3324 if (D->isAnonymousStructOrUnion())
3325 D2->setAnonymousStructOrUnion(true);
3326
3327 if (D->isCompleteDefinition())
3328 if (Error Err = ImportDefinition(D, D2, IDK_Default))
3329 return std::move(Err);
3330
3331 return D2;
3332}
3333
3335 // Import the major distinguishing characteristics of this enumerator.
3336 DeclContext *DC, *LexicalDC;
3337 DeclarationName Name;
3339 NamedDecl *ToD;
3340 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3341 return std::move(Err);
3342 if (ToD)
3343 return ToD;
3344
3345 // Determine whether there are any other declarations with the same name and
3346 // in the same context.
3347 if (!LexicalDC->isFunctionOrMethod()) {
3348 SmallVector<NamedDecl *, 4> ConflictingDecls;
3349 unsigned IDNS = Decl::IDNS_Ordinary;
3350 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3351 for (auto *FoundDecl : FoundDecls) {
3352 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3353 continue;
3354
3355 if (auto *FoundEnumConstant = dyn_cast<EnumConstantDecl>(FoundDecl)) {
3356 if (IsStructuralMatch(D, FoundEnumConstant))
3357 return Importer.MapImported(D, FoundEnumConstant);
3358 ConflictingDecls.push_back(FoundDecl);
3359 }
3360 }
3361
3362 if (!ConflictingDecls.empty()) {
3363 ExpectedName NameOrErr = Importer.HandleNameConflict(
3364 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3365 if (NameOrErr)
3366 Name = NameOrErr.get();
3367 else
3368 return NameOrErr.takeError();
3369 }
3370 }
3371
3372 ExpectedType TypeOrErr = import(D->getType());
3373 if (!TypeOrErr)
3374 return TypeOrErr.takeError();
3375
3376 ExpectedExpr InitOrErr = import(D->getInitExpr());
3377 if (!InitOrErr)
3378 return InitOrErr.takeError();
3379
3380 EnumConstantDecl *ToEnumerator;
3381 if (GetImportedOrCreateDecl(
3382 ToEnumerator, D, Importer.getToContext(), cast<EnumDecl>(DC), Loc,
3383 Name.getAsIdentifierInfo(), *TypeOrErr, *InitOrErr, D->getInitVal()))
3384 return ToEnumerator;
3385
3386 ToEnumerator->setAccess(D->getAccess());
3387 ToEnumerator->setLexicalDeclContext(LexicalDC);
3388 LexicalDC->addDeclInternal(ToEnumerator);
3389 return ToEnumerator;
3390}
3391
3392template <typename DeclTy>
3394 DeclTy *ToD) {
3395 unsigned int Num = FromD->getNumTemplateParameterLists();
3396 if (Num == 0)
3397 return Error::success();
3399 for (unsigned int I = 0; I < Num; ++I)
3400 if (Expected<TemplateParameterList *> ToTPListOrErr =
3401 import(FromD->getTemplateParameterList(I)))
3402 ToTPLists[I] = *ToTPListOrErr;
3403 else
3404 return ToTPListOrErr.takeError();
3405 ToD->setTemplateParameterListsInfo(Importer.ToContext, ToTPLists);
3406 return Error::success();
3407}
3408
3410 FunctionDecl *FromFD, FunctionDecl *ToFD) {
3411 switch (FromFD->getTemplatedKind()) {
3414 return Error::success();
3415
3417 if (Expected<FunctionDecl *> InstFDOrErr =
3418 import(FromFD->getInstantiatedFromDecl()))
3419 ToFD->setInstantiatedFromDecl(*InstFDOrErr);
3420 return Error::success();
3423
3424 if (Expected<FunctionDecl *> InstFDOrErr =
3425 import(FromFD->getInstantiatedFromMemberFunction()))
3426 ToFD->setInstantiationOfMemberFunction(*InstFDOrErr, TSK);
3427 else
3428 return InstFDOrErr.takeError();
3429
3430 if (ExpectedSLoc POIOrErr = import(
3433 else
3434 return POIOrErr.takeError();
3435
3436 return Error::success();
3437 }
3438
3440 auto FunctionAndArgsOrErr =
3442 if (!FunctionAndArgsOrErr)
3443 return FunctionAndArgsOrErr.takeError();
3444
3446 Importer.getToContext(), std::get<1>(*FunctionAndArgsOrErr));
3447
3448 auto *FTSInfo = FromFD->getTemplateSpecializationInfo();
3449 TemplateArgumentListInfo ToTAInfo;
3450 const auto *FromTAArgsAsWritten = FTSInfo->TemplateArgumentsAsWritten;
3451 if (FromTAArgsAsWritten)
3452 if (Error Err = ImportTemplateArgumentListInfo(
3453 *FromTAArgsAsWritten, ToTAInfo))
3454 return Err;
3455
3456 ExpectedSLoc POIOrErr = import(FTSInfo->getPointOfInstantiation());
3457 if (!POIOrErr)
3458 return POIOrErr.takeError();
3459
3460 if (Error Err = ImportTemplateParameterLists(FromFD, ToFD))
3461 return Err;
3462
3463 TemplateSpecializationKind TSK = FTSInfo->getTemplateSpecializationKind();
3464 ToFD->setFunctionTemplateSpecialization(
3465 std::get<0>(*FunctionAndArgsOrErr), ToTAList, /* InsertPos= */ nullptr,
3466 TSK, FromTAArgsAsWritten ? &ToTAInfo : nullptr, *POIOrErr);
3467 return Error::success();
3468 }
3469
3471 auto *FromInfo = FromFD->getDependentSpecializationInfo();
3472 UnresolvedSet<8> Candidates;
3473 for (FunctionTemplateDecl *FTD : FromInfo->getCandidates()) {
3474 if (Expected<FunctionTemplateDecl *> ToFTDOrErr = import(FTD))
3475 Candidates.addDecl(*ToFTDOrErr);
3476 else
3477 return ToFTDOrErr.takeError();
3478 }
3479
3480 // Import TemplateArgumentListInfo.
3481 TemplateArgumentListInfo ToTAInfo;
3482 const auto *FromTAArgsAsWritten = FromInfo->TemplateArgumentsAsWritten;
3483 if (FromTAArgsAsWritten)
3484 if (Error Err =
3485 ImportTemplateArgumentListInfo(*FromTAArgsAsWritten, ToTAInfo))
3486 return Err;
3487
3489 Importer.getToContext(), Candidates,
3490 FromTAArgsAsWritten ? &ToTAInfo : nullptr);
3491 return Error::success();
3492 }
3493 }
3494 llvm_unreachable("All cases should be covered!");
3495}
3496
3499 auto FunctionAndArgsOrErr =
3501 if (!FunctionAndArgsOrErr)
3502 return FunctionAndArgsOrErr.takeError();
3503
3504 FunctionTemplateDecl *Template;
3505 TemplateArgsTy ToTemplArgs;
3506 std::tie(Template, ToTemplArgs) = *FunctionAndArgsOrErr;
3507 void *InsertPos = nullptr;
3508 auto *FoundSpec = Template->findSpecialization(ToTemplArgs, InsertPos);
3509 return FoundSpec;
3510}
3511
3513 FunctionDecl *ToFD) {
3514 if (Stmt *FromBody = FromFD->getBody()) {
3515 if (ExpectedStmt ToBodyOrErr = import(FromBody))
3516 ToFD->setBody(*ToBodyOrErr);
3517 else
3518 return ToBodyOrErr.takeError();
3519 }
3520 return Error::success();
3521}
3522
3523// Returns true if the given D has a DeclContext up to the TranslationUnitDecl
3524// which is equal to the given DC, or D is equal to DC.
3525static bool isAncestorDeclContextOf(const DeclContext *DC, const Decl *D) {
3526 const DeclContext *DCi = dyn_cast<DeclContext>(D);
3527 if (!DCi)
3528 DCi = D->getDeclContext();
3529 assert(DCi && "Declaration should have a context");
3530 while (DCi != D->getTranslationUnitDecl()) {
3531 if (DCi == DC)
3532 return true;
3533 DCi = DCi->getParent();
3534 }
3535 return false;
3536}
3537
3538// Check if there is a declaration that has 'DC' as parent context and is
3539// referenced from statement 'S' or one of its children. The search is done in
3540// BFS order through children of 'S'.
3541static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
3542 SmallVector<const Stmt *> ToProcess;
3543 ToProcess.push_back(S);
3544 while (!ToProcess.empty()) {
3545 const Stmt *CurrentS = ToProcess.pop_back_val();
3546 ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
3547 if (const auto *DeclRef = dyn_cast<DeclRefExpr>(CurrentS)) {
3548 if (const Decl *D = DeclRef->getDecl())
3549 if (isAncestorDeclContextOf(DC, D))
3550 return true;
3551 } else if (const auto *E =
3552 dyn_cast_or_null<SubstNonTypeTemplateParmExpr>(CurrentS)) {
3553 if (const Decl *D = E->getAssociatedDecl())
3554 if (isAncestorDeclContextOf(DC, D))
3555 return true;
3556 }
3557 }
3558 return false;
3559}
3560
3561namespace {
3562/// Check if a type has any reference to a declaration that is inside the body
3563/// of a function.
3564/// The \c CheckType(QualType) function should be used to determine
3565/// this property.
3566///
3567/// The type visitor visits one type object only (not recursive).
3568/// To find all referenced declarations we must discover all type objects until
3569/// the canonical type is reached (walk over typedef and similar objects). This
3570/// is done by loop over all "sugar" type objects. For every such type we must
3571/// check all declarations that are referenced from it. For this check the
3572/// visitor is used. In the visit functions all referenced declarations except
3573/// the one that follows in the sugar chain (if any) must be checked. For this
3574/// check the same visitor is re-used (it has no state-dependent data).
3575///
3576/// The visit functions have 3 possible return values:
3577/// - True, found a declaration inside \c ParentDC.
3578/// - False, found declarations only outside \c ParentDC and it is not possible
3579/// to find more declarations (the "sugar" chain does not continue).
3580/// - Empty optional value, found no declarations or only outside \c ParentDC,
3581/// but it is possible to find more declarations in the type "sugar" chain.
3582/// The loop over the "sugar" types can be implemented by using type visit
3583/// functions only (call \c CheckType with the desugared type). With the current
3584/// solution no visit function is needed if the type has only a desugared type
3585/// as data.
3586class IsTypeDeclaredInsideVisitor
3587 : public TypeVisitor<IsTypeDeclaredInsideVisitor, std::optional<bool>> {
3588public:
3589 IsTypeDeclaredInsideVisitor(const FunctionDecl *ParentDC)
3590 : ParentDC(ParentDC) {}
3591
3592 bool CheckType(QualType T) {
3593 // Check the chain of "sugar" types.
3594 // The "sugar" types are typedef or similar types that have the same
3595 // canonical type.
3596 if (std::optional<bool> Res = Visit(T.getTypePtr()))
3597 return *Res;
3598 QualType DsT =
3599 T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3600 while (DsT != T) {
3601 if (std::optional<bool> Res = Visit(DsT.getTypePtr()))
3602 return *Res;
3603 T = DsT;
3604 DsT = T.getSingleStepDesugaredType(ParentDC->getParentASTContext());
3605 }
3606 return false;
3607 }
3608
3609 std::optional<bool> VisitTagType(const TagType *T) {
3610 if (auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(T->getDecl()))
3611 for (const auto &Arg : Spec->getTemplateArgs().asArray())
3612 if (checkTemplateArgument(Arg))
3613 return true;
3614 return isAncestorDeclContextOf(ParentDC, T->getDecl());
3615 }
3616
3617 std::optional<bool> VisitPointerType(const PointerType *T) {
3618 return CheckType(T->getPointeeType());
3619 }
3620
3621 std::optional<bool> VisitReferenceType(const ReferenceType *T) {
3622 return CheckType(T->getPointeeTypeAsWritten());
3623 }
3624
3625 std::optional<bool> VisitTypedefType(const TypedefType *T) {
3626 const TypedefNameDecl *TD = T->getDecl();
3627 assert(TD);
3628 return isAncestorDeclContextOf(ParentDC, TD);
3629 }
3630
3631 std::optional<bool> VisitUsingType(const UsingType *T) {
3632 if (T->getFoundDecl() &&
3633 isAncestorDeclContextOf(ParentDC, T->getFoundDecl()))
3634 return true;
3635
3636 return {};
3637 }
3638
3639 std::optional<bool>
3640 VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
3641 for (const auto &Arg : T->template_arguments())
3642 if (checkTemplateArgument(Arg))
3643 return true;
3644 // This type is a "sugar" to a record type, it can have a desugared type.
3645 return {};
3646 }
3647
3648 std::optional<bool> VisitUnaryTransformType(const UnaryTransformType *T) {
3649 return CheckType(T->getBaseType());
3650 }
3651
3652 std::optional<bool>
3653 VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T) {
3654 // The "associated declaration" can be the same as ParentDC.
3655 if (isAncestorDeclContextOf(ParentDC, T->getAssociatedDecl()))
3656 return true;
3657 return {};
3658 }
3659
3660 std::optional<bool> VisitConstantArrayType(const ConstantArrayType *T) {
3661 if (T->getSizeExpr() && isAncestorDeclContextOf(ParentDC, T->getSizeExpr()))
3662 return true;
3663
3664 return CheckType(T->getElementType());
3665 }
3666
3667 std::optional<bool> VisitVariableArrayType(const VariableArrayType *T) {
3668 llvm_unreachable(
3669 "Variable array should not occur in deduced return type of a function");
3670 }
3671
3672 std::optional<bool> VisitIncompleteArrayType(const IncompleteArrayType *T) {
3673 llvm_unreachable("Incomplete array should not occur in deduced return type "
3674 "of a function");
3675 }
3676
3677 std::optional<bool> VisitDependentArrayType(const IncompleteArrayType *T) {
3678 llvm_unreachable("Dependent array should not occur in deduced return type "
3679 "of a function");
3680 }
3681
3682private:
3683 const DeclContext *const ParentDC;
3684
3685 bool checkTemplateArgument(const TemplateArgument &Arg) {
3686 switch (Arg.getKind()) {
3688 return false;
3690 return CheckType(Arg.getIntegralType());
3692 return CheckType(Arg.getAsType());
3694 return isAncestorDeclContextOf(ParentDC, Arg.getAsExpr());
3696 // FIXME: The declaration in this case is not allowed to be in a function?
3697 return isAncestorDeclContextOf(ParentDC, Arg.getAsDecl());
3699 // FIXME: The type is not allowed to be in the function?
3700 return CheckType(Arg.getNullPtrType());
3702 return CheckType(Arg.getStructuralValueType());
3704 for (const auto &PackArg : Arg.getPackAsArray())
3705 if (checkTemplateArgument(PackArg))
3706 return true;
3707 return false;
3709 // Templates can not be defined locally in functions.
3710 // A template passed as argument can be not in ParentDC.
3711 return false;
3713 // Templates can not be defined locally in functions.
3714 // A template passed as argument can be not in ParentDC.
3715 return false;
3716 }
3717 llvm_unreachable("Unknown TemplateArgument::ArgKind enum");
3718 };
3719};
3720} // namespace
3721
3722/// This function checks if the given function has a return type that contains
3723/// a reference (in any way) to a declaration inside the same function.
3725 QualType FromTy = D->getType();
3726 const auto *FromFPT = FromTy->getAs<FunctionProtoType>();
3727 assert(FromFPT && "Must be called on FunctionProtoType");
3728
3729 auto IsCXX11Lambda = [&]() {
3730 if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later
3731 return false;
3732
3733 return isLambdaMethod(D);
3734 };
3735
3736 QualType RetT = FromFPT->getReturnType();
3737 if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11Lambda()) {
3738 FunctionDecl *Def = D->getDefinition();
3739 IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D);
3740 return Visitor.CheckType(RetT);
3741 }
3742
3743 return false;
3744}
3745
3747ASTNodeImporter::importExplicitSpecifier(Error &Err, ExplicitSpecifier ESpec) {
3748 Expr *ExplicitExpr = ESpec.getExpr();
3749 if (ExplicitExpr)
3750 ExplicitExpr = importChecked(Err, ESpec.getExpr());
3751 return ExplicitSpecifier(ExplicitExpr, ESpec.getKind());
3752}
3753
3755
3757 auto RedeclIt = Redecls.begin();
3758 // Import the first part of the decl chain. I.e. import all previous
3759 // declarations starting from the canonical decl.
3760 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
3761 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
3762 if (!ToRedeclOrErr)
3763 return ToRedeclOrErr.takeError();
3764 }
3765 assert(*RedeclIt == D);
3766
3767 // Import the major distinguishing characteristics of this function.
3768 DeclContext *DC, *LexicalDC;
3769 DeclarationName Name;
3771 NamedDecl *ToD;
3772 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
3773 return std::move(Err);
3774 if (ToD)
3775 return ToD;
3776
3777 FunctionDecl *FoundByLookup = nullptr;
3778 FunctionTemplateDecl *FromFT = D->getDescribedFunctionTemplate();
3779
3780 // If this is a function template specialization, then try to find the same
3781 // existing specialization in the "to" context. The lookup below will not
3782 // find any specialization, but would find the primary template; thus, we
3783 // have to skip normal lookup in case of specializations.
3784 // FIXME handle member function templates (TK_MemberSpecialization) similarly?
3785 if (D->getTemplatedKind() ==
3787 auto FoundFunctionOrErr = FindFunctionTemplateSpecialization(D);
3788 if (!FoundFunctionOrErr)
3789 return FoundFunctionOrErr.takeError();
3790 if (FunctionDecl *FoundFunction = *FoundFunctionOrErr) {
3791 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3792 return Def;
3793 FoundByLookup = FoundFunction;
3794 }
3795 }
3796 // Try to find a function in our own ("to") context with the same name, same
3797 // type, and in the same context as the function we're importing.
3798 else if (!LexicalDC->isFunctionOrMethod()) {
3799 SmallVector<NamedDecl *, 4> ConflictingDecls;
3801 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
3802 for (auto *FoundDecl : FoundDecls) {
3803 if (!FoundDecl->isInIdentifierNamespace(IDNS))
3804 continue;
3805
3806 if (auto *FoundFunction = dyn_cast<FunctionDecl>(FoundDecl)) {
3807 if (!hasSameVisibilityContextAndLinkage(FoundFunction, D))
3808 continue;
3809
3810 if (IsStructuralMatch(D, FoundFunction)) {
3811 if (Decl *Def = FindAndMapDefinition(D, FoundFunction))
3812 return Def;
3813 FoundByLookup = FoundFunction;
3814 break;
3815 }
3816 // FIXME: Check for overloading more carefully, e.g., by boosting
3817 // Sema::IsOverload out to the AST library.
3818
3819 // Function overloading is okay in C++.
3820 if (Importer.getToContext().getLangOpts().CPlusPlus)
3821 continue;
3822
3823 // Complain about inconsistent function types.
3824 Importer.ToDiag(Loc, diag::warn_odr_function_type_inconsistent)
3825 << Name << D->getType() << FoundFunction->getType();
3826 Importer.ToDiag(FoundFunction->getLocation(), diag::note_odr_value_here)
3827 << FoundFunction->getType();
3828 ConflictingDecls.push_back(FoundDecl);
3829 }
3830 }
3831
3832 if (!ConflictingDecls.empty()) {
3833 ExpectedName NameOrErr = Importer.HandleNameConflict(
3834 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
3835 if (NameOrErr)
3836 Name = NameOrErr.get();
3837 else
3838 return NameOrErr.takeError();
3839 }
3840 }
3841
3842 // We do not allow more than one in-class declaration of a function. This is
3843 // because AST clients like VTableBuilder asserts on this. VTableBuilder
3844 // assumes there is only one in-class declaration. Building a redecl
3845 // chain would result in more than one in-class declaration for
3846 // overrides (even if they are part of the same redecl chain inside the
3847 // derived class.)
3848 if (FoundByLookup) {
3849 if (isa<CXXMethodDecl>(FoundByLookup)) {
3850 if (D->getLexicalDeclContext() == D->getDeclContext()) {
3851 if (!D->doesThisDeclarationHaveABody()) {
3852 if (FunctionTemplateDecl *DescribedD =
3853 D->getDescribedFunctionTemplate()) {
3854 // Handle a "templated" function together with its described
3855 // template. This avoids need for a similar check at import of the
3856 // described template.
3857 assert(FoundByLookup->getDescribedFunctionTemplate() &&
3858 "Templated function mapped to non-templated?");
3859 Importer.MapImported(DescribedD,
3860 FoundByLookup->getDescribedFunctionTemplate());
3861 }
3862 return Importer.MapImported(D, FoundByLookup);
3863 } else {
3864 // Let's continue and build up the redecl chain in this case.
3865 // FIXME Merge the functions into one decl.
3866 }
3867 }
3868 }
3869 }
3870
3871 DeclarationNameInfo NameInfo(Name, Loc);
3872 // Import additional name location/type info.
3873 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
3874 return std::move(Err);
3875
3876 QualType FromTy = D->getType();
3877 TypeSourceInfo *FromTSI = D->getTypeSourceInfo();
3878 // Set to true if we do not import the type of the function as is. There are
3879 // cases when the original type would result in an infinite recursion during
3880 // the import. To avoid an infinite recursion when importing, we create the
3881 // FunctionDecl with a simplified function type and update it only after the
3882 // relevant AST nodes are already imported.
3883 // The type is related to TypeSourceInfo (it references the type), so we must
3884 // do the same with TypeSourceInfo.
3885 bool UsedDifferentProtoType = false;
3886 if (const auto *FromFPT = FromTy->getAs<FunctionProtoType>()) {
3887 QualType FromReturnTy = FromFPT->getReturnType();
3888 // Functions with auto return type may define a struct inside their body
3889 // and the return type could refer to that struct.
3890 // E.g.: auto foo() { struct X{}; return X(); }
3891 // To avoid an infinite recursion when importing, create the FunctionDecl
3892 // with a simplified return type.
3894 FromReturnTy = Importer.getFromContext().VoidTy;
3895 UsedDifferentProtoType = true;
3896 }
3897 FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
3898 // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
3899 // FunctionDecl that we are importing the FunctionProtoType for.
3900 // To avoid an infinite recursion when importing, create the FunctionDecl
3901 // with a simplified function type.
3902 if (FromEPI.ExceptionSpec.SourceDecl ||
3903 FromEPI.ExceptionSpec.SourceTemplate ||
3904 FromEPI.ExceptionSpec.NoexceptExpr) {
3906 FromEPI = DefaultEPI;
3907 UsedDifferentProtoType = true;
3908 }
3909 FromTy = Importer.getFromContext().getFunctionType(
3910 FromReturnTy, FromFPT->getParamTypes(), FromEPI);
3911 FromTSI = Importer.getFromContext().getTrivialTypeSourceInfo(
3912 FromTy, D->getBeginLoc());
3913 }
3914
3915 Error Err = Error::success();
3916 auto T = importChecked(Err, FromTy);
3917 auto TInfo = importChecked(Err, FromTSI);
3918 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
3919 auto ToEndLoc = importChecked(Err, D->getEndLoc());
3920 auto ToDefaultLoc = importChecked(Err, D->getDefaultLoc());
3921 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
3922 auto TrailingRequiresClause =
3923 importChecked(Err, D->getTrailingRequiresClause());
3924 if (Err)
3925 return std::move(Err);
3926
3927 // Import the function parameters.
3929 for (auto *P : D->parameters()) {
3930 if (Expected<ParmVarDecl *> ToPOrErr = import(P))
3931 Parameters.push_back(*ToPOrErr);
3932 else
3933 return ToPOrErr.takeError();
3934 }
3935
3936 // Create the imported function.
3937 FunctionDecl *ToFunction = nullptr;
3938 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
3939 ExplicitSpecifier ESpec =
3940 importExplicitSpecifier(Err, FromConstructor->getExplicitSpecifier());
3941 if (Err)
3942 return std::move(Err);
3943 auto ToInheritedConstructor = InheritedConstructor();
3944 if (FromConstructor->isInheritingConstructor()) {
3945 Expected<InheritedConstructor> ImportedInheritedCtor =
3946 import(FromConstructor->getInheritedConstructor());
3947 if (!ImportedInheritedCtor)
3948 return ImportedInheritedCtor.takeError();
3949 ToInheritedConstructor = *ImportedInheritedCtor;
3950 }
3951 if (GetImportedOrCreateDecl<CXXConstructorDecl>(
3952 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3953 ToInnerLocStart, NameInfo, T, TInfo, ESpec, D->UsesFPIntrin(),
3954 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3955 ToInheritedConstructor, TrailingRequiresClause))
3956 return ToFunction;
3957 } else if (CXXDestructorDecl *FromDtor = dyn_cast<CXXDestructorDecl>(D)) {
3958
3959 Error Err = Error::success();
3960 auto ToOperatorDelete = importChecked(
3961 Err, const_cast<FunctionDecl *>(FromDtor->getOperatorDelete()));
3962 auto ToThisArg = importChecked(Err, FromDtor->getOperatorDeleteThisArg());
3963 if (Err)
3964 return std::move(Err);
3965
3966 if (GetImportedOrCreateDecl<CXXDestructorDecl>(
3967 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3968 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3969 D->isInlineSpecified(), D->isImplicit(), D->getConstexprKind(),
3970 TrailingRequiresClause))
3971 return ToFunction;
3972
3973 CXXDestructorDecl *ToDtor = cast<CXXDestructorDecl>(ToFunction);
3974
3975 ToDtor->setOperatorDelete(ToOperatorDelete, ToThisArg);
3976 } else if (CXXConversionDecl *FromConversion =
3977 dyn_cast<CXXConversionDecl>(D)) {
3978 ExplicitSpecifier ESpec =
3979 importExplicitSpecifier(Err, FromConversion->getExplicitSpecifier());
3980 if (Err)
3981 return std::move(Err);
3982 if (GetImportedOrCreateDecl<CXXConversionDecl>(
3983 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3984 ToInnerLocStart, NameInfo, T, TInfo, D->UsesFPIntrin(),
3985 D->isInlineSpecified(), ESpec, D->getConstexprKind(),
3986 SourceLocation(), TrailingRequiresClause))
3987 return ToFunction;
3988 } else if (auto *Method = dyn_cast<CXXMethodDecl>(D)) {
3989 if (GetImportedOrCreateDecl<CXXMethodDecl>(
3990 ToFunction, D, Importer.getToContext(), cast<CXXRecordDecl>(DC),
3991 ToInnerLocStart, NameInfo, T, TInfo, Method->getStorageClass(),
3992 Method->UsesFPIntrin(), Method->isInlineSpecified(),
3993 D->getConstexprKind(), SourceLocation(), TrailingRequiresClause))
3994 return ToFunction;
3995 } else if (auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) {
3996 ExplicitSpecifier ESpec =
3997 importExplicitSpecifier(Err, Guide->getExplicitSpecifier());
3998 CXXConstructorDecl *Ctor =
3999 importChecked(Err, Guide->getCorrespondingConstructor());
4000 const CXXDeductionGuideDecl *SourceDG =
4001 importChecked(Err, Guide->getSourceDeductionGuide());
4002 if (Err)
4003 return std::move(Err);
4004 if (GetImportedOrCreateDecl<CXXDeductionGuideDecl>(
4005 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart, ESpec,
4006 NameInfo, T, TInfo, ToEndLoc, Ctor,
4007 Guide->getDeductionCandidateKind(), TrailingRequiresClause,
4008 SourceDG, Guide->getSourceDeductionGuideKind()))
4009 return ToFunction;
4010 } else {
4011 if (GetImportedOrCreateDecl(
4012 ToFunction, D, Importer.getToContext(), DC, ToInnerLocStart,
4013 NameInfo, T, TInfo, D->getStorageClass(), D->UsesFPIntrin(),
4014 D->isInlineSpecified(), D->hasWrittenPrototype(),
4015 D->getConstexprKind(), TrailingRequiresClause))
4016 return ToFunction;
4017 }
4018
4019 // Connect the redecl chain.
4020 if (FoundByLookup) {
4021 auto *Recent = const_cast<FunctionDecl *>(
4022 FoundByLookup->getMostRecentDecl());
4023 ToFunction->setPreviousDecl(Recent);
4024 // FIXME Probably we should merge exception specifications. E.g. In the
4025 // "To" context the existing function may have exception specification with
4026 // noexcept-unevaluated, while the newly imported function may have an
4027 // evaluated noexcept. A call to adjustExceptionSpec() on the imported
4028 // decl and its redeclarations may be required.
4029 }
4030
4031 StringLiteral *Msg = D->getDeletedMessage();
4032 if (Msg) {
4033 auto Imported = import(Msg);
4034 if (!Imported)
4035 return Imported.takeError();
4036 Msg = *Imported;
4037 }
4038
4039 ToFunction->setQualifierInfo(ToQualifierLoc);
4040 ToFunction->setAccess(D->getAccess());
4041 ToFunction->setLexicalDeclContext(LexicalDC);
4042 ToFunction->setVirtualAsWritten(D->isVirtualAsWritten());
4043 ToFunction->setTrivial(D->isTrivial());
4044 ToFunction->setIsPureVirtual(D->isPureVirtual());
4045 ToFunction->setDefaulted(D->isDefaulted());
4046 ToFunction->setExplicitlyDefaulted(D->isExplicitlyDefaulted());
4047 ToFunction->setDeletedAsWritten(D->isDeletedAsWritten());
4049 D->FriendConstraintRefersToEnclosingTemplate());
4050 ToFunction->setRangeEnd(ToEndLoc);
4051 ToFunction->setDefaultLoc(ToDefaultLoc);
4052
4053 if (Msg)
4054 ToFunction->setDefaultedOrDeletedInfo(
4056 Importer.getToContext(), {}, Msg));
4057
4058 // Set the parameters.
4059 for (auto *Param : Parameters) {
4060 Param->setOwningFunction(ToFunction);
4061 ToFunction->addDeclInternal(Param);
4062 if (ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable())
4063 LT->update(Param, Importer.getToContext().getTranslationUnitDecl());
4064 }
4065 ToFunction->setParams(Parameters);
4066
4067 // We need to complete creation of FunctionProtoTypeLoc manually with setting
4068 // params it refers to.
4069 if (TInfo) {
4070 if (auto ProtoLoc =
4071 TInfo->getTypeLoc().IgnoreParens().getAs<FunctionProtoTypeLoc>()) {
4072 for (unsigned I = 0, N = Parameters.size(); I != N; ++I)
4073 ProtoLoc.setParam(I, Parameters[I]);
4074 }
4075 }
4076
4077 // Import the describing template function, if any.
4078 if (FromFT) {
4079 auto ToFTOrErr = import(FromFT);
4080 if (!ToFTOrErr)
4081 return ToFTOrErr.takeError();
4082 }
4083
4084 // Import Ctor initializers.
4085 if (auto *FromConstructor = dyn_cast<CXXConstructorDecl>(D)) {
4086 if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
4087 SmallVector<CXXCtorInitializer *, 4> CtorInitializers(NumInitializers);
4088 // Import first, then allocate memory and copy if there was no error.
4089 if (Error Err = ImportContainerChecked(
4090 FromConstructor->inits(), CtorInitializers))
4091 return std::move(Err);
4092 auto **Memory =
4093 new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
4094 std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
4095 auto *ToCtor = cast<CXXConstructorDecl>(ToFunction);
4096 ToCtor->setCtorInitializers(Memory);
4097 ToCtor->setNumCtorInitializers(NumInitializers);
4098 }
4099 }
4100
4101 // If it is a template, import all related things.
4102 if (Error Err = ImportTemplateInformation(D, ToFunction))
4103 return std::move(Err);
4104
4105 if (auto *FromCXXMethod = dyn_cast<CXXMethodDecl>(D))
4106 if (Error Err = ImportOverriddenMethods(cast<CXXMethodDecl>(ToFunction),
4107 FromCXXMethod))
4108 return std::move(Err);
4109
4110 if (D->doesThisDeclarationHaveABody()) {
4111 Error Err = ImportFunctionDeclBody(D, ToFunction);
4112
4113 if (Err)
4114 return std::move(Err);
4115 }
4116
4117 // Import and set the original type in case we used another type.
4118 if (UsedDifferentProtoType) {
4119 if (ExpectedType TyOrErr = import(D->getType()))
4120 ToFunction->setType(*TyOrErr);
4121 else
4122 return TyOrErr.takeError();
4123 if (Expected<TypeSourceInfo *> TSIOrErr = import(D->getTypeSourceInfo()))
4124 ToFunction->setTypeSourceInfo(*TSIOrErr);
4125 else
4126 return TSIOrErr.takeError();
4127 }
4128
4129 // FIXME: Other bits to merge?
4130
4131 addDeclToContexts(D, ToFunction);
4132
4133 // Import the rest of the chain. I.e. import all subsequent declarations.
4134 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4135 ExpectedDecl ToRedeclOrErr = import(*RedeclIt);
4136 if (!ToRedeclOrErr)
4137 return ToRedeclOrErr.takeError();
4138 }
4139
4140 return ToFunction;
4141}
4142
4144 return VisitFunctionDecl(D);
4145}
4146
4148 return VisitCXXMethodDecl(D);
4149}
4150
4152 return VisitCXXMethodDecl(D);
4153}
4154
4156 return VisitCXXMethodDecl(D);
4157}
4158
4161 return VisitFunctionDecl(D);
4162}
4163
4165 // Import the major distinguishing characteristics of a variable.
4166 DeclContext *DC, *LexicalDC;
4167 DeclarationName Name;
4169 NamedDecl *ToD;
4170 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4171 return std::move(Err);
4172 if (ToD)
4173 return ToD;
4174
4175 // Determine whether we've already imported this field.
4176 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4177 for (auto *FoundDecl : FoundDecls) {
4178 if (FieldDecl *FoundField = dyn_cast<FieldDecl>(FoundDecl)) {
4179 // For anonymous fields, match up by index.
4180 if (!Name &&
4182 ASTImporter::getFieldIndex(FoundField))
4183 continue;
4184
4185 if (Importer.IsStructurallyEquivalent(D->getType(),
4186 FoundField->getType())) {
4187 Importer.MapImported(D, FoundField);
4188 // In case of a FieldDecl of a ClassTemplateSpecializationDecl, the
4189 // initializer of a FieldDecl might not had been instantiated in the
4190 // "To" context. However, the "From" context might instantiated that,
4191 // thus we have to merge that.
4192 // Note: `hasInClassInitializer()` is not the same as non-null
4193 // `getInClassInitializer()` value.
4194 if (Expr *FromInitializer = D->getInClassInitializer()) {
4195 if (ExpectedExpr ToInitializerOrErr = import(FromInitializer)) {
4196 // Import of the FromInitializer may result in the setting of
4197 // InClassInitializer. If not, set it here.
4198 assert(FoundField->hasInClassInitializer() &&
4199 "Field should have an in-class initializer if it has an "
4200 "expression for it.");
4201 if (!FoundField->getInClassInitializer())
4202 FoundField->setInClassInitializer(*ToInitializerOrErr);
4203 } else {
4204 return ToInitializerOrErr.takeError();
4205 }
4206 }
4207 return FoundField;
4208 }
4209
4210 // FIXME: Why is this case not handled with calling HandleNameConflict?
4211 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4212 << Name << D->getType() << FoundField->getType();
4213 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4214 << FoundField->getType();
4215
4216 return make_error<ASTImportError>(ASTImportError::NameConflict);
4217 }
4218 }
4219
4220 Error Err = Error::success();
4221 auto ToType = importChecked(Err, D->getType());
4222 auto ToTInfo = importChecked(Err, D->getTypeSourceInfo());
4223 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4224 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4225 if (Err)
4226 return std::move(Err);
4227 const Type *ToCapturedVLAType = nullptr;
4228 if (Error Err = Importer.importInto(
4229 ToCapturedVLAType, cast_or_null<Type>(D->getCapturedVLAType())))
4230 return std::move(Err);
4231
4232 FieldDecl *ToField;
4233 if (GetImportedOrCreateDecl(ToField, D, Importer.getToContext(), DC,
4234 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4235 ToType, ToTInfo, ToBitWidth, D->isMutable(),
4236 D->getInClassInitStyle()))
4237 return ToField;
4238
4239 ToField->setAccess(D->getAccess());
4240 ToField->setLexicalDeclContext(LexicalDC);
4241 ToField->setImplicit(D->isImplicit());
4242 if (ToCapturedVLAType)
4243 ToField->setCapturedVLAType(cast<VariableArrayType>(ToCapturedVLAType));
4244 LexicalDC->addDeclInternal(ToField);
4245 // Import initializer only after the field was created, it may have recursive
4246 // reference to the field.
4247 auto ToInitializer = importChecked(Err, D->getInClassInitializer());
4248 if (Err)
4249 return std::move(Err);
4250 if (ToInitializer) {
4251 auto *AlreadyImported = ToField->getInClassInitializer();
4252 if (AlreadyImported)
4253 assert(ToInitializer == AlreadyImported &&
4254 "Duplicate import of in-class initializer.");
4255 else
4256 ToField->setInClassInitializer(ToInitializer);
4257 }
4258
4259 return ToField;
4260}
4261
4263 // Import the major distinguishing characteristics of a variable.
4264 DeclContext *DC, *LexicalDC;
4265 DeclarationName Name;
4267 NamedDecl *ToD;
4268 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4269 return std::move(Err);
4270 if (ToD)
4271 return ToD;
4272
4273 // Determine whether we've already imported this field.
4274 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4275 for (unsigned I = 0, N = FoundDecls.size(); I != N; ++I) {
4276 if (auto *FoundField = dyn_cast<IndirectFieldDecl>(FoundDecls[I])) {
4277 // For anonymous indirect fields, match up by index.
4278 if (!Name &&
4280 ASTImporter::getFieldIndex(FoundField))
4281 continue;
4282
4283 if (Importer.IsStructurallyEquivalent(D->getType(),
4284 FoundField->getType(),
4285 !Name.isEmpty())) {
4286 Importer.MapImported(D, FoundField);
4287 return FoundField;
4288 }
4289
4290 // If there are more anonymous fields to check, continue.
4291 if (!Name && I < N-1)
4292 continue;
4293
4294 // FIXME: Why is this case not handled with calling HandleNameConflict?
4295 Importer.ToDiag(Loc, diag::warn_odr_field_type_inconsistent)
4296 << Name << D->getType() << FoundField->getType();
4297 Importer.ToDiag(FoundField->getLocation(), diag::note_odr_value_here)
4298 << FoundField->getType();
4299
4300 return make_error<ASTImportError>(ASTImportError::NameConflict);
4301 }
4302 }
4303
4304 // Import the type.
4305 auto TypeOrErr = import(D->getType());
4306 if (!TypeOrErr)
4307 return TypeOrErr.takeError();
4308
4309 auto **NamedChain =
4310 new (Importer.getToContext()) NamedDecl*[D->getChainingSize()];
4311
4312 unsigned i = 0;
4313 for (auto *PI : D->chain())
4314 if (Expected<NamedDecl *> ToD = import(PI))
4315 NamedChain[i++] = *ToD;
4316 else
4317 return ToD.takeError();
4318
4319 llvm::MutableArrayRef<NamedDecl *> CH = {NamedChain, D->getChainingSize()};
4320 IndirectFieldDecl *ToIndirectField;
4321 if (GetImportedOrCreateDecl(ToIndirectField, D, Importer.getToContext(), DC,
4322 Loc, Name.getAsIdentifierInfo(), *TypeOrErr, CH))
4323 // FIXME here we leak `NamedChain` which is allocated before
4324 return ToIndirectField;
4325
4326 ToIndirectField->setAccess(D->getAccess());
4327 ToIndirectField->setLexicalDeclContext(LexicalDC);
4328 LexicalDC->addDeclInternal(ToIndirectField);
4329 return ToIndirectField;
4330}
4331
4332/// Used as return type of getFriendCountAndPosition.
4334 /// Number of similar looking friends.
4335 unsigned int TotalCount;
4336 /// Index of the specific FriendDecl.
4337 unsigned int IndexOfDecl;
4338};
4339
4340static bool IsEquivalentFriend(ASTImporter &Importer, FriendDecl *FD1,
4341 FriendDecl *FD2) {
4342 if ((!FD1->getFriendType()) != (!FD2->getFriendType()))
4343 return false;
4344
4345 if (const TypeSourceInfo *TSI = FD1->getFriendType())
4346 return Importer.IsStructurallyEquivalent(
4347 TSI->getType(), FD2->getFriendType()->getType(), /*Complain=*/false);
4348
4349 ASTImporter::NonEquivalentDeclSet NonEquivalentDecls;
4351 FD1->getASTContext(), FD2->getASTContext(), NonEquivalentDecls,
4353 /* StrictTypeSpelling = */ false, /* Complain = */ false);
4354 return Ctx.IsEquivalent(FD1, FD2);
4355}
4356
4358 FriendDecl *FD) {
4359 unsigned int FriendCount = 0;
4360 std::optional<unsigned int> FriendPosition;
4361 const auto *RD = cast<CXXRecordDecl>(FD->getLexicalDeclContext());
4362
4363 for (FriendDecl *FoundFriend : RD->friends()) {
4364 if (FoundFriend == FD) {
4365 FriendPosition = FriendCount;
4366 ++FriendCount;
4367 } else if (IsEquivalentFriend(Importer, FD, FoundFriend)) {
4368 ++FriendCount;
4369 }
4370 }
4371
4372 assert(FriendPosition && "Friend decl not found in own parent.");
4373
4374 return {FriendCount, *FriendPosition};
4375}
4376
4378 // Import the major distinguishing characteristics of a declaration.
4379 DeclContext *DC, *LexicalDC;
4380 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
4381 return std::move(Err);
4382
4383 // Determine whether we've already imported this decl.
4384 // FriendDecl is not a NamedDecl so we cannot use lookup.
4385 // We try to maintain order and count of redundant friend declarations.
4386 const auto *RD = cast<CXXRecordDecl>(DC);
4387 SmallVector<FriendDecl *, 2> ImportedEquivalentFriends;
4388 for (FriendDecl *ImportedFriend : RD->friends())
4389 if (IsEquivalentFriend(Importer, D, ImportedFriend))
4390 ImportedEquivalentFriends.push_back(ImportedFriend);
4391
4392 FriendCountAndPosition CountAndPosition =
4393 getFriendCountAndPosition(Importer, D);
4394
4395 assert(ImportedEquivalentFriends.size() <= CountAndPosition.TotalCount &&
4396 "Class with non-matching friends is imported, ODR check wrong?");
4397 if (ImportedEquivalentFriends.size() == CountAndPosition.TotalCount)
4398 return Importer.MapImported(
4399 D, ImportedEquivalentFriends[CountAndPosition.IndexOfDecl]);
4400
4401 // Not found. Create it.
4402 // The declarations will be put into order later by ImportDeclContext.
4404 if (NamedDecl *FriendD = D->getFriendDecl()) {
4405 NamedDecl *ToFriendD;
4406 if (Error Err = importInto(ToFriendD, FriendD))
4407 return std::move(Err);
4408
4409 if (FriendD->getFriendObjectKind() != Decl::FOK_None &&
4410 !(FriendD->isInIdentifierNamespace(Decl::IDNS_NonMemberOperator)))
4411 ToFriendD->setObjectOfFriendDecl(false);
4412
4413 ToFU = ToFriendD;
4414 } else { // The friend is a type, not a decl.
4415 if (auto TSIOrErr = import(D->getFriendType()))
4416 ToFU = *TSIOrErr;
4417 else
4418 return TSIOrErr.takeError();
4419 }
4420
4421 SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4422 auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4423 for (unsigned I = 0; I < D->NumTPLists; I++) {
4424 if (auto ListOrErr = import(FromTPLists[I]))
4425 ToTPLists[I] = *ListOrErr;
4426 else
4427 return ListOrErr.takeError();
4428 }
4429
4430 auto LocationOrErr = import(D->getLocation());
4431 if (!LocationOrErr)
4432 return LocationOrErr.takeError();
4433 auto FriendLocOrErr = import(D->getFriendLoc());
4434 if (!FriendLocOrErr)
4435 return FriendLocOrErr.takeError();
4436 auto EllipsisLocOrErr = import(D->getEllipsisLoc());
4437 if (!EllipsisLocOrErr)
4438 return EllipsisLocOrErr.takeError();
4439
4440 FriendDecl *FrD;
4441 if (GetImportedOrCreateDecl(FrD, D, Importer.getToContext(), DC,
4442 *LocationOrErr, ToFU, *FriendLocOrErr,
4443 *EllipsisLocOrErr, ToTPLists))
4444 return FrD;
4445
4446 FrD->setAccess(D->getAccess());
4447 FrD->setLexicalDeclContext(LexicalDC);
4448 LexicalDC->addDeclInternal(FrD);
4449 return FrD;
4450}
4451
4453 // Import the major distinguishing characteristics of an ivar.
4454 DeclContext *DC, *LexicalDC;
4455 DeclarationName Name;
4457 NamedDecl *ToD;
4458 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4459 return std::move(Err);
4460 if (ToD)
4461 return ToD;
4462
4463 // Determine whether we've already imported this ivar
4464 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4465 for (auto *FoundDecl : FoundDecls) {
4466 if (ObjCIvarDecl *FoundIvar = dyn_cast<ObjCIvarDecl>(FoundDecl)) {
4467 if (Importer.IsStructurallyEquivalent(D->getType(),
4468 FoundIvar->getType())) {
4469 Importer.MapImported(D, FoundIvar);
4470 return FoundIvar;
4471 }
4472
4473 Importer.ToDiag(Loc, diag::warn_odr_ivar_type_inconsistent)
4474 << Name << D->getType() << FoundIvar->getType();
4475 Importer.ToDiag(FoundIvar->getLocation(), diag::note_odr_value_here)
4476 << FoundIvar->getType();
4477
4478 return make_error<ASTImportError>(ASTImportError::NameConflict);
4479 }
4480 }
4481
4482 Error Err = Error::success();
4483 auto ToType = importChecked(Err, D->getType());
4484 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4485 auto ToBitWidth = importChecked(Err, D->getBitWidth());
4486 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4487 if (Err)
4488 return std::move(Err);
4489
4490 ObjCIvarDecl *ToIvar;
4491 if (GetImportedOrCreateDecl(
4492 ToIvar, D, Importer.getToContext(), cast<ObjCContainerDecl>(DC),
4493 ToInnerLocStart, Loc, Name.getAsIdentifierInfo(),
4494 ToType, ToTypeSourceInfo,
4495 D->getAccessControl(),ToBitWidth, D->getSynthesize()))
4496 return ToIvar;
4497
4498 ToIvar->setLexicalDeclContext(LexicalDC);
4499 LexicalDC->addDeclInternal(ToIvar);
4500 return ToIvar;
4501}
4502
4504
4506 auto RedeclIt = Redecls.begin();
4507 // Import the first part of the decl chain. I.e. import all previous
4508 // declarations starting from the canonical decl.
4509 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
4510 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4511 if (!RedeclOrErr)
4512 return RedeclOrErr.takeError();
4513 }
4514 assert(*RedeclIt == D);
4515
4516 // Import the major distinguishing characteristics of a variable.
4517 DeclContext *DC, *LexicalDC;
4518 DeclarationName Name;
4520 NamedDecl *ToD;
4521 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4522 return std::move(Err);
4523 if (ToD)
4524 return ToD;
4525
4526 // Try to find a variable in our own ("to") context with the same name and
4527 // in the same context as the variable we're importing.
4528 VarDecl *FoundByLookup = nullptr;
4529 if (D->isFileVarDecl()) {
4530 SmallVector<NamedDecl *, 4> ConflictingDecls;
4531 unsigned IDNS = Decl::IDNS_Ordinary;
4532 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4533 for (auto *FoundDecl : FoundDecls) {
4534 if (!FoundDecl->isInIdentifierNamespace(IDNS))
4535 continue;
4536
4537 if (auto *FoundVar = dyn_cast<VarDecl>(FoundDecl)) {
4538 if (!hasSameVisibilityContextAndLinkage(FoundVar, D))
4539 continue;
4540 if (Importer.IsStructurallyEquivalent(D->getType(),
4541 FoundVar->getType())) {
4542
4543 // The VarDecl in the "From" context has a definition, but in the
4544 // "To" context we already have a definition.
4545 VarDecl *FoundDef = FoundVar->getDefinition();
4546 if (D->isThisDeclarationADefinition() && FoundDef)
4547 // FIXME Check for ODR error if the two definitions have
4548 // different initializers?
4549 return Importer.MapImported(D, FoundDef);
4550
4551 // The VarDecl in the "From" context has an initializer, but in the
4552 // "To" context we already have an initializer.
4553 const VarDecl *FoundDInit = nullptr;
4554 if (D->getInit() && FoundVar->getAnyInitializer(FoundDInit))
4555 // FIXME Diagnose ODR error if the two initializers are different?
4556 return Importer.MapImported(D, const_cast<VarDecl*>(FoundDInit));
4557
4558 FoundByLookup = FoundVar;
4559 break;
4560 }
4561
4562 const ArrayType *FoundArray
4563 = Importer.getToContext().getAsArrayType(FoundVar->getType());
4564 const ArrayType *TArray
4565 = Importer.getToContext().getAsArrayType(D->getType());
4566 if (FoundArray && TArray) {
4567 if (isa<IncompleteArrayType>(FoundArray) &&
4568 isa<ConstantArrayType>(TArray)) {
4569 // Import the type.
4570 if (auto TyOrErr = import(D->getType()))
4571 FoundVar->setType(*TyOrErr);
4572 else
4573 return TyOrErr.takeError();
4574
4575 FoundByLookup = FoundVar;
4576 break;
4577 } else if (isa<IncompleteArrayType>(TArray) &&
4578 isa<ConstantArrayType>(FoundArray)) {
4579 FoundByLookup = FoundVar;
4580 break;
4581 }
4582 }
4583
4584 Importer.ToDiag(Loc, diag::warn_odr_variable_type_inconsistent)
4585 << Name << D->getType() << FoundVar->getType();
4586 Importer.ToDiag(FoundVar->getLocation(), diag::note_odr_value_here)
4587 << FoundVar->getType();
4588 ConflictingDecls.push_back(FoundDecl);
4589 }
4590 }
4591
4592 if (!ConflictingDecls.empty()) {
4593 ExpectedName NameOrErr = Importer.HandleNameConflict(
4594 Name, DC, IDNS, ConflictingDecls.data(), ConflictingDecls.size());
4595 if (NameOrErr)
4596 Name = NameOrErr.get();
4597 else
4598 return NameOrErr.takeError();
4599 }
4600 }
4601
4602 Error Err = Error::success();
4603 auto ToType = importChecked(Err, D->getType());
4604 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4605 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4606 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
4607 if (Err)
4608 return std::move(Err);
4609
4610 VarDecl *ToVar;
4611 if (auto *FromDecomp = dyn_cast<DecompositionDecl>(D)) {
4612 SmallVector<BindingDecl *> Bindings(FromDecomp->bindings().size());
4613 if (Error Err =
4614 ImportArrayChecked(FromDecomp->bindings(), Bindings.begin()))
4615 return std::move(Err);
4616 DecompositionDecl *ToDecomp;
4617 if (GetImportedOrCreateDecl(
4618 ToDecomp, FromDecomp, Importer.getToContext(), DC, ToInnerLocStart,
4619 Loc, ToType, ToTypeSourceInfo, D->getStorageClass(), Bindings))
4620 return ToDecomp;
4621 ToVar = ToDecomp;
4622 } else {
4623 // Create the imported variable.
4624 if (GetImportedOrCreateDecl(ToVar, D, Importer.getToContext(), DC,
4625 ToInnerLocStart, Loc,
4626 Name.getAsIdentifierInfo(), ToType,
4627 ToTypeSourceInfo, D->getStorageClass()))
4628 return ToVar;
4629 }
4630
4631 ToVar->setTSCSpec(D->getTSCSpec());
4632 ToVar->setQualifierInfo(ToQualifierLoc);
4633 ToVar->setAccess(D->getAccess());
4634 ToVar->setLexicalDeclContext(LexicalDC);
4635 if (D->isInlineSpecified())
4636 ToVar->setInlineSpecified();
4637 if (D->isInline())
4638 ToVar->setImplicitlyInline();
4639
4640 if (FoundByLookup) {
4641 auto *Recent = const_cast<VarDecl *>(FoundByLookup->getMostRecentDecl());
4642 ToVar->setPreviousDecl(Recent);
4643 }
4644
4645 // Import the described template, if any.
4646 if (D->getDescribedVarTemplate()) {
4647 auto ToVTOrErr = import(D->getDescribedVarTemplate());
4648 if (!ToVTOrErr)
4649 return ToVTOrErr.takeError();
4650 } else if (MemberSpecializationInfo *MSI = D->getMemberSpecializationInfo()) {
4651 TemplateSpecializationKind SK = MSI->getTemplateSpecializationKind();
4652 VarDecl *FromInst = D->getInstantiatedFromStaticDataMember();
4653 if (Expected<VarDecl *> ToInstOrErr = import(FromInst))
4654 ToVar->setInstantiationOfStaticDataMember(*ToInstOrErr, SK);
4655 else
4656 return ToInstOrErr.takeError();
4657 if (ExpectedSLoc POIOrErr = import(MSI->getPointOfInstantiation()))
4659 else
4660 return POIOrErr.takeError();
4661 }
4662
4663 if (Error Err = ImportInitializer(D, ToVar))
4664 return std::move(Err);
4665
4666 if (D->isConstexpr())
4667 ToVar->setConstexpr(true);
4668
4669 addDeclToContexts(D, ToVar);
4670
4671 // Import the rest of the chain. I.e. import all subsequent declarations.
4672 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
4673 ExpectedDecl RedeclOrErr = import(*RedeclIt);
4674 if (!RedeclOrErr)
4675 return RedeclOrErr.takeError();
4676 }
4677
4678 return ToVar;
4679}
4680
4682 // Parameters are created in the translation unit's context, then moved
4683 // into the function declaration's context afterward.
4685
4686 Error Err = Error::success();
4687 auto ToDeclName = importChecked(Err, D->getDeclName());
4688 auto ToLocation = importChecked(Err, D->getLocation());
4689 auto ToType = importChecked(Err, D->getType());
4690 if (Err)
4691 return std::move(Err);
4692
4693 // Create the imported parameter.
4694 ImplicitParamDecl *ToParm = nullptr;
4695 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4696 ToLocation, ToDeclName.getAsIdentifierInfo(),
4697 ToType, D->getParameterKind()))
4698 return ToParm;
4699 return ToParm;
4700}
4701
4703 const ParmVarDecl *FromParam, ParmVarDecl *ToParam) {
4704
4705 if (auto LocOrErr = import(FromParam->getExplicitObjectParamThisLoc()))
4706 ToParam->setExplicitObjectParameterLoc(*LocOrErr);
4707 else
4708 return LocOrErr.takeError();
4709
4711 ToParam->setKNRPromoted(FromParam->isKNRPromoted());
4712
4713 if (FromParam->hasUninstantiatedDefaultArg()) {
4714 if (auto ToDefArgOrErr = import(FromParam->getUninstantiatedDefaultArg()))
4715 ToParam->setUninstantiatedDefaultArg(*ToDefArgOrErr);
4716 else
4717 return ToDefArgOrErr.takeError();
4718 } else if (FromParam->hasUnparsedDefaultArg()) {
4719 ToParam->setUnparsedDefaultArg();
4720 } else if (FromParam->hasDefaultArg()) {
4721 if (auto ToDefArgOrErr = import(FromParam->getDefaultArg()))
4722 ToParam->setDefaultArg(*ToDefArgOrErr);
4723 else
4724 return ToDefArgOrErr.takeError();
4725 }
4726
4727 return Error::success();
4728}
4729
4732 Error Err = Error::success();
4733 CXXConstructorDecl *ToBaseCtor = importChecked(Err, From.getConstructor());
4734 ConstructorUsingShadowDecl *ToShadow =
4735 importChecked(Err, From.getShadowDecl());
4736 if (Err)
4737 return std::move(Err);
4738 return InheritedConstructor(ToShadow, ToBaseCtor);
4739}
4740
4742 // Parameters are created in the translation unit's context, then moved
4743 // into the function declaration's context afterward.
4745
4746 Error Err = Error::success();
4747 auto ToDeclName = importChecked(Err, D->getDeclName());
4748 auto ToLocation = importChecked(Err, D->getLocation());
4749 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
4750 auto ToType = importChecked(Err, D->getType());
4751 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4752 if (Err)
4753 return std::move(Err);
4754
4755 ParmVarDecl *ToParm;
4756 if (GetImportedOrCreateDecl(ToParm, D, Importer.getToContext(), DC,
4757 ToInnerLocStart, ToLocation,
4758 ToDeclName.getAsIdentifierInfo(), ToType,
4759 ToTypeSourceInfo, D->getStorageClass(),
4760 /*DefaultArg*/ nullptr))
4761 return ToParm;
4762
4763 // Set the default argument. It should be no problem if it was already done.
4764 // Do not import the default expression before GetImportedOrCreateDecl call
4765 // to avoid possible infinite import loop because circular dependency.
4766 if (Error Err = ImportDefaultArgOfParmVarDecl(D, ToParm))
4767 return std::move(Err);
4768
4769 if (D->isObjCMethodParameter()) {
4770 ToParm->setObjCMethodScopeInfo(D->getFunctionScopeIndex());
4771 ToParm->setObjCDeclQualifier(D->getObjCDeclQualifier());
4772 } else {
4773 ToParm->setScopeInfo(D->getFunctionScopeDepth(),
4774 D->getFunctionScopeIndex());
4775 }
4776
4777 return ToParm;
4778}
4779
4781 // Import the major distinguishing characteristics of a method.
4782 DeclContext *DC, *LexicalDC;
4783 DeclarationName Name;
4785 NamedDecl *ToD;
4786 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4787 return std::move(Err);
4788 if (ToD)
4789 return ToD;
4790
4791 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
4792 for (auto *FoundDecl : FoundDecls) {
4793 if (auto *FoundMethod = dyn_cast<ObjCMethodDecl>(FoundDecl)) {
4794 if (FoundMethod->isInstanceMethod() != D->isInstanceMethod())
4795 continue;
4796
4797 // Check return types.
4798 if (!Importer.IsStructurallyEquivalent(D->getReturnType(),
4799 FoundMethod->getReturnType())) {
4800 Importer.ToDiag(Loc, diag::warn_odr_objc_method_result_type_inconsistent)
4801 << D->isInstanceMethod() << Name << D->getReturnType()
4802 << FoundMethod->getReturnType();
4803 Importer.ToDiag(FoundMethod->getLocation(),
4804 diag::note_odr_objc_method_here)
4805 << D->isInstanceMethod() << Name;
4806
4807 return make_error<ASTImportError>(ASTImportError::NameConflict);
4808 }
4809
4810 // Check the number of parameters.
4811 if (D->param_size() != FoundMethod->param_size()) {
4812 Importer.ToDiag(Loc, diag::warn_odr_objc_method_num_params_inconsistent)
4813 << D->isInstanceMethod() << Name
4814 << D->param_size() << FoundMethod->param_size();
4815 Importer.ToDiag(FoundMethod->getLocation(),
4816 diag::note_odr_objc_method_here)
4817 << D->isInstanceMethod() << Name;
4818
4819 return make_error<ASTImportError>(ASTImportError::NameConflict);
4820 }
4821
4822 // Check parameter types.
4823 for (ObjCMethodDecl::param_iterator P = D->param_begin(),
4824 PEnd = D->param_end(), FoundP = FoundMethod->param_begin();
4825 P != PEnd; ++P, ++FoundP) {
4826 if (!Importer.IsStructurallyEquivalent((*P)->getType(),
4827 (*FoundP)->getType())) {
4828 Importer.FromDiag((*P)->getLocation(),
4829 diag::warn_odr_objc_method_param_type_inconsistent)
4830 << D->isInstanceMethod() << Name
4831 << (*P)->getType() << (*FoundP)->getType();
4832 Importer.ToDiag((*FoundP)->getLocation(), diag::note_odr_value_here)
4833 << (*FoundP)->getType();
4834
4835 return make_error<ASTImportError>(ASTImportError::NameConflict);
4836 }
4837 }
4838
4839 // Check variadic/non-variadic.
4840 // Check the number of parameters.
4841 if (D->isVariadic() != FoundMethod->isVariadic()) {
4842 Importer.ToDiag(Loc, diag::warn_odr_objc_method_variadic_inconsistent)
4843 << D->isInstanceMethod() << Name;
4844 Importer.ToDiag(FoundMethod->getLocation(),
4845 diag::note_odr_objc_method_here)
4846 << D->isInstanceMethod() << Name;
4847
4848 return make_error<ASTImportError>(ASTImportError::NameConflict);
4849 }
4850
4851 // FIXME: Any other bits we need to merge?
4852 return Importer.MapImported(D, FoundMethod);
4853 }
4854 }
4855
4856 Error Err = Error::success();
4857 auto ToEndLoc = importChecked(Err, D->getEndLoc());
4858 auto ToReturnType = importChecked(Err, D->getReturnType());
4859 auto ToReturnTypeSourceInfo =
4860 importChecked(Err, D->getReturnTypeSourceInfo());
4861 if (Err)
4862 return std::move(Err);
4863
4864 ObjCMethodDecl *ToMethod;
4865 if (GetImportedOrCreateDecl(
4866 ToMethod, D, Importer.getToContext(), Loc, ToEndLoc,
4867 Name.getObjCSelector(), ToReturnType, ToReturnTypeSourceInfo, DC,
4868 D->isInstanceMethod(), D->isVariadic(), D->isPropertyAccessor(),
4869 D->isSynthesizedAccessorStub(), D->isImplicit(), D->isDefined(),
4870 D->getImplementationControl(), D->hasRelatedResultType()))
4871 return ToMethod;
4872
4873 // FIXME: When we decide to merge method definitions, we'll need to
4874 // deal with implicit parameters.
4875
4876 // Import the parameters
4878 for (auto *FromP : D->parameters()) {
4879 if (Expected<ParmVarDecl *> ToPOrErr = import(FromP))
4880 ToParams.push_back(*ToPOrErr);
4881 else
4882 return ToPOrErr.takeError();
4883 }
4884
4885 // Set the parameters.
4886 for (auto *ToParam : ToParams) {
4887 ToParam->setOwningFunction(ToMethod);
4888 ToMethod->addDeclInternal(ToParam);
4889 }
4890
4892 D->getSelectorLocs(FromSelLocs);
4893 SmallVector<SourceLocation, 12> ToSelLocs(FromSelLocs.size());
4894 if (Error Err = ImportContainerChecked(FromSelLocs, ToSelLocs))
4895 return std::move(Err);
4896
4897 ToMethod->setMethodParams(Importer.getToContext(), ToParams, ToSelLocs);
4898
4899 ToMethod->setLexicalDeclContext(LexicalDC);
4900 LexicalDC->addDeclInternal(ToMethod);
4901
4902 // Implicit params are declared when Sema encounters the definition but this
4903 // never happens when the method is imported. Manually declare the implicit
4904 // params now that the MethodDecl knows its class interface.
4905 if (D->getSelfDecl())
4906 ToMethod->createImplicitParams(Importer.getToContext(),
4907 ToMethod->getClassInterface());
4908
4909 return ToMethod;
4910}
4911
4913 // Import the major distinguishing characteristics of a category.
4914 DeclContext *DC, *LexicalDC;
4915 DeclarationName Name;
4917 NamedDecl *ToD;
4918 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4919 return std::move(Err);
4920 if (ToD)
4921 return ToD;
4922
4923 Error Err = Error::success();
4924 auto ToVarianceLoc = importChecked(Err, D->getVarianceLoc());
4925 auto ToLocation = importChecked(Err, D->getLocation());
4926 auto ToColonLoc = importChecked(Err, D->getColonLoc());
4927 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
4928 if (Err)
4929 return std::move(Err);
4930
4932 if (GetImportedOrCreateDecl(
4933 Result, D, Importer.getToContext(), DC, D->getVariance(),
4934 ToVarianceLoc, D->getIndex(),
4935 ToLocation, Name.getAsIdentifierInfo(),
4936 ToColonLoc, ToTypeSourceInfo))
4937 return Result;
4938
4939 // Only import 'ObjCTypeParamType' after the decl is created.
4940 auto ToTypeForDecl = importChecked(Err, D->getTypeForDecl());
4941 if (Err)
4942 return std::move(Err);
4943 Result->setTypeForDecl(ToTypeForDecl);
4944 Result->setLexicalDeclContext(LexicalDC);
4945 return Result;
4946}
4947
4949 // Import the major distinguishing characteristics of a category.
4950 DeclContext *DC, *LexicalDC;
4951 DeclarationName Name;
4953 NamedDecl *ToD;
4954 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
4955 return std::move(Err);
4956 if (ToD)
4957 return ToD;
4958
4959 ObjCInterfaceDecl *ToInterface;
4960 if (Error Err = importInto(ToInterface, D->getClassInterface()))
4961 return std::move(Err);
4962
4963 // Determine if we've already encountered this category.
4964 ObjCCategoryDecl *MergeWithCategory
4965 = ToInterface->FindCategoryDeclaration(Name.getAsIdentifierInfo());
4966 ObjCCategoryDecl *ToCategory = MergeWithCategory;
4967 if (!ToCategory) {
4968
4969 Error Err = Error::success();
4970 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
4971 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
4972 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
4973 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
4974 if (Err)
4975 return std::move(Err);
4976
4977 if (GetImportedOrCreateDecl(ToCategory, D, Importer.getToContext(), DC,
4978 ToAtStartLoc, Loc,
4979 ToCategoryNameLoc,
4980 Name.getAsIdentifierInfo(), ToInterface,
4981 /*TypeParamList=*/nullptr,
4982 ToIvarLBraceLoc,
4983 ToIvarRBraceLoc))
4984 return ToCategory;
4985
4986 ToCategory->setLexicalDeclContext(LexicalDC);
4987 LexicalDC->addDeclInternal(ToCategory);
4988 // Import the type parameter list after MapImported, to avoid
4989 // loops when bringing in their DeclContext.
4990 if (auto PListOrErr = ImportObjCTypeParamList(D->getTypeParamList()))
4991 ToCategory->setTypeParamList(*PListOrErr);
4992 else
4993 return PListOrErr.takeError();
4994
4995 // Import protocols
4997 SmallVector<SourceLocation, 4> ProtocolLocs;
4999 = D->protocol_loc_begin();
5000 for (ObjCCategoryDecl::protocol_iterator FromProto = D->protocol_begin(),
5001 FromProtoEnd = D->protocol_end();
5002 FromProto != FromProtoEnd;
5003 ++FromProto, ++FromProtoLoc) {
5004 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5005 Protocols.push_back(*ToProtoOrErr);
5006 else
5007 return ToProtoOrErr.takeError();
5008
5009 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5010 ProtocolLocs.push_back(*ToProtoLocOrErr);
5011 else
5012 return ToProtoLocOrErr.takeError();
5013 }
5014
5015 // FIXME: If we're merging, make sure that the protocol list is the same.
5016 ToCategory->setProtocolList(Protocols.data(), Protocols.size(),
5017 ProtocolLocs.data(), Importer.getToContext());
5018
5019 } else {
5020 Importer.MapImported(D, ToCategory);
5021 }
5022
5023 // Import all of the members of this category.
5024 if (Error Err = ImportDeclContext(D))
5025 return std::move(Err);
5026
5027 // If we have an implementation, import it as well.
5028 if (D->getImplementation()) {
5029 if (Expected<ObjCCategoryImplDecl *> ToImplOrErr =
5030 import(D->getImplementation()))
5031 ToCategory->setImplementation(*ToImplOrErr);
5032 else
5033 return ToImplOrErr.takeError();
5034 }
5035
5036 return ToCategory;
5037}
5038
5041 if (To->getDefinition()) {
5043 if (Error Err = ImportDeclContext(From))
5044 return Err;
5045 return Error::success();
5046 }
5047
5048 // Start the protocol definition
5049 To->startDefinition();
5050
5051 // Import protocols
5053 SmallVector<SourceLocation, 4> ProtocolLocs;
5055 From->protocol_loc_begin();
5056 for (ObjCProtocolDecl::protocol_iterator FromProto = From->protocol_begin(),
5057 FromProtoEnd = From->protocol_end();
5058 FromProto != FromProtoEnd;
5059 ++FromProto, ++FromProtoLoc) {
5060 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5061 Protocols.push_back(*ToProtoOrErr);
5062 else
5063 return ToProtoOrErr.takeError();
5064
5065 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5066 ProtocolLocs.push_back(*ToProtoLocOrErr);
5067 else
5068 return ToProtoLocOrErr.takeError();
5069
5070 }
5071
5072 // FIXME: If we're merging, make sure that the protocol list is the same.
5073 To->setProtocolList(Protocols.data(), Protocols.size(),
5074 ProtocolLocs.data(), Importer.getToContext());
5075
5076 if (shouldForceImportDeclContext(Kind)) {
5077 // Import all of the members of this protocol.
5078 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5079 return Err;
5080 }
5081 return Error::success();
5082}
5083
5085 // If this protocol has a definition in the translation unit we're coming
5086 // from, but this particular declaration is not that definition, import the
5087 // definition and map to that.
5088 ObjCProtocolDecl *Definition = D->getDefinition();
5089 if (Definition && Definition != D) {
5090 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5091 return Importer.MapImported(D, *ImportedDefOrErr);
5092 else
5093 return ImportedDefOrErr.takeError();
5094 }
5095
5096 // Import the major distinguishing characteristics of a protocol.
5097 DeclContext *DC, *LexicalDC;
5098 DeclarationName Name;
5100 NamedDecl *ToD;
5101 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5102 return std::move(Err);
5103 if (ToD)
5104 return ToD;
5105
5106 ObjCProtocolDecl *MergeWithProtocol = nullptr;
5107 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5108 for (auto *FoundDecl : FoundDecls) {
5110 continue;
5111
5112 if ((MergeWithProtocol = dyn_cast<ObjCProtocolDecl>(FoundDecl)))
5113 break;
5114 }
5115
5116 ObjCProtocolDecl *ToProto = MergeWithProtocol;
5117 if (!ToProto) {
5118 auto ToAtBeginLocOrErr = import(D->getAtStartLoc());
5119 if (!ToAtBeginLocOrErr)
5120 return ToAtBeginLocOrErr.takeError();
5121
5122 if (GetImportedOrCreateDecl(ToProto, D, Importer.getToContext(), DC,
5123 Name.getAsIdentifierInfo(), Loc,
5124 *ToAtBeginLocOrErr,
5125 /*PrevDecl=*/nullptr))
5126 return ToProto;
5127 ToProto->setLexicalDeclContext(LexicalDC);
5128 LexicalDC->addDeclInternal(ToProto);
5129 }
5130
5131 Importer.MapImported(D, ToProto);
5132
5133 if (D->isThisDeclarationADefinition())
5134 if (Error Err = ImportDefinition(D, ToProto))
5135 return std::move(Err);
5136
5137 return ToProto;
5138}
5139
5141 DeclContext *DC, *LexicalDC;
5142 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5143 return std::move(Err);
5144
5145 ExpectedSLoc ExternLocOrErr = import(D->getExternLoc());
5146 if (!ExternLocOrErr)
5147 return ExternLocOrErr.takeError();
5148
5149 ExpectedSLoc LangLocOrErr = import(D->getLocation());
5150 if (!LangLocOrErr)
5151 return LangLocOrErr.takeError();
5152
5153 bool HasBraces = D->hasBraces();
5154
5155 LinkageSpecDecl *ToLinkageSpec;
5156 if (GetImportedOrCreateDecl(ToLinkageSpec, D, Importer.getToContext(), DC,
5157 *ExternLocOrErr, *LangLocOrErr,
5158 D->getLanguage(), HasBraces))
5159 return ToLinkageSpec;
5160
5161 if (HasBraces) {
5162 ExpectedSLoc RBraceLocOrErr = import(D->getRBraceLoc());
5163 if (!RBraceLocOrErr)
5164 return RBraceLocOrErr.takeError();
5165 ToLinkageSpec->setRBraceLoc(*RBraceLocOrErr);
5166 }
5167
5168 ToLinkageSpec->setLexicalDeclContext(LexicalDC);
5169 LexicalDC->addDeclInternal(ToLinkageSpec);
5170
5171 return ToLinkageSpec;
5172}
5173
5175 BaseUsingDecl *ToSI) {
5176 for (UsingShadowDecl *FromShadow : D->shadows()) {
5177 if (Expected<UsingShadowDecl *> ToShadowOrErr = import(FromShadow))
5178 ToSI->addShadowDecl(*ToShadowOrErr);
5179 else
5180 // FIXME: We return error here but the definition is already created
5181 // and available with lookups. How to fix this?..
5182 return ToShadowOrErr.takeError();
5183 }
5184 return ToSI;
5185}
5186
5188 DeclContext *DC, *LexicalDC;
5189 DeclarationName Name;
5191 NamedDecl *ToD = nullptr;
5192 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5193 return std::move(Err);
5194 if (ToD)
5195 return ToD;
5196
5197 Error Err = Error::success();
5198 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5199 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5200 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5201 if (Err)
5202 return std::move(Err);
5203
5204 DeclarationNameInfo NameInfo(Name, ToLoc);
5205 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5206 return std::move(Err);
5207
5208 UsingDecl *ToUsing;
5209 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5210 ToUsingLoc, ToQualifierLoc, NameInfo,
5211 D->hasTypename()))
5212 return ToUsing;
5213
5214 ToUsing->setLexicalDeclContext(LexicalDC);
5215 LexicalDC->addDeclInternal(ToUsing);
5216
5217 if (NamedDecl *FromPattern =
5219 if (Expected<NamedDecl *> ToPatternOrErr = import(FromPattern))
5221 ToUsing, *ToPatternOrErr);
5222 else
5223 return ToPatternOrErr.takeError();
5224 }
5225
5226 return ImportUsingShadowDecls(D, ToUsing);
5227}
5228
5230 DeclContext *DC, *LexicalDC;
5231 DeclarationName Name;
5233 NamedDecl *ToD = nullptr;
5234 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5235 return std::move(Err);
5236 if (ToD)
5237 return ToD;
5238
5239 Error Err = Error::success();
5240 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5241 auto ToEnumLoc = importChecked(Err, D->getEnumLoc());
5242 auto ToNameLoc = importChecked(Err, D->getLocation());
5243 auto *ToEnumType = importChecked(Err, D->getEnumType());
5244 if (Err)
5245 return std::move(Err);
5246
5247 UsingEnumDecl *ToUsingEnum;
5248 if (GetImportedOrCreateDecl(ToUsingEnum, D, Importer.getToContext(), DC,
5249 ToUsingLoc, ToEnumLoc, ToNameLoc, ToEnumType))
5250 return ToUsingEnum;
5251
5252 ToUsingEnum->setLexicalDeclContext(LexicalDC);
5253 LexicalDC->addDeclInternal(ToUsingEnum);
5254
5255 if (UsingEnumDecl *FromPattern =
5257 if (Expected<UsingEnumDecl *> ToPatternOrErr = import(FromPattern))
5258 Importer.getToContext().setInstantiatedFromUsingEnumDecl(ToUsingEnum,
5259 *ToPatternOrErr);
5260 else
5261 return ToPatternOrErr.takeError();
5262 }
5263
5264 return ImportUsingShadowDecls(D, ToUsingEnum);
5265}
5266
5268 DeclContext *DC, *LexicalDC;
5269 DeclarationName Name;
5271 NamedDecl *ToD = nullptr;
5272 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5273 return std::move(Err);
5274 if (ToD)
5275 return ToD;
5276
5277 Expected<BaseUsingDecl *> ToIntroducerOrErr = import(D->getIntroducer());
5278 if (!ToIntroducerOrErr)
5279 return ToIntroducerOrErr.takeError();
5280
5281 Expected<NamedDecl *> ToTargetOrErr = import(D->getTargetDecl());
5282 if (!ToTargetOrErr)
5283 return ToTargetOrErr.takeError();
5284
5285 UsingShadowDecl *ToShadow;
5286 if (auto *FromConstructorUsingShadow =
5287 dyn_cast<ConstructorUsingShadowDecl>(D)) {
5288 Error Err = Error::success();
5290 Err, FromConstructorUsingShadow->getNominatedBaseClassShadowDecl());
5291 if (Err)
5292 return std::move(Err);
5293 // The 'Target' parameter of ConstructorUsingShadowDecl constructor
5294 // is really the "NominatedBaseClassShadowDecl" value if it exists
5295 // (see code of ConstructorUsingShadowDecl::ConstructorUsingShadowDecl).
5296 // We should pass the NominatedBaseClassShadowDecl to it (if non-null) to
5297 // get the correct values.
5298 if (GetImportedOrCreateDecl<ConstructorUsingShadowDecl>(
5299 ToShadow, D, Importer.getToContext(), DC, Loc,
5300 cast<UsingDecl>(*ToIntroducerOrErr),
5301 Nominated ? Nominated : *ToTargetOrErr,
5302 FromConstructorUsingShadow->constructsVirtualBase()))
5303 return ToShadow;
5304 } else {
5305 if (GetImportedOrCreateDecl(ToShadow, D, Importer.getToContext(), DC, Loc,
5306 Name, *ToIntroducerOrErr, *ToTargetOrErr))
5307 return ToShadow;
5308 }
5309
5310 ToShadow->setLexicalDeclContext(LexicalDC);
5311 ToShadow->setAccess(D->getAccess());
5312
5313 if (UsingShadowDecl *FromPattern =
5315 if (Expected<UsingShadowDecl *> ToPatternOrErr = import(FromPattern))
5317 ToShadow, *ToPatternOrErr);
5318 else
5319 // FIXME: We return error here but the definition is already created
5320 // and available with lookups. How to fix this?..
5321 return ToPatternOrErr.takeError();
5322 }
5323
5324 LexicalDC->addDeclInternal(ToShadow);
5325
5326 return ToShadow;
5327}
5328
5330 DeclContext *DC, *LexicalDC;
5331 DeclarationName Name;
5333 NamedDecl *ToD = nullptr;
5334 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5335 return std::move(Err);
5336 if (ToD)
5337 return ToD;
5338
5339 auto ToComAncestorOrErr = Importer.ImportContext(D->getCommonAncestor());
5340 if (!ToComAncestorOrErr)
5341 return ToComAncestorOrErr.takeError();
5342
5343 Error Err = Error::success();
5344 auto ToNominatedNamespace = importChecked(Err, D->getNominatedNamespace());
5345 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5346 auto ToNamespaceKeyLocation =
5347 importChecked(Err, D->getNamespaceKeyLocation());
5348 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5349 auto ToIdentLocation = importChecked(Err, D->getIdentLocation());
5350 if (Err)
5351 return std::move(Err);
5352
5353 UsingDirectiveDecl *ToUsingDir;
5354 if (GetImportedOrCreateDecl(ToUsingDir, D, Importer.getToContext(), DC,
5355 ToUsingLoc,
5356 ToNamespaceKeyLocation,
5357 ToQualifierLoc,
5358 ToIdentLocation,
5359 ToNominatedNamespace, *ToComAncestorOrErr))
5360 return ToUsingDir;
5361
5362 ToUsingDir->setLexicalDeclContext(LexicalDC);
5363 LexicalDC->addDeclInternal(ToUsingDir);
5364
5365 return ToUsingDir;
5366}
5367
5369 DeclContext *DC, *LexicalDC;
5370 DeclarationName Name;
5372 NamedDecl *ToD = nullptr;
5373 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5374 return std::move(Err);
5375 if (ToD)
5376 return ToD;
5377
5378 auto ToInstantiatedFromUsingOrErr =
5379 Importer.Import(D->getInstantiatedFromUsingDecl());
5380 if (!ToInstantiatedFromUsingOrErr)
5381 return ToInstantiatedFromUsingOrErr.takeError();
5382 SmallVector<NamedDecl *, 4> Expansions(D->expansions().size());
5383 if (Error Err = ImportArrayChecked(D->expansions(), Expansions.begin()))
5384 return std::move(Err);
5385
5386 UsingPackDecl *ToUsingPack;
5387 if (GetImportedOrCreateDecl(ToUsingPack, D, Importer.getToContext(), DC,
5388 cast<NamedDecl>(*ToInstantiatedFromUsingOrErr),
5389 Expansions))
5390 return ToUsingPack;
5391
5392 addDeclToContexts(D, ToUsingPack);
5393
5394 return ToUsingPack;
5395}
5396
5399 DeclContext *DC, *LexicalDC;
5400 DeclarationName Name;
5402 NamedDecl *ToD = nullptr;
5403 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5404 return std::move(Err);
5405 if (ToD)
5406 return ToD;
5407
5408 Error Err = Error::success();
5409 auto ToLoc = importChecked(Err, D->getNameInfo().getLoc());
5410 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5411 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5412 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5413 if (Err)
5414 return std::move(Err);
5415
5416 DeclarationNameInfo NameInfo(Name, ToLoc);
5417 if (Error Err = ImportDeclarationNameLoc(D->getNameInfo(), NameInfo))
5418 return std::move(Err);
5419
5420 UnresolvedUsingValueDecl *ToUsingValue;
5421 if (GetImportedOrCreateDecl(ToUsingValue, D, Importer.getToContext(), DC,
5422 ToUsingLoc, ToQualifierLoc, NameInfo,
5423 ToEllipsisLoc))
5424 return ToUsingValue;
5425
5426 ToUsingValue->setAccess(D->getAccess());
5427 ToUsingValue->setLexicalDeclContext(LexicalDC);
5428 LexicalDC->addDeclInternal(ToUsingValue);
5429
5430 return ToUsingValue;
5431}
5432
5435 DeclContext *DC, *LexicalDC;
5436 DeclarationName Name;
5438 NamedDecl *ToD = nullptr;
5439 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5440 return std::move(Err);
5441 if (ToD)
5442 return ToD;
5443
5444 Error Err = Error::success();
5445 auto ToUsingLoc = importChecked(Err, D->getUsingLoc());
5446 auto ToTypenameLoc = importChecked(Err, D->getTypenameLoc());
5447 auto ToQualifierLoc = importChecked(Err, D->getQualifierLoc());
5448 auto ToEllipsisLoc = importChecked(Err, D->getEllipsisLoc());
5449 if (Err)
5450 return std::move(Err);
5451
5453 if (GetImportedOrCreateDecl(ToUsing, D, Importer.getToContext(), DC,
5454 ToUsingLoc, ToTypenameLoc,
5455 ToQualifierLoc, Loc, Name, ToEllipsisLoc))
5456 return ToUsing;
5457
5458 ToUsing->setAccess(D->getAccess());
5459 ToUsing->setLexicalDeclContext(LexicalDC);
5460 LexicalDC->addDeclInternal(ToUsing);
5461
5462 return ToUsing;
5463}
5464
5466 Decl* ToD = nullptr;
5467 switch (D->getBuiltinTemplateKind()) {
5469 ToD = Importer.getToContext().getMakeIntegerSeqDecl();
5470 break;
5472 ToD = Importer.getToContext().getTypePackElementDecl();
5473 break;
5475 ToD = Importer.getToContext().getBuiltinCommonTypeDecl();
5476 break;
5477 }
5478 assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
5479 Importer.MapImported(D, ToD);
5480 return ToD;
5481}
5482
5485 if (To->getDefinition()) {
5486 // Check consistency of superclass.
5487 ObjCInterfaceDecl *FromSuper = From->getSuperClass();
5488 if (FromSuper) {
5489 if (auto FromSuperOrErr = import(FromSuper))
5490 FromSuper = *FromSuperOrErr;
5491 else
5492 return FromSuperOrErr.takeError();
5493 }
5494
5495 ObjCInterfaceDecl *ToSuper = To->getSuperClass();
5496 if ((bool)FromSuper != (bool)ToSuper ||
5497 (FromSuper && !declaresSameEntity(FromSuper, ToSuper))) {
5498 Importer.ToDiag(To->getLocation(),
5499 diag::warn_odr_objc_superclass_inconsistent)
5500 << To->getDeclName();
5501 if (ToSuper)
5502 Importer.ToDiag(To->getSuperClassLoc(), diag::note_odr_objc_superclass)
5503 << To->getSuperClass()->getDeclName();
5504 else
5505 Importer.ToDiag(To->getLocation(),
5506 diag::note_odr_objc_missing_superclass);
5507 if (From->getSuperClass())
5508 Importer.FromDiag(From->getSuperClassLoc(),
5509 diag::note_odr_objc_superclass)
5510 << From->getSuperClass()->getDeclName();
5511 else
5512 Importer.FromDiag(From->getLocation(),
5513 diag::note_odr_objc_missing_superclass);
5514 }
5515
5517 if (Error Err = ImportDeclContext(From))
5518 return Err;
5519 return Error::success();
5520 }
5521
5522 // Start the definition.
5523 To->startDefinition();
5524
5525 // If this class has a superclass, import it.
5526 if (From->getSuperClass()) {
5527 if (auto SuperTInfoOrErr = import(From->getSuperClassTInfo()))
5528 To->setSuperClass(*SuperTInfoOrErr);
5529 else
5530 return SuperTInfoOrErr.takeError();
5531 }
5532
5533 // Import protocols
5535 SmallVector<SourceLocation, 4> ProtocolLocs;
5537 From->protocol_loc_begin();
5538
5540 FromProtoEnd = From->protocol_end();
5541 FromProto != FromProtoEnd;
5542 ++FromProto, ++FromProtoLoc) {
5543 if (Expected<ObjCProtocolDecl *> ToProtoOrErr = import(*FromProto))
5544 Protocols.push_back(*ToProtoOrErr);
5545 else
5546 return ToProtoOrErr.takeError();
5547
5548 if (ExpectedSLoc ToProtoLocOrErr = import(*FromProtoLoc))
5549 ProtocolLocs.push_back(*ToProtoLocOrErr);
5550 else
5551 return ToProtoLocOrErr.takeError();
5552
5553 }
5554
5555 // FIXME: If we're merging, make sure that the protocol list is the same.
5556 To->setProtocolList(Protocols.data(), Protocols.size(),
5557 ProtocolLocs.data(), Importer.getToContext());
5558
5559 // Import categories. When the categories themselves are imported, they'll
5560 // hook themselves into this interface.
5561 for (auto *Cat : From->known_categories()) {
5562 auto ToCatOrErr = import(Cat);
5563 if (!ToCatOrErr)
5564 return ToCatOrErr.takeError();
5565 }
5566
5567 // If we have an @implementation, import it as well.
5568 if (From->getImplementation()) {
5569 if (Expected<ObjCImplementationDecl *> ToImplOrErr =
5570 import(From->getImplementation()))
5571 To->setImplementation(*ToImplOrErr);
5572 else
5573 return ToImplOrErr.takeError();
5574 }
5575
5576 // Import all of the members of this class.
5577 if (Error Err = ImportDeclContext(From, /*ForceImport=*/true))
5578 return Err;
5579
5580 return Error::success();
5581}
5582
5585 if (!list)
5586 return nullptr;
5587
5589 for (auto *fromTypeParam : *list) {
5590 if (auto toTypeParamOrErr = import(fromTypeParam))
5591 toTypeParams.push_back(*toTypeParamOrErr);
5592 else
5593 return toTypeParamOrErr.takeError();
5594 }
5595
5596 auto LAngleLocOrErr = import(list->getLAngleLoc());
5597 if (!LAngleLocOrErr)
5598 return LAngleLocOrErr.takeError();
5599
5600 auto RAngleLocOrErr = import(list->getRAngleLoc());
5601 if (!RAngleLocOrErr)
5602 return RAngleLocOrErr.takeError();
5603
5604 return ObjCTypeParamList::create(Importer.getToContext(),
5605 *LAngleLocOrErr,
5606 toTypeParams,
5607 *RAngleLocOrErr);
5608}
5609
5611 // If this class has a definition in the translation unit we're coming from,
5612 // but this particular declaration is not that definition, import the
5613 // definition and map to that.
5614 ObjCInterfaceDecl *Definition = D->getDefinition();
5615 if (Definition && Definition != D) {
5616 if (ExpectedDecl ImportedDefOrErr = import(Definition))
5617 return Importer.MapImported(D, *ImportedDefOrErr);
5618 else
5619 return ImportedDefOrErr.takeError();
5620 }
5621
5622 // Import the major distinguishing characteristics of an @interface.
5623 DeclContext *DC, *LexicalDC;
5624 DeclarationName Name;
5626 NamedDecl *ToD;
5627 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5628 return std::move(Err);
5629 if (ToD)
5630 return ToD;
5631
5632 // Look for an existing interface with the same name.
5633 ObjCInterfaceDecl *MergeWithIface = nullptr;
5634 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5635 for (auto *FoundDecl : FoundDecls) {
5637 continue;
5638
5639 if ((MergeWithIface = dyn_cast<ObjCInterfaceDecl>(FoundDecl)))
5640 break;
5641 }
5642
5643 // Create an interface declaration, if one does not already exist.
5644 ObjCInterfaceDecl *ToIface = MergeWithIface;
5645 if (!ToIface) {
5646 ExpectedSLoc AtBeginLocOrErr = import(D->getAtStartLoc());
5647 if (!AtBeginLocOrErr)
5648 return AtBeginLocOrErr.takeError();
5649
5650 if (GetImportedOrCreateDecl(
5651 ToIface, D, Importer.getToContext(), DC,
5652 *AtBeginLocOrErr, Name.getAsIdentifierInfo(),
5653 /*TypeParamList=*/nullptr,
5654 /*PrevDecl=*/nullptr, Loc, D->isImplicitInterfaceDecl()))
5655 return ToIface;
5656 ToIface->setLexicalDeclContext(LexicalDC);
5657 LexicalDC->addDeclInternal(ToIface);
5658 }
5659 Importer.MapImported(D, ToIface);
5660 // Import the type parameter list after MapImported, to avoid
5661 // loops when bringing in their DeclContext.
5662 if (auto ToPListOrErr =
5663 ImportObjCTypeParamList(D->getTypeParamListAsWritten()))
5664 ToIface->setTypeParamList(*ToPListOrErr);
5665 else
5666 return ToPListOrErr.takeError();
5667
5668 if (D->isThisDeclarationADefinition())
5669 if (Error Err = ImportDefinition(D, ToIface))
5670 return std::move(Err);
5671
5672 return ToIface;
5673}
5674
5678 if (Error Err = importInto(Category, D->getCategoryDecl()))
5679 return std::move(Err);
5680
5681 ObjCCategoryImplDecl *ToImpl = Category->getImplementation();
5682 if (!ToImpl) {
5683 DeclContext *DC, *LexicalDC;
5684 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5685 return std::move(Err);
5686
5687 Error Err = Error::success();
5688 auto ToLocation = importChecked(Err, D->getLocation());
5689 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5690 auto ToCategoryNameLoc = importChecked(Err, D->getCategoryNameLoc());
5691 if (Err)
5692 return std::move(Err);
5693
5694 if (GetImportedOrCreateDecl(
5695 ToImpl, D, Importer.getToContext(), DC,
5696 Importer.Import(D->getIdentifier()), Category->getClassInterface(),
5697 ToLocation, ToAtStartLoc, ToCategoryNameLoc))
5698 return ToImpl;
5699
5700 ToImpl->setLexicalDeclContext(LexicalDC);
5701 LexicalDC->addDeclInternal(ToImpl);
5702 Category->setImplementation(ToImpl);
5703 }
5704
5705 Importer.MapImported(D, ToImpl);
5706 if (Error Err = ImportDeclContext(D))
5707 return std::move(Err);
5708
5709 return ToImpl;
5710}
5711
5714 // Find the corresponding interface.
5715 ObjCInterfaceDecl *Iface;
5716 if (Error Err = importInto(Iface, D->getClassInterface()))
5717 return std::move(Err);
5718
5719 // Import the superclass, if any.
5720 ObjCInterfaceDecl *Super;
5721 if (Error Err = importInto(Super, D->getSuperClass()))
5722 return std::move(Err);
5723
5725 if (!Impl) {
5726 // We haven't imported an implementation yet. Create a new @implementation
5727 // now.
5728 DeclContext *DC, *LexicalDC;
5729 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5730 return std::move(Err);
5731
5732 Error Err = Error::success();
5733 auto ToLocation = importChecked(Err, D->getLocation());
5734 auto ToAtStartLoc = importChecked(Err, D->getAtStartLoc());
5735 auto ToSuperClassLoc = importChecked(Err, D->getSuperClassLoc());
5736 auto ToIvarLBraceLoc = importChecked(Err, D->getIvarLBraceLoc());
5737 auto ToIvarRBraceLoc = importChecked(Err, D->getIvarRBraceLoc());
5738 if (Err)
5739 return std::move(Err);
5740
5741 if (GetImportedOrCreateDecl(Impl, D, Importer.getToContext(),
5742 DC, Iface, Super,
5743 ToLocation,
5744 ToAtStartLoc,
5745 ToSuperClassLoc,
5746 ToIvarLBraceLoc,
5747 ToIvarRBraceLoc))
5748 return Impl;
5749
5750 Impl->setLexicalDeclContext(LexicalDC);
5751
5752 // Associate the implementation with the class it implements.
5753 Iface->setImplementation(Impl);
5754 Importer.MapImported(D, Iface->getImplementation());
5755 } else {
5756 Importer.MapImported(D, Iface->getImplementation());
5757
5758 // Verify that the existing @implementation has the same superclass.
5759 if ((Super && !Impl->getSuperClass()) ||
5760 (!Super && Impl->getSuperClass()) ||
5761 (Super && Impl->getSuperClass() &&
5763 Impl->getSuperClass()))) {
5764 Importer.ToDiag(Impl->getLocation(),
5765 diag::warn_odr_objc_superclass_inconsistent)
5766 << Iface->getDeclName();
5767 // FIXME: It would be nice to have the location of the superclass
5768 // below.
5769 if (Impl->getSuperClass())
5770 Importer.ToDiag(Impl->getLocation(),
5771 diag::note_odr_objc_superclass)
5772 << Impl->getSuperClass()->getDeclName();
5773 else
5774 Importer.ToDiag(Impl->getLocation(),
5775 diag::note_odr_objc_missing_superclass);
5776 if (D->getSuperClass())
5777 Importer.FromDiag(D->getLocation(),
5778 diag::note_odr_objc_superclass)
5779 << D->getSuperClass()->getDeclName();
5780 else
5781 Importer.FromDiag(D->getLocation(),
5782 diag::note_odr_objc_missing_superclass);
5783
5784 return make_error<ASTImportError>(ASTImportError::NameConflict);
5785 }
5786 }
5787
5788 // Import all of the members of this @implementation.
5789 if (Error Err = ImportDeclContext(D))
5790 return std::move(Err);
5791
5792 return Impl;
5793}
5794
5796 // Import the major distinguishing characteristics of an @property.
5797 DeclContext *DC, *LexicalDC;
5798 DeclarationName Name;
5800 NamedDecl *ToD;
5801 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
5802 return std::move(Err);
5803 if (ToD)
5804 return ToD;
5805
5806 // Check whether we have already imported this property.
5807 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
5808 for (auto *FoundDecl : FoundDecls) {
5809 if (auto *FoundProp = dyn_cast<ObjCPropertyDecl>(FoundDecl)) {
5810 // Instance and class properties can share the same name but are different
5811 // declarations.
5812 if (FoundProp->isInstanceProperty() != D->isInstanceProperty())
5813 continue;
5814
5815 // Check property types.
5816 if (!Importer.IsStructurallyEquivalent(D->getType(),
5817 FoundProp->getType())) {
5818 Importer.ToDiag(Loc, diag::warn_odr_objc_property_type_inconsistent)
5819 << Name << D->getType() << FoundProp->getType();
5820 Importer.ToDiag(FoundProp->getLocation(), diag::note_odr_value_here)
5821 << FoundProp->getType();
5822
5823 return make_error<ASTImportError>(ASTImportError::NameConflict);
5824 }
5825
5826 // FIXME: Check property attributes, getters, setters, etc.?
5827
5828 // Consider these properties to be equivalent.
5829 Importer.MapImported(D, FoundProp);
5830 return FoundProp;
5831 }
5832 }
5833
5834 Error Err = Error::success();
5835 auto ToType = importChecked(Err, D->getType());
5836 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
5837 auto ToAtLoc = importChecked(Err, D->getAtLoc());
5838 auto ToLParenLoc = importChecked(Err, D->getLParenLoc());
5839 if (Err)
5840 return std::move(Err);
5841
5842 // Create the new property.
5843 ObjCPropertyDecl *ToProperty;
5844 if (GetImportedOrCreateDecl(
5845 ToProperty, D, Importer.getToContext(), DC, Loc,
5846 Name.getAsIdentifierInfo(), ToAtLoc,
5847 ToLParenLoc, ToType,
5848 ToTypeSourceInfo, D->getPropertyImplementation()))
5849 return ToProperty;
5850
5851 auto ToGetterName = importChecked(Err, D->getGetterName());
5852 auto ToSetterName = importChecked(Err, D->getSetterName());
5853 auto ToGetterNameLoc = importChecked(Err, D->getGetterNameLoc());
5854 auto ToSetterNameLoc = importChecked(Err, D->getSetterNameLoc());
5855 auto ToGetterMethodDecl = importChecked(Err, D->getGetterMethodDecl());
5856 auto ToSetterMethodDecl = importChecked(Err, D->getSetterMethodDecl());
5857 auto ToPropertyIvarDecl = importChecked(Err, D->getPropertyIvarDecl());
5858 if (Err)
5859 return std::move(Err);
5860
5861 ToProperty->setLexicalDeclContext(LexicalDC);
5862 LexicalDC->addDeclInternal(ToProperty);
5863
5864 ToProperty->setPropertyAttributes(D->getPropertyAttributes());
5866 D->getPropertyAttributesAsWritten());
5867 ToProperty->setGetterName(ToGetterName, ToGetterNameLoc);
5868 ToProperty->setSetterName(ToSetterName, ToSetterNameLoc);
5869 ToProperty->setGetterMethodDecl(ToGetterMethodDecl);
5870 ToProperty->setSetterMethodDecl(ToSetterMethodDecl);
5871 ToProperty->setPropertyIvarDecl(ToPropertyIvarDecl);
5872 return ToProperty;
5873}
5874
5878 if (Error Err = importInto(Property, D->getPropertyDecl()))
5879 return std::move(Err);
5880
5881 DeclContext *DC, *LexicalDC;
5882 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
5883 return std::move(Err);
5884
5885 auto *InImpl = cast<ObjCImplDecl>(LexicalDC);
5886
5887 // Import the ivar (for an @synthesize).
5888 ObjCIvarDecl *Ivar = nullptr;
5889 if (Error Err = importInto(Ivar, D->getPropertyIvarDecl()))
5890 return std::move(Err);
5891
5892 ObjCPropertyImplDecl *ToImpl
5893 = InImpl->FindPropertyImplDecl(Property->getIdentifier(),
5894 Property->getQueryKind());
5895 if (!ToImpl) {
5896
5897 Error Err = Error::success();
5898 auto ToBeginLoc = importChecked(Err, D->getBeginLoc());
5899 auto ToLocation = importChecked(Err, D->getLocation());
5900 auto ToPropertyIvarDeclLoc =
5901 importChecked(Err, D->getPropertyIvarDeclLoc());
5902 if (Err)
5903 return std::move(Err);
5904
5905 if (GetImportedOrCreateDecl(ToImpl, D, Importer.getToContext(), DC,
5906 ToBeginLoc,
5907 ToLocation, Property,
5908 D->getPropertyImplementation(), Ivar,
5909 ToPropertyIvarDeclLoc))
5910 return ToImpl;
5911
5912 ToImpl->setLexicalDeclContext(LexicalDC);
5913 LexicalDC->addDeclInternal(ToImpl);
5914 } else {
5915 // Check that we have the same kind of property implementation (@synthesize
5916 // vs. @dynamic).
5917 if (D->getPropertyImplementation() != ToImpl->getPropertyImplementation()) {
5918 Importer.ToDiag(ToImpl->getLocation(),
5919 diag::warn_odr_objc_property_impl_kind_inconsistent)
5920 << Property->getDeclName()
5921 << (ToImpl->getPropertyImplementation()
5923 Importer.FromDiag(D->getLocation(),
5924 diag::note_odr_objc_property_impl_kind)
5925 << D->getPropertyDecl()->getDeclName()
5926 << (D->getPropertyImplementation() == ObjCPropertyImplDecl::Dynamic);
5927
5928 return make_error<ASTImportError>(ASTImportError::NameConflict);
5929 }
5930
5931 // For @synthesize, check that we have the same
5932 if (D->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize &&
5933 Ivar != ToImpl->getPropertyIvarDecl()) {
5934 Importer.ToDiag(ToImpl->getPropertyIvarDeclLoc(),
5935 diag::warn_odr_objc_synthesize_ivar_inconsistent)
5936 << Property->getDeclName()
5937 << ToImpl->getPropertyIvarDecl()->getDeclName()
5938 << Ivar->getDeclName();
5939 Importer.FromDiag(D->getPropertyIvarDeclLoc(),
5940 diag::note_odr_objc_synthesize_ivar_here)
5941 << D->getPropertyIvarDecl()->getDeclName();
5942
5943 return make_error<ASTImportError>(ASTImportError::NameConflict);
5944 }
5945
5946 // Merge the existing implementation with the new implementation.
5947 Importer.MapImported(D, ToImpl);
5948 }
5949
5950 return ToImpl;
5951}
5952
5955 // For template arguments, we adopt the translation unit as our declaration
5956 // context. This context will be fixed when (during) the actual template
5957 // declaration is created.
5958
5959 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
5960 if (!BeginLocOrErr)
5961 return BeginLocOrErr.takeError();
5962
5963 ExpectedSLoc LocationOrErr = import(D->getLocation());
5964 if (!LocationOrErr)
5965 return LocationOrErr.takeError();
5966
5967 TemplateTypeParmDecl *ToD = nullptr;
5968 if (GetImportedOrCreateDecl(
5969 ToD, D, Importer.getToContext(),
5971 *BeginLocOrErr, *LocationOrErr,
5972 D->getDepth(), D->getIndex(), Importer.Import(D->getIdentifier()),
5973 D->wasDeclaredWithTypename(), D->isParameterPack(),
5974 D->hasTypeConstraint()))
5975 return ToD;
5976
5977 // Import the type-constraint
5978 if (const TypeConstraint *TC = D->getTypeConstraint()) {
5979
5980 Error Err = Error::success();
5981 auto ToConceptRef = importChecked(Err, TC->getConceptReference());
5982 auto ToIDC = importChecked(Err, TC->getImmediatelyDeclaredConstraint());
5983 if (Err)
5984 return std::move(Err);
5985
5986 ToD->setTypeConstraint(ToConceptRef, ToIDC);
5987 }
5988
5989 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
5990 return Err;
5991
5992 return ToD;
5993}
5994
5997
5998 Error Err = Error::success();
5999 auto ToDeclName = importChecked(Err, D->getDeclName());
6000 auto ToLocation = importChecked(Err, D->getLocation());
6001 auto ToType = importChecked(Err, D->getType());
6002 auto ToTypeSourceInfo = importChecked(Err, D->getTypeSourceInfo());
6003 auto ToInnerLocStart = importChecked(Err, D->getInnerLocStart());
6004 if (Err)
6005 return std::move(Err);
6006
6007 NonTypeTemplateParmDecl *ToD = nullptr;
6008 if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(),
6010 ToInnerLocStart, ToLocation, D->getDepth(),
6011 D->getPosition(),
6012 ToDeclName.getAsIdentifierInfo(), ToType,
6013 D->isParameterPack(), ToTypeSourceInfo))
6014 return ToD;
6015
6016 Err = importTemplateParameterDefaultArgument(D, ToD);
6017 if (Err)
6018 return Err;
6019
6020 return ToD;
6021}
6022
6025 // Import the name of this declaration.
6026 auto NameOrErr = import(D->getDeclName());
6027 if (!NameOrErr)
6028 return NameOrErr.takeError();
6029
6030 // Import the location of this declaration.
6031 ExpectedSLoc LocationOrErr = import(D->getLocation());
6032 if (!LocationOrErr)
6033 return LocationOrErr.takeError();
6034
6035 // Import template parameters.
6036 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6037 if (!TemplateParamsOrErr)
6038 return TemplateParamsOrErr.takeError();
6039
6040 TemplateTemplateParmDecl *ToD = nullptr;
6041 if (GetImportedOrCreateDecl(
6042 ToD, D, Importer.getToContext(),
6043 Importer.getToContext().getTranslationUnitDecl(), *LocationOrErr,
6044 D->getDepth(), D->getPosition(), D->isParameterPack(),
6045 (*NameOrErr).getAsIdentifierInfo(), D->wasDeclaredWithTypename(),
6046 *TemplateParamsOrErr))
6047 return ToD;
6048
6049 if (Error Err = importTemplateParameterDefaultArgument(D, ToD))
6050 return Err;
6051
6052 return ToD;
6053}
6054
6055// Returns the definition for a (forward) declaration of a TemplateDecl, if
6056// it has any definition in the redecl chain.
6057template <typename T> static auto getTemplateDefinition(T *D) -> T * {
6058 assert(D->getTemplatedDecl() && "Should be called on templates only");
6059 auto *ToTemplatedDef = D->getTemplatedDecl()->getDefinition();
6060 if (!ToTemplatedDef)
6061 return nullptr;
6062 auto *TemplateWithDef = ToTemplatedDef->getDescribedTemplate();
6063 return cast_or_null<T>(TemplateWithDef);
6064}
6065
6067
6068 // Import the major distinguishing characteristics of this class template.
6069 DeclContext *DC, *LexicalDC;
6070 DeclarationName Name;
6072 NamedDecl *ToD;
6073 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6074 return std::move(Err);
6075 if (ToD)
6076 return ToD;
6077
6078 // Should check if a declaration is friend in a dependent context.
6079 // Such templates are not linked together in a declaration chain.
6080 // The ASTImporter strategy is to map existing forward declarations to
6081 // imported ones only if strictly necessary, otherwise import these as new
6082 // forward declarations. In case of the "dependent friend" declarations, new
6083 // declarations are created, but not linked in a declaration chain.
6084 auto IsDependentFriend = [](ClassTemplateDecl *TD) {
6085 return TD->getFriendObjectKind() != Decl::FOK_None &&
6087 };
6088 bool DependentFriend = IsDependentFriend(D);
6089
6090 ClassTemplateDecl *FoundByLookup = nullptr;
6091
6092 // We may already have a template of the same name; try to find and match it.
6093 if (!DC->isFunctionOrMethod()) {
6094 SmallVector<NamedDecl *, 4> ConflictingDecls;
6095 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6096 for (auto *FoundDecl : FoundDecls) {
6099 continue;
6100
6101 auto *FoundTemplate = dyn_cast<ClassTemplateDecl>(FoundDecl);
6102 if (FoundTemplate) {
6103 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6104 continue;
6105
6106 // FIXME: sufficient conditon for 'IgnoreTemplateParmDepth'?
6107 bool IgnoreTemplateParmDepth =
6108 (FoundTemplate->getFriendObjectKind() != Decl::FOK_None) !=
6110 if (IsStructuralMatch(D, FoundTemplate, /*Complain=*/true,
6111 IgnoreTemplateParmDepth)) {
6112 if (DependentFriend || IsDependentFriend(FoundTemplate))
6113 continue;
6114
6115 ClassTemplateDecl *TemplateWithDef =
6116 getTemplateDefinition(FoundTemplate);
6117 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6118 return Importer.MapImported(D, TemplateWithDef);
6119 if (!FoundByLookup)
6120 FoundByLookup = FoundTemplate;
6121 // Search in all matches because there may be multiple decl chains,
6122 // see ASTTests test ImportExistingFriendClassTemplateDef.
6123 continue;
6124 }
6125 // When importing a friend, it is possible that multiple declarations
6126 // with same name can co-exist in specific cases (if a template contains
6127 // a friend template and has a specialization). For this case the
6128 // declarations should match, except that the "template depth" is
6129 // different. No linking of previous declaration is needed in this case.
6130 // FIXME: This condition may need refinement.
6132 FoundTemplate->getFriendObjectKind() != Decl::FOK_None &&
6133 D->getFriendObjectKind() != FoundTemplate->getFriendObjectKind() &&
6134 IsStructuralMatch(D, FoundTemplate, /*Complain=*/false,
6135 /*IgnoreTemplateParmDepth=*/true))
6136 continue;
6137
6138 ConflictingDecls.push_back(FoundDecl);
6139 }
6140 }
6141
6142 if (!ConflictingDecls.empty()) {
6143 ExpectedName NameOrErr = Importer.HandleNameConflict(
6144 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6145 ConflictingDecls.size());
6146 if (NameOrErr)
6147 Name = NameOrErr.get();
6148 else
6149 return NameOrErr.takeError();
6150 }
6151 }
6152
6153 CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
6154
6155 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6156 if (!TemplateParamsOrErr)
6157 return TemplateParamsOrErr.takeError();
6158
6159 // Create the declaration that is being templated.
6160 CXXRecordDecl *ToTemplated;
6161 if (Error Err = importInto(ToTemplated, FromTemplated))
6162 return std::move(Err);
6163
6164 // Create the class template declaration itself.
6166 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
6167 *TemplateParamsOrErr, ToTemplated))
6168 return D2;
6169
6170 ToTemplated->setDescribedClassTemplate(D2);
6171
6172 D2->setAccess(D->getAccess());
6173 D2->setLexicalDeclContext(LexicalDC);
6174
6175 addDeclToContexts(D, D2);
6176 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6177
6178 if (FoundByLookup) {
6179 auto *Recent =
6180 const_cast<ClassTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6181
6182 // It is possible that during the import of the class template definition
6183 // we start the import of a fwd friend decl of the very same class template
6184 // and we add the fwd friend decl to the lookup table. But the ToTemplated
6185 // had been created earlier and by that time the lookup could not find
6186 // anything existing, so it has no previous decl. Later, (still during the
6187 // import of the fwd friend decl) we start to import the definition again
6188 // and this time the lookup finds the previous fwd friend class template.
6189 // In this case we must set up the previous decl for the templated decl.
6190 if (!ToTemplated->getPreviousDecl()) {
6191 assert(FoundByLookup->getTemplatedDecl() &&
6192 "Found decl must have its templated decl set");
6193 CXXRecordDecl *PrevTemplated =
6194 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6195 if (ToTemplated != PrevTemplated)
6196 ToTemplated->setPreviousDecl(PrevTemplated);
6197 }
6198
6199 D2->setPreviousDecl(Recent);
6200 }
6201
6202 return D2;
6203}
6204
6207 ClassTemplateDecl *ClassTemplate;
6208 if (Error Err = importInto(ClassTemplate, D->getSpecializedTemplate()))
6209 return std::move(Err);
6210
6211 // Import the context of this declaration.
6212 DeclContext *DC, *LexicalDC;
6213 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6214 return std::move(Err);
6215
6216 // Import template arguments.
6218 if (Error Err =
6219 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6220 return std::move(Err);
6221 // Try to find an existing specialization with these template arguments and
6222 // template parameter list.
6223 void *InsertPos = nullptr;
6224 ClassTemplateSpecializationDecl *PrevDecl = nullptr;
6226 dyn_cast<ClassTemplatePartialSpecializationDecl>(D);
6227
6228 // Import template parameters.
6229 TemplateParameterList *ToTPList = nullptr;
6230
6231 if (PartialSpec) {
6232 auto ToTPListOrErr = import(PartialSpec->getTemplateParameters());
6233 if (!ToTPListOrErr)
6234 return ToTPListOrErr.takeError();
6235 ToTPList = *ToTPListOrErr;
6236 PrevDecl = ClassTemplate->findPartialSpecialization(TemplateArgs,
6237 *ToTPListOrErr,
6238 InsertPos);
6239 } else
6240 PrevDecl = ClassTemplate->findSpecialization(TemplateArgs, InsertPos);
6241
6242 if (PrevDecl) {
6243 if (IsStructuralMatch(D, PrevDecl)) {
6244 CXXRecordDecl *PrevDefinition = PrevDecl->getDefinition();
6245 if (D->isThisDeclarationADefinition() && PrevDefinition) {
6246 Importer.MapImported(D, PrevDefinition);
6247 // Import those default field initializers which have been
6248 // instantiated in the "From" context, but not in the "To" context.
6249 for (auto *FromField : D->fields()) {
6250 auto ToOrErr = import(FromField);
6251 if (!ToOrErr)
6252 return ToOrErr.takeError();
6253 }
6254
6255 // Import those methods which have been instantiated in the
6256 // "From" context, but not in the "To" context.
6257 for (CXXMethodDecl *FromM : D->methods()) {
6258 auto ToOrErr = import(FromM);
6259 if (!ToOrErr)
6260 return ToOrErr.takeError();
6261 }
6262
6263 // TODO Import instantiated default arguments.
6264 // TODO Import instantiated exception specifications.
6265 //
6266 // Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
6267 // what else could be fused during an AST merge.
6268 return PrevDefinition;
6269 }
6270 } else { // ODR violation.
6271 // FIXME HandleNameConflict
6272 return make_error<ASTImportError>(ASTImportError::NameConflict);
6273 }
6274 }
6275
6276 // Import the location of this declaration.
6277 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6278 if (!BeginLocOrErr)
6279 return BeginLocOrErr.takeError();
6280 ExpectedSLoc IdLocOrErr = import(D->getLocation());
6281 if (!IdLocOrErr)
6282 return IdLocOrErr.takeError();
6283
6284 // Import TemplateArgumentListInfo.
6285 TemplateArgumentListInfo ToTAInfo;
6286 if (const auto *ASTTemplateArgs = D->getTemplateArgsAsWritten()) {
6287 if (Error Err = ImportTemplateArgumentListInfo(*ASTTemplateArgs, ToTAInfo))
6288 return std::move(Err);
6289 }
6290
6291 // Create the specialization.
6292 ClassTemplateSpecializationDecl *D2 = nullptr;
6293 if (PartialSpec) {
6294 QualType CanonInjType;
6295 if (Error Err = importInto(
6296 CanonInjType, PartialSpec->getInjectedSpecializationType()))
6297 return std::move(Err);
6298 CanonInjType = CanonInjType.getCanonicalType();
6299
6300 if (GetImportedOrCreateDecl<ClassTemplatePartialSpecializationDecl>(
6301 D2, D, Importer.getToContext(), D->getTagKind(), DC, *BeginLocOrErr,
6302 *IdLocOrErr, ToTPList, ClassTemplate,
6303 llvm::ArrayRef(TemplateArgs.data(), TemplateArgs.size()),
6304 CanonInjType,
6305 cast_or_null<ClassTemplatePartialSpecializationDecl>(PrevDecl)))
6306 return D2;
6307
6308 // Update InsertPos, because preceding import calls may have invalidated
6309 // it by adding new specializations.
6310 auto *PartSpec2 = cast<ClassTemplatePartialSpecializationDecl>(D2);
6311 if (!ClassTemplate->findPartialSpecialization(TemplateArgs, ToTPList,
6312 InsertPos))
6313 // Add this partial specialization to the class template.
6314 ClassTemplate->AddPartialSpecialization(PartSpec2, InsertPos);
6316 import(PartialSpec->getInstantiatedFromMember()))
6317 PartSpec2->setInstantiatedFromMember(*ToInstOrErr);
6318 else
6319 return ToInstOrErr.takeError();
6320
6321 updateLookupTableForTemplateParameters(*ToTPList);
6322 } else { // Not a partial specialization.
6323 if (GetImportedOrCreateDecl(
6324 D2, D, Importer.getToContext(), D->getTagKind(), DC,
6325 *BeginLocOrErr, *IdLocOrErr, ClassTemplate, TemplateArgs,
6326 PrevDecl))
6327 return D2;
6328
6329 // Update InsertPos, because preceding import calls may have invalidated
6330 // it by adding new specializations.
6331 if (!ClassTemplate->findSpecialization(TemplateArgs, InsertPos))
6332 // Add this specialization to the class template.
6333 ClassTemplate->AddSpecialization(D2, InsertPos);
6334 }
6335
6336 D2->setSpecializationKind(D->getSpecializationKind());
6337
6338 // Set the context of this specialization/instantiation.
6339 D2->setLexicalDeclContext(LexicalDC);
6340
6341 // Add to the DC only if it was an explicit specialization/instantiation.
6343 LexicalDC->addDeclInternal(D2);
6344 }
6345
6346 if (auto BraceRangeOrErr = import(D->getBraceRange()))
6347 D2->setBraceRange(*BraceRangeOrErr);
6348 else
6349 return BraceRangeOrErr.takeError();
6350
6351 if (Error Err = ImportTemplateParameterLists(D, D2))
6352 return std::move(Err);
6353
6354 // Import the qualifier, if any.
6355 if (auto LocOrErr = import(D->getQualifierLoc()))
6356 D2->setQualifierInfo(*LocOrErr);
6357 else
6358 return LocOrErr.takeError();
6359
6360 if (D->getTemplateArgsAsWritten())
6361 D2->setTemplateArgsAsWritten(ToTAInfo);
6362
6363 if (auto LocOrErr = import(D->getTemplateKeywordLoc()))
6364 D2->setTemplateKeywordLoc(*LocOrErr);
6365 else
6366 return LocOrErr.takeError();
6367
6368 if (auto LocOrErr = import(D->getExternKeywordLoc()))
6369 D2->setExternKeywordLoc(*LocOrErr);
6370 else
6371 return LocOrErr.takeError();
6372
6373 if (D->getPointOfInstantiation().isValid()) {
6374 if (auto POIOrErr = import(D->getPointOfInstantiation()))
6375 D2->setPointOfInstantiation(*POIOrErr);
6376 else
6377 return POIOrErr.takeError();
6378 }
6379
6380 D2->setTemplateSpecializationKind(D->getTemplateSpecializationKind());
6381
6382 if (auto P = D->getInstantiatedFrom()) {
6383 if (auto *CTD = dyn_cast<ClassTemplateDecl *>(P)) {
6384 if (auto CTDorErr = import(CTD))
6385 D2->setInstantiationOf(*CTDorErr);
6386 } else {
6387 auto *CTPSD = cast<ClassTemplatePartialSpecializationDecl *>(P);
6388 auto CTPSDOrErr = import(CTPSD);
6389 if (!CTPSDOrErr)
6390 return CTPSDOrErr.takeError();
6391 const TemplateArgumentList &DArgs = D->getTemplateInstantiationArgs();
6392 SmallVector<TemplateArgument, 2> D2ArgsVec(DArgs.size());
6393 for (unsigned I = 0; I < DArgs.size(); ++I) {
6394 const TemplateArgument &DArg = DArgs[I];
6395 if (auto ArgOrErr = import(DArg))
6396 D2ArgsVec[I] = *ArgOrErr;
6397 else
6398 return ArgOrErr.takeError();
6399 }
6401 *CTPSDOrErr,
6402 TemplateArgumentList::CreateCopy(Importer.getToContext(), D2ArgsVec));
6403 }
6404 }
6405
6406 if (D->isCompleteDefinition())
6407 if (Error Err = ImportDefinition(D, D2))
6408 return std::move(Err);
6409
6410 return D2;
6411}
6412
6414 // Import the major distinguishing characteristics of this variable template.
6415 DeclContext *DC, *LexicalDC;
6416 DeclarationName Name;
6418 NamedDecl *ToD;
6419 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6420 return std::move(Err);
6421 if (ToD)
6422 return ToD;
6423
6424 // We may already have a template of the same name; try to find and match it.
6425 assert(!DC->isFunctionOrMethod() &&
6426 "Variable templates cannot be declared at function scope");
6427
6428 SmallVector<NamedDecl *, 4> ConflictingDecls;
6429 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6430 VarTemplateDecl *FoundByLookup = nullptr;
6431 for (auto *FoundDecl : FoundDecls) {
6433 continue;
6434
6435 if (VarTemplateDecl *FoundTemplate = dyn_cast<VarTemplateDecl>(FoundDecl)) {
6436 // Use the templated decl, some linkage flags are set only there.
6437 if (!hasSameVisibilityContextAndLinkage(FoundTemplate->getTemplatedDecl(),
6438 D->getTemplatedDecl()))
6439 continue;
6440 if (IsStructuralMatch(D, FoundTemplate)) {
6441 // FIXME Check for ODR error if the two definitions have
6442 // different initializers?
6443 VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
6444 if (D->getDeclContext()->isRecord()) {
6445 assert(FoundTemplate->getDeclContext()->isRecord() &&
6446 "Member variable template imported as non-member, "
6447 "inconsistent imported AST?");
6448 if (FoundDef)
6449 return Importer.MapImported(D, FoundDef);
6450 if (!D->isThisDeclarationADefinition())
6451 return Importer.MapImported(D, FoundTemplate);
6452 } else {
6453 if (FoundDef && D->isThisDeclarationADefinition())
6454 return Importer.MapImported(D, FoundDef);
6455 }
6456 FoundByLookup = FoundTemplate;
6457 break;
6458 }
6459 ConflictingDecls.push_back(FoundDecl);
6460 }
6461 }
6462
6463 if (!ConflictingDecls.empty()) {
6464 ExpectedName NameOrErr = Importer.HandleNameConflict(
6465 Name, DC, Decl::IDNS_Ordinary, ConflictingDecls.data(),
6466 ConflictingDecls.size());
6467 if (NameOrErr)
6468 Name = NameOrErr.get();
6469 else
6470 return NameOrErr.takeError();
6471 }
6472
6473 VarDecl *DTemplated = D->getTemplatedDecl();
6474
6475 // Import the type.
6476 // FIXME: Value not used?
6477 ExpectedType TypeOrErr = import(DTemplated->getType());
6478 if (!TypeOrErr)
6479 return TypeOrErr.takeError();
6480
6481 // Create the declaration that is being templated.
6482 VarDecl *ToTemplated;
6483 if (Error Err = importInto(ToTemplated, DTemplated))
6484 return std::move(Err);
6485
6486 // Create the variable template declaration itself.
6487 auto TemplateParamsOrErr = import(D->getTemplateParameters());
6488 if (!TemplateParamsOrErr)
6489 return TemplateParamsOrErr.takeError();
6490
6491 VarTemplateDecl *ToVarTD;
6492 if (GetImportedOrCreateDecl(ToVarTD, D, Importer.getToContext(), DC, Loc,
6493 Name, *TemplateParamsOrErr, ToTemplated))
6494 return ToVarTD;
6495
6496 ToTemplated->setDescribedVarTemplate(ToVarTD);
6497
6498 ToVarTD->setAccess(D->getAccess());
6499 ToVarTD->setLexicalDeclContext(LexicalDC);
6500 LexicalDC->addDeclInternal(ToVarTD);
6501 if (DC != Importer.getToContext().getTranslationUnitDecl())
6502 updateLookupTableForTemplateParameters(**TemplateParamsOrErr);
6503
6504 if (FoundByLookup) {
6505 auto *Recent =
6506 const_cast<VarTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6507 if (!ToTemplated->getPreviousDecl()) {
6508 auto *PrevTemplated =
6509 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6510 if (ToTemplated != PrevTemplated)
6511 ToTemplated->setPreviousDecl(PrevTemplated);
6512 }
6513 ToVarTD->setPreviousDecl(Recent);
6514 }
6515
6516 return ToVarTD;
6517}
6518
6521 // A VarTemplateSpecializationDecl inherits from VarDecl, the import is done
6522 // in an analog way (but specialized for this case).
6523
6525 auto RedeclIt = Redecls.begin();
6526 // Import the first part of the decl chain. I.e. import all previous
6527 // declarations starting from the canonical decl.
6528 for (; RedeclIt != Redecls.end() && *RedeclIt != D; ++RedeclIt) {
6529 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6530 if (!RedeclOrErr)
6531 return RedeclOrErr.takeError();
6532 }
6533 assert(*RedeclIt == D);
6534
6535 VarTemplateDecl *VarTemplate = nullptr;
6536 if (Error Err = importInto(VarTemplate, D->getSpecializedTemplate()))
6537 return std::move(Err);
6538
6539 // Import the context of this declaration.
6540 DeclContext *DC, *LexicalDC;
6541 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
6542 return std::move(Err);
6543
6544 // Import the location of this declaration.
6545 ExpectedSLoc BeginLocOrErr = import(D->getBeginLoc());
6546 if (!BeginLocOrErr)
6547 return BeginLocOrErr.takeError();
6548
6549 auto IdLocOrErr = import(D->getLocation());
6550 if (!IdLocOrErr)
6551 return IdLocOrErr.takeError();
6552
6553 // Import template arguments.
6555 if (Error Err =
6556 ImportTemplateArguments(D->getTemplateArgs().asArray(), TemplateArgs))
6557 return std::move(Err);
6558
6559 // Try to find an existing specialization with these template arguments.
6560 void *InsertPos = nullptr;
6561 VarTemplateSpecializationDecl *FoundSpecialization =
6562 VarTemplate->findSpecialization(TemplateArgs, InsertPos);
6563 if (FoundSpecialization) {
6564 if (IsStructuralMatch(D, FoundSpecialization)) {
6565 VarDecl *FoundDef = FoundSpecialization->getDefinition();
6566 if (D->getDeclContext()->isRecord()) {
6567 // In a record, it is allowed only to have one optional declaration and
6568 // one definition of the (static or constexpr) variable template.
6569 assert(
6570 FoundSpecialization->getDeclContext()->isRecord() &&
6571 "Member variable template specialization imported as non-member, "
6572 "inconsistent imported AST?");
6573 if (FoundDef)
6574 return Importer.MapImported(D, FoundDef);
6575 if (!D->isThisDeclarationADefinition())
6576 return Importer.MapImported(D, FoundSpecialization);
6577 } else {
6578 // If definition is imported and there is already one, map to it.
6579 // Otherwise create a new variable and link it to the existing.
6580 if (FoundDef && D->isThisDeclarationADefinition())
6581 return Importer.MapImported(D, FoundDef);
6582 }
6583 } else {
6584 return make_error<ASTImportError>(ASTImportError::NameConflict);
6585 }
6586 }
6587
6588 VarTemplateSpecializationDecl *D2 = nullptr;
6589
6590 TemplateArgumentListInfo ToTAInfo;
6591 if (const auto *Args = D->getTemplateArgsAsWritten()) {
6592 if (Error Err = ImportTemplateArgumentListInfo(*Args, ToTAInfo))
6593 return std::move(Err);
6594 }
6595
6596 using PartVarSpecDecl = VarTemplatePartialSpecializationDecl;
6597 // Create a new specialization.
6598 if (auto *FromPartial = dyn_cast<PartVarSpecDecl>(D)) {
6599 auto ToTPListOrErr = import(FromPartial->getTemplateParameters());
6600 if (!ToTPListOrErr)
6601 return ToTPListOrErr.takeError();
6602
6603 PartVarSpecDecl *ToPartial;
6604 if (GetImportedOrCreateDecl(ToPartial, D, Importer.getToContext(), DC,
6605 *BeginLocOrErr, *IdLocOrErr, *ToTPListOrErr,
6606 VarTemplate, QualType(), nullptr,
6607 D->getStorageClass(), TemplateArgs))
6608 return ToPartial;
6609
6610 if (Expected<PartVarSpecDecl *> ToInstOrErr =
6611 import(FromPartial->getInstantiatedFromMember()))
6612 ToPartial->setInstantiatedFromMember(*ToInstOrErr);
6613 else
6614 return ToInstOrErr.takeError();
6615
6616 if (FromPartial->isMemberSpecialization())
6617 ToPartial->setMemberSpecialization();
6618
6619 D2 = ToPartial;
6620
6621 // FIXME: Use this update if VarTemplatePartialSpecializationDecl is fixed
6622 // to adopt template parameters.
6623 // updateLookupTableForTemplateParameters(**ToTPListOrErr);
6624 } else { // Full specialization
6625 if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC,
6626 *BeginLocOrErr, *IdLocOrErr, VarTemplate,
6627 QualType(), nullptr, D->getStorageClass(),
6628 TemplateArgs))
6629 return D2;
6630 }
6631
6632 // Update InsertPos, because preceding import calls may have invalidated
6633 // it by adding new specializations.
6634 if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6635 VarTemplate->AddSpecialization(D2, InsertPos);
6636
6637 QualType T;
6638 if (Error Err = importInto(T, D->getType()))
6639 return std::move(Err);
6640 D2->setType(T);
6641
6642 auto TInfoOrErr = import(D->getTypeSourceInfo());
6643 if (!TInfoOrErr)
6644 return TInfoOrErr.takeError();
6645 D2->setTypeSourceInfo(*TInfoOrErr);
6646
6647 if (D->getPointOfInstantiation().isValid()) {
6648 if (ExpectedSLoc POIOrErr = import(D->getPointOfInstantiation()))
6649 D2->setPointOfInstantiation(*POIOrErr);
6650 else
6651 return POIOrErr.takeError();
6652 }
6653
6654 D2->setSpecializationKind(D->getSpecializationKind());
6655
6656 if (D->getTemplateArgsAsWritten())
6657 D2->setTemplateArgsAsWritten(ToTAInfo);
6658
6659 if (auto LocOrErr = import(D->getQualifierLoc()))
6660 D2->setQualifierInfo(*LocOrErr);
6661 else
6662 return LocOrErr.takeError();
6663
6664 if (D->isConstexpr())
6665 D2->setConstexpr(true);
6666
6667 D2->setAccess(D->getAccess());
6668
6669 if (Error Err = ImportInitializer(D, D2))
6670 return std::move(Err);
6671
6672 if (FoundSpecialization)
6673 D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
6674
6675 addDeclToContexts(D, D2);
6676
6677 // Import the rest of the chain. I.e. import all subsequent declarations.
6678 for (++RedeclIt; RedeclIt != Redecls.end(); ++RedeclIt) {
6679 ExpectedDecl RedeclOrErr = import(*RedeclIt);
6680 if (!RedeclOrErr)
6681 return RedeclOrErr.takeError();
6682 }
6683
6684 return D2;
6685}
6686
6689 DeclContext *DC, *LexicalDC;
6690 DeclarationName Name;
6692 NamedDecl *ToD;
6693
6694 if (Error Err = ImportDeclParts(D, DC, LexicalDC, Name, ToD, Loc))
6695 return std::move(Err);
6696
6697 if (ToD)
6698 return ToD;
6699
6700 const FunctionTemplateDecl *FoundByLookup = nullptr;
6701
6702 // Try to find a function in our own ("to") context with the same name, same
6703 // type, and in the same context as the function we're importing.
6704 // FIXME Split this into a separate function.
6705 if (!LexicalDC->isFunctionOrMethod()) {
6707 auto FoundDecls = Importer.findDeclsInToCtx(DC, Name);
6708 for (auto *FoundDecl : FoundDecls) {
6709 if (!FoundDecl->isInIdentifierNamespace(IDNS))
6710 continue;
6711
6712 if (auto *FoundTemplate = dyn_cast<FunctionTemplateDecl>(FoundDecl)) {
6713 if (!hasSameVisibilityContextAndLinkage(FoundTemplate, D))
6714 continue;
6715 if (IsStructuralMatch(D, FoundTemplate)) {
6716 FunctionTemplateDecl *TemplateWithDef =
6717 getTemplateDefinition(FoundTemplate);
6718 if (D->isThisDeclarationADefinition() && TemplateWithDef)
6719 return Importer.MapImported(D, TemplateWithDef);
6720
6721 FoundByLookup = FoundTemplate;
6722 break;
6723 // TODO: handle conflicting names
6724 }
6725 }
6726 }
6727 }
6728
6729 auto ParamsOrErr = import(D->getTemplateParameters());
6730 if (!ParamsOrErr)
6731 return ParamsOrErr.takeError();
6732 TemplateParameterList *Params = *ParamsOrErr;
6733
6734 FunctionDecl *TemplatedFD;
6735 if (Error Err = importInto(TemplatedFD, D->getTemplatedDecl()))
6736 return std::move(Err);
6737
6738 // At creation of the template the template parameters are "adopted"
6739 // (DeclContext is changed). After this possible change the lookup table
6740 // must be updated.
6741 // At deduction guides the DeclContext of the template parameters may be
6742 // different from what we would expect, it may be the class template, or a
6743 // probably different CXXDeductionGuideDecl. This may come from the fact that
6744 // the template parameter objects may be shared between deduction guides or
6745 // the class template, and at creation of multiple FunctionTemplateDecl
6746 // objects (for deduction guides) the same parameters are re-used. The
6747 // "adoption" happens multiple times with different parent, even recursively
6748 // for TemplateTemplateParmDecl. The same happens at import when the
6749 // FunctionTemplateDecl objects are created, but in different order.
6750 // In this way the DeclContext of these template parameters is not necessarily
6751 // the same as in the "from" context.
6753 OldParamDC.reserve(Params->size());
6754 llvm::transform(*Params, std::back_inserter(OldParamDC),
6755 [](NamedDecl *ND) { return ND->getDeclContext(); });
6756
6757 FunctionTemplateDecl *ToFunc;
6758 if (GetImportedOrCreateDecl(ToFunc, D, Importer.getToContext(), DC, Loc, Name,
6759 Params, TemplatedFD))
6760 return ToFunc;
6761
6762 // Fail if TemplatedFD is already part of a template.
6763 // The template should have been found by structural equivalence check before,
6764 // or ToFunc should be already imported.
6765 // If not, there is AST incompatibility that can be caused by previous import
6766 // errors. (NameConflict is not exact here.)
6767 if (TemplatedFD->getDescribedTemplate())
6768 return make_error<ASTImportError>(ASTImportError::NameConflict);
6769
6770 TemplatedFD->setDescribedFunctionTemplate(ToFunc);
6771
6772 ToFunc->setAccess(D->getAccess());
6773 ToFunc->setLexicalDeclContext(LexicalDC);
6774 addDeclToContexts(D, ToFunc);
6775
6776 ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable();
6777 if (LT && !OldParamDC.empty()) {
6778 for (unsigned int I = 0; I < OldParamDC.size(); ++I)
6779 LT->updateForced(Params->getParam(I), OldParamDC[I]);
6780 }
6781
6782 if (FoundByLookup) {
6783 auto *Recent =
6784 const_cast<FunctionTemplateDecl *>(FoundByLookup->getMostRecentDecl());
6785 if (!TemplatedFD->getPreviousDecl()) {
6786 assert(FoundByLookup->getTemplatedDecl() &&
6787 "Found decl must have its templated decl set");
6788 auto *PrevTemplated =
6789 FoundByLookup->getTemplatedDecl()->getMostRecentDecl();
6790 if (TemplatedFD != PrevTemplated)
6791 TemplatedFD->setPreviousDecl(PrevTemplated);
6792 }
6793 ToFunc->setPreviousDecl(Recent);
6794 }
6795
6796 return ToFunc;
6797}
6798
6799//----------------------------------------------------------------------------
6800// Import Statements
6801//----------------------------------------------------------------------------
6802
6804 Importer.FromDiag(S->getBeginLoc(), diag::err_unsupported_ast_node)
6805 << S->getStmtClassName();
6806 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6807}
6808
6809
6811 if (Importer.returnWithErrorInTest())
6812 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
6814 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6815 IdentifierInfo *ToII = Importer.Import(S->getOutputIdentifier(I));
6816 // ToII is nullptr when no symbolic name is given for output operand
6817 // see ParseStmtAsm::ParseAsmOperandsOpt
6818 Names.push_back(ToII);
6819 }
6820
6821 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6822 IdentifierInfo *ToII = Importer.Import(S->getInputIdentifier(I));
6823 // ToII is nullptr when no symbolic name is given for input operand
6824 // see ParseStmtAsm::ParseAsmOperandsOpt
6825 Names.push_back(ToII);
6826 }
6827
6829 for (unsigned I = 0, E = S->getNumClobbers(); I != E; I++) {
6830 if (auto ClobberOrErr = import(S->getClobberStringLiteral(I)))
6831 Clobbers.push_back(*ClobberOrErr);
6832 else
6833 return ClobberOrErr.takeError();
6834
6835 }
6836
6838 for (unsigned I = 0, E = S->getNumOutputs(); I != E; I++) {
6839 if (auto OutputOrErr = import(S->getOutputConstraintLiteral(I)))
6840 Constraints.push_back(*OutputOrErr);
6841 else
6842 return OutputOrErr.takeError();
6843 }
6844
6845 for (unsigned I = 0, E = S->getNumInputs(); I != E; I++) {
6846 if (auto InputOrErr = import(S->getInputConstraintLiteral(I)))
6847 Constraints.push_back(*InputOrErr);
6848 else
6849 return InputOrErr.takeError();
6850 }
6851
6852 SmallVector<Expr *, 4> Exprs(S->getNumOutputs() + S->getNumInputs() +
6853 S->getNumLabels());
6854 if (Error Err = ImportContainerChecked(S->outputs(), Exprs))
6855 return std::move(Err);
6856
6857 if (Error Err =
6858 ImportArrayChecked(S->inputs(), Exprs.begin() + S->getNumOutputs()))
6859 return std::move(Err);
6860
6861 if (Error Err = ImportArrayChecked(
6862 S->labels(), Exprs.begin() + S->getNumOutputs() + S->getNumInputs()))
6863 return std::move(Err);
6864
6865 ExpectedSLoc AsmLocOrErr = import(S->getAsmLoc());
6866 if (!AsmLocOrErr)
6867 return AsmLocOrErr.takeError();
6868 auto AsmStrOrErr = import(S->getAsmString());
6869 if (!AsmStrOrErr)
6870 return AsmStrOrErr.takeError();
6871 ExpectedSLoc RParenLocOrErr = import(S->getRParenLoc());
6872 if (!RParenLocOrErr)
6873 return RParenLocOrErr.takeError();
6874
6875 return new (Importer.getToContext()) GCCAsmStmt(
6876 Importer.getToContext(),
6877 *AsmLocOrErr,
6878 S->isSimple(),
6879 S->isVolatile(),
6880 S->getNumOutputs(),
6881 S->getNumInputs(),
6882 Names.data(),
6883 Constraints.data(),
6884 Exprs.data(),
6885 *AsmStrOrErr,
6886 S->getNumClobbers(),
6887 Clobbers.data(),
6888 S->getNumLabels(),
6889 *RParenLocOrErr);
6890}
6891
6893
6894 Error Err = Error::success();
6895 auto ToDG = importChecked(Err, S->getDeclGroup());
6896 auto ToBeginLoc = importChecked(Err, S->getBeginLoc());
6897 auto ToEndLoc = importChecked(Err, S->getEndLoc());
6898 if (Err)
6899 return std::move(Err);
6900 return new (Importer.getToContext()) DeclStmt(ToDG, ToBeginLoc, ToEndLoc);
6901}
6902
6904 ExpectedSLoc ToSemiLocOrErr = import(S->getSemiLoc());
6905 if (!ToSemiLocOrErr)
6906 return ToSemiLocOrErr.takeError();
6907 return new (Importer.getToContext()) NullStmt(
6908 *ToSemiLocOrErr, S->hasLeadingEmptyMacro());
6909}
6910
6912 SmallVector<Stmt *, 8> ToStmts(S->size());
6913
6914 if (Error Err = ImportContainerChecked(S->body(), ToStmts))
6915 return std::move(Err);
6916
6917 ExpectedSLoc ToLBracLocOrErr = import(S->getLBracLoc());
6918 if (!ToLBracLocOrErr)
6919 return ToLBracLocOrErr.takeError();
6920
6921 ExpectedSLoc ToRBracLocOrErr = import(S->getRBracLoc());
6922 if (!ToRBracLocOrErr)
6923 return ToRBracLocOrErr.takeError();
6924
6925 FPOptionsOverride FPO =
6926 S->hasStoredFPFeatures() ? S->getStoredFPFeatures() : FPOptionsOverride();
6927 return CompoundStmt::Create(Importer.getToContext(), ToStmts, FPO,
6928 *ToLBracLocOrErr, *ToRBracLocOrErr);
6929}
6930
6932
6933 Error Err = Error::success();
6934 auto ToLHS = importChecked(Err, S->getLHS());
6935 auto ToRHS = importChecked(Err, S->getRHS());
6936 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6937 auto ToCaseLoc = importChecked(Err, S->getCaseLoc());
6938 auto ToEllipsisLoc = importChecked(Err, S->getEllipsisLoc());
6939 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6940 if (Err)
6941 return std::move(Err);
6942
6943 auto *ToStmt = CaseStmt::Create(Importer.getToContext(), ToLHS, ToRHS,
6944 ToCaseLoc, ToEllipsisLoc, ToColonLoc);
6945 ToStmt->setSubStmt(ToSubStmt);
6946
6947 return ToStmt;
6948}
6949
6951
6952 Error Err = Error::success();
6953 auto ToDefaultLoc = importChecked(Err, S->getDefaultLoc());
6954 auto ToColonLoc = importChecked(Err, S->getColonLoc());
6955 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6956 if (Err)
6957 return std::move(Err);
6958
6959 return new (Importer.getToContext()) DefaultStmt(
6960 ToDefaultLoc, ToColonLoc, ToSubStmt);
6961}
6962
6964
6965 Error Err = Error::success();
6966 auto ToIdentLoc = importChecked(Err, S->getIdentLoc());
6967 auto ToLabelDecl = importChecked(Err, S->getDecl());
6968 auto ToSubStmt = importChecked(Err, S->getSubStmt());
6969 if (Err)
6970 return std::move(Err);
6971
6972 return new (Importer.getToContext()) LabelStmt(
6973 ToIdentLoc, ToLabelDecl, ToSubStmt);
6974}
6975
6977 ExpectedSLoc ToAttrLocOrErr = import(S->getAttrLoc());
6978 if (!ToAttrLocOrErr)
6979 return ToAttrLocOrErr.takeError();
6980 ArrayRef<const Attr*> FromAttrs(S->getAttrs());
6981 SmallVector<const Attr *, 1> ToAttrs(FromAttrs.size());
6982 if (Error Err = ImportContainerChecked(FromAttrs, ToAttrs))
6983 return std::move(Err);
6984 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
6985 if (!ToSubStmtOrErr)
6986 return ToSubStmtOrErr.takeError();
6987
6989 Importer.getToContext(), *ToAttrLocOrErr, ToAttrs, *ToSubStmtOrErr);
6990}
6991
6993
6994 Error Err = Error::success();
6995 auto ToIfLoc = importChecked(Err, S->getIfLoc());
6996 auto ToInit = importChecked(Err, S->getInit());
6997 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
6998 auto ToCond = importChecked(Err, S->getCond());
6999 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7000 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7001 auto ToThen = importChecked(Err, S->getThen());
7002 auto ToElseLoc = importChecked(Err, S->getElseLoc());
7003 auto ToElse = importChecked(Err, S->getElse());
7004 if (Err)
7005 return std::move(Err);
7006
7007 return IfStmt::Create(Importer.getToContext(), ToIfLoc, S->getStatementKind(),
7008 ToInit, ToConditionVariable, ToCond, ToLParenLoc,
7009 ToRParenLoc, ToThen, ToElseLoc, ToElse);
7010}
7011
7013
7014 Error Err = Error::success();
7015 auto ToInit = importChecked(Err, S->getInit());
7016 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7017 auto ToCond = importChecked(Err, S->getCond());
7018 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7019 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7020 auto ToBody = importChecked(Err, S->getBody());
7021 auto ToSwitchLoc = importChecked(Err, S->getSwitchLoc());
7022 if (Err)
7023 return std::move(Err);
7024
7025 auto *ToStmt =
7026 SwitchStmt::Create(Importer.getToContext(), ToInit, ToConditionVariable,
7027 ToCond, ToLParenLoc, ToRParenLoc);
7028 ToStmt->setBody(ToBody);
7029 ToStmt->setSwitchLoc(ToSwitchLoc);
7030
7031 // Now we have to re-chain the cases.
7032 SwitchCase *LastChainedSwitchCase = nullptr;
7033 for (SwitchCase *SC = S->getSwitchCaseList(); SC != nullptr;
7034 SC = SC->getNextSwitchCase()) {
7035 Expected<SwitchCase *> ToSCOrErr = import(SC);
7036 if (!ToSCOrErr)
7037 return ToSCOrErr.takeError();
7038 if (LastChainedSwitchCase)
7039 LastChainedSwitchCase->setNextSwitchCase(*ToSCOrErr);
7040 else
7041 ToStmt->setSwitchCaseList(*ToSCOrErr);
7042 LastChainedSwitchCase = *ToSCOrErr;
7043 }
7044
7045 return ToStmt;
7046}
7047
7049
7050 Error Err = Error::success();
7051 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7052 auto ToCond = importChecked(Err, S->getCond());
7053 auto ToBody = importChecked(Err, S->getBody());
7054 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7055 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7056 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7057 if (Err)
7058 return std::move(Err);
7059
7060 return WhileStmt::Create(Importer.getToContext(), ToConditionVariable, ToCond,
7061 ToBody, ToWhileLoc, ToLParenLoc, ToRParenLoc);
7062}
7063
7065
7066 Error Err = Error::success();
7067 auto ToBody = importChecked(Err, S->getBody());
7068 auto ToCond = importChecked(Err, S->getCond());
7069 auto ToDoLoc = importChecked(Err, S->getDoLoc());
7070 auto ToWhileLoc = importChecked(Err, S->getWhileLoc());
7071 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7072 if (Err)
7073 return std::move(Err);
7074
7075 return new (Importer.getToContext()) DoStmt(
7076 ToBody, ToCond, ToDoLoc, ToWhileLoc, ToRParenLoc);
7077}
7078
7080
7081 Error Err = Error::success();
7082 auto ToInit = importChecked(Err, S->getInit());
7083 auto ToCond = importChecked(Err, S->getCond());
7084 auto ToConditionVariable = importChecked(Err, S->getConditionVariable());
7085 auto ToInc = importChecked(Err, S->getInc());
7086 auto ToBody = importChecked(Err, S->getBody());
7087 auto ToForLoc = importChecked(Err, S->getForLoc());
7088 auto ToLParenLoc = importChecked(Err, S->getLParenLoc());
7089 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7090 if (Err)
7091 return std::move(Err);
7092
7093 return new (Importer.getToContext()) ForStmt(
7094 Importer.getToContext(),
7095 ToInit, ToCond, ToConditionVariable, ToInc, ToBody, ToForLoc, ToLParenLoc,
7096 ToRParenLoc);
7097}
7098
7100
7101 Error Err = Error::success();
7102 auto ToLabel = importChecked(Err, S->getLabel());
7103 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7104 auto ToLabelLoc = importChecked(Err, S->getLabelLoc());
7105 if (Err)
7106 return std::move(Err);
7107
7108 return new (Importer.getToContext()) GotoStmt(
7109 ToLabel, ToGotoLoc, ToLabelLoc);
7110}
7111
7113
7114 Error Err = Error::success();
7115 auto ToGotoLoc = importChecked(Err, S->getGotoLoc());
7116 auto ToStarLoc = importChecked(Err, S->getStarLoc());
7117 auto ToTarget = importChecked(Err, S->getTarget());
7118 if (Err)
7119 return std::move(Err);
7120
7121 return new (Importer.getToContext()) IndirectGotoStmt(
7122 ToGotoLoc, ToStarLoc, ToTarget);
7123}
7124
7126 ExpectedSLoc ToContinueLocOrErr = import(S->getContinueLoc());
7127 if (!ToContinueLocOrErr)
7128 return ToContinueLocOrErr.takeError();
7129 return new (Importer.getToContext()) ContinueStmt(*ToContinueLocOrErr);
7130}
7131
7133 auto ToBreakLocOrErr = import(S->getBreakLoc());
7134 if (!ToBreakLocOrErr)
7135 return ToBreakLocOrErr.takeError();
7136 return new (Importer.getToContext()) BreakStmt(*ToBreakLocOrErr);
7137}
7138
7140
7141 Error Err = Error::success();
7142 auto ToReturnLoc = importChecked(Err, S->getReturnLoc());
7143 auto ToRetValue = importChecked(Err, S->getRetValue());
7144 auto ToNRVOCandidate = importChecked(Err, S->getNRVOCandidate());
7145 if (Err)
7146 return std::move(Err);
7147
7148 return ReturnStmt::Create(Importer.getToContext(), ToReturnLoc, ToRetValue,
7149 ToNRVOCandidate);
7150}
7151
7153
7154 Error Err = Error::success();
7155 auto ToCatchLoc = importChecked(Err, S->getCatchLoc());
7156 auto ToExceptionDecl = importChecked(Err, S->getExceptionDecl());
7157 auto ToHandlerBlock = importChecked(Err, S->getHandlerBlock());
7158 if (Err)
7159 return std::move(Err);
7160
7161 return new (Importer.getToContext()) CXXCatchStmt (
7162 ToCatchLoc, ToExceptionDecl, ToHandlerBlock);
7163}
7164
7166 ExpectedSLoc ToTryLocOrErr = import(S->getTryLoc());
7167 if (!ToTryLocOrErr)
7168 return ToTryLocOrErr.takeError();
7169
7170 ExpectedStmt ToTryBlockOrErr = import(S->getTryBlock());
7171 if (!ToTryBlockOrErr)
7172 return ToTryBlockOrErr.takeError();
7173
7174 SmallVector<Stmt *, 1> ToHandlers(S->getNumHandlers());
7175 for (unsigned HI = 0, HE = S->getNumHandlers(); HI != HE; ++HI) {
7176 CXXCatchStmt *FromHandler = S->getHandler(HI);
7177 if (auto ToHandlerOrErr = import(FromHandler))
7178 ToHandlers[HI] = *ToHandlerOrErr;
7179 else
7180 return ToHandlerOrErr.takeError();
7181 }
7182
7183 return CXXTryStmt::Create(Importer.getToContext(), *ToTryLocOrErr,
7184 cast<CompoundStmt>(*ToTryBlockOrErr), ToHandlers);
7185}
7186
7188
7189 Error Err = Error::success();
7190 auto ToInit = importChecked(Err, S->getInit());
7191 auto ToRangeStmt = importChecked(Err, S->getRangeStmt());
7192 auto ToBeginStmt = importChecked(Err, S->getBeginStmt());
7193 auto ToEndStmt = importChecked(Err, S->getEndStmt());
7194 auto ToCond = importChecked(Err, S->getCond());
7195 auto ToInc = importChecked(Err, S->getInc());
7196 auto ToLoopVarStmt = importChecked(Err, S->getLoopVarStmt());
7197 auto ToBody = importChecked(Err, S->getBody());
7198 auto ToForLoc = importChecked(Err, S->getForLoc());
7199 auto ToCoawaitLoc = importChecked(Err, S->getCoawaitLoc());
7200 auto ToColonLoc = importChecked(Err, S->getColonLoc());
7201 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7202 if (Err)
7203 return std::move(Err);
7204
7205 return new (Importer.getToContext()) CXXForRangeStmt(
7206 ToInit, ToRangeStmt, ToBeginStmt, ToEndStmt, ToCond, ToInc, ToLoopVarStmt,
7207 ToBody, ToForLoc, ToCoawaitLoc, ToColonLoc, ToRParenLoc);
7208}
7209
7212 Error Err = Error::success();
7213 auto ToElement = importChecked(Err, S->getElement());
7214 auto ToCollection = importChecked(Err, S->getCollection());
7215 auto ToBody = importChecked(Err, S->getBody());
7216 auto ToForLoc = importChecked(Err, S->getForLoc());
7217 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7218 if (Err)
7219 return std::move(Err);
7220
7221 return new (Importer.getToContext()) ObjCForCollectionStmt(ToElement,
7222 ToCollection,
7223 ToBody,
7224 ToForLoc,
7225 ToRParenLoc);
7226}
7227
7229
7230 Error Err = Error::success();
7231 auto ToAtCatchLoc = importChecked(Err, S->getAtCatchLoc());
7232 auto ToRParenLoc = importChecked(Err, S->getRParenLoc());
7233 auto ToCatchParamDecl = importChecked(Err, S->getCatchParamDecl());
7234 auto ToCatchBody = importChecked(Err, S->getCatchBody());
7235 if (Err)
7236 return std::move(Err);
7237
7238 return new (Importer.getToContext()) ObjCAtCatchStmt (
7239 ToAtCatchLoc, ToRParenLoc, ToCatchParamDecl, ToCatchBody);
7240}
7241
7243 ExpectedSLoc ToAtFinallyLocOrErr = import(S->getAtFinallyLoc());
7244 if (!ToAtFinallyLocOrErr)
7245 return ToAtFinallyLocOrErr.takeError();
7246 ExpectedStmt ToAtFinallyStmtOrErr = import(S->getFinallyBody());
7247 if (!ToAtFinallyStmtOrErr)
7248 return ToAtFinallyStmtOrErr.takeError();
7249 return new (Importer.getToContext()) ObjCAtFinallyStmt(*ToAtFinallyLocOrErr,
7250 *ToAtFinallyStmtOrErr);
7251}
7252
7254
7255 Error Err = Error::success();
7256 auto ToAtTryLoc = importChecked(Err, S->getAtTryLoc());
7257 auto ToTryBody = importChecked(Err, S->getTryBody());
7258 auto ToFinallyStmt = importChecked(Err, S->getFinallyStmt());
7259 if (Err)
7260 return std::move(Err);
7261
7262 SmallVector<Stmt *, 1> ToCatchStmts(S->getNumCatchStmts());
7263 for (unsigned CI = 0, CE = S->getNumCatchStmts(); CI != CE; ++CI) {
7264 ObjCAtCatchStmt *FromCatchStmt = S->getCatchStmt(CI);
7265 if (ExpectedStmt ToCatchStmtOrErr = import(FromCatchStmt))
7266 ToCatchStmts[CI] = *ToCatchStmtOrErr;
7267 else
7268 return ToCatchStmtOrErr.takeError();
7269 }
7270
7271 return ObjCAtTryStmt::Create(Importer.getToContext(),
7272 ToAtTryLoc, ToTryBody,
7273 ToCatchStmts.begin(), ToCatchStmts.size(),
7274 ToFinallyStmt);
7275}
7276
7279
7280 Error Err = Error::success();
7281 auto ToAtSynchronizedLoc = importChecked(Err, S->getAtSynchronizedLoc());
7282 auto ToSynchExpr = importChecked(Err, S->getSynchExpr());
7283 auto ToSynchBody = importChecked(Err, S->getSynchBody());
7284 if (Err)
7285 return std::move(Err);
7286
7287 return new (Importer.getToContext()) ObjCAtSynchronizedStmt(
7288 ToAtSynchronizedLoc, ToSynchExpr, ToSynchBody);
7289}
7290
7292 ExpectedSLoc ToThrowLocOrErr = import(S->getThrowLoc());
7293 if (!ToThrowLocOrErr)
7294 return ToThrowLocOrErr.takeError();
7295 ExpectedExpr ToThrowExprOrErr = import(S->getThrowExpr());
7296 if (!ToThrowExprOrErr)
7297 return ToThrowExprOrErr.takeError();
7298 return new (Importer.getToContext()) ObjCAtThrowStmt(
7299 *ToThrowLocOrErr, *ToThrowExprOrErr);
7300}
7301
7304 ExpectedSLoc ToAtLocOrErr = import(S->getAtLoc());
7305 if (!ToAtLocOrErr)
7306 return ToAtLocOrErr.takeError();
7307 ExpectedStmt ToSubStmtOrErr = import(S->getSubStmt());
7308 if (!ToSubStmtOrErr)
7309 return ToSubStmtOrErr.takeError();
7310 return new (Importer.getToContext()) ObjCAutoreleasePoolStmt(*ToAtLocOrErr,
7311 *ToSubStmtOrErr);
7312}
7313
7314//----------------------------------------------------------------------------
7315// Import Expressions
7316//----------------------------------------------------------------------------
7318 Importer.FromDiag(E->getBeginLoc(), diag::err_unsupported_ast_node)
7319 << E->getStmtClassName();
7320 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
7321}
7322
7324 Error Err = Error::success();
7325 auto ToType = importChecked(Err, E->getType());
7326 auto BLoc = importChecked(Err, E->getBeginLoc());
7327 auto RParenLoc = importChecked(Err, E->getEndLoc());
7328 if (Err)
7329 return std::move(Err);
7330 auto ParentContextOrErr = Importer.ImportContext(E->getParentContext());
7331 if (!ParentContextOrErr)
7332 return ParentContextOrErr.takeError();
7333
7334 return new (Importer.getToContext())
7335 SourceLocExpr(Importer.getToContext(), E->getIdentKind(), ToType, BLoc,
7336 RParenLoc, *ParentContextOrErr);
7337}
7338
7340
7341 Error Err = Error::success();
7342 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7343 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7344 auto ToWrittenTypeInfo = importChecked(Err, E->getWrittenTypeInfo());
7345 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7346 auto ToType = importChecked(Err, E->getType());
7347 if (Err)
7348 return std::move(Err);
7349
7350 return new (Importer.getToContext()) VAArgExpr(
7351 ToBuiltinLoc, ToSubExpr, ToWrittenTypeInfo, ToRParenLoc, ToType,
7352 E->isMicrosoftABI());
7353}
7354
7356
7357 Error Err = Error::success();
7358 auto ToCond = importChecked(Err, E->getCond());
7359 auto ToLHS = importChecked(Err, E->getLHS());
7360 auto ToRHS = importChecked(Err, E->getRHS());
7361 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7362 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7363 auto ToType = importChecked(Err, E->getType());
7364 if (Err)
7365 return std::move(Err);
7366
7369
7370 // The value of CondIsTrue only matters if the value is not
7371 // condition-dependent.
7372 bool CondIsTrue = !E->isConditionDependent() && E->isConditionTrue();
7373
7374 return new (Importer.getToContext())
7375 ChooseExpr(ToBuiltinLoc, ToCond, ToLHS, ToRHS, ToType, VK, OK,
7376 ToRParenLoc, CondIsTrue);
7377}
7378
7380 Error Err = Error::success();
7381 auto *ToSrcExpr = importChecked(Err, E->getSrcExpr());
7382 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7383 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7384 auto ToType = importChecked(Err, E->getType());
7385 auto *ToTSI = importChecked(Err, E->getTypeSourceInfo());
7386 if (Err)
7387 return std::move(Err);
7388
7389 return new (Importer.getToContext())
7390 ConvertVectorExpr(ToSrcExpr, ToTSI, ToType, E->getValueKind(),
7391 E->getObjectKind(), ToBuiltinLoc, ToRParenLoc);
7392}
7393
7395 Error Err = Error::success();
7396 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7397 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7398 auto ToType = importChecked(Err, E->getType());
7399 const unsigned NumSubExprs = E->getNumSubExprs();
7400
7402 llvm::ArrayRef<Expr *> FromSubExprs(E->getSubExprs(), NumSubExprs);
7403 ToSubExprs.resize(NumSubExprs);
7404
7405 if ((Err = ImportContainerChecked(FromSubExprs, ToSubExprs)))
7406 return std::move(Err);
7407
7408 return new (Importer.getToContext()) ShuffleVectorExpr(
7409 Importer.getToContext(), ToSubExprs, ToType, ToBeginLoc, ToRParenLoc);
7410}
7411
7413 ExpectedType TypeOrErr = import(E->getType());
7414 if (!TypeOrErr)
7415 return TypeOrErr.takeError();
7416
7417 ExpectedSLoc BeginLocOrErr = import(E->getBeginLoc());
7418 if (!BeginLocOrErr)
7419 return BeginLocOrErr.takeError();
7420
7421 return new (Importer.getToContext()) GNUNullExpr(*TypeOrErr, *BeginLocOrErr);
7422}
7423
7426 Error Err = Error::success();
7427 auto ToGenericLoc = importChecked(Err, E->getGenericLoc());
7428 Expr *ToControllingExpr = nullptr;
7429 TypeSourceInfo *ToControllingType = nullptr;
7430 if (E->isExprPredicate())
7431 ToControllingExpr = importChecked(Err, E->getControllingExpr());
7432 else
7433 ToControllingType = importChecked(Err, E->getControllingType());
7434 assert((ToControllingExpr || ToControllingType) &&
7435 "Either the controlling expr or type must be nonnull");
7436 auto ToDefaultLoc = importChecked(Err, E->getDefaultLoc());
7437 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7438 if (Err)
7439 return std::move(Err);
7440
7441 ArrayRef<const TypeSourceInfo *> FromAssocTypes(E->getAssocTypeSourceInfos());
7442 SmallVector<TypeSourceInfo *, 1> ToAssocTypes(FromAssocTypes.size());
7443 if (Error Err = ImportContainerChecked(FromAssocTypes, ToAssocTypes))
7444 return std::move(Err);
7445
7446 ArrayRef<const Expr *> FromAssocExprs(E->getAssocExprs());
7447 SmallVector<Expr *, 1> ToAssocExprs(FromAssocExprs.size());
7448 if (Error Err = ImportContainerChecked(FromAssocExprs, ToAssocExprs))
7449 return std::move(Err);
7450
7451 const ASTContext &ToCtx = Importer.getToContext();
7452 if (E->isResultDependent()) {
7453 if (ToControllingExpr) {
7455 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7456 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7458 }
7460 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7461 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7463 }
7464
7465 if (ToControllingExpr) {
7467 ToCtx, ToGenericLoc, ToControllingExpr, llvm::ArrayRef(ToAssocTypes),
7468 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7469 E->containsUnexpandedParameterPack(), E->getResultIndex());
7470 }
7472 ToCtx, ToGenericLoc, ToControllingType, llvm::ArrayRef(ToAssocTypes),
7473 llvm::ArrayRef(ToAssocExprs), ToDefaultLoc, ToRParenLoc,
7474 E->containsUnexpandedParameterPack(), E->getResultIndex());
7475}
7476
7478
7479 Error Err = Error::success();
7480 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7481 auto ToType = importChecked(Err, E->getType());
7482 auto ToFunctionName = importChecked(Err, E->getFunctionName());
7483 if (Err)
7484 return std::move(Err);
7485
7486 return PredefinedExpr::Create(Importer.getToContext(), ToBeginLoc, ToType,
7487 E->getIdentKind(), E->isTransparent(),
7488 ToFunctionName);
7489}
7490
7492
7493 Error Err = Error::success();
7494 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
7495 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
7496 auto ToDecl = importChecked(Err, E->getDecl());
7497 auto ToLocation = importChecked(Err, E->getLocation());
7498 auto ToType = importChecked(Err, E->getType());
7499 if (Err)
7500 return std::move(Err);
7501
7502 NamedDecl *ToFoundD = nullptr;
7503 if (E->getDecl() != E->getFoundDecl()) {
7504 auto FoundDOrErr = import(E->getFoundDecl());
7505 if (!FoundDOrErr)
7506 return FoundDOrErr.takeError();
7507 ToFoundD = *FoundDOrErr;
7508 }
7509
7510 TemplateArgumentListInfo ToTAInfo;
7511 TemplateArgumentListInfo *ToResInfo = nullptr;
7512 if (E->hasExplicitTemplateArgs()) {
7513 if (Error Err =
7514 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
7515 E->template_arguments(), ToTAInfo))
7516 return std::move(Err);
7517 ToResInfo = &ToTAInfo;
7518 }
7519
7520 auto *ToE = DeclRefExpr::Create(
7521 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc, ToDecl,
7522 E->refersToEnclosingVariableOrCapture(), ToLocation, ToType,
7523 E->getValueKind(), ToFoundD, ToResInfo, E->isNonOdrUse());
7524 if (E->hadMultipleCandidates())
7525 ToE->setHadMultipleCandidates(true);
7526 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
7527 return ToE;
7528}
7529
7531 ExpectedType TypeOrErr = import(E->getType());
7532 if (!TypeOrErr)
7533 return TypeOrErr.takeError();
7534
7535 return new (Importer.getToContext()) ImplicitValueInitExpr(*TypeOrErr);
7536}
7537
7539 ExpectedExpr ToInitOrErr = import(E->getInit());
7540 if (!ToInitOrErr)
7541 return ToInitOrErr.takeError();
7542
7543 ExpectedSLoc ToEqualOrColonLocOrErr = import(E->getEqualOrColonLoc());
7544 if (!ToEqualOrColonLocOrErr)
7545 return ToEqualOrColonLocOrErr.takeError();
7546
7547 SmallVector<Expr *, 4> ToIndexExprs(E->getNumSubExprs() - 1);
7548 // List elements from the second, the first is Init itself
7549 for (unsigned I = 1, N = E->getNumSubExprs(); I < N; I++) {
7550 if (ExpectedExpr ToArgOrErr = import(E->getSubExpr(I)))
7551 ToIndexExprs[I - 1] = *ToArgOrErr;
7552 else
7553 return ToArgOrErr.takeError();
7554 }
7555
7556 SmallVector<Designator, 4> ToDesignators(E->size());
7557 if (Error Err = ImportContainerChecked(E->designators(), ToDesignators))
7558 return std::move(Err);
7559
7561 Importer.getToContext(), ToDesignators,
7562 ToIndexExprs, *ToEqualOrColonLocOrErr,
7563 E->usesGNUSyntax(), *ToInitOrErr);
7564}
7565
7568 ExpectedType ToTypeOrErr = import(E->getType());
7569 if (!ToTypeOrErr)
7570 return ToTypeOrErr.takeError();
7571
7572 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7573 if (!ToLocationOrErr)
7574 return ToLocationOrErr.takeError();
7575
7576 return new (Importer.getToContext()) CXXNullPtrLiteralExpr(
7577 *ToTypeOrErr, *ToLocationOrErr);
7578}
7579
7581 ExpectedType ToTypeOrErr = import(E->getType());
7582 if (!ToTypeOrErr)
7583 return ToTypeOrErr.takeError();
7584
7585 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7586 if (!ToLocationOrErr)
7587 return ToLocationOrErr.takeError();
7588
7590 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr);
7591}
7592
7593
7595 ExpectedType ToTypeOrErr = import(E->getType());
7596 if (!ToTypeOrErr)
7597 return ToTypeOrErr.takeError();
7598
7599 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7600 if (!ToLocationOrErr)
7601 return ToLocationOrErr.takeError();
7602
7604 Importer.getToContext(), E->getValue(), E->isExact(),
7605 *ToTypeOrErr, *ToLocationOrErr);
7606}
7607
7609 auto ToTypeOrErr = import(E->getType());
7610 if (!ToTypeOrErr)
7611 return ToTypeOrErr.takeError();
7612
7613 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7614 if (!ToSubExprOrErr)
7615 return ToSubExprOrErr.takeError();
7616
7617 return new (Importer.getToContext()) ImaginaryLiteral(
7618 *ToSubExprOrErr, *ToTypeOrErr);
7619}
7620
7622 auto ToTypeOrErr = import(E->getType());
7623 if (!ToTypeOrErr)
7624 return ToTypeOrErr.takeError();
7625
7626 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7627 if (!ToLocationOrErr)
7628 return ToLocationOrErr.takeError();
7629
7630 return new (Importer.getToContext()) FixedPointLiteral(
7631 Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
7632 Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
7633}
7634
7636 ExpectedType ToTypeOrErr = import(E->getType());
7637 if (!ToTypeOrErr)
7638 return ToTypeOrErr.takeError();
7639
7640 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
7641 if (!ToLocationOrErr)
7642 return ToLocationOrErr.takeError();
7643
7644 return new (Importer.getToContext()) CharacterLiteral(
7645 E->getValue(), E->getKind(), *ToTypeOrErr, *ToLocationOrErr);
7646}
7647
7649 ExpectedType ToTypeOrErr = import(E->getType());
7650 if (!ToTypeOrErr)
7651 return ToTypeOrErr.takeError();
7652
7653 SmallVector<SourceLocation, 4> ToLocations(E->getNumConcatenated());
7654 if (Error Err = ImportArrayChecked(
7655 E->tokloc_begin(), E->tokloc_end(), ToLocations.begin()))
7656 return std::move(Err);
7657
7658 return StringLiteral::Create(
7659 Importer.getToContext(), E->getBytes(), E->getKind(), E->isPascal(),
7660 *ToTypeOrErr, ToLocations.data(), ToLocations.size());
7661}
7662
7664
7665 Error Err = Error::success();
7666 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7667 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
7668 auto ToType = importChecked(Err, E->getType());
7669 auto ToInitializer = importChecked(Err, E->getInitializer());
7670 if (Err)
7671 return std::move(Err);
7672
7673 return new (Importer.getToContext()) CompoundLiteralExpr(
7674 ToLParenLoc, ToTypeSourceInfo, ToType, E->getValueKind(),
7675 ToInitializer, E->isFileScope());
7676}
7677
7679
7680 Error Err = Error::success();
7681 auto ToBuiltinLoc = importChecked(Err, E->getBuiltinLoc());
7682 auto ToType = importChecked(Err, E->getType());
7683 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7684 if (Err)
7685 return std::move(Err);
7686
7687 SmallVector<Expr *, 6> ToExprs(E->getNumSubExprs());
7688 if (Error Err = ImportArrayChecked(
7689 E->getSubExprs(), E->getSubExprs() + E->getNumSubExprs(),
7690 ToExprs.begin()))
7691 return std::move(Err);
7692
7693 return new (Importer.getToContext()) AtomicExpr(
7694
7695 ToBuiltinLoc, ToExprs, ToType, E->getOp(), ToRParenLoc);
7696}
7697
7699 Error Err = Error::success();
7700 auto ToAmpAmpLoc = importChecked(Err, E->getAmpAmpLoc());
7701 auto ToLabelLoc = importChecked(Err, E->getLabelLoc());
7702 auto ToLabel = importChecked(Err, E->getLabel());
7703 auto ToType = importChecked(Err, E->getType());
7704 if (Err)
7705 return std::move(Err);
7706
7707 return new (Importer.getToContext()) AddrLabelExpr(
7708 ToAmpAmpLoc, ToLabelLoc, ToLabel, ToType);
7709}
7711 Error Err = Error::success();
7712 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7713 auto ToResult = importChecked(Err, E->getAPValueResult());
7714 if (Err)
7715 return std::move(Err);
7716
7717 return ConstantExpr::Create(Importer.getToContext(), ToSubExpr, ToResult);
7718}
7720 Error Err = Error::success();
7721 auto ToLParen = importChecked(Err, E->getLParen());
7722 auto ToRParen = importChecked(Err, E->getRParen());
7723 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7724 if (Err)
7725 return std::move(Err);
7726
7727 return new (Importer.getToContext())
7728 ParenExpr(ToLParen, ToRParen, ToSubExpr);
7729}
7730
7732 SmallVector<Expr *, 4> ToExprs(E->getNumExprs());
7733 if (Error Err = ImportContainerChecked(E->exprs(), ToExprs))
7734 return std::move(Err);
7735
7736 ExpectedSLoc ToLParenLocOrErr = import(E->getLParenLoc());
7737 if (!ToLParenLocOrErr)
7738 return ToLParenLocOrErr.takeError();
7739
7740 ExpectedSLoc ToRParenLocOrErr = import(E->getRParenLoc());
7741 if (!ToRParenLocOrErr)
7742 return ToRParenLocOrErr.takeError();
7743
7744 return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
7745 ToExprs, *ToRParenLocOrErr);
7746}
7747
7749 Error Err = Error::success();
7750 auto ToSubStmt = importChecked(Err, E->getSubStmt());
7751 auto ToType = importChecked(Err, E->getType());
7752 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
7753 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7754 if (Err)
7755 return std::move(Err);
7756
7757 return new (Importer.getToContext())
7758 StmtExpr(ToSubStmt, ToType, ToLParenLoc, ToRParenLoc,
7759 E->getTemplateDepth());
7760}
7761
7763 Error Err = Error::success();
7764 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7765 auto ToType = importChecked(Err, E->getType());
7766 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7767 if (Err)
7768 return std::move(Err);
7769
7770 auto *UO = UnaryOperator::CreateEmpty(Importer.getToContext(),
7771 E->hasStoredFPFeatures());
7772 UO->setType(ToType);
7773 UO->setSubExpr(ToSubExpr);
7774 UO->setOpcode(E->getOpcode());
7775 UO->setOperatorLoc(ToOperatorLoc);
7776 UO->setCanOverflow(E->canOverflow());
7777 if (E->hasStoredFPFeatures())
7778 UO->setStoredFPFeatures(E->getStoredFPFeatures());
7779
7780 return UO;
7781}
7782
7784
7786 Error Err = Error::success();
7787 auto ToType = importChecked(Err, E->getType());
7788 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7789 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
7790 if (Err)
7791 return std::move(Err);
7792
7793 if (E->isArgumentType()) {
7794 Expected<TypeSourceInfo *> ToArgumentTypeInfoOrErr =
7795 import(E->getArgumentTypeInfo());
7796 if (!ToArgumentTypeInfoOrErr)
7797 return ToArgumentTypeInfoOrErr.takeError();
7798
7799 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7800 E->getKind(), *ToArgumentTypeInfoOrErr, ToType, ToOperatorLoc,
7801 ToRParenLoc);
7802 }
7803
7804 ExpectedExpr ToArgumentExprOrErr = import(E->getArgumentExpr());
7805 if (!ToArgumentExprOrErr)
7806 return ToArgumentExprOrErr.takeError();
7807
7808 return new (Importer.getToContext()) UnaryExprOrTypeTraitExpr(
7809 E->getKind(), *ToArgumentExprOrErr, ToType, ToOperatorLoc, ToRParenLoc);
7810}
7811
7813 Error Err = Error::success();
7814 auto ToLHS = importChecked(Err, E->getLHS());
7815 auto ToRHS = importChecked(Err, E->getRHS());
7816 auto ToType = importChecked(Err, E->getType());
7817 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7818 if (Err)
7819 return std::move(Err);
7820
7822 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7823 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7824 E->getFPFeatures());
7825}
7826
7828 Error Err = Error::success();
7829 auto ToCond = importChecked(Err, E->getCond());
7830 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7831 auto ToLHS = importChecked(Err, E->getLHS());
7832 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7833 auto ToRHS = importChecked(Err, E->getRHS());
7834 auto ToType = importChecked(Err, E->getType());
7835 if (Err)
7836 return std::move(Err);
7837
7838 return new (Importer.getToContext()) ConditionalOperator(
7839 ToCond, ToQuestionLoc, ToLHS, ToColonLoc, ToRHS, ToType,
7840 E->getValueKind(), E->getObjectKind());
7841}
7842
7845 Error Err = Error::success();
7846 auto ToCommon = importChecked(Err, E->getCommon());
7847 auto ToOpaqueValue = importChecked(Err, E->getOpaqueValue());
7848 auto ToCond = importChecked(Err, E->getCond());
7849 auto ToTrueExpr = importChecked(Err, E->getTrueExpr());
7850 auto ToFalseExpr = importChecked(Err, E->getFalseExpr());
7851 auto ToQuestionLoc = importChecked(Err, E->getQuestionLoc());
7852 auto ToColonLoc = importChecked(Err, E->getColonLoc());
7853 auto ToType = importChecked(Err, E->getType());
7854 if (Err)
7855 return std::move(Err);
7856
7857 return new (Importer.getToContext()) BinaryConditionalOperator(
7858 ToCommon, ToOpaqueValue, ToCond, ToTrueExpr, ToFalseExpr,
7859 ToQuestionLoc, ToColonLoc, ToType, E->getValueKind(),
7860 E->getObjectKind());
7861}
7862
7865 Error Err = Error::success();
7866 auto ToSemanticForm = importChecked(Err, E->getSemanticForm());
7867 if (Err)
7868 return std::move(Err);
7869
7870 return new (Importer.getToContext())
7871 CXXRewrittenBinaryOperator(ToSemanticForm, E->isReversed());
7872}
7873
7875 Error Err = Error::success();
7876 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7877 auto ToQueriedTypeSourceInfo =
7878 importChecked(Err, E->getQueriedTypeSourceInfo());
7879 auto ToDimensionExpression = importChecked(Err, E->getDimensionExpression());
7880 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7881 auto ToType = importChecked(Err, E->getType());
7882 if (Err)
7883 return std::move(Err);
7884
7885 return new (Importer.getToContext()) ArrayTypeTraitExpr(
7886 ToBeginLoc, E->getTrait(), ToQueriedTypeSourceInfo, E->getValue(),
7887 ToDimensionExpression, ToEndLoc, ToType);
7888}
7889
7891 Error Err = Error::success();
7892 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
7893 auto ToQueriedExpression = importChecked(Err, E->getQueriedExpression());
7894 auto ToEndLoc = importChecked(Err, E->getEndLoc());
7895 auto ToType = importChecked(Err, E->getType());
7896 if (Err)
7897 return std::move(Err);
7898
7899 return new (Importer.getToContext()) ExpressionTraitExpr(
7900 ToBeginLoc, E->getTrait(), ToQueriedExpression, E->getValue(),
7901 ToEndLoc, ToType);
7902}
7903
7905 Error Err = Error::success();
7906 auto ToLocation = importChecked(Err, E->getLocation());
7907 auto ToType = importChecked(Err, E->getType());
7908 auto ToSourceExpr = importChecked(Err, E->getSourceExpr());
7909 if (Err)
7910 return std::move(Err);
7911
7912 return new (Importer.getToContext()) OpaqueValueExpr(
7913 ToLocation, ToType, E->getValueKind(), E->getObjectKind(), ToSourceExpr);
7914}
7915
7917 Error Err = Error::success();
7918 auto ToLHS = importChecked(Err, E->getLHS());
7919 auto ToRHS = importChecked(Err, E->getRHS());
7920 auto ToType = importChecked(Err, E->getType());
7921 auto ToRBracketLoc = importChecked(Err, E->getRBracketLoc());
7922 if (Err)
7923 return std::move(Err);
7924
7925 return new (Importer.getToContext()) ArraySubscriptExpr(
7926 ToLHS, ToRHS, ToType, E->getValueKind(), E->getObjectKind(),
7927 ToRBracketLoc);
7928}
7929
7932 Error Err = Error::success();
7933 auto ToLHS = importChecked(Err, E->getLHS());
7934 auto ToRHS = importChecked(Err, E->getRHS());
7935 auto ToType = importChecked(Err, E->getType());
7936 auto ToComputationLHSType = importChecked(Err, E->getComputationLHSType());
7937 auto ToComputationResultType =
7938 importChecked(Err, E->getComputationResultType());
7939 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
7940 if (Err)
7941 return std::move(Err);
7942
7944 Importer.getToContext(), ToLHS, ToRHS, E->getOpcode(), ToType,
7945 E->getValueKind(), E->getObjectKind(), ToOperatorLoc,
7946 E->getFPFeatures(),
7947 ToComputationLHSType, ToComputationResultType);
7948}
7949
7953 for (auto I = CE->path_begin(), E = CE->path_end(); I != E; ++I) {
7954 if (auto SpecOrErr = import(*I))
7955 Path.push_back(*SpecOrErr);
7956 else
7957 return SpecOrErr.takeError();
7958 }
7959 return Path;
7960}
7961
7963 ExpectedType ToTypeOrErr = import(E->getType());
7964 if (!ToTypeOrErr)
7965 return ToTypeOrErr.takeError();
7966
7967 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
7968 if (!ToSubExprOrErr)
7969 return ToSubExprOrErr.takeError();
7970
7971 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7972 if (!ToBasePathOrErr)
7973 return ToBasePathOrErr.takeError();
7974
7976 Importer.getToContext(), *ToTypeOrErr, E->getCastKind(), *ToSubExprOrErr,
7977 &(*ToBasePathOrErr), E->getValueKind(), E->getFPFeatures());
7978}
7979
7981 Error Err = Error::success();
7982 auto ToType = importChecked(Err, E->getType());
7983 auto ToSubExpr = importChecked(Err, E->getSubExpr());
7984 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
7985 if (Err)
7986 return std::move(Err);
7987
7988 Expected<CXXCastPath> ToBasePathOrErr = ImportCastPath(E);
7989 if (!ToBasePathOrErr)
7990 return ToBasePathOrErr.takeError();
7991 CXXCastPath *ToBasePath = &(*ToBasePathOrErr);
7992
7993 switch (E->getStmtClass()) {
7994 case Stmt::CStyleCastExprClass: {
7995 auto *CCE = cast<CStyleCastExpr>(E);
7996 ExpectedSLoc ToLParenLocOrErr = import(CCE->getLParenLoc());
7997 if (!ToLParenLocOrErr)
7998 return ToLParenLocOrErr.takeError();
7999 ExpectedSLoc ToRParenLocOrErr = import(CCE->getRParenLoc());
8000 if (!ToRParenLocOrErr)
8001 return ToRParenLocOrErr.takeError();
8003 Importer.getToContext(), ToType, E->getValueKind(), E->getCastKind(),
8004 ToSubExpr, ToBasePath, CCE->getFPFeatures(), ToTypeInfoAsWritten,
8005 *ToLParenLocOrErr, *ToRParenLocOrErr);
8006 }
8007
8008 case Stmt::CXXFunctionalCastExprClass: {
8009 auto *FCE = cast<CXXFunctionalCastExpr>(E);
8010 ExpectedSLoc ToLParenLocOrErr = import(FCE->getLParenLoc());
8011 if (!ToLParenLocOrErr)
8012 return ToLParenLocOrErr.takeError();
8013 ExpectedSLoc ToRParenLocOrErr = import(FCE->getRParenLoc());
8014 if (!ToRParenLocOrErr)
8015 return ToRParenLocOrErr.takeError();
8017 Importer.getToContext(), ToType, E->getValueKind(), ToTypeInfoAsWritten,
8018 E->getCastKind(), ToSubExpr, ToBasePath, FCE->getFPFeatures(),
8019 *ToLParenLocOrErr, *ToRParenLocOrErr);
8020 }
8021
8022 case Stmt::ObjCBridgedCastExprClass: {
8023 auto *OCE = cast<ObjCBridgedCastExpr>(E);
8024 ExpectedSLoc ToLParenLocOrErr = import(OCE->getLParenLoc());
8025 if (!ToLParenLocOrErr)
8026 return ToLParenLocOrErr.takeError();
8027 ExpectedSLoc ToBridgeKeywordLocOrErr = import(OCE->getBridgeKeywordLoc());
8028 if (!ToBridgeKeywordLocOrErr)
8029 return ToBridgeKeywordLocOrErr.takeError();
8030 return new (Importer.getToContext()) ObjCBridgedCastExpr(
8031 *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
8032 *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
8033 }
8034 case Stmt::BuiltinBitCastExprClass: {
8035 auto *BBC = cast<BuiltinBitCastExpr>(E);
8036 ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc());
8037 if (!ToKWLocOrErr)
8038 return ToKWLocOrErr.takeError();
8039 ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc());
8040 if (!ToRParenLocOrErr)
8041 return ToRParenLocOrErr.takeError();
8042 return new (Importer.getToContext()) BuiltinBitCastExpr(
8043 ToType, E->getValueKind(), E->getCastKind(), ToSubExpr,
8044 ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr);
8045 }
8046 default:
8047 llvm_unreachable("Cast expression of unsupported type!");
8048 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
8049 }
8050}
8051
8054 for (int I = 0, N = E->getNumComponents(); I < N; ++I) {
8055 const OffsetOfNode &FromNode = E->getComponent(I);
8056
8057 SourceLocation ToBeginLoc, ToEndLoc;
8058
8059 if (FromNode.getKind() != OffsetOfNode::Base) {
8060 Error Err = Error::success();
8061 ToBeginLoc = importChecked(Err, FromNode.getBeginLoc());
8062 ToEndLoc = importChecked(Err, FromNode.getEndLoc());
8063 if (Err)
8064 return std::move(Err);
8065 }
8066
8067 switch (FromNode.getKind()) {
8069 ToNodes.push_back(
8070 OffsetOfNode(ToBeginLoc, FromNode.getArrayExprIndex(), ToEndLoc));
8071 break;
8072 case OffsetOfNode::Base: {
8073 auto ToBSOrErr = import(FromNode.getBase());
8074 if (!ToBSOrErr)
8075 return ToBSOrErr.takeError();
8076 ToNodes.push_back(OffsetOfNode(*ToBSOrErr));
8077 break;
8078 }
8079 case OffsetOfNode::Field: {
8080 auto ToFieldOrErr = import(FromNode.getField());
8081 if (!ToFieldOrErr)
8082 return ToFieldOrErr.takeError();
8083 ToNodes.push_back(OffsetOfNode(ToBeginLoc, *ToFieldOrErr, ToEndLoc));
8084 break;
8085 }
8087 IdentifierInfo *ToII = Importer.Import(FromNode.getFieldName());
8088 ToNodes.push_back(OffsetOfNode(ToBeginLoc, ToII, ToEndLoc));
8089 break;
8090 }
8091 }
8092 }
8093
8094 SmallVector<Expr *, 4> ToExprs(E->getNumExpressions());
8095 for (int I = 0, N = E->getNumExpressions(); I < N; ++I) {
8096 ExpectedExpr ToIndexExprOrErr = import(E->getIndexExpr(I));
8097 if (!ToIndexExprOrErr)
8098 return ToIndexExprOrErr.takeError();
8099 ToExprs[I] = *ToIndexExprOrErr;
8100 }
8101
8102 Error Err = Error::success();
8103 auto ToType = importChecked(Err, E->getType());
8104 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8105 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8106 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8107 if (Err)
8108 return std::move(Err);
8109
8110 return OffsetOfExpr::Create(
8111 Importer.getToContext(), ToType, ToOperatorLoc, ToTypeSourceInfo, ToNodes,
8112 ToExprs, ToRParenLoc);
8113}
8114
8116 Error Err = Error::success();
8117 auto ToType = importChecked(Err, E->getType());
8118 auto ToOperand = importChecked(Err, E->getOperand());
8119 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8120 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8121 if (Err)
8122 return std::move(Err);
8123
8124 CanThrowResult ToCanThrow;
8125 if (E->isValueDependent())
8126 ToCanThrow = CT_Dependent;
8127 else
8128 ToCanThrow = E->getValue() ? CT_Can : CT_Cannot;
8129
8130 return new (Importer.getToContext()) CXXNoexceptExpr(
8131 ToType, ToOperand, ToCanThrow, ToBeginLoc, ToEndLoc);
8132}
8133
8135 Error Err = Error::success();
8136 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8137 auto ToType = importChecked(Err, E->getType());
8138 auto ToThrowLoc = importChecked(Err, E->getThrowLoc());
8139 if (Err)
8140 return std::move(Err);
8141
8142 return new (Importer.getToContext()) CXXThrowExpr(
8143 ToSubExpr, ToType, ToThrowLoc, E->isThrownVariableInScope());
8144}
8145
8147 ExpectedSLoc ToUsedLocOrErr = import(E->getUsedLocation());
8148 if (!ToUsedLocOrErr)
8149 return ToUsedLocOrErr.takeError();
8150
8151 auto ToParamOrErr = import(E->getParam());
8152 if (!ToParamOrErr)
8153 return ToParamOrErr.takeError();
8154
8155 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8156 if (!UsedContextOrErr)
8157 return UsedContextOrErr.takeError();
8158
8159 // Import the default arg if it was not imported yet.
8160 // This is needed because it can happen that during the import of the
8161 // default expression (from VisitParmVarDecl) the same ParmVarDecl is
8162 // encountered here. The default argument for a ParmVarDecl is set in the
8163 // ParmVarDecl only after it is imported (set in VisitParmVarDecl if not here,
8164 // see VisitParmVarDecl).
8165 ParmVarDecl *ToParam = *ToParamOrErr;
8166 if (!ToParam->getDefaultArg()) {
8167 std::optional<ParmVarDecl *> FromParam =
8168 Importer.getImportedFromDecl(ToParam);
8169 assert(FromParam && "ParmVarDecl was not imported?");
8170
8171 if (Error Err = ImportDefaultArgOfParmVarDecl(*FromParam, ToParam))
8172 return std::move(Err);
8173 }
8174 Expr *RewrittenInit = nullptr;
8175 if (E->hasRewrittenInit()) {
8176 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8177 if (!ExprOrErr)
8178 return ExprOrErr.takeError();
8179 RewrittenInit = ExprOrErr.get();
8180 }
8181 return CXXDefaultArgExpr::Create(Importer.getToContext(), *ToUsedLocOrErr,
8182 *ToParamOrErr, RewrittenInit,
8183 *UsedContextOrErr);
8184}
8185
8188 Error Err = Error::success();
8189 auto ToType = importChecked(Err, E->getType());
8190 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8191 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8192 if (Err)
8193 return std::move(Err);
8194
8195 return new (Importer.getToContext()) CXXScalarValueInitExpr(
8196 ToType, ToTypeSourceInfo, ToRParenLoc);
8197}
8198
8201 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8202 if (!ToSubExprOrErr)
8203 return ToSubExprOrErr.takeError();
8204
8205 auto ToDtorOrErr = import(E->getTemporary()->getDestructor());
8206 if (!ToDtorOrErr)
8207 return ToDtorOrErr.takeError();
8208
8209 ASTContext &ToCtx = Importer.getToContext();
8210 CXXTemporary *Temp = CXXTemporary::Create(ToCtx, *ToDtorOrErr);
8211 return CXXBindTemporaryExpr::Create(ToCtx, Temp, *ToSubExprOrErr);
8212}
8213
8215
8217 Error Err = Error::success();
8218 auto ToConstructor = importChecked(Err, E->getConstructor());
8219 auto ToType = importChecked(Err, E->getType());
8220 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8221 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8222 if (Err)
8223 return std::move(Err);
8224
8225 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8226 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8227 return std::move(Err);
8228
8230 Importer.getToContext(), ToConstructor, ToType, ToTypeSourceInfo, ToArgs,
8231 ToParenOrBraceRange, E->hadMultipleCandidates(),
8232 E->isListInitialization(), E->isStdInitListInitialization(),
8233 E->requiresZeroInitialization());
8234}
8235
8238 DeclContext *DC, *LexicalDC;
8239 if (Error Err = ImportDeclContext(D, DC, LexicalDC))
8240 return std::move(Err);
8241
8242 Error Err = Error::success();
8243 auto Temporary = importChecked(Err, D->getTemporaryExpr());
8244 auto ExtendingDecl = importChecked(Err, D->getExtendingDecl());
8245 if (Err)
8246 return std::move(Err);
8247 // FIXME: Should ManglingNumber get numbers associated with 'to' context?
8248
8250 if (GetImportedOrCreateDecl(To, D, Temporary, ExtendingDecl,
8251 D->getManglingNumber()))
8252 return To;
8253
8254 To->setLexicalDeclContext(LexicalDC);
8255 LexicalDC->addDeclInternal(To);
8256 return To;
8257}
8258
8261 Error Err = Error::success();
8262 auto ToType = importChecked(Err, E->getType());
8263 Expr *ToTemporaryExpr = importChecked(
8264 Err, E->getLifetimeExtendedTemporaryDecl() ? nullptr : E->getSubExpr());
8265 auto ToMaterializedDecl =
8266 importChecked(Err, E->getLifetimeExtendedTemporaryDecl());
8267 if (Err)
8268 return std::move(Err);
8269
8270 if (!ToTemporaryExpr)
8271 ToTemporaryExpr = cast<Expr>(ToMaterializedDecl->getTemporaryExpr());
8272
8273 auto *ToMTE = new (Importer.getToContext()) MaterializeTemporaryExpr(
8274 ToType, ToTemporaryExpr, E->isBoundToLvalueReference(),
8275 ToMaterializedDecl);
8276
8277 return ToMTE;
8278}
8279
8281 Error Err = Error::success();
8282 auto ToType = importChecked(Err, E->getType());
8283 auto ToPattern = importChecked(Err, E->getPattern());
8284 auto ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
8285 if (Err)
8286 return std::move(Err);
8287
8288 return new (Importer.getToContext()) PackExpansionExpr(
8289 ToType, ToPattern, ToEllipsisLoc, E->getNumExpansions());
8290}
8291
8293 Error Err = Error::success();
8294 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8295 auto ToPack = importChecked(Err, E->getPack());
8296 auto ToPackLoc = importChecked(Err, E->getPackLoc());
8297 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8298 if (Err)
8299 return std::move(Err);
8300
8301 std::optional<unsigned> Length;
8302 if (!E->isValueDependent())
8303 Length = E->getPackLength();
8304
8305 SmallVector<TemplateArgument, 8> ToPartialArguments;
8306 if (E->isPartiallySubstituted()) {
8307 if (Error Err = ImportTemplateArguments(E->getPartialArguments(),
8308 ToPartialArguments))
8309 return std::move(Err);
8310 }
8311
8313 Importer.getToContext(), ToOperatorLoc, ToPack, ToPackLoc, ToRParenLoc,
8314 Length, ToPartialArguments);
8315}
8316
8317
8319 Error Err = Error::success();
8320 auto ToOperatorNew = importChecked(Err, E->getOperatorNew());
8321 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8322 auto ToTypeIdParens = importChecked(Err, E->getTypeIdParens());
8323 auto ToArraySize = importChecked(Err, E->getArraySize());
8324 auto ToInitializer = importChecked(Err, E->getInitializer());
8325 auto ToType = importChecked(Err, E->getType());
8326 auto ToAllocatedTypeSourceInfo =
8327 importChecked(Err, E->getAllocatedTypeSourceInfo());
8328 auto ToSourceRange = importChecked(Err, E->getSourceRange());
8329 auto ToDirectInitRange = importChecked(Err, E->getDirectInitRange());
8330 if (Err)
8331 return std::move(Err);
8332
8333 SmallVector<Expr *, 4> ToPlacementArgs(E->getNumPlacementArgs());
8334 if (Error Err =
8335 ImportContainerChecked(E->placement_arguments(), ToPlacementArgs))
8336 return std::move(Err);
8337
8338 return CXXNewExpr::Create(
8339 Importer.getToContext(), E->isGlobalNew(), ToOperatorNew,
8340 ToOperatorDelete, E->passAlignment(), E->doesUsualArrayDeleteWantSize(),
8341 ToPlacementArgs, ToTypeIdParens, ToArraySize, E->getInitializationStyle(),
8342 ToInitializer, ToType, ToAllocatedTypeSourceInfo, ToSourceRange,
8343 ToDirectInitRange);
8344}
8345
8347 Error Err = Error::success();
8348 auto ToType = importChecked(Err, E->getType());
8349 auto ToOperatorDelete = importChecked(Err, E->getOperatorDelete());
8350 auto ToArgument = importChecked(Err, E->getArgument());
8351 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8352 if (Err)
8353 return std::move(Err);
8354
8355 return new (Importer.getToContext()) CXXDeleteExpr(
8356 ToType, E->isGlobalDelete(), E->isArrayForm(), E->isArrayFormAsWritten(),
8357 E->doesUsualArrayDeleteWantSize(), ToOperatorDelete, ToArgument,
8358 ToBeginLoc);
8359}
8360
8362 Error Err = Error::success();
8363 auto ToType = importChecked(Err, E->getType());
8364 auto ToLocation = importChecked(Err, E->getLocation());
8365 auto ToConstructor = importChecked(Err, E->getConstructor());
8366 auto ToParenOrBraceRange = importChecked(Err, E->getParenOrBraceRange());
8367 if (Err)
8368 return std::move(Err);
8369
8370 SmallVector<Expr *, 6> ToArgs(E->getNumArgs());
8371 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8372 return std::move(Err);
8373
8375 Importer.getToContext(), ToType, ToLocation, ToConstructor,
8376 E->isElidable(), ToArgs, E->hadMultipleCandidates(),
8377 E->isListInitialization(), E->isStdInitListInitialization(),
8378 E->requiresZeroInitialization(), E->getConstructionKind(),
8379 ToParenOrBraceRange);
8380 ToE->setIsImmediateEscalating(E->isImmediateEscalating());
8381 return ToE;
8382}
8383
8385 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8386 if (!ToSubExprOrErr)
8387 return ToSubExprOrErr.takeError();
8388
8389 SmallVector<ExprWithCleanups::CleanupObject, 8> ToObjects(E->getNumObjects());
8390 if (Error Err = ImportContainerChecked(E->getObjects(), ToObjects))
8391 return std::move(Err);
8392
8394 Importer.getToContext(), *ToSubExprOrErr, E->cleanupsHaveSideEffects(),
8395 ToObjects);
8396}
8397
8399 Error Err = Error::success();
8400 auto ToCallee = importChecked(Err, E->getCallee());
8401 auto ToType = importChecked(Err, E->getType());
8402 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8403 if (Err)
8404 return std::move(Err);
8405
8406 SmallVector<Expr *, 4> ToArgs(E->getNumArgs());
8407 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8408 return std::move(Err);
8409
8410 return CXXMemberCallExpr::Create(Importer.getToContext(), ToCallee, ToArgs,
8411 ToType, E->getValueKind(), ToRParenLoc,
8412 E->getFPFeatures());
8413}
8414
8416 ExpectedType ToTypeOrErr = import(E->getType());
8417 if (!ToTypeOrErr)
8418 return ToTypeOrErr.takeError();
8419
8420 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8421 if (!ToLocationOrErr)
8422 return ToLocationOrErr.takeError();
8423
8424 return CXXThisExpr::Create(Importer.getToContext(), *ToLocationOrErr,
8425 *ToTypeOrErr, E->isImplicit());
8426}
8427
8429 ExpectedType ToTypeOrErr = import(E->getType());
8430 if (!ToTypeOrErr)
8431 return ToTypeOrErr.takeError();
8432
8433 ExpectedSLoc ToLocationOrErr = import(E->getLocation());
8434 if (!ToLocationOrErr)
8435 return ToLocationOrErr.takeError();
8436
8437 return CXXBoolLiteralExpr::Create(Importer.getToContext(), E->getValue(),
8438 *ToTypeOrErr, *ToLocationOrErr);
8439}
8440
8442 Error Err = Error::success();
8443 auto ToBase = importChecked(Err, E->getBase());
8444 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8445 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8446 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8447 auto ToMemberDecl = importChecked(Err, E->getMemberDecl());
8448 auto ToType = importChecked(Err, E->getType());
8449 auto ToDecl = importChecked(Err, E->getFoundDecl().getDecl());
8450 auto ToName = importChecked(Err, E->getMemberNameInfo().getName());
8451 auto ToLoc = importChecked(Err, E->getMemberNameInfo().getLoc());
8452 if (Err)
8453 return std::move(Err);
8454
8455 DeclAccessPair ToFoundDecl =
8456 DeclAccessPair::make(ToDecl, E->getFoundDecl().getAccess());
8457
8458 DeclarationNameInfo ToMemberNameInfo(ToName, ToLoc);
8459
8460 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8461 if (E->hasExplicitTemplateArgs()) {
8462 if (Error Err =
8463 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8464 E->template_arguments(), ToTAInfo))
8465 return std::move(Err);
8466 ResInfo = &ToTAInfo;
8467 }
8468
8469 return MemberExpr::Create(Importer.getToContext(), ToBase, E->isArrow(),
8470 ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8471 ToMemberDecl, ToFoundDecl, ToMemberNameInfo,
8472 ResInfo, ToType, E->getValueKind(),
8473 E->getObjectKind(), E->isNonOdrUse());
8474}
8475
8478 Error Err = Error::success();
8479 auto ToBase = importChecked(Err, E->getBase());
8480 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8481 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8482 auto ToScopeTypeInfo = importChecked(Err, E->getScopeTypeInfo());
8483 auto ToColonColonLoc = importChecked(Err, E->getColonColonLoc());
8484 auto ToTildeLoc = importChecked(Err, E->getTildeLoc());
8485 if (Err)
8486 return std::move(Err);
8487
8489 if (const IdentifierInfo *FromII = E->getDestroyedTypeIdentifier()) {
8490 const IdentifierInfo *ToII = Importer.Import(FromII);
8491 ExpectedSLoc ToDestroyedTypeLocOrErr = import(E->getDestroyedTypeLoc());
8492 if (!ToDestroyedTypeLocOrErr)
8493 return ToDestroyedTypeLocOrErr.takeError();
8494 Storage = PseudoDestructorTypeStorage(ToII, *ToDestroyedTypeLocOrErr);
8495 } else {
8496 if (auto ToTIOrErr = import(E->getDestroyedTypeInfo()))
8497 Storage = PseudoDestructorTypeStorage(*ToTIOrErr);
8498 else
8499 return ToTIOrErr.takeError();
8500 }
8501
8502 return new (Importer.getToContext()) CXXPseudoDestructorExpr(
8503 Importer.getToContext(), ToBase, E->isArrow(), ToOperatorLoc,
8504 ToQualifierLoc, ToScopeTypeInfo, ToColonColonLoc, ToTildeLoc, Storage);
8505}
8506
8509 Error Err = Error::success();
8510 auto ToType = importChecked(Err, E->getType());
8511 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8512 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8513 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8514 auto ToFirstQualifierFoundInScope =
8515 importChecked(Err, E->getFirstQualifierFoundInScope());
8516 if (Err)
8517 return std::move(Err);
8518
8519 Expr *ToBase = nullptr;
8520 if (!E->isImplicitAccess()) {
8521 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8522 ToBase = *ToBaseOrErr;
8523 else
8524 return ToBaseOrErr.takeError();
8525 }
8526
8527 TemplateArgumentListInfo ToTAInfo, *ResInfo = nullptr;
8528
8529 if (E->hasExplicitTemplateArgs()) {
8530 if (Error Err =
8531 ImportTemplateArgumentListInfo(E->getLAngleLoc(), E->getRAngleLoc(),
8532 E->template_arguments(), ToTAInfo))
8533 return std::move(Err);
8534 ResInfo = &ToTAInfo;
8535 }
8536 auto ToMember = importChecked(Err, E->getMember());
8537 auto ToMemberLoc = importChecked(Err, E->getMemberLoc());
8538 if (Err)
8539 return std::move(Err);
8540 DeclarationNameInfo ToMemberNameInfo(ToMember, ToMemberLoc);
8541
8542 // Import additional name location/type info.
8543 if (Error Err =
8544 ImportDeclarationNameLoc(E->getMemberNameInfo(), ToMemberNameInfo))
8545 return std::move(Err);
8546
8548 Importer.getToContext(), ToBase, ToType, E->isArrow(), ToOperatorLoc,
8549 ToQualifierLoc, ToTemplateKeywordLoc, ToFirstQualifierFoundInScope,
8550 ToMemberNameInfo, ResInfo);
8551}
8552
8555 Error Err = Error::success();
8556 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8557 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8558 auto ToDeclName = importChecked(Err, E->getDeclName());
8559 auto ToNameLoc = importChecked(Err, E->getNameInfo().getLoc());
8560 auto ToLAngleLoc = importChecked(Err, E->getLAngleLoc());
8561 auto ToRAngleLoc = importChecked(Err, E->getRAngleLoc());
8562 if (Err)
8563 return std::move(Err);
8564
8565 DeclarationNameInfo ToNameInfo(ToDeclName, ToNameLoc);
8566 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8567 return std::move(Err);
8568
8569 TemplateArgumentListInfo ToTAInfo(ToLAngleLoc, ToRAngleLoc);
8570 TemplateArgumentListInfo *ResInfo = nullptr;
8571 if (E->hasExplicitTemplateArgs()) {
8572 if (Error Err =
8573 ImportTemplateArgumentListInfo(E->template_arguments(), ToTAInfo))
8574 return std::move(Err);
8575 ResInfo = &ToTAInfo;
8576 }
8577
8579 Importer.getToContext(), ToQualifierLoc, ToTemplateKeywordLoc,
8580 ToNameInfo, ResInfo);
8581}
8582
8585 Error Err = Error::success();
8586 auto ToLParenLoc = importChecked(Err, E->getLParenLoc());
8587 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8588 auto ToType = importChecked(Err, E->getType());
8589 auto ToTypeSourceInfo = importChecked(Err, E->getTypeSourceInfo());
8590 if (Err)
8591 return std::move(Err);
8592
8593 SmallVector<Expr *, 8> ToArgs(E->getNumArgs());
8594 if (Error Err =
8595 ImportArrayChecked(E->arg_begin(), E->arg_end(), ToArgs.begin()))
8596 return std::move(Err);
8597
8599 Importer.getToContext(), ToType, ToTypeSourceInfo, ToLParenLoc,
8600 llvm::ArrayRef(ToArgs), ToRParenLoc, E->isListInitialization());
8601}
8602
8605 Expected<CXXRecordDecl *> ToNamingClassOrErr = import(E->getNamingClass());
8606 if (!ToNamingClassOrErr)
8607 return ToNamingClassOrErr.takeError();
8608
8609 auto ToQualifierLocOrErr = import(E->getQualifierLoc());
8610 if (!ToQualifierLocOrErr)
8611 return ToQualifierLocOrErr.takeError();
8612
8613 Error Err = Error::success();
8614 auto ToName = importChecked(Err, E->getName());
8615 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8616 if (Err)
8617 return std::move(Err);
8618 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8619
8620 // Import additional name location/type info.
8621 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8622 return std::move(Err);
8623
8624 UnresolvedSet<8> ToDecls;
8625 for (auto *D : E->decls())
8626 if (auto ToDOrErr = import(D))
8627 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8628 else
8629 return ToDOrErr.takeError();
8630
8631 if (E->hasExplicitTemplateArgs()) {
8632 TemplateArgumentListInfo ToTAInfo;
8633 if (Error Err = ImportTemplateArgumentListInfo(
8634 E->getLAngleLoc(), E->getRAngleLoc(), E->template_arguments(),
8635 ToTAInfo))
8636 return std::move(Err);
8637
8638 ExpectedSLoc ToTemplateKeywordLocOrErr = import(E->getTemplateKeywordLoc());
8639 if (!ToTemplateKeywordLocOrErr)
8640 return ToTemplateKeywordLocOrErr.takeError();
8641
8642 const bool KnownDependent =
8643 (E->getDependence() & ExprDependence::TypeValue) ==
8644 ExprDependence::TypeValue;
8646 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8647 *ToTemplateKeywordLocOrErr, ToNameInfo, E->requiresADL(), &ToTAInfo,
8648 ToDecls.begin(), ToDecls.end(), KnownDependent,
8649 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8650 }
8651
8653 Importer.getToContext(), *ToNamingClassOrErr, *ToQualifierLocOrErr,
8654 ToNameInfo, E->requiresADL(), ToDecls.begin(), ToDecls.end(),
8655 /*KnownDependent=*/E->isTypeDependent(),
8656 /*KnownInstantiationDependent=*/E->isInstantiationDependent());
8657}
8658
8661 Error Err = Error::success();
8662 auto ToType = importChecked(Err, E->getType());
8663 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8664 auto ToQualifierLoc = importChecked(Err, E->getQualifierLoc());
8665 auto ToTemplateKeywordLoc = importChecked(Err, E->getTemplateKeywordLoc());
8666 auto ToName = importChecked(Err, E->getName());
8667 auto ToNameLoc = importChecked(Err, E->getNameLoc());
8668 if (Err)
8669 return std::move(Err);
8670
8671 DeclarationNameInfo ToNameInfo(ToName, ToNameLoc);
8672 // Import additional name location/type info.
8673 if (Error Err = ImportDeclarationNameLoc(E->getNameInfo(), ToNameInfo))
8674 return std::move(Err);
8675
8676 UnresolvedSet<8> ToDecls;
8677 for (Decl *D : E->decls())
8678 if (auto ToDOrErr = import(D))
8679 ToDecls.addDecl(cast<NamedDecl>(*ToDOrErr));
8680 else
8681 return ToDOrErr.takeError();
8682
8683 TemplateArgumentListInfo ToTAInfo;
8684 TemplateArgumentListInfo *ResInfo = nullptr;
8685 if (E->hasExplicitTemplateArgs()) {
8686 TemplateArgumentListInfo FromTAInfo;
8687 E->copyTemplateArgumentsInto(FromTAInfo);
8688 if (Error Err = ImportTemplateArgumentListInfo(FromTAInfo, ToTAInfo))
8689 return std::move(Err);
8690 ResInfo = &ToTAInfo;
8691 }
8692
8693 Expr *ToBase = nullptr;
8694 if (!E->isImplicitAccess()) {
8695 if (ExpectedExpr ToBaseOrErr = import(E->getBase()))
8696 ToBase = *ToBaseOrErr;
8697 else
8698 return ToBaseOrErr.takeError();
8699 }
8700
8702 Importer.getToContext(), E->hasUnresolvedUsing(), ToBase, ToType,
8703 E->isArrow(), ToOperatorLoc, ToQualifierLoc, ToTemplateKeywordLoc,
8704 ToNameInfo, ResInfo, ToDecls.begin(), ToDecls.end());
8705}
8706
8708 Error Err = Error::success();
8709 auto ToCallee = importChecked(Err, E->getCallee());
8710 auto ToType = importChecked(Err, E->getType());
8711 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8712 if (Err)
8713 return std::move(Err);
8714
8715 unsigned NumArgs = E->getNumArgs();
8716 llvm::SmallVector<Expr *, 2> ToArgs(NumArgs);
8717 if (Error Err = ImportContainerChecked(E->arguments(), ToArgs))
8718 return std::move(Err);
8719
8720 if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(E)) {
8722 Importer.getToContext(), OCE->getOperator(), ToCallee, ToArgs, ToType,
8723 OCE->getValueKind(), ToRParenLoc, OCE->getFPFeatures(),
8724 OCE->getADLCallKind());
8725 }
8726
8727 return CallExpr::Create(Importer.getToContext(), ToCallee, ToArgs, ToType,
8728 E->getValueKind(), ToRParenLoc, E->getFPFeatures(),
8729 /*MinNumArgs=*/0, E->getADLCallKind());
8730}
8731
8733 CXXRecordDecl *FromClass = E->getLambdaClass();
8734 auto ToClassOrErr = import(FromClass);
8735 if (!ToClassOrErr)
8736 return ToClassOrErr.takeError();
8737 CXXRecordDecl *ToClass = *ToClassOrErr;
8738
8739 auto ToCallOpOrErr = import(E->getCallOperator());
8740 if (!ToCallOpOrErr)
8741 return ToCallOpOrErr.takeError();
8742
8743 SmallVector<Expr *, 8> ToCaptureInits(E->capture_size());
8744 if (Error Err = ImportContainerChecked(E->capture_inits(), ToCaptureInits))
8745 return std::move(Err);
8746
8747 Error Err = Error::success();
8748 auto ToIntroducerRange = importChecked(Err, E->getIntroducerRange());
8749 auto ToCaptureDefaultLoc = importChecked(Err, E->getCaptureDefaultLoc());
8750 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8751 if (Err)
8752 return std::move(Err);
8753
8754 return LambdaExpr::Create(Importer.getToContext(), ToClass, ToIntroducerRange,
8755 E->getCaptureDefault(), ToCaptureDefaultLoc,
8756 E->hasExplicitParameters(),
8757 E->hasExplicitResultType(), ToCaptureInits,
8758 ToEndLoc, E->containsUnexpandedParameterPack());
8759}
8760
8761
8763 Error Err = Error::success();
8764 auto ToLBraceLoc = importChecked(Err, E->getLBraceLoc());
8765 auto ToRBraceLoc = importChecked(Err, E->getRBraceLoc());
8766 auto ToType = importChecked(Err, E->getType());
8767 if (Err)
8768 return std::move(Err);
8769
8770 SmallVector<Expr *, 4> ToExprs(E->getNumInits());
8771 if (Error Err = ImportContainerChecked(E->inits(), ToExprs))
8772 return std::move(Err);
8773
8774 ASTContext &ToCtx = Importer.getToContext();
8775 InitListExpr *To = new (ToCtx) InitListExpr(
8776 ToCtx, ToLBraceLoc, ToExprs, ToRBraceLoc);
8777 To->setType(ToType);
8778
8779 if (E->hasArrayFiller()) {
8780 if (ExpectedExpr ToFillerOrErr = import(E->getArrayFiller()))
8781 To->setArrayFiller(*ToFillerOrErr);
8782 else
8783 return ToFillerOrErr.takeError();
8784 }
8785
8786 if (FieldDecl *FromFD = E->getInitializedFieldInUnion()) {
8787 if (auto ToFDOrErr = import(FromFD))
8788 To->setInitializedFieldInUnion(*ToFDOrErr);
8789 else
8790 return ToFDOrErr.takeError();
8791 }
8792
8793 if (InitListExpr *SyntForm = E->getSyntacticForm()) {
8794 if (auto ToSyntFormOrErr = import(SyntForm))
8795 To->setSyntacticForm(*ToSyntFormOrErr);
8796 else
8797 return ToSyntFormOrErr.takeError();
8798 }
8799
8800 // Copy InitListExprBitfields, which are not handled in the ctor of
8801 // InitListExpr.
8802 To->sawArrayRangeDesignator(E->hadArrayRangeDesignator());
8803
8804 return To;
8805}
8806
8809 ExpectedType ToTypeOrErr = import(E->getType());
8810 if (!ToTypeOrErr)
8811 return ToTypeOrErr.takeError();
8812
8813 ExpectedExpr ToSubExprOrErr = import(E->getSubExpr());
8814 if (!ToSubExprOrErr)
8815 return ToSubExprOrErr.takeError();
8816
8817 return new (Importer.getToContext()) CXXStdInitializerListExpr(
8818 *ToTypeOrErr, *ToSubExprOrErr);
8819}
8820
8823 Error Err = Error::success();
8824 auto ToLocation = importChecked(Err, E->getLocation());
8825 auto ToType = importChecked(Err, E->getType());
8826 auto ToConstructor = importChecked(Err, E->getConstructor());
8827 if (Err)
8828 return std::move(Err);
8829
8830 return new (Importer.getToContext()) CXXInheritedCtorInitExpr(
8831 ToLocation, ToType, ToConstructor, E->constructsVBase(),
8832 E->inheritedFromVBase());
8833}
8834
8836 Error Err = Error::success();
8837 auto ToType = importChecked(Err, E->getType());
8838 auto ToCommonExpr = importChecked(Err, E->getCommonExpr());
8839 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8840 if (Err)
8841 return std::move(Err);
8842
8843 return new (Importer.getToContext()) ArrayInitLoopExpr(
8844 ToType, ToCommonExpr, ToSubExpr);
8845}
8846
8848 ExpectedType ToTypeOrErr = import(E->getType());
8849 if (!ToTypeOrErr)
8850 return ToTypeOrErr.takeError();
8851 return new (Importer.getToContext()) ArrayInitIndexExpr(*ToTypeOrErr);
8852}
8853
8855 ExpectedSLoc ToBeginLocOrErr = import(E->getBeginLoc());
8856 if (!ToBeginLocOrErr)
8857 return ToBeginLocOrErr.takeError();
8858
8859 auto ToFieldOrErr = import(E->getField());
8860 if (!ToFieldOrErr)
8861 return ToFieldOrErr.takeError();
8862
8863 auto UsedContextOrErr = Importer.ImportContext(E->getUsedContext());
8864 if (!UsedContextOrErr)
8865 return UsedContextOrErr.takeError();
8866
8867 FieldDecl *ToField = *ToFieldOrErr;
8868 assert(ToField->hasInClassInitializer() &&
8869 "Field should have in-class initializer if there is a default init "
8870 "expression that uses it.");
8871 if (!ToField->getInClassInitializer()) {
8872 // The in-class initializer may be not yet set in "To" AST even if the
8873 // field is already there. This must be set here to make construction of
8874 // CXXDefaultInitExpr work.
8875 auto ToInClassInitializerOrErr =
8876 import(E->getField()->getInClassInitializer());
8877 if (!ToInClassInitializerOrErr)
8878 return ToInClassInitializerOrErr.takeError();
8879 ToField->setInClassInitializer(*ToInClassInitializerOrErr);
8880 }
8881
8882 Expr *RewrittenInit = nullptr;
8883 if (E->hasRewrittenInit()) {
8884 ExpectedExpr ExprOrErr = import(E->getRewrittenExpr());
8885 if (!ExprOrErr)
8886 return ExprOrErr.takeError();
8887 RewrittenInit = ExprOrErr.get();
8888 }
8889
8890 return CXXDefaultInitExpr::Create(Importer.getToContext(), *ToBeginLocOrErr,
8891 ToField, *UsedContextOrErr, RewrittenInit);
8892}
8893
8895 Error Err = Error::success();
8896 auto ToType = importChecked(Err, E->getType());
8897 auto ToSubExpr = importChecked(Err, E->getSubExpr());
8898 auto ToTypeInfoAsWritten = importChecked(Err, E->getTypeInfoAsWritten());
8899 auto ToOperatorLoc = importChecked(Err, E->getOperatorLoc());
8900 auto ToRParenLoc = importChecked(Err, E->getRParenLoc());
8901 auto ToAngleBrackets = importChecked(Err, E->getAngleBrackets());
8902 if (Err)
8903 return std::move(Err);
8904
8906 CastKind CK = E->getCastKind();
8907 auto ToBasePathOrErr = ImportCastPath(E);
8908 if (!ToBasePathOrErr)
8909 return ToBasePathOrErr.takeError();
8910
8911 if (auto CCE = dyn_cast<CXXStaticCastExpr>(E)) {
8913 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8914 ToTypeInfoAsWritten, CCE->getFPFeatures(), ToOperatorLoc, ToRParenLoc,
8915 ToAngleBrackets);
8916 } else if (isa<CXXDynamicCastExpr>(E)) {
8918 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8919 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8920 } else if (isa<CXXReinterpretCastExpr>(E)) {
8922 Importer.getToContext(), ToType, VK, CK, ToSubExpr, &(*ToBasePathOrErr),
8923 ToTypeInfoAsWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8924 } else if (isa<CXXConstCastExpr>(E)) {
8926 Importer.getToContext(), ToType, VK, ToSubExpr, ToTypeInfoAsWritten,
8927 ToOperatorLoc, ToRParenLoc, ToAngleBrackets);
8928 } else {
8929 llvm_unreachable("Unknown cast type");
8930 return make_error<ASTImportError>();
8931 }
8932}
8933
8936 Error Err = Error::success();
8937 auto ToType = importChecked(Err, E->getType());
8938 auto ToExprLoc = importChecked(Err, E->getExprLoc());
8939 auto ToAssociatedDecl = importChecked(Err, E->getAssociatedDecl());
8940 auto ToReplacement = importChecked(Err, E->getReplacement());
8941 if (Err)
8942 return std::move(Err);
8943
8944 return new (Importer.getToContext()) SubstNonTypeTemplateParmExpr(
8945 ToType, E->getValueKind(), ToExprLoc, ToReplacement, ToAssociatedDecl,
8946 E->getIndex(), E->getPackIndex(), E->isReferenceParameter());
8947}
8948
8950 Error Err = Error::success();
8951 auto ToType = importChecked(Err, E->getType());
8952 auto ToBeginLoc = importChecked(Err, E->getBeginLoc());
8953 auto ToEndLoc = importChecked(Err, E->getEndLoc());
8954 if (Err)
8955 return std::move(Err);
8956
8957 SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs());
8958 if (Error Err = ImportContainerChecked(E->getArgs(), ToArgs))
8959 return std::move(Err);
8960
8961 // According to Sema::BuildTypeTrait(), if E is value-dependent,
8962 // Value is always false.
8963 bool ToValue = (E->isValueDependent() ? false : E->getValue());
8964
8965 return TypeTraitExpr::Create(
8966 Importer.getToContext(), ToType, ToBeginLoc, E->getTrait(), ToArgs,
8967 ToEndLoc, ToValue);
8968}
8969
8971 ExpectedType ToTypeOrErr = import(E->getType());
8972 if (!ToTypeOrErr)
8973 return ToTypeOrErr.takeError();
8974
8975 auto ToSourceRangeOrErr = import(E->getSourceRange());
8976 if (!ToSourceRangeOrErr)
8977 return ToSourceRangeOrErr.takeError();
8978
8979 if (E->isTypeOperand()) {
8980 if (auto ToTSIOrErr = import(E->getTypeOperandSourceInfo()))
8981 return new (Importer.getToContext()) CXXTypeidExpr(
8982 *ToTypeOrErr, *ToTSIOrErr, *ToSourceRangeOrErr);
8983 else
8984 return ToTSIOrErr.takeError();
8985 }
8986
8987 ExpectedExpr ToExprOperandOrErr = import(E->getExprOperand());
8988 if (!ToExprOperandOrErr)
8989 return ToExprOperandOrErr.takeError();
8990
8991 return new (Importer.getToContext()) CXXTypeidExpr(
8992 *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
8993}
8994
8996 Error Err = Error::success();
8997
8998 QualType ToType = importChecked(Err, E->getType());
8999 UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
9000 SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
9001 Expr *ToLHS = importChecked(Err, E->getLHS());
9002 SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
9003 Expr *ToRHS = importChecked(Err, E->getRHS());
9004 SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
9005
9006 if (Err)
9007 return std::move(Err);
9008
9009 return new (Importer.getToContext())
9010 CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
9011 ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
9012}
9013
9015 CXXMethodDecl *FromMethod) {
9016 Error ImportErrors = Error::success();
9017 for (auto *FromOverriddenMethod : FromMethod->overridden_methods()) {
9018 if (auto ImportedOrErr = import(FromOverriddenMethod))
9019 ToMethod->getCanonicalDecl()->addOverriddenMethod(cast<CXXMethodDecl>(
9020 (*ImportedOrErr)->getCanonicalDecl()));
9021 else
9022 ImportErrors =
9023 joinErrors(std::move(ImportErrors), ImportedOrErr.takeError());
9024 }
9025 return ImportErrors;
9026}
9027
9029 ASTContext &FromContext, FileManager &FromFileManager,
9030 bool MinimalImport,
9031 std::shared_ptr<ASTImporterSharedState> SharedState)
9032 : SharedState(SharedState), ToContext(ToContext), FromContext(FromContext),
9033 ToFileManager(ToFileManager), FromFileManager(FromFileManager),
9034 Minimal(MinimalImport), ODRHandling(ODRHandlingType::Conservative) {
9035
9036 // Create a default state without the lookup table: LLDB case.
9037 if (!SharedState) {
9038 this->SharedState = std::make_shared<ASTImporterSharedState>();
9039 }
9040
9041 ImportedDecls[FromContext.getTranslationUnitDecl()] =
9042 ToContext.getTranslationUnitDecl();
9043}
9044
9045ASTImporter::~ASTImporter() = default;
9046
9047std::optional<unsigned> ASTImporter::getFieldIndex(Decl *F) {
9048 assert(F && (isa<FieldDecl>(*F) || isa<IndirectFieldDecl>(*F)) &&
9049 "Try to get field index for non-field.");
9050
9051 auto *Owner = dyn_cast<RecordDecl>(F->getDeclContext());
9052 if (!Owner)
9053 return std::nullopt;
9054
9055 unsigned Index = 0;
9056 for (const auto *D : Owner->decls()) {
9057 if (D == F)
9058 return Index;
9059
9060 if (isa<FieldDecl>(*D) || isa<IndirectFieldDecl>(*D))
9061 ++Index;
9062 }
9063
9064 llvm_unreachable("Field was not found in its parent context.");
9065
9066 return std::nullopt;
9067}
9068
9070ASTImporter::findDeclsInToCtx(DeclContext *DC, DeclarationName Name) {
9071 // We search in the redecl context because of transparent contexts.
9072 // E.g. a simple C language enum is a transparent context:
9073 // enum E { A, B };
9074 // Now if we had a global variable in the TU
9075 // int A;
9076 // then the enum constant 'A' and the variable 'A' violates ODR.
9077 // We can diagnose this only if we search in the redecl context.
9078 DeclContext *ReDC = DC->getRedeclContext();
9079 if (SharedState->getLookupTable()) {
9080 if (ReDC->isNamespace()) {
9081 // Namespaces can be reopened.
9082 // Lookup table does not handle this, we must search here in all linked
9083 // namespaces.
9084 FoundDeclsTy Result;
9085 SmallVector<Decl *, 2> NSChain =
9086 getCanonicalForwardRedeclChain<NamespaceDecl>(
9087 dyn_cast<NamespaceDecl>(ReDC));
9088 for (auto *D : NSChain) {
9090 SharedState->getLookupTable()->lookup(dyn_cast<NamespaceDecl>(D),
9091 Name);
9093 }
9094 return Result;
9095 } else {
9097 SharedState->getLookupTable()->lookup(ReDC, Name);
9098 return FoundDeclsTy(LookupResult.begin(), LookupResult.end());
9099 }
9100 } else {
9101 DeclContext::lookup_result NoloadLookupResult = ReDC->noload_lookup(Name);
9102 FoundDeclsTy Result(NoloadLookupResult.begin(), NoloadLookupResult.end());
9103 // We must search by the slow case of localUncachedLookup because that is
9104 // working even if there is no LookupPtr for the DC. We could use
9105 // DC::buildLookup() to create the LookupPtr, but that would load external
9106 // decls again, we must avoid that case.
9107 // Also, even if we had the LookupPtr, we must find Decls which are not
9108 // in the LookupPtr, so we need the slow case.
9109 // These cases are handled in ASTImporterLookupTable, but we cannot use
9110 // that with LLDB since that traverses through the AST which initiates the
9111 // load of external decls again via DC::decls(). And again, we must avoid
9112 // loading external decls during the import.
9113 if (Result.empty())
9114 ReDC->localUncachedLookup(Name, Result);
9115 return Result;
9116 }
9117}
9118
9119void ASTImporter::AddToLookupTable(Decl *ToD) {
9120 SharedState->addDeclToLookup(ToD);
9121}
9122
9124 // Import the decl using ASTNodeImporter.
9125 ASTNodeImporter Importer(*this);
9126 return Importer.Visit(FromD);
9127}
9128
9130 MapImported(FromD, ToD);
9131}
9132
9135 if (auto *CLE = From.dyn_cast<CompoundLiteralExpr *>()) {
9136 if (Expected<Expr *> R = Import(CLE))
9137 return ExprWithCleanups::CleanupObject(cast<CompoundLiteralExpr>(*R));
9138 }
9139
9140 // FIXME: Handle BlockDecl when we implement importing BlockExpr in
9141 // ASTNodeImporter.
9142 return make_error<ASTImportError>(ASTImportError::UnsupportedConstruct);
9143}
9144
9146 if (!FromT)
9147 return FromT;
9148
9149 // Check whether we've already imported this type.
9150 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
9151 ImportedTypes.find(FromT);
9152 if (Pos != ImportedTypes.end())
9153 return Pos->second;
9154
9155 // Import the type.
9156 ASTNodeImporter Importer(*this);
9157 ExpectedType ToTOrErr = Importer.Visit(FromT);
9158 if (!ToTOrErr)
9159 return ToTOrErr.takeError();
9160
9161 // Record the imported type.
9162 ImportedTypes[FromT] = ToTOrErr->getTypePtr();
9163
9164 return ToTOrErr->getTypePtr();
9165}
9166
9168 if (FromT.isNull())
9169 return QualType{};
9170
9171 ExpectedTypePtr ToTyOrErr = Import(FromT.getTypePtr());
9172 if (!ToTyOrErr)
9173 return ToTyOrErr.takeError();
9174
9175 return ToContext.getQualifiedType(*ToTyOrErr, FromT.getLocalQualifiers());
9176}
9177
9179 if (!FromTSI)
9180 return FromTSI;
9181
9182 // FIXME: For now we just create a "trivial" type source info based
9183 // on the type and a single location. Implement a real version of this.
9184 ExpectedType TOrErr = Import(FromTSI->getType());
9185 if (!TOrErr)
9186 return TOrErr.takeError();
9187 ExpectedSLoc BeginLocOrErr = Import(FromTSI->getTypeLoc().getBeginLoc());
9188 if (!BeginLocOrErr)
9189 return BeginLocOrErr.takeError();
9190
9191 return ToContext.getTrivialTypeSourceInfo(*TOrErr, *BeginLocOrErr);
9192}
9193
9194namespace {
9195// To use this object, it should be created before the new attribute is created,
9196// and destructed after it is created. The construction already performs the
9197// import of the data.
9198template <typename T> struct AttrArgImporter {
9199 AttrArgImporter(const AttrArgImporter<T> &) = delete;
9200 AttrArgImporter(AttrArgImporter<T> &&) = default;
9201 AttrArgImporter<T> &operator=(const AttrArgImporter<T> &) = delete;
9202 AttrArgImporter<T> &operator=(AttrArgImporter<T> &&) = default;
9203
9204 AttrArgImporter(ASTNodeImporter &I, Error &Err, const T &From)
9205 : To(I.importChecked(Err, From)) {}
9206
9207 const T &value() { return To; }
9208
9209private:
9210 T To;
9211};
9212
9213// To use this object, it should be created before the new attribute is created,
9214// and destructed after it is created. The construction already performs the
9215// import of the data. The array data is accessible in a pointer form, this form
9216// is used by the attribute classes. This object should be created once for the
9217// array data to be imported (the array size is not imported, just copied).
9218template <typename T> struct AttrArgArrayImporter {
9219 AttrArgArrayImporter(const AttrArgArrayImporter<T> &) = delete;
9220 AttrArgArrayImporter(AttrArgArrayImporter<T> &&) = default;
9221 AttrArgArrayImporter<T> &operator=(const AttrArgArrayImporter<T> &) = delete;
9222 AttrArgArrayImporter<T> &operator=(AttrArgArrayImporter<T> &&) = default;
9223
9224 AttrArgArrayImporter(ASTNodeImporter &I, Error &Err,
9225 const llvm::iterator_range<T *> &From,
9226 unsigned ArraySize) {
9227 if (Err)
9228 return;
9229 To.reserve(ArraySize);
9230 Err = I.ImportContainerChecked(From, To);
9231 }
9232
9233 T *value() { return To.data(); }
9234
9235private:
9237};
9238
9239class AttrImporter {
9240 Error Err{Error::success()};
9241 Attr *ToAttr = nullptr;
9242 ASTImporter &Importer;
9243 ASTNodeImporter NImporter;
9244
9245public:
9246 AttrImporter(ASTImporter &I) : Importer(I), NImporter(I) {}
9247
9248 // Useful for accessing the imported attribute.
9249 template <typename T> T *castAttrAs() { return cast<T>(ToAttr); }
9250 template <typename T> const T *castAttrAs() const { return cast<T>(ToAttr); }
9251
9252 // Create an "importer" for an attribute parameter.
9253 // Result of the 'value()' of that object is to be passed to the function
9254 // 'importAttr', in the order that is expected by the attribute class.
9255 template <class T> AttrArgImporter<T> importArg(const T &From) {
9256 return AttrArgImporter<T>(NImporter, Err, From);
9257 }
9258
9259 // Create an "importer" for an attribute parameter that has array type.
9260 // Result of the 'value()' of that object is to be passed to the function
9261 // 'importAttr', then the size of the array as next argument.
9262 template <typename T>
9263 AttrArgArrayImporter<T> importArrayArg(const llvm::iterator_range<T *> &From,
9264 unsigned ArraySize) {
9265 return AttrArgArrayImporter<T>(NImporter, Err, From, ArraySize);
9266 }
9267
9268 // Create an attribute object with the specified arguments.
9269 // The 'FromAttr' is the original (not imported) attribute, the 'ImportedArg'
9270 // should be values that are passed to the 'Create' function of the attribute.
9271 // (The 'Create' with 'ASTContext' first and 'AttributeCommonInfo' last is
9272 // used here.) As much data is copied or imported from the old attribute
9273 // as possible. The passed arguments should be already imported.
9274 // If an import error happens, the internal error is set to it, and any
9275 // further import attempt is ignored.
9276 template <typename T, typename... Arg>
9277 void importAttr(const T *FromAttr, Arg &&...ImportedArg) {
9278 static_assert(std::is_base_of<Attr, T>::value,
9279 "T should be subclass of Attr.");
9280 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9281
9282 const IdentifierInfo *ToAttrName = Importer.Import(FromAttr->getAttrName());
9283 const IdentifierInfo *ToScopeName =
9284 Importer.Import(FromAttr->getScopeName());
9285 SourceRange ToAttrRange =
9286 NImporter.importChecked(Err, FromAttr->getRange());
9287 SourceLocation ToScopeLoc =
9288 NImporter.importChecked(Err, FromAttr->getScopeLoc());
9289
9290 if (Err)
9291 return;
9292
9293 AttributeCommonInfo ToI(ToAttrName, ToScopeName, ToAttrRange, ToScopeLoc,
9294 FromAttr->getParsedKind(), FromAttr->getForm());
9295 // The "SemanticSpelling" is not needed to be passed to the constructor.
9296 // That value is recalculated from the SpellingListIndex if needed.
9297 ToAttr = T::Create(Importer.getToContext(),
9298 std::forward<Arg>(ImportedArg)..., ToI);
9299
9300 ToAttr->setImplicit(FromAttr->isImplicit());
9301 ToAttr->setPackExpansion(FromAttr->isPackExpansion());
9302 if (auto *ToInheritableAttr = dyn_cast<InheritableAttr>(ToAttr))
9303 ToInheritableAttr->setInherited(FromAttr->isInherited());
9304 }
9305
9306 // Create a clone of the 'FromAttr' and import its source range only.
9307 // This causes objects with invalid references to be created if the 'FromAttr'
9308 // contains other data that should be imported.
9309 void cloneAttr(const Attr *FromAttr) {
9310 assert(!ToAttr && "Use one AttrImporter to import one Attribute object.");
9311
9312 SourceRange ToRange = NImporter.importChecked(Err, FromAttr->getRange());
9313 if (Err)
9314 return;
9315
9316 ToAttr = FromAttr->clone(Importer.getToContext());
9317 ToAttr->setRange(ToRange);
9318 ToAttr->setAttrName(Importer.Import(FromAttr->getAttrName()));
9319 }
9320
9321 // Get the result of the previous import attempt (can be used only once).
9322 llvm::Expected<Attr *> getResult() && {
9323 if (Err)
9324 return std::move(Err);
9325 assert(ToAttr && "Attribute should be created.");
9326 return ToAttr;
9327 }
9328};
9329} // namespace
9330
9332 AttrImporter AI(*this);
9333
9334 // FIXME: Is there some kind of AttrVisitor to use here?
9335 switch (FromAttr->getKind()) {
9336 case attr::Aligned: {
9337 auto *From = cast<AlignedAttr>(FromAttr);
9338 if (From->isAlignmentExpr())
9339 AI.importAttr(From, true, AI.importArg(From->getAlignmentExpr()).value());
9340 else
9341 AI.importAttr(From, false,
9342 AI.importArg(From->getAlignmentType()).value());
9343 break;
9344 }
9345
9346 case attr::AlignValue: {
9347 auto *From = cast<AlignValueAttr>(FromAttr);
9348 AI.importAttr(From, AI.importArg(From->getAlignment()).value());
9349 break;
9350 }
9351
9352 case attr::Format: {
9353 const auto *From = cast<FormatAttr>(FromAttr);
9354 AI.importAttr(From, Import(From->getType()), From->getFormatIdx(),
9355 From->getFirstArg());
9356 break;
9357 }
9358
9359 case attr::EnableIf: {
9360 const auto *From = cast<EnableIfAttr>(FromAttr);
9361 AI.importAttr(From, AI.importArg(From->getCond()).value(),
9362 From->getMessage());
9363 break;
9364 }
9365
9366 case attr::AssertCapability: {
9367 const auto *From = cast<AssertCapabilityAttr>(FromAttr);
9368 AI.importAttr(From,
9369 AI.importArrayArg(From->args(), From->args_size()).value(),
9370 From->args_size());
9371 break;
9372 }
9373 case attr::AcquireCapability: {
9374 const auto *From = cast<AcquireCapabilityAttr>(FromAttr);
9375 AI.importAttr(From,
9376 AI.importArrayArg(From->args(), From->args_size()).value(),
9377 From->args_size());
9378 break;
9379 }
9380 case attr::TryAcquireCapability: {
9381 const auto *From = cast<TryAcquireCapabilityAttr>(FromAttr);
9382 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9383 AI.importArrayArg(From->args(), From->args_size()).value(),
9384 From->args_size());
9385 break;
9386 }
9387 case attr::ReleaseCapability: {
9388 const auto *From = cast<ReleaseCapabilityAttr>(FromAttr);
9389 AI.importAttr(From,
9390 AI.importArrayArg(From->args(), From->args_size()).value(),
9391 From->args_size());
9392 break;
9393 }
9394 case attr::RequiresCapability: {
9395 const auto *From = cast<RequiresCapabilityAttr>(FromAttr);
9396 AI.importAttr(From,
9397 AI.importArrayArg(From->args(), From->args_size()).value(),
9398 From->args_size());
9399 break;
9400 }
9401 case attr::GuardedBy: {
9402 const auto *From = cast<GuardedByAttr>(FromAttr);
9403 AI.importAttr(From, AI.importArg(From->getArg()).value());
9404 break;
9405 }
9406 case attr::PtGuardedBy: {
9407 const auto *From = cast<PtGuardedByAttr>(FromAttr);
9408 AI.importAttr(From, AI.importArg(From->getArg()).value());
9409 break;
9410 }
9411 case attr::AcquiredAfter: {
9412 const auto *From = cast<AcquiredAfterAttr>(FromAttr);
9413 AI.importAttr(From,
9414 AI.importArrayArg(From->args(), From->args_size()).value(),
9415 From->args_size());
9416 break;
9417 }
9418 case attr::AcquiredBefore: {
9419 const auto *From = cast<AcquiredBeforeAttr>(FromAttr);
9420 AI.importAttr(From,
9421 AI.importArrayArg(From->args(), From->args_size()).value(),
9422 From->args_size());
9423 break;
9424 }
9425 case attr::AssertExclusiveLock: {
9426 const auto *From = cast<AssertExclusiveLockAttr>(FromAttr);
9427 AI.importAttr(From,
9428 AI.importArrayArg(From->args(), From->args_size()).value(),
9429 From->args_size());
9430 break;
9431 }
9432 case attr::AssertSharedLock: {
9433 const auto *From = cast<AssertSharedLockAttr>(FromAttr);
9434 AI.importAttr(From,
9435 AI.importArrayArg(From->args(), From->args_size()).value(),
9436 From->args_size());
9437 break;
9438 }
9439 case attr::ExclusiveTrylockFunction: {
9440 const auto *From = cast<ExclusiveTrylockFunctionAttr>(FromAttr);
9441 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9442 AI.importArrayArg(From->args(), From->args_size()).value(),
9443 From->args_size());
9444 break;
9445 }
9446 case attr::SharedTrylockFunction: {
9447 const auto *From = cast<SharedTrylockFunctionAttr>(FromAttr);
9448 AI.importAttr(From, AI.importArg(From->getSuccessValue()).value(),
9449 AI.importArrayArg(From->args(), From->args_size()).value(),
9450 From->args_size());
9451 break;
9452 }
9453 case attr::LockReturned: {
9454 const auto *From = cast<LockReturnedAttr>(FromAttr);
9455 AI.importAttr(From, AI.importArg(From->getArg()).value());
9456 break;
9457 }
9458 case attr::LocksExcluded: {
9459 const auto *From = cast<LocksExcludedAttr>(FromAttr);
9460 AI.importAttr(From,
9461 AI.importArrayArg(From->args(), From->args_size()).value(),
9462 From->args_size());
9463 break;
9464 }
9465 default: {
9466 // The default branch works for attributes that have no arguments to import.
9467 // FIXME: Handle every attribute type that has arguments of type to import
9468 // (most often Expr* or Decl* or type) in the switch above.
9469 AI.cloneAttr(FromAttr);
9470 break;
9471 }
9472 }
9473
9474 return std::move(AI).getResult();
9475}
9476
9478 return ImportedDecls.lookup(FromD);
9479}
9480
9482 auto FromDPos = ImportedFromDecls.find(ToD);
9483 if (FromDPos == ImportedFromDecls.end())
9484 return nullptr;
9485 return FromDPos->second->getTranslationUnitDecl();
9486}
9487
9489 if (!FromD)
9490 return nullptr;
9491
9492 // Push FromD to the stack, and remove that when we return.
9493 ImportPath.push(FromD);
9494 auto ImportPathBuilder =
9495 llvm::make_scope_exit([this]() { ImportPath.pop(); });
9496
9497 // Check whether there was a previous failed import.
9498 // If yes return the existing error.
9499 if (auto Error = getImportDeclErrorIfAny(FromD))
9500 return make_error<ASTImportError>(*Error);
9501
9502 // Check whether we've already imported this declaration.
9503 Decl *ToD = GetAlreadyImportedOrNull(FromD);
9504 if (ToD) {
9505 // Already imported (possibly from another TU) and with an error.
9506 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9507 setImportDeclError(FromD, *Error);
9508 return make_error<ASTImportError>(*Error);
9509 }
9510
9511 // If FromD has some updated flags after last import, apply it.
9512 updateFlags(FromD, ToD);
9513 // If we encounter a cycle during an import then we save the relevant part
9514 // of the import path associated to the Decl.
9515 if (ImportPath.hasCycleAtBack())
9516 SavedImportPaths[FromD].push_back(ImportPath.copyCycleAtBack());
9517 return ToD;
9518 }
9519
9520 // Import the declaration.
9521 ExpectedDecl ToDOrErr = ImportImpl(FromD);
9522 if (!ToDOrErr) {
9523 // Failed to import.
9524
9525 auto Pos = ImportedDecls.find(FromD);
9526 if (Pos != ImportedDecls.end()) {
9527 // Import failed after the object was created.
9528 // Remove all references to it.
9529 auto *ToD = Pos->second;
9530 ImportedDecls.erase(Pos);
9531
9532 // ImportedDecls and ImportedFromDecls are not symmetric. It may happen
9533 // (e.g. with namespaces) that several decls from the 'from' context are
9534 // mapped to the same decl in the 'to' context. If we removed entries
9535 // from the LookupTable here then we may end up removing them multiple
9536 // times.
9537
9538 // The Lookuptable contains decls only which are in the 'to' context.
9539 // Remove from the Lookuptable only if it is *imported* into the 'to'
9540 // context (and do not remove it if it was added during the initial
9541 // traverse of the 'to' context).
9542 auto PosF = ImportedFromDecls.find(ToD);
9543 if (PosF != ImportedFromDecls.end()) {
9544 // In the case of TypedefNameDecl we create the Decl first and only
9545 // then we import and set its DeclContext. So, the DC might not be set
9546 // when we reach here.
9547 if (ToD->getDeclContext())
9548 SharedState->removeDeclFromLookup(ToD);
9549 ImportedFromDecls.erase(PosF);
9550 }
9551
9552 // FIXME: AST may contain remaining references to the failed object.
9553 // However, the ImportDeclErrors in the shared state contains all the
9554 // failed objects together with their error.
9555 }
9556
9557 // Error encountered for the first time.
9558 // After takeError the error is not usable any more in ToDOrErr.
9559 // Get a copy of the error object (any more simple solution for this?).
9560 ASTImportError ErrOut;
9561 handleAllErrors(ToDOrErr.takeError(),
9562 [&ErrOut](const ASTImportError &E) { ErrOut = E; });
9563 setImportDeclError(FromD, ErrOut);
9564 // Set the error for the mapped to Decl, which is in the "to" context.
9565 if (Pos != ImportedDecls.end())
9566 SharedState->setImportDeclError(Pos->second, ErrOut);
9567
9568 // Set the error for all nodes which have been created before we
9569 // recognized the error.
9570 for (const auto &Path : SavedImportPaths[FromD]) {
9571 // The import path contains import-dependency nodes first.
9572 // Save the node that was imported as dependency of the current node.
9573 Decl *PrevFromDi = FromD;
9574 for (Decl *FromDi : Path) {
9575 // Begin and end of the path equals 'FromD', skip it.
9576 if (FromDi == FromD)
9577 continue;
9578 // We should not set import error on a node and all following nodes in
9579 // the path if child import errors are ignored.
9580 if (ChildErrorHandlingStrategy(FromDi).ignoreChildErrorOnParent(
9581 PrevFromDi))
9582 break;
9583 PrevFromDi = FromDi;
9584 setImportDeclError(FromDi, ErrOut);
9585 //FIXME Should we remove these Decls from ImportedDecls?
9586 // Set the error for the mapped to Decl, which is in the "to" context.
9587 auto Ii = ImportedDecls.find(FromDi);
9588 if (Ii != ImportedDecls.end())
9589 SharedState->setImportDeclError(Ii->second, ErrOut);
9590 // FIXME Should we remove these Decls from the LookupTable,
9591 // and from ImportedFromDecls?
9592 }
9593 }
9594 SavedImportPaths.erase(FromD);
9595
9596 // Do not return ToDOrErr, error was taken out of it.
9597 return make_error<ASTImportError>(ErrOut);
9598 }
9599
9600 ToD = *ToDOrErr;
9601
9602 // FIXME: Handle the "already imported with error" case. We can get here
9603 // nullptr only if GetImportedOrCreateDecl returned nullptr (after a
9604 // previously failed create was requested).
9605 // Later GetImportedOrCreateDecl can be updated to return the error.
9606 if (!ToD) {
9607 auto Err = getImportDeclErrorIfAny(FromD);
9608 assert(Err);
9609 return make_error<ASTImportError>(*Err);
9610 }
9611
9612 // We could import from the current TU without error. But previously we
9613 // already had imported a Decl as `ToD` from another TU (with another
9614 // ASTImporter object) and with an error.
9615 if (auto Error = SharedState->getImportDeclErrorIfAny(ToD)) {
9616 setImportDeclError(FromD, *Error);
9617 return make_error<ASTImportError>(*Error);
9618 }
9619 // Make sure that ImportImpl registered the imported decl.
9620 assert(ImportedDecls.count(FromD) != 0 && "Missing call to MapImported?");
9621
9622 if (FromD->hasAttrs())
9623 for (const Attr *FromAttr : FromD->getAttrs()) {
9624 auto ToAttrOrErr = Import(FromAttr);
9625 if (ToAttrOrErr)
9626 ToD->addAttr(*ToAttrOrErr);
9627 else
9628 return ToAttrOrErr.takeError();
9629 }
9630
9631 // Notify subclasses.
9632 Imported(FromD, ToD);
9633
9634 updateFlags(FromD, ToD);
9635 SavedImportPaths.erase(FromD);
9636 return ToDOrErr;
9637}
9638
9641 return ASTNodeImporter(*this).ImportInheritedConstructor(From);
9642}
9643
9645 if (!FromDC)
9646 return FromDC;
9647
9648 ExpectedDecl ToDCOrErr = Import(cast<Decl>(FromDC));
9649 if (!ToDCOrErr)
9650 return ToDCOrErr.takeError();
9651 auto *ToDC = cast<DeclContext>(*ToDCOrErr);
9652
9653 // When we're using a record/enum/Objective-C class/protocol as a context, we
9654 // need it to have a definition.
9655 if (auto *ToRecord = dyn_cast<RecordDecl>(ToDC)) {
9656 auto *FromRecord = cast<RecordDecl>(FromDC);
9657 if (ToRecord->isCompleteDefinition())
9658 return ToDC;
9659
9660 // If FromRecord is not defined we need to force it to be.
9661 // Simply calling CompleteDecl(...) for a RecordDecl will break some cases
9662 // it will start the definition but we never finish it.
9663 // If there are base classes they won't be imported and we will
9664 // be missing anything that we inherit from those bases.
9665 if (FromRecord->getASTContext().getExternalSource() &&
9666 !FromRecord->isCompleteDefinition())
9667 FromRecord->getASTContext().getExternalSource()->CompleteType(FromRecord);
9668
9669 if (FromRecord->isCompleteDefinition())
9670 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9671 FromRecord, ToRecord, ASTNodeImporter::IDK_Basic))
9672 return std::move(Err);
9673 } else if (auto *ToEnum = dyn_cast<EnumDecl>(ToDC)) {
9674 auto *FromEnum = cast<EnumDecl>(FromDC);
9675 if (ToEnum->isCompleteDefinition()) {
9676 // Do nothing.
9677 } else if (FromEnum->isCompleteDefinition()) {
9678 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9679 FromEnum, ToEnum, ASTNodeImporter::IDK_Basic))
9680 return std::move(Err);
9681 } else {
9682 CompleteDecl(ToEnum);
9683 }
9684 } else if (auto *ToClass = dyn_cast<ObjCInterfaceDecl>(ToDC)) {
9685 auto *FromClass = cast<ObjCInterfaceDecl>(FromDC);
9686 if (ToClass->getDefinition()) {
9687 // Do nothing.
9688 } else if (ObjCInterfaceDecl *FromDef = FromClass->getDefinition()) {
9689 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9690 FromDef, ToClass, ASTNodeImporter::IDK_Basic))
9691 return std::move(Err);
9692 } else {
9693 CompleteDecl(ToClass);
9694 }
9695 } else if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(ToDC)) {
9696 auto *FromProto = cast<ObjCProtocolDecl>(FromDC);
9697 if (ToProto->getDefinition()) {
9698 // Do nothing.
9699 } else if (ObjCProtocolDecl *FromDef = FromProto->getDefinition()) {
9700 if (Error Err = ASTNodeImporter(*this).ImportDefinition(
9701 FromDef, ToProto, ASTNodeImporter::IDK_Basic))
9702 return std::move(Err);
9703 } else {
9704 CompleteDecl(ToProto);
9705 }
9706 }
9707
9708 return ToDC;
9709}
9710
9712 if (ExpectedStmt ToSOrErr = Import(cast_or_null<Stmt>(FromE)))
9713 return cast_or_null<Expr>(*ToSOrErr);
9714 else
9715 return ToSOrErr.takeError();
9716}
9717
9719 if (!FromS)
9720 return nullptr;
9721
9722 // Check whether we've already imported this statement.
9723 llvm::DenseMap<Stmt *, Stmt *>::iterator Pos = ImportedStmts.find(FromS);
9724 if (Pos != ImportedStmts.end())
9725 return Pos->second;
9726
9727 // Import the statement.
9728 ASTNodeImporter Importer(*this);
9729 ExpectedStmt ToSOrErr = Importer.Visit(FromS);
9730 if (!ToSOrErr)
9731 return ToSOrErr;
9732
9733 if (auto *ToE = dyn_cast<Expr>(*ToSOrErr)) {
9734 auto *FromE = cast<Expr>(FromS);
9735 // Copy ExprBitfields, which may not be handled in Expr subclasses
9736 // constructors.
9737 ToE->setValueKind(FromE->getValueKind());
9738 ToE->setObjectKind(FromE->getObjectKind());
9739 ToE->setDependence(FromE->getDependence());
9740 }
9741
9742 // Record the imported statement object.
9743 ImportedStmts[FromS] = *ToSOrErr;
9744 return ToSOrErr;
9745}
9746
9749 if (!FromNNS)
9750 return nullptr;
9751
9752 NestedNameSpecifier *Prefix = nullptr;
9753 if (Error Err = importInto(Prefix, FromNNS->getPrefix()))
9754 return std::move(Err);
9755
9756 switch (FromNNS->getKind()) {
9758 assert(FromNNS->getAsIdentifier() && "NNS should contain identifier.");
9759 return NestedNameSpecifier::Create(ToContext, Prefix,
9760 Import(FromNNS->getAsIdentifier()));
9761
9763 if (ExpectedDecl NSOrErr = Import(FromNNS->getAsNamespace())) {
9764 return NestedNameSpecifier::Create(ToContext, Prefix,
9765 cast<NamespaceDecl>(*NSOrErr));
9766 } else
9767 return NSOrErr.takeError();
9768
9770 if (ExpectedDecl NSADOrErr = Import(FromNNS->getAsNamespaceAlias()))
9771 return NestedNameSpecifier::Create(ToContext, Prefix,
9772 cast<NamespaceAliasDecl>(*NSADOrErr));
9773 else
9774 return NSADOrErr.takeError();
9775
9777 return NestedNameSpecifier::GlobalSpecifier(ToContext);
9778
9780 if (ExpectedDecl RDOrErr = Import(FromNNS->getAsRecordDecl()))
9781 return NestedNameSpecifier::SuperSpecifier(ToContext,
9782 cast<CXXRecordDecl>(*RDOrErr));
9783 else
9784 return RDOrErr.takeError();
9785
9788 if (ExpectedTypePtr TyOrErr = Import(FromNNS->getAsType())) {
9789 bool TSTemplate =
9791 return NestedNameSpecifier::Create(ToContext, Prefix, TSTemplate,
9792 *TyOrErr);
9793 } else {
9794 return TyOrErr.takeError();
9795 }
9796 }
9797
9798 llvm_unreachable("Invalid nested name specifier kind");
9799}
9800
9803 // Copied from NestedNameSpecifier mostly.
9805 NestedNameSpecifierLoc NNS = FromNNS;
9806
9807 // Push each of the nested-name-specifiers's onto a stack for
9808 // serialization in reverse order.
9809 while (NNS) {
9810 NestedNames.push_back(NNS);
9811 NNS = NNS.getPrefix();
9812 }
9813
9815
9816 while (!NestedNames.empty()) {
9817 NNS = NestedNames.pop_back_val();
9818 NestedNameSpecifier *Spec = nullptr;
9819 if (Error Err = importInto(Spec, NNS.getNestedNameSpecifier()))
9820 return std::move(Err);
9821
9823
9824 SourceLocation ToLocalBeginLoc, ToLocalEndLoc;
9825 if (Kind != NestedNameSpecifier::Super) {
9826 if (Error Err = importInto(ToLocalBeginLoc, NNS.getLocalBeginLoc()))
9827 return std::move(Err);
9828
9829 if (Kind != NestedNameSpecifier::Global)
9830 if (Error Err = importInto(ToLocalEndLoc, NNS.getLocalEndLoc()))
9831 return std::move(Err);
9832 }
9833
9834 switch (Kind) {
9836 Builder.Extend(getToContext(), Spec->getAsIdentifier(), ToLocalBeginLoc,
9837 ToLocalEndLoc);
9838 break;
9839
9841 Builder.Extend(getToContext(), Spec->getAsNamespace(), ToLocalBeginLoc,
9842 ToLocalEndLoc);
9843 break;
9844
9846 Builder.Extend(getToContext(), Spec->getAsNamespaceAlias(),
9847 ToLocalBeginLoc, ToLocalEndLoc);
9848 break;
9849
9852 SourceLocation ToTLoc;
9853 if (Error Err = importInto(ToTLoc, NNS.getTypeLoc().getBeginLoc()))
9854 return std::move(Err);
9856 QualType(Spec->getAsType(), 0), ToTLoc);
9858 // ToLocalBeginLoc is here the location of the 'template' keyword.
9859 Builder.Extend(getToContext(), ToLocalBeginLoc, TSI->getTypeLoc(),
9860 ToLocalEndLoc);
9861 else
9862 // No location for 'template' keyword here.
9863 Builder.Extend(getToContext(), SourceLocation{}, TSI->getTypeLoc(),
9864 ToLocalEndLoc);
9865 break;
9866 }
9867
9869 Builder.MakeGlobal(getToContext(), ToLocalBeginLoc);
9870 break;
9871
9873 auto ToSourceRangeOrErr = Import(NNS.getSourceRange());
9874 if (!ToSourceRangeOrErr)
9875 return ToSourceRangeOrErr.takeError();
9876
9877 Builder.MakeSuper(getToContext(), Spec->getAsRecordDecl(),
9878 ToSourceRangeOrErr->getBegin(),
9879 ToSourceRangeOrErr->getEnd());
9880 }
9881 }
9882 }
9883
9884 return Builder.getWithLocInContext(getToContext());
9885}
9886
9888 switch (From.getKind()) {
9890 if (ExpectedDecl ToTemplateOrErr = Import(From.getAsTemplateDecl()))
9891 return TemplateName(cast<TemplateDecl>((*ToTemplateOrErr)->getCanonicalDecl()));
9892 else
9893 return ToTemplateOrErr.takeError();
9894
9897 UnresolvedSet<2> ToTemplates;
9898 for (auto *I : *FromStorage) {
9899 if (auto ToOrErr = Import(I))
9900 ToTemplates.addDecl(cast<NamedDecl>(*ToOrErr));
9901 else
9902 return ToOrErr.takeError();
9903 }
9904 return ToContext.getOverloadedTemplateName(ToTemplates.begin(),
9905 ToTemplates.end());
9906 }
9907
9910 auto DeclNameOrErr = Import(FromStorage->getDeclName());
9911 if (!DeclNameOrErr)
9912 return DeclNameOrErr.takeError();
9913 return ToContext.getAssumedTemplateName(*DeclNameOrErr);
9914 }
9915
9918 auto QualifierOrErr = Import(QTN->getQualifier());
9919 if (!QualifierOrErr)
9920 return QualifierOrErr.takeError();
9921 auto TNOrErr = Import(QTN->getUnderlyingTemplate());
9922 if (!TNOrErr)
9923 return TNOrErr.takeError();
9924 return ToContext.getQualifiedTemplateName(
9925 *QualifierOrErr, QTN->hasTemplateKeyword(), *TNOrErr);
9926 }
9927
9930 auto QualifierOrErr = Import(DTN->getQualifier());
9931 if (!QualifierOrErr)
9932 return QualifierOrErr.takeError();
9933
9934 if (DTN->isIdentifier()) {
9935 return ToContext.getDependentTemplateName(*QualifierOrErr,
9936 Import(DTN->getIdentifier()));
9937 }
9938
9939 return ToContext.getDependentTemplateName(*QualifierOrErr,
9940 DTN->getOperator());
9941 }
9942
9946 auto ReplacementOrErr = Import(Subst->getReplacement());
9947 if (!ReplacementOrErr)
9948 return ReplacementOrErr.takeError();
9949
9950 auto AssociatedDeclOrErr = Import(Subst->getAssociatedDecl());
9951 if (!AssociatedDeclOrErr)
9952 return AssociatedDeclOrErr.takeError();
9953
9954 return ToContext.getSubstTemplateTemplateParm(
9955 *ReplacementOrErr, *AssociatedDeclOrErr, Subst->getIndex(),
9956 Subst->getPackIndex());
9957 }
9958
9962 ASTNodeImporter Importer(*this);
9963 auto ArgPackOrErr =
9964 Importer.ImportTemplateArgument(SubstPack->getArgumentPack());
9965 if (!ArgPackOrErr)
9966 return ArgPackOrErr.takeError();
9967
9968 auto AssociatedDeclOrErr = Import(SubstPack->getAssociatedDecl());
9969 if (!AssociatedDeclOrErr)
9970 return AssociatedDeclOrErr.takeError();
9971
9972 return ToContext.getSubstTemplateTemplateParmPack(
9973 *ArgPackOrErr, *AssociatedDeclOrErr, SubstPack->getIndex(),
9974 SubstPack->getFinal());
9975 }
9977 auto UsingOrError = Import(From.getAsUsingShadowDecl());
9978 if (!UsingOrError)
9979 return UsingOrError.takeError();
9980 return TemplateName(cast<UsingShadowDecl>(*UsingOrError));
9981 }
9983 llvm_unreachable("Unexpected DeducedTemplate");
9984 }
9985
9986 llvm_unreachable("Invalid template name kind");
9987}
9988
9990 if (FromLoc.isInvalid())
9991 return SourceLocation{};
9992
9993 SourceManager &FromSM = FromContext.getSourceManager();
9994 bool IsBuiltin = FromSM.isWrittenInBuiltinFile(FromLoc);
9995
9996 std::pair<FileID, unsigned> Decomposed = FromSM.getDecomposedLoc(FromLoc);
9997 Expected<FileID> ToFileIDOrErr = Import(Decomposed.first, IsBuiltin);
9998 if (!ToFileIDOrErr)
9999 return ToFileIDOrErr.takeError();
10000 SourceManager &ToSM = ToContext.getSourceManager();
10001 return ToSM.getComposedLoc(*ToFileIDOrErr, Decomposed.second);
10002}
10003
10005 SourceLocation ToBegin, ToEnd;
10006 if (Error Err = importInto(ToBegin, FromRange.getBegin()))
10007 return std::move(Err);
10008 if (Error Err = importInto(ToEnd, FromRange.getEnd()))
10009 return std::move(Err);
10010
10011 return SourceRange(ToBegin, ToEnd);
10012}
10013
10015 llvm::DenseMap<FileID, FileID>::iterator Pos = ImportedFileIDs.find(FromID);
10016 if (Pos != ImportedFileIDs.end())
10017 return Pos->second;
10018
10019 SourceManager &FromSM = FromContext.getSourceManager();
10020 SourceManager &ToSM = ToContext.getSourceManager();
10021 const SrcMgr::SLocEntry &FromSLoc = FromSM.getSLocEntry(FromID);
10022
10023 // Map the FromID to the "to" source manager.
10024 FileID ToID;
10025 if (FromSLoc.isExpansion()) {
10026 const SrcMgr::ExpansionInfo &FromEx = FromSLoc.getExpansion();
10027 ExpectedSLoc ToSpLoc = Import(FromEx.getSpellingLoc());
10028 if (!ToSpLoc)
10029 return ToSpLoc.takeError();
10030 ExpectedSLoc ToExLocS = Import(FromEx.getExpansionLocStart());
10031 if (!ToExLocS)
10032 return ToExLocS.takeError();
10033 unsigned ExLength = FromSM.getFileIDSize(FromID);
10034 SourceLocation MLoc;
10035 if (FromEx.isMacroArgExpansion()) {
10036 MLoc = ToSM.createMacroArgExpansionLoc(*ToSpLoc, *ToExLocS, ExLength);
10037 } else {
10038 if (ExpectedSLoc ToExLocE = Import(FromEx.getExpansionLocEnd()))
10039 MLoc = ToSM.createExpansionLoc(*ToSpLoc, *ToExLocS, *ToExLocE, ExLength,
10040 FromEx.isExpansionTokenRange());
10041 else
10042 return ToExLocE.takeError();
10043 }
10044 ToID = ToSM.getFileID(MLoc);
10045 } else {
10046 const SrcMgr::ContentCache *Cache = &FromSLoc.getFile().getContentCache();
10047
10048 if (!IsBuiltin && !Cache->BufferOverridden) {
10049 // Include location of this file.
10050 ExpectedSLoc ToIncludeLoc = Import(FromSLoc.getFile().getIncludeLoc());
10051 if (!ToIncludeLoc)
10052 return ToIncludeLoc.takeError();
10053
10054 // Every FileID that is not the main FileID needs to have a valid include
10055 // location so that the include chain points to the main FileID. When
10056 // importing the main FileID (which has no include location), we need to
10057 // create a fake include location in the main file to keep this property
10058 // intact.
10059 SourceLocation ToIncludeLocOrFakeLoc = *ToIncludeLoc;
10060 if (FromID == FromSM.getMainFileID())
10061 ToIncludeLocOrFakeLoc = ToSM.getLocForStartOfFile(ToSM.getMainFileID());
10062
10063 if (Cache->OrigEntry && Cache->OrigEntry->getDir()) {
10064 // FIXME: We probably want to use getVirtualFileRef(), so we don't hit
10065 // the disk again
10066 // FIXME: We definitely want to re-use the existing MemoryBuffer, rather
10067 // than mmap the files several times.
10068 auto Entry =
10069 ToFileManager.getOptionalFileRef(Cache->OrigEntry->getName());
10070 // FIXME: The filename may be a virtual name that does probably not
10071 // point to a valid file and we get no Entry here. In this case try with
10072 // the memory buffer below.
10073 if (Entry)
10074 ToID = ToSM.createFileID(*Entry, ToIncludeLocOrFakeLoc,
10075 FromSLoc.getFile().getFileCharacteristic());
10076 }
10077 }
10078
10079 if (ToID.isInvalid() || IsBuiltin) {
10080 // FIXME: We want to re-use the existing MemoryBuffer!
10081 std::optional<llvm::MemoryBufferRef> FromBuf =
10082 Cache->getBufferOrNone(FromContext.getDiagnostics(),
10083 FromSM.getFileManager(), SourceLocation{});
10084 if (!FromBuf)
10085 return llvm::make_error<ASTImportError>(ASTImportError::Unknown);
10086
10087 std::unique_ptr<llvm::MemoryBuffer> ToBuf =
10088 llvm::MemoryBuffer::getMemBufferCopy(FromBuf->getBuffer(),
10089 FromBuf->getBufferIdentifier());
10090 ToID = ToSM.createFileID(std::move(ToBuf),
10091 FromSLoc.getFile().getFileCharacteristic());
10092 }
10093 }
10094
10095 assert(ToID.isValid() && "Unexpected invalid fileID was created.");
10096
10097 ImportedFileIDs[FromID] = ToID;
10098 return ToID;
10099}
10100
10102 ExpectedExpr ToExprOrErr = Import(From->getInit());
10103 if (!ToExprOrErr)
10104 return ToExprOrErr.takeError();
10105
10106 auto LParenLocOrErr = Import(From->getLParenLoc());
10107 if (!LParenLocOrErr)
10108 return LParenLocOrErr.takeError();
10109
10110 auto RParenLocOrErr = Import(From->getRParenLoc());
10111 if (!RParenLocOrErr)
10112 return RParenLocOrErr.takeError();
10113
10114 if (From->isBaseInitializer()) {
10115 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10116 if (!ToTInfoOrErr)
10117 return ToTInfoOrErr.takeError();
10118
10119 SourceLocation EllipsisLoc;
10120 if (From->isPackExpansion())
10121 if (Error Err = importInto(EllipsisLoc, From->getEllipsisLoc()))
10122 return std::move(Err);
10123
10124 return new (ToContext) CXXCtorInitializer(
10125 ToContext, *ToTInfoOrErr, From->isBaseVirtual(), *LParenLocOrErr,
10126 *ToExprOrErr, *RParenLocOrErr, EllipsisLoc);
10127 } else if (From->isMemberInitializer()) {
10128 ExpectedDecl ToFieldOrErr = Import(From->getMember());
10129 if (!ToFieldOrErr)
10130 return ToFieldOrErr.takeError();
10131
10132 auto MemberLocOrErr = Import(From->getMemberLocation());
10133 if (!MemberLocOrErr)
10134 return MemberLocOrErr.takeError();
10135
10136 return new (ToContext) CXXCtorInitializer(
10137 ToContext, cast_or_null<FieldDecl>(*ToFieldOrErr), *MemberLocOrErr,
10138 *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10139 } else if (From->isIndirectMemberInitializer()) {
10140 ExpectedDecl ToIFieldOrErr = Import(From->getIndirectMember());
10141 if (!ToIFieldOrErr)
10142 return ToIFieldOrErr.takeError();
10143
10144 auto MemberLocOrErr = Import(From->getMemberLocation());
10145 if (!MemberLocOrErr)
10146 return MemberLocOrErr.takeError();
10147
10148 return new (ToContext) CXXCtorInitializer(
10149 ToContext, cast_or_null<IndirectFieldDecl>(*ToIFieldOrErr),
10150 *MemberLocOrErr, *LParenLocOrErr, *ToExprOrErr, *RParenLocOrErr);
10151 } else if (From->isDelegatingInitializer()) {
10152 auto ToTInfoOrErr = Import(From->getTypeSourceInfo());
10153 if (!ToTInfoOrErr)
10154 return ToTInfoOrErr.takeError();
10155
10156 return new (ToContext)
10157 CXXCtorInitializer(ToContext, *ToTInfoOrErr, *LParenLocOrErr,
10158 *ToExprOrErr, *RParenLocOrErr);
10159 } else {
10160 // FIXME: assert?
10161 return make_error<ASTImportError>();
10162 }
10163}
10164
10167 auto Pos = ImportedCXXBaseSpecifiers.find(BaseSpec);
10168 if (Pos != ImportedCXXBaseSpecifiers.end())
10169 return Pos->second;
10170
10171 Expected<SourceRange> ToSourceRange = Import(BaseSpec->getSourceRange());
10172 if (!ToSourceRange)
10173 return ToSourceRange.takeError();
10175 if (!ToTSI)
10176 return ToTSI.takeError();
10177 ExpectedSLoc ToEllipsisLoc = Import(BaseSpec->getEllipsisLoc());
10178 if (!ToEllipsisLoc)
10179 return ToEllipsisLoc.takeError();
10180 CXXBaseSpecifier *Imported = new (ToContext) CXXBaseSpecifier(
10181 *ToSourceRange, BaseSpec->isVirtual(), BaseSpec->isBaseOfClass(),
10182 BaseSpec->getAccessSpecifierAsWritten(), *ToTSI, *ToEllipsisLoc);
10183 ImportedCXXBaseSpecifiers[BaseSpec] = Imported;
10184 return Imported;
10185}
10186
10188 ASTNodeImporter Importer(*this);
10189 return Importer.ImportAPValue(FromValue);
10190}
10191
10193 ExpectedDecl ToOrErr = Import(From);
10194 if (!ToOrErr)
10195 return ToOrErr.takeError();
10196 Decl *To = *ToOrErr;
10197
10198 auto *FromDC = cast<DeclContext>(From);
10199 ASTNodeImporter Importer(*this);
10200
10201 if (auto *ToRecord = dyn_cast<RecordDecl>(To)) {
10202 if (!ToRecord->getDefinition()) {
10203 return Importer.ImportDefinition(
10204 cast<RecordDecl>(FromDC), ToRecord,
10206 }
10207 }
10208
10209 if (auto *ToEnum = dyn_cast<EnumDecl>(To)) {
10210 if (!ToEnum->getDefinition()) {
10211 return Importer.ImportDefinition(
10212 cast<EnumDecl>(FromDC), ToEnum, ASTNodeImporter::IDK_Everything);
10213 }
10214 }
10215
10216 if (auto *ToIFace = dyn_cast<ObjCInterfaceDecl>(To)) {
10217 if (!ToIFace->getDefinition()) {
10218 return Importer.ImportDefinition(
10219 cast<ObjCInterfaceDecl>(FromDC), ToIFace,
10221 }
10222 }
10223
10224 if (auto *ToProto = dyn_cast<ObjCProtocolDecl>(To)) {
10225 if (!ToProto->getDefinition()) {
10226 return Importer.ImportDefinition(
10227 cast<ObjCProtocolDecl>(FromDC), ToProto,
10229 }
10230 }
10231
10232 return Importer.ImportDeclContext(FromDC, true);
10233}
10234
10236 if (!FromName)
10237 return DeclarationName{};
10238
10239 switch (FromName.getNameKind()) {
10241 return DeclarationName(Import(FromName.getAsIdentifierInfo()));
10242
10246 if (auto ToSelOrErr = Import(FromName.getObjCSelector()))
10247 return DeclarationName(*ToSelOrErr);
10248 else
10249 return ToSelOrErr.takeError();
10250
10252 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10253 return ToContext.DeclarationNames.getCXXConstructorName(
10254 ToContext.getCanonicalType(*ToTyOrErr));
10255 else
10256 return ToTyOrErr.takeError();
10257 }
10258
10260 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10261 return ToContext.DeclarationNames.getCXXDestructorName(
10262 ToContext.getCanonicalType(*ToTyOrErr));
10263 else
10264 return ToTyOrErr.takeError();
10265 }
10266
10268 if (auto ToTemplateOrErr = Import(FromName.getCXXDeductionGuideTemplate()))
10270 cast<TemplateDecl>(*ToTemplateOrErr));
10271 else
10272 return ToTemplateOrErr.takeError();
10273 }
10274
10276 if (auto ToTyOrErr = Import(FromName.getCXXNameType()))
10278 ToContext.getCanonicalType(*ToTyOrErr));
10279 else
10280 return ToTyOrErr.takeError();
10281 }
10282
10284 return ToContext.DeclarationNames.getCXXOperatorName(
10285 FromName.getCXXOverloadedOperator());
10286
10289 Import(FromName.getCXXLiteralIdentifier()));
10290
10292 // FIXME: STATICS!
10294 }
10295
10296 llvm_unreachable("Invalid DeclarationName Kind!");
10297}
10298
10300 if (!FromId)
10301 return nullptr;
10302
10303 IdentifierInfo *ToId = &ToContext.Idents.get(FromId->getName());
10304
10305 if (!ToId->getBuiltinID() && FromId->getBuiltinID())
10306 ToId->setBuiltinID(FromId->getBuiltinID());
10307
10308 return ToId;
10309}
10310
10312 if (FromSel.isNull())
10313 return Selector{};
10314
10316 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(0)));
10317 for (unsigned I = 1, N = FromSel.getNumArgs(); I < N; ++I)
10318 Idents.push_back(Import(FromSel.getIdentifierInfoForSlot(I)));
10319 return ToContext.Selectors.getSelector(FromSel.getNumArgs(), Idents.data());
10320}
10321
10325 llvm::Error Err = llvm::Error::success();
10326 auto ImportLoop = [&](const APValue *From, APValue *To, unsigned Size) {
10327 for (unsigned Idx = 0; Idx < Size; Idx++) {
10328 APValue Tmp = importChecked(Err, From[Idx]);
10329 To[Idx] = Tmp;
10330 }
10331 };
10332 switch (FromValue.getKind()) {
10333 case APValue::None:
10335 case APValue::Int:
10336 case APValue::Float:
10340 Result = FromValue;
10341 break;
10342 case APValue::Vector: {
10343 Result.MakeVector();
10345 Result.setVectorUninit(FromValue.getVectorLength());
10346 ImportLoop(((const APValue::Vec *)(const char *)&FromValue.Data)->Elts,
10347 Elts.data(), FromValue.getVectorLength());
10348 break;
10349 }
10350 case APValue::Array:
10351 Result.MakeArray(FromValue.getArrayInitializedElts(),
10352 FromValue.getArraySize());
10353 ImportLoop(((const APValue::Arr *)(const char *)&FromValue.Data)->Elts,
10354 ((const APValue::Arr *)(const char *)&Result.Data)->Elts,
10355 FromValue.getArrayInitializedElts());
10356 break;
10357 case APValue::Struct:
10358 Result.MakeStruct(FromValue.getStructNumBases(),
10359 FromValue.getStructNumFields());
10360 ImportLoop(
10361 ((const APValue::StructData *)(const char *)&FromValue.Data)->Elts,
10362 ((const APValue::StructData *)(const char *)&Result.Data)->Elts,
10363 FromValue.getStructNumBases() + FromValue.getStructNumFields());
10364 break;
10365 case APValue::Union: {
10366 Result.MakeUnion();
10367 const Decl *ImpFDecl = importChecked(Err, FromValue.getUnionField());
10368 APValue ImpValue = importChecked(Err, FromValue.getUnionValue());
10369 if (Err)
10370 return std::move(Err);
10371 Result.setUnion(cast<FieldDecl>(ImpFDecl), ImpValue);
10372 break;
10373 }
10375 Result.MakeAddrLabelDiff();
10376 const Expr *ImpLHS = importChecked(Err, FromValue.getAddrLabelDiffLHS());
10377 const Expr *ImpRHS = importChecked(Err, FromValue.getAddrLabelDiffRHS());
10378 if (Err)
10379 return std::move(Err);
10380 Result.setAddrLabelDiff(cast<AddrLabelExpr>(ImpLHS),
10381 cast<AddrLabelExpr>(ImpRHS));
10382 break;
10383 }
10385 const Decl *ImpMemPtrDecl =
10386 importChecked(Err, FromValue.getMemberPointerDecl());
10387 if (Err)
10388 return std::move(Err);
10390 Result.setMemberPointerUninit(
10391 cast<const ValueDecl>(ImpMemPtrDecl),
10393 FromValue.getMemberPointerPath().size());
10395 Result.getMemberPointerPath();
10396 for (unsigned Idx = 0; Idx < FromValue.getMemberPointerPath().size();
10397 Idx++) {
10398 const Decl *ImpDecl = importChecked(Err, FromPath[Idx]);
10399 if (Err)
10400 return std::move(Err);
10401 ToPath[Idx] = cast<const CXXRecordDecl>(ImpDecl->getCanonicalDecl());
10402 }
10403 break;
10404 }
10405 case APValue::LValue:
10407 QualType FromElemTy;
10408 if (FromValue.getLValueBase()) {
10409 assert(!FromValue.getLValueBase().is<DynamicAllocLValue>() &&
10410 "in C++20 dynamic allocation are transient so they shouldn't "
10411 "appear in the AST");
10412 if (!FromValue.getLValueBase().is<TypeInfoLValue>()) {
10413 if (const auto *E =
10414 FromValue.getLValueBase().dyn_cast<const Expr *>()) {
10415 FromElemTy = E->getType();
10416 const Expr *ImpExpr = importChecked(Err, E);
10417 if (Err)
10418 return std::move(Err);
10419 Base = APValue::LValueBase(ImpExpr,
10420 FromValue.getLValueBase().getCallIndex(),
10421 FromValue.getLValueBase().getVersion());
10422 } else {
10423 FromElemTy =
10424 FromValue.getLValueBase().get<const ValueDecl *>()->getType();
10425 const Decl *ImpDecl = importChecked(
10426 Err, FromValue.getLValueBase().get<const ValueDecl *>());
10427 if (Err)
10428 return std::move(Err);
10429 Base = APValue::LValueBase(cast<ValueDecl>(ImpDecl),
10430 FromValue.getLValueBase().getCallIndex(),
10431 FromValue.getLValueBase().getVersion());
10432 }
10433 } else {
10434 FromElemTy = FromValue.getLValueBase().getTypeInfoType();
10435 const Type *ImpTypeInfo = importChecked(
10436 Err, FromValue.getLValueBase().get<TypeInfoLValue>().getType());
10437 QualType ImpType =
10438 importChecked(Err, FromValue.getLValueBase().getTypeInfoType());
10439 if (Err)
10440 return std::move(Err);
10442 ImpType);
10443 }
10444 }
10445 CharUnits Offset = FromValue.getLValueOffset();
10446 unsigned PathLength = FromValue.getLValuePath().size();
10447 Result.MakeLValue();
10448 if (FromValue.hasLValuePath()) {
10449 MutableArrayRef<APValue::LValuePathEntry> ToPath = Result.setLValueUninit(
10450 Base, Offset, PathLength, FromValue.isLValueOnePastTheEnd(),
10451 FromValue.isNullPointer());
10453 FromValue.getLValuePath();
10454 for (unsigned LoopIdx = 0; LoopIdx < PathLength; LoopIdx++) {
10455 if (FromElemTy->isRecordType()) {
10456 const Decl *FromDecl =
10457 FromPath[LoopIdx].getAsBaseOrMember().getPointer();
10458 const Decl *ImpDecl = importChecked(Err, FromDecl);
10459 if (Err)
10460 return std::move(Err);
10461 if (auto *RD = dyn_cast<CXXRecordDecl>(FromDecl))
10462 FromElemTy = Importer.FromContext.getRecordType(RD);
10463 else
10464 FromElemTy = cast<ValueDecl>(FromDecl)->getType();
10466 ImpDecl, FromPath[LoopIdx].getAsBaseOrMember().getInt()));
10467 } else {
10468 FromElemTy =
10469 Importer.FromContext.getAsArrayType(FromElemTy)->getElementType();
10470 ToPath[LoopIdx] = APValue::LValuePathEntry::ArrayIndex(
10471 FromPath[LoopIdx].getAsArrayIndex());
10472 }
10473 }
10474 } else
10475 Result.setLValue(Base, Offset, APValue::NoLValuePath{},
10476 FromValue.isNullPointer());
10477 }
10478 if (Err)
10479 return std::move(Err);
10480 return Result;
10481}
10482
10484 DeclContext *DC,
10485 unsigned IDNS,
10486 NamedDecl **Decls,
10487 unsigned NumDecls) {
10488 if (ODRHandling == ODRHandlingType::Conservative)
10489 // Report error at any name conflict.
10490 return make_error<ASTImportError>(ASTImportError::NameConflict);
10491 else
10492 // Allow to create the new Decl with the same name.
10493 return Name;
10494}
10495
10497 if (LastDiagFromFrom)
10499 FromContext.getDiagnostics());
10500 LastDiagFromFrom = false;
10501 return ToContext.getDiagnostics().Report(Loc, DiagID);
10502}
10503
10505 if (!LastDiagFromFrom)
10507 ToContext.getDiagnostics());
10508 LastDiagFromFrom = true;
10509 return FromContext.getDiagnostics().Report(Loc, DiagID);
10510}
10511
10513 if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
10514 if (!ID->getDefinition())
10515 ID->startDefinition();
10516 }
10517 else if (auto *PD = dyn_cast<ObjCProtocolDecl>(D)) {
10518 if (!PD->getDefinition())
10519 PD->startDefinition();
10520 }
10521 else if (auto *TD = dyn_cast<TagDecl>(D)) {
10522 if (!TD->getDefinition() && !TD->isBeingDefined()) {
10523 TD->startDefinition();
10524 TD->setCompleteDefinition(true);
10525 }
10526 }
10527 else {
10528 assert(0 && "CompleteDecl called on a Decl that can't be completed");
10529 }
10530}
10531
10533 llvm::DenseMap<Decl *, Decl *>::iterator Pos = ImportedDecls.find(From);
10534 assert((Pos == ImportedDecls.end() || Pos->second == To) &&
10535 "Try to import an already imported Decl");
10536 if (Pos != ImportedDecls.end())
10537 return Pos->second;
10538 ImportedDecls[From] = To;
10539 // This mapping should be maintained only in this function. Therefore do not
10540 // check for additional consistency.
10541 ImportedFromDecls[To] = From;
10542 // In the case of TypedefNameDecl we create the Decl first and only then we
10543 // import and set its DeclContext. So, the DC is still not set when we reach
10544 // here from GetImportedOrCreateDecl.
10545 if (To->getDeclContext())
10546 AddToLookupTable(To);
10547 return To;
10548}
10549
10550std::optional<ASTImportError>
10552 auto Pos = ImportDeclErrors.find(FromD);
10553 if (Pos != ImportDeclErrors.end())
10554 return Pos->second;
10555 else
10556 return std::nullopt;
10557}
10558
10560 auto InsertRes = ImportDeclErrors.insert({From, Error});
10561 (void)InsertRes;
10562 // Either we set the error for the first time, or we already had set one and
10563 // now we want to set the same error.
10564 assert(InsertRes.second || InsertRes.first->second.Error == Error.Error);
10565}
10566
10568 bool Complain) {
10569 llvm::DenseMap<const Type *, const Type *>::iterator Pos =
10570 ImportedTypes.find(From.getTypePtr());
10571 if (Pos != ImportedTypes.end()) {
10572 if (ExpectedType ToFromOrErr = Import(From)) {
10573 if (ToContext.hasSameType(*ToFromOrErr, To))
10574 return true;
10575 } else {
10576 llvm::consumeError(ToFromOrErr.takeError());
10577 }
10578 }
10579
10580 StructuralEquivalenceContext Ctx(FromContext, ToContext, NonEquivalentDecls,
10581 getStructuralEquivalenceKind(*this), false,
10582 Complain);
10583 return Ctx.IsEquivalent(From, To);
10584}
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)
This file provides some common utility functions for processing Lambda related AST Constructs.
Defines enum values for all the target-independent builtin functions.
const Decl * D
IndirectLocalPath & Path
enum clang::sema::@1727::IndirectLocalPathEntry::EntryKind Kind
Expr * E
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the ExceptionSpecificationType enumeration and various utility functions.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines the clang::FileManager interface and associated types.
int Category
Definition: Format.cpp:3059
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the LambdaCapture class.
Defines the clang::LangOptions interface.
llvm::MachO::Record Record
Definition: MachO.h:31
llvm::SmallVector< std::pair< const MemRegion *, SVal >, 4 > Bindings
SourceLocation Loc
Definition: SemaObjC.cpp:759
Defines the clang::SourceLocation class and associated facilities.
Defines the SourceManager interface.
Defines various enumerations that describe declaration and type specifiers.
Defines the Objective-C statement AST node classes.
Defines the clang::TypeLoc interface and its subclasses.
C Language Family Type Representation.
const NamedDecl * FromDecl
unsigned getVersion() const
Definition: APValue.cpp:113
QualType getTypeInfoType() const
Definition: APValue.cpp:117
static LValueBase getTypeInfo(TypeInfoLValue LV, QualType TypeInfo)
Definition: APValue.cpp:55
unsigned getCallIndex() const
Definition: APValue.cpp:108
A non-discriminated union of a base, field, or array index.
Definition: APValue.h:207
static LValuePathEntry ArrayIndex(uint64_t Index)
Definition: APValue.h:215
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Definition: APValue.h:122
const LValueBase getLValueBase() const
Definition: APValue.cpp:984
ArrayRef< LValuePathEntry > getLValuePath() const
Definition: APValue.cpp:1004
const FieldDecl * getUnionField() const
Definition: APValue.h:629
unsigned getStructNumFields() const
Definition: APValue.h:608
llvm::PointerIntPair< const Decl *, 1, bool > BaseOrMemberType
A FieldDecl or CXXRecordDecl, along with a flag indicating whether we mean a virtual or non-virtual b...
Definition: APValue.h:204
ValueKind getKind() const
Definition: APValue.h:461
bool isLValueOnePastTheEnd() const
Definition: APValue.cpp:989
bool isMemberPointerToDerivedMember() const
Definition: APValue.cpp:1074
unsigned getArrayInitializedElts() const
Definition: APValue.h:595
unsigned getStructNumBases() const
Definition: APValue.h:604
bool hasLValuePath() const
Definition: APValue.cpp:999
const ValueDecl * getMemberPointerDecl() const
Definition: APValue.cpp:1067
APValue & getUnionValue()
Definition: APValue.h:633
const AddrLabelExpr * getAddrLabelDiffRHS() const
Definition: APValue.h:649
CharUnits & getLValueOffset()
Definition: APValue.cpp:994
unsigned getVectorLength() const
Definition: APValue.h:571
ArrayRef< const CXXRecordDecl * > getMemberPointerPath() const
Definition: APValue.cpp:1081
unsigned getArraySize() const
Definition: APValue.h:599
@ Indeterminate
This object has an indeterminate value (C++ [basic.indet]).
Definition: APValue.h:131
@ None
There is no such object (it's outside its lifetime).
Definition: APValue.h:129
bool isNullPointer() const
Definition: APValue.cpp:1020
const AddrLabelExpr * getAddrLabelDiffLHS() const
Definition: APValue.h:645
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:188
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
SourceManager & getSourceManager()
Definition: ASTContext.h:741
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1141
QualType getAtomicType(QualType T) const
Return the uniqued reference to the atomic type for the specified type.
QualType getParenType(QualType NamedType) const
QualType getRValueReferenceType(QualType T) const
Return the uniqued reference to the type for an rvalue reference to the specified type.
BuiltinTemplateDecl * getBuiltinCommonTypeDecl() const
BuiltinTemplateDecl * getMakeIntegerSeqDecl() const
void setInstantiatedFromUsingDecl(NamedDecl *Inst, NamedDecl *Pattern)
Remember that the using decl Inst is an instantiation of the using decl Pattern of a class template.
QualType getAutoType(QualType DeducedType, AutoTypeKeyword Keyword, bool IsDependent, bool IsPack=false, ConceptDecl *TypeConstraintConcept=nullptr, ArrayRef< TemplateArgument > TypeConstraintArgs={}) const
C++11 deduced auto type.
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getBlockPointerType(QualType T) const
Return the uniqued reference to the type for a block of the specified type.
QualType getTagDeclType(const TagDecl *Decl) const
Return the unique reference to the type for the specified TagDecl (struct/union/class/enum) decl.
QualType getMemberPointerType(QualType T, const Type *Cls) const
Return the uniqued reference to the type for a member pointer to the specified type in the specified ...
NamedDecl * getInstantiatedFromUsingDecl(NamedDecl *Inst)
If the given using decl Inst is an instantiation of another (possibly unresolved) using decl,...
DeclarationNameTable DeclarationNames
Definition: ASTContext.h:684
QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, QualType equivalentType, const Attr *attr=nullptr) const
QualType getTemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon=QualType()) const
QualType getRecordType(const RecordDecl *Decl) const
QualType getInjectedClassNameType(CXXRecordDecl *Decl, QualType TST) const
getInjectedClassNameType - Return the unique reference to the injected class name type for the specif...
QualType getVariableArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a variable array of the specified element type.
QualType getFunctionNoProtoType(QualType ResultTy, const FunctionType::ExtInfo &Info) const
Return a K&R style C function type like 'int()'.
QualType getArrayParameterType(QualType Ty) const
Return the uniqued reference to a specified array parameter type from the original array type.
QualType getCountAttributedType(QualType T, Expr *CountExpr, bool CountInBytes, bool OrNull, ArrayRef< TypeCoupledDeclRefInfo > DependentDecls) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2723
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2739
void setInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst, UsingShadowDecl *Pattern)
TemplateName getQualifiedTemplateName(NestedNameSpecifier *NNS, bool TemplateKeyword, TemplateName Template) const
Retrieve the template name that represents a qualified template name such as std::vector.
QualType getVectorType(QualType VectorType, unsigned NumElts, VectorKind VecKind) const
Return the unique reference to a vector type of the specified element type and size.
QualType getReadPipeType(QualType T) const
Return a read_only pipe type for the specified type.
QualType getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex, SubstTemplateTypeParmTypeFlag Flag=SubstTemplateTypeParmTypeFlag::None) const
Retrieve a substitution-result type.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1703
IdentifierTable & Idents
Definition: ASTContext.h:680
TemplateName getSubstTemplateTemplateParm(TemplateName replacement, Decl *AssociatedDecl, unsigned Index, std::optional< unsigned > PackIndex) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
SelectorTable & Selectors
Definition: ASTContext.h:681
QualType getMacroQualifiedType(QualType UnderlyingTy, const IdentifierInfo *MacroII) const
QualType getDecayedType(QualType T) const
Return the uniqued reference to the decayed version of the given type.
void setInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst, UsingEnumDecl *Pattern)
Remember that the using enum decl Inst is an instantiation of the using enum decl Pattern of a class ...
UsingEnumDecl * getInstantiatedFromUsingEnumDecl(UsingEnumDecl *Inst)
If the given using-enum decl Inst is an instantiation of another using-enum decl, return it.
QualType getDeducedTemplateSpecializationType(TemplateName Template, QualType DeducedType, bool IsDependent) const
C++17 deduced class template specialization type.
QualType getTemplateTypeParmType(unsigned Depth, unsigned Index, bool ParameterPack, TemplateTypeParmDecl *ParmDecl=nullptr) const
Retrieve the template type parameter type for a template parameter or parameter pack with the given d...
TypeSourceInfo * getTrivialTypeSourceInfo(QualType T, SourceLocation Loc=SourceLocation()) const
Allocate a TypeSourceInfo where all locations have been initialized to a given location,...
QualType getSubstTemplateTypeParmPackType(Decl *AssociatedDecl, unsigned Index, bool Final, const TemplateArgument &ArgPack)
Retrieve a.
CanQualType CharTy
Definition: ASTContext.h:1162
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
Definition: ASTContext.h:2296
QualType getElaboratedType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, QualType NamedType, TagDecl *OwnedTagDecl=nullptr) const
CanQualType SignedCharTy
Definition: ASTContext.h:1169
QualType getObjCObjectPointerType(QualType OIT) const
Return a ObjCObjectPointerType type for the given ObjCObjectType.
QualType getPackExpansionType(QualType Pattern, std::optional< unsigned > NumExpansions, bool ExpectPackInType=true) const
Form a pack expansion type with the given pattern.
QualType getObjCObjectType(QualType Base, ObjCProtocolDecl *const *Protocols, unsigned NumProtocols) const
Legacy interface: cannot provide type arguments or __kindof.
QualType getDependentSizedArrayType(QualType EltTy, Expr *NumElts, ArraySizeModifier ASM, unsigned IndexTypeQuals, SourceRange Brackets) const
Return a non-unique reference to the type for a dependently-sized array of the specified element type...
UsingShadowDecl * getInstantiatedFromUsingShadowDecl(UsingShadowDecl *Inst)
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
QualType getWritePipeType(QualType T) const
Return a write_only pipe type for the specified type.
CanQualType VoidTy
Definition: ASTContext.h:1160
CanQualType UnsignedCharTy
Definition: ASTContext.h:1170
TemplateName getDependentTemplateName(NestedNameSpecifier *NNS, const IdentifierInfo *Name) const
Retrieve the template name that represents a dependent template name such as MetaFun::template apply.
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1681
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, QualType Canon=QualType()) const
QualType getPackIndexingType(QualType Pattern, Expr *IndexExpr, bool FullySubstituted=false, ArrayRef< QualType > Expansions={}, int Index=-1) const
QualType getUnaryTransformType(QualType BaseType, QualType UnderlyingType, UnaryTransformType::UTTKind UKind) const
Unary type transforms.
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
DiagnosticsEngine & getDiagnostics() const
QualType getExtVectorType(QualType VectorType, unsigned NumElts) const
Return the unique reference to an extended vector type of the specified element type and size.
TemplateName getOverloadedTemplateName(UnresolvedSetIterator Begin, UnresolvedSetIterator End) const
Retrieve the template name that corresponds to a non-empty lookup.
TemplateName getSubstTemplateTemplateParmPack(const TemplateArgument &ArgPack, Decl *AssociatedDecl, unsigned Index, bool Final) const
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
Definition: ASTContext.h:1274
BuiltinTemplateDecl * getTypePackElementDecl() const
QualType getTypeOfType(QualType QT, TypeOfKind Kind) const
getTypeOfType - Unlike many "get<Type>" functions, we don't unique TypeOfType nodes.
CanQualType WCharTy
Definition: ASTContext.h:1163
QualType getDecltypeType(Expr *e, QualType UnderlyingType) const
C++11 decltype.
QualType getTypedefType(const TypedefNameDecl *Decl, QualType Underlying=QualType()) const
Return the unique reference to the type for the specified typedef-name decl.
unsigned char getFixedPointScale(QualType Ty) const
QualType getIncompleteArrayType(QualType EltTy, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return a unique reference to the type for an incomplete array of the specified element type.
QualType getDependentSizedExtVectorType(QualType VectorType, Expr *SizeExpr, SourceLocation AttrLoc) const
TemplateName getAssumedTemplateName(DeclarationName Name) const
Retrieve a template name representing an unqualified-id that has been assumed to name a template for ...
QualType getTypeOfExprType(Expr *E, TypeOfKind Kind) const
C23 feature and GCC extension.
std::error_code convertToErrorCode() const override
void log(llvm::raw_ostream &OS) const override
Definition: ASTImporter.cpp:99
std::string toString() const
Definition: ASTImporter.cpp:85
@ Unknown
Not supported node or case.
@ UnsupportedConstruct
Naming ambiguity (likely ODR violation).
void update(NamedDecl *ND, DeclContext *OldDC)
void updateForced(NamedDecl *ND, DeclContext *OldDC)
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
Definition: ASTImporter.h:165
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Definition: ASTImporter.h:179
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
Definition: ASTImporter.h:62
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Definition: ASTImporter.h:528
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
Definition: ASTImporter.h:543
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
Definition: ASTImporter.h:525
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
llvm::DenseSet< std::tuple< Decl *, Decl *, int > > NonEquivalentDeclSet
Definition: ASTImporter.h:66
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Definition: ASTImporter.h:270
std::optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
Definition: ASTImporter.h:371
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
std::optional< ASTImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
friend class ASTNodeImporter
Definition: ASTImporter.h:63
static std::optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Definition: ASTImporter.h:308
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
Definition: ASTImporter.h:568
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Definition: ASTImporter.h:553
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
virtual ~ASTImporter()
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
Definition: ASTImporter.h:298
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
Decl * GetAlreadyImportedOrNull(const Decl *FromD) const
Return the copy of the given declaration in the "to" context if it has already been imported from the...
void setImportDeclError(Decl *From, ASTImportError Error)
Mark (newly) imported declaration with error.
ExpectedDecl VisitObjCImplementationDecl(ObjCImplementationDecl *D)
ExpectedStmt VisitGenericSelectionExpr(GenericSelectionExpr *E)
ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E)
ExpectedDecl VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D)
ExpectedDecl VisitObjCInterfaceDecl(ObjCInterfaceDecl *D)
ExpectedStmt VisitDeclRefExpr(DeclRefExpr *E)
ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D)
ExpectedDecl VisitFunctionDecl(FunctionDecl *D)
ExpectedDecl VisitParmVarDecl(ParmVarDecl *D)
ExpectedStmt VisitImplicitValueInitExpr(ImplicitValueInitExpr *E)
ExpectedStmt VisitImplicitCastExpr(ImplicitCastExpr *E)
ExpectedDecl VisitCXXMethodDecl(CXXMethodDecl *D)
ExpectedDecl VisitUsingDecl(UsingDecl *D)
ExpectedDecl VisitObjCProtocolDecl(ObjCProtocolDecl *D)
ExpectedStmt VisitStmt(Stmt *S)
ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D)
ExpectedDecl VisitFieldDecl(FieldDecl *D)
Error ImportFieldDeclDefinition(const FieldDecl *From, const FieldDecl *To)
Error ImportDefinitionIfNeeded(Decl *FromD, Decl *ToD=nullptr)
ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E)
ExpectedStmt VisitCXXConstructExpr(CXXConstructExpr *E)
ExpectedStmt VisitObjCAtThrowStmt(ObjCAtThrowStmt *S)
ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D)
ExpectedStmt VisitShuffleVectorExpr(ShuffleVectorExpr *E)
ExpectedDecl VisitObjCPropertyDecl(ObjCPropertyDecl *D)
ExpectedDecl VisitRecordDecl(RecordDecl *D)
ExpectedStmt VisitDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E)
ExpectedDecl VisitUsingShadowDecl(UsingShadowDecl *D)
Error ImportArrayChecked(const InContainerTy &InContainer, OIter Obegin)
ExpectedStmt VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *S)
T importChecked(Error &Err, const T &From)
ExpectedStmt VisitVAArgExpr(VAArgExpr *E)
ExpectedStmt VisitDefaultStmt(DefaultStmt *S)
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D)
ExpectedStmt VisitCXXThrowExpr(CXXThrowExpr *E)
ExpectedDecl VisitLabelDecl(LabelDecl *D)
ExpectedStmt VisitSizeOfPackExpr(SizeOfPackExpr *E)
ExpectedStmt VisitObjCAtTryStmt(ObjCAtTryStmt *S)
ExpectedStmt VisitUnaryOperator(UnaryOperator *E)
Error ImportTemplateParameterLists(const DeclTy *FromD, DeclTy *ToD)
Error ImportDeclContext(DeclContext *FromDC, bool ForceImport=false)
ExpectedStmt VisitContinueStmt(ContinueStmt *S)
ExpectedStmt VisitCXXMemberCallExpr(CXXMemberCallExpr *E)
ExpectedDecl VisitVarDecl(VarDecl *D)
ExpectedStmt VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E)
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D)
Error ImportImplicitMethods(const CXXRecordDecl *From, CXXRecordDecl *To)
ExpectedStmt VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E)
ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E)
ExpectedDecl VisitLinkageSpecDecl(LinkageSpecDecl *D)
ExpectedDecl VisitCXXDestructorDecl(CXXDestructorDecl *D)
ExpectedStmt VisitCXXNamedCastExpr(CXXNamedCastExpr *E)
ExpectedStmt VisitOffsetOfExpr(OffsetOfExpr *OE)
ExpectedStmt VisitExprWithCleanups(ExprWithCleanups *E)
ExpectedDecl VisitIndirectFieldDecl(IndirectFieldDecl *D)
ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E)
ExpectedDecl VisitTypeAliasDecl(TypeAliasDecl *D)
Expected< InheritedConstructor > ImportInheritedConstructor(const InheritedConstructor &From)
ExpectedStmt VisitCXXNewExpr(CXXNewExpr *E)
Error ImportDeclParts(NamedDecl *D, DeclarationName &Name, NamedDecl *&ToD, SourceLocation &Loc)
Error ImportDefinition(RecordDecl *From, RecordDecl *To, ImportDefinitionKind Kind=IDK_Default)
ExpectedStmt VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S)
ExpectedStmt VisitConstantExpr(ConstantExpr *E)
ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E)
ExpectedStmt VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E)
ExpectedDecl VisitDecl(Decl *D)
bool hasSameVisibilityContextAndLinkage(T *Found, T *From)
ExpectedStmt VisitParenExpr(ParenExpr *E)
ExpectedStmt VisitObjCForCollectionStmt(ObjCForCollectionStmt *S)
ExpectedStmt VisitSourceLocExpr(SourceLocExpr *E)
ExpectedStmt VisitInitListExpr(InitListExpr *E)
Expected< FunctionTemplateAndArgsTy > ImportFunctionTemplateWithTemplateArgsFromSpecialization(FunctionDecl *FromFD)
ExpectedStmt VisitReturnStmt(ReturnStmt *S)
ExpectedStmt VisitAtomicExpr(AtomicExpr *E)
ExpectedStmt VisitConditionalOperator(ConditionalOperator *E)
ExpectedStmt VisitChooseExpr(ChooseExpr *E)
ExpectedStmt VisitCompoundStmt(CompoundStmt *S)
Expected< TemplateArgument > ImportTemplateArgument(const TemplateArgument &From)
ExpectedStmt VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *E)
ExpectedStmt VisitCaseStmt(CaseStmt *S)
ExpectedStmt VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E)
ExpectedStmt VisitDesignatedInitExpr(DesignatedInitExpr *E)
ExpectedDecl VisitObjCTypeParamDecl(ObjCTypeParamDecl *D)
ExpectedStmt VisitCompoundAssignOperator(CompoundAssignOperator *E)
ExpectedStmt VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E)
ExpectedStmt VisitLambdaExpr(LambdaExpr *LE)
ExpectedStmt VisitBinaryOperator(BinaryOperator *E)
ExpectedStmt VisitCallExpr(CallExpr *E)
ExpectedStmt VisitDeclStmt(DeclStmt *S)
ExpectedStmt VisitCXXDeleteExpr(CXXDeleteExpr *E)
ExpectedStmt VisitUnaryExprOrTypeTraitExpr(UnaryExprOrTypeTraitExpr *E)
Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin)
ExpectedDecl VisitClassTemplateDecl(ClassTemplateDecl *D)
ExpectedDecl VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D)
Expected< CXXCastPath > ImportCastPath(CastExpr *E)
Expected< APValue > ImportAPValue(const APValue &FromValue)
ExpectedDecl VisitFunctionTemplateDecl(FunctionTemplateDecl *D)
ExpectedStmt VisitGNUNullExpr(GNUNullExpr *E)
ExpectedDecl VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *D)
ExpectedStmt VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E)
ExpectedDecl VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D)
ExpectedDecl VisitTypedefNameDecl(TypedefNameDecl *D, bool IsAlias)
ExpectedDecl VisitCXXConstructorDecl(CXXConstructorDecl *D)
ExpectedDecl VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D)
ExpectedDecl VisitObjCIvarDecl(ObjCIvarDecl *D)
Expected< ObjCTypeParamList * > ImportObjCTypeParamList(ObjCTypeParamList *list)
ExpectedDecl VisitUsingPackDecl(UsingPackDecl *D)
ExpectedStmt VisitWhileStmt(WhileStmt *S)
ExpectedDecl VisitEnumConstantDecl(EnumConstantDecl *D)
ExpectedStmt VisitUnresolvedMemberExpr(UnresolvedMemberExpr *E)
ExpectedStmt VisitCXXForRangeStmt(CXXForRangeStmt *S)
ExpectedDecl VisitFriendDecl(FriendDecl *D)
Error ImportContainerChecked(const InContainerTy &InContainer, OutContainerTy &OutContainer)
ExpectedStmt VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *E)
ExpectedStmt VisitExpressionTraitExpr(ExpressionTraitExpr *E)
bool IsStructuralMatch(Decl *From, Decl *To, bool Complain=true, bool IgnoreTemplateParmDepth=false)
ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E)
ExpectedStmt VisitForStmt(ForStmt *S)
ExpectedStmt VisitUnresolvedLookupExpr(UnresolvedLookupExpr *E)
ExpectedDecl VisitEnumDecl(EnumDecl *D)
ExpectedDecl VisitObjCCategoryDecl(ObjCCategoryDecl *D)
ExpectedStmt VisitAddrLabelExpr(AddrLabelExpr *E)
ExpectedStmt VisitBinaryConditionalOperator(BinaryConditionalOperator *E)
ExpectedStmt VisitSwitchStmt(SwitchStmt *S)
ExpectedType VisitType(const Type *T)
ExpectedDecl VisitVarTemplateDecl(VarTemplateDecl *D)
ExpectedDecl ImportUsingShadowDecls(BaseUsingDecl *D, BaseUsingDecl *ToSI)
ExpectedStmt VisitPredefinedExpr(PredefinedExpr *E)
ExpectedStmt VisitOpaqueValueExpr(OpaqueValueExpr *E)
ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D)
ExpectedStmt VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E)
ExpectedDecl VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D)
ExpectedStmt VisitPackExpansionExpr(PackExpansionExpr *E)
ExpectedStmt VisitCXXUnresolvedConstructExpr(CXXUnresolvedConstructExpr *E)
ExpectedDecl VisitObjCMethodDecl(ObjCMethodDecl *D)
Error ImportTemplateArguments(ArrayRef< TemplateArgument > FromArgs, SmallVectorImpl< TemplateArgument > &ToArgs)
ExpectedDecl VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D)
ExpectedStmt VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *E)
ExpectedDecl VisitImplicitParamDecl(ImplicitParamDecl *D)
ExpectedDecl VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D)
ExpectedStmt VisitExplicitCastExpr(ExplicitCastExpr *E)
ExpectedStmt VisitArrayInitIndexExpr(ArrayInitIndexExpr *E)
Error ImportTemplateArgumentListInfo(const InContainerTy &Container, TemplateArgumentListInfo &ToTAInfo)
ExpectedStmt VisitDoStmt(DoStmt *S)
ExpectedStmt VisitNullStmt(NullStmt *S)
ExpectedStmt VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E)
ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
Error ImportOverriddenMethods(CXXMethodDecl *ToMethod, CXXMethodDecl *FromMethod)
ExpectedStmt VisitStringLiteral(StringLiteral *E)
Error ImportDeclarationNameLoc(const DeclarationNameInfo &From, DeclarationNameInfo &To)
ExpectedStmt VisitCXXDependentScopeMemberExpr(CXXDependentScopeMemberExpr *E)
bool hasReturnTypeDeclaredInside(FunctionDecl *D)
This function checks if the given function has a return type that contains a reference (in any way) t...
ASTNodeImporter(ASTImporter &Importer)
std::tuple< FunctionTemplateDecl *, TemplateArgsTy > FunctionTemplateAndArgsTy
ExpectedDecl VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D)
ExpectedStmt VisitMemberExpr(MemberExpr *E)
ExpectedStmt VisitCXXThisExpr(CXXThisExpr *E)
Error ImportInitializer(VarDecl *From, VarDecl *To)
ImportDefinitionKind
What we should import from the definition.
@ IDK_Everything
Import everything.
@ IDK_Default
Import the default subset of the definition, which might be nothing (if minimal import is set) or mig...
@ IDK_Basic
Import only the bare bones needed to establish a valid DeclContext.
ExpectedDecl VisitTypedefDecl(TypedefDecl *D)
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D)
ExpectedStmt VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E)
ExpectedDecl VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D)
ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E)
ExpectedStmt VisitIfStmt(IfStmt *S)
ExpectedStmt VisitLabelStmt(LabelStmt *S)
ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E)
ExpectedStmt VisitConvertVectorExpr(ConvertVectorExpr *E)
ExpectedDecl VisitUsingEnumDecl(UsingEnumDecl *D)
ExpectedStmt VisitGotoStmt(GotoStmt *S)
ExpectedStmt VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E)
ExpectedStmt VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S)
ExpectedStmt VisitGCCAsmStmt(GCCAsmStmt *S)
ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D)
ExpectedStmt VisitCXXTryStmt(CXXTryStmt *S)
ExpectedDecl VisitImportDecl(ImportDecl *D)
Error ImportFunctionDeclBody(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitArraySubscriptExpr(ArraySubscriptExpr *E)
ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E)
ExpectedDecl VisitEmptyDecl(EmptyDecl *D)
ExpectedStmt VisitCXXNoexceptExpr(CXXNoexceptExpr *E)
ExpectedStmt VisitExpr(Expr *E)
Error ImportDefaultArgOfParmVarDecl(const ParmVarDecl *FromParam, ParmVarDecl *ToParam)
ExpectedStmt VisitArrayInitLoopExpr(ArrayInitLoopExpr *E)
ExpectedStmt VisitCXXCatchStmt(CXXCatchStmt *S)
ExpectedStmt VisitAttributedStmt(AttributedStmt *S)
ExpectedStmt VisitIndirectGotoStmt(IndirectGotoStmt *S)
ExpectedStmt VisitParenListExpr(ParenListExpr *E)
Expected< FunctionDecl * > FindFunctionTemplateSpecialization(FunctionDecl *FromFD)
ExpectedDecl VisitCXXConversionDecl(CXXConversionDecl *D)
ExpectedStmt VisitObjCAtCatchStmt(ObjCAtCatchStmt *S)
Error ImportTemplateInformation(FunctionDecl *FromFD, FunctionDecl *ToFD)
ExpectedStmt VisitStmtExpr(StmtExpr *E)
ExpectedStmt VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E)
bool shouldForceImportDeclContext(ImportDefinitionKind IDK)
ExpectedDecl VisitBindingDecl(BindingDecl *D)
ExpectedStmt VisitBreakStmt(BreakStmt *S)
Represents an access specifier followed by colon ':'.
Definition: DeclCXX.h:86
AddrLabelExpr - The GNU address of label extension, representing &&label.
Definition: Expr.h:4421
Represents a type which was implicitly adjusted by the semantic engine for arbitrary reasons.
Definition: Type.h:3358
Represents the index of the current element of an array being initialized by an ArrayInitLoopExpr.
Definition: Expr.h:5805
Represents a loop initializing the elements of an array.
Definition: Expr.h:5752
Represents a constant array type that does not decay to a pointer when used as a function parameter.
Definition: Type.h:3748
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Definition: Expr.h:2718
An Embarcadero array type trait, as used in the implementation of __array_rank and __array_extent.
Definition: ExprCXX.h:2853
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition: Type.h:3578
QualType getElementType() const
Definition: Type.h:3590
A structure for storing the information associated with a name that has been assumed to be a template...
DeclarationName getDeclName() const
Get the name of the template.
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6678
Attr - This represents one attribute.
Definition: Attr.h:43
attr::Kind getKind() const
Definition: Attr.h:89
void setPackExpansion(bool PE)
Definition: Attr.h:105
Attr * clone(ASTContext &C) const
void setImplicit(bool I)
Definition: Attr.h:103
void setAttrName(const IdentifierInfo *AttrNameII)
const IdentifierInfo * getAttrName() const
Represents an attribute applied to a statement.
Definition: Stmt.h:2107
static AttributedStmt * Create(const ASTContext &C, SourceLocation Loc, ArrayRef< const Attr * > Attrs, Stmt *SubStmt)
Definition: Stmt.cpp:433
An attributed type is a type to which a type attribute has been applied.
Definition: Type.h:6133
Represents a C++11 auto or C++14 decltype(auto) type, possibly constrained by a type-constraint.
Definition: Type.h:6562
Represents a C++ declaration that introduces decls from somewhere else.
Definition: DeclCXX.h:3479
void addShadowDecl(UsingShadowDecl *S)
Definition: DeclCXX.cpp:3278
BinaryConditionalOperator - The GNU extension to the conditional operator which allows the middle ope...
Definition: Expr.h:4324
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3909
static BinaryOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures)
Definition: Expr.cpp:4901
A binding in a decomposition declaration.
Definition: DeclCXX.h:4169
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:4206
void setDecomposedDecl(ValueDecl *Decomposed)
Set the decomposed variable for this BindingDecl.
Definition: DeclCXX.h:4212
A fixed int type of a specified bitwidth.
Definition: Type.h:7820
Pointer to a block type.
Definition: Type.h:3409
BreakStmt - This represents a break.
Definition: Stmt.h:3007
Represents a C++2a __builtin_bit_cast(T, v) expression.
Definition: ExprCXX.h:5296
Represents the builtin template declaration which is used to implement __make_integer_seq and other b...
This class is used for builtin types like 'int'.
Definition: Type.h:3035
static CStyleCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *BasePath, FPOptionsOverride FPO, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation R)
Definition: Expr.cpp:2119
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
AccessSpecifier getAccessSpecifierAsWritten() const
Retrieves the access specifier as written in the source code (which may mean that no access specifier...
Definition: DeclCXX.h:242
SourceLocation getEllipsisLoc() const
For a pack expansion, determine the location of the ellipsis.
Definition: DeclCXX.h:221
bool isVirtual() const
Determines whether the base class is a virtual base class (or not).
Definition: DeclCXX.h:203
TypeSourceInfo * getTypeSourceInfo() const
Retrieves the type and source location of the base class.
Definition: DeclCXX.h:254
bool isBaseOfClass() const
Determine whether this base class is a base of a class declared with the 'class' keyword (vs.
Definition: DeclCXX.h:207
SourceRange getSourceRange() const LLVM_READONLY
Retrieves the source range that contains the entire base specifier.
Definition: DeclCXX.h:193
Represents binding an expression to a temporary.
Definition: ExprCXX.h:1491
static CXXBindTemporaryExpr * Create(const ASTContext &C, CXXTemporary *Temp, Expr *SubExpr)
Definition: ExprCXX.cpp:1097
A boolean literal, per ([C++ lex.bool] Boolean literals).
Definition: ExprCXX.h:720
static CXXBoolLiteralExpr * Create(const ASTContext &C, bool Val, QualType Ty, SourceLocation Loc)
Definition: ExprCXX.h:732
CXXCatchStmt - This represents a C++ catch block.
Definition: StmtCXX.h:28
static CXXConstCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, Expr *Op, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:875
Represents a call to a C++ constructor.
Definition: ExprCXX.h:1546
void setIsImmediateEscalating(bool Set)
Definition: ExprCXX.h:1708
static CXXConstructExpr * Create(const ASTContext &Ctx, QualType Ty, SourceLocation Loc, CXXConstructorDecl *Ctor, bool Elidable, ArrayRef< Expr * > Args, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization, CXXConstructionKind ConstructKind, SourceRange ParenOrBraceRange)
Create a C++ construction expression.
Definition: ExprCXX.cpp:1159
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2592
Represents a C++ conversion function within a class.
Definition: DeclCXX.h:2924
Represents a C++ base or member initializer.
Definition: DeclCXX.h:2357
FieldDecl * getMember() const
If this is a member initializer, returns the declaration of the non-static data member being initiali...
Definition: DeclCXX.h:2497
bool isDelegatingInitializer() const
Determine whether this initializer is creating a delegating constructor.
Definition: DeclCXX.h:2457
Expr * getInit() const
Get the initializer.
Definition: DeclCXX.h:2559
SourceLocation getRParenLoc() const
Definition: DeclCXX.h:2556
SourceLocation getEllipsisLoc() const
Definition: DeclCXX.h:2467
SourceLocation getLParenLoc() const
Definition: DeclCXX.h:2555
bool isPackExpansion() const
Determine whether this initializer is a pack expansion.
Definition: DeclCXX.h:2462
TypeSourceInfo * getTypeSourceInfo() const
Returns the declarator information for a base class or delegating initializer.
Definition: DeclCXX.h:2491
bool isMemberInitializer() const
Determine whether this initializer is initializing a non-static data member.
Definition: DeclCXX.h:2435
bool isBaseInitializer() const
Determine whether this initializer is initializing a base class.
Definition: DeclCXX.h:2429
bool isIndirectMemberInitializer() const
Definition: DeclCXX.h:2441
SourceLocation getMemberLocation() const
Definition: DeclCXX.h:2517
IndirectFieldDecl * getIndirectMember() const
Definition: DeclCXX.h:2511
bool isBaseVirtual() const
Returns whether the base is virtual or not.
Definition: DeclCXX.h:2483
Represents a C++ deduction guide declaration.
Definition: DeclCXX.h:1967
SourceDeductionGuideKind getSourceDeductionGuideKind() const
Definition: DeclCXX.h:2051
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1268
static CXXDefaultArgExpr * Create(const ASTContext &C, SourceLocation Loc, ParmVarDecl *Param, Expr *RewrittenExpr, DeclContext *UsedContext)
Definition: ExprCXX.cpp:1018
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1375
static CXXDefaultInitExpr * Create(const ASTContext &Ctx, SourceLocation Loc, FieldDecl *Field, DeclContext *UsedContext, Expr *RewrittenInitExpr)
Field is the non-static data member whose default initializer is used by this expression.
Definition: ExprCXX.cpp:1072
Represents a delete expression for memory deallocation and destructor calls, e.g.
Definition: ExprCXX.h:2498
Represents a C++ member access expression where the actual member referenced could not be resolved be...
Definition: ExprCXX.h:3683
static CXXDependentScopeMemberExpr * Create(const ASTContext &Ctx, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, NamedDecl *FirstQualifierFoundInScope, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:1533
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2856
void setOperatorDelete(FunctionDecl *OD, Expr *ThisArg)
Definition: DeclCXX.cpp:3007
static CXXDynamicCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:787
Represents a folding of a pack over an operator.
Definition: ExprCXX.h:4844
CXXForRangeStmt - This represents C++0x [stmt.ranged]'s ranged for statement, represented as 'for (ra...
Definition: StmtCXX.h:135
static CXXFunctionalCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, TypeSourceInfo *Written, CastKind Kind, Expr *Op, const CXXCastPath *Path, FPOptionsOverride FPO, SourceLocation LPLoc, SourceLocation RPLoc)
Definition: ExprCXX.cpp:901
Represents a call to an inherited base class constructor from an inheriting constructor.
Definition: ExprCXX.h:1737
Represents a call to a member function that may be written either with member call syntax (e....
Definition: ExprCXX.h:176
static CXXMemberCallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RP, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0)
Definition: ExprCXX.cpp:675
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2117
void addOverriddenMethod(const CXXMethodDecl *MD)
Definition: DeclCXX.cpp:2648
overridden_method_range overridden_methods() const
Definition: DeclCXX.cpp:2671
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclCXX.h:2213
Abstract class common to all of the C++ "named"/"keyword" casts.
Definition: ExprCXX.h:372
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Definition: ExprCXX.h:2241
static CXXNewExpr * Create(const ASTContext &Ctx, bool IsGlobalNew, FunctionDecl *OperatorNew, FunctionDecl *OperatorDelete, bool ShouldPassAlignment, bool UsualArrayDeleteWantsSize, ArrayRef< Expr * > PlacementArgs, SourceRange TypeIdParens, std::optional< Expr * > ArraySize, CXXNewInitializationStyle InitializationStyle, Expr *Initializer, QualType Ty, TypeSourceInfo *AllocatedTypeInfo, SourceRange Range, SourceRange DirectInitRange)
Create a c++ new expression.
Definition: ExprCXX.cpp:291
Represents a C++11 noexcept expression (C++ [expr.unary.noexcept]).
Definition: ExprCXX.h:4126
The null pointer literal (C++11 [lex.nullptr])
Definition: ExprCXX.h:765
static CXXOperatorCallExpr * Create(const ASTContext &Ctx, OverloadedOperatorKind OpKind, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation OperatorLoc, FPOptionsOverride FPFeatures, ADLCallKind UsesADL=NotADL)
Definition: ExprCXX.cpp:611
Represents a C++ pseudo-destructor (C++ [expr.pseudo]).
Definition: ExprCXX.h:2617
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CXXRecordDecl * getMostRecentDecl()
Definition: DeclCXX.h:541
CXXRecordDecl * getInstantiatedFromMemberClass() const
If this record is an instantiation of a member class, retrieves the member class from which it was in...
Definition: DeclCXX.cpp:1982
method_range methods() const
Definition: DeclCXX.h:662
CXXRecordDecl * getDefinition() const
Definition: DeclCXX.h:565
static CXXRecordDecl * CreateLambda(const ASTContext &C, DeclContext *DC, TypeSourceInfo *Info, SourceLocation Loc, unsigned DependencyKind, bool IsGeneric, LambdaCaptureDefault CaptureDefault)
Definition: DeclCXX.cpp:148
void setInstantiationOfMemberClass(CXXRecordDecl *RD, TemplateSpecializationKind TSK)
Specify that this record is an instantiation of the member class RD.
Definition: DeclCXX.cpp:1995
void setDescribedClassTemplate(ClassTemplateDecl *Template)
Definition: DeclCXX.cpp:2008
void setLambdaNumbering(LambdaNumbering Numbering)
Set the mangling numbers and context declaration for a lambda class.
Definition: DeclCXX.cpp:1797
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this class is an instantiation of a member class of a class template specialization,...
Definition: DeclCXX.cpp:1989
void setTemplateSpecializationKind(TemplateSpecializationKind TSK)
Set the kind of specialization or template instantiation this is.
Definition: DeclCXX.cpp:2023
CXXRecordDecl * getPreviousDecl()
Definition: DeclCXX.h:532
static CXXReinterpretCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind Kind, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *WrittenTy, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:852
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
An expression "T()" which creates an rvalue of a non-class type T.
Definition: ExprCXX.h:2182
static CXXStaticCastExpr * Create(const ASTContext &Context, QualType T, ExprValueKind VK, CastKind K, Expr *Op, const CXXCastPath *Path, TypeSourceInfo *Written, FPOptionsOverride FPO, SourceLocation L, SourceLocation RParenLoc, SourceRange AngleBrackets)
Definition: ExprCXX.cpp:761
Implicit construction of a std::initializer_list<T> object from an array temporary within list-initia...
Definition: ExprCXX.h:797
Represents a C++ functional cast expression that builds a temporary object.
Definition: ExprCXX.h:1885
static CXXTemporaryObjectExpr * Create(const ASTContext &Ctx, CXXConstructorDecl *Cons, QualType Ty, TypeSourceInfo *TSI, ArrayRef< Expr * > Args, SourceRange ParenOrBraceRange, bool HadMultipleCandidates, bool ListInitialization, bool StdInitListInitialization, bool ZeroInitialization)
Definition: ExprCXX.cpp:1125
Represents a C++ temporary.
Definition: ExprCXX.h:1457
static CXXTemporary * Create(const ASTContext &C, const CXXDestructorDecl *Destructor)
Definition: ExprCXX.cpp:1092
Represents the this expression in C++.
Definition: ExprCXX.h:1152
static CXXThisExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType Ty, bool IsImplicit)
Definition: ExprCXX.cpp:1568
A C++ throw-expression (C++ [except.throw]).
Definition: ExprCXX.h:1206
CXXTryStmt - A C++ try block, including all handlers.
Definition: StmtCXX.h:69
static CXXTryStmt * Create(const ASTContext &C, SourceLocation tryLoc, CompoundStmt *tryBlock, ArrayRef< Stmt * > handlers)
Definition: StmtCXX.cpp:25
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
Definition: ExprCXX.h:845
Describes an explicit type conversion that uses functional notion but could not be resolved because o...
Definition: ExprCXX.h:3557
static CXXUnresolvedConstructExpr * Create(const ASTContext &Context, QualType T, TypeSourceInfo *TSI, SourceLocation LParenLoc, ArrayRef< Expr * > Args, SourceLocation RParenLoc, bool IsListInit)
Definition: ExprCXX.cpp:1471
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2874
static CallExpr * Create(const ASTContext &Ctx, Expr *Fn, ArrayRef< Expr * > Args, QualType Ty, ExprValueKind VK, SourceLocation RParenLoc, FPOptionsOverride FPFeatures, unsigned MinNumArgs=0, ADLCallKind UsesADL=NotADL)
Create a call expression.
Definition: Expr.cpp:1498
CaseStmt - Represent a case statement.
Definition: Stmt.h:1828
static CaseStmt * Create(const ASTContext &Ctx, Expr *lhs, Expr *rhs, SourceLocation caseLoc, SourceLocation ellipsisLoc, SourceLocation colonLoc)
Build a case statement.
Definition: Stmt.cpp:1228
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3547
path_iterator path_begin()
Definition: Expr.h:3617
path_iterator path_end()
Definition: Expr.h:3618
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
How to handle import errors that occur when import of a child declaration of a DeclContext fails.
bool ignoreChildErrorOnParent(Decl *FromChildD) const
Determine if import failure of a child does not cause import failure of its parent.
ChildErrorHandlingStrategy(const Decl *FromD)
void handleChildImportResult(Error &ResultErr, Error &&ChildErr)
Process the import result of a child (of the current declaration).
ChildErrorHandlingStrategy(const DeclContext *FromDC)
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4641
Declaration of a class template.
void AddPartialSpecialization(ClassTemplatePartialSpecializationDecl *D, void *InsertPos)
Insert the specified partial specialization knowing that it is not already in.
ClassTemplateDecl * getMostRecentDecl()
CXXRecordDecl * getTemplatedDecl() const
Get the underlying class declarations of the template.
ClassTemplatePartialSpecializationDecl * findPartialSpecialization(ArrayRef< TemplateArgument > Args, TemplateParameterList *TPL, void *&InsertPos)
Return the partial specialization with the provided arguments if it exists, otherwise return the inse...
void AddSpecialization(ClassTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
QualType getInjectedClassNameSpecialization()
Retrieve the template specialization type of the injected-class-name for this class template.
ClassTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
ClassTemplatePartialSpecializationDecl * getInstantiatedFromMember() const
Retrieve the member class template partial specialization from which this particular class template p...
QualType getInjectedSpecializationType() const
Retrieves the injected specialization type for this partial specialization.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
Represents a class template specialization, which refers to a class template with a given set of temp...
void setPointOfInstantiation(SourceLocation Loc)
void setExternKeywordLoc(SourceLocation Loc)
Sets the location of the extern keyword.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setTemplateKeywordLoc(SourceLocation Loc)
Sets the location of the template keyword.
void setInstantiationOf(ClassTemplatePartialSpecializationDecl *PartialSpec, const TemplateArgumentList *TemplateArgs)
Note that this class template specialization is actually an instantiation of the given class template...
bool isExplicitInstantiationOrSpecialization() const
True if this declaration is an explicit specialization, explicit instantiation declaration,...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
Complex values, per C99 6.2.5p11.
Definition: Type.h:3146
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4171
static CompoundAssignOperator * Create(const ASTContext &C, Expr *lhs, Expr *rhs, Opcode opc, QualType ResTy, ExprValueKind VK, ExprObjectKind OK, SourceLocation opLoc, FPOptionsOverride FPFeatures, QualType CompLHSType=QualType(), QualType CompResultType=QualType())
Definition: Expr.cpp:4923
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3477
CompoundStmt - This represents a group of statements like { stmt stmt }.
Definition: Stmt.h:1628
static CompoundStmt * Create(const ASTContext &C, ArrayRef< Stmt * > Stmts, FPOptionsOverride FPFeatures, SourceLocation LB, SourceLocation RB)
Definition: Stmt.cpp:391
A reference to a concept and its template args, as it appears in the code.
Definition: ASTConcept.h:124
const NestedNameSpecifierLoc & getNestedNameSpecifierLoc() const
Definition: ASTConcept.h:163
NamedDecl * getFoundDecl() const
Definition: ASTConcept.h:195
const DeclarationNameInfo & getConceptNameInfo() const
Definition: ASTConcept.h:167
ConceptDecl * getNamedConcept() const
Definition: ASTConcept.h:199
static ConceptReference * Create(const ASTContext &C, NestedNameSpecifierLoc NNS, SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, NamedDecl *FoundDecl, ConceptDecl *NamedConcept, const ASTTemplateArgumentListInfo *ArgsAsWritten)
Definition: ASTConcept.cpp:87
const ASTTemplateArgumentListInfo * getTemplateArgsAsWritten() const
Definition: ASTConcept.h:203
SourceLocation getTemplateKWLoc() const
Definition: ASTConcept.h:173
ConditionalOperator - The ?: ternary operator.
Definition: Expr.h:4262
Represents the canonical version of C arrays with a specified constant size.
Definition: Type.h:3616
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1077
static ConstantExpr * Create(const ASTContext &Context, Expr *E, const APValue &Result)
Definition: Expr.cpp:349
Represents a concrete matrix type with constant number of rows and columns.
Definition: Type.h:4233
Represents a shadow constructor declaration introduced into a class by a C++11 using-declaration that...
Definition: DeclCXX.h:3660
ContinueStmt - This represents a continue.
Definition: Stmt.h:2977
ConvertVectorExpr - Clang builtin function __builtin_convertvector This AST node provides support for...
Definition: Expr.h:4582
Represents a sugar type with __counted_by or __sized_by annotations, including their _or_null variant...
Definition: Type.h:3307
Represents a pointer type decayed from an array or function type.
Definition: Type.h:3392
A POD class for pairing a NamedDecl* with an access specifier.
static DeclAccessPair make(NamedDecl *D, AccessSpecifier AS)
The results of name lookup within a DeclContext.
Definition: DeclBase.h:1372
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1439
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2104
void makeDeclVisibleInContext(NamedDecl *D)
Makes a declaration visible within this context.
Definition: DeclBase.cpp:2065
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1345
bool isNamespace() const
Definition: DeclBase.h:2193
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
Definition: DeclBase.cpp:1866
bool isRecord() const
Definition: DeclBase.h:2184
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2010
void addDeclInternal(Decl *D)
Add the declaration D into this context, but suppress searches for external declarations with the sam...
Definition: DeclBase.cpp:1788
bool containsDeclAndLoad(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1654
void removeDecl(Decl *D)
Removes a declaration from this context.
Definition: DeclBase.cpp:1699
lookup_result noload_lookup(DeclarationName Name)
Find the declarations with the given name that are visible within this context; don't attempt to retr...
Definition: DeclBase.cpp:1939
bool containsDecl(Decl *D) const
Checks whether a declaration is in this context.
Definition: DeclBase.cpp:1649
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
Definition: DeclBase.h:2364
bool isFunctionOrMethod() const
Definition: DeclBase.h:2156
void localUncachedLookup(DeclarationName Name, SmallVectorImpl< NamedDecl * > &Results)
A simplistic name lookup mechanism that performs name lookup into this declaration context without co...
Definition: DeclBase.cpp:1971
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition: DeclGroup.h:68
iterator begin()
Definition: DeclGroup.h:99
iterator end()
Definition: DeclGroup.h:105
bool isNull() const
Definition: DeclGroup.h:79
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1265
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
Definition: Expr.cpp:487
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Definition: Stmt.h:1519
A simple visitor class that helps create declaration visitors.
Definition: DeclVisitor.h:67
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclBase.h:438
TemplateDecl * getDescribedTemplate() const
If this is a declaration that describes some template, this method returns that template declaration.
Definition: DeclBase.cpp:266
FriendObjectKind getFriendObjectKind() const
Determines whether this declaration is the object of a friend declaration and, if so,...
Definition: DeclBase.h:1219
bool hasAttrs() const
Definition: DeclBase.h:521
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:528
void addAttr(Attr *A)
Definition: DeclBase.cpp:1019
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
Definition: DeclBase.h:596
bool isParameterPack() const
Whether this declaration is a parameter pack.
Definition: DeclBase.cpp:247
bool isInIdentifierNamespace(unsigned NS) const
Definition: DeclBase.h:886
@ FOK_None
Not a friend object.
Definition: DeclBase.h:1210
void setObjectOfFriendDecl(bool PerformFriendInjection=false)
Changes the namespace of this declaration to reflect that it's the object of a friend declaration.
Definition: DeclBase.h:1173
void setAccess(AccessSpecifier AS)
Definition: DeclBase.h:505
SourceLocation getLocation() const
Definition: DeclBase.h:442
const char * getDeclKindName() const
Definition: DeclBase.cpp:150
IdentifierNamespace
IdentifierNamespace - The different namespaces in which declarations may appear.
Definition: DeclBase.h:115
@ IDNS_NonMemberOperator
This declaration is a C++ operator declared in a non-class context.
Definition: DeclBase.h:168
@ IDNS_TagFriend
This declaration is a friend class.
Definition: DeclBase.h:157
@ IDNS_Ordinary
Ordinary names.
Definition: DeclBase.h:144
@ IDNS_ObjCProtocol
Objective C @protocol.
Definition: DeclBase.h:147
@ IDNS_Namespace
Namespaces, declared with 'namespace foo {}'.
Definition: DeclBase.h:140
@ IDNS_OrdinaryFriend
This declaration is a friend function.
Definition: DeclBase.h:152
@ IDNS_Tag
Tags, declared with 'struct foo;' and referenced with 'struct foo'.
Definition: DeclBase.h:125
void setImplicit(bool I=true)
Definition: DeclBase.h:597
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
Definition: DeclBase.h:1042
void setIsUsed()
Set whether the declaration is used, in the sense of odr-use.
Definition: DeclBase.h:611
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
Definition: DeclBase.cpp:557
DeclContext * getDeclContext()
Definition: DeclBase.h:451
AccessSpecifier getAccess() const
Definition: DeclBase.h:510
bool isInAnonymousNamespace() const
Definition: DeclBase.cpp:420
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclBase.h:434
TranslationUnitDecl * getTranslationUnitDecl()
Definition: DeclBase.cpp:513
AttrVec & getAttrs()
Definition: DeclBase.h:527
void setDeclContext(DeclContext *DC)
setDeclContext - Set both the semantic and lexical DeclContext to DC.
Definition: DeclBase.cpp:363
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
Definition: DeclBase.h:911
void setLexicalDeclContext(DeclContext *DC)
Definition: DeclBase.cpp:367
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:971
DeclarationName getCXXConversionFunctionName(CanQualType Ty)
Returns the name of a C++ conversion function for the given Type.
DeclarationName getCXXDestructorName(CanQualType Ty)
Returns the name of a C++ destructor for the given Type.
DeclarationName getCXXOperatorName(OverloadedOperatorKind Op)
Get the name of the overloadable C++ operator corresponding to Op.
DeclarationName getCXXDeductionGuideName(TemplateDecl *TD)
Returns the name of a C++ deduction guide for the given template.
DeclarationName getCXXConstructorName(CanQualType Ty)
Returns the name of a C++ constructor for the given Type.
DeclarationName getCXXLiteralOperatorName(const IdentifierInfo *II)
Get the name of the literal operator function with II as the identifier.
The name of a declaration.
IdentifierInfo * getAsIdentifierInfo() const
Retrieve the IdentifierInfo * stored in this declaration name, or null if this declaration name isn't...
TemplateDecl * getCXXDeductionGuideTemplate() const
If this name is the name of a C++ deduction guide, return the template associated with that name.
const IdentifierInfo * getCXXLiteralIdentifier() const
If this name is the name of a literal operator, retrieve the identifier associated with it.
static DeclarationName getUsingDirectiveName()
Returns the name for all C++ using-directives.
OverloadedOperatorKind getCXXOverloadedOperator() const
If this name is the name of an overloadable operator in C++ (e.g., operator+), retrieve the kind of o...
QualType getCXXNameType() const
If this name is one of the C++ names (of a constructor, destructor, or conversion function),...
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
NameKind getNameKind() const
Determine what kind of name this is.
bool isEmpty() const
Evaluates true when this declaration name is empty.
void setTypeSourceInfo(TypeSourceInfo *TI)
Definition: Decl.h:769
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:1989
Represents the type decltype(expr) (C++11).
Definition: Type.h:5880
A decomposition declaration.
Definition: DeclCXX.h:4228
Represents a C++17 deduced template specialization type.
Definition: Type.h:6610
Represents an extended address space qualifier where the input address space value is dependent.
Definition: Type.h:3921
Represents a qualified type name for which the type name is dependent.
Definition: Type.h:7030
A qualified reference to a name whose declaration cannot yet be resolved.
Definition: ExprCXX.h:3323
static DependentScopeDeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &NameInfo, const TemplateArgumentListInfo *TemplateArgs)
Definition: ExprCXX.cpp:531
Represents an array type in C++ whose size is a value-dependent expression.
Definition: Type.h:3863
Represents an extended vector type where either the type or size is dependent.
Definition: Type.h:3961
Represents a matrix type where the type and the number of rows and columns is dependent on a template...
Definition: Type.h:4292
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
OverloadedOperatorKind getOperator() const
Return the overloaded operator to which this template name refers.
Definition: TemplateName.h:620
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:607
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:604
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:610
Represents a template specialization type whose template cannot be resolved, e.g.
Definition: Type.h:7082
Represents a vector type where either the type or size is dependent.
Definition: Type.h:4087
Represents a single C99 designator.
Definition: Expr.h:5376
static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
Creates a GNU array-range designator.
Definition: Expr.h:5503
static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc)
Creates a field designator.
Definition: Expr.h:5457
static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc)
Creates an array designator.
Definition: Expr.h:5493
Represents a C99 designated initializer expression.
Definition: Expr.h:5333
static DesignatedInitExpr * Create(const ASTContext &C, llvm::ArrayRef< Designator > Designators, ArrayRef< Expr * > IndexExprs, SourceLocation EqualOrColonLoc, bool GNUSyntax, Expr *Init)
Definition: Expr.cpp:4633
A little helper class used to produce diagnostics.
Definition: Diagnostic.h:1224
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1497
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:923
DoStmt - This represents a 'do/while' stmt.
Definition: Stmt.h:2752
Symbolic representation of a dynamic allocation.
Definition: APValue.h:65
Represents a type that was referred to using an elaborated type keyword, e.g., struct S,...
Definition: Type.h:6949
Represents an empty-declaration.
Definition: Decl.h:5011
An instance of this object exists for each enum constant that is defined.
Definition: Decl.h:3291
Represents an enum.
Definition: Decl.h:3861
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4120
unsigned getNumNegativeBits() const
Returns the width in bits required to store all the negative enumerators of this enum.
Definition: Decl.h:4058
void setIntegerType(QualType T)
Set the underlying integer type.
Definition: Decl.h:4030
EnumDecl * getMostRecentDecl()
Definition: Decl.h:3957
void completeDefinition(QualType NewType, QualType PromotionType, unsigned NumPositiveBits, unsigned NumNegativeBits)
When created, the EnumDecl corresponds to a forward-declared enum.
Definition: Decl.cpp:4922
EnumDecl * getDefinition() const
Definition: Decl.h:3964
unsigned getNumPositiveBits() const
Returns the width in bits required to store all the non-negative enumerators of this enum.
Definition: Decl.h:4047
QualType getPromotionType() const
Return the integer type that enumerators should promote to.
Definition: Decl.h:4013
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:6104
ExplicitCastExpr - An explicit cast written in the source code.
Definition: Expr.h:3799
Store information needed for an explicit specifier.
Definition: DeclCXX.h:1912
ExplicitSpecKind getKind() const
Definition: DeclCXX.h:1920
const Expr * getExpr() const
Definition: DeclCXX.h:1921
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3474
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Definition: ExprCXX.h:3480
static ExprWithCleanups * Create(const ASTContext &C, EmptyShell empty, unsigned numObjects)
Definition: ExprCXX.cpp:1446
This represents one expression.
Definition: Expr.h:110
void setType(QualType t)
Definition: Expr.h:143
bool isValueDependent() const
Determines whether the value of this expression depends on.
Definition: Expr.h:175
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Definition: Expr.h:437
bool isTypeDependent() const
Determines whether the type of this expression depends on.
Definition: Expr.h:192
bool containsUnexpandedParameterPack() const
Whether this expression contains an unexpanded parameter pack (for C++11 variadic templates).
Definition: Expr.h:239
ExprObjectKind getObjectKind() const
getObjectKind - The object kind that this expression produces.
Definition: Expr.h:444
bool isInstantiationDependent() const
Whether this expression is instantiation-dependent, meaning that it depends in some way on.
Definition: Expr.h:221
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:276
QualType getType() const
Definition: Expr.h:142
ExprDependence getDependence() const
Definition: Expr.h:162
An expression trait intrinsic.
Definition: ExprCXX.h:2924
ExtVectorType - Extended vector type.
Definition: Type.h:4127
virtual void CompleteType(TagDecl *Tag)
Gives the external AST source an opportunity to complete an incomplete type.
Represents difference between two FPOptions values.
Definition: LangOptions.h:979
Represents a member of a struct/union/class.
Definition: Decl.h:3033
Expr * getInClassInitializer() const
Get the C++11 default member initializer for this member, or null if one has not been set.
Definition: Decl.cpp:4599
bool hasInClassInitializer() const
Determine whether this member has a C++11 default member initializer.
Definition: Decl.h:3208
void setInClassInitializer(Expr *NewInit)
Set the C++11 in-class initializer for this member.
Definition: Decl.cpp:4609
void setCapturedVLAType(const VariableArrayType *VLAType)
Set the captured variable length array type for this field.
Definition: Decl.cpp:4706
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isValid() const
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
OptionalFileEntryRef getOptionalFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Get a FileEntryRef if it exists, without doing anything on error.
Definition: FileManager.h:245
static FloatingLiteral * Create(const ASTContext &C, const llvm::APFloat &V, bool isexact, QualType Type, SourceLocation L)
Definition: Expr.cpp:1080
ForStmt - This represents a 'for (init;cond;inc)' stmt.
Definition: Stmt.h:2808
FriendDecl - Represents the declaration of a friend entity, which can be a function,...
Definition: DeclFriend.h:54
llvm::PointerUnion< NamedDecl *, TypeSourceInfo * > FriendUnion
Definition: DeclFriend.h:58
TypeSourceInfo * getFriendType() const
If this friend declaration names an (untemplated but possibly dependent) type, return the type; other...
Definition: DeclFriend.h:126
static DefaultedOrDeletedFunctionInfo * Create(ASTContext &Context, ArrayRef< DeclAccessPair > Lookups, StringLiteral *DeletedMessage=nullptr)
Definition: Decl.cpp:3103
Represents a function declaration or definition.
Definition: Decl.h:1935
Stmt * getBody(const FunctionDecl *&Definition) const
Retrieve the body (definition) of the function.
Definition: Decl.cpp:3243
void setDescribedFunctionTemplate(FunctionTemplateDecl *Template)
Definition: Decl.cpp:4072
FunctionTemplateDecl * getDescribedFunctionTemplate() const
Retrieves the function template that is described by this function declaration.
Definition: Decl.cpp:4067
void setIsPureVirtual(bool P=true)
Definition: Decl.cpp:3262
void setDefaultedOrDeletedInfo(DefaultedOrDeletedFunctionInfo *Info)
Definition: Decl.cpp:3124
void setFriendConstraintRefersToEnclosingTemplate(bool V=true)
Definition: Decl.h:2577
ArrayRef< ParmVarDecl * > parameters() const
Definition: Decl.h:2649
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4046
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
Definition: Decl.cpp:4197
void setDefaultLoc(SourceLocation NewLoc)
Definition: Decl.h:2330
DependentFunctionTemplateSpecializationInfo * getDependentSpecializationInfo() const
Definition: Decl.cpp:4263
@ TK_MemberSpecialization
Definition: Decl.h:1947
@ TK_DependentNonTemplate
Definition: Decl.h:1956
@ TK_FunctionTemplateSpecialization
Definition: Decl.h:1951
@ TK_DependentFunctionTemplateSpecialization
Definition: Decl.h:1954
void setTrivial(bool IT)
Definition: Decl.h:2306
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
Definition: Decl.cpp:4018
void setInstantiatedFromDecl(FunctionDecl *FD)
Specify that this function declaration was instantiated from a FunctionDecl FD.
Definition: Decl.cpp:4085
void setDependentTemplateSpecialization(ASTContext &Context, const UnresolvedSetImpl &Templates, const TemplateArgumentListInfo *TemplateArgs)
Specifies that this function declaration is actually a dependent function template specialization.
Definition: Decl.cpp:4252
void setVirtualAsWritten(bool V)
State that this function is marked as virtual explicitly.
Definition: Decl.h:2284
void setRangeEnd(SourceLocation E)
Definition: Decl.h:2153
FunctionDecl * getInstantiatedFromDecl() const
Definition: Decl.cpp:4091
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template instantiation this function represents.
Definition: Decl.cpp:4292
void setDefaulted(bool D=true)
Definition: Decl.h:2314
void setBody(Stmt *B)
Definition: Decl.cpp:3255
void setDeletedAsWritten(bool D=true, StringLiteral *Message=nullptr)
Definition: Decl.cpp:3133
void setExplicitlyDefaulted(bool ED=true)
State that this function is explicitly defaulted.
Definition: Decl.h:2322
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Definition: Decl.cpp:4039
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
Definition: Decl.cpp:3163
Represents a K&R-style 'int foo()' function, which has no information available about its arguments.
Definition: Type.h:4687
Represents a prototype with parameter type info, e.g.
Definition: Type.h:5108
QualType desugar() const
Definition: Type.h:5652
ExtProtoInfo getExtProtoInfo() const
Definition: Type.h:5372
ArrayRef< QualType > exceptions() const
Definition: Type.h:5531
ArrayRef< QualType > param_types() const
Definition: Type.h:5517
Declaration of a template function.
Definition: DeclTemplate.h:958
FunctionDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
FunctionDecl * getTemplatedDecl() const
Get the underlying function declaration of the template.
FunctionTemplateDecl * getMostRecentDecl()
ExtInfo getExtInfo() const
Definition: Type.h:4661
QualType getReturnType() const
Definition: Type.h:4649
This represents a GCC inline-assembly statement extension.
Definition: Stmt.h:3286
GNUNullExpr - Implements the GNU __null extension, which is a name for a null pointer constant that h...
Definition: Expr.h:4716
Represents a C11 generic selection.
Definition: Expr.h:5966
static GenericSelectionExpr * Create(const ASTContext &Context, SourceLocation GenericLoc, Expr *ControllingExpr, ArrayRef< TypeSourceInfo * > AssocTypes, ArrayRef< Expr * > AssocExprs, SourceLocation DefaultLoc, SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack, unsigned ResultIndex)
Create a non-result-dependent generic selection expression accepting an expression predicate.
Definition: Expr.cpp:4521
GotoStmt - This represents a direct goto.
Definition: Stmt.h:2889
One of these records is kept for each identifier that is lexed.
unsigned getBuiltinID() const
Return a value indicating whether this is a builtin function.
void setBuiltinID(unsigned ID)
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IfStmt - This represents an if/then/else.
Definition: Stmt.h:2165
static IfStmt * Create(const ASTContext &Ctx, SourceLocation IL, IfStatementKind Kind, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LPL, SourceLocation RPL, Stmt *Then, SourceLocation EL=SourceLocation(), Stmt *Else=nullptr)
Create an IfStmt.
Definition: Stmt.cpp:966
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1717
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3724
static ImplicitCastExpr * Create(const ASTContext &Context, QualType T, CastKind Kind, Expr *Operand, const CXXCastPath *BasePath, ExprValueKind Cat, FPOptionsOverride FPO)
Definition: Expr.cpp:2088
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5841
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Definition: Decl.h:4885
Represents a C array with an unspecified size.
Definition: Type.h:3765
Represents a field injected from an anonymous union/struct into the parent scope.
Definition: Decl.h:3335
IndirectGotoStmt - This represents an indirect goto.
Definition: Stmt.h:2928
Description of a constructor that was inherited from a base class.
Definition: DeclCXX.h:2563
CXXConstructorDecl * getConstructor() const
Definition: DeclCXX.h:2576
ConstructorUsingShadowDecl * getShadowDecl() const
Definition: DeclCXX.h:2575
Describes an C or C++ initializer list.
Definition: Expr.h:5088
void setSyntacticForm(InitListExpr *Init)
Definition: Expr.h:5258
void setArrayFiller(Expr *filler)
Definition: Expr.cpp:2442
void setInitializedFieldInUnion(FieldDecl *FD)
Definition: Expr.h:5213
void sawArrayRangeDesignator(bool ARD=true)
Definition: Expr.h:5268
The injected class name of a C++ class template or class template partial specialization.
Definition: Type.h:6799
static IntegerLiteral * Create(const ASTContext &C, const llvm::APInt &V, QualType type, SourceLocation l)
Returns a new integer literal with value 'V' and type 'type'.
Definition: Expr.cpp:979
An lvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3484
Represents the declaration of a label.
Definition: Decl.h:503
void setStmt(LabelStmt *T)
Definition: Decl.h:528
LabelStmt - Represents a label, which has a substatement.
Definition: Stmt.h:2058
Describes the capture of a variable or of this, or of a C++1y init-capture.
Definition: LambdaCapture.h:25
bool capturesVariable() const
Determine whether this capture handles a variable.
Definition: LambdaCapture.h:88
bool isPackExpansion() const
Determine whether this capture is a pack expansion, which captures a function parameter pack.
SourceLocation getEllipsisLoc() const
Retrieve the location of the ellipsis for a capture that is a pack expansion.
LambdaCaptureKind getCaptureKind() const
Determine the kind of capture.
Definition: ExprCXX.cpp:1245
ValueDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
bool isImplicit() const
Determine whether this was an implicit capture (not written between the square brackets introducing t...
SourceLocation getLocation() const
Retrieve the source location of the capture.
A C++ lambda expression, which produces a function object (of unspecified type) that can be invoked l...
Definition: ExprCXX.h:1954
static LambdaExpr * Create(const ASTContext &C, CXXRecordDecl *Class, SourceRange IntroducerRange, LambdaCaptureDefault CaptureDefault, SourceLocation CaptureDefaultLoc, bool ExplicitParams, bool ExplicitResultType, ArrayRef< Expr * > CaptureInits, SourceLocation ClosingBrace, bool ContainsUnexpandedParameterPack)
Construct a new lambda expression.
Definition: ExprCXX.cpp:1293
Implicit declaration of a temporary that was materialized by a MaterializeTemporaryExpr and lifetime-...
Definition: DeclCXX.h:3291
Represents a linkage specification.
Definition: DeclCXX.h:2996
void setRBraceLoc(SourceLocation L)
Definition: DeclCXX.h:3038
Represents the results of name lookup.
Definition: Lookup.h:46
iterator end() const
Definition: Lookup.h:359
iterator begin() const
Definition: Lookup.h:358
Sugar type that represents a type that was qualified by a qualifier written as a macro invocation.
Definition: Type.h:5771
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
Definition: ExprCXX.h:4732
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3236
static MemberExpr * Create(const ASTContext &C, Expr *Base, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *MemberDecl, DeclAccessPair FoundDecl, DeclarationNameInfo MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, QualType T, ExprValueKind VK, ExprObjectKind OK, NonOdrUseReason NOUR)
Definition: Expr.cpp:1768
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition: Type.h:3520
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:619
SourceLocation getPointOfInstantiation() const
Retrieve the first point of instantiation of this member.
Definition: DeclTemplate.h:659
void setPointOfInstantiation(SourceLocation POI)
Set the first point of instantiation.
Definition: DeclTemplate.h:664
This represents a decl that may have a name.
Definition: Decl.h:253
Linkage getLinkageInternal() const
Determine what kind of linkage this entity has.
Definition: Decl.cpp:1176
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Definition: Decl.h:319
Represents a C++ namespace alias.
Definition: DeclCXX.h:3182
Represent a C++ namespace.
Definition: Decl.h:551
NamespaceDecl * getAnonymousNamespace() const
Retrieve the anonymous namespace that inhabits this namespace, if any.
Definition: Decl.h:634
void setRBraceLoc(SourceLocation L)
Definition: Decl.h:653
Class that aids in the construction of nested-name-specifiers along with source-location information ...
A C++ nested-name-specifier augmented with source location information.
SourceLocation getLocalEndLoc() const
Retrieve the location of the end of this component of the nested-name-specifier.
TypeLoc getTypeLoc() const
For a nested-name-specifier that refers to a type, retrieve the type with source-location information...
NestedNameSpecifierLoc getPrefix() const
Return the prefix of this nested-name-specifier.
NestedNameSpecifier * getNestedNameSpecifier() const
Retrieve the nested-name-specifier to which this instance refers.
SourceLocation getLocalBeginLoc() const
Retrieve the location of the beginning of this component of the nested-name-specifier.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range covering the entirety of this nested-name-specifier.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
static NestedNameSpecifier * Create(const ASTContext &Context, NestedNameSpecifier *Prefix, const IdentifierInfo *II)
Builds a specifier combining a prefix and an identifier.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
static NestedNameSpecifier * GlobalSpecifier(const ASTContext &Context)
Returns the nested name specifier representing the global scope.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
SpecifierKind
The kind of specifier that completes this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
static NestedNameSpecifier * SuperSpecifier(const ASTContext &Context, CXXRecordDecl *RD)
Returns the nested name specifier representing the __super scope for the given CXXRecordDecl.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
NonTypeTemplateParmDecl - Declares a non-type template parameter, e.g., "Size" in.
NullStmt - This is the null statement ";": C99 6.8.3p3.
Definition: Stmt.h:1591
Represents Objective-C's @catch statement.
Definition: StmtObjC.h:77
Represents Objective-C's @finally statement.
Definition: StmtObjC.h:127
Represents Objective-C's @synchronized statement.
Definition: StmtObjC.h:303
Represents Objective-C's @throw statement.
Definition: StmtObjC.h:358
Represents Objective-C's @try ... @catch ... @finally statement.
Definition: StmtObjC.h:167
static ObjCAtTryStmt * Create(const ASTContext &Context, SourceLocation atTryLoc, Stmt *atTryStmt, Stmt **CatchStmts, unsigned NumCatchStmts, Stmt *atFinallyStmt)
Definition: StmtObjC.cpp:45
Represents Objective-C's @autoreleasepool Statement.
Definition: StmtObjC.h:394
An Objective-C "bridged" cast expression, which casts between Objective-C pointers and C pointers,...
Definition: ExprObjC.h:1632
ObjCCategoryDecl - Represents a category declaration.
Definition: DeclObjC.h:2328
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this category.
Definition: DeclObjC.cpp:2165
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2390
void setImplementation(ObjCCategoryImplDecl *ImplD)
Definition: DeclObjC.cpp:2161
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2399
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration.
Definition: DeclObjC.h:2544
Represents Objective-C's collection statement.
Definition: StmtObjC.h:23
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Definition: DeclObjC.h:2596
const ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.h:2734
Represents an ObjC class declaration.
Definition: DeclObjC.h:1153
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:1484
ObjCCategoryDecl * FindCategoryDeclaration(const IdentifierInfo *CategoryId) const
FindCategoryDeclaration - Finds category declaration in the list of categories for this class and ret...
Definition: DeclObjC.cpp:1746
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:1391
void setImplementation(ObjCImplementationDecl *ImplD)
Definition: DeclObjC.cpp:1640
known_categories_range known_categories() const
Definition: DeclObjC.h:1686
void setSuperClass(TypeSourceInfo *superClass)
Definition: DeclObjC.h:1587
protocol_iterator protocol_end() const
Definition: DeclObjC.h:1373
SourceLocation getSuperClassLoc() const
Retrieve the starting location of the superclass.
Definition: DeclObjC.cpp:370
void setTypeParamList(ObjCTypeParamList *TPL)
Set the type parameters of this class.
Definition: DeclObjC.cpp:341
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:1355
ObjCImplementationDecl * getImplementation() const
Definition: DeclObjC.cpp:1627
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:1362
void startDefinition()
Starts the definition of this Objective-C class, taking it from a forward declaration (@class) to a d...
Definition: DeclObjC.cpp:614
ObjCInterfaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this Objective-C class.
Definition: DeclObjC.h:1914
ObjCInterfaceDecl * getSuperClass() const
Definition: DeclObjC.cpp:350
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Definition: DeclObjC.h:1541
TypeSourceInfo * getSuperClassTInfo() const
Definition: DeclObjC.h:1572
Interfaces are the core concept in Objective-C for object oriented design.
Definition: Type.h:7530
ObjCIvarDecl - Represents an ObjC instance variable.
Definition: DeclObjC.h:1951
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:140
void setMethodParams(ASTContext &C, ArrayRef< ParmVarDecl * > Params, ArrayRef< SourceLocation > SelLocs={})
Sets the method's parameters and selector source locations.
Definition: DeclObjC.cpp:942
void createImplicitParams(ASTContext &Context, const ObjCInterfaceDecl *ID)
createImplicitParams - Used to lazily create the self and cmd implicit parameters.
Definition: DeclObjC.cpp:1188
ParmVarDecl *const * param_iterator
Definition: DeclObjC.h:350
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1209
Represents a pointer to an Objective C object.
Definition: Type.h:7586
Represents a class type in Objective C.
Definition: Type.h:7332
Represents one property declaration in an Objective-C interface.
Definition: DeclObjC.h:730
void setSetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:895
void setPropertyAttributes(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:818
void setPropertyAttributesAsWritten(ObjCPropertyAttribute::Kind PRVal)
Definition: DeclObjC.h:830
void setPropertyIvarDecl(ObjCIvarDecl *Ivar)
Definition: DeclObjC.h:919
void setSetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:904
void setGetterName(Selector Sel, SourceLocation Loc=SourceLocation())
Definition: DeclObjC.h:887
void setGetterMethodDecl(ObjCMethodDecl *gDecl)
Definition: DeclObjC.h:901
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
Definition: DeclObjC.h:2804
ObjCIvarDecl * getPropertyIvarDecl() const
Definition: DeclObjC.h:2878
SourceLocation getPropertyIvarDeclLoc() const
Definition: DeclObjC.h:2881
Kind getPropertyImplementation() const
Definition: DeclObjC.h:2874
Represents an Objective-C protocol declaration.
Definition: DeclObjC.h:2083
void setProtocolList(ObjCProtocolDecl *const *List, unsigned Num, const SourceLocation *Locs, ASTContext &C)
setProtocolList - Set the list of protocols that this interface implements.
Definition: DeclObjC.h:2208
ObjCProtocolDecl * getDefinition()
Retrieve the definition of this protocol, if any.
Definition: DeclObjC.h:2249
void startDefinition()
Starts the definition of this Objective-C protocol.
Definition: DeclObjC.cpp:2021
ObjCProtocolList::iterator protocol_iterator
Definition: DeclObjC.h:2157
protocol_iterator protocol_begin() const
Definition: DeclObjC.h:2164
protocol_iterator protocol_end() const
Definition: DeclObjC.h:2171
protocol_loc_iterator protocol_loc_begin() const
Definition: DeclObjC.h:2185
Represents the declaration of an Objective-C type parameter.
Definition: DeclObjC.h:578
Stores a list of Objective-C type parameters for a parameterized class or a category/extension thereo...
Definition: DeclObjC.h:659
SourceLocation getRAngleLoc() const
Definition: DeclObjC.h:710
static ObjCTypeParamList * create(ASTContext &ctx, SourceLocation lAngleLoc, ArrayRef< ObjCTypeParamDecl * > typeParams, SourceLocation rAngleLoc)
Create a new Objective-C type parameter list.
Definition: DeclObjC.cpp:1518
SourceLocation getLAngleLoc() const
Definition: DeclObjC.h:709
Represents a type parameter type in Objective C.
Definition: Type.h:7258
OffsetOfExpr - [C99 7.17] - This represents an expression of the form offsetof(record-type,...
Definition: Expr.h:2519
static OffsetOfExpr * Create(const ASTContext &C, QualType type, SourceLocation OperatorLoc, TypeSourceInfo *tsi, ArrayRef< OffsetOfNode > comps, ArrayRef< Expr * > exprs, SourceLocation RParenLoc)
Definition: Expr.cpp:1671
Helper class for OffsetOfExpr.
Definition: Expr.h:2413
unsigned getArrayExprIndex() const
For an array element node, returns the index into the array of expressions.
Definition: Expr.h:2471
FieldDecl * getField() const
For a field offsetof node, returns the field.
Definition: Expr.h:2477
IdentifierInfo * getFieldName() const
For a field or identifier offsetof node, returns the name of the field.
Definition: Expr.cpp:1706
@ Array
An index into an array.
Definition: Expr.h:2418
@ Identifier
A field in a dependent type, known only by its name.
Definition: Expr.h:2422
@ Field
A field.
Definition: Expr.h:2420
@ Base
An implicit indirection through a C++ base class, when the field found is in a base class.
Definition: Expr.h:2425
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Expr.h:2499
Kind getKind() const
Determine what kind of offsetof node this is.
Definition: Expr.h:2467
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Expr.h:2500
CXXBaseSpecifier * getBase() const
For a base class node, returns the base specifier.
Definition: Expr.h:2487
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1173
A structure for storing the information associated with an overloaded template name.
Definition: TemplateName.h:116
Represents a C++11 pack expansion that produces a sequence of expressions.
Definition: ExprCXX.h:4180
Represents a pack expansion of types.
Definition: Type.h:7147
ParenExpr - This represents a parenthesized expression, e.g.
Definition: Expr.h:2170
static ParenListExpr * Create(const ASTContext &Ctx, SourceLocation LParenLoc, ArrayRef< Expr * > Exprs, SourceLocation RParenLoc)
Create a paren list.
Definition: Expr.cpp:4773
Sugar for parentheses used when specifying types.
Definition: Type.h:3173
Represents a parameter to a function.
Definition: Decl.h:1725
bool isKNRPromoted() const
True if the value passed to this parameter must undergo K&R-style default argument promotion:
Definition: Decl.h:1806
void setObjCDeclQualifier(ObjCDeclQualifier QTVal)
Definition: Decl.h:1793
void setDefaultArg(Expr *defarg)
Definition: Decl.cpp:2987
SourceLocation getExplicitObjectParamThisLoc() const
Definition: Decl.h:1821
void setUnparsedDefaultArg()
Specify that this parameter has an unparsed default argument.
Definition: Decl.h:1866
bool hasUnparsedDefaultArg() const
Determines whether this parameter has a default argument that has not yet been parsed.
Definition: Decl.h:1854
void setUninstantiatedDefaultArg(Expr *arg)
Definition: Decl.cpp:3012
void setScopeInfo(unsigned scopeDepth, unsigned parameterIndex)
Definition: Decl.h:1758
bool hasUninstantiatedDefaultArg() const
Definition: Decl.h:1858
void setObjCMethodScopeInfo(unsigned parameterIndex)
Definition: Decl.h:1753
bool hasInheritedDefaultArg() const
Definition: Decl.h:1870
void setKNRPromoted(bool promoted)
Definition: Decl.h:1809
void setExplicitObjectParameterLoc(SourceLocation Loc)
Definition: Decl.h:1817
Expr * getDefaultArg()
Definition: Decl.cpp:2975
Expr * getUninstantiatedDefaultArg()
Definition: Decl.cpp:3017
bool hasDefaultArg() const
Determines whether this parameter has a default argument, either parsed or not.
Definition: Decl.cpp:3023
void setHasInheritedDefaultArg(bool I=true)
Definition: Decl.h:1874
PipeType - OpenCL20.
Definition: Type.h:7786
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition: Type.h:3199
[C99 6.4.2.2] - A predefined identifier such as func.
Definition: Expr.h:1991
static PredefinedExpr * Create(const ASTContext &Ctx, SourceLocation L, QualType FNTy, PredefinedIdentKind IK, bool IsTransparent, StringLiteral *SL)
Create a PredefinedExpr.
Definition: Expr.cpp:637
Stores the type being destroyed by a pseudo-destructor expression.
Definition: ExprCXX.h:2566
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7937
QualType getCanonicalType() const
Definition: Type.h:7989
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
Definition: Type.h:7969
Represents a template name as written in source code.
Definition: TemplateName.h:491
TemplateName getUnderlyingTemplate() const
Return the underlying template name.
Definition: TemplateName.h:526
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:519
bool hasTemplateKeyword() const
Whether the template name was prefixed by the "template" keyword.
Definition: TemplateName.h:523
An rvalue reference type, per C++11 [dcl.ref].
Definition: Type.h:3502
Represents a struct/union/class.
Definition: Decl.h:4162
bool isLambda() const
Determine whether this record is a class describing a lambda function object.
Definition: Decl.cpp:5085
void setAnonymousStructOrUnion(bool Anon)
Definition: Decl.h:4218
RecordDecl * getMostRecentDecl()
Definition: Decl.h:4188
virtual void completeDefinition()
Note that the definition of this type is now complete.
Definition: Decl.cpp:5126
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4361
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:6078
RecordDecl * getDecl() const
Definition: Type.h:6088
Provides common interface for the Decls that can be redeclared.
Definition: Redeclarable.h:84
decl_type * getPreviousDecl()
Return the previous declaration of this declaration or NULL if this is the first declaration.
Definition: Redeclarable.h:203
decl_type * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
Definition: Redeclarable.h:225
void setPreviousDecl(decl_type *PrevDecl)
Set the previous declaration.
Definition: Decl.h:5080
Base for LValueReferenceType and RValueReferenceType.
Definition: Type.h:3440
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
Definition: Stmt.h:3046
static ReturnStmt * Create(const ASTContext &Ctx, SourceLocation RL, Expr *E, const VarDecl *NRVOCandidate)
Create a return statement.
Definition: Stmt.cpp:1212
Selector getSelector(unsigned NumArgs, const IdentifierInfo **IIV)
Can create any sort of selector.
Smart pointer class that efficiently represents Objective-C method names.
const IdentifierInfo * getIdentifierInfoForSlot(unsigned argIndex) const
Retrieve the identifier at a given position in the selector.
bool isNull() const
Determine whether this is the empty selector.
unsigned getNumArgs() const
static std::enable_if_t< std::is_base_of_v< Attr, AttrInfo >, SourceLocation > getAttrLoc(const AttrInfo &AL)
A helper function to provide Attribute Location for the Attr types AND the ParsedAttr.
Definition: Sema.h:4413
ShuffleVectorExpr - clang-specific builtin-in function __builtin_shufflevector.
Definition: Expr.h:4514
Represents an expression that computes the length of a parameter pack.
Definition: ExprCXX.h:4258
static SizeOfPackExpr * Create(ASTContext &Context, SourceLocation OperatorLoc, NamedDecl *Pack, SourceLocation PackLoc, SourceLocation RParenLoc, std::optional< unsigned > Length=std::nullopt, ArrayRef< TemplateArgument > PartialArgs={})
Definition: ExprCXX.cpp:1693
Represents a function call to one of __builtin_LINE(), __builtin_COLUMN(), __builtin_FUNCTION(),...
Definition: Expr.h:4810
Encodes a location in the source.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
bool isWrittenInBuiltinFile(SourceLocation Loc) const
Returns whether Loc is located in a <built-in> file.
FileID createFileID(FileEntryRef SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
SourceLocation getComposedLoc(FileID FID, unsigned Offset) const
Form a SourceLocation from a FileID and Offset pair.
FileManager & getFileManager() const
FileID getMainFileID() const
Returns the FileID of the main source file.
unsigned getFileIDSize(FileID FID) const
The size of the SLocEntry that FID represents.
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
SourceLocation createExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned Length, bool ExpansionIsTokenRange=true, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Creates an expansion SLocEntry for a macro use.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation createMacroArgExpansionLoc(SourceLocation SpellingLoc, SourceLocation ExpansionLoc, unsigned Length)
Creates an expansion SLocEntry for the substitution of an argument into a function-like macro's body.
A trivial tuple used to represent a source range.
SourceLocation getEnd() const
SourceLocation getBegin() const
One instance of this struct is kept for every file loaded or used.
Each ExpansionInfo encodes the expansion location - where the token was ultimately expanded,...
SourceLocation getExpansionLocStart() const
SourceLocation getSpellingLoc() const
SourceLocation getExpansionLocEnd() const
const ContentCache & getContentCache() const
CharacteristicKind getFileCharacteristic() const
Return whether this is a system header or not.
SourceLocation getIncludeLoc() const
This is a discriminated union of FileInfo and ExpansionInfo.
const FileInfo & getFile() const
const ExpansionInfo & getExpansion() const
Represents a C++11 static_assert declaration.
Definition: DeclCXX.h:4120
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4466
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:186
Stmt - This represents one statement.
Definition: Stmt.h:84
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:358
child_iterator child_begin()
Definition: Stmt.h:1479
StmtClass getStmtClass() const
Definition: Stmt.h:1380
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition: Stmt.cpp:334
child_iterator child_end()
Definition: Stmt.h:1480
const char * getStmtClassName() const
Definition: Stmt.cpp:87
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:346
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1778
static StringLiteral * Create(const ASTContext &Ctx, StringRef Str, StringLiteralKind Kind, bool Pascal, QualType Ty, const SourceLocation *Loc, unsigned NumConcatenated)
This is the "fully general" constructor that allows representation of strings formed from multiple co...
Definition: Expr.cpp:1193
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4488
A structure for storing an already-substituted template template parameter pack.
Definition: TemplateName.h:149
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
TemplateArgument getArgumentPack() const
Retrieve the template template argument pack with which this parameter was substituted.
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:164
A structure for storing the information associated with a substituted template template parameter.
Definition: TemplateName.h:408
std::optional< unsigned > getPackIndex() const
Definition: TemplateName.h:432
unsigned getIndex() const
Returns the index of the replaced parameter in the associated declaration.
Definition: TemplateName.h:430
Decl * getAssociatedDecl() const
A template-like entity which owns the whole pattern being substituted.
Definition: TemplateName.h:426
Represents the result of substituting a set of types for a template type parameter pack.
Definition: Type.h:6470
Represents the result of substituting a type for a template type parameter.
Definition: Type.h:6389
void setNextSwitchCase(SwitchCase *SC)
Definition: Stmt.h:1803
SwitchStmt - This represents a 'switch' stmt.
Definition: Stmt.h:2415
static SwitchStmt * Create(const ASTContext &Ctx, Stmt *Init, VarDecl *Var, Expr *Cond, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a switch statement.
Definition: Stmt.cpp:1089
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3578
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3701
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3681
TypedefNameDecl * getTypedefNameForAnonDecl() const
Definition: Decl.h:3806
void startDefinition()
Starts the definition of this tag declaration.
Definition: Decl.cpp:4781
void setTypedefNameForAnonDecl(TypedefNameDecl *TDD)
Definition: Decl.cpp:4772
void setQualifierInfo(NestedNameSpecifierLoc QualifierLoc)
Definition: Decl.cpp:4827
void setBraceRange(SourceRange R)
Definition: Decl.h:3658
void setCompleteDefinition(bool V=true)
True if this decl has its body fully specified.
Definition: Decl.h:3684
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
SourceLocation getRAngleLoc() const
Definition: TemplateBase.h:648
void addArgument(const TemplateArgumentLoc &Loc)
Definition: TemplateBase.h:667
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
SourceLocation getLAngleLoc() const
Definition: TemplateBase.h:647
A template argument list.
Definition: DeclTemplate.h:250
static TemplateArgumentList * CreateCopy(ASTContext &Context, ArrayRef< TemplateArgument > Args)
Create a new template argument list that copies the given set of template arguments.
unsigned size() const
Retrieve the number of template arguments in this template argument list.
Definition: DeclTemplate.h:286
Location wrapper for a TemplateArgument.
Definition: TemplateBase.h:524
TemplateArgumentLocInfo getLocInfo() const
Definition: TemplateBase.h:576
const TemplateArgument & getArgument() const
Definition: TemplateBase.h:574
Represents a template argument.
Definition: TemplateBase.h:61
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Definition: TemplateBase.h:444
QualType getStructuralValueType() const
Get the type of a StructuralValue.
Definition: TemplateBase.h:399
QualType getParamTypeForDecl() const
Definition: TemplateBase.h:331
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Definition: TemplateBase.h:408
std::optional< unsigned > getNumTemplateExpansions() const
Retrieve the number of expansions that a template template argument expansion will produce,...
QualType getAsType() const
Retrieve the type for a type template argument.
Definition: TemplateBase.h:319
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
Definition: TemplateBase.h:337
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
Definition: TemplateBase.h:343
unsigned pack_size() const
The number of template arguments in the given template argument pack.
Definition: TemplateBase.h:438
QualType getIntegralType() const
Retrieve the type of the integral value.
Definition: TemplateBase.h:377
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
Definition: TemplateBase.h:393
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Definition: TemplateBase.h:326
ArrayRef< TemplateArgument > pack_elements() const
Iterator range referencing all of the elements of a template argument pack.
Definition: TemplateBase.h:432
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
Definition: TemplateBase.h:74
@ Template
The template argument is a template name that was provided for a template template parameter.
Definition: TemplateBase.h:93
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
Definition: TemplateBase.h:89
@ Pack
The template argument is actually a parameter pack.
Definition: TemplateBase.h:107
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
Definition: TemplateBase.h:97
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Definition: TemplateBase.h:78
@ Type
The template argument is a type.
Definition: TemplateBase.h:70
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
Definition: TemplateBase.h:67
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
Definition: TemplateBase.h:82
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
Definition: TemplateBase.h:103
ArgKind getKind() const
Return the kind of stored template argument.
Definition: TemplateBase.h:295
TemplateName getAsTemplateOrTemplatePattern() const
Retrieve the template argument as a template name; if the argument is a pack expansion,...
Definition: TemplateBase.h:350
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
Definition: TemplateBase.h:396
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
QualifiedTemplateName * getAsQualifiedTemplateName() const
Retrieve the underlying qualified template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
NameKind getKind() const
@ UsingTemplate
A template name that refers to a template declaration found through a specific using shadow declarati...
Definition: TemplateName.h:265
@ OverloadedTemplate
A set of overloaded template declarations.
Definition: TemplateName.h:240
@ Template
A single template declaration.
Definition: TemplateName.h:237
@ DependentTemplate
A dependent template name that has not been resolved to a template (or set of templates).
Definition: TemplateName.h:252
@ SubstTemplateTemplateParm
A template template parameter that has been substituted for some other template name.
Definition: TemplateName.h:256
@ SubstTemplateTemplateParmPack
A template template parameter pack that has been substituted for a template template argument pack,...
Definition: TemplateName.h:261
@ DeducedTemplate
A template name that refers to another TemplateName with deduced default arguments.
Definition: TemplateName.h:269
@ QualifiedTemplate
A qualified template name, where the qualification is kept to describe the source code as written.
Definition: TemplateName.h:248
@ AssumedTemplate
An unqualified-id that has been assumed to name a function template that will be found by ADL.
Definition: TemplateName.h:244
UsingShadowDecl * getAsUsingShadowDecl() const
Retrieve the using shadow declaration through which the underlying template declaration is introduced...
SubstTemplateTemplateParmPackStorage * getAsSubstTemplateTemplateParmPack() const
Retrieve the substituted template template parameter pack, if known.
SubstTemplateTemplateParmStorage * getAsSubstTemplateTemplateParm() const
Retrieve the substituted template template parameter, if known.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
NamedDecl * getParam(unsigned Idx)
Definition: DeclTemplate.h:147
static TemplateParameterList * Create(const ASTContext &C, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl * > Params, SourceLocation RAngleLoc, Expr *RequiresClause)
Expr * getRequiresClause()
The constraint-expression of the associated requires-clause.
Definition: DeclTemplate.h:183
SourceLocation getRAngleLoc() const
Definition: DeclTemplate.h:207
SourceLocation getLAngleLoc() const
Definition: DeclTemplate.h:206
SourceLocation getTemplateLoc() const
Definition: DeclTemplate.h:205
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6667
TemplateTemplateParmDecl - Declares a template template parameter, e.g., "T" in.
Declaration of a template type parameter.
void setTypeConstraint(ConceptReference *CR, Expr *ImmediatelyDeclaredConstraint)
The top declaration context.
Definition: Decl.h:84
Represents the declaration of a typedef-name via a C++11 alias-declaration.
Definition: Decl.h:3549
TypeAliasTemplateDecl * getDescribedAliasTemplate() const
Definition: Decl.h:3567
Declaration of an alias template.
Models the abbreviated syntax to constrain a template type parameter: template <convertible_to<string...
Definition: ASTConcept.h:227
[BoundsSafety] Represents information of declarations referenced by the arguments of the counted_by a...
Definition: Type.h:3227
void setTypeForDecl(const Type *TD)
Definition: Decl.h:3410
const Type * getTypeForDecl() const
Definition: Decl.h:3409
Symbolic representation of typeid(T) for some type T.
Definition: APValue.h:44
const Type * getType() const
Definition: APValue.h:51
SourceLocation getBeginLoc() const
Get the begin source location.
Definition: TypeLoc.cpp:192
Represents a typeof (or typeof) expression (a C23 feature and GCC extension) or a typeof_unqual expre...
Definition: Type.h:5803
Represents typeof(type), a C23 feature and GCC extension, or `typeof_unqual(type),...
Definition: Type.h:5853
The type-property cache.
Definition: Type.cpp:4499
A container of type source information.
Definition: Type.h:7908
TypeLoc getTypeLoc() const
Return the TypeLoc wrapper for the type source info.
Definition: TypeLoc.h:256
QualType getType() const
Return the type wrapped by this type source info.
Definition: Type.h:7919
A type trait used in the implementation of various C++11 and Library TR1 trait templates.
Definition: ExprCXX.h:2768
static TypeTraitExpr * Create(const ASTContext &C, QualType T, SourceLocation Loc, TypeTrait Kind, ArrayRef< TypeSourceInfo * > Args, SourceLocation RParenLoc, bool Value)
Create a new type trait expression.
Definition: ExprCXX.cpp:1876
An operation on a type.
Definition: TypeVisitor.h:64
ExpectedType Visit(const Type *T)
Performs the operation associated with this visitor object.
Definition: TypeVisitor.h:68
The base class of the type hierarchy.
Definition: Type.h:1828
const Type * getPointeeOrArrayElementType() const
If this is a pointer type, return the pointee type.
Definition: Type.h:8698
bool isArrayType() const
Definition: Type.h:8264
bool isPointerType() const
Definition: Type.h:8192
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition: Type.cpp:738
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2707
QualType getCanonicalTypeInternal() const
Definition: Type.h:2990
const char * getTypeClassName() const
Definition: Type.cpp:3316
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
Definition: Type.h:8691
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2396
bool isCanonicalUnqualified() const
Determines if this type would be canonical if it had no further qualification.
Definition: Type.h:2367
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8741
bool isRecordType() const
Definition: Type.h:8292
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition: Type.cpp:1920
Represents the declaration of a typedef-name via the 'typedef' type specifier.
Definition: Decl.h:3528
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3427
UnaryExprOrTypeTraitExpr - expression with either a type or (unevaluated) expression operand.
Definition: Expr.h:2622
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2232
static UnaryOperator * CreateEmpty(const ASTContext &C, bool hasFPFeatures)
Definition: Expr.cpp:4937
A unary type transform, which is a type constructed from another.
Definition: Type.h:5995
A reference to a name which we were able to look up during parsing but could not resolve to a specifi...
Definition: ExprCXX.h:3203
static UnresolvedLookupExpr * Create(const ASTContext &Context, CXXRecordDecl *NamingClass, NestedNameSpecifierLoc QualifierLoc, const DeclarationNameInfo &NameInfo, bool RequiresADL, UnresolvedSetIterator Begin, UnresolvedSetIterator End, bool KnownDependent, bool KnownInstantiationDependent)
Definition: ExprCXX.cpp:419
Represents a C++ member access expression for which lookup produced a set of overloaded functions.
Definition: ExprCXX.h:3943
static UnresolvedMemberExpr * Create(const ASTContext &Context, bool HasUnresolvedUsing, Expr *Base, QualType BaseType, bool IsArrow, SourceLocation OperatorLoc, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, const DeclarationNameInfo &MemberNameInfo, const TemplateArgumentListInfo *TemplateArgs, UnresolvedSetIterator Begin, UnresolvedSetIterator End)
Definition: ExprCXX.cpp:1635
void addDecl(NamedDecl *D)
Definition: UnresolvedSet.h:91
A set of unresolved declarations.
Represents the dependent type named by a dependently-scoped typename using declaration,...
Definition: Type.h:5673
Represents a dependent using declaration which was marked with typename.
Definition: DeclCXX.h:4021
Represents a dependent using declaration which was not marked with typename.
Definition: DeclCXX.h:3924
Represents a C++ using-declaration.
Definition: DeclCXX.h:3574
Represents C++ using-directive.
Definition: DeclCXX.h:3077
Represents a C++ using-enum-declaration.
Definition: DeclCXX.h:3775
Represents a pack of using declarations that a single using-declarator pack-expanded into.
Definition: DeclCXX.h:3856
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
Definition: DeclCXX.h:3382
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4750
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition: Decl.h:671
void setType(QualType newType)
Definition: Decl.h:683
QualType getType() const
Definition: Decl.h:682
Represents a variable declaration or definition.
Definition: Decl.h:882
void setInstantiationOfStaticDataMember(VarDecl *VD, TemplateSpecializationKind TSK)
Specify that this variable is an instantiation of the static data member VD.
Definition: Decl.cpp:2911
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
Definition: Decl.cpp:2355
EvaluatedStmt * getEvaluatedStmt() const
Definition: Decl.cpp:2543
EvaluatedStmt * ensureEvaluatedStmt() const
Convert the initializer for this declaration to the elaborated EvaluatedStmt form,...
Definition: Decl.cpp:2529
void setInlineSpecified()
Definition: Decl.h:1502
void setTSCSpec(ThreadStorageClassSpecifier TSC)
Definition: Decl.h:1124
const Expr * getInit() const
Definition: Decl.h:1319
void setConstexpr(bool IC)
Definition: Decl.h:1516
void setInit(Expr *I)
Definition: Decl.cpp:2449
void setDescribedVarTemplate(VarTemplateDecl *Template)
Definition: Decl.cpp:2791
void setImplicitlyInline()
Definition: Decl.h:1507
const Expr * getAnyInitializer() const
Get the initializer for this variable, no matter which declaration it is attached to.
Definition: Decl.h:1309
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this variable is an instantiation of a static data member of a class template specialization,...
Definition: Decl.cpp:2874
Declaration of a variable template.
VarDecl * getTemplatedDecl() const
Get the underlying variable declarations of the template.
void AddSpecialization(VarTemplateSpecializationDecl *D, void *InsertPos)
Insert the specified specialization knowing that it is not already in.
VarTemplateSpecializationDecl * findSpecialization(ArrayRef< TemplateArgument > Args, void *&InsertPos)
Return the specialization with the provided arguments if it exists, otherwise return the insertion po...
VarTemplateDecl * getMostRecentDecl()
void setInstantiatedFromMember(VarTemplatePartialSpecializationDecl *PartialSpec)
Represents a variable template specialization, which refers to a variable template with a given set o...
void setTemplateArgsAsWritten(const ASTTemplateArgumentListInfo *ArgsWritten)
Set the template argument list as written in the sources.
void setSpecializationKind(TemplateSpecializationKind TSK)
void setPointOfInstantiation(SourceLocation Loc)
VarTemplateSpecializationDecl * getMostRecentDecl()
Represents a C array with a specified size that is not an integer-constant-expression.
Definition: Type.h:3809
Represents a GCC generic vector type.
Definition: Type.h:4035
WhileStmt - This represents a 'while' stmt.
Definition: Stmt.h:2611
static WhileStmt * Create(const ASTContext &Ctx, VarDecl *Var, Expr *Cond, Stmt *Body, SourceLocation WL, SourceLocation LParenLoc, SourceLocation RParenLoc)
Create a while statement.
Definition: Stmt.cpp:1151
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
Definition: Address.h:328
StructuralEquivalenceKind
Whether to perform a normal or minimal equivalence check.
CanThrowResult
Possible results from evaluation of a noexcept expression.
ExprObjectKind
A further classification of the kind of object referenced by an l-value or x-value.
Definition: Specifiers.h:149
@ Property
The type of a property.
@ Result
The result type of a method or function.
@ BTK__type_pack_element
This names the __type_pack_element BuiltinTemplateDecl.
Definition: Builtins.h:313
@ BTK__builtin_common_type
This names the __builtin_common_type BuiltinTemplateDecl.
Definition: Builtins.h:316
@ BTK__make_integer_seq
This names the __make_integer_seq BuiltinTemplateDecl.
Definition: Builtins.h:310
CastKind
CastKind - The kind of operation required for a conversion.
ExprValueKind
The categorization of expression values, currently following the C++11 scheme.
Definition: Specifiers.h:132
const FunctionProtoType * T
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
bool declaresSameEntity(const Decl *D1, const Decl *D2)
Determine whether two declarations declare the same entity.
Definition: DeclBase.h:1278
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
Definition: Specifiers.h:188
bool isLambdaMethod(const DeclContext *DC)
Definition: ASTLambda.h:39
static void updateFlags(const Decl *From, Decl *To)
#define false
Definition: stdbool.h:26
Used as return type of getFriendCountAndPosition.
unsigned int IndexOfDecl
Index of the specific FriendDecl.
unsigned int TotalCount
Number of similar looking friends.
Represents an explicit template argument list in C++, e.g., the "<int>" in "sort<int>".
Definition: TemplateBase.h:676
static const ASTTemplateArgumentListInfo * Create(const ASTContext &C, const TemplateArgumentListInfo &List)
Information about how a lambda is numbered within its context.
Definition: DeclCXX.h:1813
DeclarationNameInfo - A collector data type for bundling together a DeclarationName and the correspon...
SourceLocation getLoc() const
getLoc - Returns the main location of the declaration name.
DeclarationName getName() const
getName - Returns the embedded declaration name.
void setCXXLiteralOperatorNameLoc(SourceLocation Loc)
setCXXLiteralOperatorNameLoc - Sets the location of the literal operator name (not the operator keywo...
void setNamedTypeInfo(TypeSourceInfo *TInfo)
setNamedTypeInfo - Sets the source type info associated to the name.
void setCXXOperatorNameRange(SourceRange R)
setCXXOperatorNameRange - Sets the range of the operator name (without the operator keyword).
SourceRange getCXXOperatorNameRange() const
getCXXOperatorNameRange - Gets the range of the operator name (without the operator keyword).
TypeSourceInfo * getNamedTypeInfo() const
getNamedTypeInfo - Returns the source type info associated to the name.
SourceLocation getCXXLiteralOperatorNameLoc() const
getCXXLiteralOperatorNameLoc - Returns the location of the literal operator name (not the operator ke...
Structure used to store a statement, the constant value to which it was evaluated (if any),...
Definition: Decl.h:847
bool HasConstantDestruction
Whether this variable is known to have constant destruction.
Definition: Decl.h:865
bool HasConstantInitialization
Whether this variable is known to have constant initialization.
Definition: Decl.h:858
FunctionDecl * SourceDecl
The function whose exception specification this is, for EST_Unevaluated and EST_Uninstantiated.
Definition: Type.h:5177
FunctionDecl * SourceTemplate
The function template whose exception specification this is instantiated from, for EST_Uninstantiated...
Definition: Type.h:5181
ExceptionSpecificationType Type
The kind of exception specification this is.
Definition: Type.h:5167
ArrayRef< QualType > Exceptions
Explicitly-specified list of exception types.
Definition: Type.h:5170
Expr * NoexceptExpr
Noexcept expression, if this is a computed noexcept specification.
Definition: Type.h:5173
Extra information about a function prototype.
Definition: Type.h:5193
ExceptionSpecInfo ExceptionSpec
Definition: Type.h:5200
FunctionType::ExtInfo ExtInfo
Definition: Type.h:5194
Location information for a TemplateArgument.
Definition: TemplateBase.h:472
SourceLocation getTemplateEllipsisLoc() const
Definition: TemplateBase.h:517
NestedNameSpecifierLoc getTemplateQualifierLoc() const
Definition: TemplateBase.h:507
TypeSourceInfo * getAsTypeSourceInfo() const
Definition: TemplateBase.h:501
SourceLocation getTemplateNameLoc() const
Definition: TemplateBase.h:513