LLVM: llvm::SourceMgr Class Reference (original) (raw)

This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling. More...

#include "[llvm/Support/SourceMgr.h](Support%5F2SourceMgr%5F8h%5Fsource.html)"

Public Types
enum DiagKind { DK_Error, DK_Warning, DK_Remark, DK_Note }
using DiagHandlerTy = void (*)(const SMDiagnostic &, void *Context)
Clients that want to handle their own diagnostics in a custom way can register a function pointer+context as a diagnostic handler.
Public Member Functions
LLVM_ABI SourceMgr ()
Create new source manager without support for include files.
SourceMgr (IntrusiveRefCntPtr< vfs::FileSystem > FS)
Create new source manager with the capability of finding include files via the provided file system.
SourceMgr (const SourceMgr &)=delete
SourceMgr & operator= (const SourceMgr &)=delete
SourceMgr (SourceMgr &&)
SourceMgr & operator= (SourceMgr &&)
LLVM_ABI ~SourceMgr ()
IntrusiveRefCntPtr< vfs::FileSystem > getVirtualFileSystem () const
LLVM_ABI void setVirtualFileSystem (IntrusiveRefCntPtr< vfs::FileSystem > FS)
ArrayRef< std::string > getIncludeDirs () const
Return the include directories of this source manager.
void setIncludeDirs (const std::vector< std::string > &Dirs)
void setDiagHandler (DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
DiagHandlerTy getDiagHandler () const
void * getDiagContext () const
const SrcBuffer & getBufferInfo (unsigned i) const
const MemoryBuffer * getMemoryBuffer (unsigned i) const
unsigned getNumBuffers () const
unsigned getMainFileID () const
SMLoc getParentIncludeLoc (unsigned i) const
unsigned AddNewSourceBuffer (std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
void takeSourceBuffersFrom (SourceMgr &SrcMgr, SMLoc MainBufferIncludeLoc=SMLoc())
Takes the source buffers from the given source manager and append them to the current manager.
LLVM_ABI unsigned AddIncludeFile (const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs.
LLVM_ABI ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile (const std::string &Filename, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs, and try to open it without adding to the SourceMgr.
LLVM_ABI unsigned FindBufferContainingLoc (SMLoc Loc) const
Return the ID of the buffer containing the specified location.
unsigned FindLineNumber (SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
LLVM_ABI std::pair< unsigned, unsigned > getLineAndColumn (SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file.
LLVM_ABI std::string getFormattedLocationNoOffset (SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
LLVM_ABI SMLoc FindLocForLineAndColumn (unsigned BufferID, unsigned LineNo, unsigned ColNo)
Given a line and column number in a mapped buffer, turn it into an SMLoc.
LLVM_ABI void PrintMessage (raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
LLVM_ABI void PrintMessage (SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emits a diagnostic to llvm::errs().
LLVM_ABI void PrintMessage (raw_ostream &OS, const SMDiagnostic &Diagnostic, bool ShowColors=true) const
Emits a manually-constructed diagnostic to the given output stream.
LLVM_ABI SMDiagnostic GetMessage (SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
LLVM_ABI void PrintIncludeStack (SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.

This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.

Definition at line 37 of file SourceMgr.h.

DiagHandlerTy

Clients that want to handle their own diagnostics in a custom way can register a function pointer+context as a diagnostic handler.

It gets called each time PrintMessage is invoked.

Definition at line 49 of file SourceMgr.h.

DiagKind

Enumerator
DK_Error
DK_Warning
DK_Remark
DK_Note

Definition at line 39 of file SourceMgr.h.

SourceMgr::SourceMgr ( ) default

SourceMgr() [2/4]

Create new source manager with the capability of finding include files via the provided file system.

Definition at line 44 of file SourceMgr.cpp.

References llvm::move().

SourceMgr() [3/4]

SourceMgr() [4/4]

SourceMgr::SourceMgr ( SourceMgr && ) default

References SourceMgr().

~SourceMgr()

SourceMgr::~SourceMgr ( ) default

AddIncludeFile()

unsigned SourceMgr::AddIncludeFile ( const std::string & Filename,
SMLoc IncludeLoc,
std::string & IncludedFile )

Search for a file with the specified name in the current directory or in one of the IncludeDirs.

If no file is found, this returns 0, otherwise it returns the buffer ID of the stacked file. The full path to the included file can be found in IncludedFile.

Definition at line 58 of file SourceMgr.cpp.

References AddNewSourceBuffer(), and OpenIncludeFile().

AddNewSourceBuffer()

Add a new source buffer to this source manager.

This takes ownership of the memory buffer.

Definition at line 160 of file SourceMgr.h.

References F.

Referenced by AddIncludeFile(), llvm::lsp::TextDocumentContentChangeEvent::applyTo(), llvm::FileCheckPatternContext::defineCmdlineVariables(), llvm::MIRParserImpl::initializeMachineFunction(), parseAssemblyInto(), llvm::parseConstantValue(), llvm::parseDIExpressionBodyAtBeginning(), parseSummaryIndexAssemblyInto(), llvm::parseType(), llvm::parseTypeAtBeginning(), and llvm::FileCheck::readCheckFile().

FindBufferContainingLoc()

FindLineNumber()

FindLocForLineAndColumn()

getBufferInfo()

const SrcBuffer & llvm::SourceMgr::getBufferInfo ( unsigned i) const inline

getDiagContext()

void * llvm::SourceMgr::getDiagContext ( ) const inline

getDiagHandler()

DiagHandlerTy llvm::SourceMgr::getDiagHandler ( ) const inline

getFormattedLocationNoOffset()

std::string SourceMgr::getFormattedLocationNoOffset ( SMLoc Loc,
bool IncludePath = false ) const

getIncludeDirs()

ArrayRef< std::string > llvm::SourceMgr::getIncludeDirs ( ) const inline

getLineAndColumn()

getMainFileID()

unsigned llvm::SourceMgr::getMainFileID ( ) const inline

getMemoryBuffer()

GetMessage()

Return an SMDiagnostic at the specified location with the specified string.

Parameters

Msg If non-null, the kind of message (e.g., "error") which is prefixed to the message.

Definition at line 294 of file SourceMgr.cpp.

References assert(), FindBufferContainingLoc(), llvm::MemoryBuffer::getBufferEnd(), llvm::MemoryBuffer::getBufferIdentifier(), llvm::MemoryBuffer::getBufferStart(), llvm::SMLoc::getFromPointer(), getLineAndColumn(), getMemoryBuffer(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), and llvm::Twine::str().

Referenced by llvm::parseType(), PrintMessage(), llvm::MCContext::reportError(), and llvm::MCContext::reportWarning().

getNumBuffers()

unsigned llvm::SourceMgr::getNumBuffers ( ) const inline

getParentIncludeLoc()

SMLoc llvm::SourceMgr::getParentIncludeLoc ( unsigned i) const inline

getVirtualFileSystem()

OpenIncludeFile()

ErrorOr< std::unique_ptr< MemoryBuffer > > SourceMgr::OpenIncludeFile ( const std::string & Filename,
std::string & IncludedFile )

Search for a file with the specified name in the current directory or in one of the IncludeDirs, and try to open it without adding to the SourceMgr.

If the opened file is intended to be added to the source manager, prefer AddIncludeFile instead.

If no file is found, this returns an Error, otherwise it returns the buffer of the stacked file. The full path to the included file can be found in IncludedFile.

Definition at line 70 of file SourceMgr.cpp.

References llvm::sys::path::append(), and llvm::MemoryBuffer::getFile().

Referenced by AddIncludeFile().

operator=() [1/2]

operator=() [2/2]

PrintIncludeStack()

PrintMessage() [1/3]

PrintMessage() [2/3]

Emit a message about the specified location with the specified string.

Parameters

ShowColors Display colored messages if output is a terminal and the default error handler is used.

Definition at line 372 of file SourceMgr.cpp.

References GetMessage(), and PrintMessage().

Referenced by llvm::FileCheckString::CheckDag(), llvm::FileCheckString::CheckNext(), llvm::FileCheckString::CheckSame(), llvm::vfs::RedirectingFileSystem::create(), llvm::MCObjectStreamer::emitFill(), llvm::Pattern::parsePattern(), llvm::Pattern::printFuzzyMatch(), printMatch(), PrintMessage(), PrintMessage(), printNoMatch(), llvm::Pattern::printSubstitutions(), llvm::Pattern::printVariableDefs(), and llvm::FileCheck::readCheckFile().

PrintMessage() [3/3]

setDiagHandler()

void llvm::SourceMgr::setDiagHandler ( DiagHandlerTy DH, void * Ctx = nullptr ) inline

setIncludeDirs()

void llvm::SourceMgr::setIncludeDirs ( const std::vector< std::string > & Dirs) inline

setVirtualFileSystem()

takeSourceBuffersFrom()

void llvm::SourceMgr::takeSourceBuffersFrom ( SourceMgr & SrcMgr, SMLoc MainBufferIncludeLoc = SMLoc() ) inline

Takes the source buffers from the given source manager and append them to the current manager.

MainBufferIncludeLoc is an optional include location to attach to the main buffer of SrcMgr after it gets moved to the current manager.

Definition at line 173 of file SourceMgr.h.

References getNumBuffers(), SourceMgr(), and llvm::SrcMgr.

Referenced by llvm::TableGenParseFile().


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