LCOV - code coverage report
Current view: top level - lib/Support - SourceMgr.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 185 208 88.9 %
Date: 2018-06-17 00:07:59 Functions: 18 19 94.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the SourceMgr class.  This class is used as a simple
      11             : // substrate for diagnostics, #include handling, and other low level things for
      12             : // simple parsers.
      13             : //
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #include "llvm/Support/SourceMgr.h"
      17             : #include "llvm/ADT/ArrayRef.h"
      18             : #include "llvm/ADT/STLExtras.h"
      19             : #include "llvm/ADT/SmallVector.h"
      20             : #include "llvm/ADT/StringRef.h"
      21             : #include "llvm/ADT/Twine.h"
      22             : #include "llvm/Support/ErrorOr.h"
      23             : #include "llvm/Support/Locale.h"
      24             : #include "llvm/Support/MemoryBuffer.h"
      25             : #include "llvm/Support/Path.h"
      26             : #include "llvm/Support/SMLoc.h"
      27             : #include "llvm/Support/raw_ostream.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        7978 : unsigned SourceMgr::AddIncludeFile(const std::string &Filename,
      41             :                                    SMLoc IncludeLoc,
      42             :                                    std::string &IncludedFile) {
      43             :   IncludedFile = Filename;
      44             :   ErrorOr<std::unique_ptr<MemoryBuffer>> NewBufOrErr =
      45        7978 :     MemoryBuffer::getFile(IncludedFile);
      46             : 
      47             :   // If the file didn't exist directly, see if it's in an include path.
      48       47651 :   for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr;
      49             :        ++i) {
      50       12101 :     IncludedFile =
      51       60505 :         IncludeDirectories[i] + sys::path::get_separator().data() + Filename;
      52       24202 :     NewBufOrErr = MemoryBuffer::getFile(IncludedFile);
      53             :   }
      54             : 
      55        7978 :   if (!NewBufOrErr)
      56             :     return 0;
      57             : 
      58       15956 :   return AddNewSourceBuffer(std::move(*NewBufOrErr), IncludeLoc);
      59             : }
      60             : 
      61      197251 : unsigned SourceMgr::FindBufferContainingLoc(SMLoc Loc) const {
      62      517283 :   for (unsigned i = 0, e = Buffers.size(); i != e; ++i)
      63      738793 :     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      189537 :         Loc.getPointer() <= Buffers[i].Buffer->getBufferEnd())
      67      151847 :       return i + 1;
      68             :   return 0;
      69             : }
      70             : 
      71             : template <typename T>
      72       49609 : 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       49609 :   if (OffsetCache.isNull()) {
      78        2800 :     Offsets = new std::vector<T>();
      79             :     OffsetCache = Offsets;
      80        2800 :     size_t Sz = Buffer->getBufferSize();
      81             :     assert(Sz <= std::numeric_limits<T>::max());
      82             :     StringRef S = Buffer->getBuffer();
      83    24848196 :     for (size_t N = 0; N < Sz; ++N) {
      84    12422698 :       if (S[N] == '\n') {
      85      628890 :         Offsets->push_back(static_cast<T>(N));
      86             :       }
      87             :     }
      88             :   } else {
      89             :     Offsets = OffsetCache.get<std::vector<T> *>();
      90             :   }
      91             : 
      92       49609 :   const char *BufStart = Buffer->getBufferStart();
      93             :   assert(Ptr >= BufStart && Ptr <= Buffer->getBufferEnd());
      94       49609 :   ptrdiff_t PtrDiff = Ptr - BufStart;
      95             :   assert(PtrDiff >= 0 && static_cast<size_t>(PtrDiff) <= std::numeric_limits<T>::max());
      96       49609 :   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       49609 :   return (1 + (EOL - Offsets->begin()));
     106             : }
     107             : 
     108      603147 : SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other)
     109             :   : Buffer(std::move(Other.Buffer)),
     110             :     OffsetCache(Other.OffsetCache),
     111      603147 :     IncludeLoc(Other.IncludeLoc) {
     112             :   Other.OffsetCache = nullptr;
     113      603147 : }
     114             : 
     115     1909880 : SourceMgr::SrcBuffer::~SrcBuffer() {
     116      954940 :   if (!OffsetCache.isNull()) {
     117             :     if (OffsetCache.is<std::vector<uint8_t>*>())
     118         716 :       delete OffsetCache.get<std::vector<uint8_t>*>();
     119             :     else if (OffsetCache.is<std::vector<uint16_t>*>())
     120        2056 :       delete OffsetCache.get<std::vector<uint16_t>*>();
     121             :     else if (OffsetCache.is<std::vector<uint32_t>*>())
     122          17 :       delete OffsetCache.get<std::vector<uint32_t>*>();
     123             :     else
     124           0 :       delete OffsetCache.get<std::vector<uint64_t>*>();
     125             :     OffsetCache = nullptr;
     126             :   }
     127      954940 : }
     128             : 
     129             : std::pair<unsigned, unsigned>
     130       49609 : SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
     131       49609 :   if (!BufferID)
     132          98 :     BufferID = FindBufferContainingLoc(Loc);
     133             :   assert(BufferID && "Invalid Location!");
     134             : 
     135             :   auto &SB = getBufferInfo(BufferID);
     136             :   const char *Ptr = Loc.getPointer();
     137             : 
     138       49609 :   size_t Sz = SB.Buffer->getBufferSize();
     139             :   assert(Sz <= std::numeric_limits<uint64_t>::max());
     140             :   unsigned LineNo;
     141       49609 :   if (Sz <= std::numeric_limits<uint8_t>::max())
     142         864 :     LineNo = SB.getLineNumber<uint8_t>(Ptr);
     143       48745 :   else if (Sz <= std::numeric_limits<uint16_t>::max())
     144       32758 :     LineNo = SB.getLineNumber<uint16_t>(Ptr);
     145       15987 :   else if (Sz <= std::numeric_limits<uint32_t>::max())
     146       15987 :     LineNo = SB.getLineNumber<uint32_t>(Ptr);
     147             :   else
     148           0 :     LineNo = SB.getLineNumber<uint64_t>(Ptr);
     149             : 
     150       49609 :   const char *BufStart = SB.Buffer->getBufferStart();
     151       99218 :   size_t NewlineOffs = StringRef(BufStart, Ptr-BufStart).find_last_of("\n\r");
     152       49609 :   if (NewlineOffs == StringRef::npos) NewlineOffs = ~(size_t)0;
     153       99218 :   return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs);
     154             : }
     155             : 
     156        3661 : void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
     157        3661 :   if (IncludeLoc == SMLoc()) return;  // Top of stack.
     158             : 
     159           0 :   unsigned CurBuf = FindBufferContainingLoc(IncludeLoc);
     160             :   assert(CurBuf && "Invalid or unspecified location!");
     161             : 
     162           0 :   PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
     163             : 
     164           0 :   OS << "Included from "
     165           0 :      << getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
     166           0 :      << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n";
     167             : }
     168             : 
     169       49393 : SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
     170             :                                    const Twine &Msg,
     171             :                                    ArrayRef<SMRange> Ranges,
     172             :                                    ArrayRef<SMFixIt> FixIts) const {
     173             :   // First thing to do: find the current buffer containing the specified
     174             :   // location to pull out the source line.
     175             :   SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges;
     176             :   std::pair<unsigned, unsigned> LineAndCol;
     177             :   StringRef BufferID = "<unknown>";
     178             :   std::string LineStr;
     179             :   
     180       49393 :   if (Loc.isValid()) {
     181       49324 :     unsigned CurBuf = FindBufferContainingLoc(Loc);
     182             :     assert(CurBuf && "Invalid or unspecified location!");
     183             : 
     184             :     const MemoryBuffer *CurMB = getMemoryBuffer(CurBuf);
     185       49324 :     BufferID = CurMB->getBufferIdentifier();
     186             :     
     187             :     // Scan backward to find the start of the line.
     188             :     const char *LineStart = Loc.getPointer();
     189       49324 :     const char *BufStart = CurMB->getBufferStart();
     190     1173026 :     while (LineStart != BufStart && LineStart[-1] != '\n' &&
     191             :            LineStart[-1] != '\r')
     192      561851 :       --LineStart;
     193             : 
     194             :     // Get the end of the line.
     195             :     const char *LineEnd = Loc.getPointer();
     196       49324 :     const char *BufEnd = CurMB->getBufferEnd();
     197     2533016 :     while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r')
     198     1241846 :       ++LineEnd;
     199       98648 :     LineStr = std::string(LineStart, LineEnd);
     200             : 
     201             :     // Convert any ranges to column ranges that only intersect the line of the
     202             :     // location.
     203       94365 :     for (unsigned i = 0, e = Ranges.size(); i != e; ++i) {
     204       90082 :       SMRange R = Ranges[i];
     205       45041 :       if (!R.isValid()) continue;
     206             :       
     207             :       // If the line doesn't contain any part of the range, then ignore it.
     208         376 :       if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
     209           0 :         continue;
     210             :      
     211             :       // Ignore pieces of the range that go onto other lines.
     212         376 :       if (R.Start.getPointer() < LineStart)
     213             :         R.Start = SMLoc::getFromPointer(LineStart);
     214         376 :       if (R.End.getPointer() > LineEnd)
     215             :         R.End = SMLoc::getFromPointer(LineEnd);
     216             :       
     217             :       // Translate from SMLoc ranges to column ranges.
     218             :       // FIXME: Handle multibyte characters.
     219         752 :       ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
     220         376 :                                          R.End.getPointer()-LineStart));
     221             :     }
     222             : 
     223       98648 :     LineAndCol = getLineAndColumn(Loc, CurBuf);
     224             :   }
     225             :     
     226             :   return SMDiagnostic(*this, Loc, BufferID, LineAndCol.first,
     227      148179 :                       LineAndCol.second-1, Kind, Msg.str(),
     228      148179 :                       LineStr, ColRanges, FixIts);
     229             : }
     230             : 
     231       49068 : void SourceMgr::PrintMessage(raw_ostream &OS, const SMDiagnostic &Diagnostic,
     232             :                              bool ShowColors) const {
     233             :   // Report the message with the diagnostic handler if present.
     234       49068 :   if (DiagHandler) {
     235       45444 :     DiagHandler(Diagnostic, DiagContext);
     236       45444 :     return;
     237             :   }
     238             : 
     239        3624 :   if (Diagnostic.getLoc().isValid()) {
     240        3624 :     unsigned CurBuf = FindBufferContainingLoc(Diagnostic.getLoc());
     241             :     assert(CurBuf && "Invalid or unspecified location!");
     242        3624 :     PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS);
     243             :   }
     244             : 
     245        3624 :   Diagnostic.print(nullptr, OS, ShowColors);
     246             : }
     247             : 
     248       49068 : void SourceMgr::PrintMessage(raw_ostream &OS, SMLoc Loc,
     249             :                              SourceMgr::DiagKind Kind,
     250             :                              const Twine &Msg, ArrayRef<SMRange> Ranges,
     251             :                              ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
     252       49068 :   PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors);
     253       49068 : }
     254             : 
     255       49028 : void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind,
     256             :                              const Twine &Msg, ArrayRef<SMRange> Ranges,
     257             :                              ArrayRef<SMFixIt> FixIts, bool ShowColors) const {
     258       49028 :   PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors);
     259       49028 : }
     260             : 
     261             : //===----------------------------------------------------------------------===//
     262             : // SMDiagnostic Implementation
     263             : //===----------------------------------------------------------------------===//
     264             : 
     265       49535 : SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, StringRef FN,
     266             :                            int Line, int Col, SourceMgr::DiagKind Kind,
     267             :                            StringRef Msg, StringRef LineStr,
     268             :                            ArrayRef<std::pair<unsigned,unsigned>> Ranges,
     269       49535 :                            ArrayRef<SMFixIt> Hints)
     270             :   : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind),
     271             :     Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()),
     272       99070 :     FixIts(Hints.begin(), Hints.end()) {
     273             :   llvm::sort(FixIts.begin(), FixIts.end());
     274       49535 : }
     275             : 
     276       49260 : static void buildFixItLine(std::string &CaretLine, std::string &FixItLine,
     277             :                            ArrayRef<SMFixIt> FixIts, ArrayRef<char> SourceLine){
     278       49260 :   if (FixIts.empty())
     279             :     return;
     280             : 
     281             :   const char *LineStart = SourceLine.begin();
     282             :   const char *LineEnd = SourceLine.end();
     283             : 
     284             :   size_t PrevHintEndCol = 0;
     285             : 
     286          23 :   for (ArrayRef<SMFixIt>::iterator I = FixIts.begin(), E = FixIts.end();
     287          46 :        I != E; ++I) {
     288             :     // If the fixit contains a newline or tab, ignore it.
     289          46 :     if (I->getText().find_first_of("\n\r\t") != StringRef::npos)
     290           0 :       continue;
     291             : 
     292             :     SMRange R = I->getRange();
     293             : 
     294             :     // If the line doesn't contain any part of the range, then ignore it.
     295          23 :     if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart)
     296           0 :       continue;
     297             : 
     298             :     // Translate from SMLoc to column.
     299             :     // Ignore pieces of the range that go onto other lines.
     300             :     // FIXME: Handle multibyte characters in the source line.
     301             :     unsigned FirstCol;
     302          23 :     if (R.Start.getPointer() < LineStart)
     303             :       FirstCol = 0;
     304             :     else
     305          23 :       FirstCol = R.Start.getPointer() - LineStart;
     306             : 
     307             :     // If we inserted a long previous hint, push this one forwards, and add
     308             :     // an extra space to show that this is not part of the previous
     309             :     // completion. This is sort of the best we can do when two hints appear
     310             :     // to overlap.
     311             :     //
     312             :     // Note that if this hint is located immediately after the previous
     313             :     // hint, no space will be added, since the location is more important.
     314             :     unsigned HintCol = FirstCol;
     315          23 :     if (HintCol < PrevHintEndCol)
     316           0 :       HintCol = PrevHintEndCol + 1;
     317             : 
     318             :     // FIXME: This assertion is intended to catch unintended use of multibyte
     319             :     // characters in fixits. If we decide to do this, we'll have to track
     320             :     // separate byte widths for the source and fixit lines.
     321             :     assert((size_t)sys::locale::columnWidth(I->getText()) ==
     322             :            I->getText().size());
     323             : 
     324             :     // This relies on one byte per column in our fixit hints.
     325          23 :     unsigned LastColumnModified = HintCol + I->getText().size();
     326          23 :     if (LastColumnModified > FixItLine.size())
     327          23 :       FixItLine.resize(LastColumnModified, ' ');
     328             : 
     329             :     std::copy(I->getText().begin(), I->getText().end(),
     330             :               FixItLine.begin() + HintCol);
     331             : 
     332             :     PrevHintEndCol = LastColumnModified;
     333             : 
     334             :     // For replacements, mark the removal range with '~'.
     335             :     // FIXME: Handle multibyte characters in the source line.
     336             :     unsigned LastCol;
     337          23 :     if (R.End.getPointer() >= LineEnd)
     338           1 :       LastCol = LineEnd - LineStart;
     339             :     else
     340          22 :       LastCol = R.End.getPointer() - LineStart;
     341             : 
     342          23 :     std::fill(&CaretLine[FirstCol], &CaretLine[LastCol], '~');
     343             :   }
     344             : }
     345             : 
     346       49263 : static void printSourceLine(raw_ostream &S, StringRef LineContents) {
     347             :   // Print out the source line one character at a time, so we can expand tabs.
     348     1850116 :   for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) {
     349     5378526 :     if (LineContents[i] != '\t') {
     350             :       S << LineContents[i];
     351     1776820 :       ++OutCol;
     352     1776820 :       continue;
     353             :     }
     354             : 
     355             :     // If we have a tab, emit at least one space, then round up to 8 columns.
     356             :     do {
     357             :       S << ' ';
     358      137531 :       ++OutCol;
     359      137531 :     } while ((OutCol % TabStop) != 0);
     360             :   }
     361             :   S << '\n';
     362       49263 : }
     363             : 
     364     1800796 : static bool isNonASCII(char c) {
     365     1800796 :   return c & 0x80;
     366             : }
     367             : 
     368       49339 : void SMDiagnostic::print(const char *ProgName, raw_ostream &S, bool ShowColors,
     369             :                          bool ShowKindLabel) const {
     370             :   // Display colors only if OS supports colors.
     371       49339 :   ShowColors &= S.has_colors();
     372             : 
     373       49339 :   if (ShowColors)
     374           0 :     S.changeColor(raw_ostream::SAVEDCOLOR, true);
     375             : 
     376       49339 :   if (ProgName && ProgName[0])
     377         204 :     S << ProgName << ": ";
     378             : 
     379       49339 :   if (!Filename.empty()) {
     380       98512 :     if (Filename == "-")
     381           0 :       S << "<stdin>";
     382             :     else
     383             :       S << Filename;
     384             : 
     385       49256 :     if (LineNo != -1) {
     386       49249 :       S << ':' << LineNo;
     387       49249 :       if (ColumnNo != -1)
     388       49180 :         S << ':' << (ColumnNo+1);
     389             :     }
     390       49256 :     S << ": ";
     391             :   }
     392             : 
     393       49339 :   if (ShowKindLabel) {
     394       49221 :     switch (Kind) {
     395       40054 :     case SourceMgr::DK_Error:
     396       40054 :       if (ShowColors)
     397           0 :         S.changeColor(raw_ostream::RED, true);
     398       40054 :       S << "error: ";
     399       40054 :       break;
     400        5546 :     case SourceMgr::DK_Warning:
     401        5546 :       if (ShowColors)
     402           0 :         S.changeColor(raw_ostream::MAGENTA, true);
     403        5546 :       S << "warning: ";
     404        5546 :       break;
     405        3620 :     case SourceMgr::DK_Note:
     406        3620 :       if (ShowColors)
     407           0 :         S.changeColor(raw_ostream::BLACK, true);
     408        3620 :       S << "note: ";
     409        3620 :       break;
     410           1 :     case SourceMgr::DK_Remark:
     411           1 :       if (ShowColors)
     412           0 :         S.changeColor(raw_ostream::BLUE, true);
     413           1 :       S << "remark: ";
     414           1 :       break;
     415             :     }
     416             : 
     417       49221 :     if (ShowColors) {
     418           0 :       S.resetColor();
     419           0 :       S.changeColor(raw_ostream::SAVEDCOLOR, true);
     420             :     }
     421             :   }
     422             : 
     423             :   S << Message << '\n';
     424             : 
     425       49339 :   if (ShowColors)
     426           0 :     S.resetColor();
     427             : 
     428       49339 :   if (LineNo == -1 || ColumnNo == -1)
     429       49316 :     return;
     430             : 
     431             :   // FIXME: If there are multibyte or multi-column characters in the source, all
     432             :   // our ranges will be wrong. To do this properly, we'll need a byte-to-column
     433             :   // map like Clang's TextDiagnostic. For now, we'll just handle tabs by
     434             :   // expanding them later, and bail out rather than show incorrect ranges and
     435             :   // misaligned fixits for any other odd characters.
     436       49263 :   if (find_if(LineContents, isNonASCII) != LineContents.end()) {
     437           3 :     printSourceLine(S, LineContents);
     438           3 :     return;
     439             :   }
     440       49260 :   size_t NumColumns = LineContents.size();
     441             : 
     442             :   // Build the line with the caret and ranges.
     443       49260 :   std::string CaretLine(NumColumns+1, ' ');
     444             :   
     445             :   // Expand any ranges.
     446       98825 :   for (unsigned r = 0, e = Ranges.size(); r != e; ++r) {
     447         610 :     std::pair<unsigned, unsigned> R = Ranges[r];
     448         305 :     std::fill(&CaretLine[R.first],
     449         915 :               &CaretLine[std::min((size_t)R.second, CaretLine.size())],
     450             :               '~');
     451             :   }
     452             : 
     453             :   // Add any fix-its.
     454             :   // FIXME: Find the beginning of the line properly for multibyte characters.
     455             :   std::string FixItInsertionLine;
     456      147780 :   buildFixItLine(CaretLine, FixItInsertionLine, FixIts,
     457       49260 :                  makeArrayRef(Loc.getPointer() - ColumnNo,
     458             :                               LineContents.size()));
     459             : 
     460             :   // Finally, plop on the caret.
     461       49260 :   if (unsigned(ColumnNo) <= NumColumns)
     462       98520 :     CaretLine[ColumnNo] = '^';
     463             :   else 
     464           0 :     CaretLine[NumColumns] = '^';
     465             :   
     466             :   // ... and remove trailing whitespace so the output doesn't wrap for it.  We
     467             :   // know that the line isn't completely empty because it has the caret in it at
     468             :   // least.
     469       49260 :   CaretLine.erase(CaretLine.find_last_not_of(' ')+1);
     470             :   
     471       49260 :   printSourceLine(S, LineContents);
     472             : 
     473       49260 :   if (ShowColors)
     474           0 :     S.changeColor(raw_ostream::GREEN, true);
     475             : 
     476             :   // Print out the caret line, matching tabs in the source line.
     477      659905 :   for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) {
     478     1809928 :     if (i >= LineContents.size() || LineContents[i] != '\t') {
     479      589096 :       S << CaretLine[i];
     480      589096 :       ++OutCol;
     481      589096 :       continue;
     482             :     }
     483             :     
     484             :     // Okay, we have a tab.  Insert the appropriate number of characters.
     485             :     do {
     486      131835 :       S << CaretLine[i];
     487      131835 :       ++OutCol;
     488      131835 :     } while ((OutCol % TabStop) != 0);
     489             :   }
     490             :   S << '\n';
     491             : 
     492       49260 :   if (ShowColors)
     493           0 :     S.resetColor();
     494             : 
     495             :   // Print out the replacement line, matching tabs in the source line.
     496       49260 :   if (FixItInsertionLine.empty())
     497             :     return;
     498             :   
     499        1369 :   for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) {
     500        2004 :     if (i >= LineContents.size() || LineContents[i] != '\t') {
     501         658 :       S << FixItInsertionLine[i];
     502         658 :       ++OutCol;
     503         658 :       continue;
     504             :     }
     505             : 
     506             :     // Okay, we have a tab.  Insert the appropriate number of characters.
     507             :     do {
     508          55 :       S << FixItInsertionLine[i];
     509             :       // FIXME: This is trying not to break up replacements, but then to re-sync
     510             :       // with the tabs between replacements. This will fail, though, if two
     511             :       // fix-it replacements are exactly adjacent, or if a fix-it contains a
     512             :       // space. Really we should be precomputing column widths, which we'll
     513             :       // need anyway for multibyte chars.
     514          55 :       if (FixItInsertionLine[i] != ' ')
     515           3 :         ++i;
     516          55 :       ++OutCol;
     517          55 :     } while (((OutCol % TabStop) != 0) && i != e);
     518             :   }
     519             :   S << '\n';
     520             : }

Generated by: LCOV version 1.13