[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa4a7c1259e8a: [clang-format] Add SpaceBeforeBrackets 
(authored by MyDeveloperDay).

Changed prior to commit:
  https://reviews.llvm.org/D6920?vs=229612&id=229686#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10643,6 +10643,41 @@
   verifyFormat("int foo = [ &bar, = ]() {};", Spaces);
 }
 
+TEST_F(FormatTest, ConfigurableSpaceBeforeBrackets) {
+  FormatStyle NoSpaceStyle = getLLVMStyle();
+  verifyFormat("int a[5];", NoSpaceStyle);
+  verifyFormat("a[3] += 42;", NoSpaceStyle);
+
+  verifyFormat("int a[1];", NoSpaceStyle);
+  verifyFormat("int 1 [a];", NoSpaceStyle);
+  verifyFormat("int a[1][2];", NoSpaceStyle);
+  verifyFormat("a[7] = 5;", NoSpaceStyle);
+  verifyFormat("int a = (f())[23];", NoSpaceStyle);
+  verifyFormat("f([] {})", NoSpaceStyle);
+
+  FormatStyle Space = getLLVMStyle();
+  Space.SpaceBeforeSquareBrackets = true;
+  verifyFormat("int c = []() -> int { return 2; }();\n", Space);
+  verifyFormat("return [i, args...] {};", Space);
+
+  verifyFormat("int a [5];", Space);
+  verifyFormat("a [3] += 42;", Space);
+  verifyFormat("constexpr char hello []{\"hello\"};", Space);
+  verifyFormat("double &operator[](int i) { return 0; }\n"
+   "int i;",
+   Space);
+  verifyFormat("std::unique_ptr foo() {}", Space);
+  verifyFormat("int i = a [a][a]->f();", Space);
+  verifyFormat("int i = (*b) [a]->f();", Space);
+
+  verifyFormat("int a [1];", Space);
+  verifyFormat("int 1 [a];", Space);
+  verifyFormat("int a [1][2];", Space);
+  verifyFormat("a [7] = 5;", Space);
+  verifyFormat("int a = (f()) [23];", Space);
+  verifyFormat("f([] {})", Space);
+}
+
 TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
   verifyFormat("int a = 5;");
   verifyFormat("a += 42;");
@@ -12529,6 +12564,7 @@
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
+  CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(UseCRLF);
 
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterCaseLabel);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2724,7 +2724,9 @@
   !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
  TT_DesignatedInitializerLSquare,
  TT_StructuredBindingLSquare, TT_AttributeSquare) &&
-  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
+  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral) &&
+  !(!Left.is(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
+Right.is(TT_ArraySubscriptLSquare)))
 return false;
   if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
 return !Left.Children.empty(); // No spaces in "{}".
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -543,6 +543,8 @@
Style.SpacesInCStyleCastParentheses);
 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
+IO.mapOptional("SpaceBeforeSquareBrackets",
+   Style.SpaceBeforeSquareBrackets);
 IO.mapOptional("Standard", Style.Standard);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
 IO.mapOptional("TabWidth", Style.TabWidth);
@@ -813,6 +815,7 @@
   LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
   LLVMStyle.SpaceBeforeCpp11BracedList = false;
+  LLVMStyle.SpaceBeforeSquareBrackets = false;
   LLVMStyle.SpacesInAngles = false;
 
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
@@ -1354,10 +1357,11 @@
 
 WhitespaceManager Whitespaces(
 Env.getSourceManager(), Style,
-Style.DeriveLineEnding ?
-  inputUsesCRLF(Env.getSourceManager().getBufferData(Env.getFileID()),
-Style.UseCRLF) :
-  Style.UseCRLF);
+Style.DeriveLineEnding
+? inputUsesCRLF(
+  Env.getSourceManager().getBufferData(Env.getFileID()),
+  Style.UseCRLF)
+: Style.UseCRLF);
 ContinuationIndenter Indenter(Style, Tokens.getKeywords(),
   Env.getSourceManage

[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

Would be nice to add this to the release notes too ;)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

fyi, +x permissions was added to clang/lib/Format/Format.cpp 
I reverted the change in a4a7c1259e8a8f2d11fa29686a6c2834948c1358 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D6920#1748764 , @sylvestre.ledru 
wrote:

> Would be nice to add this to the release notes too ;)


Addressing this and other missing release notes in D70355: [clang-format] [NFC] 
add recent changes to release notes , want to 
try and bring about a change were new clang-format changes are always release 
noted as I've seen  done with `clang-tidy`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

@Anteru thanks for the patch this got landed today, I got burnt by the 100755 
mode change on the file, but thanks to @sylvestre.ledru it got resolved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread Matthäus G. Chajdas via Phabricator via cfe-commits
Anteru added a comment.

Thanks a lot!


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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay accepted this revision.
MyDeveloperDay added a comment.
This revision is now accepted and ready to land.

Thank you for this patch. I'm sorry it took so long, I think this is a 
perfectly reasonable idea and helps cover the functionality that visual studio 
also supports. (which ultimately will help visual studio users embrace 
clang-format even more than they are already)

F10751363: image.png 

This LGTM, and thank you, let us know if you need someone to land this for you.


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

https://reviews.llvm.org/D6920



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


[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-16 Thread Matthäus G. Chajdas via Phabricator via cfe-commits
Anteru updated this revision to Diff 229612.
Anteru edited the summary of this revision.
Anteru added a comment.

Updated as requested.


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

https://reviews.llvm.org/D6920

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

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10643,6 +10643,41 @@
   verifyFormat("int foo = [ &bar, = ]() {};", Spaces);
 }
 
+TEST_F(FormatTest, ConfigurableSpaceBeforeBrackets) {
+  FormatStyle NoSpaceStyle = getLLVMStyle();
+  verifyFormat("int a[5];", NoSpaceStyle);
+  verifyFormat("a[3] += 42;", NoSpaceStyle);
+
+  verifyFormat("int a[1];", NoSpaceStyle);
+  verifyFormat("int 1 [a];", NoSpaceStyle);
+  verifyFormat("int a[1][2];", NoSpaceStyle);
+  verifyFormat("a[7] = 5;", NoSpaceStyle);
+  verifyFormat("int a = (f())[23];", NoSpaceStyle);
+  verifyFormat("f([] {})", NoSpaceStyle);
+
+  FormatStyle Space = getLLVMStyle();
+  Space.SpaceBeforeSquareBrackets = true;
+  verifyFormat("int c = []() -> int { return 2; }();\n", Space);
+  verifyFormat("return [i, args...] {};", Space);
+
+  verifyFormat("int a [5];", Space);
+  verifyFormat("a [3] += 42;", Space);
+  verifyFormat("constexpr char hello []{\"hello\"};", Space);
+  verifyFormat("double &operator[](int i) { return 0; }\n"
+   "int i;",
+   Space);
+  verifyFormat("std::unique_ptr foo() {}", Space);
+  verifyFormat("int i = a [a][a]->f();", Space);
+  verifyFormat("int i = (*b) [a]->f();", Space);
+
+  verifyFormat("int a [1];", Space);
+  verifyFormat("int 1 [a];", Space);
+  verifyFormat("int a [1][2];", Space);
+  verifyFormat("a [7] = 5;", Space);
+  verifyFormat("int a = (f()) [23];", Space);
+  verifyFormat("f([] {})", Space);
+}
+
 TEST_F(FormatTest, ConfigurableSpaceBeforeAssignmentOperators) {
   verifyFormat("int a = 5;");
   verifyFormat("a += 42;");
@@ -12529,6 +12564,7 @@
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
+  CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
   CHECK_PARSE_BOOL(UseCRLF);
 
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterCaseLabel);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2724,7 +2724,9 @@
   !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
  TT_DesignatedInitializerLSquare,
  TT_StructuredBindingLSquare, TT_AttributeSquare) &&
-  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
+  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral) &&
+  !(!Left.is(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
+Right.is(TT_ArraySubscriptLSquare)))
 return false;
   if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
 return !Left.Children.empty(); // No spaces in "{}".
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -543,6 +543,8 @@
Style.SpacesInCStyleCastParentheses);
 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
+IO.mapOptional("SpaceBeforeSquareBrackets",
+   Style.SpaceBeforeSquareBrackets);
 IO.mapOptional("Standard", Style.Standard);
 IO.mapOptional("StatementMacros", Style.StatementMacros);
 IO.mapOptional("TabWidth", Style.TabWidth);
@@ -813,6 +815,7 @@
   LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
   LLVMStyle.SpaceBeforeCpp11BracedList = false;
+  LLVMStyle.SpaceBeforeSquareBrackets = false;
   LLVMStyle.SpacesInAngles = false;
 
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -1986,6 +1986,15 @@
   /// \endcode
   bool SpacesInSquareBrackets;
 
+  /// If ``true``, spaces will be before  ``[``.
+  /// Lambdas will not be affected. Only the first ``[`` will get a space added.
+  /// \code
+  ///true:  false:
+  ///int a [5];vs.  int a[5];
+  ///int a [5][5]; vs.  int a[5][5];
+  /// \endcode
+  bool SpaceBeforeSquareBrackets;
+
   /// Supported language standards for parsing and formatting C++ constructs.
   /// \code
   ///Latest:vector>
@@ -2150,10 +2159,1

[PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2019-11-12 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

I realize this is an old diff, and you and I have just spoke about it on 
twitter https://twitter.com/NIV_Anteru/status/1193792307386081281?s=20 would 
you consider rebasing as the /brief style isn't used any more

It would help the approval process if you could highlight a public project with 
a style guide that uses this style.

I think this is a simple enough addition to consider by getting it upto date 
will help




Comment at: include/clang/Format/Format.h:415
+  bool SpaceBeforeSquareBrackets;
+
   /// \brief Supported language standards.

when you rebase you'll see examples of /codeblocks with before and after I 
think that would really help


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6920



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


Re: [PATCH] D6920: [clang-format] Add SpaceBeforeBrackets

2015-09-26 Thread Matthäus G . Chajdas via cfe-commits
Anteru updated this revision to Diff 35810.
Anteru added a comment.

Here's an updated diff which should do the trick. If not, please tell me how to 
improve -- this is my first change to Clang.


http://reviews.llvm.org/D6920

Files:
  include/clang/Format/Format.h
  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
@@ -8358,6 +8358,43 @@
   verifyFormat("X A::operator++ (T);", Space);
 }
 
+TEST_F(FormatTest, ConfigurableSpaceBeforeSquareBrackets) {
+  FormatStyle NoSpace = getLLVMStyle();
+  NoSpace.SpaceBeforeSquareBrackets = false;
+  
+  verifyFormat("int a[5];", NoSpace);
+  verifyFormat("a[3] += 42;", NoSpace);
+
+  verifyFormat("int a[1];", NoSpace);
+  verifyFormat("int 1 [a];", NoSpace);
+  verifyFormat("int a[1][2];", NoSpace);
+  verifyFormat("a[7] = 5;", NoSpace);
+  verifyFormat("int a = (f())[23];", NoSpace);
+  verifyFormat("f([] {})", NoSpace);
+
+  FormatStyle Space = getLLVMStyle();
+  Space.SpaceBeforeSquareBrackets = true;
+  verifyFormat("int c = []() -> int { return 2; }();\n", Space);
+  verifyFormat("return [i, args...] {};", Space);
+
+  verifyFormat("int a [5];", Space);
+  verifyFormat("a [3] += 42;", Space);
+  verifyFormat("constexpr char hello []{\"hello\"};", Space);
+  verifyFormat("double &operator[](int i) { return 0; }\n"
+"int i;",
+Space);
+  verifyFormat("std::unique_ptr foo() {}", Space);
+  verifyFormat("int i = a [a][a]->f();", Space);
+  verifyFormat("int i = (*b) [a]->f();", Space);
+
+  verifyFormat("int a [1];", Space);
+  verifyFormat("int 1 [a];", Space);
+  verifyFormat("int a [1][2];", Space);
+  verifyFormat("a [7] = 5;", Space);
+  verifyFormat("int a = (f()) [23];", Space);
+  verifyFormat("f([] {})", Space);
+}
+
 TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
   FormatStyle Spaces = getLLVMStyle();
 
@@ -9303,6 +9340,7 @@
   CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeSquareBrackets);
 }
 
 #undef CHECK_PARSE_BOOL
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1882,7 +1882,9 @@
  Right.MatchingParen->is(TT_ArraySubscriptLSquare)));
   if (Right.is(tok::l_square) &&
   !Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare) &&
-  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral))
+  !Left.isOneOf(tok::numeric_constant, TT_DictLiteral) &&
+  !(!Left.is(tok::r_square) && Style.SpaceBeforeSquareBrackets &&
+Right.is(TT_ArraySubscriptLSquare)))
 return false;
   if (Left.is(tok::colon))
 return !Left.is(TT_ObjCMethodExpr);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -279,6 +279,7 @@
Style.SpacesInCStyleCastParentheses);
 IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
 IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
+IO.mapOptional("SpaceBeforeSquareBrackets", Style.SpaceBeforeSquareBrackets);
 IO.mapOptional("Standard", Style.Standard);
 IO.mapOptional("TabWidth", Style.TabWidth);
 IO.mapOptional("UseTab", Style.UseTab);
@@ -391,6 +392,7 @@
   LLVMStyle.UseTab = FormatStyle::UT_Never;
   LLVMStyle.SpacesInParentheses = false;
   LLVMStyle.SpacesInSquareBrackets = false;
+  LLVMStyle.SpaceBeforeSquareBrackets = false;
   LLVMStyle.SpaceInEmptyParentheses = false;
   LLVMStyle.SpacesInContainerLiterals = true;
   LLVMStyle.SpacesInCStyleCastParentheses = false;
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -410,6 +410,9 @@
   /// \brief If \c true, spaces will be inserted after '[' and before ']'.
   bool SpacesInSquareBrackets;
 
+  /// \brief If \c true, a space will be inserted before '[' in array subscripts.
+  bool SpaceBeforeSquareBrackets;
+
   /// \brief Supported language standards.
   enum LanguageStandard {
 /// Use C++03-compatible syntax.
@@ -515,6 +518,7 @@
SpacesInCStyleCastParentheses == R.SpacesInCStyleCastParentheses &&
SpacesInParentheses == R.SpacesInParentheses &&
SpacesInSquareBrackets == R.SpacesInSquareBrackets &&
+   SpaceBeforeSquareBrackets == R.SpaceBeforeSquareBrackets &&
Standard == R.Standard &&
TabWidth == R.TabWidth &&
UseTab == R.UseTab;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman