Lines Matching +full:slice +full:- +full:per +full:- +full:line
1 //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
75 if (Loc.getPointer() >= Buffers[i].Buffer->getBufferStart() &&
78 Loc.getPointer() <= Buffers[i].Buffer->getBufferEnd())
91 size_t Sz = Buffer->getBufferSize();
93 StringRef S = Buffer->getBuffer();
96 Offsets->push_back(static_cast<T>(N));
108 const char *BufStart = Buffer->getBufferStart();
109 assert(Ptr >= BufStart && Ptr <= Buffer->getBufferEnd());
110 ptrdiff_t PtrDiff = Ptr - BufStart;
116 // the line number.
117 return llvm::lower_bound(Offsets, PtrOffset) - Offsets.begin() + 1;
120 /// Look up a given \p Ptr in the buffer, determining which line it came
123 size_t Sz = Buffer->getBufferSize();
140 // We start counting line and column numbers from 1.
142 --LineNo;
144 const char *BufStart = Buffer->getBufferStart();
146 // The offset cache contains the location of the \n for the specified line,
147 // we want the start of the line. As such, we look for the previous entry.
152 return BufStart + Offsets[LineNo - 1] + 1;
155 /// Return a pointer to the first character of the specified line number or
156 /// null if the line number is invalid.
159 size_t Sz = Buffer->getBufferSize();
178 size_t Sz = Buffer->getBufferSize();
201 const char *BufStart = SB.Buffer->getBufferStart();
202 size_t NewlineOffs = StringRef(BufStart, Ptr - BufStart).find_last_of("\n\r");
205 return std::make_pair(LineNo, Ptr - BufStart - NewlineOffs);
210 // solution would be a general-purpose source location formatter
214 /// style, but without the line offset. If \p IncludePath is true, the path
220 auto FileSpec = getBufferInfo(BufferID).Buffer->getBufferIdentifier();
232 /// Given a line and column number in a mapped buffer, turn it into an SMLoc.
233 /// This will return a null SMLoc if the line/column location is invalid.
241 // We start counting line and column numbers from 1.
243 --ColNo;
247 // Make sure the location is within the current line.
248 if (Ptr + ColNo > SB.Buffer->getBufferEnd())
270 OS << "Included from " << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
278 // location to pull out the source line.
289 BufferID = CurMB->getBufferIdentifier();
291 // Scan backward to find the start of the line.
293 const char *BufStart = CurMB->getBufferStart();
294 while (LineStart != BufStart && LineStart[-1] != '\n' &&
295 LineStart[-1] != '\r')
296 --LineStart;
298 // Get the end of the line.
300 const char *BufEnd = CurMB->getBufferEnd();
303 LineStr = StringRef(LineStart, LineEnd - LineStart);
305 // Convert any ranges to column ranges that only intersect the line of the
311 // If the line doesn't contain any part of the range, then ignore it.
323 ColRanges.push_back(std::make_pair(R.Start.getPointer() - LineStart,
324 R.End.getPointer() - LineStart));
331 LineAndCol.second - 1, Kind, Msg.str(), LineStr,
365 //===----------------------------------------------------------------------===//
367 //===----------------------------------------------------------------------===//
374 //===----------------------------------------------------------------------===//
376 //===----------------------------------------------------------------------===//
378 SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, StringRef FN, int Line,
383 : SM(&sm), Loc(L), Filename(std::string(FN)), LineNo(Line), ColumnNo(Col),
407 // If the line doesn't contain any part of the range, then ignore it.
413 // FIXME: Handle multibyte characters in the source line.
418 FirstCol = R.Start.getPointer() - LineStart;
437 // This relies on one byte per column in our fixit hints.
447 // FIXME: Handle multibyte characters in the source line.
450 LastCol = LineEnd - LineStart;
452 LastCol = R.End.getPointer() - LineStart;
459 // Print out the source line one character at a time, so we can expand tabs.
469 S << LineContents.slice(i, NextTab);
470 OutCol += NextTab - i;
495 if (Filename == "-")
500 if (LineNo != -1) {
502 if (ColumnNo != -1)
528 if (LineNo == -1 || ColumnNo == -1)
531 // FIXME: If there are multibyte or multi-column characters in the source, all
532 // our ranges will be wrong. To do this properly, we'll need a byte-to-column
542 // Build the line with the caret and ranges.
550 // Add any fix-its.
551 // FIXME: Find the beginning of the line properly for multibyte characters.
554 ArrayRef(Loc.getPointer() - ColumnNo, LineContents.size()));
563 // know that the line isn't completely empty because it has the caret in it at
573 // Print out the caret line, matching tabs in the source line.
590 // Print out the replacement line, matching tabs in the source line.
604 // FIXME: This is trying not to break up replacements, but then to re-sync
606 // fix-it replacements are exactly adjacent, or if a fix-it contains a