[clang] [clang-format][NFC] Return early in isWordLike() for non-Verilog (PR #90363)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Apr 27 15:23:23 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-format
Author: Owen Pan (owenca)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/90363.diff
2 Files Affected:
- (modified) clang/lib/Format/FormatToken.h (+6-2)
- (modified) clang/lib/Format/TokenAnnotator.cpp (+8-5)
``````````diff
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index f651e6228c206d..28b6488e54a422 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -1623,10 +1623,10 @@ struct AdditionalKeywords {
IdentifierInfo *kw_then;
/// Returns \c true if \p Tok is a keyword or an identifier.
- bool isWordLike(const FormatToken &Tok) const {
+ bool isWordLike(const FormatToken &Tok, bool IsVerilog = true) const {
// getIdentifierinfo returns non-null for keywords as well as identifiers.
return Tok.Tok.getIdentifierInfo() &&
- !Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
+ (!IsVerilog || !isVerilogKeywordSymbol(Tok));
}
/// Returns \c true if \p Tok is a true JavaScript identifier, returns
@@ -1755,6 +1755,10 @@ struct AdditionalKeywords {
}
}
+ bool isVerilogKeywordSymbol(const FormatToken &Tok) const {
+ return Tok.isOneOf(kw_verilogHash, kw_verilogHashHash, kw_apostrophe);
+ }
+
bool isVerilogWordOperator(const FormatToken &Tok) const {
return Tok.isOneOf(kw_before, kw_intersect, kw_dist, kw_iff, kw_inside,
kw_with);
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 63629fa743184e..d366ae2080bc25 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -4780,9 +4780,14 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if (Left.Finalized)
return Right.hasWhitespaceBefore();
+ const bool IsVerilog = Style.isVerilog();
+ assert(!IsVerilog || !IsCpp);
+
// Never ever merge two words.
- if (Keywords.isWordLike(Right) && Keywords.isWordLike(Left))
+ if (Keywords.isWordLike(Right, IsVerilog) &&
+ Keywords.isWordLike(Left, IsVerilog)) {
return true;
+ }
// Leave a space between * and /* to avoid C4138 `comment end` found outside
// of comment.
@@ -5063,12 +5068,10 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Right.is(TT_TemplateOpener)) {
return true;
}
- } else if (Style.isVerilog()) {
+ } else if (IsVerilog) {
// An escaped identifier ends with whitespace.
- if (Style.isVerilog() && Left.is(tok::identifier) &&
- Left.TokenText[0] == '\\') {
+ if (Left.is(tok::identifier) && Left.TokenText[0] == '\\')
return true;
- }
// Add space between things in a primitive's state table unless in a
// transition like `(0?)`.
if ((Left.is(TT_VerilogTableItem) &&
``````````
</details>
https://github.com/llvm/llvm-project/pull/90363
More information about the cfe-commits
mailing list