Skip to content

Commit 9c1de62

Browse files
authored
[clang-format][NFC] Return early in isWordLike() for non-Verilog (#90363)
1 parent aafed34 commit 9c1de62

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

clang/lib/Format/FormatToken.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,10 +1623,10 @@ struct AdditionalKeywords {
16231623
IdentifierInfo *kw_then;
16241624

16251625
/// Returns \c true if \p Tok is a keyword or an identifier.
1626-
bool isWordLike(const FormatToken &Tok) const {
1626+
bool isWordLike(const FormatToken &Tok, bool IsVerilog = true) const {
16271627
// getIdentifierinfo returns non-null for keywords as well as identifiers.
16281628
return Tok.Tok.getIdentifierInfo() &&
1629-
!Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
1629+
(!IsVerilog || !isVerilogKeywordSymbol(Tok));
16301630
}
16311631

16321632
/// Returns \c true if \p Tok is a true JavaScript identifier, returns
@@ -1755,6 +1755,10 @@ struct AdditionalKeywords {
17551755
}
17561756
}
17571757

1758+
bool isVerilogKeywordSymbol(const FormatToken &Tok) const {
1759+
return Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
1760+
}
1761+
17581762
bool isVerilogWordOperator(const FormatToken &Tok) const {
17591763
return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
17601764
kw_with);

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,9 +4780,14 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
47804780
if (Left.Finalized)
47814781
return Right.hasWhitespaceBefore();
47824782

4783+
const bool IsVerilog = Style.isVerilog();
4784+
assert(!IsVerilog || !IsCpp);
4785+
47834786
// Never ever merge two words.
4784-
if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
4787+
if (Keywords.isWordLike(Right, IsVerilog) &&
4788+
Keywords.isWordLike(Left, IsVerilog)) {
47854789
return true;
4790+
}
47864791

47874792
// Leave a space between * and /* to avoid C4138 `comment end` found outside
47884793
// of comment.
@@ -5063,12 +5068,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
50635068
Right.is(TT_TemplateOpener)) {
50645069
return true;
50655070
}
5066-
} else if (Style.isVerilog()) {
5071+
} else if (IsVerilog) {
50675072
// An escaped identifier ends with whitespace.
5068-
if (Style.isVerilog() && Left.is(tok::identifier) &&
5069-
Left.TokenText[0] == '\\') {
5073+
if (Left.is(tok::identifier) && Left.TokenText[0] == '\\')
50705074
return true;
5071-
}
50725075
// Add space between things in a primitive's state table unless in a
50735076
// transition like `(0?)`.
50745077
if ((Left.is(TT_VerilogTableItem) &&

0 commit comments

Comments
 (0)