15#ifndef LLVM_SUPPORT_SOURCEMGR_H
16#define LLVM_SUPPORT_SOURCEMGR_H
49 std::unique_ptr<MemoryBuffer> Buffer;
61 mutable void *OffsetCache =
nullptr;
65 LLVM_ABI unsigned getLineNumber(
const char *
Ptr)
const;
67 unsigned getLineNumberSpecialized(
const char *
Ptr)
const;
71 LLVM_ABI const char *getPointerForLineNumber(
unsigned LineNo)
const;
73 const char *getPointerForLineNumberSpecialized(
unsigned LineNo)
const;
78 SrcBuffer() =
default;
80 SrcBuffer(
const SrcBuffer &) =
delete;
81 SrcBuffer &operator=(
const SrcBuffer &) =
delete;
86 std::vector<SrcBuffer> Buffers;
89 std::vector<std::string> IncludeDirectories;
92 void *DiagContext =
nullptr;
94 bool isValidBufferID(
unsigned i)
const {
return i && i <= Buffers.size(); }
108 IncludeDirectories = Dirs;
122 assert(isValidBufferID(i));
123 return Buffers[i - 1];
127 assert(isValidBufferID(i));
128 return Buffers[i - 1].Buffer.get();
139 assert(isValidBufferID(i));
140 return Buffers[i - 1].IncludeLoc;
148 NB.Buffer = std::move(
F);
149 NB.IncludeLoc = IncludeLoc;
150 Buffers.push_back(std::move(NB));
151 return Buffers.size();
160 if (
SrcMgr.Buffers.empty())
165 std::back_inserter(Buffers));
167 Buffers[OldNumBuffers].IncludeLoc = MainBufferIncludeLoc;
177 SMLoc IncludeLoc, std::string &IncludedFile);
188 OpenIncludeFile(
const std::string &Filename, std::string &IncludedFile);
203 LLVM_ABI std::pair<unsigned, unsigned>
222 ArrayRef<SMFixIt> FixIts = {},
223 bool ShowColors =
true)
const;
227 ArrayRef<SMRange> Ranges = {},
228 ArrayRef<SMFixIt> FixIts = {},
229 bool ShowColors =
true)
const;
236 bool ShowColors =
true)
const;
244 ArrayRef<SMRange> Ranges = {},
245 ArrayRef<SMFixIt> FixIts = {})
const;
272 if (
Range.Start.getPointer() !=
Other.Range.Start.getPointer())
273 return Range.Start.getPointer() <
Other.Range.Start.getPointer();
274 if (
Range.End.getPointer() !=
Other.Range.End.getPointer())
275 return Range.End.getPointer() <
Other.Range.End.getPointer();
276 return Text <
Other.Text;
285 std::string Filename;
289 std::string Message, LineContents;
290 std::vector<std::pair<unsigned, unsigned>> Ranges;
298 : Filename(filename), LineNo(-1), ColumnNo(-1), Kind(Knd), Message(Msg) {}
304 ArrayRef<std::pair<unsigned, unsigned>> Ranges,
322 bool ShowColors =
true,
bool ShowKindLabel =
true,
323 bool ShowLocation =
true)
const;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
This file defines the SmallVector class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Represents either an error or a value T.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
LLVM_ABI void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true, bool ShowLocation=true) const
SourceMgr::DiagKind getKind() const
StringRef getFilename() const
SMDiagnostic(StringRef filename, SourceMgr::DiagKind Knd, StringRef Msg)
StringRef getLineContents() const
StringRef getMessage() const
ArrayRef< SMFixIt > getFixIts() const
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
void addFixIt(const SMFixIt &Hint)
const SourceMgr * getSourceMgr() const
Represents a single fixit, a replacement of one range of text with another.
bool operator<(const SMFixIt &Other) const
StringRef getText() const
SMFixIt(SMLoc Loc, const Twine &Replacement)
Represents a location in source code.
Represents a range in source code.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
LLVM_ABI 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,...
SourceMgr & operator=(SourceMgr &&)=default
void * getDiagContext() const
SourceMgr(SourceMgr &&)=default
ArrayRef< std::string > getIncludeDirs() const
Return the include directories of this source manager.
unsigned getMainFileID() const
DiagHandlerTy getDiagHandler() const
SourceMgr & operator=(const SourceMgr &)=delete
void setIncludeDirs(const std::vector< std::string > &Dirs)
LLVM_ABI 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.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
unsigned getNumBuffers() const
LLVM_ABI 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.
SMLoc getParentIncludeLoc(unsigned i) const
LLVM_ABI void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
LLVM_ABI unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
LLVM_ABI 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.
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 setDiagHandler(DiagHandlerTy DH, void *Ctx=nullptr)
Specify a diagnostic handler to be invoked every time PrintMessage is called.
LLVM_ABI 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.
SourceMgr(const SourceMgr &)=delete
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
LLVM_ABI std::string getFormattedLocationNoOffset(SMLoc Loc, bool IncludePath=false) const
Get a string with the SMLoc filename and line number formatted in the standard style.
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.
LLVM_ABI SMLoc FindLocForLineAndColumn(unsigned BufferID, unsigned LineNo, unsigned ColNo)
Given a line and column number in a mapped buffer, turn it into an SMLoc.
const SrcBuffer & getBufferInfo(unsigned i) const
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.