class SourceMgr
Declaration
class SourceMgr { /* full declaration omitted */ };
Description
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Declared at: llvm/include/llvm/Support/SourceMgr.h:31
Member Variables
- private std::vector<SrcBuffer> Buffers
- This is all of the buffers that we are reading from.
- private std::vector<std::string> IncludeDirectories
- private llvm::SourceMgr::DiagHandlerTy DiagHandler = nullptr
- private void* DiagContext = nullptr
Method Overview
- public unsigned int AddIncludeFile(const std::string & Filename, llvm::SMLoc IncludeLoc, std::string & IncludedFile)
- public unsigned int AddNewSourceBuffer(std::unique_ptr<MemoryBuffer> F, llvm::SMLoc IncludeLoc)
- public unsigned int FindBufferContainingLoc(llvm::SMLoc Loc) const
- public unsigned int FindLineNumber(llvm::SMLoc Loc, unsigned int BufferID = 0) const
- public llvm::SMLoc FindLocForLineAndColumn(unsigned int BufferID, unsigned int LineNo, unsigned int ColNo)
- public llvm::SMDiagnostic GetMessage(llvm::SMLoc Loc, llvm::SourceMgr::DiagKind Kind, const llvm::Twine & Msg, ArrayRef<llvm::SMRange> Ranges = {}, ArrayRef<llvm::SMFixIt> FixIts = {}) const
- public ErrorOr<std::unique_ptr<MemoryBuffer>> OpenIncludeFile(const std::string & Filename, std::string & IncludedFile)
- public void PrintIncludeStack(llvm::SMLoc IncludeLoc, llvm::raw_ostream & OS) const
- public void PrintMessage(llvm::raw_ostream & OS, const llvm::SMDiagnostic & Diagnostic, bool ShowColors = true) const
- public void PrintMessage(llvm::SMLoc Loc, llvm::SourceMgr::DiagKind Kind, const llvm::Twine & Msg, ArrayRef<llvm::SMRange> Ranges = {}, ArrayRef<llvm::SMFixIt> FixIts = {}, bool ShowColors = true) const
- public void PrintMessage(llvm::raw_ostream & OS, llvm::SMLoc Loc, llvm::SourceMgr::DiagKind Kind, const llvm::Twine & Msg, ArrayRef<llvm::SMRange> Ranges = {}, ArrayRef<llvm::SMFixIt> FixIts = {}, bool ShowColors = true) const
- public SourceMgr()
- public SourceMgr(const llvm::SourceMgr &)
- public SourceMgr(llvm::SourceMgr &&)
- public const llvm::SourceMgr::SrcBuffer & getBufferInfo(unsigned int i) const
- public void * getDiagContext() const
- public llvm::SourceMgr::DiagHandlerTy getDiagHandler() const
- public std::string getFormattedLocationNoOffset(llvm::SMLoc Loc, bool IncludePath = false) const
- public ArrayRef<std::string> getIncludeDirs() const
- public std::pair<unsigned int, unsigned int> getLineAndColumn(llvm::SMLoc Loc, unsigned int BufferID = 0) const
- public unsigned int getMainFileID() const
- public const llvm::MemoryBuffer * getMemoryBuffer(unsigned int i) const
- public unsigned int getNumBuffers() const
- public llvm::SMLoc getParentIncludeLoc(unsigned int i) const
- private bool isValidBufferID(unsigned int i) const
- public void setDiagHandler(llvm::SourceMgr::DiagHandlerTy DH, void * Ctx = nullptr)
- public void setIncludeDirs(const std::vector<std::string> & Dirs)
- public void takeSourceBuffersFrom(llvm::SourceMgr & SrcMgr, llvm::SMLoc MainBufferIncludeLoc = llvm::SMLoc())
- public ~SourceMgr()
Methods
¶unsigned int AddIncludeFile(
const std::string& Filename,
llvm::SMLoc IncludeLoc,
std::string& IncludedFile)
unsigned int AddIncludeFile(
const std::string& Filename,
llvm::SMLoc IncludeLoc,
std::string& IncludedFile)
Description
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\p IncludedFile.
Declared at: llvm/include/llvm/Support/SourceMgr.h:175
Parameters
- const std::string& Filename
- llvm::SMLoc IncludeLoc
- std::string& IncludedFile
¶unsigned int AddNewSourceBuffer(
std::unique_ptr<MemoryBuffer> F,
llvm::SMLoc IncludeLoc)
unsigned int AddNewSourceBuffer(
std::unique_ptr<MemoryBuffer> F,
llvm::SMLoc IncludeLoc)
Description
Add a new source buffer to this source manager. This takes ownership of the memory buffer.
Declared at: llvm/include/llvm/Support/SourceMgr.h:144
Parameters
- std::unique_ptr<MemoryBuffer> F
- llvm::SMLoc IncludeLoc
¶unsigned int FindBufferContainingLoc(
llvm::SMLoc Loc) const
unsigned int FindBufferContainingLoc(
llvm::SMLoc Loc) const
Description
Return the ID of the buffer containing the specified location. 0 is returned if the buffer is not found.
Declared at: llvm/include/llvm/Support/SourceMgr.h:192
Parameters
- llvm::SMLoc Loc
¶unsigned int FindLineNumber(
llvm::SMLoc Loc,
unsigned int BufferID = 0) const
unsigned int FindLineNumber(
llvm::SMLoc Loc,
unsigned int BufferID = 0) const
Description
Find the line number for the specified location in the specified file. This is not a fast method.
Declared at: llvm/include/llvm/Support/SourceMgr.h:196
Parameters
- llvm::SMLoc Loc
- unsigned int BufferID = 0
¶llvm::SMLoc FindLocForLineAndColumn(
unsigned int BufferID,
unsigned int LineNo,
unsigned int ColNo)
llvm::SMLoc FindLocForLineAndColumn(
unsigned int BufferID,
unsigned int LineNo,
unsigned int ColNo)
Description
Given a line and column number in a mapped buffer, turn it into an SMLoc. This will return a null SMLoc if the line/column location is invalid.
Declared at: llvm/include/llvm/Support/SourceMgr.h:212
Parameters
- unsigned int BufferID
- unsigned int LineNo
- unsigned int ColNo
¶llvm::SMDiagnostic GetMessage(
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {}) const
llvm::SMDiagnostic GetMessage(
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {}) const
Description
Return an SMDiagnostic at the specified location with the specified string.
Declared at: llvm/include/llvm/Support/SourceMgr.h:242
Parameters
- llvm::SMLoc Loc
- llvm::SourceMgr::DiagKind Kind
- const llvm::Twine& Msg
- If non-null, the kind of message (e.g., "error") which is prefixed to the message.
- ArrayRef<llvm::SMRange> Ranges = {}
- ArrayRef<llvm::SMFixIt> FixIts = {}
¶ErrorOr<std::unique_ptr<MemoryBuffer>>
OpenIncludeFile(const std::string& Filename,
std::string& IncludedFile)
ErrorOr<std::unique_ptr<MemoryBuffer>>
OpenIncludeFile(const std::string& Filename,
std::string& IncludedFile)
Description
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 \p IncludedFile.
Declared at: llvm/include/llvm/Support/SourceMgr.h:187
Parameters
- const std::string& Filename
- std::string& IncludedFile
¶void PrintIncludeStack(
llvm::SMLoc IncludeLoc,
llvm::raw_ostream& OS) const
void PrintIncludeStack(
llvm::SMLoc IncludeLoc,
llvm::raw_ostream& OS) const
Description
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.
Declared at: llvm/include/llvm/Support/SourceMgr.h:252
Parameters
- llvm::SMLoc IncludeLoc
- The location of the include.
- llvm::raw_ostream& OS
- the raw_ostream to print on.
¶void PrintMessage(
llvm::raw_ostream& OS,
const llvm::SMDiagnostic& Diagnostic,
bool ShowColors = true) const
void PrintMessage(
llvm::raw_ostream& OS,
const llvm::SMDiagnostic& Diagnostic,
bool ShowColors = true) const
Description
Emits a manually-constructed diagnostic to the given output stream.
Declared at: llvm/include/llvm/Support/SourceMgr.h:234
Parameters
- llvm::raw_ostream& OS
- const llvm::SMDiagnostic& Diagnostic
- bool ShowColors = true
- Display colored messages if output is a terminal and the default error handler is used.
¶void PrintMessage(
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {},
bool ShowColors = true) const
void PrintMessage(
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {},
bool ShowColors = true) const
Description
Emits a diagnostic to llvm::errs().
Declared at: llvm/include/llvm/Support/SourceMgr.h:225
Parameters
- llvm::SMLoc Loc
- llvm::SourceMgr::DiagKind Kind
- const llvm::Twine& Msg
- ArrayRef<llvm::SMRange> Ranges = {}
- ArrayRef<llvm::SMFixIt> FixIts = {}
- bool ShowColors = true
¶void PrintMessage(
llvm::raw_ostream& OS,
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {},
bool ShowColors = true) const
void PrintMessage(
llvm::raw_ostream& OS,
llvm::SMLoc Loc,
llvm::SourceMgr::DiagKind Kind,
const llvm::Twine& Msg,
ArrayRef<llvm::SMRange> Ranges = {},
ArrayRef<llvm::SMFixIt> FixIts = {},
bool ShowColors = true) const
Description
Emit a message about the specified location with the specified string.
Declared at: llvm/include/llvm/Support/SourceMgr.h:219
Parameters
- llvm::raw_ostream& OS
- llvm::SMLoc Loc
- llvm::SourceMgr::DiagKind Kind
- const llvm::Twine& Msg
- ArrayRef<llvm::SMRange> Ranges = {}
- ArrayRef<llvm::SMFixIt> FixIts = {}
- bool ShowColors = true
- Display colored messages if output is a terminal and the default error handler is used.
¶SourceMgr()
SourceMgr()
Declared at: llvm/include/llvm/Support/SourceMgr.h:96
¶SourceMgr(const llvm::SourceMgr&)
SourceMgr(const llvm::SourceMgr&)
Declared at: llvm/include/llvm/Support/SourceMgr.h:97
Parameters
- const llvm::SourceMgr&
¶SourceMgr(llvm::SourceMgr&&)
SourceMgr(llvm::SourceMgr&&)
Declared at: llvm/include/llvm/Support/SourceMgr.h:99
Parameters
¶const llvm::SourceMgr::SrcBuffer& getBufferInfo(
unsigned int i) const
const llvm::SourceMgr::SrcBuffer& getBufferInfo(
unsigned int i) const
Declared at: llvm/include/llvm/Support/SourceMgr.h:120
Parameters
- unsigned int i
¶void* getDiagContext() const
void* getDiagContext() const
Declared at: llvm/include/llvm/Support/SourceMgr.h:118
¶llvm::SourceMgr::DiagHandlerTy getDiagHandler()
const
llvm::SourceMgr::DiagHandlerTy getDiagHandler()
const
Declared at: llvm/include/llvm/Support/SourceMgr.h:117
¶std::string getFormattedLocationNoOffset(
llvm::SMLoc Loc,
bool IncludePath = false) const
std::string getFormattedLocationNoOffset(
llvm::SMLoc Loc,
bool IncludePath = false) const
Description
Get a string with the \p SMLoc filename and line number formatted in the standard style.
Declared at: llvm/include/llvm/Support/SourceMgr.h:207
Parameters
- llvm::SMLoc Loc
- bool IncludePath = false
¶ArrayRef<std::string> getIncludeDirs() const
ArrayRef<std::string> getIncludeDirs() const
Description
Return the include directories of this source manager.
Declared at: llvm/include/llvm/Support/SourceMgr.h:104
¶std::pair<unsigned int, unsigned int>
getLineAndColumn(llvm::SMLoc Loc,
unsigned int BufferID = 0) const
std::pair<unsigned int, unsigned int>
getLineAndColumn(llvm::SMLoc Loc,
unsigned int BufferID = 0) const
Description
Find the line and column number for the specified location in the specified file. This is not a fast method.
Declared at: llvm/include/llvm/Support/SourceMgr.h:202
Parameters
- llvm::SMLoc Loc
- unsigned int BufferID = 0
¶unsigned int getMainFileID() const
unsigned int getMainFileID() const
Declared at: llvm/include/llvm/Support/SourceMgr.h:132
¶const llvm::MemoryBuffer* getMemoryBuffer(
unsigned int i) const
const llvm::MemoryBuffer* getMemoryBuffer(
unsigned int i) const
Declared at: llvm/include/llvm/Support/SourceMgr.h:125
Parameters
- unsigned int i
¶unsigned int getNumBuffers() const
unsigned int getNumBuffers() const
Declared at: llvm/include/llvm/Support/SourceMgr.h:130
¶llvm::SMLoc getParentIncludeLoc(
unsigned int i) const
llvm::SMLoc getParentIncludeLoc(
unsigned int i) const
Declared at: llvm/include/llvm/Support/SourceMgr.h:137
Parameters
- unsigned int i
¶bool isValidBufferID(unsigned int i) const
bool isValidBufferID(unsigned int i) const
Declared at: llvm/include/llvm/Support/SourceMgr.h:93
Parameters
- unsigned int i
¶void setDiagHandler(
llvm::SourceMgr::DiagHandlerTy DH,
void* Ctx = nullptr)
void setDiagHandler(
llvm::SourceMgr::DiagHandlerTy DH,
void* Ctx = nullptr)
Description
Specify a diagnostic handler to be invoked every time PrintMessage is called. \p Ctx is passed into the handler when it is invoked.
Declared at: llvm/include/llvm/Support/SourceMgr.h:112
Parameters
- llvm::SourceMgr::DiagHandlerTy DH
- void* Ctx = nullptr
¶void setIncludeDirs(
const std::vector<std::string>& Dirs)
void setIncludeDirs(
const std::vector<std::string>& Dirs)
Declared at: llvm/include/llvm/Support/SourceMgr.h:106
Parameters
- const std::vector<std::string>& Dirs
¶void takeSourceBuffersFrom(
llvm::SourceMgr& SrcMgr,
llvm::SMLoc MainBufferIncludeLoc =
llvm::SMLoc())
void takeSourceBuffersFrom(
llvm::SourceMgr& SrcMgr,
llvm::SMLoc MainBufferIncludeLoc =
llvm::SMLoc())
Description
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.
Declared at: llvm/include/llvm/Support/SourceMgr.h:157
Parameters
- llvm::SourceMgr& SrcMgr
- llvm::SMLoc MainBufferIncludeLoc = llvm::SMLoc()
¶~SourceMgr()
~SourceMgr()
Declared at: llvm/include/llvm/Support/SourceMgr.h:101