[PATCH] D121754: [clang-format] Refactor determineStarAmpUsage
sstwcw via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 15 16:26:04 PDT 2022
sstwcw created this revision.
sstwcw added a reviewer: clang-format.
sstwcw added a project: clang-format.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
There was some duplicate code in determineStarAmpUsage and
determinePlusMinusCaretUsage
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D121754
Files:
clang/lib/Format/TokenAnnotator.cpp
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2158,12 +2158,7 @@
if (PrevToken->is(tok::r_paren) && PrevToken->is(TT_TypeDeclarationParen))
return TT_PointerOrReference;
- if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
- tok::comma, tok::semi, tok::kw_return, tok::colon,
- tok::kw_co_return, tok::kw_co_await,
- tok::kw_co_yield, tok::equal, tok::kw_delete,
- tok::kw_sizeof, tok::kw_throw, TT_BinaryOperator,
- TT_ConditionalExpr, TT_UnaryOperator, TT_CastRParen))
+ if (determinePlusMinusCaretUsage(Tok) == TT_UnaryOperator)
return TT_UnaryOperator;
if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare))
@@ -2210,19 +2205,12 @@
if (!PrevToken)
return TT_UnaryOperator;
- if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator))
- // This must be a sequence of leading unary operators.
- return TT_UnaryOperator;
-
- // Use heuristics to recognize unary operators.
- if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square,
- tok::question, tok::colon, tok::kw_return,
- tok::kw_case, tok::at, tok::l_brace, tok::kw_throw,
- tok::kw_co_return, tok::kw_co_yield))
- return TT_UnaryOperator;
-
- // There can't be two consecutive binary operators.
- if (PrevToken->is(TT_BinaryOperator))
+ if (PrevToken->isOneOf(
+ TT_BinaryOperator, TT_CastRParen, TT_ConditionalExpr,
+ TT_UnaryOperator, tok::l_paren, tok::comma, tok::colon, tok::semi,
+ tok::equal, tok::question, tok::at, tok::l_square, tok::l_brace,
+ tok::kw_case, tok::kw_co_await, tok::kw_co_return, tok::kw_co_yield,
+ tok::kw_delete, tok::kw_return, tok::kw_sizeof, tok::kw_throw))
return TT_UnaryOperator;
// Fall back to marking the token as binary operator.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121754.415627.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220315/9ac3c494/attachment.bin>
More information about the cfe-commits
mailing list