Go to the documentation of this file.
15 #ifndef LLVM_SUPPORT_SOURCEMGR_H
16 #define LLVM_SUPPORT_SOURCEMGR_H
48 std::unique_ptr<MemoryBuffer> Buffer;
60 mutable void *OffsetCache =
nullptr;
64 unsigned getLineNumber(
const char *Ptr)
const;
66 unsigned getLineNumberSpecialized(
const char *Ptr)
const;
70 const char *getPointerForLineNumber(
unsigned LineNo)
const;
72 const char *getPointerForLineNumberSpecialized(
unsigned LineNo)
const;
77 SrcBuffer() =
default;
78 SrcBuffer(SrcBuffer &&);
79 SrcBuffer(
const SrcBuffer &) =
delete;
80 SrcBuffer &
operator=(
const SrcBuffer &) =
delete;
85 std::vector<SrcBuffer> Buffers;
88 std::vector<std::string> IncludeDirectories;
91 void *DiagContext =
nullptr;
93 bool isValidBufferID(
unsigned i)
const {
return i &&
i <= Buffers.size(); }
107 IncludeDirectories = Dirs;
122 return Buffers[
i - 1];
127 return Buffers[
i - 1].Buffer.get();
139 return Buffers[
i - 1].IncludeLoc;
148 NB.IncludeLoc = IncludeLoc;
150 return Buffers.size();
159 if (
SrcMgr.Buffers.empty())
164 std::back_inserter(Buffers));
166 Buffers[OldNumBuffers].IncludeLoc = MainBufferIncludeLoc;
176 std::string &IncludedFile);
187 OpenIncludeFile(
const std::string &Filename, std::string &IncludedFile);
203 unsigned BufferID = 0)
const;
208 bool IncludePath =
false)
const;
221 ArrayRef<SMFixIt> FixIts = {},
222 bool ShowColors =
true)
const;
226 ArrayRef<SMRange> Ranges = {},
227 ArrayRef<SMFixIt> FixIts = {},
228 bool ShowColors =
true)
const;
234 void PrintMessage(raw_ostream &OS,
const SMDiagnostic &Diagnostic,
235 bool ShowColors =
true)
const;
243 ArrayRef<SMRange> Ranges = {},
244 ArrayRef<SMFixIt> FixIts = {})
const;
275 return Text <
Other.Text;
284 std::string Filename;
288 std::string Message, LineContents;
289 std::vector<std::pair<unsigned, unsigned>> Ranges;
297 : Filename(
filename), LineNo(-1), ColumnNo(-1), Kind(Knd), Message(
Msg) {}
302 ArrayRef<std::pair<unsigned, unsigned>> Ranges,
320 bool ShowKindLabel =
true)
const;
325 #endif // LLVM_SUPPORT_SOURCEMGR_H
SMFixIt(SMLoc Loc, const Twine &Replacement)
SMFixIt(SMRange R, const Twine &Replacement)
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< std::string > getIncludeDirs() const
Return the include directories of this source manager.
StringRef getMessage() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
SMLoc getParentIncludeLoc(unsigned i) const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
This interface provides simple read-only access to a block of memory, and provides simple methods for...
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
SourceMgr & operator=(const SourceMgr &)=delete
Represents a single fixit, a replacement of one range of text with another.
Represents a location in source code.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned getMainFileID() const
StringRef getLineContents() const
void setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
ErrorOr< std::unique_ptr< MemoryBuffer > > OpenIncludeFile(const std::string &Filename, std::string &IncludedFile)
Search for a file with the specified name in the current directory or in one of the IncludeDirs,...
ArrayRef< SMFixIt > getFixIts() const
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
void addFixIt(const SMFixIt &Hint)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
void(*)(const SMDiagnostic &, void *Context) DiagHandlerTy
Clients that want to handle their own diagnostics in a custom way can register a function pointer+con...
void * getDiagContext() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef getText() const
DiagHandlerTy getDiagHandler() const
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
StringRef - Represent a constant reference to a string, i.e.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
void setIncludeDirs(const std::vector< std::string > &Dirs)
SourceMgr::DiagKind getKind() const
const CustomOperand< const MCSubtargetInfo & > Msg[]
const SourceMgr * getSourceMgr() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
const char * getPointer() const
void takeSourceBuffersFrom(SourceMgr &SrcMgr, SMLoc MainBufferIncludeLoc=SMLoc())
Takes the source buffers from the given source manager and append them to the current manager.
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges={}, ArrayRef< SMFixIt > FixIts={}) const
Return an SMDiagnostic at the specified location with the specified string.
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.
bool operator<(const SMFixIt &Other) const
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
Represents a range in source code.
Represents either an error or a value T.
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.
SMLoc FindLocForLineAndColumn(unsigned BufferID, unsigned LineNo, unsigned ColNo)
Given a line and column number in a mapped buffer, turn it into an SMLoc.
StringRef getFilename() const
unsigned getNumBuffers() const
SMDiagnostic(StringRef filename, SourceMgr::DiagKind Knd, StringRef Msg)
const SrcBuffer & getBufferInfo(unsigned i) const
Optional< std::vector< StOtherPiece > > Other
std::string getFormattedLocationNoOffset(SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.