clang API Documentation
Manages the set of modules loaded by an AST reader. More...
#include <ModuleManager.h>
Classes | |
struct | VisitState |
State used by the "visit" operation to avoid malloc traffic in calls to visit(). | |
Public Types | |
enum | AddModuleResult { AlreadyLoaded, NewlyLoaded, Missing, OutOfDate } |
The result of attempting to add a new module. More... | |
typedef SmallVectorImpl < ModuleFile * >::iterator | ModuleIterator |
typedef SmallVectorImpl < ModuleFile * > ::const_iterator | ModuleConstIterator |
typedef SmallVectorImpl < ModuleFile * > ::reverse_iterator | ModuleReverseIterator |
typedef std::pair< uint32_t, StringRef > | ModuleOffset |
Public Member Functions | |
ModuleManager (FileManager &FileMgr) | |
~ModuleManager () | |
ModuleIterator | begin () |
Forward iterator to traverse all loaded modules. This is reverse source-order. | |
ModuleIterator | end () |
Forward iterator end-point to traverse all loaded modules. | |
ModuleConstIterator | begin () const |
Const forward iterator to traverse all loaded modules. This is in reverse source-order. | |
ModuleConstIterator | end () const |
Const forward iterator end-point to traverse all loaded modules. | |
ModuleReverseIterator | rbegin () |
Reverse iterator to traverse all loaded modules. This is in source order. | |
ModuleReverseIterator | rend () |
Reverse iterator end-point to traverse all loaded modules. | |
ModuleFile & | getPrimaryModule () |
Returns the primary module associated with the manager, that is, the first module loaded. | |
ModuleFile & | getPrimaryModule () const |
Returns the primary module associated with the manager, that is, the first module loaded. | |
ModuleFile & | operator[] (unsigned Index) const |
Returns the module associated with the given index. | |
ModuleFile * | lookup (StringRef Name) |
Returns the module associated with the given name. | |
ModuleFile * | lookup (const FileEntry *File) |
Returns the module associated with the given module file. | |
std::unique_ptr < llvm::MemoryBuffer > | lookupBuffer (StringRef Name) |
Returns the in-memory (virtual file) buffer with the given name. | |
unsigned | size () const |
Number of modules loaded. | |
AddModuleResult | addModule (StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, unsigned Generation, off_t ExpectedSize, time_t ExpectedModTime, ASTFileSignature ExpectedSignature, std::function< ASTFileSignature(llvm::BitstreamReader &)> ReadSignature, ModuleFile *&Module, std::string &ErrorStr) |
Attempts to create a new module and add it to the list of known modules. | |
void | removeModules (ModuleIterator first, ModuleIterator last, llvm::SmallPtrSetImpl< ModuleFile * > &LoadedSuccessfully, ModuleMap *modMap) |
Remove the given set of modules. | |
void | addInMemoryBuffer (StringRef FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer) |
Add an in-memory buffer the list of known buffers. | |
void | setGlobalIndex (GlobalModuleIndex *Index) |
Set the global module index. | |
void | moduleFileAccepted (ModuleFile *MF) |
Notification from the AST reader that the given module file has been "accepted", and will not (can not) be unloaded. | |
void | visit (bool(*Visitor)(ModuleFile &M, void *UserData), void *UserData, llvm::SmallPtrSetImpl< ModuleFile * > *ModuleFilesHit=nullptr) |
Visit each of the modules. | |
void | visitDepthFirst (bool(*Visitor)(ModuleFile &M, bool Preorder, void *UserData), void *UserData) |
Visit each of the modules with a depth-first traversal. | |
bool | lookupModuleFile (StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, const FileEntry *&File) |
Attempt to resolve the given module file name to a file entry. | |
void | viewGraph () |
View the graphviz representation of the module graph. |
Manages the set of modules loaded by an AST reader.
Definition at line 31 of file ModuleManager.h.
typedef SmallVectorImpl<ModuleFile*>::const_iterator clang::serialization::ModuleManager::ModuleConstIterator |
Definition at line 102 of file ModuleManager.h.
typedef SmallVectorImpl<ModuleFile*>::iterator clang::serialization::ModuleManager::ModuleIterator |
Definition at line 101 of file ModuleManager.h.
typedef std::pair<uint32_t, StringRef> clang::serialization::ModuleManager::ModuleOffset |
Definition at line 104 of file ModuleManager.h.
typedef SmallVectorImpl<ModuleFile*>::reverse_iterator clang::serialization::ModuleManager::ModuleReverseIterator |
Definition at line 103 of file ModuleManager.h.
The result of attempting to add a new module.
Definition at line 151 of file ModuleManager.h.
ModuleManager::ModuleManager | ( | FileManager & | FileMgr | ) | [explicit] |
Definition at line 265 of file ModuleManager.cpp.
Definition at line 268 of file ModuleManager.cpp.
void ModuleManager::addInMemoryBuffer | ( | StringRef | FileName, |
std::unique_ptr< llvm::MemoryBuffer > | Buffer | ||
) |
Add an in-memory buffer the list of known buffers.
Definition at line 215 of file ModuleManager.cpp.
References clang::FileManager::getVirtualFile().
Referenced by clang::ASTReader::addInMemoryBuffer().
ModuleManager::AddModuleResult ModuleManager::addModule | ( | StringRef | FileName, |
ModuleKind | Type, | ||
SourceLocation | ImportLoc, | ||
ModuleFile * | ImportedBy, | ||
unsigned | Generation, | ||
off_t | ExpectedSize, | ||
time_t | ExpectedModTime, | ||
ASTFileSignature | ExpectedSignature, | ||
std::function< ASTFileSignature(llvm::BitstreamReader &)> | ReadSignature, | ||
ModuleFile *& | Module, | ||
std::string & | ErrorStr | ||
) |
Attempts to create a new module and add it to the list of known modules.
FileName | The file name of the module to be loaded. |
Type | The kind of module being loaded. |
ImportLoc | The location at which the module is imported. |
ImportedBy | The module that is importing this module, or NULL if this module is imported directly by the user. |
Generation | The generation in which this module was loaded. |
ExpectedSize | The expected size of the module file, used for validation. This will be zero if unknown. |
ExpectedModTime | The expected modification time of the module file, used for validation. This will be zero if unknown. |
ExpectedSignature | The expected signature of the module file, used for validation. This will be zero if unknown. |
ReadSignature | Reads the signature from an AST file without actually loading it. |
Module | A pointer to the module file if the module was successfully loaded. |
ErrorStr | Will be set to a non-empty string if any errors occurred while trying to load the module. |
Definition at line 56 of file ModuleManager.cpp.
References AlreadyLoaded, clang::serialization::ModuleFile::Buffer, clang::serialization::ModuleFile::DirectlyImported, clang::serialization::ModuleFile::File, clang::serialization::ModuleFile::FileName, clang::FileManager::getBufferForFile(), clang::vfs::Status::getLastModificationTime(), clang::FileManager::getNoncachedStatValue(), clang::serialization::ModuleFile::getTimestampFilename(), clang::serialization::ModuleFile::ImportedBy, clang::serialization::ModuleFile::ImportLoc, clang::serialization::ModuleFile::Imports, clang::serialization::ModuleFile::Index, clang::serialization::ModuleFile::InputFilesValidationTimestamp, clang::serialization::ModuleFile::Kind, lookupBuffer(), lookupModuleFile(), Missing, clang::serialization::MK_ImplicitModule, NewlyLoaded, OutOfDate, clang::serialization::ModuleFile::Signature, and clang::serialization::ModuleFile::StreamFile.
ModuleIterator clang::serialization::ModuleManager::begin | ( | ) | [inline] |
Forward iterator to traverse all loaded modules. This is reverse source-order.
Definition at line 111 of file ModuleManager.h.
Referenced by clang::ASTReader::getTotalNumPreprocessedEntities(), llvm::GraphTraits< ModuleManager >::nodes_begin(), and visit().
ModuleConstIterator clang::serialization::ModuleManager::begin | ( | ) | const [inline] |
Const forward iterator to traverse all loaded modules. This is in reverse source-order.
Definition at line 117 of file ModuleManager.h.
ModuleIterator clang::serialization::ModuleManager::end | ( | ) | [inline] |
Forward iterator end-point to traverse all loaded modules.
Definition at line 113 of file ModuleManager.h.
Referenced by clang::ASTReader::getTotalNumPreprocessedEntities(), llvm::GraphTraits< ModuleManager >::nodes_end(), and visit().
ModuleConstIterator clang::serialization::ModuleManager::end | ( | ) | const [inline] |
Const forward iterator end-point to traverse all loaded modules.
Definition at line 119 of file ModuleManager.h.
Returns the primary module associated with the manager, that is, the first module loaded.
Definition at line 129 of file ModuleManager.h.
Referenced by clang::ASTReader::getOriginalSourceFile().
ModuleFile& clang::serialization::ModuleManager::getPrimaryModule | ( | ) | const [inline] |
Returns the primary module associated with the manager, that is, the first module loaded.
Definition at line 133 of file ModuleManager.h.
ModuleFile * ModuleManager::lookup | ( | StringRef | Name | ) |
Returns the module associated with the given name.
Definition at line 30 of file ModuleManager.cpp.
References clang::FileManager::getFile().
ModuleFile * ModuleManager::lookup | ( | const FileEntry * | File | ) |
Returns the module associated with the given module file.
Definition at line 39 of file ModuleManager.cpp.
std::unique_ptr< llvm::MemoryBuffer > ModuleManager::lookupBuffer | ( | StringRef | Name | ) |
Returns the in-memory (virtual file) buffer with the given name.
Definition at line 49 of file ModuleManager.cpp.
References clang::FileManager::getFile().
Referenced by addModule().
bool ModuleManager::lookupModuleFile | ( | StringRef | FileName, |
off_t | ExpectedSize, | ||
time_t | ExpectedModTime, | ||
const FileEntry *& | File | ||
) |
Attempt to resolve the given module file name to a file entry.
FileName | The name of the module file. |
ExpectedSize | The size that the module file is expected to have. If the actual size differs, the resolver should return true . |
ExpectedModTime | The modification time that the module file is expected to have. If the actual modification time differs, the resolver should return true . |
File | Will be set to the file if there is one, or null otherwise. |
Definition at line 424 of file ModuleManager.cpp.
References clang::FileManager::getFile(), clang::FileEntry::getModificationTime(), and clang::FileEntry::getSize().
Referenced by addModule().
void ModuleManager::moduleFileAccepted | ( | ModuleFile * | MF | ) |
Notification from the AST reader that the given module file has been "accepted", and will not (can not) be unloaded.
Definition at line 258 of file ModuleManager.cpp.
References clang::GlobalModuleIndex::loadedModuleFile().
ModuleFile& clang::serialization::ModuleManager::operator[] | ( | unsigned | Index | ) | const [inline] |
Returns the module associated with the given index.
Definition at line 136 of file ModuleManager.h.
Reverse iterator to traverse all loaded modules. This is in source order.
Definition at line 123 of file ModuleManager.h.
Referenced by clang::PCHValidator::ReadDiagnosticOptions().
void ModuleManager::removeModules | ( | ModuleIterator | first, |
ModuleIterator | last, | ||
llvm::SmallPtrSetImpl< ModuleFile * > & | LoadedSuccessfully, | ||
ModuleMap * | modMap | ||
) |
Remove the given set of modules.
Definition at line 173 of file ModuleManager.cpp.
References clang::ModuleMap::findModule(), and clang::FileManager::invalidateCache().
Reverse iterator end-point to traverse all loaded modules.
Definition at line 125 of file ModuleManager.h.
void ModuleManager::setGlobalIndex | ( | GlobalModuleIndex * | Index | ) |
Set the global module index.
Definition at line 242 of file ModuleManager.cpp.
References clang::GlobalModuleIndex::loadedModuleFile().
unsigned clang::serialization::ModuleManager::size | ( | ) | const [inline] |
Number of modules loaded.
Definition at line 148 of file ModuleManager.h.
Referenced by clang::PCHValidator::ReadDiagnosticOptions(), visit(), and visitDepthFirst().
void ModuleManager::viewGraph | ( | ) |
View the graphviz representation of the module graph.
Definition at line 485 of file ModuleManager.cpp.
void ModuleManager::visit | ( | bool(*)(ModuleFile &M, void *UserData) | Visitor, |
void * | UserData, | ||
llvm::SmallPtrSetImpl< ModuleFile * > * | ModuleFilesHit = nullptr |
||
) |
Visit each of the modules.
This routine visits each of the modules, starting with the "root" modules that no other loaded modules depend on, and proceeding to the leaf modules, visiting each module only once during the traversal.
This traversal is intended to support various "lookup" operations that can find data in any of the loaded modules.
Visitor | A visitor function that will be invoked with each module and the given user data pointer. The return value must be convertible to bool; when false, the visitation continues to modules that the current module depends on. When true, the visitation skips any modules that the current module depends on. |
UserData | User data associated with the visitor object, which will be passed along to the visitor. |
ModuleFilesHit | If non-NULL, contains the set of module files that we know we need to visit because the global module index told us to. Any module that is known to both the global module index and the module manager that is *not* in this set can be skipped. |
Definition at line 275 of file ModuleManager.cpp.
References begin(), end(), clang::serialization::ModuleFile::Imports, clang::serialization::ModuleFile::Index, size(), and State.
Referenced by clang::ASTReader::ReadMethodPool().
void ModuleManager::visitDepthFirst | ( | bool(*)(ModuleFile &M, bool Preorder, void *UserData) | Visitor, |
void * | UserData | ||
) |
Visit each of the modules with a depth-first traversal.
This routine visits each of the modules known to the module manager using a depth-first search, starting with the first loaded module. The traversal invokes the callback both before traversing the children (preorder traversal) and after traversing the children (postorder traversal).
Visitor | A visitor function that will be invoked with each module and given a Preorder flag that indicates whether we're visiting the module before or after visiting its children. The visitor may return true at any time to abort the depth-first visitation. |
UserData | User data ssociated with the visitor object, which will be passed along to the user. |
Definition at line 410 of file ModuleManager.cpp.
References size().