27 struct LineNoCacheTy {
28 unsigned LastQueryBufferID;
29 const char *LastQuery;
30 unsigned LineNoOfQuery;
35 return (LineNoCacheTy*)Ptr;
41 if (LineNoCacheTy *Cache =
getCache(LineNoCache))
47 std::string &IncludedFile) {
48 IncludedFile = Filename;
53 for (
unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
67 for (
unsigned i = 0, e = Buffers.size(); i != e; ++i)
68 if (Loc.
getPointer() >= Buffers[i].Buffer->getBufferStart() &&
71 Loc.
getPointer() <= Buffers[i].Buffer->getBufferEnd())
76 std::pair<unsigned, unsigned>
80 assert(BufferID &&
"Invalid Location!");
89 const char *Ptr = BufStart;
94 if (LineNoCacheTy *Cache =
getCache(LineNoCache))
95 if (Cache->LastQueryBufferID == BufferID &&
97 Ptr = Cache->LastQuery;
98 LineNo = Cache->LineNoOfQuery;
104 if (*Ptr ==
'\n') ++LineNo;
108 LineNoCache =
new LineNoCacheTy();
111 LineNoCacheTy &Cache = *
getCache(LineNoCache);
112 Cache.LastQueryBufferID = BufferID;
113 Cache.LastQuery = Ptr;
114 Cache.LineNoOfQuery = LineNo;
118 return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
122 if (IncludeLoc ==
SMLoc())
return;
125 assert(CurBuf &&
"Invalid or unspecified location!");
129 OS <<
"Included from "
143 std::pair<unsigned, unsigned> LineAndCol;
144 const char *BufferID =
"<unknown>";
149 assert(CurBuf &&
"Invalid or unspecified location!");
157 while (LineStart != BufStart && LineStart[-1] !=
'\n' &&
158 LineStart[-1] !=
'\r')
164 while (LineEnd != BufEnd && LineEnd[0] !=
'\n' && LineEnd[0] !=
'\r')
166 LineStr = std::string(LineStart, LineEnd);
170 for (
unsigned i = 0, e = Ranges.
size(); i != e; ++i) {
193 return SMDiagnostic(*
this, Loc, BufferID, LineAndCol.first,
194 LineAndCol.second-1, Kind, Msg.
str(),
195 LineStr, ColRanges, FixIts);
199 bool ShowColors)
const {
202 DiagHandler(Diagnostic, DiagContext);
208 assert(CurBuf &&
"Invalid or unspecified location!");
212 Diagnostic.
print(
nullptr, OS, ShowColors);
237 : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
238 Message(Msg), LineContents(LineStr),
Ranges(
Ranges.vec()),
239 FixIts(Hints.
begin(), Hints.
end()) {
240 std::sort(FixIts.begin(), FixIts.end());
248 const char *LineStart = SourceLine.
begin();
249 const char *LineEnd = SourceLine.
end();
251 size_t PrevHintEndCol = 0;
281 unsigned HintCol = FirstCol;
282 if (HintCol < PrevHintEndCol)
283 HintCol = PrevHintEndCol + 1;
289 I->getText().size());
292 unsigned LastColumnModified = HintCol +
I->getText().size();
293 if (LastColumnModified > FixItLine.size())
294 FixItLine.resize(LastColumnModified,
' ');
296 std::copy(
I->getText().begin(),
I->getText().end(),
297 FixItLine.begin() + HintCol);
299 PrevHintEndCol = LastColumnModified;
305 LastCol = LineEnd - LineStart;
309 std::fill(&CaretLine[FirstCol], &CaretLine[LastCol],
'~');
315 for (
unsigned i = 0, e = LineContents.
size(), OutCol = 0; i != e; ++i) {
316 if (LineContents[i] !=
'\t') {
317 S << LineContents[i];
326 }
while ((OutCol %
TabStop) != 0);
336 bool ShowKindLabel)
const {
343 if (ProgName && ProgName[0])
344 S << ProgName <<
": ";
346 if (!Filename.empty()) {
355 S <<
':' << (ColumnNo+1);
385 S << Message <<
'\n';
390 if (LineNo == -1 || ColumnNo == -1)
398 if (std::find_if(LineContents.begin(), LineContents.end(),
isNonASCII) !=
399 LineContents.end()) {
403 size_t NumColumns = LineContents.size();
406 std::string CaretLine(NumColumns+1,
' ');
409 for (
unsigned r = 0, e = Ranges.size(); r != e; ++r) {
410 std::pair<unsigned, unsigned> R = Ranges[r];
411 std::fill(&CaretLine[R.first],
412 &CaretLine[
std::min((
size_t)R.second, CaretLine.size())],
418 std::string FixItInsertionLine;
421 LineContents.size()));
424 if (
unsigned(ColumnNo) <= NumColumns)
425 CaretLine[ColumnNo] =
'^';
427 CaretLine[NumColumns] =
'^';
432 CaretLine.erase(CaretLine.find_last_not_of(
' ')+1);
440 for (
unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
441 if (i >= LineContents.size() || LineContents[i] !=
'\t') {
451 }
while ((OutCol %
TabStop) != 0);
459 if (FixItInsertionLine.empty())
462 for (
size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
463 if (i >= LineContents.size() || LineContents[i] !=
'\t') {
464 S << FixItInsertionLine[i];
471 S << FixItInsertionLine[i];
477 if (FixItInsertionLine[i] !=
' ')
480 }
while (((OutCol %
TabStop) != 0) && i != e);
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Represents a range in source code.
void push_back(const T &Elt)
const_iterator end(StringRef path)
Get end iterator over path.
Represents either an error or a value T.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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
size_t size() const
size - Get the string size.
const char * getBufferStart() const
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. ...
virtual bool has_colors() const
This function determines if this stream is displayed and supports colors.
static const char * ProgName
virtual raw_ostream & changeColor(enum Colors Color, bool Bold=false, bool BG=false)
Changes the foreground color of text that will be output from this point forward. ...
const_iterator begin(StringRef path)
Get begin iterator over path.
virtual const char * getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
std::string str() const
Return the twine contents as a std::string.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Number of individual test Apply this number of consecutive mutations to each input exit after the first new interesting input is found the minimized corpus is saved into the first input directory Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static const size_t TabStop
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)...
size_t size() const
size - Get the array size.
int columnWidth(StringRef s)
bool empty() const
empty - Check if the array is empty.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
const SrcBuffer & getBufferInfo(unsigned i) const
static LineNoCacheTy * getCache(void *Ptr)
size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static void printSourceLine(raw_ostream &S, StringRef LineContents)
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.
StringRef get_separator()
Return the preferred separator for this platform.
static bool isNonASCII(char c)
static SMLoc getFromPointer(const char *Ptr)
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
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, ArrayRef< SMFixIt > FixIts, ArrayRef< char > SourceLine)
const char * getBufferEnd() const
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
const ARM::ArchExtKind Kind
virtual raw_ostream & resetColor()
Resets the colors to terminal defaults.
This class implements an extremely fast bulk output stream that can only output to a stream...
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.
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.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...