LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | List of all members
llvm::SourceMgr Class Reference

#include <SourceMgr.h>

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=0)
 
DiagHandlerTy getDiagHandler () const
 
void * getDiagContext () const
 
const SrcBuffer & getBufferInfo (unsigned i) const
 
const MemoryBuffergetMemoryBuffer (unsigned i) const
 
size_t getNumBuffers () const
 
SMLoc getParentIncludeLoc (unsigned i) const
 
size_t AddNewSourceBuffer (MemoryBuffer *F, SMLoc IncludeLoc)
 
size_t AddIncludeFile (const std::string &Filename, SMLoc IncludeLoc, std::string &IncludedFile)
 
int FindBufferContainingLoc (SMLoc Loc) const
 
unsigned FindLineNumber (SMLoc Loc, int BufferID=-1) const
 
std::pair< unsigned, unsignedgetLineAndColumn (SMLoc Loc, int BufferID=-1) 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(). More...
 
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

SourceMgr - 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)

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

SourceMgr::~SourceMgr ( )

Definition at line 41 of file SourceMgr.cpp.

References getCache().

Member Function Documentation

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

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

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

Definition at line 55 of file SourceMgr.cpp.

References AddNewSourceBuffer(), llvm::MemoryBuffer::getFile(), and llvm::OwningPtr< T >::take().

size_t llvm::SourceMgr::AddNewSourceBuffer ( MemoryBuffer F,
SMLoc  IncludeLoc 
)
inline

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

Definition at line 112 of file SourceMgr.h.

References F().

Referenced by AddIncludeFile(), llvm::ParseAssembly(), llvm::yaml::Scanner::Scanner(), and llvm::TableGenMain().

int SourceMgr::FindBufferContainingLoc ( SMLoc  Loc) const

FindBufferContainingLoc - Return the ID of the buffer containing the specified location, returning -1 if not found.

Definition at line 76 of file SourceMgr.cpp.

References llvm::SMLoc::getPointer().

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

unsigned llvm::SourceMgr::FindLineNumber ( SMLoc  Loc,
int  BufferID = -1 
) const
inline

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

Definition at line 133 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 91 of file SourceMgr.h.

Referenced by getLineAndColumn(), GetMessage(), PrintIncludeStack(), and PrintMessage().

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

Definition at line 89 of file SourceMgr.h.

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

Definition at line 88 of file SourceMgr.h.

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

getLineAndColumn - 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 llvm::StringRef::find_last_of(), FindBufferContainingLoc(), getBufferInfo(), llvm::MemoryBuffer::getBufferStart(), getCache(), llvm::SMLoc::getFromPointer(), llvm::SMLoc::getPointer(), and llvm::StringRef::npos.

Referenced by FindLineNumber(), and GetMessage().

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

Definition at line 96 of file SourceMgr.h.

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

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

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

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

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

Definition at line 151 of file SourceMgr.cpp.

References llvm::SMRange::End, FindBufferContainingLoc(), llvm::MemoryBuffer::getBufferEnd(), llvm::MemoryBuffer::getBufferIdentifier(), getBufferInfo(), llvm::MemoryBuffer::getBufferStart(), llvm::SMLoc::getFromPointer(), getLineAndColumn(), llvm::SMLoc::getPointer(), llvm::SMLoc::isValid(), llvm::SMRange::isValid(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::ArrayRef< T >::size(), llvm::SMRange::Start, and llvm::Twine::str().

Referenced by llvm::LLLexer::Error(), and PrintMessage().

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

Definition at line 101 of file SourceMgr.h.

Referenced by llvm::MCContext::MCContext().

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

Definition at line 105 of file SourceMgr.h.

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

PrintIncludeStack - 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
IncludeLoc- The line of the include.
OSthe raw_ostream to print on.

Definition at line 132 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

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

References FindBufferContainingLoc(), getBufferInfo(), GetMessage(), llvm::SMDiagnostic::print(), and PrintIncludeStack().

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

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

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

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

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

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

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

Definition at line 77 of file SourceMgr.h.

Referenced by llvm::TableGenMain().


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