aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/UnwrappedLineParser.cpp
diff options
context:
space:
mode:
authorAlexander Kornienko <alexfh@google.com>2012-12-04 14:46:19 +0000
committerAlexander Kornienko <alexfh@google.com>2012-12-04 14:46:19 +0000
commita166e73d39d2f554d0f35f94c9804284d1ff804a (patch)
treefd6d15315ea36e25e5d99d626d8e8278e06f35c6 /lib/Format/UnwrappedLineParser.cpp
parent8cb9bf577e3cfe31f1f023ed3a978d726f136edc (diff)
Enum formatting implementation
Reviewers: djasper, klimek Reviewed By: klimek CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D161 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@169272 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/UnwrappedLineParser.cpp')
-rw-r--r--lib/Format/UnwrappedLineParser.cpp80
1 files changed, 53 insertions, 27 deletions
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index d9ff99d3cb..7c04ce09dd 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -99,19 +99,38 @@ void UnwrappedLineParser::parseComment() {
}
void UnwrappedLineParser::parseStatement() {
- if (FormatTok.Tok.is(tok::kw_public) || FormatTok.Tok.is(tok::kw_protected) ||
- FormatTok.Tok.is(tok::kw_private)) {
+ switch (FormatTok.Tok.getKind()) {
+ case tok::kw_public:
+ case tok::kw_protected:
+ case tok::kw_private:
parseAccessSpecifier();
return;
- }
- if (FormatTok.Tok.is(tok::kw_enum)) {
- parseEnum();
+ case tok::kw_if:
+ parseIfThenElse();
+ return;
+ case tok::kw_do:
+ parseDoWhile();
+ return;
+ case tok::kw_switch:
+ parseSwitch();
+ return;
+ case tok::kw_default:
+ nextToken();
+ parseLabel();
+ return;
+ case tok::kw_case:
+ parseCaseLabel();
return;
+ default:
+ break;
}
int TokenNumber = 0;
do {
++TokenNumber;
switch (FormatTok.Tok.getKind()) {
+ case tok::kw_enum:
+ parseEnum();
+ return;
case tok::semi:
nextToken();
addUnwrappedLine();
@@ -123,32 +142,16 @@ void UnwrappedLineParser::parseStatement() {
parseBlock();
addUnwrappedLine();
return;
- case tok::kw_if:
- parseIfThenElse();
- return;
- case tok::kw_do:
- parseDoWhile();
- return;
- case tok::kw_switch:
- parseSwitch();
- return;
- case tok::kw_default:
- nextToken();
- parseLabel();
- return;
- case tok::kw_case:
- parseCaseLabel();
- return;
- case tok::raw_identifier:
- nextToken();
- break;
- default:
+ case tok::identifier:
nextToken();
if (TokenNumber == 1 && FormatTok.Tok.is(tok::colon)) {
parseLabel();
return;
}
break;
+ default:
+ nextToken();
+ break;
}
} while (!eof());
}
@@ -265,12 +268,35 @@ void UnwrappedLineParser::parseAccessSpecifier() {
}
void UnwrappedLineParser::parseEnum() {
+ bool HasContents = false;
do {
- nextToken();
- if (FormatTok.Tok.is(tok::semi)) {
+ switch (FormatTok.Tok.getKind()) {
+ case tok::l_brace:
+ nextToken();
+ addUnwrappedLine();
+ ++Line.Level;
+ break;
+ case tok::l_paren:
+ parseParens();
+ break;
+ case tok::comma:
+ nextToken();
+ addUnwrappedLine();
+ break;
+ case tok::r_brace:
+ if (HasContents)
+ addUnwrappedLine();
+ --Line.Level;
+ nextToken();
+ break;
+ case tok::semi:
nextToken();
addUnwrappedLine();
return;
+ default:
+ HasContents = true;
+ nextToken();
+ break;
}
} while (!eof());
}