clang  6.0.0svn
Classes | Public Types | Public Member Functions | List of all members
clang::serialization::ModuleManager Class Reference

Manages the set of modules loaded by an AST reader. More...

#include "clang/Serialization/ModuleManager.h"

Public Types

enum  AddModuleResult { AlreadyLoaded, NewlyLoaded, Missing, OutOfDate }
 The result of attempting to add a new module. More...
 
using ModuleIterator = llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::iterator >
 
using ModuleConstIterator = llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::const_iterator >
 
using ModuleReverseIterator = llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::reverse_iterator >
 
using ModuleOffset = std::pair< uint32_t, StringRef >
 
using ASTFileSignatureReader = ASTFileSignature(*)(StringRef)
 

Public Member Functions

 ModuleManager (FileManager &FileMgr, MemoryBufferCache &PCMCache, const PCHContainerReader &PCHContainerRdr, const HeaderSearch &HeaderSearchInfo)
 
 ~ModuleManager ()
 
ModuleIterator begin ()
 Forward iterator to traverse all loaded modules. More...
 
ModuleIterator end ()
 Forward iterator end-point to traverse all loaded modules. More...
 
ModuleConstIterator begin () const
 Const forward iterator to traverse all loaded modules. More...
 
ModuleConstIterator end () const
 Const forward iterator end-point to traverse all loaded modules. More...
 
ModuleReverseIterator rbegin ()
 Reverse iterator to traverse all loaded modules. More...
 
ModuleReverseIterator rend ()
 Reverse iterator end-point to traverse all loaded modules. More...
 
llvm::iterator_range< SmallVectorImpl< ModuleFile * >::const_iterator > pch_modules () const
 A range covering the PCH and preamble module files loaded. More...
 
ModuleFilegetPrimaryModule ()
 Returns the primary module associated with the manager, that is, the first module loaded. More...
 
ModuleFilegetPrimaryModule () const
 Returns the primary module associated with the manager, that is, the first module loaded. More...
 
ModuleFileoperator[] (unsigned Index) const
 Returns the module associated with the given index. More...
 
ModuleFilelookupByFileName (StringRef FileName) const
 Returns the module associated with the given file name. More...
 
ModuleFilelookupByModuleName (StringRef ModName) const
 Returns the module associated with the given module name. More...
 
ModuleFilelookup (const FileEntry *File) const
 Returns the module associated with the given module file. More...
 
std::unique_ptr< llvm::MemoryBuffer > lookupBuffer (StringRef Name)
 Returns the in-memory (virtual file) buffer with the given name. More...
 
unsigned size () const
 Number of modules loaded. More...
 
AddModuleResult addModule (StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, unsigned Generation, off_t ExpectedSize, time_t ExpectedModTime, ASTFileSignature ExpectedSignature, ASTFileSignatureReader ReadSignature, ModuleFile *&Module, std::string &ErrorStr)
 Attempts to create a new module and add it to the list of known modules. More...
 
void removeModules (ModuleIterator First, llvm::SmallPtrSetImpl< ModuleFile *> &LoadedSuccessfully, ModuleMap *modMap)
 Remove the modules starting from First (to the end). More...
 
void addInMemoryBuffer (StringRef FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
 Add an in-memory buffer the list of known buffers. More...
 
void setGlobalIndex (GlobalModuleIndex *Index)
 Set the global module index. More...
 
void moduleFileAccepted (ModuleFile *MF)
 Notification from the AST reader that the given module file has been "accepted", and will not (can not) be unloaded. More...
 
void visit (llvm::function_ref< bool(ModuleFile &M)> Visitor, llvm::SmallPtrSetImpl< ModuleFile *> *ModuleFilesHit=nullptr)
 Visit each of the modules. More...
 
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. More...
 
void viewGraph ()
 View the graphviz representation of the module graph. More...
 
MemoryBufferCachegetPCMCache () const
 

Detailed Description

Manages the set of modules loaded by an AST reader.

Definition at line 49 of file ModuleManager.h.

Member Typedef Documentation

◆ ASTFileSignatureReader

Definition at line 213 of file ModuleManager.h.

◆ ModuleConstIterator

using clang::serialization::ModuleManager::ModuleConstIterator = llvm::pointee_iterator< SmallVectorImpl<std::unique_ptr<ModuleFile> >::const_iterator>

Definition at line 138 of file ModuleManager.h.

◆ ModuleIterator

using clang::serialization::ModuleManager::ModuleIterator = llvm::pointee_iterator< SmallVectorImpl<std::unique_ptr<ModuleFile> >::iterator>

Definition at line 136 of file ModuleManager.h.

◆ ModuleOffset

using clang::serialization::ModuleManager::ModuleOffset = std::pair<uint32_t, StringRef>

Definition at line 141 of file ModuleManager.h.

◆ ModuleReverseIterator

using clang::serialization::ModuleManager::ModuleReverseIterator = llvm::pointee_iterator< SmallVectorImpl<std::unique_ptr<ModuleFile> >::reverse_iterator>

Definition at line 140 of file ModuleManager.h.

Member Enumeration Documentation

◆ AddModuleResult

The result of attempting to add a new module.

Enumerator
AlreadyLoaded 

The module file had already been loaded.

NewlyLoaded 

The module file was just loaded in response to this call.

Missing 

The module file is missing.

OutOfDate 

The module file is out-of-date.

Definition at line 199 of file ModuleManager.h.

Constructor & Destructor Documentation

◆ ModuleManager()

ModuleManager::ModuleManager ( FileManager FileMgr,
MemoryBufferCache PCMCache,
const PCHContainerReader PCHContainerRdr,
const HeaderSearch HeaderSearchInfo 
)
explicit

Definition at line 328 of file ModuleManager.cpp.

◆ ~ModuleManager()

ModuleManager::~ModuleManager ( )

Definition at line 334 of file ModuleManager.cpp.

Member Function Documentation

◆ addInMemoryBuffer()

void ModuleManager::addInMemoryBuffer ( StringRef  FileName,
std::unique_ptr< llvm::MemoryBuffer >  Buffer 
)

Add an in-memory buffer the list of known buffers.

Definition at line 281 of file ModuleManager.cpp.

◆ addModule()

ModuleManager::AddModuleResult ModuleManager::addModule ( StringRef  FileName,
ModuleKind  Type,
SourceLocation  ImportLoc,
ModuleFile ImportedBy,
unsigned  Generation,
off_t  ExpectedSize,
time_t  ExpectedModTime,
ASTFileSignature  ExpectedSignature,
ASTFileSignatureReader  ReadSignature,
ModuleFile *&  Module,
std::string &  ErrorStr 
)

Attempts to create a new module and add it to the list of known modules.

Parameters
FileNameThe file name of the module to be loaded.
TypeThe kind of module being loaded.
ImportLocThe location at which the module is imported.
ImportedByThe module that is importing this module, or NULL if this module is imported directly by the user.
GenerationThe generation in which this module was loaded.
ExpectedSizeThe expected size of the module file, used for validation. This will be zero if unknown.
ExpectedModTimeThe expected modification time of the module file, used for validation. This will be zero if unknown.
ExpectedSignatureThe expected signature of the module file, used for validation. This will be zero if unknown.
ReadSignatureReads the signature from an AST file without actually loading it.
ModuleA pointer to the module file if the module was successfully loaded.
ErrorStrWill be set to a non-empty string if any errors occurred while trying to load the module.
Returns
A pointer to the module that corresponds to this file name, and a value indicating whether the module was loaded.

Definition at line 102 of file ModuleManager.cpp.

◆ begin() [1/2]

ModuleIterator clang::serialization::ModuleManager::begin ( )
inline

Forward iterator to traverse all loaded modules.

Definition at line 149 of file ModuleManager.h.

Referenced by llvm::GraphTraits< ModuleManager >::nodes_begin().

◆ begin() [2/2]

ModuleConstIterator clang::serialization::ModuleManager::begin ( ) const
inline

Const forward iterator to traverse all loaded modules.

Definition at line 155 of file ModuleManager.h.

◆ end() [1/2]

ModuleIterator clang::serialization::ModuleManager::end ( )
inline

Forward iterator end-point to traverse all loaded modules.

Definition at line 152 of file ModuleManager.h.

Referenced by llvm::GraphTraits< ModuleManager >::nodes_end(), and removeModules().

◆ end() [2/2]

ModuleConstIterator clang::serialization::ModuleManager::end ( ) const
inline

Const forward iterator end-point to traverse all loaded modules.

Definition at line 158 of file ModuleManager.h.

◆ getPCMCache()

MemoryBufferCache& clang::serialization::ModuleManager::getPCMCache ( ) const
inline

Definition at line 321 of file ModuleManager.h.

◆ getPrimaryModule() [1/2]

ModuleFile& clang::serialization::ModuleManager::getPrimaryModule ( )
inline

Returns the primary module associated with the manager, that is, the first module loaded.

Definition at line 174 of file ModuleManager.h.

Referenced by clang::ASTReader::getOriginalSourceFile().

◆ getPrimaryModule() [2/2]

ModuleFile& clang::serialization::ModuleManager::getPrimaryModule ( ) const
inline

Returns the primary module associated with the manager, that is, the first module loaded.

Definition at line 178 of file ModuleManager.h.

◆ lookup()

ModuleFile * ModuleManager::lookup ( const FileEntry File) const

Returns the module associated with the given module file.

Definition at line 62 of file ModuleManager.cpp.

◆ lookupBuffer()

std::unique_ptr< llvm::MemoryBuffer > ModuleManager::lookupBuffer ( StringRef  Name)

Returns the in-memory (virtual file) buffer with the given name.

Definition at line 71 of file ModuleManager.cpp.

◆ lookupByFileName()

ModuleFile * ModuleManager::lookupByFileName ( StringRef  FileName) const

Returns the module associated with the given file name.

Definition at line 45 of file ModuleManager.cpp.

Referenced by operator[]().

◆ lookupByModuleName()

ModuleFile * ModuleManager::lookupByModuleName ( StringRef  ModName) const

Returns the module associated with the given module name.

Definition at line 54 of file ModuleManager.cpp.

◆ lookupModuleFile()

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.

Parameters
FileNameThe name of the module file.
ExpectedSizeThe size that the module file is expected to have. If the actual size differs, the resolver should return true.
ExpectedModTimeThe modification time that the module file is expected to have. If the actual modification time differs, the resolver should return true.
FileWill be set to the file if there is one, or null otherwise.
Returns
True if a file exists but does not meet the size/ modification time criteria, false if the file is either available and suitable, or is missing.

Definition at line 440 of file ModuleManager.cpp.

◆ moduleFileAccepted()

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 321 of file ModuleManager.cpp.

References clang::GlobalModuleIndex::loadedModuleFile().

◆ operator[]()

ModuleFile& clang::serialization::ModuleManager::operator[] ( unsigned  Index) const
inline

Returns the module associated with the given index.

Definition at line 181 of file ModuleManager.h.

References lookupByFileName().

◆ pch_modules()

llvm::iterator_range<SmallVectorImpl<ModuleFile *>::const_iterator> clang::serialization::ModuleManager::pch_modules ( ) const
inline

A range covering the PCH and preamble module files loaded.

Definition at line 168 of file ModuleManager.h.

◆ rbegin()

ModuleReverseIterator clang::serialization::ModuleManager::rbegin ( )
inline

Reverse iterator to traverse all loaded modules.

Definition at line 161 of file ModuleManager.h.

Referenced by getTopImportImplicitModule().

◆ removeModules()

void ModuleManager::removeModules ( ModuleIterator  First,
llvm::SmallPtrSetImpl< ModuleFile *> &  LoadedSuccessfully,
ModuleMap modMap 
)

Remove the modules starting from First (to the end).

Definition at line 217 of file ModuleManager.cpp.

References end(), and clang::Last.

◆ rend()

ModuleReverseIterator clang::serialization::ModuleManager::rend ( )
inline

Reverse iterator end-point to traverse all loaded modules.

Definition at line 164 of file ModuleManager.h.

◆ setGlobalIndex()

void ModuleManager::setGlobalIndex ( GlobalModuleIndex Index)

Set the global module index.

Definition at line 307 of file ModuleManager.cpp.

References clang::GlobalModuleIndex::loadedModuleFile().

◆ size()

unsigned clang::serialization::ModuleManager::size ( ) const
inline

Number of modules loaded.

Definition at line 196 of file ModuleManager.h.

Referenced by clang::PCHValidator::ReadDiagnosticOptions(), and visit().

◆ viewGraph()

void ModuleManager::viewGraph ( )

View the graphviz representation of the module graph.

Definition at line 504 of file ModuleManager.cpp.

◆ visit()

void ModuleManager::visit ( llvm::function_ref< bool(ModuleFile &M)>  Visitor,
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.

Parameters
VisitorA visitor function that will be invoked with each module. 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.
ModuleFilesHitIf 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 336 of file ModuleManager.cpp.

References clang::serialization::ModuleFile::ImportedBy, clang::serialization::ModuleFile::Imports, clang::serialization::ModuleFile::Index, size(), and State.


The documentation for this class was generated from the following files: