diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-09-02 06:30:30 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-09-02 06:30:30 +0000 |
commit | cca61589cada607478fbf05cdc70a7983c5e58d1 (patch) | |
tree | 92ddd6386b27bbb226599fa8c7b73f97fef5a5c5 /lib/Frontend/TextDiagnosticPrinter.cpp | |
parent | 46331ef4301d8e295776649bcccd8c4bb4de81da (diff) |
Hoist the emission of parseable fixits into a helper method, simplifying
and reducing indentation through the clever use of early exits. ;]
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139001 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/TextDiagnosticPrinter.cpp')
-rw-r--r-- | lib/Frontend/TextDiagnosticPrinter.cpp | 76 |
1 files changed, 38 insertions, 38 deletions
diff --git a/lib/Frontend/TextDiagnosticPrinter.cpp b/lib/Frontend/TextDiagnosticPrinter.cpp index 6b4513210f..781cab6b53 100644 --- a/lib/Frontend/TextDiagnosticPrinter.cpp +++ b/lib/Frontend/TextDiagnosticPrinter.cpp @@ -677,50 +677,50 @@ public: OS.resetColor(); } - if (DiagOpts.ShowParseableFixits) { - - // We follow FixItRewriter's example in not (yet) handling - // fix-its in macros. - bool BadApples = false; - for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) { - if (Hint->RemoveRange.isInvalid() || - Hint->RemoveRange.getBegin().isMacroID() || - Hint->RemoveRange.getEnd().isMacroID()) { - BadApples = true; - break; - } - } + // Print out any parseable fixit information requested by the options. + EmitParseableFixits(Hints, NumHints); + } - if (!BadApples) { - for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) { +private: + void EmitParseableFixits(const FixItHint *Hints, unsigned NumHints) { + if (!DiagOpts.ShowParseableFixits) + return; - SourceLocation B = Hint->RemoveRange.getBegin(); - SourceLocation E = Hint->RemoveRange.getEnd(); + // We follow FixItRewriter's example in not (yet) handling + // fix-its in macros. + for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) { + if (Hint->RemoveRange.isInvalid() || + Hint->RemoveRange.getBegin().isMacroID() || + Hint->RemoveRange.getEnd().isMacroID()) + return; + } - std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B); - std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E); + for (const FixItHint *Hint = Hints; Hint != Hints + NumHints; ++Hint) { + SourceLocation B = Hint->RemoveRange.getBegin(); + SourceLocation E = Hint->RemoveRange.getEnd(); - // Adjust for token ranges. - if (Hint->RemoveRange.isTokenRange()) - EInfo.second += Lexer::MeasureTokenLength(E, SM, LangOpts); + std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B); + std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E); - // We specifically do not do word-wrapping or tab-expansion here, - // because this is supposed to be easy to parse. - PresumedLoc PLoc = SM.getPresumedLoc(B); - if (PLoc.isInvalid()) - break; + // Adjust for token ranges. + if (Hint->RemoveRange.isTokenRange()) + EInfo.second += Lexer::MeasureTokenLength(E, SM, LangOpts); - OS << "fix-it:\""; - OS.write_escaped(SM.getPresumedLoc(B).getFilename()); - OS << "\":{" << SM.getLineNumber(BInfo.first, BInfo.second) - << ':' << SM.getColumnNumber(BInfo.first, BInfo.second) - << '-' << SM.getLineNumber(EInfo.first, EInfo.second) - << ':' << SM.getColumnNumber(EInfo.first, EInfo.second) - << "}:\""; - OS.write_escaped(Hint->CodeToInsert); - OS << "\"\n"; - } - } + // We specifically do not do word-wrapping or tab-expansion here, + // because this is supposed to be easy to parse. + PresumedLoc PLoc = SM.getPresumedLoc(B); + if (PLoc.isInvalid()) + break; + + OS << "fix-it:\""; + OS.write_escaped(SM.getPresumedLoc(B).getFilename()); + OS << "\":{" << SM.getLineNumber(BInfo.first, BInfo.second) + << ':' << SM.getColumnNumber(BInfo.first, BInfo.second) + << '-' << SM.getLineNumber(EInfo.first, EInfo.second) + << ':' << SM.getColumnNumber(EInfo.first, EInfo.second) + << "}:\""; + OS.write_escaped(Hint->CodeToInsert); + OS << "\"\n"; } } }; |