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 | e79ddf8c6734307c67af33da01276b150ca51e36 (patch) | |
tree | 571eb963a7861ffeb459d9d59b2b104535dad095 /clang/lib | |
parent | 0f1006a95ac27b689915c1ed2452ab360182bac6 (diff) | |
download | bcm5719-llvm-e79ddf8c6734307c67af33da01276b150ca51e36.tar.gz bcm5719-llvm-e79ddf8c6734307c67af33da01276b150ca51e36.zip |
Hoist the tab expansion into a helper function.
llvm-svn: 139226
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/TextDiagnosticPrinter.cpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp index 100362f7739..716ce06f77e 100644 --- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/clang/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; |