16 #ifndef LLVM_SUPPORT_SOURCEMGR_H
17 #define LLVM_SUPPORT_SOURCEMGR_H
57 std::unique_ptr<MemoryBuffer> Buffer;
64 std::vector<SrcBuffer> Buffers;
67 std::vector<std::string> IncludeDirectories;
71 mutable void *LineNoCache =
nullptr;
74 void *DiagContext =
nullptr;
76 bool isValidBufferID(
unsigned i)
const {
return i && i <= Buffers.size(); }
85 IncludeDirectories = Dirs;
99 assert(isValidBufferID(i));
100 return Buffers[i - 1];
104 assert(isValidBufferID(i));
105 return Buffers[i - 1].Buffer.get();
109 return Buffers.size();
118 assert(isValidBufferID(i));
119 return Buffers[i - 1].IncludeLoc;
127 NB.Buffer = std::move(F);
128 NB.IncludeLoc = IncludeLoc;
129 Buffers.push_back(std::move(NB));
130 return Buffers.size();
140 std::string &IncludedFile);
156 unsigned BufferID = 0)
const;
166 bool ShowColors =
true)
const;
172 bool ShowColors =
true)
const;
179 bool ShowColors =
true)
const;
208 : Range(Loc, Loc), Text(Insertion.str()) {
214 : Range(R), Text(Replacement.str()) {
226 return Text < Other.Text;
235 std::string Filename;
239 std::string Message, LineContents;
240 std::vector<std::pair<unsigned, unsigned>> Ranges;
248 : Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Knd), Message(Msg) {}
254 ArrayRef<std::pair<unsigned,unsigned>> Ranges,
268 FixIts.push_back(Hint);
276 bool ShowKindLabel =
true)
const;
281 #endif // LLVM_SUPPORT_SOURCEMGR_H
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
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
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
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
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
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
SourceMgr & operator=(const SourceMgr &)=delete
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...