[PATCH] Formatting 'enum class' and 'enum struct' as enumerations
Joe Hermaszewski
expipiplus1 at gmail.com
Sun Aug 18 01:59:06 PDT 2013
The change and tests in the same diff.
Also replacing . with -> to dereference FormatTok to keep up with changes since the original change.
Hi klimek, djasper,
http://llvm-reviews.chandlerc.com/D876
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D876?vs=2155&id=3553#toc
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTest.cpp
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -918,6 +918,10 @@
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)) {
Index: unittests/Format/FormatTest.cpp
===================================================================
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1518,6 +1518,40 @@
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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D876.3.patch
Type: text/x-patch
Size: 2272 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130818/18c04d1b/attachment.bin>
More information about the cfe-commits
mailing list