[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310831: clang-format: Fix left pointer alignment after 
delctype/typeof (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D35847?vs=110032=110938#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35847

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1406,11 +1406,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2214,14 +2216,23 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() ||
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+  Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -5448,6 +5448,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5494,9 +5498,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1406,11 +1406,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2214,14 +2216,23 @@
 Left.Previous->is(tok::kw_case));
   if 

[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-07 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann marked 2 inline comments as done.
euhlmann added a comment.

I resolved the formatting issues. I apologize for not paying closer attention 
to formatting earlier.

I don't have commit access, so if this change looks good now, could someone 
with access please commit?


https://reviews.llvm.org/D35847



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


[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-07 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann updated this revision to Diff 110032.
euhlmann added a comment.

Ran clang-format over changes and corrected formatting


https://reviews.llvm.org/D35847

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1397,11 +1397,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+  PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2205,15 +2207,25 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
- Left.Previous->is(tok::r_paren)) ||
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+  Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() ||
+(Left.is(tok::kw_const) && Left.Previous &&
+ Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ 

[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-05 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Looks good! Please reformat the newly added code blocks with `clang-format` 
before submitting.




Comment at: lib/Format/TokenAnnotator.cpp:1402
+  FormatToken *TokenBeforeMatchingParen =
+PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&

Please reformat this block with `clang-format`: `PrevToken` gets indented by 
two more columns to the right.



Comment at: lib/Format/TokenAnnotator.cpp:2212
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;

Pleasereformat this block with `clang-format`: when I run it, it produces:
```
  if (Right.is(TT_PointerOrReference)) {
if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
  if (!Left.MatchingParen)
return true;
  FormatToken *TokenBeforeMatchingParen =
  Left.MatchingParen->getPreviousNonComment();
  if (!TokenBeforeMatchingParen ||
  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
return true;
}
return (Left.Tok.isLiteral() ||
(Left.is(tok::kw_const) && Left.Previous &&
 Left.Previous->is(tok::r_paren)) ||
(!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
 (Style.PointerAlignment != FormatStyle::PAS_Left ||
  (Line.IsMultiVariableDeclStmt &&
   (Left.NestingLevel == 0 ||
(Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
  }
```


https://reviews.llvm.org/D35847



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


[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-04 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann updated this revision to Diff 109805.
euhlmann added a comment.

Fix bad formatting


https://reviews.llvm.org/D35847

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1397,11 +1397,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2205,15 +2207,24 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
  Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1397,11 +1397,13 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
  

[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-04 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann updated this revision to Diff 109785.
euhlmann added a comment.

Pulled out `getPreviousNonComment()` into local variable to avoid calling twice.


https://reviews.llvm.org/D35847

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1397,11 +1397,15 @@
 if (NextToken->isOneOf(tok::comma, tok::semi))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
-  return TT_PointerOrReference;
+if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen) {
+  FormatToken *TokenBeforeMatchingParen =
+PrevToken->MatchingParen->getPreviousNonComment();
+  if (TokenBeforeMatchingParen &&
+  TokenBeforeMatchingParen->isOneOf(
+tok::kw_typeof,
+tok::kw_decltype))
+return TT_PointerOrReference;
+}
 
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
@@ -2205,15 +2209,24 @@
 Left.Previous->is(tok::kw_case));
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
-  if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
-   (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
+  if (Right.is(TT_PointerOrReference)) {
+if (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) {
+  if (!Left.MatchingParen)
+return true;
+  FormatToken *TokenBeforeMatchingParen =
+Left.MatchingParen->getPreviousNonComment();
+  if (!TokenBeforeMatchingParen ||
+  !TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+return true;
+}
+return (Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
  Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
  (Style.PointerAlignment != FormatStyle::PAS_Left ||
   (Line.IsMultiVariableDeclStmt &&
(Left.NestingLevel == 0 ||
 (Left.NestingLevel == 1 && Line.First->is(tok::kw_for)));
+  }
   if (Right.is(TT_FunctionTypeLParen) && Left.isNot(tok::l_paren) &&
   (!Left.is(TT_PointerOrReference) ||
(Style.PointerAlignment != FormatStyle::PAS_Right &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ 

[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-04 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1402
+PrevToken->MatchingParen->getPreviousNonComment() &&
+PrevToken->MatchingParen->getPreviousNonComment()->isOneOf(
+  tok::kw_typeof,

It would be cool if you extract the calls to getPreviousNonComment to a 
variable, saving the double iteration.


https://reviews.llvm.org/D35847



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


[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-03 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann updated this revision to Diff 109613.
euhlmann added a comment.

This uses `FormatToken::getPreviousNonComment` and adds a test. This also fixes 
a bug in token annotation that was breaking the test (by also using 
`getPreviousNonComment` instead of `Previous`)


https://reviews.llvm.org/D35847

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1398,9 +1398,10 @@
   return TT_PointerOrReference;
 
 if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
+PrevToken->MatchingParen->getPreviousNonComment() &&
+PrevToken->MatchingParen->getPreviousNonComment()->isOneOf(
+  tok::kw_typeof,
+  tok::kw_decltype))
   return TT_PointerOrReference;
 
 if (PrevToken->Tok.isLiteral() ||
@@ -2206,7 +2207,12 @@
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
   if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
+return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl &&
+!(Left.MatchingParen &&
+  Left.MatchingParen->getPreviousNonComment() &&
+  Left.MatchingParen->getPreviousNonComment()->isOneOf(
+tok::kw_typeof,
+tok::kw_decltype))) ||
(Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
  Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5422,6 +5422,10 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
+  verifyFormat("typedef typeof /*comment*/ (int(int, int))* MyFuncPtr;", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5468,9 +5472,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1398,9 +1398,10 @@
   return TT_PointerOrReference;
 
 if (PrevToken->is(tok::r_paren) && PrevToken->MatchingParen &&
-PrevToken->MatchingParen->Previous &&
-PrevToken->MatchingParen->Previous->isOneOf(tok::kw_typeof,
-tok::kw_decltype))
+PrevToken->MatchingParen->getPreviousNonComment() &&
+PrevToken->MatchingParen->getPreviousNonComment()->isOneOf(
+  tok::kw_typeof,
+  tok::kw_decltype))
   return TT_PointerOrReference;
 
 if (PrevToken->Tok.isLiteral() ||
@@ -2206,7 +2207,12 @@
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
   if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
+return (Left.is(tok::r_paren) && 

[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-08-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2206
+return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl &&
+!(Left.MatchingParen && Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->isOneOf(tok::kw_typeof,

Please use `FormatToken::getPreviousNonComment` here and add a test like 
`typedef typeof/*comment*/(int(int, int))* MyFuncPtr;`


https://reviews.llvm.org/D35847



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


[PATCH] D35847: clang-format: Fix left pointer alignment after delctype/typeof

2017-07-25 Thread Erik Uhlmann via Phabricator via cfe-commits
euhlmann created this revision.
euhlmann added a project: clang.

Change 272124* introduced a regression in spaceRequiredBetween for left aligned 
pointers to decltype and typeof expressions. This fix adds logic to fix this. 
The test added is based on a related test in determineStarAmpUsage. Also add 
test cases for the regression.

- http://llvm.org/viewvc/llvm-project?view=revision=272124

LLVM bug tracker: https://bugs.llvm.org/show_bug.cgi?id=30407


https://reviews.llvm.org/D35847

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5351,6 +5351,9 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5397,9 +5400,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2202,7 +2202,10 @@
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
   if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
+return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl &&
+!(Left.MatchingParen && Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->isOneOf(tok::kw_typeof,
+tok::kw_decltype))) ||
(Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
  Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5351,6 +5351,9 @@
   verifyFormat("for (;; *a = b) {\n}", Left);
   verifyFormat("return *this += 1;", Left);
   verifyFormat("throw *x;", Left);
+  verifyFormat("delete *x;", Left);
+  verifyFormat("typedef typeof(int(int, int))* MyFuncPtr;", Left);
+  verifyFormat("[](const decltype(*a)* ptr) {}", Left);
 
   verifyIndependentOfContext("a = *(x + y);");
   verifyIndependentOfContext("a = &(x + y);");
@@ -5397,9 +5400,6 @@
   verifyGoogleFormat("T** t = new T*;");
   verifyGoogleFormat("T** t = new T*();");
 
-  FormatStyle PointerLeft = getLLVMStyle();
-  PointerLeft.PointerAlignment = FormatStyle::PAS_Left;
-  verifyFormat("delete *x;", PointerLeft);
   verifyFormat("STATIC_ASSERT((a & b) == 0);");
   verifyFormat("STATIC_ASSERT(0 == (a & b));");
   verifyFormat("template  "
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2202,7 +2202,10 @@
   if (Left.is(tok::l_square) && Right.is(tok::amp))
 return false;
   if (Right.is(TT_PointerOrReference))
-return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl) ||
+return (Left.is(tok::r_paren) && Line.MightBeFunctionDecl &&
+!(Left.MatchingParen && Left.MatchingParen->Previous &&
+  Left.MatchingParen->Previous->isOneOf(tok::kw_typeof,
+tok::kw_decltype))) ||
(Left.Tok.isLiteral() || (Left.is(tok::kw_const) && Left.Previous &&
  Left.Previous->is(tok::r_paren)) ||
 (!Left.isOneOf(TT_PointerOrReference, tok::l_paren) &&
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits