[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclarationsOnePerLine

2019-09-26 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked an inline comment as done.
Manikishan added inline comments.



Comment at: lib/Format/FormatToken.h:524
+T = T->getPreviousNonComment();
+return (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+T->Next->Tok.is(tok::colon));

MyDeveloperDay wrote:
> Manikishan wrote:
> > MyDeveloperDay wrote:
> > > do you think you might need
> > > 
> > > (T && T->Tok.is(tok::comma)..
> > > 
> > I have found a method `FieldDecl::isBitField() ` which check whether a 
> > current field is a BitField, But `FieldDecl` is not used anywhere in 
> > `lib/Format/` . I think it may not be related to Formatting and so I have 
> > to modify my declaration of `isBitield()` in `FormatToken.h`. 
> > Can I get suggestions whether my understanding is correct?
> FieldDecl will be part of the AST tree, but clang-format doesn't use that (or 
> it would need compiler arguments etc..)
> 
> Take a look at TokenAnnotator.cpp... (and try running clang-format with the 
> -debug option), it may show you that the bitfield can be identified by the 
> TT_BitFieldColon type rather than by a colon directly.
> 
> 
> ```
>   } else if (CurrentToken && CurrentToken->is(tok::numeric_constant)) {
> Tok->Type = TT_BitFieldColon;
> 
> ```
> 
> 
Sure will have a look at it, and figure out how can I check for bitfields


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062



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


[PATCH] D64695: [clang-format] Modified SortIncludes and IncludeCategories to priority for sorting #includes within the Group Category.

2019-09-12 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

>>! In D64695#1667696 , 
>>@MyDeveloperDay wrote:

> Does this need landing? given that you have a number of patches in flight 
> perhaps it would be good to request commit access

Yes, it would be good if it is landed. And can I know the procedure for getting 
commit access


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Modified SortIncludes and IncludeCategories to priority for sorting #includes within the Group Category.

2019-08-22 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 216576.
Manikishan edited the summary of this revision.
Manikishan added a comment.

I have removed the introduction to the NetBSDStyle, as there are some styles 
that are needed to implemented before launching the NetBSD style.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -70,6 +70,78 @@
  {tooling::Range(25, 1)}));
 }
 
+
+TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  FmtStyle.IncludeStyle.IncludeCategories = {
+  {"^", 1, 0},
+  {"^", 1, 1},
+  {"^", 8, 10},
+  {"^\".*\\.h\"", 10, 12}};
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"  
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \"pathnames.h\"\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"));
+}
+TEST_F(SortIncludesTest, SortPriorityNotDefined) {
+  FmtStyle = getLLVMStyle();
+  EXPECT_EQ("#include \"FormatTestUtils.h\"\n"
+"#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"
+"#include \"gtest/gtest.h\"\n",
+sort("#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"FormatTestUtils.h\"\n"
+"#include \"gtest/gtest.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "#include \n"
Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,19 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName, bool CheckMainHeader) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  if(Ret == 0)
+Ret = Style.IncludeCategories[i].Priority;
+  break;
+}
+  if (CheckMainHeader && IsMainFile && Ret > 0 && isMainHeader(IncludeName))
+Ret = 0;
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1727,6 +1727,7 @@
   StringRef Text;
   unsigned Offset;
   int Category;
+  int Priority;
 };
 
 struct JavaImportDirective {
@@ -1790,6 +1791,7 @@
 ArrayRef Ranges, StringRef FileName,
 StringRef Code, tooling::Replacements ,
 unsigned *Cursor) {
+  tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
   unsigned IncludesBeginOffset = Includes.front().Offset;
   unsigned IncludesEndOffset =
   Includes.back().Offset + 

[PATCH] D64695: [clang-format] Modified SortIncludes and IncludeCategories to priority for sorting #includes within the Group Category.

2019-08-21 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1614386 , @MyDeveloperDay 
wrote:

> Assuming this works and the other unit tests don't show issues then this 
> LGTM. Please consider running this on your NetBSD code base before 
> committing, if possible please also run on clang code based to ensure 
> existing sorted headers aren't sorted unexpectedly.
>
> I do feel like there could be a documentation change missing really to 
> explain to people how this really works and what if anything they have to 
> change in their existing .clang-format files


I wIll update the documentation soon, within a day. And I will  also run it 
over both the clang, and netbsd code to make sure nothing goes wrong.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D65648: [clang-format] Add support to SpacesBeforeTrailingComments to add spaces before Block comments.

2019-08-06 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked an inline comment as done.
Manikishan added inline comments.



Comment at: unittests/Format/FormatTest.cpp:3663
+  FormatStyle Style = getGoogleStyle();
+  Style.SpacesBeforeTrailingComments = 0;
   EXPECT_EQ("#define MACRO() \\\n"

MyDeveloperDay wrote:
> this feels odd, suggesting those using google style will get reformatted 
> changes?
Yes, so in that case shall I add a new style variable like 
spacesBeforeTrailingBlockComments. Using which they can enable the style. This 
also supports new styles which need. spaces before Block Comments and styles 
which doesn't need spaces.


Repository:
  rC Clang

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

https://reviews.llvm.org/D65648



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


[PATCH] D65648: [clang-format] Add support to SpacesBeforeTrailingComments to add spaces before Block comments.

2019-08-02 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan created this revision.
Manikishan added reviewers: cfe-commits, mgorny, christos, MyDeveloperDay, 
rdwampler, lebedev.ri.
Manikishan added a project: clang.
Herald added a subscriber: krytarowski.

Patch: SpacesBeforeTrailingBlockComments

This patch is to support ```spacesBeforeTrailingComments``` to support spaces 
before  Trailing BlockComments. According to the Documentation, this was not 
implemented because block comments have different usage patterns and a various 
number of special cases. I am trying to cover as many cases as possible which 
can be useful.
This patch covers some cases such as Declarations, definitions, and Includes

This is also under the Project of Adding NetBSD-KNF support to clang-format.

Example for supported cases:

  Int a;\*foo *\
  int b;\*bar *\
  Int c;\*baz *\
  
  #include ads.h\*foo *\
  #include bar.h\*bar *\

These following tests fail for this patch:

1. FormatTests/FormatTestComments.UnderstandsBlockComments
2. FormatTests/FormatTestJS.AddsLastLinePenaltyIfEndingIsBroken
3. FormatTests/FormatTestJS.TemplateStrings

I have to discuss whether to add support to those cases because I think the 
tests need to be modified while implementing this style.

I would like to discuss more one this specific style to know which cases I 
could work on, as it was chosen not to support. 
It will be good if I can get more inputs on the cases I could cover.


Repository:
  rC Clang

https://reviews.llvm.org/D65648

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


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -2600,6 +2600,33 @@
"  // b");
 }
 
+TEST_F(FormatTestComments, SpacesBeforeTrailingBlockComments){
+  FormatStyle Style = getGoogleStyle();
+  Style.SpacesBeforeTrailingComments = 4;
+  EXPECT_EQ("int a;/*a*/\n"
+"int b;/*a*/\n"
+"int c;/*a*/\n"
+"int d;/*a*/\n"
+"int e;/*a*/\n"
+"int f;/*a*/\n"
+"int g;/*a*/\n"
+"int h;/*a*/",
+format("int a; /*a*/\n"
+   "int b; /*a*/\n"
+   "int c; /*a*/\n"
+   "int d; /*a*/\n"
+   "int e; /*a*/\n"
+   "int f; /*a*/\n"
+   "int g; /*a*/\n"
+   "int h; /*a*/", Style));
+  EXPECT_EQ("#define A   \\\n"
+"  int i;  /*a*/ \\\n"
+"  int jjj;/*b*/",
+format("#define A\\\n"
+   "  int i;   /*a*/ \\\n"
+   "  int jjj; /*b*/", Style));
+
+}
 TEST_F(FormatTestComments, AlignTrailingComments) {
   EXPECT_EQ("#define MACRO(V)   \\\n"
 "  V(Rt2) /* one more char */   \\\n"
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3659,6 +3659,8 @@
 }
 
 TEST_F(FormatTest, FormatNestedBlocksInMacros) {
+  FormatStyle Style = getGoogleStyle();
+  Style.SpacesBeforeTrailingComments = 0;
   EXPECT_EQ("#define MACRO() \\\n"
 "  Debug(aaa, /* force line break */ \\\n"
 "{   \\\n"
@@ -3667,7 +3669,7 @@
 "})",
 format("#define   MACRO()   Debug(aaa,  /* force line break */ 
\\\n"
"  {  int   i;  int  j;   })",
-   getGoogleStyle()));
+   Style));
 
   EXPECT_EQ("#define A   \\\n"
 "  [] {  \\\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2159,6 +2159,14 @@
   while (Current) {
 if (isFunctionDeclarationName(*Current, Line))
   Current->Type = TT_FunctionDeclarationName;
+if (Current->is(TT_BlockComment)){
+  std::cout << "TYPE"isOneOf(TT_TemplateCloser,tok::l_paren) && 
Current->isTrailingComment()){
+  Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
+}
+  }
+}
 if (Current->is(TT_LineComment)) {
   if (Current->Previous->BlockKind == BK_BracedInit &&
   Current->Previous->opensScope())


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -2600,6 +2600,33 @@
"  // b");
 }
 
+TEST_F(FormatTestComments, 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-08-02 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 212978.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -70,6 +70,79 @@
  {tooling::Range(25, 1)}));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n",
+  sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+  
+}
+
+TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"  
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \"pathnames.h\"\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"));
+  
+  FmtStyle = getLLVMStyle();
+  EXPECT_EQ("#include \"FormatTestUtils.h\"\n"
+"#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"
+"#include \"gtest/gtest.h\"\n",
+sort("#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"FormatTestUtils.h\"\n"
+"#include \"gtest/gtest.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "#include \n"
Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,19 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName, bool CheckMainHeader) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  if(Ret == 0)
+Ret = Style.IncludeCategories[i].Priority;
+  break;
+}
+  if (CheckMainHeader && IsMainFile && Ret > 0 && isMainHeader(IncludeName))
+Ret = 0;
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-08-02 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 212974.
Manikishan added a comment.

Added Tests for using and not using SortPriority Field, Now, even if the 
SortPriorityis not set it will be set to the value of Category by default


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Format/Format.h
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -70,6 +70,79 @@
  {tooling::Range(25, 1)}));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n",
+  sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+  
+}
+
+TEST_F(SortIncludesTest, SortedIncludesUsingSortPriorityAttribute) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"  
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \"pathnames.h\"\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"));
+  
+  FmtStyle = getLLVMStyle();
+  EXPECT_EQ("#include \"FormatTestUtils.h\"\n"
+"#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"
+"#include \"gtest/gtest.h\"\n",
+sort("#include \"clang/Format/Format.h\"\n"
+"#include \"llvm/ADT/None.h\"\n"
+"#include \"FormatTestUtils.h\"\n"
+"#include \"gtest/gtest.h\"\n"
+"#include \"llvm/Support/Debug.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, NoReplacementsForValidIncludes) {
   // Identical #includes have led to a failure with an unstable sort.
   std::string Code = "#include \n"
Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,19 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName, bool CheckMainHeader) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  if(Ret == 0)
+Ret = Style.IncludeCategories[i].Priority;
+  break;
+}
+  if (CheckMainHeader && IsMainFile && Ret > 0 && isMainHeader(IncludeName))
+Ret = 0;
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-08-01 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1606256 , @rdwampler wrote:

> In D64695#1605676 , @Manikishan 
> wrote:
>
> > In D64695#1590948 , @Manikishan 
> > wrote:
> >
> > > In D64695#1589818 , @lebedev.ri 
> > > wrote:
> > >
> > > > In D64695#1589740 , 
> > > > @Manikishan wrote:
> > > >
> > > > > In D64695#1589508 , 
> > > > > @lebedev.ri wrote:
> > > > >
> > > > > > Is there sufficient test coverage as to what happens if 
> > > > > > `SortPriority` is not set?
> > > > >
> > > > >
> > > > > If SortPriority is not set, the Includes will be grouped without 
> > > > > sorting,
> > > >
> > > >
> > > > Let me rephrase - for the exiting `.clang-format`s, that don't 
> > > > currently specify `SortPriority`,
> > > >  this introduction of `SortPriority` should not change the header 
> > > > handling.
> > > >  Is that the case, and if so is there sufficient test coverage for that?
> > >
> > >
> > > I got your idea now.
> > >  No, there is no test coverage for that case, and with the current patch 
> > > they have to add SortPriority.
> > >  To avoid this shall I set SortPriority as Priority as default if it is 
> > > not defined? I think that will fix the issue.
> >
> >
> > any reviews on it ?
>
>
> That's sounds like it will work. Can you add some additional test cases 
> around this in `SortIncludesTest.cpp`. Also, adding a test case specifically 
> for sorting the NetBSD headers would be good.


Sorry for the delay, I am facing issues with  "NoCrash_Bug34236" will update 
the patch once I am able to fix it.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-29 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1590948 , @Manikishan wrote:

> In D64695#1589818 , @lebedev.ri 
> wrote:
>
> > In D64695#1589740 , @Manikishan 
> > wrote:
> >
> > > In D64695#1589508 , @lebedev.ri 
> > > wrote:
> > >
> > > > Is there sufficient test coverage as to what happens if `SortPriority` 
> > > > is not set?
> > >
> > >
> > > If SortPriority is not set, the Includes will be grouped without sorting,
> >
> >
> > Let me rephrase - for the exiting `.clang-format`s, that don't currently 
> > specify `SortPriority`,
> >  this introduction of `SortPriority` should not change the header handling.
> >  Is that the case, and if so is there sufficient test coverage for that?
>
>
> I got your idea now.
>  No, there is no test coverage for that case, and with the current patch they 
> have to add SortPriority.
>  To avoid this shall I set SortPriority as Priority as default if it is not 
> defined? I think that will fix the issue.


any reviews on it ?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclarationsOnePerLine

2019-07-18 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked an inline comment as done.
Manikishan added inline comments.



Comment at: lib/Format/FormatToken.h:524
+T = T->getPreviousNonComment();
+return (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+T->Next->Tok.is(tok::colon));

MyDeveloperDay wrote:
> do you think you might need
> 
> (T && T->Tok.is(tok::comma)..
> 
I have found a method `FieldDecl::isBitField() ` which check whether a current 
field is a BitField, But `FieldDecl` is not used anywhere in `lib/Format/` . I 
think it may not be related to Formatting and so I have to modify my 
declaration of `isBitield()` in `FormatToken.h`. 
Can I get suggestions whether my understanding is correct?


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-18 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1589818 , @lebedev.ri wrote:

> In D64695#1589740 , @Manikishan 
> wrote:
>
> > In D64695#1589508 , @lebedev.ri 
> > wrote:
> >
> > > Is there sufficient test coverage as to what happens if `SortPriority` is 
> > > not set?
> >
> >
> > If SortPriority is not set, the Includes will be grouped without sorting,
>
>
> Let me rephrase - for the exiting `.clang-format`s, that don't currently 
> specify `SortPriority`,
>  this introduction of `SortPriority` should not change the header handling.
>  Is that the case, and if so is there sufficient test coverage for that?


I got your idea now.
No, there is no test coverage for that case, and with the current patch they 
have to add SortPriority.
To avoid this shall I set SortPriority as Priority as default if it is not 
defined? I think that will fix the issue.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-17 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 210358.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp

Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,15 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  break;
+}
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 1, 0},
+  {"^", 1, 1},
+  {"^", 9, 11},
+  {"^\".*\.h\"", 10, 12}};
+  NetBSDStyle.SortIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1080,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1774,8 +1809,9 @@
 static void sortCppIncludes(const FormatStyle ,
 const SmallVectorImpl ,
 ArrayRef Ranges, StringRef FileName,
-StringRef Code,
-tooling::Replacements , unsigned *Cursor) {
+StringRef Code, tooling::Replacements ,
+unsigned *Cursor) {
+  tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
   unsigned IncludesBeginOffset = Includes.front().Offset;
   unsigned IncludesEndOffset =
   Includes.back().Offset + Includes.back().Text.size();
@@ -1783,11 +1819,15 @@
   if (!affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
 return;
   SmallVector Indices;
-  for (unsigned i = 0, e = Includes.size(); i != e; ++i)
+  SmallVector IncludesPriority;
+  for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
+IncludesPriority.push_back(
+Categories.getSortIncludePriority(Includes[i].Filename));
 Indices.push_back(i);
+  }
   llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
-return std::tie(Includes[LHSI].Category, Includes[LHSI].Filename) <
-   std::tie(Includes[RHSI].Category, Includes[RHSI].Filename);
+return std::tie(IncludesPriority[LHSI], Includes[LHSI].Filename) <
+   std::tie(IncludesPriority[RHSI], Includes[RHSI].Filename);
   });
   // The index of the include on which the cursor will be put after
   // sorting/deduplicating.
Index: include/clang/Tooling/Inclusions/IncludeStyle.h
===
--- include/clang/Tooling/Inclusions/IncludeStyle.h
+++ include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -58,6 +58,8 @@
 std::string Regex;
 /// The priority to assign to this category.
 int Priority;
+/// The custom priority to sort before grouping.
+int 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-17 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1589508 , @lebedev.ri wrote:

> Is there sufficient test coverage as to what happens if `SortPriority` is not 
> set?


If SortPriority is not set, the Includes will be grouped without sorting,

For example:

  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include "pathnames.h"
  #include 
  #include 
  #include 
  #include 

will be grouped as

  #include "pathnames.h"
  
  #include 
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  
  #include 
  
  #include 
  
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 
  #include 

Can we add a test case for this and mention that users should set SortPriority, 
or handle this case some how?
One way can be when the values are not set their Priority value is set as 
SortPriority, but this is also a problem 
when users give SortPriority as "0". Any comments on this issue?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-17 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 210353.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp

Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,15 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  break;
+}
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 1, 0},
+  {"^", 1, 1},
+  {"^", 9, 11},
+  {"^\"\w.*\.h\"$", 10, 12}};
+  NetBSDStyle.SortIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1080,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1774,8 +1809,9 @@
 static void sortCppIncludes(const FormatStyle ,
 const SmallVectorImpl ,
 ArrayRef Ranges, StringRef FileName,
-StringRef Code,
-tooling::Replacements , unsigned *Cursor) {
+StringRef Code, tooling::Replacements ,
+unsigned *Cursor) {
+  tooling::IncludeCategoryManager Categories(Style.IncludeStyle, FileName);
   unsigned IncludesBeginOffset = Includes.front().Offset;
   unsigned IncludesEndOffset =
   Includes.back().Offset + Includes.back().Text.size();
@@ -1783,11 +1819,15 @@
   if (!affectsRange(Ranges, IncludesBeginOffset, IncludesEndOffset))
 return;
   SmallVector Indices;
-  for (unsigned i = 0, e = Includes.size(); i != e; ++i)
+  SmallVector IncludesPriority;
+  for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
+IncludesPriority.push_back(
+Categories.getSortIncludePriority(Includes[i].Filename));
 Indices.push_back(i);
+  }
   llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
-return std::tie(Includes[LHSI].Category, Includes[LHSI].Filename) <
-   std::tie(Includes[RHSI].Category, Includes[RHSI].Filename);
+return std::tie(IncludesPriority[LHSI], Includes[LHSI].Filename) <
+   std::tie(IncludesPriority[RHSI], Includes[RHSI].Filename);
   });
   // The index of the include on which the cursor will be put after
   // sorting/deduplicating.
Index: include/clang/Tooling/Inclusions/IncludeStyle.h
===
--- include/clang/Tooling/Inclusions/IncludeStyle.h
+++ include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -58,6 +58,8 @@
 std::string Regex;
 /// The priority to assign to this category.
 int Priority;
+/// The custom priority to sort before grouping.
+int 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-17 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1589497 , @rdwampler wrote:

> Thanks! Can you update the documentation too?


Thanks!
So, is this Implementation fine? But there is a thing, The values which we give 
two Priority does not really matter they need to be different to be in 
different groups. Is that ok? and should I Rename any options?.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-16 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In the following patch I have modified Include categories by adding a new field 
"sortInlcudes" which defines the priority of the sort. And priority field will 
now only be used for grouping.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-16 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 210218.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Tooling/Inclusions/HeaderIncludes.h
  include/clang/Tooling/Inclusions/IncludeStyle.h
  lib/Format/Format.cpp
  lib/Tooling/Inclusions/HeaderIncludes.cpp
  lib/Tooling/Inclusions/IncludeStyle.cpp

Index: lib/Tooling/Inclusions/IncludeStyle.cpp
===
--- lib/Tooling/Inclusions/IncludeStyle.cpp
+++ lib/Tooling/Inclusions/IncludeStyle.cpp
@@ -17,6 +17,7 @@
 IO , IncludeStyle::IncludeCategory ) {
   IO.mapOptional("Regex", Category.Regex);
   IO.mapOptional("Priority", Category.Priority);
+  IO.mapOptional("SortPriority", Category.SortPriority);
 }
 
 void ScalarEnumerationTraits::enumeration(
Index: lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -199,6 +199,18 @@
   return Ret;
 }
 
+int IncludeCategoryManager::getSortIncludePriority(StringRef IncludeName) const {
+  int Ret = INT_MAX;
+  for (unsigned i = 0, e = CategoryRegexs.size(); i != e; ++i)
+if (CategoryRegexs[i].match(IncludeName)) {
+  Ret = Style.IncludeCategories[i].SortPriority;
+  break;
+}
+else{
+  Ret = 0;
+}
+  return Ret;
+}
 bool IncludeCategoryManager::isMainHeader(StringRef IncludeName) const {
   if (!IncludeName.startswith("\""))
 return false;
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -452,7 +452,8 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
-IO.mapOptional("BitFieldDeclarationsOnePerLine", Style.BitFieldDeclarationsOnePerLine);
+IO.mapOptional("BitFieldDeclarationsOnePerLine",
+   Style.BitFieldDeclarationsOnePerLine);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
@@ -609,8 +610,8 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
-false, false, true,  true,  true};
+false, false, false, false, false, false,
+false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -688,8 +689,8 @@
   LLVMStyle.BreakBeforeTernaryOperators = true;
   LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
   LLVMStyle.BraceWrapping = {false, false, false, false, false, false,
- false, false, false, false, false,
- false, false, true,  true,  true};
+ false, false, false, false, false, false,
+ false, true,  true,  true};
   LLVMStyle.BreakAfterJavaFieldAnnotations = false;
   LLVMStyle.BreakConstructorInitializers = FormatStyle::BCIS_BeforeColon;
   LLVMStyle.BreakInheritanceList = FormatStyle::BILS_BeforeColon;
@@ -1023,6 +1024,39 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 1, 0},
+  {"^", 1, 1},
+  {"^", 9, 11},
+  {"^\"\w.*\.h\"$", 10, 12}};
+  NetBSDStyle.SortIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1081,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1774,8 +1810,9 @@
 static void sortCppIncludes(const FormatStyle ,
 const SmallVectorImpl ,
 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1586157 , @MyDeveloperDay 
wrote:

> I appreciate what you've done to make this patch less duplicated code..but 
> now you've almost got to the point where being able to control it all via 
> configuration.
>
> I'm with @rdwampler I think you should be able to extend the include 
> categories...and then this becomes a very powerful capability. There are many 
> people who use clang-format for a "non" standard style source trees, and they 
> might like to use such a capability themselves without having to inherit from 
> NetBSD type.
>
> I agree it will be complex, but that is a good justification for adding hard 
> coded a NetBSD style.


Thanks, I will try to implement it as suggested. 
This is my proposal algorithm:

1. Modify Include.Categories by adding one more field for grouping priority.
2. Add support for this third field in sortIncludes.

Am I missing anything?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209933.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -278,8 +278,15 @@
   }
 };
 
-template <>
-struct ScalarEnumerationTraits {
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO ,
+  FormatStyle::IncludeHeadersStyle ) {
+IO.enumCase(Value, "None", FormatStyle::SIS_None);
+IO.enumCase(Value, "NetBSD", FormatStyle::SIS_NetBSD);
+  }
+};
+
+template <> struct ScalarEnumerationTraits {
   static void enumeration(IO ,
   FormatStyle::SpaceBeforeParensOptions ) {
 IO.enumCase(Value, "Never", FormatStyle::SBPO_Never);
@@ -479,6 +486,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortIncludesStyle", Style.SortIncludesStyle);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +617,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -759,6 +767,7 @@
 
   LLVMStyle.DisableFormat = false;
   LLVMStyle.SortIncludes = true;
+  LLVMStyle.SortIncludesStyle = FormatStyle::SIS_None;
   LLVMStyle.SortUsingDeclarations = true;
   LLVMStyle.StatementMacros.push_back("Q_UNUSED");
   LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
@@ -919,6 +928,7 @@
 "javax",
 };
 ChromiumStyle.SortIncludes = true;
+ChromiumStyle.SortIncludesStyle = FormatStyle::SIS_None;
   } else if (Language == FormatStyle::LK_JavaScript) {
 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
 ChromiumStyle.AllowShortLoopsOnASingleLine = false;
@@ -1023,6 +1033,30 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclarationsOnePerLine

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked an inline comment as done.
Manikishan added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:2921
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+  return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)

MyDeveloperDay wrote:
> mgorny wrote:
> > Misindent.
> This code appears 3 times (does it need to appear 3 times?), do we need some 
> sort of 
> 
> ```
> bool isBitField(FormatToken)
> {
> ...
> }
> ```
> 
> Should a bit field check for the existence of a number after the colon? I 
> can't think of other C++ constructs that appear as
> 
> ```
> comma identifier colon
> ```
> 
> but given that clang-format is used for ObjC,ProtoBuf,Java,JavaScript,C# I'm 
> pretty sure something odd is going to happen with JavaScript named 
> parameters, to be honest I think this is going to cause the following to get 
> reformatted 
> 
> MyFunctionCall({ xPosition: 20**, yPosition: 50,** width: 100, height: 5, 
> drawingNow: true });
> 
> 
> ```
> MyFunctionCall({ xPosition: 20**, yPosition: 50,**
> width: 100, 
> height: 5, 
> drawingNow: true });
> ```
> 
> or something like that
Yes,  you are correct this patch is failing many Javascript Tests. Will 
refactor the implementation.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062



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


[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclarationsOnePerLine

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked 5 inline comments as done.
Manikishan added inline comments.



Comment at: unittests/Format/FormatTest.cpp:3671
+  );
+} 
 

MyDeveloperDay wrote:
> MyDeveloperDay wrote:
> > please add a test with comments (it will get logged)
> > 
> > 
> > ```
> > unsigned int baz : 11, /*motor control flags*/
> >  add: 2/* control code for turning the lights on */ 
> > ,
> >  foo: 3 /* (unused */
> > ```
> > 
> any thoughts on these comments?
Sorry, I totally have to keep this aside because of some reasons, will update 
within a day.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1585835 , @lebedev.ri wrote:

> In D64695#1585772 , @Manikishan 
> wrote:
>
> > In D64695#1585754 , @rdwampler 
> > wrote:
> >
> > > I am not quite sure why this change is required to sort the headers for 
> > > NetBSD, you can set the priorities via `IncludeStyle.IncludeCategories`. 
> > > Is that not sufficient?
> >
> >
> > It can be done by setting priorities in IncludeCategories, but here we have 
> > nearly 40+ cases and categories to hardcode due to complex 
> > interdependencies between their headers. So, I have added this style 
> > reducing the cases using regex. And if this is fully parameterised any OS 
> > related project can add their own header priorities.
>
>
> Note that `IncludeCategories` is already a regex - 
> https://clang.llvm.org/docs/ClangFormatStyleOptions.html


Sorry,  my mistake I was but I added Regex for priorities while sorting and If 
I am not wrong I think IncludeCategories are used while Regrouping after 
sorting the Includes. In addition to that in my case I have to sort the 
includes In a particular order then grouping them in different
For example:

  #include /*  first, */
  #include /*next, */
  #include /*   and then the rest, */
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 

As shown in the above example  should follow  then  but while 
regrouping they should be in the same group.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1585754 , @rdwampler wrote:

> I am not quite sure why this change is required to sort the headers for 
> NetBSD, you can set the priorities via `IncludeStyle.IncludeCategories`. Is 
> that not sufficient?


It can be done by setting priorities in IncludeCategories, but here we have 
nearly 40+ cases and categories to hardcode due to complex interdependencies 
between their headers. So, I have added this style decreasing the cases using 
regex.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209873.
Manikishan added a comment.

Is this change that was meant?


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -278,8 +278,15 @@
   }
 };
 
-template <>
-struct ScalarEnumerationTraits {
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO ,
+  FormatStyle::IncludeHeadersStyle ) {
+IO.enumCase(Value, "None", FormatStyle::SIS_None);
+IO.enumCase(Value, "NetBSD", FormatStyle::SIS_NetBSD);
+  }
+};
+
+template <> struct ScalarEnumerationTraits {
   static void enumeration(IO ,
   FormatStyle::SpaceBeforeParensOptions ) {
 IO.enumCase(Value, "Never", FormatStyle::SBPO_Never);
@@ -479,6 +486,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortIncludesStyle", Style.SortIncludesStyle);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +617,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -759,6 +767,7 @@
 
   LLVMStyle.DisableFormat = false;
   LLVMStyle.SortIncludes = true;
+  LLVMStyle.SortIncludesStyle = FormatStyle::SIS_None;
   LLVMStyle.SortUsingDeclarations = true;
   LLVMStyle.StatementMacros.push_back("Q_UNUSED");
   LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION");
@@ -919,6 +928,7 @@
 "javax",
 };
 ChromiumStyle.SortIncludes = true;
+ChromiumStyle.SortIncludesStyle = FormatStyle::SIS_None;
   } else if (Language == FormatStyle::LK_JavaScript) {
 ChromiumStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never;
 ChromiumStyle.AllowShortLoopsOnASingleLine = false;
@@ -1023,6 +1033,30 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209814.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1023,6 +1024,29 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*", 0}};
+  NetBSDStyle.SortNetBSDIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1071,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1763,7 +1789,163 @@
   }
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
+enum CppIncludeHeadersKind {
+  IHK_KERNELHEADERS,
+  IHK_NETWORKHEADERS,
+  IHK_FILESYSHEADERS,
+  IHK_MACHINESHEADERS,
+  IHK_ARCHHEADERS,
+  IHK_USERHEADERS,
+  IHK_INCLUDESWITHQUOTES,
+};
+
+CppIncludeHeadersKind getHeadersKind(std::string Filename) {
+  SmallVector Matches;
+  const char KernelHeaderPattern[] = R"(^<(sys.*|uvm|dev)/)";
+  const char NetworkHeaderPattern[] = R"(^<(net.*|protocols)/)";
+  const char FilesSystemHeaderPattern[] =
+  

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.



> I guess my comment was that you patche introduces a lot of code duplication, 
> could the small amount of code you added be say put into a lambda and past in 
> based on style?

Yes, I will add that and submit a patch soon.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added inline comments.



Comment at: unittests/Format/SortIncludesTest.cpp:709
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"  
+   "#include \n"  

MyDeveloperDay wrote:
> should you add a test which has groups defined already, I'm unclear as to how 
> your algorithm works across groups?
The include groups in NetBSD files are made depending on the use, for example 
Kernel headers, File systems headers, Network and protocol headers are grouped 
together. 
My algorithm is to detect the include type by regex and assign a priority to 
them to sort. And to regroup I used IncludeCategories.


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-15 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209776.
Manikishan marked an inline comment as done.

Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  include/clang/Format/Format.h
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,23 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1064,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -2083,6 +2083,10 @@
 /// http://www.gnu.org/prep/standards/standards.html
 FormatStyle getGNUStyle();
 
+/// Returns a format style complying with NetBSD Coding Standards:
+/// 
http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD=text/x-cvsweb-markup
+FormatStyle getNetBSDStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1023,6 +1023,23 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1064,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -2083,6 +2083,10 @@
 /// http://www.gnu.org/prep/standards/standards.html
 FormatStyle getGNUStyle();
 
+/// Returns a format style complying with NetBSD Coding Standards:
+/// http://cvsweb.netbsd.org/bsdweb.cgi/src/share/misc/style?rev=HEAD=text/x-cvsweb-markup
+FormatStyle getNetBSDStyle();
+
 /// Returns style indicating formatting should be not applied at all.
 FormatStyle getNoStyle();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-14 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan marked an inline comment as done.
Manikishan added a comment.

In D64695#1584706 , @MyDeveloperDay 
wrote:

> There also seems like alot of duplication between the existing sortCppIncludes
>
> I think the only difference here is really just
>
> 
>
>   SmallVector Indices;
> SmallVector Includes_p;
> for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
>   unsigned pl = getNetBSDIncludePriority(Includes[i].Filename);
>   Includes_p.push_back(pl);
>   Indices.push_back(i);
> }
>
>
> vs the original
>
>   SmallVector Indices;
>   for (unsigned i = 0, e = Includes.size(); i != e; ++i)
> Indices.push_back(i);
>   
>
> plus way the sorting is performed, are we sure we couldn't have just made the 
> original sorting more powerful based on style settings?


Does it mean that adding the priority to sort based on style? 
like this:

  if (Style== NetBSD)
 // set priority to netbsd's priority

I didn't want to mess up the original sorting and made up this patch, if we 
have parameterise this solution, I will go for it.




Comment at: lib/Format/Format.cpp:1878
+  SmallVector Indices;
+  SmallVector Includes_p;
+  for (unsigned i = 0, e = Includes.size(); i != e; ++i) {

MyDeveloperDay wrote:
> _p? I don't understand what it stands for?
> 
> IncludesPriority?
Yes , it means priority


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-14 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan added a comment.

In D64695#1584630 , @MyDeveloperDay 
wrote:

> Do you think there is anything about this algorithm that could be 
> parameterized so that other projects could utilize it?


I think we can take input from users the header files which should be grouped 
together and pass them to regex searches which then sets up priority. 
But I dob the feasibility of this approach. Will  come up with one.

> I guess its not completely clear how this differs from just using the 
> IncludeCategories?

This style works only via NetBSD includes order instead of alphabetical .


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695



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


[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-13 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 209685.
Manikishan added a comment.

This is the squashed commit of both Adding NetBSD Style and adding 
sortNetBSDIncludes


Repository:
  rC Clang

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

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1023,6 +1024,29 @@
   return Style;
 }
 
+FormatStyle getNetBSDStyle() {
+  FormatStyle NetBSDStyle = getLLVMStyle();
+  NetBSDStyle.AlignTrailingComments = true;
+  NetBSDStyle.AlwaysBreakAfterReturnType = FormatStyle::RTBS_AllDefinitions;
+  NetBSDStyle.AlignConsecutiveMacros = true;
+  NetBSDStyle.BreakBeforeBraces = FormatStyle::BS_Mozilla;
+  NetBSDStyle.ColumnLimit = 80;
+  NetBSDStyle.ContinuationIndentWidth = 4;
+  NetBSDStyle.Cpp11BracedListStyle = false;
+  NetBSDStyle.FixNamespaceComments = true;
+  NetBSDStyle.IndentCaseLabels = false;
+  NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*", 0}};
+  NetBSDStyle.SortNetBSDIncludes = true;
+  NetBSDStyle.TabWidth = 8;
+  NetBSDStyle.UseTab = FormatStyle::UT_Always;
+  return NetBSDStyle;
+}
+
 FormatStyle getNoStyle() {
   FormatStyle NoStyle = getLLVMStyle();
   NoStyle.DisableFormat = true;
@@ -1047,6 +1071,8 @@
 *Style = getGNUStyle();
   } else if (Name.equals_lower("microsoft")) {
 *Style = getMicrosoftStyle(Language);
+  } else if (Name.equals_lower("netbsd")) {
+*Style = getNetBSDStyle();
   } else if (Name.equals_lower("none")) {
 *Style = getNoStyle();
   } else {
@@ -1763,7 +1789,163 @@
   }
   return std::make_pair(CursorIndex, OffsetToEOL);
 }
+enum CppIncludeHeadersKind {
+  IHK_KERNELHEADERS,
+  IHK_NETWORKHEADERS,
+  IHK_FILESYSHEADERS,
+  IHK_MACHINESHEADERS,
+  IHK_ARCHHEADERS,
+  IHK_USERHEADERS,
+  IHK_INCLUDESWITHQUOTES,
+};
+
+CppIncludeHeadersKind getHeadersKind(std::string Filename) {
+  SmallVector Matches;
+  const char KernelHeaderPattern[] = R"(^<(sys.*|uvm|dev)/)";
+  const char 

[PATCH] D64695: [clang-format] Added new style rule: SortNetBSDIncludes

2019-07-13 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan created this revision.
Manikishan added reviewers: cfe-commits, mgorny, christos, MyDeveloperDay.
Herald added a subscriber: krytarowski.
Herald added a project: clang.
Manikishan added subscribers: mgorny, christos.

This new Style rule is made as a part of adding support for NetBSD KNF in 
clang-format. NetBSD have it's own priority of includes which should be 
followed while formatting NetBSD code. This style sorts the Cpp Includes 
according to the priorities of NetBSD, as mentioned in the Style Guide 

 The working of this Style rule shown below:

**Configuration:**
In addition to this commit I am also adding another diff which Introduces 
NetBSD Style in clang-format, The required configurations are already made in 
this patch and can be used by

  clang-format -style=NetBSD ...

(The NetBSD Style is not fully implemented but it supports SortNetBSDIncludes 
for now).

Here is an example how this Style sorts cpp includes according to NetBSD KNF.
**Before Formatting:  **

  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  #include
  #include 
  #include  
  #include 
  #include 
  #include 
  #include 
  #include "pathnames.h"
  #include 
  #include 
  #include 
  #include 

**After Formatting: **

  #include 
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  #include 
  #include 
  #include 
  #include 
  
  #include 
  
  #include "pathnames.h"




Repository:
  rC Clang

https://reviews.llvm.org/D64695

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  unittests/Format/SortIncludesTest.cpp

Index: unittests/Format/SortIncludesTest.cpp
===
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -665,6 +665,67 @@
  "#include \"a.h\""));
 }
 
+TEST_F(SortIncludesTest, ParamAndTypesCheck) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n"
+			"#include \n",
+			sort("#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"
+ "#include \n"));
+	
+}
+
+TEST_F(SortIncludesTest, SortedIncludesInSingleBlockReGroupWithNetBSDSpecifications) {
+  FmtStyle = getNetBSDStyle();
+  EXPECT_EQ("#include \n"  
+  "#include \n"  
+  "#include \n"  
+  "#include \n" 
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "#include \n"
+  "\n"
+  "#include \n"
+  "\n"
+  "#include \"pathnames.h\"\n",
+  sort("#include \n"		
+   "#include \n"		
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"	
+   "#include \n"
+   "#include \n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \"pathnames.h\"\n"		
+   "#include \n"
+   "#include \n"
+   "#include \n"
+   "#include \n"));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -479,6 +479,7 @@
 IO.mapOptional("RawStringFormats", Style.RawStringFormats);
 IO.mapOptional("ReflowComments", Style.ReflowComments);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
+IO.mapOptional("SortNetBSDIncludes", Style.SortNetBSDIncludes);
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
@@ -609,7 +610,7 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false,
+false, false, false, false, false, 
 false, false, true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
@@ -1035,6 +1036,12 @@
   NetBSDStyle.FixNamespaceComments = true;
   NetBSDStyle.IndentCaseLabels = false;
   NetBSDStyle.IndentWidth = 8;
+  NetBSDStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  NetBSDStyle.IncludeStyle.IncludeCategories = {
+  {"^", 2},
+  {"^\"\w.*\.h\"$", 1}, {".*", 0}};
+  

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclarationsOnePerLine

2019-06-12 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 204340.
Manikishan marked 4 inline comments as done and 2 inline comments as done.
Manikishan retitled this revision from "[clang-format] Added New Style Rule:  
OnePerLineBitFieldDecl" to "[clang-format] Added New Style Rule: 
BitFieldDeclarationsOnePerLine".

Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.BitFieldDeclarationsOnePerLine = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.BitFieldDeclarationsOnePerLine = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.BitFieldDeclarationsOnePerLine &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -516,6 +516,14 @@
 return T && T->is(tok::kw_auto);
   }
 
+  /// Returns whether the token is a Bit field, and checks whether
+  /// the Style is C / C++.
+  bool isBitField() const {
+const FormatToken *T = this;
+T = T->getPreviousNonComment();
+return (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+T->Next->Tok.is(tok::colon));
+  }
   /// Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclarationsOnePerLine", Style.BitFieldDeclarationsOnePerLine);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -329,6 +329,8 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Style.isCpp() && Current.isBitField() && Style.BitFieldDeclarationsOnePerLine)
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +543,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclarationsOnePerLine;
+

[PATCH] D63062: [clang-format] Added New Style Rule: OnePerLineBitFieldDecl

2019-06-11 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 204068.

Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.OnePerLineBitFieldDecl = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.OnePerLineBitFieldDecl = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.OnePerLineBitFieldDecl &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -516,6 +516,14 @@
 return T && T->is(tok::kw_auto);
   }
 
+  /// Returns whether the token is a Bit field, and checks whether
+  /// the Style is C / C++.
+  bool isBitField() const {
+const FormatToken *T = this;
+T = T->getPreviousNonComment();
+return (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+T->Next->Tok.is(tok::colon));
+  }
   /// Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("OnePerLineBitFieldDecl", Style.OnePerLineBitFieldDecl);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -329,6 +329,8 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Style.isCpp() && Current.isBitField() && Style.OnePerLineBitFieldDecl)
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +543,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool OnePerLineBitFieldDecl;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-11 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 204040.
Manikishan marked an inline comment as done.

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.OnePerLineBitFieldDecl = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.OnePerLineBitFieldDecl = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.OnePerLineBitFieldDecl &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -516,6 +516,16 @@
 return T && T->is(tok::kw_auto);
   }
 
+/// Returns whether the token is a Bit field, and checks whether
+/// the Style is C / C++.
+bool isBitField() const {
+  const FormatToken *T = this;
+  T = T->getPreviousNonComment();
+  if (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+  T->Next->Tok.is(tok::colon))
+return true;
+  return false;
+}
   /// Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("OnePerLineBitFieldDecl", Style.OnePerLineBitFieldDecl);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -329,6 +329,8 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Style.isCpp() && Current.isBitField() && Style.OnePerLineBitFieldDecl)
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +543,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool OnePerLineBitFieldDecl;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==
   

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-11 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 204022.
Manikishan marked 4 inline comments as done.
Manikishan added a comment.

Changed Style name to OnePerLineBitFieldDecl


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.OnePerLineBitFieldDecl = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.OnePerLineBitFieldDecl = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.OnePerLineBitFieldDecl &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -516,6 +516,16 @@
 return T && T->is(tok::kw_auto);
   }
 
+/// Returns whether the token is a Bit field, and checks whether
+/// the Style is C / C++.
+bool isBitField() const {
+  const FormatToken *T = this;
+  T = T->getPreviousNonComment();
+  if (T->Tok.is(tok::comma) && Tok.is(tok::identifier) &&
+  T->Next->Tok.is(tok::colon))
+return true;
+  return false;
+}
   /// Same as opensBlockOrBlockTypeList, but for the closing token.
   bool closesBlockOrBlockTypeList(const FormatStyle ) const {
 if (is(TT_TemplateString) && closesScope())
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -329,6 +329,8 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Style.isCpp() && Current.isBitField() && Style.OnePerLineBitFieldDecl)
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +543,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool OnePerLineBitFieldDecl;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-10 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 203860.
Manikishan marked 4 inline comments as done.
Manikishan added a comment.

Updated unittest


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.BitFieldDeclsOnSeparateLines = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.BitFieldDeclsOnSeparateLines = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,9 @@
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
   assert( == Current.Previous);
+  if (Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Current.is(tok::identifier) && Current.Next->is(tok::colon))
+return true;
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +332,9 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Current.is(tok::identifier) && Current.Next->is(tok::colon))
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +547,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
+   BitFieldDeclsOnSeparateLines == 

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-10 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 203841.
Manikishan added a comment.

Made some missing style modifications in the last revision


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.BitFieldDeclsOnSeparateLines = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.BitFieldDeclsOnSeparateLines = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,9 @@
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
   assert( == Current.Previous);
+  if (Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Current.is(tok::identifier) && Current.Next->is(tok::colon))
+return true;
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +332,9 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Current.is(tok::identifier) && Current.Next->is(tok::colon))
+return true; 
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +547,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
+   BitFieldDeclsOnSeparateLines == 

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-10 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 203838.
Manikishan marked 4 inline comments as done.
Manikishan added a comment.

Added unittests and made the changes suggested by @mgorny


Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -3656,6 +3656,19 @@
"#define A Just forcing a new line\n"
"ddd);");
 }
+TEST_F(FormatTest, AlignBitFieldDeclarationsOnConsecutiveLines){
+  FormatStyle Style = {};
+  Style.BitFieldDeclsOnSeparateLines = true;
+  verifyFormat(
+"unsigned int baz : 11,
+  aaa : 2,
+  foo : 3"
+  );
+  Style.BitFieldDeclsOnSeparateLines = false;
+  verifyFormat(
+"unsigned int baz : 11, aaa : 2, foo : 3"
+  );
+} 
 
 TEST_F(FormatTest, LineBreakingInBinaryExpressions) {
   verifyFormat(
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,10 @@
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
   assert( == Current.Previous);
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon))
+return true;
+  }
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +333,11 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if (Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)) {
+  if (Current.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +550,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==

[PATCH] D63062: [clang-format] Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-10 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan updated this revision to Diff 203833.
Manikishan added a subscriber: mgorny.

Repository:
  rC Clang

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

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp

Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,9 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if (Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines &&
+  Right.is(tok::identifier) && (Right.Next->is(tok::colon)))
+  return true;
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,10 @@
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
   assert( == Current.Previous);
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon))
+return true;
+  }
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +333,11 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +550,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&
KeepEmptyLinesAtTheStartOfBlocks ==
R.KeepEmptyLinesAtTheStartOfBlocks &&
+   BitFieldDeclsOnSeparateLines == R.BitFieldDeclsOnSeparateLines &&
MacroBlockBegin == R.MacroBlockBegin &&
MacroBlockEnd == R.MacroBlockEnd &&
MaxEmptyLinesToKeep == R.MaxEmptyLinesToKeep &&
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -191,6 +191,18 @@
   argument1, argument2);
 
 
+**BitFieldDeclsOnSeparateLines** (``bool``)
+  If ``true``, Align Bitfield Declarations on seperate lines.
+
+  This will align Bitfield declarations on consecutive lines. This
+  will result in formatting like:
+
+  .. code-block:: c++
+
+unsigned int  baz : 1,
+  fuz : 5,
+  zap : 2;
+
 
 **AlignConsecutiveAssignments** (``bool``)
   If 

[PATCH] D63062: Added New Style Rule: BitFieldDeclsOnSeparateLines

2019-06-09 Thread Manikishan Ghantasala via Phabricator via cfe-commits
Manikishan created this revision.
Manikishan added reviewers: aaron.ballman, rsmith.
Herald added a subscriber: krytarowski.
Herald added a project: clang.

This new Style rule is made as a part of adding support for NetBSD KNF in 
clang-format. This style Lines up BitField Declarations on consecutive lines 
with correct Indentation. The working of this Style rule shown below:

//Configuration
BitFieldDeclsOnSeparateLines: true

//Before Formatting:

unsigned int bas :3,  hh : 4, jjj : 8;

unsigned int baz:1,

  fuz:5, 
  zap:2;

//After Formatting:

unsigned int bas : 3,

  hh : 4,
  jjj : 8;

unsigned int baz : 1,

  fuz : 5,
  zap : 2;

This style is formatted even if the one-line declaration line is less than the 
column limit.

There is a minor Bug:
Comments after the bitfield in before the break line will not cause a proper 
indentation.

//Before Formatting:

unsigned int baz:1, /* foo*/

  fuz:5,  /*bar*/
  zap:2;

//After Formatting:
unsigned int  baz : 1, /* Bitfield; line up entries if desire*/

  fuz : 5, /*jgifjjggirrj*/
  zap : 2;


Repository:
  rC Clang

https://reviews.llvm.org/D63062

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp

Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2916,6 +2916,11 @@
 bool TokenAnnotator::mustBreakBefore(const AnnotatedLine ,
  const FormatToken ) {
   const FormatToken  = *Right.Previous;
+  if(Right.Previous->is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Right.is(tok::identifier)){
+  if(Right.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0)
 return true;
 
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -451,6 +451,7 @@
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+IO.mapOptional("BitFieldDeclsOnSeparateLines", Style.BitFieldDeclsOnSeparateLines);
 IO.mapOptional("MacroBlockBegin", Style.MacroBlockBegin);
 IO.mapOptional("MacroBlockEnd", Style.MacroBlockEnd);
 IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -278,6 +278,10 @@
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
   assert( == Current.Previous);
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon))
+return true;
+  }
   if (!Current.CanBreakBefore && !(State.Stack.back().BreakBeforeClosingBrace &&
Current.closesBlockOrBlockTypeList(Style)))
 return false;
@@ -329,6 +333,11 @@
 bool ContinuationIndenter::mustBreak(const LineState ) {
   const FormatToken  = *State.NextToken;
   const FormatToken  = *Current.Previous;
+  if(Previous.is(tok::comma) && Style.BitFieldDeclsOnSeparateLines && Current.is(tok::identifier)){
+  if(Current.Next->is(tok::colon)){
+return true;
+  }
+  }
   if (Current.MustBreakBefore || Current.is(TT_InlineASMColon))
 return true;
   if (State.Stack.back().BreakBeforeClosingBrace &&
@@ -541,7 +550,7 @@
  unsigned ExtraSpaces) {
   FormatToken  = *State.NextToken;
   const FormatToken  = *State.NextToken->Previous;
-  if (Current.is(tok::equal) &&
+  if (Current.isOneOf(tok::equal, tok::colon) &&
   (State.Line->First->is(tok::kw_for) || Current.NestingLevel == 0) &&
   State.Stack.back().VariablePos == 0) {
 State.Stack.back().VariablePos = State.Column;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -101,6 +101,16 @@
   /// \endcode
   bool AlignConsecutiveDeclarations;
 
+  /// If ``true``, Linesup Bitfield Declarations.
+  /// This will lineup Bitfield declarations on consecutive lines. This
+  /// will result in formatting like
+  /// \code
+  ///  unsigned int  baz : 1, /* Bitfield; line up entries if desire*/
+  ///fuz : 5,
+  ///zap : 2;
+  /// \endcode
+  bool BitFieldDeclsOnSeparateLines;
+
   /// Different styles for aligning escaped newlines.
   enum EscapedNewlineAlignmentStyle {
 /// Don't align escaped newlines.
@@ -1950,6 +1960,7 @@
JavaScriptWrapImports == R.JavaScriptWrapImports &&