summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineFormatter.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-12-12 09:40:58 +0000
committerDaniel Jasper <djasper@google.com>2014-12-12 09:40:58 +0000
commit11a0ac66e10658f9eec87db0e846f6f5eaafc9cf (patch)
tree762746194ec8f9c799b260bea96a55d2f67a9930 /clang/lib/Format/UnwrappedLineFormatter.cpp
parent9e3a60769fe93241ee1bcdd711a1d38b014c15a6 (diff)
downloadbcm5719-llvm-11a0ac66e10658f9eec87db0e846f6f5eaafc9cf.tar.gz
bcm5719-llvm-11a0ac66e10658f9eec87db0e846f6f5eaafc9cf.zip
clang-format: Revamp nested block formatting.
This fixed llvm.org/PR21804 and hopefully a few other strange cases. Before: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } After: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } llvm-svn: 224112
Diffstat (limited to 'clang/lib/Format/UnwrappedLineFormatter.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineFormatter.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index fe9cf593999..56feaf6e54e 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -593,6 +593,15 @@ unsigned UnwrappedLineFormatter::analyzeSolutionSpace(LineState &InitialState,
return Penalty;
}
+static void printLineState(const LineState &State) {
+ llvm::dbgs() << "State: ";
+ for (const ParenState &P : State.Stack) {
+ llvm::dbgs() << P.Indent << "|" << P.LastSpace << "|" << P.NestedBlockIndent
+ << " ";
+ }
+ llvm::dbgs() << State.NextToken->TokenText << "\n";
+}
+
void UnwrappedLineFormatter::reconstructPath(LineState &State,
StateNode *Current) {
std::deque<StateNode *> Path;
@@ -608,6 +617,7 @@ void UnwrappedLineFormatter::reconstructPath(LineState &State,
Penalty += Indenter->addTokenToState(State, (*I)->NewLine, false);
DEBUG({
+ printLineState((*I)->Previous->State);
if ((*I)->NewLine) {
llvm::dbgs() << "Penalty for placing "
<< (*I)->Previous->State.NextToken->Tok.getName() << ": "
@@ -648,13 +658,8 @@ bool UnwrappedLineFormatter::formatChildren(LineState &State, bool NewLine,
return true;
if (NewLine) {
- int AdditionalIndent =
- State.FirstIndent - State.Line->Level * Style.IndentWidth;
- if (State.Stack.size() < 2 ||
- !State.Stack[State.Stack.size() - 2].NestedBlockInlined) {
- AdditionalIndent = State.Stack.back().Indent -
- Previous.Children[0]->Level * Style.IndentWidth;
- }
+ int AdditionalIndent = State.Stack.back().Indent -
+ Previous.Children[0]->Level * Style.IndentWidth;
Penalty += format(Previous.Children, DryRun, AdditionalIndent,
/*FixBadIndentation=*/true);
OpenPOWER on IntegriCloud