LLVM  6.0.0svn
Classes | Public Types | Public Member Functions | List of all members
llvm::SourceMgr Class Reference

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

#include "llvm/Support/SourceMgr.h"

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. More...
 

Public Member Functions

 SourceMgr ()=default
 
 SourceMgr (const SourceMgr &)=delete
 
SourceMgroperator= (const SourceMgr &)=delete
 
 ~SourceMgr ()
 
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. More...
 
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)
 Add a new source buffer to this source manager. More...
 
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. More...
 
unsigned FindBufferContainingLoc (SMLoc Loc) const
 Return the ID of the buffer containing the specified location. More...
 
unsigned FindLineNumber (SMLoc Loc, unsigned BufferID=0) const
 Find the line number for the specified location in the specified file. More...
 
std::pair< unsigned, unsignedgetLineAndColumn (SMLoc Loc, unsigned BufferID=0) const
 Find the line and column number for the specified location in the specified file. More...
 
void PrintMessage (raw_ostream &OS, SMLoc Loc, 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. More...
 
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(). More...
 
void PrintMessage (raw_ostream &OS, const SMDiagnostic &Diagnostic, bool ShowColors=true) const
 Emits a manually-constructed diagnostic to the given output stream. More...
 
SMDiagnostic GetMessage (SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
 Return an SMDiagnostic at the specified location with the specified string. More...
 
void PrintIncludeStack (SMLoc IncludeLoc, raw_ostream &OS) const
 Prints the names of included files and the line of the file they were included from. More...
 

Detailed Description

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

Definition at line 41 of file SourceMgr.h.

Member Typedef Documentation

◆ 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 53 of file SourceMgr.h.

Member Enumeration Documentation

◆ DiagKind

Enumerator
DK_Error 
DK_Warning 
DK_Remark 
DK_Note 

Definition at line 43 of file SourceMgr.h.

Constructor & Destructor Documentation

◆ SourceMgr() [1/2]

llvm::SourceMgr::SourceMgr ( )
default

◆ SourceMgr() [2/2]

llvm::SourceMgr::SourceMgr ( const SourceMgr )
delete

◆ ~SourceMgr()

SourceMgr::~SourceMgr ( )

Definition at line 53 of file SourceMgr.cpp.

References getCache().

Member Function Documentation

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

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

Referenced by AddNewSourceBuffer(), and llvm::TGLexer::getLoc().

◆ AddNewSourceBuffer()

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

◆ FindBufferContainingLoc()

unsigned SourceMgr::FindBufferContainingLoc ( SMLoc  Loc) const

Return the ID of the buffer containing the specified location.

0 is returned if the buffer is not found.

Definition at line 78 of file SourceMgr.cpp.

References llvm::SMLoc::getPointer().

Referenced by AddNewSourceBuffer(), getGNUBinOpPrecedence(), llvm::TGLexer::getLoc(), llvm::MCGenDwarfLabelEntry::Make(), and srcMgrDiagHandler().

◆ FindLineNumber()

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 150 of file SourceMgr.h.

References getLineAndColumn(), GetMessage(), Kind, llvm::None, PrintIncludeStack(), and PrintMessage().

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

◆ getBufferInfo()

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

Definition at line 99 of file SourceMgr.h.

References assert().

◆ getDiagContext()

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

Definition at line 97 of file SourceMgr.h.

◆ getDiagHandler()

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

Definition at line 96 of file SourceMgr.h.

◆ getLineAndColumn()

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

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

Referenced by FindLineNumber(), and llvm::MIRParserImpl::initializeJumpTableInfo().

◆ getMainFileID()

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

◆ getMemoryBuffer()

const MemoryBuffer* llvm::SourceMgr::getMemoryBuffer ( unsigned  i) const
inline

◆ GetMessage()

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

◆ getNumBuffers()

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

Definition at line 109 of file SourceMgr.h.

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

◆ getParentIncludeLoc()

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

Definition at line 118 of file SourceMgr.h.

References assert().

Referenced by getGNUBinOpPrecedence(), and llvm::TGLexer::getLoc().

◆ operator=()

SourceMgr& llvm::SourceMgr::operator= ( const SourceMgr )
delete

◆ PrintIncludeStack()

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

References assert().

Referenced by FindLineNumber(), and getGNUBinOpPrecedence().

◆ PrintMessage() [1/3]

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

References llvm::PrintMessage().

Referenced by llvm::MCObjectStreamer::emitFill(), FindLineNumber(), llvm::TGLexer::getLoc(), llvm::PrintError(), llvm::yaml::Scanner::printError(), llvm::PrintMessage(), llvm::PrintWarning(), llvm::MCContext::reportError(), llvm::HexagonMCChecker::reportWarning(), and llvm::LLLexer::Warning().

◆ PrintMessage() [2/3]

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

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

◆ PrintMessage() [3/3]

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

References assert(), llvm::SMDiagnostic::getLoc(), llvm::SMLoc::isValid(), and llvm::SMDiagnostic::print().

◆ setDiagHandler()

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 91 of file SourceMgr.h.

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

◆ setIncludeDirs()

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

Definition at line 85 of file SourceMgr.h.

Referenced by srcMgrDiagHandler(), and llvm::TableGenMain().


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