diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-09-07 05:36:50 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-09-07 05:36:50 +0000 |
commit | d2156fcd15c9ad3e0d538f0fe372d7a9e2be965a (patch) | |
tree | c42d246bcbd59a2843a425330af380bbbd987c4f | |
parent | 0580e7dccecadc8edee3ed47fe22283addf92e2b (diff) |
Hoist the tab expansion into a helper function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139226 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 100362f773..716ce06f77 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -545,27 +545,7 @@ public: else CaretLine.push_back('^'); - // Scan the source line, looking for tabs. If we find any, manually expand - // them to spaces and update the CaretLine to match. - for (unsigned i = 0; i != SourceLine.size(); ++i) { - if (SourceLine[i] != '\t') continue; - - // Replace this tab with at least one space. - SourceLine[i] = ' '; - - // Compute the number of spaces we need to insert. - unsigned TabStop = DiagOpts.TabStop; - assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop && - "Invalid -ftabstop value"); - unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1); - assert(NumSpaces < TabStop && "Invalid computation of space amt"); - - // Insert spaces into the SourceLine. - SourceLine.insert(i+1, NumSpaces, ' '); - - // Insert spaces or ~'s into CaretLine. - CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' '); - } + ExpandTabs(SourceLine, CaretLine); // If we are in -fdiagnostics-print-source-range-info mode, we are trying // to produce easily machine parsable output. Add a space before the @@ -689,6 +669,30 @@ private: return FixItInsertionLine; } + void ExpandTabs(std::string &SourceLine, std::string &CaretLine) { + // Scan the source line, looking for tabs. If we find any, manually expand + // them to spaces and update the CaretLine to match. + for (unsigned i = 0; i != SourceLine.size(); ++i) { + if (SourceLine[i] != '\t') continue; + + // Replace this tab with at least one space. + SourceLine[i] = ' '; + + // Compute the number of spaces we need to insert. + unsigned TabStop = DiagOpts.TabStop; + assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop && + "Invalid -ftabstop value"); + unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1); + assert(NumSpaces < TabStop && "Invalid computation of space amt"); + + // Insert spaces into the SourceLine. + SourceLine.insert(i+1, NumSpaces, ' '); + + // Insert spaces or ~'s into CaretLine. + CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' '); + } + } + void EmitParseableFixits(ArrayRef<FixItHint> Hints) { if (!DiagOpts.ShowParseableFixits) return; |