diff options
author | Alexander Kornienko <alexfh@google.com> | 2012-12-05 15:06:06 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2012-12-05 15:06:06 +0000 |
commit | 2e97cfc78743fcaa988e3c45f7af1002063f780c (patch) | |
tree | c76ab7eec9dc86d9b98c0a0ccca7f853248720f1 /lib/Format/UnwrappedLineParser.cpp | |
parent | 33182dd0f7d5b5e913b1957c2cb6dc04942efd46 (diff) |
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
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r-- | lib/Format/UnwrappedLineParser.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index c2cb5b8027..99e58321cd 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/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(); |