r188794 - clang-format: Format enum struct/class like enum.
Daniel Jasper
djasper at google.com
Tue Aug 20 05:42:50 PDT 2013
Author: djasper
Date: Tue Aug 20 07:42:50 2013
New Revision: 188794
URL: http://llvm.org/viewvc/llvm-project?rev=188794&view=rev
Log:
clang-format: Format enum struct/class like enum.
Patch by Joe Hermaszewski. Thank you!
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=188794&r1=188793&r2=188794&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Aug 20 07:42:50 2013
@@ -918,6 +918,10 @@ void UnwrappedLineParser::parseAccessSpe
void UnwrappedLineParser::parseEnum() {
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) ||
FormatTok->Tok.is(tok::kw___attribute) ||
FormatTok->Tok.is(tok::kw___declspec)) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=188794&r1=188793&r2=188794&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Aug 20 07:42:50 2013
@@ -1518,6 +1518,40 @@ TEST_F(FormatTest, FormatsEnum) {
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) {
verifyFormat("struct Bitfields {\n"
" unsigned sClass : 8;\n"
More information about the cfe-commits
mailing list