From feb585e7d62ce92fcd8334abde4a84ee0301dcd3 Mon Sep 17 00:00:00 2001 From: sstwcw Date: Sat, 1 Apr 2023 17:10:06 +0000 Subject: [PATCH] [clang-format] Handle Verilog struct literals Previously `isVerilogIdentifier` was mistaking the apostrophe used in struct literals as an identifier. It is fixed. Reviewed By: HazardyKnusperkeks, owenpan Differential Revision: https://reviews.llvm.org/D147329 --- clang/lib/Format/Format.cpp | 1 + clang/lib/Format/FormatToken.h | 5 +++-- clang/unittests/Format/FormatTestVerilog.cpp | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 618cdb6..97c4867 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -1489,6 +1489,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { break; case FormatStyle::LK_Verilog: LLVMStyle.IndentCaseLabels = true; + LLVMStyle.SpacesInContainerLiterals = false; break; default: break; diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h index 5cd3422..59d4a87 100644 --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -1722,8 +1722,9 @@ struct AdditionalKeywords { 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(); diff --git a/clang/unittests/Format/FormatTestVerilog.cpp b/clang/unittests/Format/FormatTestVerilog.cpp index 3243d33..9d3ccf9 100644 --- a/clang/unittests/Format/FormatTestVerilog.cpp +++ b/clang/unittests/Format/FormatTestVerilog.cpp @@ -916,6 +916,25 @@ TEST_F(FormatTestVerilog, Streaming) { verifyFormat("{<