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

This class handles loading and caching of source files into memory. More...

#include "clang/Basic/SourceManager.h"

Inheritance diagram for clang::SourceManager:
Inheritance graph
[legend]
Collaboration diagram for clang::SourceManager:
Collaboration graph
[legend]

Classes

struct  MemoryBufferSizes
 

Public Types

enum  UnownedTag { Unowned }
 
using fileinfo_iterator = llvm::DenseMap< const FileEntry *, SrcMgr::ContentCache * >::const_iterator
 

Public Member Functions

 SourceManager (DiagnosticsEngine &Diag, FileManager &FileMgr, bool UserFilesAreVolatile=false)
 
 SourceManager (const SourceManager &)=delete
 
SourceManageroperator= (const SourceManager &)=delete
 
 ~SourceManager ()
 
void clearIDTables ()
 
void initializeForReplay (const SourceManager &Old)
 Initialize this source manager suitably to replay the compilation described by Old. More...
 
DiagnosticsEnginegetDiagnostics () const
 
FileManagergetFileManager () const
 
void setOverridenFilesKeepOriginalName (bool value)
 Set true if the SourceManager should report the original file name for contents of files that were overridden by other files. More...
 
bool userFilesAreVolatile () const
 True if non-system source files should be treated as volatile (likely to change while trying to use them). More...
 
ModuleBuildStack getModuleBuildStack () const
 Retrieve the module build stack. More...
 
void setModuleBuildStack (ModuleBuildStack stack)
 Set the module build stack. More...
 
void pushModuleBuildStack (StringRef moduleName, FullSourceLoc importLoc)
 Push an entry to the module build stack. More...
 
FileID getMainFileID () const
 Returns the FileID of the main source file. More...
 
void setMainFileID (FileID FID)
 Set the file ID for the main source file. More...
 
void setPreambleFileID (FileID Preamble)
 Set the file ID for the precompiled preamble. More...
 
FileID getPreambleFileID () const
 Get the file ID for the precompiled preamble if there is one. More...
 
FileID createFileID (const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
 Create a new FileID that represents the specified file being #included from the specified IncludePosition. More...
 
FileID createFileID (std::unique_ptr< llvm::MemoryBuffer > Buffer, SrcMgr::CharacteristicKind FileCharacter=SrcMgr::C_User, int LoadedID=0, unsigned LoadedOffset=0, SourceLocation IncludeLoc=SourceLocation())
 Create a new FileID that represents the specified memory buffer. More...
 
FileID createFileID (UnownedTag, llvm::MemoryBuffer *Buffer, SrcMgr::CharacteristicKind FileCharacter=SrcMgr::C_User, int LoadedID=0, unsigned LoadedOffset=0, SourceLocation IncludeLoc=SourceLocation())
 Create a new FileID that represents the specified memory buffer. More...
 
FileID getOrCreateFileID (const FileEntry *SourceFile, SrcMgr::CharacteristicKind FileCharacter)
 Get the FileID for SourceFile if it exists. More...
 
SourceLocation createMacroArgExpansionLoc (SourceLocation Loc, SourceLocation ExpansionLoc, unsigned TokLength)
 Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be referenced from ExpansionLoc, and that it represents the expansion of a macro argument into the function-like macro body. More...
 
SourceLocation createExpansionLoc (SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
 Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be referenced from ExpansionLoc. More...
 
llvm::MemoryBuffer * getMemoryBufferForFile (const FileEntry *File, bool *Invalid=nullptr)
 Retrieve the memory buffer associated with the given file. More...
 
void overrideFileContents (const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
 Override the contents of the given source file by providing an already-allocated buffer. More...
 
void overrideFileContents (const FileEntry *SourceFile, std::unique_ptr< llvm::MemoryBuffer > Buffer)
 
void overrideFileContents (const FileEntry *SourceFile, const FileEntry *NewFile)
 Override the given source file with another one. More...
 
bool isFileOverridden (const FileEntry *File) const
 Returns true if the file contents have been overridden. More...
 
void disableFileContentsOverride (const FileEntry *File)
 Disable overridding the contents of a file, previously enabled with overrideFileContents. More...
 
void setFileIsTransient (const FileEntry *SourceFile)
 Specify that a file is transient. More...
 
void setAllFilesAreTransient (bool Transient)
 Specify that all files that are read during this compilation are transient. More...
 
llvm::MemoryBuffer * getBuffer (FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
 Return the buffer for the specified FileID. More...
 
llvm::MemoryBuffer * getBuffer (FileID FID, bool *Invalid=nullptr) const
 
const FileEntrygetFileEntryForID (FileID FID) const
 Returns the FileEntry record for the provided FileID. More...
 
const FileEntrygetFileEntryForSLocEntry (const SrcMgr::SLocEntry &sloc) const
 Returns the FileEntry record for the provided SLocEntry. More...
 
StringRef getBufferData (FileID FID, bool *Invalid=nullptr) const
 Return a StringRef to the source buffer data for the specified FileID. More...
 
unsigned getNumCreatedFIDsForFileID (FileID FID) const
 Get the number of FileIDs (files and macros) that were created during preprocessing of FID, including it. More...
 
void setNumCreatedFIDsForFileID (FileID FID, unsigned NumFIDs) const
 Set the number of FileIDs (files and macros) that were created during preprocessing of FID, including it. More...
 
FileID getFileID (SourceLocation SpellingLoc) const
 Return the FileID for a SourceLocation. More...
 
StringRef getFilename (SourceLocation SpellingLoc) const
 Return the filename of the file containing a SourceLocation. More...
 
SourceLocation getLocForStartOfFile (FileID FID) const
 Return the source location corresponding to the first byte of the specified file. More...
 
SourceLocation getLocForEndOfFile (FileID FID) const
 Return the source location corresponding to the last byte of the specified file. More...
 
SourceLocation getIncludeLoc (FileID FID) const
 Returns the include location if FID is a #include'd file otherwise it returns an invalid location. More...
 
std::pair< SourceLocation, StringRef > getModuleImportLoc (SourceLocation Loc) const
 
SourceLocation getExpansionLoc (SourceLocation Loc) const
 Given a SourceLocation object Loc, return the expansion location referenced by the ID. More...
 
SourceLocation getFileLoc (SourceLocation Loc) const
 Given Loc, if it is a macro location return the expansion location or the spelling location, depending on if it comes from a macro argument or not. More...
 
std::pair< SourceLocation, SourceLocationgetImmediateExpansionRange (SourceLocation Loc) const
 Return the start/end of the expansion information for an expansion location. More...
 
std::pair< SourceLocation, SourceLocationgetExpansionRange (SourceLocation Loc) const
 Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate file. More...
 
SourceRange getExpansionRange (SourceRange Range) const
 Given a SourceRange object, return the range of tokens covered by the expansion in the ultimate file. More...
 
SourceLocation getSpellingLoc (SourceLocation Loc) const
 Given a SourceLocation object, return the spelling location referenced by the ID. More...
 
SourceLocation getImmediateSpellingLoc (SourceLocation Loc) const
 Given a SourceLocation object, return the spelling location referenced by the ID. More...
 
std::pair< FileID, unsigned > getDecomposedLoc (SourceLocation Loc) const
 Decompose the specified location into a raw FileID + Offset pair. More...
 
std::pair< FileID, unsigned > getDecomposedExpansionLoc (SourceLocation Loc) const
 Decompose the specified location into a raw FileID + Offset pair. More...
 
std::pair< FileID, unsigned > getDecomposedSpellingLoc (SourceLocation Loc) const
 Decompose the specified location into a raw FileID + Offset pair. More...
 
std::pair< FileID, unsigned > getDecomposedIncludedLoc (FileID FID) const
 Returns the "included/expanded in" decomposed location of the given FileID. More...
 
unsigned getFileOffset (SourceLocation SpellingLoc) const
 Returns the offset from the start of the file that the specified SourceLocation represents. More...
 
bool isMacroArgExpansion (SourceLocation Loc, SourceLocation *StartLoc=nullptr) const
 Tests whether the given source location represents a macro argument's expansion into the function-like macro definition. More...
 
bool isMacroBodyExpansion (SourceLocation Loc) const
 Tests whether the given source location represents the expansion of a macro body. More...
 
bool isAtStartOfImmediateMacroExpansion (SourceLocation Loc, SourceLocation *MacroBegin=nullptr) const
 Returns true if the given MacroID location points at the beginning of the immediate macro expansion. More...
 
bool isAtEndOfImmediateMacroExpansion (SourceLocation Loc, SourceLocation *MacroEnd=nullptr) const
 Returns true if the given MacroID location points at the character end of the immediate macro expansion. More...
 
bool isInSLocAddrSpace (SourceLocation Loc, SourceLocation Start, unsigned Length, unsigned *RelativeOffset=nullptr) const
 Returns true if Loc is inside the [Start, +Length) chunk of the source location address space. More...
 
bool isInSameSLocAddrSpace (SourceLocation LHS, SourceLocation RHS, int *RelativeOffset) const
 Return true if both LHS and RHS are in the local source location address space or the loaded one. More...
 
const char * getCharacterData (SourceLocation SL, bool *Invalid=nullptr) const
 Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer. More...
 
unsigned getColumnNumber (FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
 Return the column # for the specified file position. More...
 
unsigned getSpellingColumnNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
unsigned getExpansionColumnNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
unsigned getPresumedColumnNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
unsigned getLineNumber (FileID FID, unsigned FilePos, bool *Invalid=nullptr) const
 Given a SourceLocation, return the spelling line number for the position indicated. More...
 
unsigned getSpellingLineNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
unsigned getExpansionLineNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
unsigned getPresumedLineNumber (SourceLocation Loc, bool *Invalid=nullptr) const
 
StringRef getBufferName (SourceLocation Loc, bool *Invalid=nullptr) const
 Return the filename or buffer identifier of the buffer the location is in. More...
 
SrcMgr::CharacteristicKind getFileCharacteristic (SourceLocation Loc) const
 Return the file characteristic of the specified source location, indicating whether this is a normal file, a system header, or an "implicit extern C" system header. More...
 
PresumedLoc getPresumedLoc (SourceLocation Loc, bool UseLineDirectives=true) const
 Returns the "presumed" location of a SourceLocation specifies. More...
 
bool isInMainFile (SourceLocation Loc) const
 Returns whether the PresumedLoc for a given SourceLocation is in the main file. More...
 
bool isWrittenInSameFile (SourceLocation Loc1, SourceLocation Loc2) const
 Returns true if the spelling locations for both SourceLocations are part of the same file buffer. More...
 
bool isWrittenInMainFile (SourceLocation Loc) const
 Returns true if the spelling location for the given location is in the main file buffer. More...
 
bool isInSystemHeader (SourceLocation Loc) const
 Returns if a SourceLocation is in a system header. More...
 
bool isInExternCSystemHeader (SourceLocation Loc) const
 Returns if a SourceLocation is in an "extern C" system header. More...
 
bool isInSystemMacro (SourceLocation loc) const
 Returns whether Loc is expanded from a macro in a system header. More...
 
unsigned getFileIDSize (FileID FID) const
 The size of the SLocEntry that FID represents. More...
 
bool isInFileID (SourceLocation Loc, FileID FID, unsigned *RelativeOffset=nullptr) const
 Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (offset of Loc from beginning of FileID) to relativeOffset. More...
 
unsigned getLineTableFilenameID (StringRef Str)
 Return the uniqued ID for the specified filename. More...
 
void AddLineNote (SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, SrcMgr::CharacteristicKind FileKind)
 Add a line note to the line table for the FileID and offset specified by Loc. More...
 
bool hasLineTable () const
 Determine if the source manager has a line table. More...
 
LineTableInfogetLineTable ()
 Retrieve the stored line table. More...
 
size_t getContentCacheSize () const
 Return the total amount of physical memory allocated by the ContentCache allocator. More...
 
MemoryBufferSizes getMemoryBufferSizes () const
 Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memory. More...
 
size_t getDataStructureSizes () const
 Return the amount of memory used for various side tables and data structures in the SourceManager. More...
 
SourceLocation translateFileLineCol (const FileEntry *SourceFile, unsigned Line, unsigned Col) const
 Get the source location for the given file:line:col triplet. More...
 
FileID translateFile (const FileEntry *SourceFile) const
 Get the FileID for the given file. More...
 
SourceLocation translateLineCol (FileID FID, unsigned Line, unsigned Col) const
 Get the source location in FID for the given line:col. More...
 
SourceLocation getMacroArgExpandedLocation (SourceLocation Loc) const
 If Loc points inside a function macro argument, the returned location will be the macro location in which the argument was expanded. More...
 
bool isBeforeInTranslationUnit (SourceLocation LHS, SourceLocation RHS) const
 Determines the order of 2 source locations in the translation unit. More...
 
std::pair< bool, boolisInTheSameTranslationUnit (std::pair< FileID, unsigned > &LOffs, std::pair< FileID, unsigned > &ROffs) const
 Determines whether the two decomposed source location is in the same translation unit. More...
 
bool isBeforeInSLocAddrSpace (SourceLocation LHS, SourceLocation RHS) const
 Determines the order of 2 source locations in the "source location address space". More...
 
bool isBeforeInSLocAddrSpace (SourceLocation LHS, unsigned RHS) const
 Determines the order of a source location and a source location offset in the "source location address space". More...
 
bool isPointWithin (SourceLocation Location, SourceLocation Start, SourceLocation End) const
 Return true if the Point is within Start and End. More...
 
fileinfo_iterator fileinfo_begin () const
 
fileinfo_iterator fileinfo_end () const
 
bool hasFileInfo (const FileEntry *File) const
 
void PrintStats () const
 Print statistics to stderr. More...
 
void dump () const
 
unsigned local_sloc_entry_size () const
 Get the number of local SLocEntries we have. More...
 
const SrcMgr::SLocEntrygetLocalSLocEntry (unsigned Index, bool *Invalid=nullptr) const
 Get a local SLocEntry. This is exposed for indexing. More...
 
unsigned loaded_sloc_entry_size () const
 Get the number of loaded SLocEntries we have. More...
 
const SrcMgr::SLocEntrygetLoadedSLocEntry (unsigned Index, bool *Invalid=nullptr) const
 Get a loaded SLocEntry. This is exposed for indexing. More...
 
const SrcMgr::SLocEntrygetSLocEntry (FileID FID, bool *Invalid=nullptr) const
 
unsigned getNextLocalOffset () const
 
void setExternalSLocEntrySource (ExternalSLocEntrySource *Source)
 
std::pair< int, unsigned > AllocateLoadedSLocEntries (unsigned NumSLocEntries, unsigned TotalSize)
 Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external source. More...
 
bool isLoadedSourceLocation (SourceLocation Loc) const
 Returns true if Loc came from a PCH/Module. More...
 
bool isLocalSourceLocation (SourceLocation Loc) const
 Returns true if Loc did not come from a PCH/Module. More...
 
bool isLoadedFileID (FileID FID) const
 Returns true if FID came from a PCH/Module. More...
 
bool isLocalFileID (FileID FID) const
 Returns true if FID did not come from a PCH/Module. More...
 
SourceLocation getImmediateMacroCallerLoc (SourceLocation Loc) const
 Gets the location of the immediate macro caller, one level up the stack toward the initial macro typed into the source. More...
 

Friends

class ASTReader
 
class ASTWriter
 

Detailed Description

This class handles loading and caching of source files into memory.

This object owns the MemoryBuffer objects for all of the loaded files and assigns unique FileID's for each unique #include chain.

The SourceManager can be queried for information about SourceLocation objects, turning them into either spelling or expansion locations. Spelling locations represent where the bytes corresponding to a token came from and expansion locations represent where the location is in the user's view. In the case of a macro expansion, for example, the spelling location indicates where the expanded token came from and the expansion location specifies where it was expanded.

Definition at line 559 of file SourceManager.h.

Member Typedef Documentation

◆ fileinfo_iterator

using clang::SourceManager::fileinfo_iterator = llvm::DenseMap<const FileEntry*, SrcMgr::ContentCache*>::const_iterator

Definition at line 1539 of file SourceManager.h.

Member Enumeration Documentation

◆ UnownedTag

Enumerator
Unowned 

Definition at line 816 of file SourceManager.h.

Constructor & Destructor Documentation

◆ SourceManager() [1/2]

SourceManager::SourceManager ( DiagnosticsEngine Diag,
FileManager FileMgr,
bool  UserFilesAreVolatile = false 
)

◆ SourceManager() [2/2]

clang::SourceManager::SourceManager ( const SourceManager )
explicitdelete

◆ ~SourceManager()

SourceManager::~SourceManager ( )

Definition at line 320 of file SourceManager.cpp.

Member Function Documentation

◆ AddLineNote()

void SourceManager::AddLineNote ( SourceLocation  Loc,
unsigned  LineNo,
int  FilenameID,
bool  IsFileEntry,
bool  IsFileExit,
SrcMgr::CharacteristicKind  FileKind 
)

Add a line note to the line table for the FileID and offset specified by Loc.

AddLineNote - Add a line note to the line table for the FileID and offset specified by Loc.

If FilenameID is -1, it is considered to be unspecified.

Definition at line 275 of file SourceManager.cpp.

References clang::SrcMgr::SLocEntry::getFile(), and clang::SrcMgr::SLocEntry::isFile().

◆ AllocateLoadedSLocEntries()

std::pair< int, unsigned > SourceManager::AllocateLoadedSLocEntries ( unsigned  NumSLocEntries,
unsigned  TotalSize 
)

Allocate a number of loaded SLocEntries, which will be actually loaded on demand from the external source.

NumSLocEntries will be allocated, which occupy a total of TotalSize space in the global source view. The lowest ID and the base offset of the entries will be returned.

Definition at line 455 of file SourceManager.cpp.

References createFileID(), clang::SrcMgr::ContentCache::getSize(), clang::FileID::isInvalid(), and local_sloc_entry_size().

◆ clearIDTables()

void SourceManager::clearIDTables ( )

Definition at line 341 of file SourceManager.cpp.

References clang::LineTableInfo::clear(), and createExpansionLoc().

Referenced by SourceManager().

◆ createExpansionLoc()

SourceLocation SourceManager::createExpansionLoc ( SourceLocation  Loc,
SourceLocation  ExpansionLocStart,
SourceLocation  ExpansionLocEnd,
unsigned  TokLength,
int  LoadedID = 0,
unsigned  LoadedOffset = 0 
)

Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be referenced from ExpansionLoc.

Definition at line 575 of file SourceManager.cpp.

References clang::serialized_diags::create().

Referenced by clearIDTables(), clang::Lexer::Create_PragmaLexer(), clang::Preprocessor::CreateString(), ExpectFeatureIdentifierInfo(), clang::TokenLexer::Init(), isTrivialSingleTokenExpansion(), and clang::TokenLexer::Lex().

◆ createFileID() [1/3]

FileID clang::SourceManager::createFileID ( const FileEntry SourceFile,
SourceLocation  IncludePos,
SrcMgr::CharacteristicKind  FileCharacter,
int  LoadedID = 0,
unsigned  LoadedOffset = 0 
)
inline

Create a new FileID that represents the specified file being #included from the specified IncludePosition.

This translates NULL into standard input.

Definition at line 794 of file SourceManager.h.

References clang::SrcMgr::isSystem().

Referenced by AllocateLoadedSLocEntries(), clang::tooling::applyAllReplacements(), applyEditsToTemp(), ConvertBackendLocation(), clang::Preprocessor::EnterMainSourceFile(), clang::ScratchBuffer::getToken(), and clang::ASTImporter::Import().

◆ createFileID() [2/3]

FileID clang::SourceManager::createFileID ( std::unique_ptr< llvm::MemoryBuffer >  Buffer,
SrcMgr::CharacteristicKind  FileCharacter = SrcMgr::C_User,
int  LoadedID = 0,
unsigned  LoadedOffset = 0,
SourceLocation  IncludeLoc = SourceLocation() 
)
inline

Create a new FileID that represents the specified memory buffer.

This does no caching of the buffer and takes ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.

Definition at line 807 of file SourceManager.h.

◆ createFileID() [3/3]

FileID clang::SourceManager::createFileID ( UnownedTag  ,
llvm::MemoryBuffer *  Buffer,
SrcMgr::CharacteristicKind  FileCharacter = SrcMgr::C_User,
int  LoadedID = 0,
unsigned  LoadedOffset = 0,
SourceLocation  IncludeLoc = SourceLocation() 
)
inline

Create a new FileID that represents the specified memory buffer.

This does no caching of the buffer and takes ownership of the MemoryBuffer, so only pass a MemoryBuffer to this once.

Definition at line 822 of file SourceManager.h.

◆ createMacroArgExpansionLoc()

SourceLocation SourceManager::createMacroArgExpansionLoc ( SourceLocation  Loc,
SourceLocation  ExpansionLoc,
unsigned  TokLength 
)

Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be referenced from ExpansionLoc, and that it represents the expansion of a macro argument into the function-like macro body.

Definition at line 566 of file SourceManager.cpp.

Referenced by updateConsecutiveMacroArgTokens().

◆ disableFileContentsOverride()

void SourceManager::disableFileContentsOverride ( const FileEntry File)

Disable overridding the contents of a file, previously enabled with overrideFileContents.

This should be called before parsing has begun.

Definition at line 639 of file SourceManager.cpp.

References isFileOverridden(), and clang::SrcMgr::ContentCache::OrigEntry.

◆ dump()

LLVM_DUMP_METHOD void SourceManager::dump ( ) const

◆ fileinfo_begin()

fileinfo_iterator clang::SourceManager::fileinfo_begin ( ) const
inline

Definition at line 1541 of file SourceManager.h.

◆ fileinfo_end()

fileinfo_iterator clang::SourceManager::fileinfo_end ( ) const
inline

Definition at line 1542 of file SourceManager.h.

◆ getBuffer() [1/2]

llvm::MemoryBuffer* clang::SourceManager::getBuffer ( FileID  FID,
SourceLocation  Loc,
bool Invalid = nullptr 
) const
inline

◆ getBuffer() [2/2]

llvm::MemoryBuffer* clang::SourceManager::getBuffer ( FileID  FID,
bool Invalid = nullptr 
) const
inline

◆ getBufferData()

StringRef SourceManager::getBufferData ( FileID  FID,
bool Invalid = nullptr 
) const

◆ getBufferName()

StringRef SourceManager::getBufferName ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

Return the filename or buffer identifier of the buffer the location is in.

Note that this name does not respect #line directives. Use getPresumedLoc for normal clients.

Definition at line 1422 of file SourceManager.cpp.

References getBuffer(), getFileID(), and isInvalid().

Referenced by clang::Preprocessor::CheckMacroName(), clang::CodeGen::CodeGenModule::EmitAnnotationUnit(), and clang::CoverageSourceInfo::SourceRangeSkipped().

◆ getCharacterData()

const char * SourceManager::getCharacterData ( SourceLocation  SL,
bool Invalid = nullptr 
) const

◆ getColumnNumber()

unsigned SourceManager::getColumnNumber ( FileID  FID,
unsigned  FilePos,
bool Invalid = nullptr 
) const

Return the column # for the specified file position.

getColumnNumber - Return the column # for the specified file position.

This is significantly cheaper to compute than the line number. This returns zero if the column number isn't known. This may only be called on a file sloc, so you must choose a spelling or expansion location before calling this method.

this is significantly cheaper to compute than the line number.

Definition at line 1097 of file SourceManager.cpp.

References getBuffer(), and clang::SrcMgr::ContentCache::SourceLineCache.

Referenced by getExpansionColumnNumber(), getPresumedLoc(), and getSpellingColumnNumber().

◆ getContentCacheSize()

size_t clang::SourceManager::getContentCacheSize ( ) const
inline

Return the total amount of physical memory allocated by the ContentCache allocator.

Definition at line 1440 of file SourceManager.h.

◆ getDataStructureSizes()

size_t SourceManager::getDataStructureSizes ( ) const

Return the amount of memory used for various side tables and data structures in the SourceManager.

Definition at line 2227 of file SourceManager.cpp.

◆ getDecomposedExpansionLoc()

std::pair<FileID, unsigned> clang::SourceManager::getDecomposedExpansionLoc ( SourceLocation  Loc) const
inline

Decompose the specified location into a raw FileID + Offset pair.

If the location is an expansion record, walk through it until we find the final location expanded.

Definition at line 1158 of file SourceManager.h.

Referenced by getExpansionColumnNumber(), getExpansionLineNumber(), getFileCharacteristic(), getPresumedLoc(), isGCCAsmStatement(), isInMainFile(), and ReadLineMarkerFlags().

◆ getDecomposedIncludedLoc()

std::pair< FileID, unsigned > SourceManager::getDecomposedIncludedLoc ( FileID  FID) const

◆ getDecomposedLoc()

std::pair<FileID, unsigned> clang::SourceManager::getDecomposedLoc ( SourceLocation  Loc) const
inline

Decompose the specified location into a raw FileID + Offset pair.

The first element is the FileID, the second is the offset from the start of the buffer of the location.

Definition at line 1144 of file SourceManager.h.

Referenced by clang::ASTUnit::addFileLevelDecl(), clang::arcmt::trans::MigrationContext::addPropertyAttribute(), clang::Lexer::findNextToken(), clang::arcmt::trans::findSemiAfterLocation(), getBeginningOfFileToken(), clang::Lexer::GetBeginningOfToken(), clang::ASTWriter::getDeclID(), getDecomposedIncludedLoc(), clang::Lexer::getImmediateMacroNameForDiagnostics(), getImmediateSpellingLoc(), clang::Lexer::getIndentationForLine(), clang::StringLiteral::getLocationOfByte(), getMacroArgExpandedLocation(), clang::tooling::getRangeSize(), clang::ASTContext::getRawCommentForDeclNoCache(), clang::Lexer::getRawToken(), clang::Lexer::getSourceText(), clang::Lexer::getSpelling(), clang::comments::Lexer::getSpelling(), hasSuperInitCall(), clang::ASTImporter::Import(), clang::index::IndexingContext::importedModule(), isAtStartOfImmediateMacroExpansion(), isBeforeInTranslationUnit(), loadModuleMapForModuleBuild(), LocPropertyAttribute(), makeRangeFromFileLocs(), clang::Sema::notePreviousDefinition(), onlyWhitespaceBetween(), printLoc(), clang::RawComment::RawComment(), clang::edit::Commit::replaceText(), clang::arcmt::trans::MigrationContext::rewritePropertyAttribute(), clang::DiagnosticsEngine::SetDelayedDiagnostic(), shouldReportOccurrenceForSystemDeclOnlyMode(), and clang::ento::SuppressInlineDefensiveChecksVisitor::VisitNode().

◆ getDecomposedSpellingLoc()

std::pair<FileID, unsigned> clang::SourceManager::getDecomposedSpellingLoc ( SourceLocation  Loc) const
inline

Decompose the specified location into a raw FileID + Offset pair.

If the location is an expansion record, walk through it until we find its spelling record.

Definition at line 1177 of file SourceManager.h.

Referenced by getCharacterData(), getSpellingColumnNumber(), and getSpellingLineNumber().

◆ getDiagnostics()

DiagnosticsEngine& clang::SourceManager::getDiagnostics ( ) const
inline

Definition at line 734 of file SourceManager.h.

References Diag().

Referenced by clang::ASTContext::getDiagnostics().

◆ getExpansionColumnNumber()

unsigned SourceManager::getExpansionColumnNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getExpansionLineNumber()

unsigned SourceManager::getExpansionLineNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getExpansionLoc()

SourceLocation clang::SourceManager::getExpansionLoc ( SourceLocation  Loc) const
inline

◆ getExpansionRange() [1/2]

std::pair< SourceLocation, SourceLocation > SourceManager::getExpansionRange ( SourceLocation  Loc) const

Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate file.

getExpansionRange - Given a SourceLocation object, return the range of tokens covered by the expansion in the ultimate file.

Definition at line 960 of file SourceManager.cpp.

References getImmediateExpansionRange(), and clang::SourceLocation::isFileID().

Referenced by ExpectFeatureIdentifierInfo(), getLengthOnSingleLine(), and clang::html::HighlightMacros().

◆ getExpansionRange() [2/2]

SourceRange clang::SourceManager::getExpansionRange ( SourceRange  Range) const
inline

Given a SourceRange object, return the range of tokens covered by the expansion in the ultimate file.

Definition at line 1115 of file SourceManager.h.

References clang::SourceRange::getBegin(), and clang::SourceRange::getEnd().

◆ getFileCharacteristic()

SrcMgr::CharacteristicKind SourceManager::getFileCharacteristic ( SourceLocation  Loc) const

Return the file characteristic of the specified source location, indicating whether this is a normal file, a system header, or an "implicit extern C" system header.

getFileCharacteristic - return the file characteristic of the specified source location, indicating whether this is a normal file, a system header, or an "implicit extern C" system header.

This state can be modified with flags on GNU linemarker directives like:

# 4 "foo.h" 3

which changes all source locations in the current file after that to be considered to be from a system header.

This state can be modified with flags on GNU linemarker directives like:

4 "foo.h" 3

which changes all source locations in the current file after that to be considered to be from a system header.

Definition at line 1392 of file SourceManager.cpp.

References clang::SrcMgr::C_User, clang::LineEntry::FileKind, clang::LineTableInfo::FindNearestLineEntry(), getDecomposedExpansionLoc(), clang::SrcMgr::SLocEntry::getFile(), clang::SrcMgr::FileInfo::getFileCharacteristic(), getSLocEntry(), clang::SrcMgr::FileInfo::hasLineDirectives(), clang::SrcMgr::SLocEntry::isFile(), and clang::SourceLocation::isValid().

◆ getFileEntryForID()

const FileEntry* clang::SourceManager::getFileEntryForID ( FileID  FID) const
inline

◆ getFileEntryForSLocEntry()

const FileEntry* clang::SourceManager::getFileEntryForSLocEntry ( const SrcMgr::SLocEntry sloc) const
inline

Returns the FileEntry record for the provided SLocEntry.

Definition at line 969 of file SourceManager.h.

References clang::SrcMgr::FileInfo::getContentCache(), clang::SrcMgr::SLocEntry::getFile(), and clang::SrcMgr::ContentCache::OrigEntry.

◆ getFileID()

FileID clang::SourceManager::getFileID ( SourceLocation  SpellingLoc) const
inline

◆ getFileIDSize()

unsigned SourceManager::getFileIDSize ( FileID  FID) const

The size of the SLocEntry that FID represents.

Definition at line 1531 of file SourceManager.cpp.

References getNextLocalOffset(), clang::SrcMgr::SLocEntry::getOffset(), getSLocEntry(), and local_sloc_entry_size().

Referenced by clang::CoverageSourceInfo::SourceRangeSkipped().

◆ getFileLoc()

SourceLocation clang::SourceManager::getFileLoc ( SourceLocation  Loc) const
inline

◆ getFileManager()

FileManager& clang::SourceManager::getFileManager ( ) const
inline

◆ getFilename()

StringRef clang::SourceManager::getFilename ( SourceLocation  SpellingLoc) const
inline

◆ getFileOffset()

unsigned clang::SourceManager::getFileOffset ( SourceLocation  SpellingLoc) const
inline

◆ getImmediateExpansionRange()

std::pair< SourceLocation, SourceLocation > SourceManager::getImmediateExpansionRange ( SourceLocation  Loc) const

Return the start/end of the expansion information for an expansion location.

getImmediateExpansionRange - Loc is required to be an expansion location.

Precondition
Loc is required to be an expansion location.

Return the start/end of the expansion information.

Definition at line 951 of file SourceManager.cpp.

References clang::SrcMgr::SLocEntry::getExpansion(), clang::SrcMgr::ExpansionInfo::getExpansionLocRange(), getFileID(), getSLocEntry(), and clang::SourceLocation::isMacroID().

Referenced by checkAllAtProps(), CheckMoveOnConstruction(), DiagnoseNullConversion(), getExpansionRange(), clang::Lexer::getImmediateMacroNameForDiagnostics(), getMacroArgExpansionFileIDs(), handleObjCOwnershipTypeAttr(), retrieveMacroLocation(), and clang::CoverageSourceInfo::SourceRangeSkipped().

◆ getImmediateMacroCallerLoc()

SourceLocation clang::SourceManager::getImmediateMacroCallerLoc ( SourceLocation  Loc) const
inline

Gets the location of the immediate macro caller, one level up the stack toward the initial macro typed into the source.

Definition at line 1623 of file SourceManager.h.

References clang::SourceLocation::isMacroID().

Referenced by DiagnoseNullConversion(), getTopMostMacro(), IsFromSameFile(), IsInAnyMacroBody(), and clang::ento::ConditionBRVisitor::patternMatch().

◆ getImmediateSpellingLoc()

SourceLocation SourceManager::getImmediateSpellingLoc ( SourceLocation  Loc) const

Given a SourceLocation object, return the spelling location referenced by the ID.

getImmediateSpellingLoc - Given a SourceLocation object, return the spelling location referenced by the ID.

This is the first level down towards the place where the characters that make up the lexed token can be found. This should not generally be used by clients.

Definition at line 941 of file SourceManager.cpp.

References getDecomposedLoc(), clang::SrcMgr::SLocEntry::getExpansion(), clang::SourceLocation::getLocWithOffset(), getSLocEntry(), clang::SrcMgr::ExpansionInfo::getSpellingLoc(), and clang::SourceLocation::isFileID().

Referenced by getMacroArgExpansionFileIDs(), clang::Lexer::makeFileCharRange(), clang::edit::Commit::replaceText(), and retrieveMacroLocation().

◆ getIncludeLoc()

SourceLocation clang::SourceManager::getIncludeLoc ( FileID  FID) const
inline

◆ getLineNumber()

unsigned SourceManager::getLineNumber ( FileID  FID,
unsigned  FilePos,
bool Invalid = nullptr 
) const

Given a SourceLocation, return the spelling line number for the position indicated.

getLineNumber - Given a SourceLocation, return the spelling line number for the position indicated.

This requires building and caching a table of line offsets for the MemoryBuffer, so this is not cheap: use only when about to emit a diagnostic.

SourceLineCache for it on demand.

Definition at line 1270 of file SourceManager.cpp.

References ComputeLineNumbers(), clang::SrcMgr::FileInfo::getContentCache(), clang::SrcMgr::SLocEntry::getFile(), getSLocEntry(), clang::SrcMgr::SLocEntry::isFile(), clang::FileID::isInvalid(), clang::SrcMgr::ContentCache::NumLines, and clang::SrcMgr::ContentCache::SourceLineCache.

Referenced by getExpansionLineNumber(), getPresumedLoc(), clang::ASTContext::getRawCommentForDeclNoCache(), getSpellingLineNumber(), and isGCCAsmStatement().

◆ getLineTable()

LineTableInfo & SourceManager::getLineTable ( )

Retrieve the stored line table.

Definition at line 303 of file SourceManager.cpp.

◆ getLineTableFilenameID()

unsigned SourceManager::getLineTableFilenameID ( StringRef  Str)

Return the uniqued ID for the specified filename.

getLineTableFilenameID - Return the uniqued ID for the specified filename.

Definition at line 268 of file SourceManager.cpp.

◆ getLoadedSLocEntry()

const SrcMgr::SLocEntry& clang::SourceManager::getLoadedSLocEntry ( unsigned  Index,
bool Invalid = nullptr 
) const
inline

Get a loaded SLocEntry. This is exposed for indexing.

Definition at line 1566 of file SourceManager.h.

◆ getLocalSLocEntry()

const SrcMgr::SLocEntry& clang::SourceManager::getLocalSLocEntry ( unsigned  Index,
bool Invalid = nullptr 
) const
inline

Get a local SLocEntry. This is exposed for indexing.

Definition at line 1556 of file SourceManager.h.

◆ getLocForEndOfFile()

SourceLocation clang::SourceManager::getLocForEndOfFile ( FileID  FID) const
inline

Return the source location corresponding to the last byte of the specified file.

Definition at line 1048 of file SourceManager.h.

References clang::SrcMgr::SLocEntry::getOffset(), and clang::SrcMgr::SLocEntry::isFile().

Referenced by clang::CoverageSourceInfo::SourceRangeSkipped().

◆ getLocForStartOfFile()

SourceLocation clang::SourceManager::getLocForStartOfFile ( FileID  FID) const
inline

◆ getMacroArgExpandedLocation()

SourceLocation SourceManager::getMacroArgExpandedLocation ( SourceLocation  Loc) const

If Loc points inside a function macro argument, the returned location will be the macro location in which the argument was expanded.

If.

If a macro argument is used multiple times, the expanded location will be at the first expansion of the argument. e.g. MY_MACRO(foo); ^ Passing a file location pointing at 'foo', will yield a macro location where 'foo' was expanded into.

  • Loc points inside a function macro argument, the returned location will be the macro location in which the argument was expanded. If a macro argument is used multiple times, the expanded location will be at the first expansion of the argument. e.g. MY_MACRO(foo); ^ Passing a file location pointing at 'foo', will yield a macro location where 'foo' was expanded into.

Definition at line 1910 of file SourceManager.cpp.

References getDecomposedLoc(), clang::SourceLocation::isFileID(), clang::FileID::isInvalid(), and clang::SourceLocation::isInvalid().

Referenced by clang::ASTUnit::getLocation().

◆ getMainFileID()

FileID clang::SourceManager::getMainFileID ( ) const
inline

◆ getMemoryBufferForFile()

llvm::MemoryBuffer * SourceManager::getMemoryBufferForFile ( const FileEntry File,
bool Invalid = nullptr 
)

Retrieve the memory buffer associated with the given file.

Parameters
InvalidIf non-NULL, will be set true if an error occurs while retrieving the memory buffer.

Definition at line 609 of file SourceManager.cpp.

References clang::SrcMgr::ContentCache::getBuffer().

◆ getMemoryBufferSizes()

SourceManager::MemoryBufferSizes SourceManager::getMemoryBufferSizes ( ) const

Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memory.

Definition at line 2209 of file SourceManager.cpp.

◆ getModuleBuildStack()

ModuleBuildStack clang::SourceManager::getModuleBuildStack ( ) const
inline

Retrieve the module build stack.

Definition at line 750 of file SourceManager.h.

Referenced by clang::CompilerInstance::loadModule(), and prepareToBuildModule().

◆ getModuleImportLoc()

std::pair<SourceLocation, StringRef> clang::SourceManager::getModuleImportLoc ( SourceLocation  Loc) const
inline

◆ getNextLocalOffset()

unsigned clang::SourceManager::getNextLocalOffset ( ) const
inline

Definition at line 1583 of file SourceManager.h.

Referenced by getFileIDSize(), and clang::TokenLexer::Init().

◆ getNumCreatedFIDsForFileID()

unsigned clang::SourceManager::getNumCreatedFIDsForFileID ( FileID  FID) const
inline

Get the number of FileIDs (files and macros) that were created during preprocessing of FID, including it.

Definition at line 986 of file SourceManager.h.

References clang::SrcMgr::SLocEntry::getFile(), and clang::SrcMgr::SLocEntry::isFile().

◆ getOrCreateFileID()

FileID clang::SourceManager::getOrCreateFileID ( const FileEntry SourceFile,
SrcMgr::CharacteristicKind  FileCharacter 
)
inline

Get the FileID for SourceFile if it exists.

Otherwise, create a new FileID for the SourceFile.

Definition at line 832 of file SourceManager.h.

References clang::FileID::isValid().

Referenced by clang::tooling::Replacement::apply().

◆ getPreambleFileID()

FileID clang::SourceManager::getPreambleFileID ( ) const
inline

Get the file ID for the precompiled preamble if there is one.

Definition at line 784 of file SourceManager.h.

◆ getPresumedColumnNumber()

unsigned SourceManager::getPresumedColumnNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getPresumedLineNumber()

unsigned SourceManager::getPresumedLineNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getPresumedLoc()

PresumedLoc SourceManager::getPresumedLoc ( SourceLocation  Loc,
bool  UseLineDirectives = true 
) const

Returns the "presumed" location of a SourceLocation specifies.

getPresumedLoc - This method returns the "presumed" location of a SourceLocation specifies.

A "presumed location" can be modified by #line or GNU line marker directives. This provides a view on the data that a user should see in diagnostics, for example.

Note that a presumed location is always given as the expansion point of an expansion location, not at the spelling location.

Returns
The presumed location of the specified SourceLocation. If the presumed location cannot be calculated (e.g., because Loc is invalid or the file containing Loc has changed on disk), returns an invalid presumed location.

A "presumed location" can be modified by #line or GNU line marker directives. This provides a view on the data that a user should see in diagnostics, for example.

Note that a presumed location is always given as the expansion point of an expansion location, not at the spelling location.

Definition at line 1436 of file SourceManager.cpp.

References clang::C, Filename, clang::LineTableInfo::FindNearestLineEntry(), clang::SrcMgr::ContentCache::getBuffer(), getColumnNumber(), clang::SrcMgr::FileInfo::getContentCache(), getDecomposedExpansionLoc(), clang::SrcMgr::SLocEntry::getFile(), clang::LineTableInfo::getFilename(), clang::SrcMgr::FileInfo::getIncludeLoc(), getLineNumber(), getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), clang::FileEntry::getName(), getSLocEntry(), clang::SrcMgr::FileInfo::hasLineDirectives(), clang::SrcMgr::SLocEntry::isFile(), clang::SourceLocation::isInvalid(), and clang::SrcMgr::ContentCache::OrigEntry.

Referenced by clang::AttachHeaderIncludeGen(), clang::DoPrintPreprocessedInput(), clang::CodeGen::CodeGenModule::EmitAnnotationLineNo(), clang::CodeGen::CodeGenModule::EmitAnnotationUnit(), clang::CodeGen::CodeGenFunction::EmitCheckSourceLocation(), ExpectFeatureIdentifierInfo(), getFunctionSourceLocation(), clang::getParameterABISpelling(), getPresumedColumnNumber(), getPresumedLineNumber(), getTargetEntryUniqueInfo(), clang::LogDiagnosticPrinter::HandleDiagnostic(), isBuiltinFile(), isCommandLineFile(), clang::SourceLocation::print(), ReadLineMarkerFlags(), and clang::CodeGen::CGDebugInfo::setLocation().

◆ getSLocEntry()

const SrcMgr::SLocEntry& clang::SourceManager::getSLocEntry ( FileID  FID,
bool Invalid = nullptr 
) const
inline

◆ getSpellingColumnNumber()

unsigned SourceManager::getSpellingColumnNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getSpellingLineNumber()

unsigned SourceManager::getSpellingLineNumber ( SourceLocation  Loc,
bool Invalid = nullptr 
) const

◆ getSpellingLoc()

SourceLocation clang::SourceManager::getSpellingLoc ( SourceLocation  Loc) const
inline

◆ hasFileInfo()

bool clang::SourceManager::hasFileInfo ( const FileEntry File) const
inline

Definition at line 1543 of file SourceManager.h.

References dump().

◆ hasLineTable()

bool clang::SourceManager::hasLineTable ( ) const
inline

Determine if the source manager has a line table.

Definition at line 1429 of file SourceManager.h.

◆ initializeForReplay()

void SourceManager::initializeForReplay ( const SourceManager Old)

Initialize this source manager suitably to replay the compilation described by Old.

Requires that Old outlive *this.

Definition at line 359 of file SourceManager.cpp.

References clang::FileID::isInvalid(), and clang::SrcMgr::ContentCache::OrigEntry.

◆ isAtEndOfImmediateMacroExpansion()

bool SourceManager::isAtEndOfImmediateMacroExpansion ( SourceLocation  Loc,
SourceLocation MacroEnd = nullptr 
) const

Returns true if the given MacroID location points at the character end of the immediate macro expansion.

Parameters
MacroEndIf non-null and function returns true, it is set to the character end location of the immediate macro expansion.

Definition at line 1031 of file SourceManager.cpp.

References clang::SrcMgr::SLocEntry::getExpansion(), clang::SrcMgr::ExpansionInfo::getExpansionLocEnd(), clang::SrcMgr::ExpansionInfo::getExpansionLocStart(), getFileID(), clang::SourceLocation::getLocWithOffset(), getSLocEntry(), clang::SrcMgr::SLocEntry::isExpansion(), isInFileID(), clang::FileID::isInvalid(), clang::SrcMgr::ExpansionInfo::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), and clang::SourceLocation::isValid().

Referenced by clang::Lexer::isAtEndOfMacroExpansion().

◆ isAtStartOfImmediateMacroExpansion()

bool SourceManager::isAtStartOfImmediateMacroExpansion ( SourceLocation  Loc,
SourceLocation MacroBegin = nullptr 
) const

Returns true if the given MacroID location points at the beginning of the immediate macro expansion.

Parameters
MacroBeginIf non-null and function returns true, it is set to the begin location of the immediate macro expansion.

Definition at line 996 of file SourceManager.cpp.

References getDecomposedLoc(), clang::SrcMgr::SLocEntry::getExpansion(), clang::SrcMgr::ExpansionInfo::getExpansionLocStart(), getSLocEntry(), clang::SrcMgr::SLocEntry::isExpansion(), clang::FileID::isInvalid(), clang::SrcMgr::ExpansionInfo::isMacroArgExpansion(), clang::SourceLocation::isMacroID(), and clang::SourceLocation::isValid().

Referenced by CheckMoveOnConstruction(), and clang::Lexer::isAtStartOfMacroExpansion().

◆ isBeforeInSLocAddrSpace() [1/2]

bool clang::SourceManager::isBeforeInSLocAddrSpace ( SourceLocation  LHS,
SourceLocation  RHS 
) const
inline

Determines the order of 2 source locations in the "source location address space".

Definition at line 1511 of file SourceManager.h.

Referenced by clang::TokenLexer::Lex().

◆ isBeforeInSLocAddrSpace() [2/2]

bool clang::SourceManager::isBeforeInSLocAddrSpace ( SourceLocation  LHS,
unsigned  RHS 
) const
inline

Determines the order of a source location and a source location offset in the "source location address space".

Note that we always consider source locations loaded from

Definition at line 1519 of file SourceManager.h.

◆ isBeforeInTranslationUnit()

bool SourceManager::isBeforeInTranslationUnit ( SourceLocation  LHS,
SourceLocation  RHS 
) const

◆ isFileOverridden()

bool clang::SourceManager::isFileOverridden ( const FileEntry File) const
inline

Returns true if the file contents have been overridden.

Definition at line 891 of file SourceManager.h.

Referenced by disableFileContentsOverride().

◆ isInExternCSystemHeader()

bool clang::SourceManager::isInExternCSystemHeader ( SourceLocation  Loc) const
inline

Returns if a SourceLocation is in an "extern C" system header.

Definition at line 1386 of file SourceManager.h.

References clang::SrcMgr::C_ExternCSystem.

◆ isInFileID()

bool clang::SourceManager::isInFileID ( SourceLocation  Loc,
FileID  FID,
unsigned *  RelativeOffset = nullptr 
) const
inline

Given a specific FileID, returns true if Loc is inside that FileID chunk and sets relative offset (offset of Loc from beginning of FileID) to relativeOffset.

Definition at line 1401 of file SourceManager.h.

Referenced by clang::Lexer::getSourceText(), isAtEndOfImmediateMacroExpansion(), isPreprocessedEntityIfInFileID(), makeRangeFromFileLocs(), and clang::CoverageSourceInfo::SourceRangeSkipped().

◆ isInMainFile()

bool SourceManager::isInMainFile ( SourceLocation  Loc) const

◆ isInSameSLocAddrSpace()

bool clang::SourceManager::isInSameSLocAddrSpace ( SourceLocation  LHS,
SourceLocation  RHS,
int *  RelativeOffset 
) const
inline

Return true if both LHS and RHS are in the local source location address space or the loaded one.

If it's true and RelativeOffset is non-null, it will be set to the offset of RHS relative to LHS.

Definition at line 1268 of file SourceManager.h.

Referenced by updateConsecutiveMacroArgTokens().

◆ isInSLocAddrSpace()

bool clang::SourceManager::isInSLocAddrSpace ( SourceLocation  Loc,
SourceLocation  Start,
unsigned  Length,
unsigned *  RelativeOffset = nullptr 
) const
inline

Returns true if Loc is inside the [Start, +Length) chunk of the source location address space.

If it's true and RelativeOffset is non-null, it will be set to the relative offset of Loc inside the chunk.

Definition at line 1243 of file SourceManager.h.

Referenced by clang::TokenLexer::isParsingPreprocessorDirective().

◆ isInSystemHeader()

bool clang::SourceManager::isInSystemHeader ( SourceLocation  Loc) const
inline

◆ isInSystemMacro()

bool clang::SourceManager::isInSystemMacro ( SourceLocation  loc) const
inline

Returns whether Loc is expanded from a macro in a system header.

Definition at line 1391 of file SourceManager.h.

References clang::SourceLocation::isMacroID().

◆ isInTheSameTranslationUnit()

std::pair< bool, bool > SourceManager::isInTheSameTranslationUnit ( std::pair< FileID, unsigned > &  LOffs,
std::pair< FileID, unsigned > &  ROffs 
) const

Determines whether the two decomposed source location is in the same translation unit.

As a byproduct, it also calculates the order of the source locations in case they are in the same TU.

Returns
Pair of bools the first component is true if the two locations are in the same TU. The second bool is true if the first is true and LOffs is before ROffs.

Definition at line 2066 of file SourceManager.cpp.

References clang::InBeforeInTUCacheEntry::getCachedResult(), clang::InBeforeInTUCacheEntry::isCacheValid(), MoveUpIncludeHierarchy(), and clang::InBeforeInTUCacheEntry::setQueryFIDs().

Referenced by isBeforeInTranslationUnit().

◆ isLoadedFileID()

bool clang::SourceManager::isLoadedFileID ( FileID  FID) const
inline

Returns true if FID came from a PCH/Module.

Definition at line 1611 of file SourceManager.h.

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

◆ isLoadedSourceLocation()

bool clang::SourceManager::isLoadedSourceLocation ( SourceLocation  Loc) const
inline

Returns true if Loc came from a PCH/Module.

Definition at line 1601 of file SourceManager.h.

◆ isLocalFileID()

bool clang::SourceManager::isLocalFileID ( FileID  FID) const
inline

Returns true if FID did not come from a PCH/Module.

Definition at line 1617 of file SourceManager.h.

◆ isLocalSourceLocation()

bool clang::SourceManager::isLocalSourceLocation ( SourceLocation  Loc) const
inline

Returns true if Loc did not come from a PCH/Module.

Definition at line 1606 of file SourceManager.h.

Referenced by clang::ASTUnit::addFileLevelDecl(), clang::ASTWriter::getDeclID(), and clang::PreprocessingRecord::isEntityInFileID().

◆ isMacroArgExpansion()

bool SourceManager::isMacroArgExpansion ( SourceLocation  Loc,
SourceLocation StartLoc = nullptr 
) const

Tests whether the given source location represents a macro argument's expansion into the function-like macro definition.

Parameters
StartLocIf non-null and function returns true, it is set to the start location of the macro argument expansion.

Such source locations only appear inside of the expansion locations representing where a particular function-like macro was expanded.

Definition at line 975 of file SourceManager.cpp.

References clang::SrcMgr::SLocEntry::getExpansion(), clang::SrcMgr::ExpansionInfo::getExpansionLocStart(), getFileID(), getSLocEntry(), clang::SrcMgr::ExpansionInfo::isMacroArgExpansion(), and clang::SourceLocation::isMacroID().

Referenced by checkLocForMacroArgExpansion(), DiagnoseNullConversion(), clang::Lexer::GetBeginningOfToken(), clang::Lexer::getImmediateMacroNameForDiagnostics(), getMacroArgExpansionFileIDs(), clang::ASTContext::getRawCommentForDeclNoCache(), getStrlenExprArg(), clang::edit::Commit::replaceText(), and retrieveMacroLocation().

◆ isMacroBodyExpansion()

bool SourceManager::isMacroBodyExpansion ( SourceLocation  Loc) const

Tests whether the given source location represents the expansion of a macro body.

This is equivalent to testing whether the location is part of a macro expansion but not the expansion of an argument to a function-like macro.

Definition at line 988 of file SourceManager.cpp.

References clang::SrcMgr::SLocEntry::getExpansion(), getFileID(), getSLocEntry(), clang::SrcMgr::ExpansionInfo::isMacroBodyExpansion(), and clang::SourceLocation::isMacroID().

Referenced by IsInAnyMacroBody().

◆ isPointWithin()

bool clang::SourceManager::isPointWithin ( SourceLocation  Location,
SourceLocation  Start,
SourceLocation  End 
) const
inline

Return true if the Point is within Start and End.

Definition at line 1530 of file SourceManager.h.

◆ isWrittenInMainFile()

bool clang::SourceManager::isWrittenInMainFile ( SourceLocation  Loc) const
inline

Returns true if the spelling location for the given location is in the main file buffer.

This check ignores line marker directives.

Definition at line 1376 of file SourceManager.h.

Referenced by clang::CreateModernObjCRewriter(), clang::CreateObjCRewriter(), IsFromSameFile(), and clang::RewriteMacrosInInput().

◆ isWrittenInSameFile()

bool clang::SourceManager::isWrittenInSameFile ( SourceLocation  Loc1,
SourceLocation  Loc2 
) const
inline

Returns true if the spelling locations for both SourceLocations are part of the same file buffer.

This check ignores line marker directives.

Definition at line 1368 of file SourceManager.h.

Referenced by IsFromSameFile(), and updateConsecutiveMacroArgTokens().

◆ loaded_sloc_entry_size()

unsigned clang::SourceManager::loaded_sloc_entry_size ( ) const
inline

Get the number of loaded SLocEntries we have.

Definition at line 1563 of file SourceManager.h.

◆ local_sloc_entry_size()

unsigned clang::SourceManager::local_sloc_entry_size ( ) const
inline

Get the number of local SLocEntries we have.

Definition at line 1553 of file SourceManager.h.

Referenced by AllocateLoadedSLocEntries(), getFileIDSize(), and clang::PreprocessorLexer::PreprocessorLexer().

◆ operator=()

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

◆ overrideFileContents() [1/3]

void SourceManager::overrideFileContents ( const FileEntry SourceFile,
llvm::MemoryBuffer *  Buffer,
bool  DoNotFree 
)

Override the contents of the given source file by providing an already-allocated buffer.

Parameters
SourceFilethe source file whose contents will be overridden.
Bufferthe memory buffer whose contents will be used as the data in the given source file.
DoNotFreeIf true, then the buffer will not be freed when the source manager is destroyed.

Definition at line 616 of file SourceManager.cpp.

Referenced by InitializeFileRemapping().

◆ overrideFileContents() [2/3]

void clang::SourceManager::overrideFileContents ( const FileEntry SourceFile,
std::unique_ptr< llvm::MemoryBuffer >  Buffer 
)
inline

Definition at line 876 of file SourceManager.h.

◆ overrideFileContents() [3/3]

void SourceManager::overrideFileContents ( const FileEntry SourceFile,
const FileEntry NewFile 
)

Override the given source file with another one.

Parameters
SourceFilethe source file which will be overridden.
NewFilethe file whose contents will be used as the data instead of the contents of the given source file.

Definition at line 628 of file SourceManager.cpp.

References clang::FileEntry::getSize().

◆ PrintStats()

void SourceManager::PrintStats ( ) const

Print statistics to stderr.

Definition at line 2120 of file SourceManager.cpp.

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

◆ pushModuleBuildStack()

void clang::SourceManager::pushModuleBuildStack ( StringRef  moduleName,
FullSourceLoc  importLoc 
)
inline

Push an entry to the module build stack.

Definition at line 761 of file SourceManager.h.

Referenced by prepareToBuildModule().

◆ setAllFilesAreTransient()

void clang::SourceManager::setAllFilesAreTransient ( bool  Transient)
inline

Specify that all files that are read during this compilation are transient.

Definition at line 913 of file SourceManager.h.

◆ setExternalSLocEntrySource()

void clang::SourceManager::setExternalSLocEntrySource ( ExternalSLocEntrySource Source)
inline

Definition at line 1585 of file SourceManager.h.

◆ setFileIsTransient()

void SourceManager::setFileIsTransient ( const FileEntry SourceFile)

Specify that a file is transient.

Definition at line 652 of file SourceManager.cpp.

◆ setMainFileID()

void clang::SourceManager::setMainFileID ( FileID  FID)
inline

Set the file ID for the main source file.

Definition at line 773 of file SourceManager.h.

Referenced by clang::ento::ModelInjector::getBody().

◆ setModuleBuildStack()

void clang::SourceManager::setModuleBuildStack ( ModuleBuildStack  stack)
inline

Set the module build stack.

Definition at line 755 of file SourceManager.h.

◆ setNumCreatedFIDsForFileID()

void clang::SourceManager::setNumCreatedFIDsForFileID ( FileID  FID,
unsigned  NumFIDs 
) const
inline

Set the number of FileIDs (files and macros) that were created during preprocessing of FID, including it.

Definition at line 997 of file SourceManager.h.

References clang::SrcMgr::SLocEntry::getFile(), and clang::SrcMgr::SLocEntry::isFile().

◆ setOverridenFilesKeepOriginalName()

void clang::SourceManager::setOverridenFilesKeepOriginalName ( bool  value)
inline

Set true if the SourceManager should report the original file name for contents of files that were overridden by other files.

Defaults to true.

Definition at line 741 of file SourceManager.h.

Referenced by InitializeFileRemapping().

◆ setPreambleFileID()

void clang::SourceManager::setPreambleFileID ( FileID  Preamble)
inline

Set the file ID for the precompiled preamble.

Definition at line 778 of file SourceManager.h.

References clang::FileID::isInvalid().

◆ translateFile()

FileID SourceManager::translateFile ( const FileEntry SourceFile) const

◆ translateFileLineCol()

SourceLocation SourceManager::translateFileLineCol ( const FileEntry SourceFile,
unsigned  Line,
unsigned  Col 
) const

Get the source location for the given file:line:col triplet.

If the source file is included multiple times, the source location will be based upon the first inclusion.

If the source file is included multiple times, the source location will be based upon an arbitrary inclusion.

Definition at line 1573 of file SourceManager.cpp.

References translateFile(), and translateLineCol().

Referenced by clang::ASTUnit::getLocation().

◆ translateLineCol()

SourceLocation SourceManager::translateLineCol ( FileID  FID,
unsigned  Line,
unsigned  Col 
) const

Get the source location in FID for the given line:col.

Get the source location in.

Returns null location if FID is not a file SLocEntry.

  • FID for the given line:col. Returns null location if
  • FID is not a file SLocEntry.

Definition at line 1702 of file SourceManager.cpp.

References ComputeLineNumbers(), clang::SrcMgr::ContentCache::getBuffer(), clang::SrcMgr::FileInfo::getContentCache(), clang::SrcMgr::SLocEntry::getFile(), clang::SourceLocation::getLocWithOffset(), clang::SrcMgr::SLocEntry::getOffset(), getSLocEntry(), clang::SrcMgr::SLocEntry::isFile(), clang::FileID::isInvalid(), clang::SrcMgr::ContentCache::NumLines, and clang::SrcMgr::ContentCache::SourceLineCache.

Referenced by translateFileLineCol().

◆ userFilesAreVolatile()

bool clang::SourceManager::userFilesAreVolatile ( ) const
inline

True if non-system source files should be treated as volatile (likely to change while trying to use them).

Definition at line 747 of file SourceManager.h.

Referenced by clang::SrcMgr::ContentCache::getBuffer().

Friends And Related Function Documentation

◆ ASTReader

friend class ASTReader
friend

Definition at line 1638 of file SourceManager.h.

◆ ASTWriter

friend class ASTWriter
friend

Definition at line 1639 of file SourceManager.h.


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