clang 17.0.0git
Classes | Public Member Functions | Friends | List of all members
clang::HeaderSearch Class Reference

Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc. More...

#include "clang/Lex/HeaderSearch.h"

Public Member Functions

 HeaderSearch (std::shared_ptr< HeaderSearchOptions > HSOpts, SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target)
 
 HeaderSearch (const HeaderSearch &)=delete
 
HeaderSearchoperator= (const HeaderSearch &)=delete
 
HeaderSearchOptionsgetHeaderSearchOpts () const
 Retrieve the header-search options with which this header search was initialized.
 
FileManagergetFileMgr () const
 
DiagnosticsEnginegetDiags () const
 
void SetSearchPaths (std::vector< DirectoryLookup > dirs, unsigned angledDirIdx, unsigned systemDirIdx, bool noCurDirSearch, llvm::DenseMap< unsigned, unsigned > searchDirToHSEntry)
 Interface for setting the file search paths.
 
void AddSearchPath (const DirectoryLookup &dir, bool isAngled)
 Add an additional search path.
 
void AddSystemSearchPath (const DirectoryLookup &dir)
 Add an additional system search path.
 
void SetSystemHeaderPrefixes (ArrayRef< std::pair< std::string, bool > > P)
 Set the list of system header prefixes.
 
bool HasIncludeAliasMap () const
 Checks whether the map exists or not.
 
void AddIncludeAlias (StringRef Source, StringRef Dest)
 Map the source include name to the dest include name.
 
StringRef MapHeaderToIncludeAlias (StringRef Source)
 Maps one header file name to a different header file name, for use with the include_alias pragma.
 
void setModuleHash (StringRef Hash)
 Set the hash to use for module cache paths.
 
void setModuleCachePath (StringRef CachePath)
 Set the path to the module cache.
 
StringRef getModuleHash () const
 Retrieve the module hash.
 
StringRef getModuleCachePath () const
 Retrieve the path to the module cache.
 
void setDirectoryHasModuleMap (const DirectoryEntry *Dir)
 Consider modules when including files from this directory.
 
void ClearFileInfo ()
 Forget everything we know about headers so far.
 
void SetExternalLookup (ExternalPreprocessorSource *EPS)
 
ExternalPreprocessorSourcegetExternalLookup () 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.
 
OptionalFileEntryRef LookupFile (StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef< std::pair< const FileEntry *, const DirectoryEntry * > > Includers, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool BuildSystemModule=false, bool OpenFile=true, bool CacheFailures=true)
 Given a "foo" or <foo> reference, look up the indicated file, return null on failure.
 
OptionalFileEntryRef LookupSubframeworkHeader (StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule)
 Look up a subframework for the specified #include file.
 
FrameworkCacheEntryLookupFrameworkCache (StringRef FWName)
 Look up the specified framework name in our framework cache.
 
bool ShouldEnterIncludeFile (Preprocessor &PP, const FileEntry *File, bool isImport, bool ModulesEnabled, Module *M, bool &IsFirstIncludeOfFile)
 Mark the specified file as a target of a #include, #include_next, or #import directive.
 
SrcMgr::CharacteristicKind getFileDirFlavor (const FileEntry *File)
 Return whether the specified file is a normal header, a system header, or a C++ friendly system header.
 
void MarkFileIncludeOnce (const FileEntry *File)
 Mark the specified file as a "once only" file due to #pragma once.
 
void MarkFileSystemHeader (const FileEntry *File)
 Mark the specified file as a system header, e.g.
 
void MarkFileModuleHeader (const FileEntry *FE, ModuleMap::ModuleHeaderRole Role, bool isCompilingModuleHeader)
 Mark the specified file as part of a module.
 
void SetFileControllingMacro (const FileEntry *File, const IdentifierInfo *ControllingMacro)
 Mark the specified file as having a controlling macro.
 
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.
 
bool hasFileBeenImported (const FileEntry *File)
 Determine whether the given file is known to have ever been #imported.
 
std::vector< boolcomputeUserEntryUsage () const
 Determine which HeaderSearchOptions::UserEntries have been successfully used so far and mark their index with 'true' in the resulting bit vector.
 
const HeaderMapCreateHeaderMap (const FileEntry *FE)
 This method returns a HeaderMap for the specified FileEntry, uniquing them through the 'HeaderMaps' datastructure.
 
void getHeaderMapFileNames (SmallVectorImpl< std::string > &Names) const
 Get filenames for all registered header maps.
 
std::string getCachedModuleFileName (Module *Module)
 Retrieve the name of the cached module file that should be used to load the given module.
 
std::string getPrebuiltModuleFileName (StringRef ModuleName, bool FileMapOnly=false)
 Retrieve the name of the prebuilt module file that should be used to load a module with the given name.
 
std::string getPrebuiltImplicitModuleFileName (Module *Module)
 Retrieve the name of the prebuilt module file that should be used to load the given module.
 
std::string getCachedModuleFileName (StringRef ModuleName, StringRef ModuleMapPath)
 Retrieve the name of the (to-be-)cached module file that should be used to load a module with the given name.
 
ModulelookupModule (StringRef ModuleName, SourceLocation ImportLoc=SourceLocation(), bool AllowSearch=true, bool AllowExtraModuleMapSearch=false)
 Lookup a module Search for a module with the given name.
 
const FileEntrylookupModuleMapFile (const DirectoryEntry *Dir, bool IsFramework)
 Try to find a module map file in the given directory, returning nullptr if none is found.
 
bool hasModuleMap (StringRef Filename, const DirectoryEntry *Root, bool IsSystem)
 Determine whether there is a module map that may map the header with the given file name to a (sub)module.
 
ModuleMap::KnownHeader findModuleForHeader (const FileEntry *File, bool AllowTextual=false, bool AllowExcluded=false) const
 Retrieve the module that corresponds to the given file, if any.
 
ArrayRef< ModuleMap::KnownHeaderfindAllModulesForHeader (const FileEntry *File) const
 Retrieve all the modules corresponding to the given file.
 
bool loadModuleMapFile (const FileEntry *File, bool IsSystem, FileID ID=FileID(), unsigned *Offset=nullptr, StringRef OriginalModuleMapFile=StringRef())
 Read the contents of the given module map file.
 
void collectAllModules (SmallVectorImpl< Module * > &Modules)
 Collect the set of all known, top-level modules.
 
void loadTopLevelSystemModules ()
 Load all known, top-level system modules.
 
ModuleMapgetModuleMap ()
 Retrieve the module map.
 
const ModuleMapgetModuleMap () const
 Retrieve the module map.
 
unsigned header_file_size () const
 
HeaderFileInfogetFileInfo (const FileEntry *FE)
 Return the HeaderFileInfo structure for the specified FileEntry, in preparation for updating it in some way.
 
const HeaderFileInfogetExistingFileInfo (const FileEntry *FE, bool WantExternal=true) const
 Return the HeaderFileInfo structure for the specified FileEntry, if it has ever been filled in.
 
SearchDirIterator search_dir_begin ()
 
SearchDirIterator search_dir_end ()
 
SearchDirRange search_dir_range ()
 
ConstSearchDirIterator search_dir_begin () const
 
ConstSearchDirIterator search_dir_nth (size_t n) const
 
ConstSearchDirIterator search_dir_end () const
 
ConstSearchDirRange search_dir_range () const
 
unsigned search_dir_size () const
 
ConstSearchDirIterator quoted_dir_begin () const
 
ConstSearchDirIterator quoted_dir_end () const
 
ConstSearchDirIterator angled_dir_begin () const
 
ConstSearchDirIterator angled_dir_end () const
 
ConstSearchDirIterator system_dir_begin () const
 
ConstSearchDirIterator system_dir_end () const
 
unsigned searchDirIdx (const DirectoryLookup &DL) const
 Get the index of the given search directory.
 
StringRef getUniqueFrameworkName (StringRef Framework)
 Retrieve a uniqued framework name.
 
StringRef getIncludeNameForHeader (const FileEntry *File) const
 Retrieve the include name for the header.
 
std::string suggestPathToFileForDiagnostics (const FileEntry *File, llvm::StringRef MainFile, bool *IsSystem=nullptr)
 Suggest a path by which the specified file could be found, for use in diagnostics to suggest a #include.
 
std::string suggestPathToFileForDiagnostics (llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile, bool *IsSystem=nullptr)
 Suggest a path by which the specified file could be found, for use in diagnostics to suggest a #include.
 
void PrintStats ()
 
size_t getTotalMemory () const
 

Friends

class DirectoryLookup
 

Detailed Description

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

Definition at line 223 of file HeaderSearch.h.

Constructor & Destructor Documentation

◆ HeaderSearch() [1/2]

HeaderSearch::HeaderSearch ( std::shared_ptr< HeaderSearchOptions HSOpts,
SourceManager SourceMgr,
DiagnosticsEngine Diags,
const LangOptions LangOpts,
const TargetInfo Target 
)

Definition at line 82 of file HeaderSearch.cpp.

◆ HeaderSearch() [2/2]

clang::HeaderSearch::HeaderSearch ( const HeaderSearch )
delete

Member Function Documentation

◆ AddIncludeAlias()

void clang::HeaderSearch::AddIncludeAlias ( StringRef  Source,
StringRef  Dest 
)
inline

Map the source include name to the dest include name.

The Source should include the angle brackets or quotes, the dest should not. This allows for distinction between <> and "" headers.

Definition at line 386 of file HeaderSearch.h.

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

◆ AddSearchPath()

void HeaderSearch::AddSearchPath ( const DirectoryLookup dir,
bool  isAngled 
)

Add an additional search path.

Definition at line 122 of file HeaderSearch.cpp.

◆ AddSystemSearchPath()

void clang::HeaderSearch::AddSystemSearchPath ( const DirectoryLookup dir)
inline

Add an additional system search path.

Definition at line 369 of file HeaderSearch.h.

◆ angled_dir_begin()

ConstSearchDirIterator clang::HeaderSearch::angled_dir_begin ( ) const
inline

Definition at line 830 of file HeaderSearch.h.

Referenced by LookupFile(), and quoted_dir_end().

◆ angled_dir_end()

ConstSearchDirIterator clang::HeaderSearch::angled_dir_end ( ) const
inline

Definition at line 833 of file HeaderSearch.h.

References system_dir_begin().

◆ ClearFileInfo()

void clang::HeaderSearch::ClearFileInfo ( )
inline

Forget everything we know about headers so far.

Definition at line 426 of file HeaderSearch.h.

◆ collectAllModules()

void HeaderSearch::collectAllModules ( 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 1829 of file HeaderSearch.cpp.

References clang::FileManager::getOptionalDirectoryRef(), clang::FileManager::getVirtualFileSystem(), loadModuleMapFile(), clang::ModuleMap::modules(), and search_dir_range().

◆ computeUserEntryUsage()

std::vector< bool > HeaderSearch::computeUserEntryUsage ( ) const

Determine which HeaderSearchOptions::UserEntries have been successfully used so far and mark their index with 'true' in the resulting bit vector.

Note: implicit module maps don't contribute to entry usage.

Definition at line 131 of file HeaderSearch.cpp.

◆ CreateHeaderMap()

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

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

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

Definition at line 147 of file HeaderSearch.cpp.

References clang::HeaderMap::Create().

◆ findAllModulesForHeader()

ArrayRef< ModuleMap::KnownHeader > HeaderSearch::findAllModulesForHeader ( const FileEntry File) const

Retrieve all the modules corresponding to the given file.

findModuleForHeader should typically be used instead of this.

Definition at line 1568 of file HeaderSearch.cpp.

References clang::File, clang::ModuleMap::findAllModulesForHeader(), and getExistingFileInfo().

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

◆ findModuleForHeader()

ModuleMap::KnownHeader HeaderSearch::findModuleForHeader ( const FileEntry File,
bool  AllowTextual = false,
bool  AllowExcluded = false 
) const

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

Parameters
FileThe header that we wish to map to a module.
AllowTextualWhether we want to find textual headers too.

Definition at line 1557 of file HeaderSearch.cpp.

References clang::File, clang::ModuleMap::findModuleForHeader(), and getExistingFileInfo().

Referenced by clang::VerifyDiagnosticConsumer::HandleDiagnostic(), and suggestModule().

◆ getCachedModuleFileName() [1/2]

std::string HeaderSearch::getCachedModuleFileName ( Module Module)

Retrieve the name of the cached 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 173 of file HeaderSearch.cpp.

References getCachedModuleFileName(), getModuleMap(), clang::ModuleMap::getModuleMapFileForUniquing(), and clang::Module::Name.

Referenced by getCachedModuleFileName(), and selectModuleSource().

◆ getCachedModuleFileName() [2/2]

std::string HeaderSearch::getCachedModuleFileName ( StringRef  ModuleName,
StringRef  ModuleMapPath 
)

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

Parameters
ModuleNameThe module whose module file name will be returned.
ModuleMapPathA path that when combined with ModuleName uniquely identifies this module. See Module::ModuleMap.
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 232 of file HeaderSearch.cpp.

References getModuleCachePath().

◆ getDiags()

DiagnosticsEngine & clang::HeaderSearch::getDiags ( ) const
inline

Definition at line 358 of file HeaderSearch.h.

◆ getExistingFileInfo()

const HeaderFileInfo * HeaderSearch::getExistingFileInfo ( const FileEntry FE,
bool  WantExternal = true 
) const

Return the HeaderFileInfo structure for the specified FileEntry, if it has ever been filled in.

Parameters
WantExternalWhether the caller wants purely-external header file info (where External is true).

Definition at line 1338 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::External, clang::ExternalHeaderFileInfoSource::GetHeaderFileInfo(), clang::FileEntry::getUID(), clang::HeaderFileInfo::IsValid, mergeHeaderFileInfo(), and clang::HeaderFileInfo::Resolved.

Referenced by findAllModulesForHeader(), findModuleForHeader(), hasFileBeenImported(), isFileMultipleIncludeGuarded(), and MarkFileModuleHeader().

◆ getExternalLookup()

ExternalPreprocessorSource * clang::HeaderSearch::getExternalLookup ( ) const
inline

Definition at line 434 of file HeaderSearch.h.

◆ getFileDirFlavor()

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

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

Definition at line 520 of file HeaderSearch.h.

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

Referenced by EvaluateHasIncludeCommon().

◆ getFileInfo()

HeaderFileInfo & HeaderSearch::getFileInfo ( const FileEntry FE)

◆ getFileMgr()

FileManager & clang::HeaderSearch::getFileMgr ( ) const
inline

◆ getHeaderMapFileNames()

void HeaderSearch::getHeaderMapFileNames ( SmallVectorImpl< std::string > &  Names) const

Get filenames for all registered header maps.

Definition at line 167 of file HeaderSearch.cpp.

Referenced by collectHeaderMaps().

◆ getHeaderSearchOpts()

HeaderSearchOptions & clang::HeaderSearch::getHeaderSearchOpts ( ) const
inline

Retrieve the header-search options with which this header search was initialized.

Definition at line 354 of file HeaderSearch.h.

Referenced by clang::CompilerInstance::createPCHExternalASTSource(), clang::Sema::getDarwinSDKInfoForAvailabilityChecking(), loadModuleMapFile(), clang::ASTReader::ReadAST(), and selectModuleSource().

◆ getIncludeNameForHeader()

StringRef HeaderSearch::getIncludeNameForHeader ( const FileEntry File) const

Retrieve the include name for the header.

Parameters
FileThe entry for a given header.
Returns
The name of how the file was included when the header's location was resolved.

Definition at line 1502 of file HeaderSearch.cpp.

References clang::File.

◆ getModuleCachePath()

StringRef clang::HeaderSearch::getModuleCachePath ( ) const
inline

Retrieve the path to the module cache.

Definition at line 418 of file HeaderSearch.h.

Referenced by clang::FrontendAction::Execute(), getCachedModuleFileName(), and clang::PCHValidator::ReadHeaderSearchOptions().

◆ getModuleHash()

StringRef clang::HeaderSearch::getModuleHash ( ) const
inline

Retrieve the module hash.

Definition at line 415 of file HeaderSearch.h.

Referenced by getPrebuiltImplicitModuleFileName().

◆ getModuleMap() [1/2]

ModuleMap & clang::HeaderSearch::getModuleMap ( )
inline

◆ getModuleMap() [2/2]

const ModuleMap & clang::HeaderSearch::getModuleMap ( ) const
inline

Retrieve the module map.

Definition at line 794 of file HeaderSearch.h.

◆ getPrebuiltImplicitModuleFileName()

std::string HeaderSearch::getPrebuiltImplicitModuleFileName ( Module Module)

Retrieve the name of the prebuilt 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 214 of file HeaderSearch.cpp.

References getFileMgr(), getModuleHash(), getModuleMap(), clang::ModuleMap::getModuleMapFileForUniquing(), and clang::Module::Name.

Referenced by selectModuleSource().

◆ getPrebuiltModuleFileName()

std::string HeaderSearch::getPrebuiltModuleFileName ( StringRef  ModuleName,
bool  FileMapOnly = false 
)

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

Parameters
ModuleNameThe module whose module file name will be returned.
FileMapOnlyIf true, then only look in the explicit module name
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 183 of file HeaderSearch.cpp.

References getFileMgr(), and clang::Result.

Referenced by selectModuleSource().

◆ getTotalMemory()

size_t HeaderSearch::getTotalMemory ( ) const

Definition at line 1486 of file HeaderSearch.cpp.

◆ getUniqueFrameworkName()

StringRef HeaderSearch::getUniqueFrameworkName ( StringRef  Framework)

Retrieve a uniqued framework name.

Definition at line 1498 of file HeaderSearch.cpp.

Referenced by LookupFile().

◆ hasFileBeenImported()

bool clang::HeaderSearch::hasFileBeenImported ( const FileEntry File)
inline

Determine whether the given file is known to have ever been #imported.

Definition at line 559 of file HeaderSearch.h.

References clang::File, getExistingFileInfo(), and clang::HeaderFileInfo::isImport.

Referenced by clang::tooling::isSelfContainedHeader().

◆ HasIncludeAliasMap()

bool clang::HeaderSearch::HasIncludeAliasMap ( ) const
inline

Checks whether the map exists or not.

Definition at line 380 of file HeaderSearch.h.

◆ hasModuleMap()

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

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

Always returns false if modules are disabled.

Parameters
FilenameThe name of the file.
RootThe "root" directory, at which we should stop looking for module maps.
IsSystemWhether the directories we're looking at are system header directories.

Definition at line 1509 of file HeaderSearch.cpp.

References clang::DirectoryEntry::getName(), clang::FileManager::getOptionalDirectoryRef(), and loadModuleMapFile().

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

◆ header_file_size()

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

Definition at line 796 of file HeaderSearch.h.

◆ isFileMultipleIncludeGuarded()

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 1373 of file HeaderSearch.cpp.

References clang::File, and getExistingFileInfo().

Referenced by clang::tooling::isSelfContainedHeader().

◆ loadModuleMapFile()

bool HeaderSearch::loadModuleMapFile ( const FileEntry File,
bool  IsSystem,
FileID  ID = FileID(),
unsigned Offset = nullptr,
StringRef  OriginalModuleMapFile = StringRef() 
)

Read the contents of the given module map file.

Parameters
FileThe module map file.
IsSystemWhether this file is in a system header directory.
IDIf the module map file is already mapped (perhaps as part of processing a preprocessed module), the ID of the file.
Offset[inout] An offset within ID to start parsing. On exit, filled by the end of the parsed contents (either EOF or the location of an end-of-module-map pragma).
OriginalModuleMapFileThe original path to the module map file, used to resolve paths within the module (this is required when building the module from preprocessed source).
Returns
true if an error occurred, false otherwise.

Definition at line 1665 of file HeaderSearch.cpp.

References clang::File, getHeaderSearchOpts(), clang::DirectoryEntryRef::getName(), clang::FileManager::getOptionalDirectoryRef(), clang::FileManager::getVirtualFileRef(), and Offset.

Referenced by clang::FrontendAction::BeginSourceFile(), collectAllModules(), hasModuleMap(), loadModuleMapForModuleBuild(), and loadTopLevelSystemModules().

◆ loadTopLevelSystemModules()

void HeaderSearch::loadTopLevelSystemModules ( )

Load all known, top-level system modules.

Definition at line 1878 of file HeaderSearch.cpp.

References loadModuleMapFile(), and search_dir_range().

◆ LookupFile()

OptionalFileEntryRef HeaderSearch::LookupFile ( StringRef  Filename,
SourceLocation  IncludeLoc,
bool  isAngled,
ConstSearchDirIterator  FromDir,
ConstSearchDirIterator CurDirArg,
ArrayRef< std::pair< const FileEntry *, const DirectoryEntry * > >  Includers,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath,
Module RequestingModule,
ModuleMap::KnownHeader SuggestedModule,
bool IsMapped,
bool IsFrameworkFound,
bool  SkipCache = false,
bool  BuildSystemModule = false,
bool  OpenFile = true,
bool  CacheFailures = true 
)

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

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
IncludeLocUsed for diagnostics if valid.
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.
IncludersIndicates where the #including file(s) are, in case relative searches are needed. In reverse order of inclusion.
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.
IsMappedIf non-null, and the search involved header maps, set to true.
IsFrameworkFoundIf non-null, will be set to true if a framework is found in any of searched SearchDirs. Will be set to false if a framework is found only through header maps. Doesn't guarantee the requested file is found.

isAngled indicates whether the file reference is for system #include's or not (i.e. using <> instead of ""). Includers, if non-empty, indicates where the #including file(s) are, in case a relative search is needed. Microsoft mode will pass all #including files.

Definition at line 857 of file HeaderSearch.cpp.

References angled_dir_begin(), clang::SrcMgr::C_System, clang::SrcMgr::C_User, checkMSVCHeaderSearch(), copyString(), diagnoseFrameworkInclude(), clang::HeaderFileInfo::DirInfo, false, clang::File, Filename, clang::First, clang::HeaderFileInfo::Framework, clang::FileEntryRef::getFileEntry(), getFileInfo(), getUniqueFrameworkName(), clang::HeaderFileInfo::IndexHeaderMapHeader, clang::DiagnosticsEngine::isIgnored(), LookupFile(), search_dir_begin(), search_dir_end(), and search_dir_nth().

Referenced by clang::FrontendAction::BeginSourceFile(), clang::Preprocessor::LookupFile(), and LookupFile().

◆ LookupFrameworkCache()

FrameworkCacheEntry & clang::HeaderSearch::LookupFrameworkCache ( StringRef  FWName)
inline

Look up the specified framework name in our framework cache.

Returns
The DirectoryEntry it is in if we know, null otherwise.

Definition at line 505 of file HeaderSearch.h.

◆ lookupModule()

Module * HeaderSearch::lookupModule ( StringRef  ModuleName,
SourceLocation  ImportLoc = SourceLocation(),
bool  AllowSearch = true,
bool  AllowExtraModuleMapSearch = false 
)

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

Parameters
ModuleNameThe name of the module we're looking for.
ImportLocLocation of the module include/import.
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.
AllowExtraModuleMapSearchWhether we allow to search modulemaps in subdirectories.
Returns
The module with the given name.

Definition at line 272 of file HeaderSearch.cpp.

References clang::ModuleMap::findModule(), and lookupModule().

Referenced by clang::Sema::BuildModuleInclude(), clang::Preprocessor::getCurrentModule(), clang::FrontendAction::getCurrentModule(), clang::Preprocessor::getCurrentModuleImplementation(), clang::Preprocessor::getModuleForLocation(), getTopImportImplicitModule(), clang::PCHGenerator::HandleTranslationUnit(), clang::ASTUnit::LoadFromASTFile(), clang::CompilerInstance::loadModule(), lookupModule(), and prepareToBuildModule().

◆ lookupModuleMapFile()

const FileEntry * HeaderSearch::lookupModuleMapFile ( const DirectoryEntry Dir,
bool  IsFramework 
)

Try to find a module map file in the given directory, returning nullptr if none is found.

Definition at line 1744 of file HeaderSearch.cpp.

References clang::FileManager::getFile(), and clang::DirectoryEntry::getName().

◆ LookupSubframeworkHeader()

OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader ( StringRef  Filename,
const FileEntry ContextFileEnt,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath,
Module RequestingModule,
ModuleMap::KnownHeader SuggestedModule 
)

Look up a subframework for the specified #include file.

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 1177 of file HeaderSearch.cpp.

References clang::HeaderFileInfo::DirInfo, clang::File, Filename, getFileInfo(), clang::FileEntry::getName(), clang::FileManager::getOptionalDirectoryRef(), and clang::FileManager::getOptionalFileRef().

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

◆ MapHeaderToIncludeAlias()

StringRef clang::HeaderSearch::MapHeaderToIncludeAlias ( StringRef  Source)
inline

Maps one header file name to a different header file name, for use with the include_alias pragma.

Note that the source file name should include the angle brackets or quotes. Returns StringRef as null if the header cannot be mapped.

Definition at line 396 of file HeaderSearch.h.

◆ MarkFileIncludeOnce()

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

Mark the specified file as a "once only" file due to #pragma once.

Definition at line 526 of file HeaderSearch.h.

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

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

◆ MarkFileModuleHeader()

void HeaderSearch::MarkFileModuleHeader ( const FileEntry FE,
ModuleMap::ModuleHeaderRole  Role,
bool  isCompilingModuleHeader 
)

Mark the specified file as part of a module.

Definition at line 1383 of file HeaderSearch.cpp.

References getExistingFileInfo(), getFileInfo(), and clang::ModuleMap::isModular().

Referenced by clang::ModuleMap::addHeader().

◆ MarkFileSystemHeader()

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

Mark the specified file as a system header, e.g.

due to #pragma GCC system_header.

Definition at line 533 of file HeaderSearch.h.

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

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

◆ operator=()

HeaderSearch & clang::HeaderSearch::operator= ( const HeaderSearch )
delete

◆ PrintStats()

void HeaderSearch::PrintStats ( )

Definition at line 90 of file HeaderSearch.cpp.

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

◆ quoted_dir_begin()

ConstSearchDirIterator clang::HeaderSearch::quoted_dir_begin ( ) const
inline

Definition at line 827 of file HeaderSearch.h.

Referenced by search_dir_begin().

◆ quoted_dir_end()

ConstSearchDirIterator clang::HeaderSearch::quoted_dir_end ( ) const
inline

Definition at line 828 of file HeaderSearch.h.

References angled_dir_begin().

◆ search_dir_begin() [1/2]

SearchDirIterator clang::HeaderSearch::search_dir_begin ( )
inline

Definition at line 809 of file HeaderSearch.h.

Referenced by LookupFile(), and search_dir_range().

◆ search_dir_begin() [2/2]

ConstSearchDirIterator clang::HeaderSearch::search_dir_begin ( ) const
inline

Definition at line 815 of file HeaderSearch.h.

References quoted_dir_begin().

◆ search_dir_end() [1/2]

SearchDirIterator clang::HeaderSearch::search_dir_end ( )
inline

Definition at line 810 of file HeaderSearch.h.

Referenced by LookupFile(), and search_dir_range().

◆ search_dir_end() [2/2]

ConstSearchDirIterator clang::HeaderSearch::search_dir_end ( ) const
inline

Definition at line 820 of file HeaderSearch.h.

References system_dir_end().

◆ search_dir_nth()

ConstSearchDirIterator clang::HeaderSearch::search_dir_nth ( size_t  n) const
inline

Definition at line 816 of file HeaderSearch.h.

Referenced by LookupFile().

◆ search_dir_range() [1/2]

SearchDirRange clang::HeaderSearch::search_dir_range ( )
inline

◆ search_dir_range() [2/2]

ConstSearchDirRange clang::HeaderSearch::search_dir_range ( ) const
inline

Definition at line 821 of file HeaderSearch.h.

References search_dir_begin(), and search_dir_end().

◆ search_dir_size()

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

Definition at line 825 of file HeaderSearch.h.

◆ searchDirIdx()

unsigned HeaderSearch::searchDirIdx ( const DirectoryLookup DL) const

Get the index of the given search directory.

Definition at line 1494 of file HeaderSearch.cpp.

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

◆ setDirectoryHasModuleMap()

void clang::HeaderSearch::setDirectoryHasModuleMap ( const DirectoryEntry Dir)
inline

Consider modules when including files from this directory.

Definition at line 421 of file HeaderSearch.h.

◆ SetExternalLookup()

void clang::HeaderSearch::SetExternalLookup ( ExternalPreprocessorSource EPS)
inline

Definition at line 430 of file HeaderSearch.h.

◆ SetExternalSource()

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

Set the external source of header information.

Definition at line 439 of file HeaderSearch.h.

◆ SetFileControllingMacro()

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

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 546 of file HeaderSearch.h.

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

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

◆ setModuleCachePath()

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

Set the path to the module cache.

Definition at line 410 of file HeaderSearch.h.

◆ setModuleHash()

void clang::HeaderSearch::setModuleHash ( StringRef  Hash)
inline

Set the hash to use for module cache paths.

Definition at line 407 of file HeaderSearch.h.

◆ SetSearchPaths()

void HeaderSearch::SetSearchPaths ( std::vector< DirectoryLookup dirs,
unsigned  angledDirIdx,
unsigned  systemDirIdx,
bool  noCurDirSearch,
llvm::DenseMap< unsigned, unsigned searchDirToHSEntry 
)

Interface for setting the file search paths.

Definition at line 106 of file HeaderSearch.cpp.

◆ SetSystemHeaderPrefixes()

void clang::HeaderSearch::SetSystemHeaderPrefixes ( ArrayRef< std::pair< std::string, bool > >  P)
inline

Set the list of system header prefixes.

Definition at line 375 of file HeaderSearch.h.

References P.

◆ setTarget()

void HeaderSearch::setTarget ( const TargetInfo Target)

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

Definition at line 743 of file HeaderSearch.cpp.

References clang::ModuleMap::setTarget(), and clang::Target.

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

◆ ShouldEnterIncludeFile()

bool HeaderSearch::ShouldEnterIncludeFile ( Preprocessor PP,
const FileEntry File,
bool  isImport,
bool  ModulesEnabled,
Module M,
bool IsFirstIncludeOfFile 
)

◆ suggestPathToFileForDiagnostics() [1/2]

std::string HeaderSearch::suggestPathToFileForDiagnostics ( const FileEntry File,
llvm::StringRef  MainFile,
bool IsSystem = nullptr 
)

Suggest a path by which the specified file could be found, for use in diagnostics to suggest a #include.

Returned path will only contain forward slashes as separators. MainFile is the absolute path of the file that we are generating the diagnostics for. It will try to shorten the path using MainFile location, if none of the include search directories were prefix of File.

Parameters
IsSystemIf non-null, filled in to indicate whether the suggested path is relative to a system header directory.

Definition at line 1918 of file HeaderSearch.cpp.

References clang::File, and suggestPathToFileForDiagnostics().

Referenced by getHeaderNameForHeader(), and suggestPathToFileForDiagnostics().

◆ suggestPathToFileForDiagnostics() [2/2]

std::string HeaderSearch::suggestPathToFileForDiagnostics ( llvm::StringRef  File,
llvm::StringRef  WorkingDir,
llvm::StringRef  MainFile,
bool IsSystem = nullptr 
)

Suggest a path by which the specified file could be found, for use in diagnostics to suggest a #include.

Returned path will only contain forward slashes as separators. MainFile is the absolute path of the file that we are generating the diagnostics for. It will try to shorten the path using MainFile location, if none of the include search directories were prefix of File.

Parameters
WorkingDirIf non-empty, this will be prepended to search directory paths that are relative.

Definition at line 1927 of file HeaderSearch.cpp.

References clang::File, Filename, isFrameworkStylePath(), and search_dir_range().

◆ system_dir_begin()

ConstSearchDirIterator clang::HeaderSearch::system_dir_begin ( ) const
inline

Definition at line 835 of file HeaderSearch.h.

Referenced by angled_dir_end().

◆ system_dir_end()

ConstSearchDirIterator clang::HeaderSearch::system_dir_end ( ) const
inline

Definition at line 838 of file HeaderSearch.h.

Referenced by search_dir_end().

Friends And Related Function Documentation

◆ DirectoryLookup

friend class DirectoryLookup
friend

Definition at line 224 of file HeaderSearch.h.


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