16 #ifndef LLVM_SUPPORT_SOURCEMGR_H
17 #define LLVM_SUPPORT_SOURCEMGR_H
50 std::unique_ptr<MemoryBuffer> Buffer;
57 std::vector<SrcBuffer> Buffers;
60 std::vector<std::string> IncludeDirectories;
64 mutable void *LineNoCache;
69 bool isValidBufferID(
unsigned i)
const {
return i && i <= Buffers.size(); }
72 void operator=(
const SourceMgr&) =
delete;
75 : LineNoCache(nullptr), DiagHandler(nullptr), DiagContext(nullptr) {}
79 IncludeDirectories = Dirs;
93 assert(isValidBufferID(i));
94 return Buffers[i - 1];
98 assert(isValidBufferID(i));
99 return Buffers[i - 1].Buffer.get();
103 return Buffers.size();
112 assert(isValidBufferID(i));
113 return Buffers[i - 1].IncludeLoc;
121 NB.Buffer = std::move(F);
122 NB.IncludeLoc = IncludeLoc;
123 Buffers.push_back(std::move(NB));
124 return Buffers.size();
134 std::string &IncludedFile);
150 unsigned BufferID = 0)
const;
160 bool ShowColors =
true)
const;
166 bool ShowColors =
true)
const;
173 bool ShowColors =
true)
const;
203 : Range(Loc, Loc), Text(Insertion.str()) {
209 : Range(R), Text(Replacement.str()) {
221 return Text < Other.Text;
231 std::string Filename;
232 int LineNo, ColumnNo;
234 std::string Message, LineContents;
235 std::vector<std::pair<unsigned, unsigned> > Ranges;
241 : SM(nullptr), LineNo(0), ColumnNo(0), Kind(
SourceMgr::DK_Error) {}
244 : SM(nullptr), Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Knd),
251 ArrayRef<std::pair<unsigned,unsigned> > Ranges,
267 FixIts.push_back(Hint);
275 bool ShowKindLabel =
true)
const;
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Represents a range in source code.
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
const char * getPointer() const
SMFixIt(SMLoc Loc, const Twine &Insertion)
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. ...
void * getDiagContext() const
void addFixIt(const SMFixIt &Hint)
unsigned getMainFileID() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getLineContents() const
StringRef getMessage() const
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
StringRef getFilename() const
StringRef filename(StringRef path)
Get filename.
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
StringRef getText() const
unsigned getNumBuffers() const
void(* DiagHandlerTy)(const SMDiagnostic &, void *Context)
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
ArrayRef< SMFixIt > getFixIts() const
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
const SrcBuffer & getBufferInfo(unsigned i) const
Represents a single fixit, a replacement of one range of text with another.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
SourceMgr::DiagKind getKind() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool operator<(const SMFixIt &Other) const
SMLoc getParentIncludeLoc(unsigned i) const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
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...
const MemoryBuffer * getMemoryBuffer(unsigned i) const
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
void setIncludeDirs(const std::vector< std::string > &Dirs)
SMDiagnostic(StringRef filename, SourceMgr::DiagKind Knd, StringRef Msg)
StringRef - Represent a constant reference to a string, i.e.
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.
const SourceMgr * getSourceMgr() 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
Emit a message about the specified location with the specified string.
Represents a location in source code.
SMFixIt(SMRange R, const Twine &Replacement)
DiagHandlerTy getDiagHandler() const
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...