================ @@ -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:
> `isOneOf` won't work here, since the token has the type of `identifier` > rather than a keyword: Have you tried it? It does work because not only is `import` a `tok::identifier`, it's also a `Keywords.kw_import`. > We should leave `Current.getPreviousNonComment()` to handle comments in the > middle of the statement (something like `import /*"DPI"*/ "DPI-C" ...` comes > to mind). I was aware of that, but we usually don't call `getPreviousNonComment()` unless a comment before a token makes sense in practice. Otherwise, we would have to write ugly and inefficient code to handle things like the following: ``` /* outer l_square */ [ /* inner l_square */ [ /* attribute */ unlikely /* inner r_square */ ] /* outer r_square */ ] // comment ``` > I'd suggest to address known cases with targeted exemptions to avoid > surprises in random places. I think this is also relevant to (at least) C++ import statements, e.g.: ``` `import "clang/include/clang/Format/Format.h";` ``` I still prefer that we make a general fix here but will leave it to @sstwcw. https://github.com/llvm/llvm-project/pull/66951 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits