summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2012-12-05 15:06:06 +0000
committerAlexander Kornienko <alexfh@google.com>2012-12-05 15:06:06 +0000
commit37d6c94e28653f37611d268acca79644c6ecde9d (patch)
tree4c4b6e6e8063f1117ec19d04a1f732ea4794e313 /clang/lib/Format/UnwrappedLineParser.cpp
parentaa1c920db85e7ac07d09b80eedc66bae7e358f26 (diff)
downloadbcm5719-llvm-37d6c94e28653f37611d268acca79644c6ecde9d.tar.gz
bcm5719-llvm-37d6c94e28653f37611d268acca79644c6ecde9d.zip
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 llvm-svn: 169387
Diffstat (limited to 'clang/lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index c2cb5b8027b..99e58321cd7 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -121,6 +121,10 @@ void UnwrappedLineParser::parseStatement() {
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::parseIfThenElse() {
}
}
+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();
OpenPOWER on IntegriCloud