diff options
author | Manuel Klimek <klimek@google.com> | 2013-01-16 14:55:28 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2013-01-16 14:55:28 +0000 |
commit | ca547dbbb1e10c801158f2eecaf3d49e1071b0e3 (patch) | |
tree | 55b8bf41c4f5dbe1da3e27bb6892b240e3edad43 /lib/Format/Format.cpp | |
parent | 8fa37999164844a926448ef4656bbf7c42070235 (diff) |
Add debugging support for split penalties.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172616 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r-- | lib/Format/Format.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 4b5c2b8f66..ee9b463e90 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -16,15 +16,21 @@ /// //===----------------------------------------------------------------------===// -#include "clang/Format/Format.h" +#define DEBUG_TYPE "format-formatter" + #include "UnwrappedLineParser.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/OperatorPrecedence.h" #include "clang/Basic/SourceManager.h" +#include "clang/Format/Format.h" #include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Lex/Lexer.h" +#include "llvm/Support/Debug.h" #include <string> +// Uncomment to get debug output from tests: +// #define DEBUG_WITH_TYPE(T, X) do { X; } while(0) + namespace clang { namespace format { @@ -246,6 +252,10 @@ public: State.LineContainsContinuedForLoopSection = false; State.StartOfLineLevel = 1; + DEBUG({ + DebugTokenState(*State.NextToken); + }); + // The first token has already been indented and thus consumed. moveStateToNextToken(State); @@ -262,6 +272,18 @@ public: } else { unsigned NoBreak = calcPenalty(State, false, UINT_MAX); unsigned Break = calcPenalty(State, true, NoBreak); + DEBUG({ + if (Break < NoBreak) + llvm::errs() << "\n"; + else + llvm::errs() << " "; + llvm::errs() << "<"; + DebugPenalty(Break, Break < NoBreak); + llvm::errs() << "/"; + DebugPenalty(NoBreak, !(Break < NoBreak)); + llvm::errs() << "> "; + DebugTokenState(*State.NextToken); + }); addTokenToState(Break < NoBreak, false, State); if (State.NextToken != NULL && State.NextToken->Parent->Type == TT_CtorInitializerColon) { @@ -271,10 +293,28 @@ public: } } } + DEBUG(llvm::errs() << "\n"); return State.Column; } private: + void DebugTokenState(const AnnotatedToken &AnnotatedTok) { + const Token &Tok = AnnotatedTok.FormatTok.Tok; + llvm::errs() + << StringRef(SourceMgr.getCharacterData(Tok.getLocation()), + Tok.getLength()); + llvm::errs(); + } + + void DebugPenalty(unsigned Penalty, bool Winner) { + llvm::errs().changeColor(Winner ? raw_ostream::GREEN : raw_ostream::RED); + if (Penalty == UINT_MAX) + llvm::errs() << "MAX"; + else + llvm::errs() << Penalty; + llvm::errs().resetColor(); + } + struct ParenState { ParenState(unsigned Indent, unsigned LastSpace) : Indent(Indent), LastSpace(LastSpace), FirstLessLess(0), |