Skip to content

Commit

Permalink
Check if this is an import statement instead
Browse files Browse the repository at this point in the history
  • Loading branch information
aeubanks committed Sep 21, 2023
1 parent a956ea3 commit 23d1b3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions clang/lib/Format/ContinuationIndenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2270,14 +2270,17 @@ 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.
// The "DPI"/"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\""))
return nullptr;
if (Style.isVerilog()) {
const FormatToken *Prev = Current.getPreviousNonComment();
if (Prev && Prev == State.Line->getFirstNonComment() &&
Prev->TokenText == "import") {
return nullptr;
}
}

// We need this to address the case where there is an unbreakable tail only
// if certain other formatting decisions have been taken. The
Expand Down
2 changes: 1 addition & 1 deletion clang/unittests/Format/FormatTestVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1253,7 +1253,7 @@ TEST_F(FormatTestVerilog, StringLiteral) {
"xxxx"});)",
R"(x({"xxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx ", "xxxx"});)",
getStyleWithColumns(getDefaultStyle(), 23));
// "DPI"/"DPI-C" in imports cannot be split.
// import "DPI"/"DPI-C" cannot be split.
verifyFormat(R"(import
"DPI-C" function t foo
();)",
Expand Down

0 comments on commit 23d1b3c

Please sign in to comment.