LLVM
8.0.1
|
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 | |
SourceMgr & | operator= (const SourceMgr &)=delete |
~SourceMgr ()=default | |
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 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. 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, unsigned > | getLineAndColumn (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... | |
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition at line 42 of file SourceMgr.h.
using llvm::SourceMgr::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.
It gets called each time PrintMessage is invoked.
Definition at line 54 of file SourceMgr.h.
Enumerator | |
---|---|
DK_Error | |
DK_Warning | |
DK_Remark | |
DK_Note |
Definition at line 44 of file SourceMgr.h.
|
default |
|
default |
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 41 of file SourceMgr.cpp.
References AddNewSourceBuffer(), llvm::StringRef::data(), llvm::sys::path::get_separator(), and llvm::MemoryBuffer::getFile().
Referenced by AddNewSourceBuffer(), and llvm::TGLexer::getLoc().
|
inline |
Add a new source buffer to this source manager.
This takes ownership of the memory buffer.
Definition at line 152 of file SourceMgr.h.
References AddIncludeFile(), and FindBufferContainingLoc().
Referenced by AddIncludeFile(), llvm::MIRParserImpl::initializeMachineFunction(), isOperator(), llvm::FileCheck::ReadCheckFile(), llvm::yaml::Scanner::Scanner(), srcMgrDiagHandler(), 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 62 of file SourceMgr.cpp.
References assert(), llvm::SMLoc::getPointer(), llvm::lower_bound(), llvm::max(), N, and Other.
Referenced by AddNewSourceBuffer(), llvm::FileCheckString::CheckNext(), llvm::FileCheckString::CheckSame(), getGNUBinOpPrecedence(), getLineAndColumn(), llvm::TGLexer::getLoc(), GetMessage(), llvm::MCGenDwarfLabelEntry::Make(), PrintIncludeStack(), PrintMessage(), and srcMgrDiagHandler().
Find the line number for the specified location in the specified file.
This is not a fast method.
Definition at line 177 of file SourceMgr.h.
References getLineAndColumn(), GetMessage(), Kind, llvm::None, PrintIncludeStack(), and PrintMessage().
Referenced by getGNUBinOpPrecedence(), llvm::MCGenDwarfLabelEntry::Make(), and PrintIncludeStack().
Definition at line 126 of file SourceMgr.h.
References assert().
Referenced by getLineAndColumn(), PrintIncludeStack(), and PrintMessage().
|
inline |
Definition at line 124 of file SourceMgr.h.
|
inline |
Definition at line 123 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 131 of file SourceMgr.cpp.
References assert(), llvm::StringRef::find_last_of(), FindBufferContainingLoc(), getBufferInfo(), llvm::SMLoc::getPointer(), llvm::max(), and llvm::StringRef::npos.
Referenced by FindLineNumber(), GetMessage(), and llvm::MIRParserImpl::initializeJumpTableInfo().
|
inline |
Definition at line 140 of file SourceMgr.h.
References assert(), and getNumBuffers().
Referenced by getGNUBinOpPrecedence(), llvm::MIRParserImpl::initializeJumpTableInfo(), llvm::MCContext::MCContext(), and llvm::TGLexer::TGLexer().
|
inline |
Definition at line 131 of file SourceMgr.h.
References assert().
Referenced by llvm::FileCheckString::CheckNext(), llvm::FileCheckString::CheckSame(), llvm::TGLexer::getLoc(), GetMessage(), llvm::MIRParserImpl::initializeJumpTableInfo(), isOperator(), 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 |
Return an SMDiagnostic at the specified location with the specified string.
Msg | If non-null, the kind of message (e.g., "error") which is prefixed to the message. |
Definition at line 169 of file SourceMgr.cpp.
References assert(), llvm::SMRange::End, FindBufferContainingLoc(), llvm::MemoryBuffer::getBufferEnd(), llvm::MemoryBuffer::getBufferIdentifier(), llvm::MemoryBuffer::getBufferStart(), llvm::SMLoc::getFromPointer(), getLineAndColumn(), getMemoryBuffer(), llvm::SMLoc::getPointer(), llvm::SMLoc::isValid(), llvm::SMRange::isValid(), llvm::SmallVectorTemplateBase< T >::push_back(), llvm::ArrayRef< T >::size(), llvm::SMRange::Start, and llvm::Twine::str().
Referenced by llvm::LLLexer::Error(), llvm::MIRParserImpl::error(), FindLineNumber(), llvm::MIRParserImpl::initializeJumpTableInfo(), and PrintMessage().
|
inline |
Definition at line 136 of file SourceMgr.h.
Referenced by getMainFileID(), and llvm::MCContext::MCContext().
Definition at line 145 of file SourceMgr.h.
References assert().
Referenced by getGNUBinOpPrecedence(), and llvm::TGLexer::getLoc().
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.
IncludeLoc | The location of the include. |
OS | the raw_ostream to print on. |
Definition at line 156 of file SourceMgr.cpp.
References assert(), FindBufferContainingLoc(), FindLineNumber(), and getBufferInfo().
Referenced by FindLineNumber(), getGNUBinOpPrecedence(), and 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.
ShowColors | Display colored messages if output is a terminal and the default error handler is used. |
Definition at line 248 of file SourceMgr.cpp.
References GetMessage().
Referenced by llvm::FileCheckString::CheckNext(), llvm::FileCheckString::CheckSame(), llvm::vfs::RedirectingFileSystem::create(), llvm::MCObjectStreamer::emitFill(), FindLineNumber(), llvm::TGLexer::getLoc(), llvm::FileCheckPattern::ParsePattern(), llvm::PrintError(), llvm::yaml::Scanner::printError(), llvm::FileCheckPattern::PrintFuzzyMatch(), PrintMatch(), llvm::PrintMessage(), PrintMessage(), PrintNoMatch(), llvm::FileCheckPattern::PrintVariableUses(), llvm::PrintWarning(), llvm::FileCheck::ReadCheckFile(), llvm::HexagonShuffler::reportError(), llvm::MCContext::reportError(), llvm::HexagonMCChecker::reportNote(), llvm::HexagonMCChecker::reportWarning(), 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 255 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.
ShowColors | Display colored messages if output is a terminal and the default error handler is used. |
Definition at line 231 of file SourceMgr.cpp.
References assert(), FindBufferContainingLoc(), getBufferInfo(), llvm::SMDiagnostic::getLoc(), llvm::SMLoc::isValid(), llvm::SMDiagnostic::print(), and PrintIncludeStack().
|
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 118 of file SourceMgr.h.
Referenced by llvm::vfs::RedirectingFileSystem::create().
|
inline |
Definition at line 112 of file SourceMgr.h.
Referenced by llvm::TableGenMain().