14#ifndef LLVM_CLANG_AST_ASTIMPORTER_H
15#define LLVM_CLANG_AST_ASTIMPORTER_H
28#include "llvm/ADT/DenseMap.h"
29#include "llvm/ADT/DenseSet.h"
30#include "llvm/ADT/SmallVector.h"
37class ASTImporterSharedState;
39class CXXBaseSpecifier;
40class CXXCtorInitializer;
48class TranslationUnitDecl;
67 llvm::DenseMap<const CXXBaseSpecifier *, CXXBaseSpecifier *>;
165 auto Pos = Aux.find(Nodes.back());
166 return Pos != Aux.end() && Pos->second > 1;
169 using Cycle = llvm::iterator_range<VecTy::const_reverse_iterator>;
171 assert(Nodes.size() >= 2);
172 return Cycle(Nodes.rbegin(),
173 std::find(Nodes.rbegin() + 1, Nodes.rend(), Nodes.back()) +
180 return VecTy(R.begin(), R.end());
189 llvm::SmallDenseMap<Decl *, int, 32> Aux;
193 std::shared_ptr<ASTImporterSharedState> SharedState =
nullptr;
196 ImportPathTy ImportPath;
200 using SavedImportPathsForOneDecl =
202 using SavedImportPathsTy =
203 llvm::SmallDenseMap<Decl *, SavedImportPathsForOneDecl, 32>;
204 SavedImportPathsTy SavedImportPaths;
218 bool LastDiagFromFrom =
false;
222 llvm::DenseMap<const Type *, const Type *> ImportedTypes;
226 llvm::DenseMap<Decl *, Decl *> ImportedDecls;
234 llvm::DenseMap<Decl *, ASTImportError> ImportDeclErrors;
238 llvm::DenseMap<Decl *, Decl *> ImportedFromDecls;
242 llvm::DenseMap<Stmt *, Stmt *> ImportedStmts;
246 llvm::DenseMap<FileID, FileID> ImportedFileIDs;
260 void AddToLookupTable(
Decl *ToD);
291 std::shared_ptr<ASTImporterSharedState> SharedState =
nullptr);
306 template <
typename ImportT>
307 [[nodiscard]] llvm::Error
importInto(ImportT &To,
const ImportT &From) {
308 auto ToOrErr =
Import(From);
311 return ToOrErr.takeError();
369 template <
typename DeclT>
371 auto FromI = ImportedFromDecls.find(ToD);
372 if (FromI == ImportedFromDecls.end())
374 auto *FromD = dyn_cast<DeclT>(FromI->second);
575 bool Complain =
true);
Defines the Diagnostic-related interfaces.
Defines the clang::Expr interface and subclasses for C++ expressions.
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 clang::SourceLocation class and associated facilities.
C Language Family Type Representation.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
llvm::iterator_range< VecTy::const_reverse_iterator > Cycle
Cycle getCycleAtBack() const
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
llvm::SmallVector< Decl *, 32 > VecTy
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
llvm::DenseSet< std::pair< Decl *, Decl * > > NonEquivalentDeclSet
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
llvm::Expected< const Decl * > Import(const Decl *FromD)
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
llvm::DenseMap< const CXXBaseSpecifier *, CXXBaseSpecifier * > ImportedCXXBaseSpecifierMap
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
virtual Expected< DeclarationName > HandleNameConflict(DeclarationName Name, DeclContext *DC, unsigned IDNS, NamedDecl **Decls, unsigned NumDecls)
Cope with a name conflict when importing a declaration into the given context.
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
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...
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.
FileManager & getToFileManager() const
Retrieve the file manager that AST nodes are being imported into.
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.
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
void setODRHandling(ODRHandlingType T)
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
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...
FileManager & getFromFileManager() const
Retrieve the file manager that AST nodes are being imported from.
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.
Attr - This represents one attribute.
Represents a base class of a C++ class.
Represents a C++ base or member initializer.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
The name of a declaration.
A little helper class used to produce diagnostics.
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
This represents one expression.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Implements support for file system lookup, file system caching, and directory search management.
One of these records is kept for each identifier that is lexed.
Description of a constructor that was inherited from a base class.
This represents a decl that may have a name.
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
A (possibly-)qualified type.
Smart pointer class that efficiently represents Objective-C method names.
Encodes a location in the source.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Represents a C++ template name within the type system.
The top declaration context.
A container of type source information.
The base class of the type hierarchy.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)