summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-09-02 06:30:30 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-09-02 06:30:30 +0000
commitd3e83677b4b2488a5d07645e0798132bc3a8a599 (patch)
tree0fcb429eba729859f506da2eceee66870da3e5f6 /clang
parentdd7a654b1a50e99042c399862eba1e07452156b7 (diff)
downloadbcm5719-llvm-d3e83677b4b2488a5d07645e0798132bc3a8a599.tar.gz
bcm5719-llvm-d3e83677b4b2488a5d07645e0798132bc3a8a599.zip
Hoist the emission of parseable fixits into a helper method, simplifying
and reducing indentation through the clever use of early exits. ;] llvm-svn: 139001
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Frontend/TextDiagnosticPrinter.cpp76
1 files changed, 38 insertions, 38 deletions
diff --git a/clang/lib/Frontend/TextDiagnosticPrinter.cpp b/clang/lib/Frontend/TextDiagnosticPrinter.cpp
index 6b4513210f8..781cab6b532 100644
--- a/clang/lib/Frontend/TextDiagnosticPrinter.cpp
+++ b/clang/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";
}
}
};
OpenPOWER on IntegriCloud