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

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 20 16:49:54 PDT 2023


================
@@ -2270,7 +2270,15 @@ ContinuationIndenter::createBreakableToken(const FormatToken &Current,
     if (State.Stack.back().IsInsideObjCArrayLiteral)
       return nullptr;
 
+    // The "DPI" (or "DPI-C") in SystemVerilog direct programming interface
+    // imports cannot be split, e.g.
+    // `import "DPI" function foo();`
+    // FIXME: We should see if this is an import statement instead of hardcoding
+    // "DPI"/"DPI-C".
     StringRef Text = Current.TokenText;
+    if (Style.isVerilog() && (Text == "\"DPI\"" || Text == "\"DPI-C\""))
----------------
alexfh wrote:

I'd address the FIXME right away. Something like this:
```
      if (Style.isVerilog()) {
        const FormatToken *Prev = Current.getPreviousNonComment();
        if (Prev && Prev == State.Line->getFirstNonComment() &&
            Prev->TokenText == "import") {
          return nullptr;
        }
      }
```

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


More information about the cfe-commits mailing list