[PATCH] D155783: [clang-format] Fix variable lacks of blank when previous operator is star

2023-07-20 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Please provide a diff with the full context (`-U99` will do the trick).

And another context is needed, just `x * y` will never be (meaningful) be 
formatted. At least a `;` is missing, and I'd argue if your example is just

  ... something ...
  x * y;
  ... something ...

Your patch is wrong. While it is of course possible to just multiply something 
and drop the result, that's nonsense.
If the overloaded `operator*` has side effects, that's also possible, but bad 
code.
But defining a pointer `y` pointing to type `x` and not initializing it 
directly is more often the case:

  struct x;
  x* y;
  ... something ...




Comment at: clang/unittests/Format/FormatTest.cpp:96
   EXPECT_EQ(0, ReplacementCount);
+  EXPECT_EQ("x*y",
+format("x * y"));

This is the wrong place.

You want a TokenAnnotatorTests, there is UnderstandStarAmp or something like 
that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155783/new/

https://reviews.llvm.org/D155783

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155783: [clang-format] Fix variable lacks of blank when previous operator is star

2023-07-20 Thread cqak via Phabricator via cfe-commits
cqak updated this revision to Diff 542316.
cqak added a comment.

add test case.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155783/new/

https://reviews.llvm.org/D155783

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -93,6 +93,9 @@
"\r\n"
"*/\r\n"));
   EXPECT_EQ(0, ReplacementCount);
+  EXPECT_EQ("x*y",
+format("x * y"));
+  EXPECT_EQ(2, ReplacementCount);
 }
 
 TEST_F(FormatTest, RemovesEmptyLines) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2556,7 +2556,7 @@
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
-if (PrevToken->Tok.isLiteral() ||
+if (PrevToken->Tok.isLiteral() || PrevToken->Tok.isAnyIdentifier() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
   return TT_BinaryOperator;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -93,6 +93,9 @@
"\r\n"
"*/\r\n"));
   EXPECT_EQ(0, ReplacementCount);
+  EXPECT_EQ("x*y",
+format("x * y"));
+  EXPECT_EQ(2, ReplacementCount);
 }
 
 TEST_F(FormatTest, RemovesEmptyLines) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2556,7 +2556,7 @@
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
-if (PrevToken->Tok.isLiteral() ||
+if (PrevToken->Tok.isLiteral() || PrevToken->Tok.isAnyIdentifier() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
   return TT_BinaryOperator;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D155783: [clang-format] Fix variable lacks of blank when previous operator is star

2023-07-20 Thread cqak via Phabricator via cfe-commits
cqak created this revision.
cqak added a reviewer: egorzhdan.
cqak added a project: clang-format.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
Herald added a comment.
cqak requested review of this revision.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


In binary operator of star, the second operand lacks of blank leading by the 
wrong type of token. For example:

  x*y;

converts to:

  x *y;

which should be:

  x * y;


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D155783

Files:
  clang/lib/Format/TokenAnnotator.cpp


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2556,7 +2556,7 @@
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
-if (PrevToken->Tok.isLiteral() ||
+if (PrevToken->Tok.isLiteral() || PrevToken->Tok.isAnyIdentifier() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
   return TT_BinaryOperator;


Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2556,7 +2556,7 @@
 if (PrevToken->endsSequence(tok::r_square, tok::l_square, tok::kw_delete))
   return TT_UnaryOperator;
 
-if (PrevToken->Tok.isLiteral() ||
+if (PrevToken->Tok.isLiteral() || PrevToken->Tok.isAnyIdentifier() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
   return TT_BinaryOperator;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits