[cfe-commits] r169272 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Alexander Kornienko
alexfh at google.com
Tue Dec 4 06:46:20 PST 2012
Author: alexfh
Date: Tue Dec 4 08:46:19 2012
New Revision: 169272
URL: http://llvm.org/viewvc/llvm-project?rev=169272&view=rev
Log:
Enum formatting implementation
Reviewers: djasper, klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D161
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=169272&r1=169271&r2=169272&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Dec 4 08:46:19 2012
@@ -99,19 +99,38 @@
}
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 @@
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::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());
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=169272&r1=169271&r2=169272&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 4 08:46:19 2012
@@ -244,6 +244,21 @@
"while (something());");
}
+TEST_F(FormatTest, Enum) {
+ verifyFormat("enum {\n"
+ " Zero,\n"
+ " One = 1,\n"
+ " Two = One + 1,\n"
+ " Three = (One + Two),\n"
+ " Four = (Zero && (One ^ Two)) | (One << Two),\n"
+ " Five = (One, Two, Three, Four, 5)\n"
+ "};");
+ verifyFormat("enum Enum {\n"
+ "};");
+ verifyFormat("enum {\n"
+ "};");
+}
+
TEST_F(FormatTest, BreaksDesireably) {
verifyFormat("if (aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
" aaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa) ||\n"
More information about the cfe-commits
mailing list