sstwcw created this revision. Herald added subscribers: cfe-commits, ctetreau. Herald added projects: All, clang, clang-format. Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay. sstwcw requested review of this revision.
Previously `isVerilogIdentifier` was mistaking the apostrophe used in struct literals as an identifier. It is fixed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147329 Files: clang/lib/Format/Format.cpp clang/lib/Format/FormatToken.h clang/unittests/Format/FormatTestVerilog.cpp Index: clang/unittests/Format/FormatTestVerilog.cpp =================================================================== --- clang/unittests/Format/FormatTestVerilog.cpp +++ clang/unittests/Format/FormatTestVerilog.cpp @@ -902,6 +902,25 @@ verifyFormat("{<<byte{j}} = x;"); } +TEST_F(FormatTestVerilog, StructLiteral) { + verifyFormat("c = '{0, 0.0};"); + verifyFormat("c = '{'{1, 1.0}, '{2, 2.0}};"); + verifyFormat("c = '{a: 0, b: 0.0};"); + verifyFormat("c = '{a: 0, b: 0.0, default: 0};"); + verifyFormat("c = ab'{a: 0, b: 0.0};"); + verifyFormat("c = ab'{cd: cd'{1, 1.0}, ef: ef'{2, 2.0}};"); + verifyFormat("c = ab'{cd'{1, 1.0}, ef'{2, 2.0}};"); + verifyFormat("d = {int: 1, shortreal: 1.0};"); + verifyFormat("d = ab'{int: 1, shortreal: 1.0};"); + verifyFormat("c = '{default: 0};"); + auto Style = getDefaultStyle(); + Style.SpacesInContainerLiterals = true; + verifyFormat("c = '{a : 0, b : 0.0};", Style); + verifyFormat("c = '{a : 0, b : 0.0, default : 0};", Style); + verifyFormat("c = ab'{a : 0, b : 0.0};", Style); + verifyFormat("c = ab'{cd : cd'{1, 1.0}, ef : ef'{2, 2.0}};", Style); +} + TEST_F(FormatTestVerilog, StructuredProcedure) { // Blocks should be indented correctly. verifyFormat("initial begin\n" Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -1722,8 +1722,9 @@ case tok::kw_while: return false; case tok::identifier: - return VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == - VerilogExtraKeywords.end(); + return isWordLike(Tok) && + VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == + VerilogExtraKeywords.end(); default: // getIdentifierInfo returns non-null for both identifiers and keywords. return Tok.Tok.getIdentifierInfo(); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1483,6 +1483,7 @@ break; case FormatStyle::LK_Verilog: LLVMStyle.IndentCaseLabels = true; + LLVMStyle.SpacesInContainerLiterals = false; break; default: break;
Index: clang/unittests/Format/FormatTestVerilog.cpp =================================================================== --- clang/unittests/Format/FormatTestVerilog.cpp +++ clang/unittests/Format/FormatTestVerilog.cpp @@ -902,6 +902,25 @@ verifyFormat("{<<byte{j}} = x;"); } +TEST_F(FormatTestVerilog, StructLiteral) { + verifyFormat("c = '{0, 0.0};"); + verifyFormat("c = '{'{1, 1.0}, '{2, 2.0}};"); + verifyFormat("c = '{a: 0, b: 0.0};"); + verifyFormat("c = '{a: 0, b: 0.0, default: 0};"); + verifyFormat("c = ab'{a: 0, b: 0.0};"); + verifyFormat("c = ab'{cd: cd'{1, 1.0}, ef: ef'{2, 2.0}};"); + verifyFormat("c = ab'{cd'{1, 1.0}, ef'{2, 2.0}};"); + verifyFormat("d = {int: 1, shortreal: 1.0};"); + verifyFormat("d = ab'{int: 1, shortreal: 1.0};"); + verifyFormat("c = '{default: 0};"); + auto Style = getDefaultStyle(); + Style.SpacesInContainerLiterals = true; + verifyFormat("c = '{a : 0, b : 0.0};", Style); + verifyFormat("c = '{a : 0, b : 0.0, default : 0};", Style); + verifyFormat("c = ab'{a : 0, b : 0.0};", Style); + verifyFormat("c = ab'{cd : cd'{1, 1.0}, ef : ef'{2, 2.0}};", Style); +} + TEST_F(FormatTestVerilog, StructuredProcedure) { // Blocks should be indented correctly. verifyFormat("initial begin\n" Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -1722,8 +1722,9 @@ case tok::kw_while: return false; case tok::identifier: - return VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == - VerilogExtraKeywords.end(); + return isWordLike(Tok) && + VerilogExtraKeywords.find(Tok.Tok.getIdentifierInfo()) == + VerilogExtraKeywords.end(); default: // getIdentifierInfo returns non-null for both identifiers and keywords. return Tok.Tok.getIdentifierInfo(); Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/lib/Format/Format.cpp @@ -1483,6 +1483,7 @@ break; case FormatStyle::LK_Verilog: LLVMStyle.IndentCaseLabels = true; + LLVMStyle.SpacesInContainerLiterals = false; break; default: break;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits