clang API Documentation

Classes | Public Types | Public Member Functions | Friends
clang::SourceManager Class Reference

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

#include <SourceManager.h>

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

List of all members.

Classes

class  LocBeforeThanCompare
 Comparison function class. More...
struct  MemoryBufferSizes

Public Types

typedef llvm::DenseMap< const
FileEntry
*, SrcMgr::ContentCache * >
::const_iterator 
fileinfo_iterator

Public Member Functions

 SourceManager (DiagnosticsEngine &Diag, FileManager &FileMgr)
 ~SourceManager ()
void clearIDTables ()
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 overriden by other files.Defaults to true.
FileID createMainFileIDForMemBuffer (const llvm::MemoryBuffer *Buffer)
FileID getMainFileID () const
 getMainFileID - Returns the FileID of the main source file.
FileID createMainFileID (const FileEntry *SourceFile, SrcMgr::CharacteristicKind Kind=SrcMgr::C_User)
 createMainFileID - Create the FileID for the main source file.
void setMainFileID (FileID FID)
 Set the file ID for the main source file.
void setPreambleFileID (FileID Preamble)
 Set the file ID for the precompiled preamble.
FileID getPreambleFileID () const
 Get the file ID for the precompiled preamble if there is one.
FileID createFileID (const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
FileID createFileIDForMemBuffer (const llvm::MemoryBuffer *Buffer, int LoadedID=0, unsigned LoadedOffset=0, SourceLocation IncludeLoc=SourceLocation())
SourceLocation createMacroArgExpansionLoc (SourceLocation Loc, SourceLocation ExpansionLoc, unsigned TokLength)
SourceLocation createExpansionLoc (SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
const llvm::MemoryBuffer * getMemoryBufferForFile (const FileEntry *File, bool *Invalid=0)
 Retrieve the memory buffer associated with the given file.
void overrideFileContents (const FileEntry *SourceFile, const llvm::MemoryBuffer *Buffer, bool DoNotFree=false)
 Override the contents of the given source file by providing an already-allocated buffer.
void overrideFileContents (const FileEntry *SourceFile, const FileEntry *NewFile)
 Override the the given source file with another one.
const llvm::MemoryBuffer * getBuffer (FileID FID, SourceLocation Loc, bool *Invalid=0) const
const llvm::MemoryBuffer * getBuffer (FileID FID, bool *Invalid=0) const
const FileEntrygetFileEntryForID (FileID FID) const
 getFileEntryForID - Returns the FileEntry record for the provided FileID.
const FileEntrygetFileEntryForSLocEntry (const SrcMgr::SLocEntry &sloc) const
 Returns the FileEntry record for the provided SLocEntry.
StringRef getBufferData (FileID FID, bool *Invalid=0) const
unsigned getNumCreatedFIDsForFileID (FileID FID) const
 Get the number of FileIDs (files and macros) that were created during preprocessing of FID, including it.
void setNumCreatedFIDsForFileID (FileID FID, unsigned NumFIDs) const
 Set the number of FileIDs (files and macros) that were created during preprocessing of FID, including it.
FileID getFileID (SourceLocation SpellingLoc) const
SourceLocation getLocForStartOfFile (FileID FID) const
SourceLocation getLocForEndOfFile (FileID FID) const
 Return the source location corresponding to the last byte of the specified file.
SourceLocation getIncludeLoc (FileID FID) const
 Returns the include location if FID is a #include'd file otherwise it returns an invalid location.
SourceLocation getExpansionLoc (SourceLocation Loc) const
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.
std::pair< SourceLocation,
SourceLocation
getImmediateExpansionRange (SourceLocation Loc) const
std::pair< SourceLocation,
SourceLocation
getExpansionRange (SourceLocation Loc) const
SourceLocation getSpellingLoc (SourceLocation Loc) const
SourceLocation getImmediateSpellingLoc (SourceLocation Loc) const
std::pair< FileID, unsigned > getDecomposedLoc (SourceLocation Loc) const
std::pair< FileID, unsigned > getDecomposedExpansionLoc (SourceLocation Loc) const
std::pair< FileID, unsigned > getDecomposedSpellingLoc (SourceLocation Loc) const
unsigned getFileOffset (SourceLocation SpellingLoc) const
bool isMacroArgExpansion (SourceLocation Loc) const
bool isInSLocAddrSpace (SourceLocation Loc, SourceLocation Start, unsigned Length, unsigned *RelativeOffset=0) const
 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.
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. If it's true and RelativeOffset is non-null, it will be set to the offset of RHS relative to LHS.
const char * getCharacterData (SourceLocation SL, bool *Invalid=0) const
unsigned getColumnNumber (FileID FID, unsigned FilePos, bool *Invalid=0) const
unsigned getSpellingColumnNumber (SourceLocation Loc, bool *Invalid=0) const
unsigned getExpansionColumnNumber (SourceLocation Loc, bool *Invalid=0) const
unsigned getPresumedColumnNumber (SourceLocation Loc, bool *Invalid=0) const
unsigned getLineNumber (FileID FID, unsigned FilePos, bool *Invalid=0) const
unsigned getSpellingLineNumber (SourceLocation Loc, bool *Invalid=0) const
unsigned getExpansionLineNumber (SourceLocation Loc, bool *Invalid=0) const
unsigned getPresumedLineNumber (SourceLocation Loc, bool *Invalid=0) const
const char * getBufferName (SourceLocation Loc, bool *Invalid=0) const
SrcMgr::CharacteristicKind getFileCharacteristic (SourceLocation Loc) const
PresumedLoc getPresumedLoc (SourceLocation Loc) const
bool isFromSameFile (SourceLocation Loc1, SourceLocation Loc2) const
bool isFromMainFile (SourceLocation Loc) const
bool isInSystemHeader (SourceLocation Loc) const
 isInSystemHeader - Returns if a SourceLocation is in a system header.
bool isInExternCSystemHeader (SourceLocation Loc) const
bool isInSystemMacro (SourceLocation loc)
 Returns whether Loc is expanded from a macro in a system header.
unsigned getFileIDSize (FileID FID) const
 The size of the SLocEnty that FID represents.
bool isInFileID (SourceLocation Loc, FileID FID, unsigned *RelativeOffset=0) 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.
unsigned getLineTableFilenameID (StringRef Str)
void AddLineNote (SourceLocation Loc, unsigned LineNo, int FilenameID)
void AddLineNote (SourceLocation Loc, unsigned LineNo, int FilenameID, bool IsFileEntry, bool IsFileExit, bool IsSystemHeader, bool IsExternCHeader)
 AddLineNote - Add a GNU line marker to the line table.
bool hasLineTable () const
 Determine if the source manager has a line table.
LineTableInfogetLineTable ()
 Retrieve the stored line table.
size_t getContentCacheSize () const
MemoryBufferSizes getMemoryBufferSizes () const
size_t getDataStructureSizes () const
SourceLocation translateFileLineCol (const FileEntry *SourceFile, unsigned Line, unsigned Col) const
 Get the source location for the given file:line:col triplet.
FileID translateFile (const FileEntry *SourceFile) const
 Get the FileID for the given file.
SourceLocation translateLineCol (FileID FID, unsigned Line, unsigned Col) const
 Get the source location in FID for the given line:col. Returns null location if FID is not a file SLocEntry.
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. 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.
bool isBeforeInTranslationUnit (SourceLocation LHS, SourceLocation RHS) const
 Determines the order of 2 source locations in the translation unit.
bool isBeforeInSLocAddrSpace (SourceLocation LHS, SourceLocation RHS) const
 Determines the order of 2 source locations in the "source location address space".
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".
fileinfo_iterator fileinfo_begin () const
fileinfo_iterator fileinfo_end () const
bool hasFileInfo (const FileEntry *File) const
void PrintStats () const
unsigned local_sloc_entry_size () const
 Get the number of local SLocEntries we have.
const SrcMgr::SLocEntrygetLocalSLocEntry (unsigned Index, bool *Invalid=0) const
 Get a local SLocEntry. This is exposed for indexing.
unsigned loaded_sloc_entry_size () const
 Get the number of loaded SLocEntries we have.
const SrcMgr::SLocEntrygetLoadedSLocEntry (unsigned Index, bool *Invalid=0) const
 Get a loaded SLocEntry. This is exposed for indexing.
const SrcMgr::SLocEntrygetSLocEntry (FileID FID, bool *Invalid=0) 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.
bool isLoadedSourceLocation (SourceLocation Loc) const
 Returns true if Loc came from a PCH/Module.
bool isLocalSourceLocation (SourceLocation Loc) const
 Returns true if Loc did not come from a PCH/Module.
bool isLoadedFileID (FileID FID) const
 Returns true if FID came from a PCH/Module.
bool isLocalFileID (FileID FID) const
 Returns true if FID did not come from a PCH/Module.

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 486 of file SourceManager.h.


Member Typedef Documentation

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

Definition at line 1235 of file SourceManager.h.


Constructor & Destructor Documentation

SourceManager::SourceManager ( DiagnosticsEngine Diag,
FileManager FileMgr 
)
SourceManager::~SourceManager ( )

Definition at line 378 of file SourceManager.cpp.


Member Function Documentation

void SourceManager::AddLineNote ( SourceLocation  Loc,
unsigned  LineNo,
int  FilenameID 
)

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 295 of file SourceManager.cpp.

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

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

void SourceManager::AddLineNote ( SourceLocation  Loc,
unsigned  LineNo,
int  FilenameID,
bool  IsFileEntry,
bool  IsFileExit,
bool  IsSystemHeader,
bool  IsExternCHeader 
)

AddLineNote - Add a GNU line marker to the line table.

Definition at line 315 of file SourceManager.cpp.

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

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 473 of file SourceManager.cpp.

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

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

Definition at line 542 of file SourceManager.cpp.

References clang::serialized_diags::create().

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

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

createFileID - Create a new FileID that represents the specified file being #included from the specified IncludePosition. This translates NULL into standard input.

Definition at line 650 of file SourceManager.h.

Referenced by createFileIDForMemBuffer(), createMainFileID(), clang::ASTImporter::Import(), and clang::ModuleMap::parseModuleMapFile().

FileID clang::SourceManager::createFileIDForMemBuffer ( const llvm::MemoryBuffer *  Buffer,
int  LoadedID = 0,
unsigned  LoadedOffset = 0,
SourceLocation  IncludeLoc = SourceLocation() 
) [inline]

createFileIDForMemBuffer - 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 661 of file SourceManager.h.

References clang::SrcMgr::C_User, and createFileID().

Referenced by ConvertBackendLocation(), createMainFileIDForMemBuffer(), clang::Preprocessor::EnterMainSourceFile(), and clang::ASTImporter::Import().

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

createMacroArgExpansionLoc - 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 533 of file SourceManager.cpp.

Referenced by updateConsecutiveMacroArgTokens().

FileID clang::SourceManager::createMainFileID ( const FileEntry SourceFile,
SrcMgr::CharacteristicKind  Kind = SrcMgr::C_User 
) [inline]

createMainFileID - Create the FileID for the main source file.

Definition at line 621 of file SourceManager.h.

References createFileID(), and clang::FileID::isInvalid().

Referenced by clang::CompilerInstance::InitializeSourceManager().

FileID clang::SourceManager::createMainFileIDForMemBuffer ( const llvm::MemoryBuffer *  Buffer) [inline]

createMainFileIDForMembuffer - Create the FileID for a memory buffer that will represent the FileID for the main source. One example of when this would be used is when the main source is read from STDIN.

Definition at line 607 of file SourceManager.h.

References createFileIDForMemBuffer(), and clang::FileID::isInvalid().

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

Definition at line 1236 of file SourceManager.h.

Referenced by PrintStats().

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

Definition at line 1237 of file SourceManager.h.

Referenced by PrintStats().

const llvm::MemoryBuffer* clang::SourceManager::getBuffer ( FileID  FID,
SourceLocation  Loc,
bool *  Invalid = 0 
) const [inline]
const llvm::MemoryBuffer* clang::SourceManager::getBuffer ( FileID  FID,
bool *  Invalid = 0 
) const [inline]
StringRef SourceManager::getBufferData ( FileID  FID,
bool *  Invalid = 0 
) const
const char * SourceManager::getBufferName ( SourceLocation  Loc,
bool *  Invalid = 0 
) 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 1240 of file SourceManager.cpp.

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

Referenced by clang::CodeGen::CodeGenModule::EmitAnnotationUnit(), and clang::Preprocessor::EnterSourceFile().

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

getCharacterData - Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer.

Parameters:
InvalidIf non-NULL, will be set true if an error occurs.

getCharacterData - Return a pointer to the start of the specified location in the appropriate MemoryBuffer.

Definition at line 929 of file SourceManager.cpp.

References clang::SrcMgr::ContentCache::getBuffer(), clang::SrcMgr::FileInfo::getContentCache(), getDecomposedSpellingLoc(), clang::SrcMgr::SLocEntry::getFile(), getSLocEntry(), and clang::SrcMgr::SLocEntry::isFile().

Referenced by clang::Lexer::AdvanceToTokenCharacter(), clang::Lexer::Create_PragmaLexer(), clang::Preprocessor::DumpToken(), clang::Lexer::findLocationAfterToken(), GetFirstChar(), clang::Rewriter::getRewrittenText(), clang::Lexer::getSpelling(), and clang::Preprocessor::getSpellingOfSingleCharacterNumericConstant().

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

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.

getColumnNumber - Return the column # for the specified file position. this is significantly cheaper to compute than the line number.

Definition at line 955 of file SourceManager.cpp.

References getBuffer().

Referenced by clang::TextDiagnostic::emitDiagnosticLoc(), getExpansionColumnNumber(), getPresumedLoc(), and getSpellingColumnNumber().

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

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

Definition at line 1142 of file SourceManager.h.

size_t SourceManager::getDataStructureSizes ( ) const

Definition at line 1819 of file SourceManager.cpp.

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

getDecomposedExpansionLoc - 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 919 of file SourceManager.h.

References getFileID(), clang::SrcMgr::SLocEntry::getOffset(), getSLocEntry(), and clang::SourceLocation::isFileID().

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

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

getDecomposedSpellingLoc - 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 937 of file SourceManager.h.

References getFileID(), clang::SrcMgr::SLocEntry::getOffset(), getSLocEntry(), and clang::SourceLocation::isFileID().

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

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

Definition at line 594 of file SourceManager.h.

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

unsigned SourceManager::getExpansionColumnNumber ( SourceLocation  Loc,
bool *  Invalid = 0 
) const
unsigned SourceManager::getExpansionLineNumber ( SourceLocation  Loc,
bool *  Invalid = 0 
) const
SourceLocation clang::SourceManager::getExpansionLoc ( SourceLocation  Loc) const [inline]
std::pair< SourceLocation, SourceLocation > SourceManager::getExpansionRange ( SourceLocation  Loc) const

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

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

Definition at line 898 of file SourceManager.cpp.

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

Referenced by clang::TextDiagnostic::emitDiagnosticLoc(), and clang::html::HighlightMacros().

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

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.

Definition at line 1210 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::isInvalid().

Referenced by clang::Preprocessor::HandleEndOfFile(), isInExternCSystemHeader(), and isInSystemHeader().

const FileEntry* clang::SourceManager::getFileEntryForID ( FileID  FID) const [inline]
const FileEntry* clang::SourceManager::getFileEntryForSLocEntry ( const SrcMgr::SLocEntry sloc) const [inline]

Returns the FileEntry record for the provided SLocEntry.

Definition at line 767 of file SourceManager.h.

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

FileID clang::SourceManager::getFileID ( SourceLocation  SpellingLoc) const [inline]
unsigned SourceManager::getFileIDSize ( FileID  FID) const

The size of the SLocEnty that FID represents.

The size of the SLocEnty that.

  • FID represents.

Definition at line 1319 of file SourceManager.cpp.

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

Referenced by getLocForEndOfFile().

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

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.

Definition at line 871 of file SourceManager.h.

References clang::SourceLocation::isFileID().

Referenced by clang::ASTUnit::addFileLevelDecl(), getLocForEndOfFile(), getLocForStartOfFile(), isPreprocessedEntityIfInFileID(), and translateLineCol().

FileManager& clang::SourceManager::getFileManager ( ) const [inline]
unsigned clang::SourceManager::getFileOffset ( SourceLocation  SpellingLoc) const [inline]

getFileOffset - This method returns the offset from the start of the file that the specified SourceLocation represents. This is not very meaningful for a macro ID.

Definition at line 953 of file SourceManager.h.

References getDecomposedLoc().

Referenced by clang::html::HighlightRange(), clang::RewriteMacrosInInput(), and clang::html::SyntaxHighlight().

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

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 878 of file SourceManager.cpp.

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

Referenced by getImmediateMacroCalleeLoc(), getImmediateMacroCallerLoc(), and skipToMacroArgExpansion().

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

Returns the include location if FID is a #include'd file otherwise it returns an invalid location.

Definition at line 850 of file SourceManager.h.

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

Referenced by clang::Preprocessor::HandleEndOfFile(), and clang::ModuleMap::inferModuleFromLocation().

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

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 1064 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 clang::TextDiagnostic::emitDiagnosticLoc(), getExpansionLineNumber(), getPresumedLoc(), getSpellingLineNumber(), clang::Rewriter::IncreaseIndentation(), and clang::Rewriter::InsertText().

LineTableInfo & SourceManager::getLineTable ( )

Retrieve the stored line table.

Definition at line 360 of file SourceManager.cpp.

unsigned SourceManager::getLineTableFilenameID ( StringRef  Name)

getLineTableFilenameID - Return the uniqued ID for the specified filename.

Definition at line 285 of file SourceManager.cpp.

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

const SrcMgr::SLocEntry& clang::SourceManager::getLoadedSLocEntry ( unsigned  Index,
bool *  Invalid = 0 
) const [inline]

Get a loaded SLocEntry. This is exposed for indexing.

Definition at line 1260 of file SourceManager.h.

References Index, and clang::ExternalSLocEntrySource::ReadSLocEntry().

Referenced by translateFile().

const SrcMgr::SLocEntry& clang::SourceManager::getLocalSLocEntry ( unsigned  Index,
bool *  Invalid = 0 
) const [inline]

Get a local SLocEntry. This is exposed for indexing.

Definition at line 1250 of file SourceManager.h.

References Index.

Referenced by translateFile().

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

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

Definition at line 838 of file SourceManager.h.

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

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

SourceLocation clang::SourceManager::getLocForStartOfFile ( FileID  FID) const [inline]
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 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.

If.

  • 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 1650 of file SourceManager.cpp.

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

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

FileID clang::SourceManager::getMainFileID ( ) const [inline]
const llvm::MemoryBuffer * SourceManager::getMemoryBufferForFile ( const FileEntry File,
bool *  Invalid = 0 
)

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 577 of file SourceManager.cpp.

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

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

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 1801 of file SourceManager.cpp.

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

Definition at line 1276 of file SourceManager.h.

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

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 784 of file SourceManager.h.

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

FileID clang::SourceManager::getPreambleFileID ( ) const [inline]
unsigned SourceManager::getPresumedColumnNumber ( SourceLocation  Loc,
bool *  Invalid = 0 
) const
unsigned SourceManager::getPresumedLineNumber ( SourceLocation  Loc,
bool *  Invalid = 0 
) const

Definition at line 1195 of file SourceManager.cpp.

References clang::PresumedLoc::getLine(), getPresumedLoc(), and isInvalid().

Referenced by CheckLists(), and PrintProblem().

PresumedLoc SourceManager::getPresumedLoc ( SourceLocation  Loc) const

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 calculate (e.g., because Loc is invalid or the file containing Loc has changed on disk), returns an invalid presumed location.

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.

Definition at line 1255 of file SourceManager.cpp.

References 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::DoPrintPreprocessedInput(), clang::CodeGen::CodeGenModule::EmitAnnotationLineNo(), clang::CodeGen::CodeGenModule::EmitAnnotationUnit(), getDiagnosticPresumedLoc(), getPresumedColumnNumber(), getPresumedLineNumber(), clang::LogDiagnosticPrinter::HandleDiagnostic(), clang::Preprocessor::HandlePragmaSystemHeader(), clang::SourceLocation::print(), ReadLineMarkerFlags(), and clang::CodeGen::CGDebugInfo::setLocation().

const SrcMgr::SLocEntry& clang::SourceManager::getSLocEntry ( FileID  FID,
bool *  Invalid = 0 
) const [inline]
unsigned SourceManager::getSpellingColumnNumber ( SourceLocation  Loc,
bool *  Invalid = 0 
) const

Definition at line 987 of file SourceManager.cpp.

References getColumnNumber(), getDecomposedSpellingLoc(), and isInvalid().

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

Definition at line 1183 of file SourceManager.cpp.

References getDecomposedSpellingLoc(), getLineNumber(), and isInvalid().

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

getSpellingLoc - Given a SourceLocation object, return the spelling location referenced by the ID. This is the place where the characters that make up the lexed token can be found.

Definition at line 890 of file SourceManager.h.

References clang::SourceLocation::isFileID().

Referenced by AreTokensAdjacent(), clang::Lexer::GetBeginningOfToken(), GetFirstChar(), getImmediateMacroName(), clang::Lexer::getImmediateMacroName(), clang::StringLiteral::getLocationOfByte(), clang::ASTImporter::Import(), clang::Lexer::isAtEndOfMacroExpansion(), isInSystemMacro(), and clang::SourceLocation::print().

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

Definition at line 1238 of file SourceManager.h.

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

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

Determine if the source manager has a line table.

Definition at line 1131 of file SourceManager.h.

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 1215 of file SourceManager.h.

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

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 1223 of file SourceManager.h.

bool SourceManager::isBeforeInTranslationUnit ( SourceLocation  LHS,
SourceLocation  RHS 
) const
bool clang::SourceManager::isFromMainFile ( SourceLocation  Loc) const [inline]

isFromMainFile - Returns true if the file of provided SourceLocation is the main file.

Definition at line 1076 of file SourceManager.h.

References getFileID(), and getMainFileID().

Referenced by clang::Sema::ActOnUsingDirective(), and clang::RewriteMacrosInInput().

bool clang::SourceManager::isFromSameFile ( SourceLocation  Loc1,
SourceLocation  Loc2 
) const [inline]

isFromSameFile - Returns true if both SourceLocations correspond to the same file.

Definition at line 1070 of file SourceManager.h.

References getFileID().

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

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

Definition at line 1087 of file SourceManager.h.

References clang::SrcMgr::C_ExternCSystem, and getFileCharacteristic().

bool clang::SourceManager::isInFileID ( SourceLocation  Loc,
FileID  FID,
unsigned *  RelativeOffset = 0 
) const [inline]
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 992 of file SourceManager.h.

Referenced by isEmptyARCMTMacroStatement(), and updateConsecutiveMacroArgTokens().

bool clang::SourceManager::isInSLocAddrSpace ( SourceLocation  Loc,
SourceLocation  Start,
unsigned  Length,
unsigned *  RelativeOffset = 0 
) 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 968 of file SourceManager.h.

bool clang::SourceManager::isInSystemHeader ( SourceLocation  Loc) const [inline]
bool clang::SourceManager::isInSystemMacro ( SourceLocation  loc) [inline]

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

Definition at line 1092 of file SourceManager.h.

References getSpellingLoc(), isInSystemHeader(), and clang::SourceLocation::isMacroID().

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

Returns true if FID came from a PCH/Module.

Definition at line 1304 of file SourceManager.h.

Referenced by clang::Preprocessor::EnterMainSourceFile(), clang::ASTUnit::findFileRegionDecls(), and isLocalFileID().

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

Returns true if Loc came from a PCH/Module.

Definition at line 1294 of file SourceManager.h.

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

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

Definition at line 1310 of file SourceManager.h.

References isLoadedFileID().

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

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

Definition at line 1299 of file SourceManager.h.

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

bool SourceManager::isMacroArgExpansion ( SourceLocation  Loc) const

isMacroArgExpansion - This method tests whether the given source location represents a macro argument's expansion into the function-like macro definition. Such source locations only appear inside of the expansion locations representing where a particular function-like macro was expanded.

Definition at line 913 of file SourceManager.cpp.

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

Referenced by clang::Lexer::GetBeginningOfToken(), getImmediateMacroCalleeLoc(), getImmediateMacroCallerLoc(), getImmediateMacroName(), and skipToMacroArgExpansion().

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

Get the number of loaded SLocEntries we have.

Definition at line 1257 of file SourceManager.h.

Referenced by translateFile().

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

Get the number of local SLocEntries we have.

Definition at line 1247 of file SourceManager.h.

Referenced by getFileIDSize(), clang::Preprocessor::HandleEndOfFile(), clang::PreprocessorLexer::PreprocessorLexer(), and translateFile().

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

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

Parameters:
SourceFilethe source file whose contents will be overriden.
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 584 of file SourceManager.cpp.

Referenced by clang::GenerateModuleAction::BeginSourceFileAction(), InitializeFileRemapping(), clang::CompilerInstance::InitializeSourceManager(), and clang::Preprocessor::SetCodeCompletionPoint().

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

Override the the given source file with another one.

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

Definition at line 594 of file SourceManager.cpp.

References clang::FileEntry::getSize().

void SourceManager::PrintStats ( ) const

PrintStats - Print statistics to stderr.

Definition at line 1769 of file SourceManager.cpp.

References fileinfo_begin(), and fileinfo_end().

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

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

Definition at line 1278 of file SourceManager.h.

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

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

Set the file ID for the main source file.

Definition at line 629 of file SourceManager.h.

References clang::FileID::isInvalid().

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 795 of file SourceManager.h.

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

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

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

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

Definition at line 600 of file SourceManager.h.

Referenced by InitializeFileRemapping().

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

Set the file ID for the precompiled preamble.

Definition at line 635 of file SourceManager.h.

References clang::FileID::isInvalid().

FileID SourceManager::translateFile ( const FileEntry SourceFile) const
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 1360 of file SourceManager.cpp.

References translateFile(), and translateLineCol().

Referenced by clang::CodeGenAction::ExecuteAction(), and clang::ASTUnit::getLocation().

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

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

Get the source location in.

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

Definition at line 1487 of file SourceManager.cpp.

References ComputeLineNumbers(), Diag(), clang::SrcMgr::ContentCache::getBuffer(), clang::SrcMgr::FileInfo::getContentCache(), clang::SrcMgr::SLocEntry::getFile(), getFileLoc(), 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().


Friends And Related Function Documentation

friend class ASTReader [friend]

Definition at line 1389 of file SourceManager.h.

friend class ASTWriter [friend]

Definition at line 1390 of file SourceManager.h.


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