[PATCH] D128709: [clang-format] Handle Verilog attributes
sstwcw via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 17:40:33 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60e12068ffeb: [clang-format] Handle Verilog attributes (authored by sstwcw).
Changed prior to commit:
https://reviews.llvm.org/D128709?vs=443611&id=448491#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128709/new/
https://reviews.llvm.org/D128709
Files:
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestVerilog.cpp
Index: clang/unittests/Format/FormatTestVerilog.cpp
===================================================================
--- clang/unittests/Format/FormatTestVerilog.cpp
+++ clang/unittests/Format/FormatTestVerilog.cpp
@@ -295,6 +295,12 @@
TEST_F(FormatTestVerilog, If) {
verifyFormat("if (x)\n"
" x = x;");
+ verifyFormat("unique if (x)\n"
+ " x = x;");
+ verifyFormat("unique0 if (x)\n"
+ " x = x;");
+ verifyFormat("priority if (x)\n"
+ " x = x;");
verifyFormat("if (x)\n"
" x = x;\n"
"x = x;");
@@ -357,6 +363,14 @@
" x = {x};\n"
"else\n"
" {x} = {x};");
+
+ // With attributes.
+ verifyFormat("(* x *) if (x)\n"
+ " x = x;");
+ verifyFormat("(* x = \"x\" *) if (x)\n"
+ " x = x;");
+ verifyFormat("(* x, x = \"x\" *) if (x)\n"
+ " x = x;");
}
TEST_F(FormatTestVerilog, Operators) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -1471,6 +1471,23 @@
addUnwrappedLine();
return;
}
+
+ if (Style.isVerilog()) {
+ // Skip things that can exist before keywords like 'if' and 'case'.
+ while (true) {
+ if (FormatTok->isOneOf(Keywords.kw_priority, Keywords.kw_unique,
+ Keywords.kw_unique0)) {
+ nextToken();
+ } else if (FormatTok->is(tok::l_paren) &&
+ Tokens->peekNextToken()->is(tok::star)) {
+ parseParens();
+ } else {
+ break;
+ }
+ }
+ }
+
+ // Tokens that only make sense at the beginning of a line.
switch (FormatTok->Tok.getKind()) {
case tok::kw_asm:
nextToken();
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4067,6 +4067,9 @@
Keywords.isWordLike(Left))) {
return false;
}
+ // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
+ if (Left.endsSequence(tok::star, tok::l_paren) && Right.is(tok::identifier))
+ return true;
}
if (Left.is(TT_ImplicitStringLiteral))
return Right.hasWhitespaceBefore();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128709.448491.patch
Type: text/x-patch
Size: 2400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220729/8417e62b/attachment-0001.bin>
More information about the cfe-commits
mailing list