LLVM API Documentation

Classes | Public Types | Public Member Functions
llvm::SourceMgr Class Reference

#include <SourceMgr.h>

List of all members.

Classes

struct  SrcBuffer

Public Types

enum  DiagKind { DK_Error, DK_Warning, DK_Note }
typedef void(* DiagHandlerTy )(const SMDiagnostic &, void *Context)

Public Member Functions

 SourceMgr ()
 ~SourceMgr ()
void setIncludeDirs (const std::vector< std::string > &Dirs)
void setDiagHandler (DiagHandlerTy DH, void *Ctx=nullptr)
DiagHandlerTy getDiagHandler () const
void * getDiagContext () const
const SrcBuffer & getBufferInfo (unsigned i) const
const MemoryBuffergetMemoryBuffer (unsigned i) const
unsigned getNumBuffers () const
unsigned getMainFileID () const
SMLoc getParentIncludeLoc (unsigned i) const
unsigned AddNewSourceBuffer (std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
unsigned AddIncludeFile (const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
unsigned FindBufferContainingLoc (SMLoc Loc) const
unsigned FindLineNumber (SMLoc Loc, unsigned BufferID=0) const
std::pair< unsigned, unsignedgetLineAndColumn (SMLoc Loc, unsigned BufferID=0) const
void PrintMessage (raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
void PrintMessage (SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
 Emits a diagnostic to llvm::errs().
void PrintMessage (raw_ostream &OS, const SMDiagnostic &Diagnostic, bool ShowColors=true) const
SMDiagnostic GetMessage (SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
void PrintIncludeStack (SMLoc IncludeLoc, raw_ostream &OS) const

Detailed Description

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

Definition at line 35 of file SourceMgr.h.


Member Typedef Documentation

typedef void(* llvm::SourceMgr::DiagHandlerTy)(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. It gets called each time PrintMessage is invoked.

Definition at line 46 of file SourceMgr.h.


Member Enumeration Documentation

Enumerator:
DK_Error 
DK_Warning 
DK_Note 

Definition at line 37 of file SourceMgr.h.


Constructor & Destructor Documentation

llvm::SourceMgr::SourceMgr ( ) [inline]

Definition at line 79 of file SourceMgr.h.

Definition at line 41 of file SourceMgr.cpp.

References getCache().


Member Function Documentation

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 47 of file SourceMgr.cpp.

References AddNewSourceBuffer(), llvm::StringRef::data(), llvm::sys::path::get_separator(), and llvm::MemoryBuffer::getFile().

unsigned llvm::SourceMgr::AddNewSourceBuffer ( std::unique_ptr< MemoryBuffer F,
SMLoc  IncludeLoc 
) [inline]

Add a new source buffer to this source manager. This takes ownership of the memory buffer.

Definition at line 123 of file SourceMgr.h.

Referenced by AddIncludeFile(), llvm::object::IRObjectFile::IRObjectFile(), llvm::parseAssemblyInto(), and llvm::TableGenMain().

Return the ID of the buffer containing the specified location.

0 is returned if the buffer is not found.

Definition at line 68 of file SourceMgr.cpp.

References llvm::SMLoc::getPointer().

Referenced by getLineAndColumn(), GetMessage(), llvm::MCGenDwarfLabelEntry::Make(), PrintIncludeStack(), and PrintMessage().

unsigned llvm::SourceMgr::FindLineNumber ( SMLoc  Loc,
unsigned  BufferID = 0 
) const [inline]

Find the line number for the specified location in the specified file. This is not a fast method.

Definition at line 148 of file SourceMgr.h.

References getLineAndColumn().

Referenced by llvm::MCGenDwarfLabelEntry::Make(), and PrintIncludeStack().

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

Definition at line 97 of file SourceMgr.h.

Referenced by PrintIncludeStack(), and PrintMessage().

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

Definition at line 95 of file SourceMgr.h.

Definition at line 94 of file SourceMgr.h.

std::pair< unsigned, unsigned > SourceMgr::getLineAndColumn ( SMLoc  Loc,
unsigned  BufferID = 0 
) const

Find the line and column number for the specified location in the specified file. This is not a fast method.

Definition at line 79 of file SourceMgr.cpp.

References llvm::StringRef::find_last_of(), FindBufferContainingLoc(), llvm::MemoryBuffer::getBufferStart(), getCache(), llvm::SMLoc::getFromPointer(), getMemoryBuffer(), llvm::SMLoc::getPointer(), and llvm::StringRef::npos.

Referenced by FindLineNumber(), and GetMessage().

Definition at line 111 of file SourceMgr.h.

References getNumBuffers().

Referenced by llvm::MCContext::MCContext(), and llvm::TGLexer::TGLexer().

SMDiagnostic SourceMgr::GetMessage ( SMLoc  Loc,
SourceMgr::DiagKind  Kind,
const Twine Msg,
ArrayRef< SMRange Ranges = None,
ArrayRef< SMFixIt FixIts = None 
) const

Definition at line 107 of file SourceMgr.h.

Referenced by getMainFileID(), and llvm::MCContext::MCContext().

Definition at line 116 of file SourceMgr.h.

void SourceMgr::PrintIncludeStack ( SMLoc  IncludeLoc,
raw_ostream OS 
) const

Prints the names of included files and the line of the file they were included from. A diagnostic handler can use this before printing its custom formatted message.

Parameters:
IncludeLocThe location of the include.
OSthe raw_ostream to print on.

Definition at line 123 of file SourceMgr.cpp.

References FindBufferContainingLoc(), FindLineNumber(), and getBufferInfo().

Referenced by PrintMessage().

void SourceMgr::PrintMessage ( raw_ostream OS,
SMLoc  Loc,
SourceMgr::DiagKind  Kind,
const Twine Msg,
ArrayRef< SMRange Ranges = None,
ArrayRef< SMFixIt FixIts = None,
bool  ShowColors = true 
) const

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

Parameters:
ShowColorsDisplay colored messages if output is a terminal and the default error handler is used.

Definition at line 217 of file SourceMgr.cpp.

References GetMessage().

Referenced by llvm::MCContext::FatalError(), llvm::PrintError(), llvm::yaml::Scanner::printError(), llvm::PrintMessage(), PrintMessage(), llvm::PrintWarning(), and llvm::LLLexer::Warning().

void SourceMgr::PrintMessage ( SMLoc  Loc,
SourceMgr::DiagKind  Kind,
const Twine Msg,
ArrayRef< SMRange Ranges = None,
ArrayRef< SMFixIt FixIts = None,
bool  ShowColors = true 
) const

Emits a diagnostic to llvm::errs().

Definition at line 224 of file SourceMgr.cpp.

References llvm::errs(), and PrintMessage().

void SourceMgr::PrintMessage ( raw_ostream OS,
const SMDiagnostic Diagnostic,
bool  ShowColors = true 
) const

Emits a manually-constructed diagnostic to the given output stream.

Parameters:
ShowColorsDisplay colored messages if output is a terminal and the default error handler is used.

Definition at line 200 of file SourceMgr.cpp.

References FindBufferContainingLoc(), getBufferInfo(), llvm::SMDiagnostic::getLoc(), llvm::SMLoc::isValid(), llvm::SMDiagnostic::print(), and PrintIncludeStack().

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

Specify a diagnostic handler to be invoked every time PrintMessage is called. Ctx is passed into the handler when it is invoked.

Definition at line 89 of file SourceMgr.h.

Referenced by llvm::yaml::Input::Input().

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

Definition at line 83 of file SourceMgr.h.

Referenced by llvm::TableGenMain().


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