clang API Documentation

Public Types | Public Member Functions | Static Public Member Functions | Friends
clang::HeaderSearch Class Reference

#include <HeaderSearch.h>

List of all members.

Public Types

typedef std::vector
< DirectoryLookup >
::const_iterator 
search_dir_iterator

Public Member Functions

 HeaderSearch (FileManager &FM, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target)
 ~HeaderSearch ()
FileManagergetFileMgr () const
void SetSearchPaths (const std::vector< DirectoryLookup > &dirs, unsigned angledDirIdx, unsigned systemDirIdx, bool noCurDirSearch)
void AddSearchPath (const DirectoryLookup &dir, bool isAngled)
 AddSearchPath - Add an additional search path.
void setModuleCachePath (StringRef CachePath)
 Set the path to the module cache.
StringRef getModuleCachePath () const
 Retrieve the path to the module cache.
void ClearFileInfo ()
 ClearFileInfo - Forget everything we know about headers so far.
void SetExternalLookup (ExternalIdentifierLookup *EIL)
ExternalIdentifierLookupgetExternalLookup () const
void SetExternalSource (ExternalHeaderFileInfoSource *ES)
 Set the external source of header information.
void setTarget (const TargetInfo &Target)
 Set the target information for the header search, if not already known.
const FileEntryLookupFile (StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, const FileEntry *CurFileEnt, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module **SuggestedModule, bool SkipCache=false)
const FileEntryLookupSubframeworkHeader (StringRef Filename, const FileEntry *RelativeFileEnt, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath)
const DirectoryEntry *& LookupFrameworkCache (StringRef FWName)
bool ShouldEnterIncludeFile (const FileEntry *File, bool isImport)
SrcMgr::CharacteristicKind getFileDirFlavor (const FileEntry *File)
void MarkFileIncludeOnce (const FileEntry *File)
void MarkFileSystemHeader (const FileEntry *File)
void IncrementIncludeCount (const FileEntry *File)
void SetFileControllingMacro (const FileEntry *File, const IdentifierInfo *ControllingMacro)
bool isFileMultipleIncludeGuarded (const FileEntry *File)
 Determine whether this file is intended to be safe from multiple inclusions, e.g., it has #pragma once or a controlling macro.
const HeaderMapCreateHeaderMap (const FileEntry *FE)
std::string getModuleFileName (Module *Module)
 Retrieve the name of the module file that should be used to load the given module.
std::string getModuleFileName (StringRef ModuleName)
 Retrieve the name of the module file that should be used to load a module with the given name.
ModulelookupModule (StringRef ModuleName, bool AllowSearch=true)
 Lookup a module Search for a module with the given name.
void IncrementFrameworkLookupCount ()
bool hasModuleMap (StringRef Filename, const DirectoryEntry *Root)
 Determine whether there is a module map that may map the header with the given file name to a (sub)module.
ModulefindModuleForHeader (const FileEntry *File)
 Retrieve the module that corresponds to the given file, if any.
bool loadModuleMapFile (const FileEntry *File)
 Read the contents of the given module map file.
void collectAllModules (llvm::SmallVectorImpl< Module * > &Modules)
 Collect the set of all known, top-level modules.
ModuleMapgetModuleMap ()
 Retrieve the module map.
unsigned header_file_size () const
void setHeaderFileInfoForUID (HeaderFileInfo HFI, unsigned UID)
const HeaderFileInfogetFileInfo (const FileEntry *FE) const
search_dir_iterator search_dir_begin () const
search_dir_iterator search_dir_end () const
unsigned search_dir_size () const
search_dir_iterator quoted_dir_begin () const
search_dir_iterator quoted_dir_end () const
search_dir_iterator angled_dir_begin () const
search_dir_iterator angled_dir_end () const
search_dir_iterator system_dir_begin () const
search_dir_iterator system_dir_end () const
StringRef getUniqueFrameworkName (StringRef Framework)
 Retrieve a uniqued framework name.
void PrintStats ()
size_t getTotalMemory () const

Static Public Member Functions

static std::string NormalizeDashIncludePath (StringRef File, FileManager &FileMgr)
 Helper static function to normalize a path for injection into a synthetic header.

Friends

class DirectoryLookup

Detailed Description

HeaderSearch - This class encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.

Definition at line 121 of file HeaderSearch.h.


Member Typedef Documentation

typedef std::vector<DirectoryLookup>::const_iterator clang::HeaderSearch::search_dir_iterator

Definition at line 444 of file HeaderSearch.h.


Constructor & Destructor Documentation

HeaderSearch::HeaderSearch ( FileManager FM,
DiagnosticsEngine Diags,
const LangOptions LangOpts,
const TargetInfo Target 
)

Definition at line 41 of file HeaderSearch.cpp.

HeaderSearch::~HeaderSearch ( )

Definition at line 58 of file HeaderSearch.cpp.


Member Function Documentation

void clang::HeaderSearch::AddSearchPath ( const DirectoryLookup dir,
bool  isAngled 
) [inline]

AddSearchPath - Add an additional search path.

Definition at line 212 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::angled_dir_begin ( ) const [inline]

Definition at line 456 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::angled_dir_end ( ) const [inline]

Definition at line 459 of file HeaderSearch.h.

void clang::HeaderSearch::ClearFileInfo ( ) [inline]

ClearFileInfo - Forget everything we know about headers so far.

Definition at line 229 of file HeaderSearch.h.

void HeaderSearch::collectAllModules ( llvm::SmallVectorImpl< Module * > &  Modules)

Collect the set of all known, top-level modules.

Parameters:
ModulesWill be filled with the set of known, top-level modules.

Definition at line 961 of file HeaderSearch.cpp.

References clang::SrcMgr::C_User, clang::FileManager::getDirectory(), loadModuleMapFile(), clang::ModuleMap::module_begin(), and clang::ModuleMap::module_end().

const HeaderMap * HeaderSearch::CreateHeaderMap ( const FileEntry FE)

CreateHeaderMap - This method returns a HeaderMap for the specified FileEntry, uniquing them through the the 'HeaderMaps' datastructure.

Definition at line 88 of file HeaderSearch.cpp.

References clang::HeaderMap::Create().

Module * HeaderSearch::findModuleForHeader ( const FileEntry File)

Retrieve the module that corresponds to the given file, if any.

Parameters:
FileThe header that we wish to map to a module.

Definition at line 815 of file HeaderSearch.cpp.

References clang::ModuleMap::findModuleForHeader().

Referenced by clang::DirectoryLookup::LookupFile().

ExternalIdentifierLookup* clang::HeaderSearch::getExternalLookup ( ) const [inline]

Definition at line 237 of file HeaderSearch.h.

SrcMgr::CharacteristicKind clang::HeaderSearch::getFileDirFlavor ( const FileEntry File) [inline]

getFileDirFlavor - Return whether the specified file is a normal header, a system header, or a C++ friendly system header.

Definition at line 310 of file HeaderSearch.h.

References clang::HeaderFileInfo::DirInfo, and getFileInfo().

const HeaderFileInfo& clang::HeaderSearch::getFileInfo ( const FileEntry FE) const [inline]
FileManager& clang::HeaderSearch::getFileMgr ( ) const [inline]
StringRef clang::HeaderSearch::getModuleCachePath ( ) const [inline]

Retrieve the path to the module cache.

Definition at line 226 of file HeaderSearch.h.

Referenced by clang::GenerateModuleAction::ComputeASTConsumerArguments().

std::string HeaderSearch::getModuleFileName ( Module Module)

Retrieve the name of the module file that should be used to load the given module.

Parameters:
ModuleThe module whose module file name will be returned.
Returns:
The name of the module file that corresponds to this module, or an empty string if this module does not correspond to any module file.

Definition at line 107 of file HeaderSearch.cpp.

References clang::Module::getTopLevelModule(), and clang::Module::Name.

std::string HeaderSearch::getModuleFileName ( StringRef  ModuleName)

Retrieve the name of the module file that should be used to load a module with the given name.

Parameters:
ModuleThe module whose module file name will be returned.
Returns:
The name of the module file that corresponds to this module, or an empty string if this module does not correspond to any module file.

Definition at line 118 of file HeaderSearch.cpp.

ModuleMap& clang::HeaderSearch::getModuleMap ( ) [inline]
size_t HeaderSearch::getTotalMemory ( ) const

Definition at line 761 of file HeaderSearch.cpp.

StringRef HeaderSearch::getUniqueFrameworkName ( StringRef  Framework)

Retrieve a uniqued framework name.

Definition at line 769 of file HeaderSearch.cpp.

Referenced by LookupFile().

bool HeaderSearch::hasModuleMap ( StringRef  Filename,
const DirectoryEntry Root 
)

Determine whether there is a module map that may map the header with the given file name to a (sub)module.

Parameters:
FilenameThe name of the file.
RootThe "root" directory, at which we should stop looking for module maps.

Definition at line 773 of file HeaderSearch.cpp.

References clang::FileManager::getDirectory(), and loadModuleMapFile().

Referenced by clang::DirectoryLookup::LookupFile().

unsigned clang::HeaderSearch::header_file_size ( ) const [inline]

Definition at line 432 of file HeaderSearch.h.

void clang::HeaderSearch::IncrementFrameworkLookupCount ( ) [inline]

Definition at line 382 of file HeaderSearch.h.

void clang::HeaderSearch::IncrementIncludeCount ( const FileEntry File) [inline]

IncrementIncludeCount - Increment the count for the number of times the specified FileEntry has been entered.

Definition at line 330 of file HeaderSearch.h.

References getFileInfo(), and clang::HeaderFileInfo::NumIncludes.

Referenced by clang::Preprocessor::EnterMainSourceFile().

bool HeaderSearch::isFileMultipleIncludeGuarded ( const FileEntry File)

Determine whether this file is intended to be safe from multiple inclusions, e.g., it has #pragma once or a controlling macro.

This routine does not consider the effect of #import

Definition at line 702 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::ControllingMacro, clang::HeaderFileInfo::ControllingMacroID, clang::ExternalHeaderFileInfoSource::GetHeaderFileInfo(), clang::FileEntry::getUID(), clang::HeaderFileInfo::isPragmaOnce, mergeHeaderFileInfo(), and clang::HeaderFileInfo::Resolved.

bool HeaderSearch::loadModuleMapFile ( const FileEntry File)

Read the contents of the given module map file.

Parameters:
FileThe module map file.
OnlyModuleIf non-NULL, this will receive the
Returns:
true if an error occurred, false otherwise.

Definition at line 822 of file HeaderSearch.cpp.

References clang::FileEntry::getDir(), clang::FileManager::getFile(), clang::DirectoryEntry::getName(), clang::FileEntry::getName(), and clang::ModuleMap::parseModuleMapFile().

Referenced by clang::GenerateModuleAction::BeginSourceFileAction(), collectAllModules(), hasModuleMap(), and lookupModule().

const FileEntry * HeaderSearch::LookupFile ( StringRef  Filename,
bool  isAngled,
const DirectoryLookup FromDir,
const DirectoryLookup *&  CurDir,
const FileEntry CurFileEnt,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath,
Module **  SuggestedModule,
bool  SkipCache = false 
)

LookupFile - Given a "foo" or <foo> reference, look up the indicated file, return null on failure.

Returns:
If successful, this returns 'UsedDir', the DirectoryLookup member the file was found in, or null if not applicable.
Parameters:
isAngledindicates whether the file reference is a <> reference.
CurDirIf non-null, the file was found in the specified directory search location. This is used to implement #include_next.
CurFileEntIf non-null, indicates where the #including file is, in case a relative search is needed.
SearchPathIf non-null, will be set to the search path relative to which the file was found. If the include path is absolute, SearchPath will be set to an empty string.
RelativePathIf non-null, will be set to the path relative to SearchPath at which the file was found. This only differs from the Filename for framework includes.
SuggestedModuleIf non-null, and the file found is semantically part of a known module, this will be set to the module that should be imported instead of preprocessing/parsing the file found.

LookupFile - Given a "foo" or <foo> reference, look up the indicated file, return null on failure. isAngled indicates whether the file reference is for system #include's or not (i.e. using <> instead of ""). CurFileEnt, if non-null, indicates where the #including file is, in case a relative search is needed.

Definition at line 384 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::DirInfo, clang::HeaderFileInfo::Framework, clang::FileEntry::getDir(), clang::DirectoryLookup::getDirCharacteristic(), clang::FileManager::getFile(), getFileInfo(), clang::DirectoryEntry::getName(), getUniqueFrameworkName(), clang::HeaderFileInfo::IndexHeaderMapHeader, clang::DirectoryLookup::isIndexHeaderMap(), and NULL.

Referenced by clang::Preprocessor::LookupFile().

const DirectoryEntry*& clang::HeaderSearch::LookupFrameworkCache ( StringRef  FWName) [inline]

LookupFrameworkCache - Look up the specified framework name in our framework cache, returning the DirectoryEntry it is in if we know, otherwise, return null.

Definition at line 298 of file HeaderSearch.h.

Module * HeaderSearch::lookupModule ( StringRef  ModuleName,
bool  AllowSearch = true 
)

Lookup a module Search for a module with the given name.

Parameters:
ModuleNameThe name of the module we're looking for.
AllowSearchWhether we are allowed to search in the various search directories to produce a module definition. If not, this lookup will only return an already-known module.
Returns:
The module with the given name.

Definition at line 129 of file HeaderSearch.cpp.

References clang::SrcMgr::C_User, clang::ModuleMap::findModule(), clang::FileManager::getDirectory(), and loadModuleMapFile().

Referenced by clang::GenerateModuleAction::BeginSourceFileAction(), and clang::Preprocessor::getCurrentModule().

const FileEntry * HeaderSearch::LookupSubframeworkHeader ( StringRef  Filename,
const FileEntry ContextFileEnt,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath 
)

LookupSubframeworkHeader - Look up a subframework for the specified #include file. For example, if #include'ing <HIToolbox/HIToolbox.h> from within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox is a subframework within Carbon.framework. If so, return the FileEntry for the designated file, otherwise return null.

Definition at line 543 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::DirInfo, clang::FileManager::getDirectory(), clang::FileManager::getFile(), getFileInfo(), clang::FileEntry::getName(), and NULL.

Referenced by clang::Preprocessor::LookupFile().

void clang::HeaderSearch::MarkFileIncludeOnce ( const FileEntry File) [inline]

MarkFileIncludeOnce - Mark the specified file as a "once only" file, e.g. due to #pragma once.

Definition at line 316 of file HeaderSearch.h.

References getFileInfo(), clang::HeaderFileInfo::isImport, and clang::HeaderFileInfo::isPragmaOnce.

Referenced by clang::Preprocessor::HandlePragmaOnce().

void clang::HeaderSearch::MarkFileSystemHeader ( const FileEntry File) [inline]

MarkFileSystemHeader - Mark the specified file as a system header, e.g. due to #pragma GCC system_header.

Definition at line 324 of file HeaderSearch.h.

References clang::SrcMgr::C_System, clang::HeaderFileInfo::DirInfo, and getFileInfo().

Referenced by clang::Preprocessor::HandlePragmaSystemHeader().

std::string HeaderSearch::NormalizeDashIncludePath ( StringRef  File,
FileManager FileMgr 
) [static]

Helper static function to normalize a path for injection into a synthetic header.

Definition at line 642 of file HeaderSearch.cpp.

References clang::FileManager::getFile(), and clang::Lexer::Stringify().

Referenced by AddImplicitInclude(), AddImplicitIncludeMacros(), and clang::PCHValidator::ReadPredefinesBuffer().

void HeaderSearch::PrintStats ( )

Definition at line 64 of file HeaderSearch.cpp.

Referenced by clang::FrontendAction::EndSourceFile().

search_dir_iterator clang::HeaderSearch::quoted_dir_begin ( ) const [inline]

Definition at line 449 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::quoted_dir_end ( ) const [inline]

Definition at line 452 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::search_dir_begin ( ) const [inline]

Definition at line 445 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::search_dir_end ( ) const [inline]

Definition at line 446 of file HeaderSearch.h.

unsigned clang::HeaderSearch::search_dir_size ( ) const [inline]

Definition at line 447 of file HeaderSearch.h.

void clang::HeaderSearch::SetExternalLookup ( ExternalIdentifierLookup EIL) [inline]

Definition at line 233 of file HeaderSearch.h.

void clang::HeaderSearch::SetExternalSource ( ExternalHeaderFileInfoSource ES) [inline]

Set the external source of header information.

Definition at line 242 of file HeaderSearch.h.

void clang::HeaderSearch::SetFileControllingMacro ( const FileEntry File,
const IdentifierInfo ControllingMacro 
) [inline]

SetFileControllingMacro - Mark the specified file as having a controlling macro. This is used by the multiple-include optimization to eliminate no-op #includes.

Definition at line 337 of file HeaderSearch.h.

References clang::HeaderFileInfo::ControllingMacro, and getFileInfo().

Referenced by clang::Preprocessor::HandleEndOfFile().

void HeaderSearch::setHeaderFileInfoForUID ( HeaderFileInfo  HFI,
unsigned  UID 
)

Definition at line 715 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::Resolved.

void clang::HeaderSearch::setModuleCachePath ( StringRef  CachePath) [inline]

Set the path to the module cache.

Definition at line 221 of file HeaderSearch.h.

void clang::HeaderSearch::SetSearchPaths ( const std::vector< DirectoryLookup > &  dirs,
unsigned  angledDirIdx,
unsigned  systemDirIdx,
bool  noCurDirSearch 
) [inline]

SetSearchPaths - Interface for setting the file search paths.

Definition at line 199 of file HeaderSearch.h.

void HeaderSearch::setTarget ( const TargetInfo Target)

Set the target information for the header search, if not already known.

Definition at line 369 of file HeaderSearch.cpp.

References clang::ModuleMap::setTarget().

Referenced by clang::Preprocessor::Initialize().

bool HeaderSearch::ShouldEnterIncludeFile ( const FileEntry File,
bool  isImport 
)

ShouldEnterIncludeFile - Mark the specified file as a target of of a #include, #include_next, or #import directive. Return false if #including the file will have no effect or true if we should include it.

Definition at line 725 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::getControllingMacro(), getFileInfo(), clang::HeaderFileInfo::isImport, and clang::HeaderFileInfo::NumIncludes.

search_dir_iterator clang::HeaderSearch::system_dir_begin ( ) const [inline]

Definition at line 463 of file HeaderSearch.h.

search_dir_iterator clang::HeaderSearch::system_dir_end ( ) const [inline]

Definition at line 466 of file HeaderSearch.h.


Friends And Related Function Documentation

friend class DirectoryLookup [friend]

Definition at line 188 of file HeaderSearch.h.


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