[clang] [clang-format] Don't split "DPI"/"DPI-C" in Verilog imports (PR #66951)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 21 01:57:12 PDT 2023


================
@@ -2270,7 +2270,18 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
     if (State.Stack.back().IsInsideObjCArrayLiteral)
       return nullptr;
 
+    // The "DPI"/"DPI-C" in SystemVerilog direct programming interface imports
+    // cannot be split, e.g.
+    // `import "DPI" function foo();`
     StringRef Text = Current.TokenText;
+    if (Style.isVerilog()) {
+      const FormatToken *Prev = Current.getPreviousNonComment();
+      if (Prev && Prev == State.Line->getFirstNonComment() &&
+          Prev->TokenText == "import") {
+        return nullptr;
+      }
+    }
+
----------------
owenca wrote:

```suggestion
    if (Current.Previous &&
        Current.Previous->isOneOf(tok::kw_export, Keywords.kw_import)) {
      return nullptr;
    }

    StringRef Text = Current.TokenText;
```
Shouldn't we handle `export` as well? Also, I don't think this is Verilog specific.

https://github.com/llvm/llvm-project/pull/66951


More information about the cfe-commits mailing list