Go to the documentation of this file.
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/Optional.h"
31 #include "llvm/ADT/SmallVector.h"
37 class ASTImporterSharedState;
39 class CXXBaseSpecifier;
40 class CXXCtorInitializer;
48 class 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 *, ImportError> 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 LLVM_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);
586 #endif // LLVM_CLANG_AST_ASTIMPORTER_H
DiagnosticBuilder ToDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "to" context.
llvm::Optional< DeclT * > getImportedFromDecl(const DeclT *ToD) const
Return the declaration in the "from" context from which the declaration in the "to" context was impor...
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...
bool hasCycleAtBack() const
Returns true if the last element can be found earlier in the path.
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.
A little helper class used to produce diagnostics.
A trivial tuple used to represent a source range.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Encodes a location in the source.
This represents a decl that may have a name.
A (possibly-)qualified type.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
llvm::Optional< ImportError > getImportDeclErrorIfAny(Decl *FromD) const
Return if import of the given declaration has failed and if yes the kind of the problem.
DiagnosticBuilder FromDiag(SourceLocation Loc, unsigned DiagID)
Report a diagnostic in the "from" context.
The name of a declaration.
llvm::Expected< DeclContext * > ImportContext(DeclContext *FromDC)
Import the given declaration context from the "from" AST context into the "to" AST context.
The base class of the type hierarchy.
VecTy copyCycleAtBack() const
Returns the copy of the cycle.
Cycle getCycleAtBack() const
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
ASTContext & getToContext() const
Retrieve the context that AST nodes are being imported into.
bool isMinimalImport() const
Whether the importer will perform a minimal import, creating to-be-completed forward declarations whe...
The top declaration context.
void setODRHandling(ODRHandlingType T)
virtual Decl * GetOriginalDecl(Decl *To)
Called by StructuralEquivalenceContext.
virtual Expected< Decl * > ImportImpl(Decl *From)
Can be overwritten by subclasses to implement their own import logic.
void RegisterImportedDecl(Decl *FromD, Decl *ToD)
LLVM_NODISCARD llvm::Error importInto(ImportT &To, const ImportT &From)
Import the given object, returns the result.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
llvm::PointerUnion< BlockDecl *, CompoundLiteralExpr * > CleanupObject
The type of objects that are kept in the cleanup.
Decl * MapImported(Decl *From, Decl *To)
Store and assign the imported declaration to its counterpart.
llvm::SmallVector< Decl *, 32 > VecTy
llvm::DenseSet< std::pair< Decl *, Decl * > > NonEquivalentDeclSet
A C++ nested-name-specifier augmented with source location information.
ASTImporter(ASTContext &ToContext, FileManager &ToFileManager, ASTContext &FromContext, FileManager &FromFileManager, bool MinimalImport, std::shared_ptr< ASTImporterSharedState > SharedState=nullptr)
TranslationUnitDecl * GetFromTU(Decl *ToD)
Return the translation unit from where the declaration was imported.
static llvm::Optional< unsigned > getFieldIndex(Decl *F)
Determine the index of a field in its parent record.
Imports selected nodes from one AST context into another context, merging AST nodes where appropriate...
virtual bool returnWithErrorInTest()
Used only in unittests to verify the behaviour of the error handling.
Represents a C++ template name within the type system.
ASTContext & getFromContext() const
Retrieve the context that AST nodes are being imported from.
Decl - This represents one declaration (or definition), e.g.
virtual void CompleteDecl(Decl *D)
Called for ObjCInterfaceDecl, ObjCProtocolDecl, and TagDecl.
One of these records is kept for each identifier that is lexed.
llvm::Expected< ExprWithCleanups::CleanupObject > Import(ExprWithCleanups::CleanupObject From)
Import cleanup objects owned by ExprWithCleanup.
llvm::SmallVector< Decl *, 2 > getCanonicalForwardRedeclChain(Decl *D)
virtual void Imported(Decl *From, Decl *To)
Subclasses can override this function to observe all of the From -> To declaration mappings as they a...
Implements support for file system lookup, file system caching, and directory search management.
Smart pointer class that efficiently represents Objective-C method names.
Stmt - This represents one statement.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a base class of a C++ class.
FileManager & getFromFileManager() const
Retrieve the file manager that AST nodes are being imported from.
Attr - This represents one attribute.
A container of type source information.
llvm::DenseMap< const CXXBaseSpecifier *, CXXBaseSpecifier * > ImportedCXXBaseSpecifierMap
Description of a constructor that was inherited from a base class.
llvm::iterator_range< VecTy::const_reverse_iterator > Cycle
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
llvm::Expected< const Decl * > Import(const Decl *FromD)
This represents one expression.
FileManager & getToFileManager() const
Retrieve the file manager that AST nodes are being imported into.
Represents a C++ base or member initializer.
bool IsStructurallyEquivalent(QualType From, QualType To, bool Complain=true)
Determine whether the given types are structurally equivalent.
void setImportDeclError(Decl *From, ImportError Error)
Mark (newly) imported declaration with error.
LLVM_NODISCARD llvm::Error ImportDefinition(Decl *From)
Import the definition of the given declaration, including all of the declarations it contains.
NonEquivalentDeclSet & getNonEquivalentDecls()
Return the set of declarations that we know are not equivalent.