[PATCH] D59332: [clang-format] AlignConsecutiveDeclarations fails with attributes

2019-04-09 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added inline comments.



Comment at: clang/lib/Format/WhitespaceManager.cpp:468
C.Tok->is(TT_FunctionDeclarationName) ||
+   C.Tok->startsSequence(
+   tok::l_paren, tok::l_paren, tok::identifier, 
tok::coloncolon,

Can you add a comment explaining the newly added startsSequences, or perhaps 
even pull out a function?


Repository:
  rC Clang

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

https://reviews.llvm.org/D59332



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


[PATCH] D59332: [clang-format] AlignConsecutiveDeclarations fails with attributes

2019-03-13 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: rolandschulz, reuk, djasper, klimek.
MyDeveloperDay added a project: clang-tools-extra.

Addresses http://llvm.org/PR40418

When using `AlignConsecutiveDeclarations: true`

variables with Attributes would not be aligned correctly

  void f(int  extremlylongparametername1,
 long extremlylongparametername2,
 int[[clang::nodiscard]] extremlylongparametername3,
 int __attribute__((clang::nodiscard)) 
extremlylongparametername4) {
int   a;
unsigned long b;
int[[clang::nodiscard]] c;
int __attribute__((clang::nodiscard)) d;
  }

following this change, both parameters and variables with attributes will be 
aligned (space permitting)

  void f(int  extremlylongparametername1,
 long extremlylongparametername2,
 int  [[clang::nodiscard]] 
extremlylongparametername3,
 int __attribute__((clang::nodiscard)) 
extremlylongparametername4) {
int  a;
unsigned longb;
int  [[clang::nodiscard]] c;
int __attribute__((clang::nodiscard)) d;
  }




https://reviews.llvm.org/D59332

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10135,6 +10135,47 @@
"  unsigned c;\n"
"}",
Alignment);
+
+  // See llvm.org/PR40418
+  verifyFormat(
+  "void f(int  extremlylongparametername1,\n"
+  "   long extremlylongparametername2,\n"
+  "   int  [[a::b]] extremlylongparametername3,\n"
+  "   int __attribute__((a::b)) extremlylongparametername4) "
+  "{}\n",
+  Alignment);
+
+  verifyFormat("void f(int  extremlylongparametername1,\n"
+   "   long extremlylongparametername2,\n"
+   "   int  [[deprecated]] "
+   "extremlylongparametername3,\n"
+   "   int __attribute__((deprecated)) "
+   "extremlylongparametername4) "
+   "{}\n",
+   Alignment);
+
+  verifyFormat("int  a;\n"
+   "unsigned longb;\n"
+   "int __attribute__((a::b)) d;\n"
+   "int  [[a::b]] c;\n"
+   "int __attribute__((a::b)) e;\n"
+   "int __attribute__((depreciated)) f;\n"
+   "int __attribute__((aligned(16))) g;\n",
+   Alignment);
+
+  verifyFormat("int  a;\n"
+   "unsigned longb;\n"
+   "int __attribute__((a::b)) d;\n"
+   "int  [[deprecated]] c;\n"
+   "int __attribute__((a::b)) e;\n",
+   Alignment);
+
+  verifyFormat("int  a;\n"
+   "unsigned longb;\n"
+   "int __attribute__((deprecated)) de;\n"
+   "int  [[deprecated]] c;\n"
+   "int __attribute__((a::b)) e;\n",
+   Alignment);
 }
 
 TEST_F(FormatTest, LinuxBraceBreaking) {
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -17,8 +17,8 @@
 namespace clang {
 namespace format {
 
-bool WhitespaceManager::Change::IsBeforeInFile::
-operator()(const Change , const Change ) const {
+bool WhitespaceManager::Change::IsBeforeInFile::operator()(
+const Change , const Change ) const {
   return SourceMgr.isBeforeInTranslationUnit(
   C1.OriginalWhitespaceRange.getBegin(),
   C2.OriginalWhitespaceRange.getBegin());
@@ -465,6 +465,19 @@
 // definitions.
 return C.Tok->is(TT_StartOfName) ||
C.Tok->is(TT_FunctionDeclarationName) ||
+   C.Tok->startsSequence(
+   tok::l_paren, tok::l_paren, tok::identifier, 
tok::coloncolon,
+   tok::identifier, tok::r_paren, tok::r_paren) ||
+   C.Tok->startsSequence(tok::l_square, tok::l_square,
+ tok::identifier, tok::coloncolon,
+ tok::identifier, tok::r_square,
+ tok::r_square) ||
+   C.Tok->startsSequence(tok::l_square, tok::l_square,
+ tok::identifier, tok::r_square,
+ tok::r_square) ||
+   C.Tok->startsSequence(tok::l_paren, tok::l_paren,
+ tok::identifier, tok::r_paren,
+