llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-format

Author: sstwcw

<details>
<summary>Changes</summary>

This patch adds the space on the left of the `:=` operator.  Previously there 
was only one on the right.  It is the style used in the spec.

old

```SystemVerilog
x dist {[100 : 102]:= 1, 200:= 2, 300:= 5};
```

new

```SystemVerilog
x dist {[100 : 102] := 1, 200 := 2, 300 := 5};
```

---
Full diff: https://github.com/llvm/llvm-project/pull/224794.diff


2 Files Affected:

- (modified) clang/lib/Format/TokenAnnotator.cpp (+5) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+10) 


``````````diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 105c98e704c3b..b3bc5842a4011 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5584,6 +5584,11 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
     // Add space in attribute like `(* ASYNC_REG = "TRUE" *)`.
     if (Left.endsSequence(tok::star, tok::l_paren) && 
Right.is(tok::identifier))
       return true;
+    // Add space in the dist list like `x dist {100 := 1};`.
+    if (Right.is(tok::colon) &&
+        (Right.TokenText == ":=" || Right.TokenText == ":/")) {
+      return true;
+    }
     // Add space before drive strength like in `wire (strong1, pull0)`.
     if (Right.is(tok::l_paren) && Right.is(TT_VerilogStrength))
       return true;
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index 9baa3210dbd82..2c63cf5dd09c4 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -1109,6 +1109,16 @@ TEST_F(FormatTestVerilog, Operators) {
   verifyFormat("req dist {1};");                           // dist
   verifyFormat("a inside {b, c};");                        // inside
   verifyFormat("bus.randomize() with { atype == low; };"); // with
+
+  verifyFormat("x dist {100 := 1, 200 := 2, 300 := 5};");
+  verifyFormat("x dist {[100 : 102] := 1, 200 := 2, 300 := 5};");
+  verifyFormat("x dist {[100 : 102] :/ 1, 200 :/ 2, 300 :/ 5};");
+  auto Style = getDefaultStyle();
+  Style.Cpp11BracedListStyle = FormatStyle::BLS_Block;
+  verifyFormat("x dist { 100 := 1, 200 := 2, 300 := 5 };", Style);
+  verifyFormat("x dist { [100 : 102] := 1, 200 := 2, 300 := 5 };", Style);
+  verifyFormat("x dist { [100 : 102] :/ 1, 200 :/ 2, 300 :/ 5 };", Style);
+  verifyFormat("a inside { b, c };", Style);
 }
 
 TEST_F(FormatTestVerilog, Preprocessor) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/224794
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to