summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-05-29 15:10:11 +0000
committerManuel Klimek <klimek@google.com>2013-05-29 15:10:11 +0000
commit4c5c28bb3607f51be7a82aa6af647906af84ef1a (patch)
tree7c81e7352cde344001c56a72eb6808b55e6cc865 /clang/lib/Format/Format.cpp
parent6eb0cadda71385e8441fc8631dd90abca8a1ebea (diff)
downloadbcm5719-llvm-4c5c28bb3607f51be7a82aa6af647906af84ef1a.tar.gz
bcm5719-llvm-4c5c28bb3607f51be7a82aa6af647906af84ef1a.zip
Use a non-recursive implementation to reconstruct line breaks.
Now that the TokenAnnotator does not require stack space anymore, reconstructing the lines has become the limiting factor. This patch fixes that problem, allowing large files with multiple megabytes of single unwrapped lines to be formatted. llvm-svn: 182861
Diffstat (limited to 'clang/lib/Format/Format.cpp')
-rw-r--r--clang/lib/Format/Format.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6fc0da58c23..b6e8079b31a 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -949,22 +949,23 @@ private:
}
void reconstructPath(LineState &State, StateNode *Current) {
- // FIXME: This recursive implementation limits the possible number
- // of tokens per line if compiled into a binary with small stack space.
- // To become more independent of stack frame limitations we would need
- // to also change the TokenAnnotator.
- if (Current->Previous == NULL)
- return;
- reconstructPath(State, Current->Previous);
- DEBUG({
- if (Current->NewLine) {
- llvm::dbgs() << "Penalty for splitting before "
- << Current->Previous->State.NextToken->Tok.getName()
- << ": " << Current->Previous->State.NextToken->SplitPenalty
- << "\n";
- }
- });
- addTokenToState(Current->NewLine, false, State);
+ std::deque<StateNode *> Path;
+ // We do not need a break before the initial token.
+ while (Current->Previous) {
+ Path.push_front(Current);
+ Current = Current->Previous;
+ }
+ for (std::deque<StateNode *>::iterator I = Path.begin(), E = Path.end();
+ I != E; ++I) {
+ DEBUG({
+ if ((*I)->NewLine) {
+ llvm::dbgs() << "Penalty for splitting before "
+ << (*I)->Previous->State.NextToken->Tok.getName() << ": "
+ << (*I)->Previous->State.NextToken->SplitPenalty << "\n";
+ }
+ });
+ addTokenToState((*I)->NewLine, false, State);
+ }
}
/// \brief Add the following state to the analysis queue \c Queue.
OpenPOWER on IntegriCloud