clang-format: Format enum struct/class like enum.

Patch by Joe Hermaszewski. Thank you!

llvm-svn: 188794
This commit is contained in:
Daniel Jasper 2013-08-20 12:42:50 +00:00
parent b55acad91c
commit 2b41a82e61
2 changed files with 38 additions and 0 deletions

View File

@ -918,6 +918,10 @@ void UnwrappedLineParser::parseAccessSpecifier() {
void UnwrappedLineParser::parseEnum() { void UnwrappedLineParser::parseEnum() {
nextToken(); nextToken();
// Eat up enum class ...
if (FormatTok->Tok.is(tok::kw_class) ||
FormatTok->Tok.is(tok::kw_struct))
nextToken();
if (FormatTok->Tok.is(tok::identifier) || if (FormatTok->Tok.is(tok::identifier) ||
FormatTok->Tok.is(tok::kw___attribute) || FormatTok->Tok.is(tok::kw___attribute) ||
FormatTok->Tok.is(tok::kw___declspec)) { FormatTok->Tok.is(tok::kw___declspec)) {

View File

@ -1518,6 +1518,40 @@ TEST_F(FormatTest, FormatsEnum) {
verifyFormat("enum X f() {\n a();\n return 42;\n}"); verifyFormat("enum X f() {\n a();\n return 42;\n}");
} }
TEST_F(FormatTest, FormatsEnumStruct) {
verifyFormat("enum struct {\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 struct Enum {};");
verifyFormat("enum struct {};");
verifyFormat("enum struct X E {\n} d;");
verifyFormat("enum struct __attribute__((...)) E {\n} d;");
verifyFormat("enum struct __declspec__((...)) E {\n} d;");
verifyFormat("enum struct X f() {\n a();\n return 42;\n}");
}
TEST_F(FormatTest, FormatsEnumClass) {
verifyFormat("enum class {\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 class Enum {};");
verifyFormat("enum class {};");
verifyFormat("enum class X E {\n} d;");
verifyFormat("enum class __attribute__((...)) E {\n} d;");
verifyFormat("enum class __declspec__((...)) E {\n} d;");
verifyFormat("enum class X f() {\n a();\n return 42;\n}");
}
TEST_F(FormatTest, FormatsBitfields) { TEST_F(FormatTest, FormatsBitfields) {
verifyFormat("struct Bitfields {\n" verifyFormat("struct Bitfields {\n"
" unsigned sClass : 8;\n" " unsigned sClass : 8;\n"