LLVM  9.0.0svn
SourceMgr.cpp
Go to the documentation of this file.
1 //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the SourceMgr class. This class is used as a simple
10 // substrate for diagnostics, #include handling, and other low level things for
11 // simple parsers.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/Support/SourceMgr.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/ADT/Twine.h"
21 #include "llvm/Support/ErrorOr.h"
22 #include "llvm/Support/Locale.h"
24 #include "llvm/Support/Path.h"
25 #include "llvm/Support/SMLoc.h"
26 #include "llvm/Support/WithColor.h"
28 #include <algorithm>
29 #include <cassert>
30 #include <cstddef>
31 #include <limits>
32 #include <memory>
33 #include <string>
34 #include <utility>
35 
36 using namespace llvm;
37 
38 static const size_t TabStop = 8;
39 
40 unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
41  SMLoc IncludeLoc,
42  std::string &IncludedFile) {
43  IncludedFile = Filename;
45  MemoryBuffer::getFile(IncludedFile);
46 
47  // If the file didn't exist directly, see if it's in an include path.
48  for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
49  ++i) {
50  IncludedFile =
51  IncludeDirectories[i] + sys::path::get_separator().data() + Filename;
52  NewBufOrErr = MemoryBuffer::getFile(IncludedFile);
53  }
54 
55  if (!NewBufOrErr)
56  return 0;
57 
58  return AddNewSourceBuffer(std::move(*NewBufOrErr), IncludeLoc);
59 }
60 
62  for (unsigned i = 0, e = Buffers.size(); i != e; ++i)
63  if (Loc.getPointer() >= Buffers[i].Buffer->getBufferStart() &&
64  // Use <= here so that a pointer to the null at the end of the buffer
65  // is included as part of the buffer.
66  Loc.getPointer() <= Buffers[i].Buffer->getBufferEnd())
67  return i + 1;
68  return 0;
69 }
70 
71 template <typename T>
72 unsigned SourceMgr::SrcBuffer::getLineNumber(const char *Ptr) const {
73 
74  // Ensure OffsetCache is allocated and populated with offsets of all the
75  // '\n' bytes.
76  std::vector<T> *Offsets = nullptr;
77  if (OffsetCache.isNull()) {
78  Offsets = new std::vector<T>();
79  OffsetCache = Offsets;
80  size_t Sz = Buffer->getBufferSize();
82  StringRef S = Buffer->getBuffer();
83  for (size_t N = 0; N < Sz; ++N) {
84  if (S[N] == '\n') {
85  Offsets->push_back(static_cast<T>(N));
86  }
87  }
88  } else {
89  Offsets = OffsetCache.get<std::vector<T> *>();
90  }
91 
92  const char *BufStart = Buffer->getBufferStart();
93  assert(Ptr >= BufStart && Ptr <= Buffer->getBufferEnd());
94  ptrdiff_t PtrDiff = Ptr - BufStart;
95  assert(PtrDiff >= 0 && static_cast<size_t>(PtrDiff) <= std::numeric_limits<T>::max());
96  T PtrOffset = static_cast<T>(PtrDiff);
97 
98  // std::lower_bound returns the first EOL offset that's not-less-than
99  // PtrOffset, meaning the EOL that _ends the line_ that PtrOffset is on
100  // (including if PtrOffset refers to the EOL itself). If there's no such
101  // EOL, returns end().
102  auto EOL = std::lower_bound(Offsets->begin(), Offsets->end(), PtrOffset);
103 
104  // Lines count from 1, so add 1 to the distance from the 0th line.
105  return (1 + (EOL - Offsets->begin()));
106 }
107 
108 SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other)
109  : Buffer(std::move(Other.Buffer)),
110  OffsetCache(Other.OffsetCache),
111  IncludeLoc(Other.IncludeLoc) {
112  Other.OffsetCache = nullptr;
113 }
114 
115 SourceMgr::SrcBuffer::~SrcBuffer() {
116  if (!OffsetCache.isNull()) {
117  if (OffsetCache.is<std::vector<uint8_t>*>())
118  delete OffsetCache.get<std::vector<uint8_t>*>();
119  else if (OffsetCache.is<std::vector<uint16_t>*>())
120  delete OffsetCache.get<std::vector<uint16_t>*>();
121  else if (OffsetCache.is<std::vector<uint32_t>*>())
122  delete OffsetCache.get<std::vector<uint32_t>*>();
123  else
124  delete OffsetCache.get<std::vector<uint64_t>*>();
125  OffsetCache = nullptr;
126  }
127 }
128 
129 std::pair<unsigned, unsigned>
130 SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
131  if (!BufferID)
132  BufferID = FindBufferContainingLoc(Loc);
133  assert(BufferID && "Invalid Location!");
134 
135  auto &SB = getBufferInfo(BufferID);
136  const char *Ptr = Loc.getPointer();
137 
138  size_t Sz = SB.Buffer->getBufferSize();
139  unsigned LineNo;
141  LineNo = SB.getLineNumber<uint8_t>(Ptr);
142  else if (Sz <= std::numeric_limits<uint16_t>::max())
143  LineNo = SB.getLineNumber<uint16_t>(Ptr);
144  else if (Sz <= std::numeric_limits<uint32_t>::max())
145  LineNo = SB.getLineNumber<uint32_t>(Ptr);
146  else
147  LineNo = SB.getLineNumber<uint64_t>(Ptr);
148 
149  const char *BufStart = SB.Buffer->getBufferStart();
150  size_t NewlineOffs = StringRef(BufStart, Ptr-BufStart).find_last_of("\n\r");
151  if (NewlineOffs == StringRef::npos) NewlineOffs = ~(size_t)0;
152  return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
153 }
154 
155 void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
156  if (IncludeLoc == SMLoc()) return; // Top of stack.
157 
158  unsigned CurBuf = FindBufferContainingLoc(IncludeLoc);
159  assert(CurBuf && "Invalid or unspecified location!");
160 
161  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
162 
163  OS << "Included from "
164  << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
165  << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
166 }
167 
169  const Twine &Msg,
170  ArrayRef<SMRange> Ranges,
171  ArrayRef<SMFixIt> FixIts) const {
172  // First thing to do: find the current buffer containing the specified
173  // location to pull out the source line.
175  std::pair<unsigned, unsigned> LineAndCol;
176  StringRef BufferID = "<unknown>";
177  std::string LineStr;
178 
179  if (Loc.isValid()) {
180  unsigned CurBuf = FindBufferContainingLoc(Loc);
181  assert(CurBuf && "Invalid or unspecified location!");
182 
183  const MemoryBuffer *CurMB = getMemoryBuffer(CurBuf);
184  BufferID = CurMB->getBufferIdentifier();
185 
186  // Scan backward to find the start of the line.
187  const char *LineStart = Loc.getPointer();
188  const char *BufStart = CurMB->getBufferStart();
189  while (LineStart != BufStart && LineStart[-1] != '\n' &&
190  LineStart[-1] != '\r')
191  --LineStart;
192 
193  // Get the end of the line.
194  const char *LineEnd = Loc.getPointer();
195  const char *BufEnd = CurMB->getBufferEnd();
196  while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
197  ++LineEnd;
198  LineStr = std::string(LineStart, LineEnd);
199 
200  // Convert any ranges to column ranges that only intersect the line of the
201  // location.
202  for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
203  SMRange R = Ranges[i];
204  if (!R.isValid()) continue;
205 
206  // If the line doesn't contain any part of the range, then ignore it.
207  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
208  continue;
209 
210  // Ignore pieces of the range that go onto other lines.
211  if (R.Start.getPointer() < LineStart)
212  R.Start = SMLoc::getFromPointer(LineStart);
213  if (R.End.getPointer() > LineEnd)
214  R.End = SMLoc::getFromPointer(LineEnd);
215 
216  // Translate from SMLoc ranges to column ranges.
217  // FIXME: Handle multibyte characters.
218  ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
219  R.End.getPointer()-LineStart));
220  }
221 
222  LineAndCol = getLineAndColumn(Loc, CurBuf);
223  }
224 
225  return SMDiagnostic(*this, Loc, BufferID, LineAndCol.first,
226  LineAndCol.second-1, Kind, Msg.str(),
227  LineStr, ColRanges, FixIts);
228 }
229 
231  bool ShowColors) const {
232  // Report the message with the diagnostic handler if present.
233  if (DiagHandler) {
234  DiagHandler(Diagnostic, DiagContext);
235  return;
236  }
237 
238  if (Diagnostic.getLoc().isValid()) {
239  unsigned CurBuf = FindBufferContainingLoc(Diagnostic.getLoc());
240  assert(CurBuf && "Invalid or unspecified location!");
241  PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
242  }
243 
244  Diagnostic.print(nullptr, OS, ShowColors);
245 }
246 
249  const Twine &Msg, ArrayRef<SMRange> Ranges,
250  ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
251  PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors);
252 }
253 
255  const Twine &Msg, ArrayRef<SMRange> Ranges,
256  ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
257  PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
258 }
259 
260 //===----------------------------------------------------------------------===//
261 // SMDiagnostic Implementation
262 //===----------------------------------------------------------------------===//
263 
265  int Line, int Col, SourceMgr::DiagKind Kind,
266  StringRef Msg, StringRef LineStr,
267  ArrayRef<std::pair<unsigned,unsigned>> Ranges,
268  ArrayRef<SMFixIt> Hints)
269  : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
270  Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
271  FixIts(Hints.begin(), Hints.end()) {
272  llvm::sort(FixIts);
273 }
274 
275 static void buildFixItLine(std::string &CaretLine, std::string &FixItLine,
276  ArrayRef<SMFixIt> FixIts, ArrayRef<char> SourceLine){
277  if (FixIts.empty())
278  return;
279 
280  const char *LineStart = SourceLine.begin();
281  const char *LineEnd = SourceLine.end();
282 
283  size_t PrevHintEndCol = 0;
284 
285  for (ArrayRef<SMFixIt>::iterator I = FixIts.begin(), E = FixIts.end();
286  I != E; ++I) {
287  // If the fixit contains a newline or tab, ignore it.
288  if (I->getText().find_first_of("\n\r\t") != StringRef::npos)
289  continue;
290 
291  SMRange R = I->getRange();
292 
293  // If the line doesn't contain any part of the range, then ignore it.
294  if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
295  continue;
296 
297  // Translate from SMLoc to column.
298  // Ignore pieces of the range that go onto other lines.
299  // FIXME: Handle multibyte characters in the source line.
300  unsigned FirstCol;
301  if (R.Start.getPointer() < LineStart)
302  FirstCol = 0;
303  else
304  FirstCol = R.Start.getPointer() - LineStart;
305 
306  // If we inserted a long previous hint, push this one forwards, and add
307  // an extra space to show that this is not part of the previous
308  // completion. This is sort of the best we can do when two hints appear
309  // to overlap.
310  //
311  // Note that if this hint is located immediately after the previous
312  // hint, no space will be added, since the location is more important.
313  unsigned HintCol = FirstCol;
314  if (HintCol < PrevHintEndCol)
315  HintCol = PrevHintEndCol + 1;
316 
317  // FIXME: This assertion is intended to catch unintended use of multibyte
318  // characters in fixits. If we decide to do this, we'll have to track
319  // separate byte widths for the source and fixit lines.
320  assert((size_t)sys::locale::columnWidth(I->getText()) ==
321  I->getText().size());
322 
323  // This relies on one byte per column in our fixit hints.
324  unsigned LastColumnModified = HintCol + I->getText().size();
325  if (LastColumnModified > FixItLine.size())
326  FixItLine.resize(LastColumnModified, ' ');
327 
328  std::copy(I->getText().begin(), I->getText().end(),
329  FixItLine.begin() + HintCol);
330 
331  PrevHintEndCol = LastColumnModified;
332 
333  // For replacements, mark the removal range with '~'.
334  // FIXME: Handle multibyte characters in the source line.
335  unsigned LastCol;
336  if (R.End.getPointer() >= LineEnd)
337  LastCol = LineEnd - LineStart;
338  else
339  LastCol = R.End.getPointer() - LineStart;
340 
341  std::fill(&CaretLine[FirstCol], &CaretLine[LastCol], '~');
342  }
343 }
344 
345 static void printSourceLine(raw_ostream &S, StringRef LineContents) {
346  // Print out the source line one character at a time, so we can expand tabs.
347  for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) {
348  size_t NextTab = LineContents.find('\t', i);
349  // If there were no tabs left, print the rest, we are done.
350  if (NextTab == StringRef::npos) {
351  S << LineContents.drop_front(i);
352  break;
353  }
354 
355  // Otherwise, print from i to NextTab.
356  S << LineContents.slice(i, NextTab);
357  OutCol += NextTab - i;
358  i = NextTab;
359 
360  // If we have a tab, emit at least one space, then round up to 8 columns.
361  do {
362  S << ' ';
363  ++OutCol;
364  } while ((OutCol % TabStop) != 0);
365  }
366  S << '\n';
367 }
368 
369 static bool isNonASCII(char c) {
370  return c & 0x80;
371 }
372 
373 void SMDiagnostic::print(const char *ProgName, raw_ostream &OS,
374  bool ShowColors, bool ShowKindLabel) const {
375  {
376  WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors);
377 
378  if (ProgName && ProgName[0])
379  S << ProgName << ": ";
380 
381  if (!Filename.empty()) {
382  if (Filename == "-")
383  S << "<stdin>";
384  else
385  S << Filename;
386 
387  if (LineNo != -1) {
388  S << ':' << LineNo;
389  if (ColumnNo != -1)
390  S << ':' << (ColumnNo + 1);
391  }
392  S << ": ";
393  }
394  }
395 
396  if (ShowKindLabel) {
397  switch (Kind) {
398  case SourceMgr::DK_Error:
399  WithColor::error(OS, "", !ShowColors);
400  break;
402  WithColor::warning(OS, "", !ShowColors);
403  break;
404  case SourceMgr::DK_Note:
405  WithColor::note(OS, "", !ShowColors);
406  break;
408  WithColor::remark(OS, "", !ShowColors);
409  break;
410  }
411  }
412 
413  WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors)
414  << Message << '\n';
415 
416  if (LineNo == -1 || ColumnNo == -1)
417  return;
418 
419  // FIXME: If there are multibyte or multi-column characters in the source, all
420  // our ranges will be wrong. To do this properly, we'll need a byte-to-column
421  // map like Clang's TextDiagnostic. For now, we'll just handle tabs by
422  // expanding them later, and bail out rather than show incorrect ranges and
423  // misaligned fixits for any other odd characters.
424  if (find_if(LineContents, isNonASCII) != LineContents.end()) {
425  printSourceLine(OS, LineContents);
426  return;
427  }
428  size_t NumColumns = LineContents.size();
429 
430  // Build the line with the caret and ranges.
431  std::string CaretLine(NumColumns+1, ' ');
432 
433  // Expand any ranges.
434  for (unsigned r = 0, e = Ranges.size(); r != e; ++r) {
435  std::pair<unsigned, unsigned> R = Ranges[r];
436  std::fill(&CaretLine[R.first],
437  &CaretLine[std::min((size_t)R.second, CaretLine.size())],
438  '~');
439  }
440 
441  // Add any fix-its.
442  // FIXME: Find the beginning of the line properly for multibyte characters.
443  std::string FixItInsertionLine;
444  buildFixItLine(CaretLine, FixItInsertionLine, FixIts,
445  makeArrayRef(Loc.getPointer() - ColumnNo,
446  LineContents.size()));
447 
448  // Finally, plop on the caret.
449  if (unsigned(ColumnNo) <= NumColumns)
450  CaretLine[ColumnNo] = '^';
451  else
452  CaretLine[NumColumns] = '^';
453 
454  // ... and remove trailing whitespace so the output doesn't wrap for it. We
455  // know that the line isn't completely empty because it has the caret in it at
456  // least.
457  CaretLine.erase(CaretLine.find_last_not_of(' ')+1);
458 
459  printSourceLine(OS, LineContents);
460 
461  {
462  WithColor S(OS, raw_ostream::GREEN, true, false, !ShowColors);
463 
464  // Print out the caret line, matching tabs in the source line.
465  for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
466  if (i >= LineContents.size() || LineContents[i] != '\t') {
467  S << CaretLine[i];
468  ++OutCol;
469  continue;
470  }
471 
472  // Okay, we have a tab. Insert the appropriate number of characters.
473  do {
474  S << CaretLine[i];
475  ++OutCol;
476  } while ((OutCol % TabStop) != 0);
477  }
478  S << '\n';
479  }
480 
481  // Print out the replacement line, matching tabs in the source line.
482  if (FixItInsertionLine.empty())
483  return;
484 
485  for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
486  if (i >= LineContents.size() || LineContents[i] != '\t') {
487  OS << FixItInsertionLine[i];
488  ++OutCol;
489  continue;
490  }
491 
492  // Okay, we have a tab. Insert the appropriate number of characters.
493  do {
494  OS << FixItInsertionLine[i];
495  // FIXME: This is trying not to break up replacements, but then to re-sync
496  // with the tabs between replacements. This will fail, though, if two
497  // fix-it replacements are exactly adjacent, or if a fix-it contains a
498  // space. Really we should be precomputing column widths, which we'll
499  // need anyway for multibyte chars.
500  if (FixItInsertionLine[i] != ' ')
501  ++i;
502  ++OutCol;
503  } while (((OutCol % TabStop) != 0) && i != e);
504  }
505  OS << '\n';
506 }
auto lower_bound(R &&Range, T &&Value) -> decltype(adl_begin(Range))
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1288
virtual StringRef getBufferIdentifier() const
Return an identifier for this buffer, typically the filename it was read from.
Definition: MemoryBuffer.h:69
Represents a range in source code.
Definition: SMLoc.h:48
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:233
Represents either an error or a value T.
Definition: ErrorOr.h:56
unsigned FindBufferContainingLoc(SMLoc Loc) const
Return the ID of the buffer containing the specified location.
Definition: SourceMgr.cpp:61
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:224
This class represents lattice values for constants.
Definition: AllocatorList.h:23
SMLoc getLoc() const
Definition: SourceMgr.h:285
void print(const char *ProgName, raw_ostream &S, bool ShowColors=true, bool ShowKindLabel=true) const
Definition: SourceMgr.cpp:373
An RAII object that temporarily switches an output stream to a specific color.
Definition: WithColor.h:37
iterator begin() const
Definition: ArrayRef.h:136
static raw_ostream & error()
Convenience method for printing "error: " to stderr.
Definition: WithColor.cpp:60
void PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const
Prints the names of included files and the line of the file they were included from.
Definition: SourceMgr.cpp:155
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1042
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.
Definition: StringRef.h:406
static raw_ostream & warning()
Convenience method for printing "warning: " to stderr.
Definition: WithColor.cpp:62
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. ...
Definition: SourceMgr.cpp:130
SMLoc Start
Definition: SMLoc.h:50
SMDiagnostic()=default
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.
Definition: SourceMgr.cpp:247
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:450
LLVM_NODISCARD StringRef drop_front(size_t N=1) const
Return a StringRef equal to &#39;this&#39; but with the first N elements dropped.
Definition: StringRef.h:620
LLVM_NODISCARD StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
Definition: StringRef.h:679
static raw_ostream & note()
Convenience method for printing "note: " to stderr.
Definition: WithColor.cpp:64
ELFYAML::ELF_STO Other
Definition: ELFYAML.cpp:870
const MemoryBuffer * getMemoryBuffer(unsigned i) const
Definition: SourceMgr.h:130
static const size_t TabStop
Definition: SourceMgr.cpp:38
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
Definition: SourceMgr.h:151
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
int columnWidth(StringRef s)
Definition: Locale.cpp:9
const char * getPointer() const
Definition: SMLoc.h:34
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:285
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1220
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Definition: SourceMgr.h:41
StringRef get_separator(Style style=Style::native)
Return the preferred separator for this platform.
Definition: Path.cpp:601
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.
Definition: SourceMgr.cpp:168
const SrcBuffer & getBufferInfo(unsigned i) const
Definition: SourceMgr.h:125
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1122
bool isValid() const
Definition: SMLoc.h:59
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:837
iterator end() const
Definition: ArrayRef.h:137
static void printSourceLine(raw_ostream &S, StringRef LineContents)
Definition: SourceMgr.cpp:345
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:41
static raw_ostream & remark()
Convenience method for printing "remark: " to stderr.
Definition: WithColor.cpp:66
bool isValid() const
Definition: SMLoc.h:29
SMLoc End
Definition: SMLoc.h:50
unsigned FindLineNumber(SMLoc Loc, unsigned BufferID=0) const
Find the line number for the specified location in the specified file.
Definition: SourceMgr.h:176
static bool isNonASCII(char c)
Definition: SourceMgr.cpp:369
static SMLoc getFromPointer(const char *Ptr)
Definition: SMLoc.h:36
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...
Definition: SourceMgr.cpp:40
const char * getBufferEnd() const
Definition: MemoryBuffer.h:60
static const size_t npos
Definition: StringRef.h:50
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, ArrayRef< SMFixIt > FixIts, ArrayRef< char > SourceLine)
Definition: SourceMgr.cpp:275
const char * getBufferStart() const
Definition: MemoryBuffer.h:59
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
Provides ErrorOr<T> smart pointer.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatile=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:122
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Represents a location in source code.
Definition: SMLoc.h:23
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1244
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:143
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition: SourceMgr.h:259