Clang-format: parse for and while loops
Summary: Adds support for formatting for and while loops.
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D174
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169387 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index c2cb5b8..99e5832 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -121,6 +121,10 @@
case tok::kw_if:
parseIfThenElse();
return;
+ case tok::kw_for:
+ case tok::kw_while:
+ parseForOrWhileLoop();
+ return;
case tok::kw_do:
parseDoWhile();
return;
@@ -219,6 +223,22 @@
}
}
+void UnwrappedLineParser::parseForOrWhileLoop() {
+ assert((FormatTok.Tok.is(tok::kw_for) || FormatTok.Tok.is(tok::kw_while)) &&
+ "'for' or 'while' expected");
+ nextToken();
+ parseParens();
+ if (FormatTok.Tok.is(tok::l_brace)) {
+ parseBlock();
+ addUnwrappedLine();
+ } else {
+ addUnwrappedLine();
+ ++Line.Level;
+ parseStatement();
+ --Line.Level;
+ }
+}
+
void UnwrappedLineParser::parseDoWhile() {
assert(FormatTok.Tok.is(tok::kw_do) && "'do' expected");
nextToken();