Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/Format/FormatTokenLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,8 @@ FormatToken *FormatTokenLexer::getNextToken() {
FormatTok->Tok.setKind(tok::identifier);
} else if (Style.isTableGen() && !Keywords.isTableGenKeyword(*FormatTok)) {
FormatTok->Tok.setKind(tok::identifier);
} else if (Style.isVerilog() && Keywords.isVerilogIdentifier(*FormatTok)) {
FormatTok->Tok.setKind(tok::identifier);
}
} else if (const bool Greater = FormatTok->is(tok::greatergreater);
Greater || FormatTok->is(tok::lessless)) {
Expand Down
5 changes: 5 additions & 0 deletions clang/unittests/Format/FormatTestVerilog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ TEST_F(FormatTestVerilog, Declaration) {
verifyFormat("wire (strong1, pull0) mynet, mynet1 = enable;");
verifyFormat("wire (strong1, pull0) mynet, //\n"
" mynet1 = enable;");

// The type or variable can be a C++ keyword.
verifyFormat("private mynet;");
verifyFormat("switch mynet;");
verifyFormat("wire try;");
}

TEST_F(FormatTestVerilog, Delay) {
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2909,6 +2909,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsVerilogOperators) {
EXPECT_EQ(Tokens[0]->TokenText, R"(\busa+index\
+)");
EXPECT_TOKEN(Tokens[1], tok::semi, TT_Unknown);

// A C++ keyword should be treated as an identifier.
Tokens = Annotate("volatile delete;");
ASSERT_EQ(Tokens.size(), 4u) << Tokens;
EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName);

// An escaped newline should not be treated as an escaped identifier.
Tokens = Annotate("\\\n");
ASSERT_EQ(Tokens.size(), 1u) << Tokens;
Expand Down
Loading