28 struct LineNoCacheTy {
29 const char *LastQuery;
30 unsigned LastQueryBufferID;
31 unsigned LineNoOfQuery;
36 return (LineNoCacheTy*)
Ptr;
42 if (LineNoCacheTy *Cache =
getCache(LineNoCache))
48 std::string &IncludedFile) {
49 IncludedFile = Filename;
54 for (
unsigned i = 0, e = IncludeDirectories.size();
i != e && !NewBufOrErr;
68 for (
unsigned i = 0, e = Buffers.size();
i != e; ++
i)
69 if (Loc.
getPointer() >= Buffers[
i].Buffer->getBufferStart() &&
72 Loc.
getPointer() <= Buffers[
i].Buffer->getBufferEnd())
77 std::pair<unsigned, unsigned>
81 assert(BufferID &&
"Invalid Location!");
90 const char *
Ptr = BufStart;
95 if (LineNoCacheTy *Cache =
getCache(LineNoCache))
96 if (Cache->LastQueryBufferID == BufferID &&
98 Ptr = Cache->LastQuery;
99 LineNo = Cache->LineNoOfQuery;
105 if (*Ptr ==
'\n') ++LineNo;
109 LineNoCache =
new LineNoCacheTy();
112 LineNoCacheTy &Cache = *
getCache(LineNoCache);
113 Cache.LastQueryBufferID = BufferID;
114 Cache.LastQuery =
Ptr;
115 Cache.LineNoOfQuery = LineNo;
119 return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
123 if (IncludeLoc ==
SMLoc())
return;
126 assert(CurBuf &&
"Invalid or unspecified location!");
130 OS <<
"Included from "
144 std::pair<unsigned, unsigned> LineAndCol;
150 assert(CurBuf &&
"Invalid or unspecified location!");
158 while (LineStart != BufStart && LineStart[-1] !=
'\n' &&
159 LineStart[-1] !=
'\r')
165 while (LineEnd != BufEnd && LineEnd[0] !=
'\n' && LineEnd[0] !=
'\r')
167 LineStr = std::string(LineStart, LineEnd);
171 for (
unsigned i = 0, e = Ranges.
size();
i != e; ++
i) {
194 return SMDiagnostic(*
this, Loc, BufferID, LineAndCol.first,
195 LineAndCol.second-1, Kind, Msg.
str(),
196 LineStr, ColRanges, FixIts);
200 bool ShowColors)
const {
203 DiagHandler(Diagnostic, DiagContext);
209 assert(CurBuf &&
"Invalid or unspecified location!");
213 Diagnostic.
print(
nullptr, OS, ShowColors);
236 ArrayRef<std::pair<unsigned,unsigned> > Ranges,
238 : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
239 Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
240 FixIts(Hints.
begin(), Hints.
end()) {
241 std::sort(FixIts.begin(), FixIts.end());
249 const char *LineStart = SourceLine.
begin();
250 const char *LineEnd = SourceLine.
end();
252 size_t PrevHintEndCol = 0;
282 unsigned HintCol = FirstCol;
283 if (HintCol < PrevHintEndCol)
284 HintCol = PrevHintEndCol + 1;
290 I->getText().size());
293 unsigned LastColumnModified = HintCol +
I->getText().size();
294 if (LastColumnModified > FixItLine.size())
295 FixItLine.resize(LastColumnModified,
' ');
297 std::copy(
I->getText().begin(),
I->getText().end(),
298 FixItLine.begin() + HintCol);
300 PrevHintEndCol = LastColumnModified;
306 LastCol = LineEnd - LineStart;
310 std::fill(&CaretLine[FirstCol], &CaretLine[LastCol],
'~');
316 for (
unsigned i = 0, e = LineContents.
size(), OutCol = 0;
i != e; ++
i) {
317 if (LineContents[
i] !=
'\t') {
318 S << LineContents[
i];
327 }
while ((OutCol %
TabStop) != 0);
337 bool ShowKindLabel)
const {
344 if (ProgName && ProgName[0])
345 S << ProgName <<
": ";
347 if (!Filename.empty()) {
356 S <<
':' << (ColumnNo+1);
386 S << Message <<
'\n';
391 if (LineNo == -1 || ColumnNo == -1)
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
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.
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.
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.
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)...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
int columnWidth(StringRef s)
LLVM_NODISCARD 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.
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)
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.
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...