diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -1709,8 +1709,8 @@ // enum definition can start a structural element. if (!parseEnum()) break; - // This only applies for C++. - if (!Style.isCpp()) { + // This only applies to C++ and Verilog. + if (!Style.isCpp() && !Style.isVerilog()) { addUnwrappedLine(); return; } @@ -3541,7 +3541,15 @@ FormatTok->isOneOf(tok::colon, tok::coloncolon, tok::less, tok::greater, tok::comma, tok::question, tok::l_square, tok::r_square)) { - nextToken(); + if (Style.isVerilog()) { + FormatTok->setFinalizedType(TT_VerilogDimensionedTypeName); + nextToken(); + // In Verilog the base type can have dimensions. + while (FormatTok->is(tok::l_square)) + parseSquare(); + } else { + nextToken(); + } // We can have macros or attributes in between 'enum' and the enum name. if (FormatTok->is(tok::l_paren)) parseParens(); diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -338,6 +338,20 @@ "x = x;"); } +TEST_F(FormatTestVerilog, Enum) { + verifyFormat("enum { x } x;"); + verifyFormat("typedef enum { x } x;"); + verifyFormat("enum { red, yellow, green } x;"); + verifyFormat("typedef enum { red, yellow, green } x;"); + verifyFormat("enum integer { x } x;"); + verifyFormat("typedef enum { x = 0 } x;"); + verifyFormat("typedef enum { red = 0, yellow = 1, green = 2 } x;"); + verifyFormat("typedef enum integer { x } x;"); + verifyFormat("typedef enum bit [0 : 1] { x } x;"); + verifyFormat("typedef enum { add = 10, sub[5], jmp[6 : 8] } E1;"); + verifyFormat("typedef enum { add = 10, sub[5] = 0, jmp[6 : 8] = 1 } E1;"); +} + TEST_F(FormatTestVerilog, Headers) { // Test headers with multiple ports. verifyFormat("module mh1\n"