| Chris Lattner | 1b30e1ac | 2009-06-21 03:36:54 +0000 | [diff] [blame] | 1 | //===- SourceMgr.cpp - Manager for Simple Source Buffers & Diagnostics ----===// | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | // | 
| Chris Lattner | 1b30e1ac | 2009-06-21 03:36:54 +0000 | [diff] [blame] | 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. | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 12 | // | 
|  | 13 | //===----------------------------------------------------------------------===// | 
|  | 14 |  | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 15 | #include "llvm/Support/SourceMgr.h" | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/ArrayRef.h" | 
| David Majnemer | 562e829 | 2016-08-12 00:18:03 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallVector.h" | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringRef.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/Twine.h" | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 21 | #include "llvm/Support/ErrorOr.h" | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Locale.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/Support/MemoryBuffer.h" | 
| Yaron Keren | 1521720 | 2014-05-16 13:16:30 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Path.h" | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 25 | #include "llvm/Support/SMLoc.h" | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 26 | #include "llvm/Support/WithColor.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 28 | #include <algorithm> | 
|  | 29 | #include <cassert> | 
|  | 30 | #include <cstddef> | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 31 | #include <limits> | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 32 | #include <memory> | 
|  | 33 | #include <string> | 
|  | 34 | #include <utility> | 
|  | 35 |  | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 36 | using namespace llvm; | 
|  | 37 |  | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 38 | static const size_t TabStop = 8; | 
|  | 39 |  | 
| Dmitri Gribenko | a5b27a7 | 2014-07-09 08:30:15 +0000 | [diff] [blame] | 40 | unsigned SourceMgr::AddIncludeFile(const std::string &Filename, | 
|  | 41 | SMLoc IncludeLoc, | 
|  | 42 | std::string &IncludedFile) { | 
| Joerg Sonnenberger | af5f23e | 2011-06-01 13:10:15 +0000 | [diff] [blame] | 43 | IncludedFile = Filename; | 
| Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 44 | ErrorOr<std::unique_ptr<MemoryBuffer>> NewBufOrErr = | 
| Matt Arsenault | 6e863d1 | 2014-11-06 01:13:27 +0000 | [diff] [blame] | 45 | MemoryBuffer::getFile(IncludedFile); | 
| Chris Lattner | 976af62 | 2009-06-21 05:06:04 +0000 | [diff] [blame] | 46 |  | 
|  | 47 | // If the file didn't exist directly, see if it's in an include path. | 
| Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 48 | for (unsigned i = 0, e = IncludeDirectories.size(); i != e && !NewBufOrErr; | 
|  | 49 | ++i) { | 
|  | 50 | IncludedFile = | 
|  | 51 | IncludeDirectories[i] + sys::path::get_separator().data() + Filename; | 
| Matt Arsenault | 6e863d1 | 2014-11-06 01:13:27 +0000 | [diff] [blame] | 52 | NewBufOrErr = MemoryBuffer::getFile(IncludedFile); | 
| Chris Lattner | 976af62 | 2009-06-21 05:06:04 +0000 | [diff] [blame] | 53 | } | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 54 |  | 
| Rafael Espindola | adf21f2 | 2014-07-06 17:43:13 +0000 | [diff] [blame] | 55 | if (!NewBufOrErr) | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 56 | return 0; | 
| Chris Lattner | 976af62 | 2009-06-21 05:06:04 +0000 | [diff] [blame] | 57 |  | 
| David Blaikie | 1961f14 | 2014-08-21 20:44:56 +0000 | [diff] [blame] | 58 | return AddNewSourceBuffer(std::move(*NewBufOrErr), IncludeLoc); | 
| Chris Lattner | 976af62 | 2009-06-21 05:06:04 +0000 | [diff] [blame] | 59 | } | 
|  | 60 |  | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 61 | unsigned SourceMgr::FindBufferContainingLoc(SMLoc Loc) const { | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 62 | for (unsigned i = 0, e = Buffers.size(); i != e; ++i) | 
| Chris Lattner | 87710ca | 2009-03-13 16:01:53 +0000 | [diff] [blame] | 63 | if (Loc.getPointer() >= Buffers[i].Buffer->getBufferStart() && | 
| Chris Lattner | 0f6dc78 | 2009-03-18 20:36:45 +0000 | [diff] [blame] | 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()) | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 67 | return i + 1; | 
|  | 68 | return 0; | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 69 | } | 
|  | 70 |  | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 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(); | 
|  | 81 | assert(Sz <= std::numeric_limits<T>::max()); | 
|  | 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 |  | 
| Fangrui Song | dc8de60 | 2019-06-21 05:40:31 +0000 | [diff] [blame] | 98 | // llvm::lower_bound gives the number of EOL before PtrOffset. Add 1 to get | 
|  | 99 | // the line number. | 
|  | 100 | return llvm::lower_bound(*Offsets, PtrOffset) - Offsets->begin() + 1; | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 101 | } | 
|  | 102 |  | 
|  | 103 | SourceMgr::SrcBuffer::SrcBuffer(SourceMgr::SrcBuffer &&Other) | 
|  | 104 | : Buffer(std::move(Other.Buffer)), | 
|  | 105 | OffsetCache(Other.OffsetCache), | 
|  | 106 | IncludeLoc(Other.IncludeLoc) { | 
|  | 107 | Other.OffsetCache = nullptr; | 
|  | 108 | } | 
|  | 109 |  | 
|  | 110 | SourceMgr::SrcBuffer::~SrcBuffer() { | 
|  | 111 | if (!OffsetCache.isNull()) { | 
|  | 112 | if (OffsetCache.is<std::vector<uint8_t>*>()) | 
|  | 113 | delete OffsetCache.get<std::vector<uint8_t>*>(); | 
|  | 114 | else if (OffsetCache.is<std::vector<uint16_t>*>()) | 
|  | 115 | delete OffsetCache.get<std::vector<uint16_t>*>(); | 
|  | 116 | else if (OffsetCache.is<std::vector<uint32_t>*>()) | 
|  | 117 | delete OffsetCache.get<std::vector<uint32_t>*>(); | 
|  | 118 | else | 
|  | 119 | delete OffsetCache.get<std::vector<uint64_t>*>(); | 
|  | 120 | OffsetCache = nullptr; | 
|  | 121 | } | 
|  | 122 | } | 
|  | 123 |  | 
| Chris Lattner | 9322ba8 | 2012-05-05 22:17:32 +0000 | [diff] [blame] | 124 | std::pair<unsigned, unsigned> | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 125 | SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const { | 
|  | 126 | if (!BufferID) | 
|  | 127 | BufferID = FindBufferContainingLoc(Loc); | 
|  | 128 | assert(BufferID && "Invalid Location!"); | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 129 |  | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 130 | auto &SB = getBufferInfo(BufferID); | 
|  | 131 | const char *Ptr = Loc.getPointer(); | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 132 |  | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 133 | size_t Sz = SB.Buffer->getBufferSize(); | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 134 | unsigned LineNo; | 
|  | 135 | if (Sz <= std::numeric_limits<uint8_t>::max()) | 
|  | 136 | LineNo = SB.getLineNumber<uint8_t>(Ptr); | 
|  | 137 | else if (Sz <= std::numeric_limits<uint16_t>::max()) | 
|  | 138 | LineNo = SB.getLineNumber<uint16_t>(Ptr); | 
|  | 139 | else if (Sz <= std::numeric_limits<uint32_t>::max()) | 
|  | 140 | LineNo = SB.getLineNumber<uint32_t>(Ptr); | 
|  | 141 | else | 
|  | 142 | LineNo = SB.getLineNumber<uint64_t>(Ptr); | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 143 |  | 
| Graydon Hoare | 54fe208 | 2018-04-07 00:44:02 +0000 | [diff] [blame] | 144 | const char *BufStart = SB.Buffer->getBufferStart(); | 
| Chris Lattner | 9322ba8 | 2012-05-05 22:17:32 +0000 | [diff] [blame] | 145 | size_t NewlineOffs = StringRef(BufStart, Ptr-BufStart).find_last_of("\n\r"); | 
| Matt Beaumont-Gay | a1b3b00 | 2012-05-07 18:12:42 +0000 | [diff] [blame] | 146 | if (NewlineOffs == StringRef::npos) NewlineOffs = ~(size_t)0; | 
| Chris Lattner | 9322ba8 | 2012-05-05 22:17:32 +0000 | [diff] [blame] | 147 | return std::make_pair(LineNo, Ptr-BufStart-NewlineOffs); | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 148 | } | 
|  | 149 |  | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 150 | void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const { | 
| Chris Lattner | 526c8cb | 2009-06-21 03:39:35 +0000 | [diff] [blame] | 151 | if (IncludeLoc == SMLoc()) return;  // Top of stack. | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 152 |  | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 153 | unsigned CurBuf = FindBufferContainingLoc(IncludeLoc); | 
|  | 154 | assert(CurBuf && "Invalid or unspecified location!"); | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 155 |  | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 156 | PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS); | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 157 |  | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 158 | OS << "Included from " | 
|  | 159 | << getBufferInfo(CurBuf).Buffer->getBufferIdentifier() | 
|  | 160 | << ":" << FindLineNumber(IncludeLoc, CurBuf) << ":\n"; | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 161 | } | 
|  | 162 |  | 
| Chris Lattner | 03b80a4 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 163 | SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind, | 
| Chris Lattner | 7284526 | 2011-10-16 05:47:55 +0000 | [diff] [blame] | 164 | const Twine &Msg, | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 165 | ArrayRef<SMRange> Ranges, | 
|  | 166 | ArrayRef<SMFixIt> FixIts) const { | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 167 | // First thing to do: find the current buffer containing the specified | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 168 | // location to pull out the source line. | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 169 | SmallVector<std::pair<unsigned, unsigned>, 4> ColRanges; | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 170 | std::pair<unsigned, unsigned> LineAndCol; | 
| Mehdi Amini | 99d1b29 | 2016-10-01 16:38:28 +0000 | [diff] [blame] | 171 | StringRef BufferID = "<unknown>"; | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 172 | std::string LineStr; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 173 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 174 | if (Loc.isValid()) { | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 175 | unsigned CurBuf = FindBufferContainingLoc(Loc); | 
|  | 176 | assert(CurBuf && "Invalid or unspecified location!"); | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 177 |  | 
| Alp Toker | 7899d50 | 2014-06-25 00:41:15 +0000 | [diff] [blame] | 178 | const MemoryBuffer *CurMB = getMemoryBuffer(CurBuf); | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 179 | BufferID = CurMB->getBufferIdentifier(); | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 180 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 181 | // Scan backward to find the start of the line. | 
|  | 182 | const char *LineStart = Loc.getPointer(); | 
|  | 183 | const char *BufStart = CurMB->getBufferStart(); | 
|  | 184 | while (LineStart != BufStart && LineStart[-1] != '\n' && | 
|  | 185 | LineStart[-1] != '\r') | 
|  | 186 | --LineStart; | 
|  | 187 |  | 
|  | 188 | // Get the end of the line. | 
|  | 189 | const char *LineEnd = Loc.getPointer(); | 
|  | 190 | const char *BufEnd = CurMB->getBufferEnd(); | 
|  | 191 | while (LineEnd != BufEnd && LineEnd[0] != '\n' && LineEnd[0] != '\r') | 
|  | 192 | ++LineEnd; | 
|  | 193 | LineStr = std::string(LineStart, LineEnd); | 
|  | 194 |  | 
|  | 195 | // Convert any ranges to column ranges that only intersect the line of the | 
|  | 196 | // location. | 
|  | 197 | for (unsigned i = 0, e = Ranges.size(); i != e; ++i) { | 
|  | 198 | SMRange R = Ranges[i]; | 
|  | 199 | if (!R.isValid()) continue; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 200 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 201 | // If the line doesn't contain any part of the range, then ignore it. | 
|  | 202 | if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart) | 
|  | 203 | continue; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 204 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 205 | // Ignore pieces of the range that go onto other lines. | 
|  | 206 | if (R.Start.getPointer() < LineStart) | 
|  | 207 | R.Start = SMLoc::getFromPointer(LineStart); | 
|  | 208 | if (R.End.getPointer() > LineEnd) | 
|  | 209 | R.End = SMLoc::getFromPointer(LineEnd); | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 210 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 211 | // Translate from SMLoc ranges to column ranges. | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 212 | // FIXME: Handle multibyte characters. | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 213 | ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart, | 
|  | 214 | R.End.getPointer()-LineStart)); | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | LineAndCol = getLineAndColumn(Loc, CurBuf); | 
|  | 218 | } | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 219 |  | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 220 | return SMDiagnostic(*this, Loc, BufferID, LineAndCol.first, | 
| Chris Lattner | 9322ba8 | 2012-05-05 22:17:32 +0000 | [diff] [blame] | 221 | LineAndCol.second-1, Kind, Msg.str(), | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 222 | LineStr, ColRanges, FixIts); | 
| Chris Lattner | 200e075 | 2009-07-02 23:08:13 +0000 | [diff] [blame] | 223 | } | 
|  | 224 |  | 
| Jordan Rose | 57ffdb0 | 2014-06-17 02:15:40 +0000 | [diff] [blame] | 225 | void SourceMgr::PrintMessage(raw_ostream &OS, const SMDiagnostic &Diagnostic, | 
|  | 226 | bool ShowColors) const { | 
| Chris Lattner | 3c79981 | 2010-04-06 00:26:48 +0000 | [diff] [blame] | 227 | // Report the message with the diagnostic handler if present. | 
|  | 228 | if (DiagHandler) { | 
| Chris Lattner | 03b80a4 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 229 | DiagHandler(Diagnostic, DiagContext); | 
| Chris Lattner | 3c79981 | 2010-04-06 00:26:48 +0000 | [diff] [blame] | 230 | return; | 
|  | 231 | } | 
| Michael J. Spencer | db97c0b | 2010-12-09 17:37:32 +0000 | [diff] [blame] | 232 |  | 
| Jordan Rose | 57ffdb0 | 2014-06-17 02:15:40 +0000 | [diff] [blame] | 233 | if (Diagnostic.getLoc().isValid()) { | 
| Alp Toker | a55b95b | 2014-07-06 10:33:31 +0000 | [diff] [blame] | 234 | unsigned CurBuf = FindBufferContainingLoc(Diagnostic.getLoc()); | 
|  | 235 | assert(CurBuf && "Invalid or unspecified location!"); | 
| Chris Lattner | 854f366 | 2012-05-06 16:20:49 +0000 | [diff] [blame] | 236 | PrintIncludeStack(getBufferInfo(CurBuf).IncludeLoc, OS); | 
|  | 237 | } | 
| Chris Lattner | 200e075 | 2009-07-02 23:08:13 +0000 | [diff] [blame] | 238 |  | 
| Craig Topper | c10719f | 2014-04-07 04:17:22 +0000 | [diff] [blame] | 239 | Diagnostic.print(nullptr, OS, ShowColors); | 
| Chris Lattner | 8db9bc7 | 2009-03-13 07:05:43 +0000 | [diff] [blame] | 240 | } | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 241 |  | 
| Jordan Rose | 57ffdb0 | 2014-06-17 02:15:40 +0000 | [diff] [blame] | 242 | void SourceMgr::PrintMessage(raw_ostream &OS, SMLoc Loc, | 
|  | 243 | SourceMgr::DiagKind Kind, | 
|  | 244 | const Twine &Msg, ArrayRef<SMRange> Ranges, | 
|  | 245 | ArrayRef<SMFixIt> FixIts, bool ShowColors) const { | 
|  | 246 | PrintMessage(OS, GetMessage(Loc, Kind, Msg, Ranges, FixIts), ShowColors); | 
|  | 247 | } | 
|  | 248 |  | 
| Dmitri Gribenko | 8f94462 | 2013-09-27 21:09:25 +0000 | [diff] [blame] | 249 | void SourceMgr::PrintMessage(SMLoc Loc, SourceMgr::DiagKind Kind, | 
|  | 250 | const Twine &Msg, ArrayRef<SMRange> Ranges, | 
|  | 251 | ArrayRef<SMFixIt> FixIts, bool ShowColors) const { | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 252 | PrintMessage(errs(), Loc, Kind, Msg, Ranges, FixIts, ShowColors); | 
| Dmitri Gribenko | 8f94462 | 2013-09-27 21:09:25 +0000 | [diff] [blame] | 253 | } | 
|  | 254 |  | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 255 | //===----------------------------------------------------------------------===// | 
|  | 256 | // SMDiagnostic Implementation | 
|  | 257 | //===----------------------------------------------------------------------===// | 
|  | 258 |  | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 259 | SMDiagnostic::SMDiagnostic(const SourceMgr &sm, SMLoc L, StringRef FN, | 
| Chris Lattner | 03b80a4 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 260 | int Line, int Col, SourceMgr::DiagKind Kind, | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 261 | StringRef Msg, StringRef LineStr, | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 262 | ArrayRef<std::pair<unsigned,unsigned>> Ranges, | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 263 | ArrayRef<SMFixIt> Hints) | 
| Chris Lattner | 03b80a4 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 264 | : SM(&sm), Loc(L), Filename(FN), LineNo(Line), ColumnNo(Col), Kind(Kind), | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 265 | Message(Msg), LineContents(LineStr), Ranges(Ranges.vec()), | 
|  | 266 | FixIts(Hints.begin(), Hints.end()) { | 
| Fangrui Song | 0cac726 | 2018-09-27 02:13:45 +0000 | [diff] [blame] | 267 | llvm::sort(FixIts); | 
| Chris Lattner | 03b80a4 | 2011-10-16 05:43:57 +0000 | [diff] [blame] | 268 | } | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 269 |  | 
| Benjamin Kramer | 6ecb1e7 | 2013-02-15 12:30:38 +0000 | [diff] [blame] | 270 | static void buildFixItLine(std::string &CaretLine, std::string &FixItLine, | 
|  | 271 | ArrayRef<SMFixIt> FixIts, ArrayRef<char> SourceLine){ | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 272 | if (FixIts.empty()) | 
|  | 273 | return; | 
|  | 274 |  | 
|  | 275 | const char *LineStart = SourceLine.begin(); | 
|  | 276 | const char *LineEnd = SourceLine.end(); | 
|  | 277 |  | 
|  | 278 | size_t PrevHintEndCol = 0; | 
|  | 279 |  | 
|  | 280 | for (ArrayRef<SMFixIt>::iterator I = FixIts.begin(), E = FixIts.end(); | 
|  | 281 | I != E; ++I) { | 
|  | 282 | // If the fixit contains a newline or tab, ignore it. | 
|  | 283 | if (I->getText().find_first_of("\n\r\t") != StringRef::npos) | 
|  | 284 | continue; | 
|  | 285 |  | 
|  | 286 | SMRange R = I->getRange(); | 
|  | 287 |  | 
|  | 288 | // If the line doesn't contain any part of the range, then ignore it. | 
|  | 289 | if (R.Start.getPointer() > LineEnd || R.End.getPointer() < LineStart) | 
|  | 290 | continue; | 
|  | 291 |  | 
|  | 292 | // Translate from SMLoc to column. | 
|  | 293 | // Ignore pieces of the range that go onto other lines. | 
|  | 294 | // FIXME: Handle multibyte characters in the source line. | 
|  | 295 | unsigned FirstCol; | 
|  | 296 | if (R.Start.getPointer() < LineStart) | 
|  | 297 | FirstCol = 0; | 
|  | 298 | else | 
|  | 299 | FirstCol = R.Start.getPointer() - LineStart; | 
|  | 300 |  | 
|  | 301 | // If we inserted a long previous hint, push this one forwards, and add | 
|  | 302 | // an extra space to show that this is not part of the previous | 
|  | 303 | // completion. This is sort of the best we can do when two hints appear | 
|  | 304 | // to overlap. | 
|  | 305 | // | 
|  | 306 | // Note that if this hint is located immediately after the previous | 
|  | 307 | // hint, no space will be added, since the location is more important. | 
|  | 308 | unsigned HintCol = FirstCol; | 
|  | 309 | if (HintCol < PrevHintEndCol) | 
|  | 310 | HintCol = PrevHintEndCol + 1; | 
|  | 311 |  | 
|  | 312 | // FIXME: This assertion is intended to catch unintended use of multibyte | 
|  | 313 | // characters in fixits. If we decide to do this, we'll have to track | 
|  | 314 | // separate byte widths for the source and fixit lines. | 
| Eugene Zelenko | 454d0ce | 2017-02-15 22:17:02 +0000 | [diff] [blame] | 315 | assert((size_t)sys::locale::columnWidth(I->getText()) == | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 316 | I->getText().size()); | 
|  | 317 |  | 
|  | 318 | // This relies on one byte per column in our fixit hints. | 
|  | 319 | unsigned LastColumnModified = HintCol + I->getText().size(); | 
|  | 320 | if (LastColumnModified > FixItLine.size()) | 
|  | 321 | FixItLine.resize(LastColumnModified, ' '); | 
|  | 322 |  | 
|  | 323 | std::copy(I->getText().begin(), I->getText().end(), | 
|  | 324 | FixItLine.begin() + HintCol); | 
|  | 325 |  | 
|  | 326 | PrevHintEndCol = LastColumnModified; | 
|  | 327 |  | 
|  | 328 | // For replacements, mark the removal range with '~'. | 
|  | 329 | // FIXME: Handle multibyte characters in the source line. | 
|  | 330 | unsigned LastCol; | 
|  | 331 | if (R.End.getPointer() >= LineEnd) | 
|  | 332 | LastCol = LineEnd - LineStart; | 
|  | 333 | else | 
|  | 334 | LastCol = R.End.getPointer() - LineStart; | 
|  | 335 |  | 
|  | 336 | std::fill(&CaretLine[FirstCol], &CaretLine[LastCol], '~'); | 
|  | 337 | } | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | static void printSourceLine(raw_ostream &S, StringRef LineContents) { | 
|  | 341 | // Print out the source line one character at a time, so we can expand tabs. | 
|  | 342 | for (unsigned i = 0, e = LineContents.size(), OutCol = 0; i != e; ++i) { | 
| Reid Kleckner | 2b8c692 | 2018-09-05 00:08:56 +0000 | [diff] [blame] | 343 | size_t NextTab = LineContents.find('\t', i); | 
|  | 344 | // If there were no tabs left, print the rest, we are done. | 
|  | 345 | if (NextTab == StringRef::npos) { | 
|  | 346 | S << LineContents.drop_front(i); | 
|  | 347 | break; | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
| Reid Kleckner | 2b8c692 | 2018-09-05 00:08:56 +0000 | [diff] [blame] | 350 | // Otherwise, print from i to NextTab. | 
|  | 351 | S << LineContents.slice(i, NextTab); | 
|  | 352 | OutCol += NextTab - i; | 
|  | 353 | i = NextTab; | 
|  | 354 |  | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 355 | // If we have a tab, emit at least one space, then round up to 8 columns. | 
|  | 356 | do { | 
|  | 357 | S << ' '; | 
|  | 358 | ++OutCol; | 
|  | 359 | } while ((OutCol % TabStop) != 0); | 
|  | 360 | } | 
|  | 361 | S << '\n'; | 
|  | 362 | } | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 363 |  | 
| Jordan Rose | ceb1dbb | 2013-01-11 02:37:55 +0000 | [diff] [blame] | 364 | static bool isNonASCII(char c) { | 
|  | 365 | return c & 0x80; | 
|  | 366 | } | 
|  | 367 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 368 | void SMDiagnostic::print(const char *ProgName, raw_ostream &OS, | 
|  | 369 | bool ShowColors, bool ShowKindLabel) const { | 
|  | 370 | { | 
|  | 371 | WithColor S(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors); | 
| Benjamin Kramer | bb73d19 | 2012-04-18 19:04:15 +0000 | [diff] [blame] | 372 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 373 | if (ProgName && ProgName[0]) | 
|  | 374 | S << ProgName << ": "; | 
| Benjamin Kramer | bb73d19 | 2012-04-18 19:04:15 +0000 | [diff] [blame] | 375 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 376 | if (!Filename.empty()) { | 
|  | 377 | if (Filename == "-") | 
|  | 378 | S << "<stdin>"; | 
|  | 379 | else | 
|  | 380 | S << Filename; | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 381 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 382 | if (LineNo != -1) { | 
|  | 383 | S << ':' << LineNo; | 
|  | 384 | if (ColumnNo != -1) | 
|  | 385 | S << ':' << (ColumnNo + 1); | 
|  | 386 | } | 
|  | 387 | S << ": "; | 
| Dan Gohman | 7c67590 | 2010-01-21 10:13:27 +0000 | [diff] [blame] | 388 | } | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 389 | } | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 390 |  | 
| Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 391 | if (ShowKindLabel) { | 
|  | 392 | switch (Kind) { | 
|  | 393 | case SourceMgr::DK_Error: | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 394 | WithColor::error(OS, "", !ShowColors); | 
| Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 395 | break; | 
|  | 396 | case SourceMgr::DK_Warning: | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 397 | WithColor::warning(OS, "", !ShowColors); | 
| Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 398 | break; | 
|  | 399 | case SourceMgr::DK_Note: | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 400 | WithColor::note(OS, "", !ShowColors); | 
| Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 401 | break; | 
| Adam Nemet | 01104ae | 2017-10-12 23:56:02 +0000 | [diff] [blame] | 402 | case SourceMgr::DK_Remark: | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 403 | WithColor::remark(OS, "", !ShowColors); | 
| Adam Nemet | 01104ae | 2017-10-12 23:56:02 +0000 | [diff] [blame] | 404 | break; | 
| Alex Lorenz | 735c47e | 2015-06-15 20:30:22 +0000 | [diff] [blame] | 405 | } | 
| Benjamin Kramer | bb73d19 | 2012-04-18 19:04:15 +0000 | [diff] [blame] | 406 | } | 
|  | 407 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 408 | WithColor(OS, raw_ostream::SAVEDCOLOR, true, false, !ShowColors) | 
|  | 409 | << Message << '\n'; | 
| Benjamin Kramer | bb73d19 | 2012-04-18 19:04:15 +0000 | [diff] [blame] | 410 |  | 
| Chris Lattner | 7284526 | 2011-10-16 05:47:55 +0000 | [diff] [blame] | 411 | if (LineNo == -1 || ColumnNo == -1) | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 412 | return; | 
| Mikhail Glushenkov | 84afae3 | 2010-01-27 10:13:11 +0000 | [diff] [blame] | 413 |  | 
| Jordan Rose | ceb1dbb | 2013-01-11 02:37:55 +0000 | [diff] [blame] | 414 | // FIXME: If there are multibyte or multi-column characters in the source, all | 
|  | 415 | // our ranges will be wrong. To do this properly, we'll need a byte-to-column | 
|  | 416 | // map like Clang's TextDiagnostic. For now, we'll just handle tabs by | 
|  | 417 | // expanding them later, and bail out rather than show incorrect ranges and | 
|  | 418 | // misaligned fixits for any other odd characters. | 
| David Majnemer | 562e829 | 2016-08-12 00:18:03 +0000 | [diff] [blame] | 419 | if (find_if(LineContents, isNonASCII) != LineContents.end()) { | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 420 | printSourceLine(OS, LineContents); | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 421 | return; | 
|  | 422 | } | 
| Jordan Rose | ceb1dbb | 2013-01-11 02:37:55 +0000 | [diff] [blame] | 423 | size_t NumColumns = LineContents.size(); | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 424 |  | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 425 | // Build the line with the caret and ranges. | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 426 | std::string CaretLine(NumColumns+1, ' '); | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 427 |  | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 428 | // Expand any ranges. | 
|  | 429 | for (unsigned r = 0, e = Ranges.size(); r != e; ++r) { | 
|  | 430 | std::pair<unsigned, unsigned> R = Ranges[r]; | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 431 | std::fill(&CaretLine[R.first], | 
|  | 432 | &CaretLine[std::min((size_t)R.second, CaretLine.size())], | 
|  | 433 | '~'); | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 434 | } | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 435 |  | 
|  | 436 | // Add any fix-its. | 
|  | 437 | // FIXME: Find the beginning of the line properly for multibyte characters. | 
|  | 438 | std::string FixItInsertionLine; | 
|  | 439 | buildFixItLine(CaretLine, FixItInsertionLine, FixIts, | 
|  | 440 | makeArrayRef(Loc.getPointer() - ColumnNo, | 
|  | 441 | LineContents.size())); | 
|  | 442 |  | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 443 | // Finally, plop on the caret. | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 444 | if (unsigned(ColumnNo) <= NumColumns) | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 445 | CaretLine[ColumnNo] = '^'; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 446 | else | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 447 | CaretLine[NumColumns] = '^'; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 448 |  | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 449 | // ... and remove trailing whitespace so the output doesn't wrap for it.  We | 
|  | 450 | // know that the line isn't completely empty because it has the caret in it at | 
|  | 451 | // least. | 
|  | 452 | CaretLine.erase(CaretLine.find_last_not_of(' ')+1); | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 453 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 454 | printSourceLine(OS, LineContents); | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 455 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 456 | { | 
|  | 457 | WithColor S(OS, raw_ostream::GREEN, true, false, !ShowColors); | 
| Benjamin Kramer | bb73d19 | 2012-04-18 19:04:15 +0000 | [diff] [blame] | 458 |  | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 459 | // Print out the caret line, matching tabs in the source line. | 
|  | 460 | for (unsigned i = 0, e = CaretLine.size(), OutCol = 0; i != e; ++i) { | 
|  | 461 | if (i >= LineContents.size() || LineContents[i] != '\t') { | 
|  | 462 | S << CaretLine[i]; | 
|  | 463 | ++OutCol; | 
|  | 464 | continue; | 
|  | 465 | } | 
|  | 466 |  | 
|  | 467 | // Okay, we have a tab.  Insert the appropriate number of characters. | 
|  | 468 | do { | 
|  | 469 | S << CaretLine[i]; | 
|  | 470 | ++OutCol; | 
|  | 471 | } while ((OutCol % TabStop) != 0); | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 472 | } | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 473 | S << '\n'; | 
| Chris Lattner | a3a0681 | 2011-10-16 04:47:35 +0000 | [diff] [blame] | 474 | } | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 475 |  | 
|  | 476 | // Print out the replacement line, matching tabs in the source line. | 
|  | 477 | if (FixItInsertionLine.empty()) | 
|  | 478 | return; | 
| Fangrui Song | f78650a | 2018-07-30 19:41:25 +0000 | [diff] [blame] | 479 |  | 
| Dmitri Gribenko | 78fe2ba | 2013-09-27 21:24:36 +0000 | [diff] [blame] | 480 | for (size_t i = 0, e = FixItInsertionLine.size(), OutCol = 0; i < e; ++i) { | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 481 | if (i >= LineContents.size() || LineContents[i] != '\t') { | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 482 | OS << FixItInsertionLine[i]; | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 483 | ++OutCol; | 
|  | 484 | continue; | 
|  | 485 | } | 
|  | 486 |  | 
|  | 487 | // Okay, we have a tab.  Insert the appropriate number of characters. | 
|  | 488 | do { | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 489 | OS << FixItInsertionLine[i]; | 
| Jordan Rose | efd8f80 | 2013-01-10 18:50:15 +0000 | [diff] [blame] | 490 | // FIXME: This is trying not to break up replacements, but then to re-sync | 
|  | 491 | // with the tabs between replacements. This will fail, though, if two | 
|  | 492 | // fix-it replacements are exactly adjacent, or if a fix-it contains a | 
|  | 493 | // space. Really we should be precomputing column widths, which we'll | 
|  | 494 | // need anyway for multibyte chars. | 
|  | 495 | if (FixItInsertionLine[i] != ' ') | 
|  | 496 | ++i; | 
|  | 497 | ++OutCol; | 
|  | 498 | } while (((OutCol % TabStop) != 0) && i != e); | 
|  | 499 | } | 
| Joel E. Denny | 3e66509 | 2018-10-24 21:46:42 +0000 | [diff] [blame] | 500 | OS << '\n'; | 
| Chris Lattner | cc64cc9 | 2009-07-02 22:24:20 +0000 | [diff] [blame] | 501 | } |