[PATCH] D71659: Adde new option to allow setting spaces before and after the operator

2019-12-18 Thread Luis Pinto via Phabricator via cfe-commits
Luis created this revision.
Luis added reviewers: djasper, klimek, owenpan, mitchell-stellar.
Luis added a project: clang-format.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The new option is called SpaceBeforeAndAfterArrows

True:
(pointer instance) -> (member)

False:
(pointer instance)->(member)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71659

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

Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3045,8 +3045,11 @@
 return Right.is(TT_TemplateCloser) && Left.is(TT_TemplateCloser) &&
(Style.Standard < FormatStyle::LS_Cpp11 || Style.SpacesInAngles);
   }
-  if (Right.isOneOf(tok::arrow, tok::arrowstar, tok::periodstar) ||
-  Left.isOneOf(tok::arrow, tok::period, tok::arrowstar, tok::periodstar) ||
+  if (Left.is(tok::arrow) || Right.is(tok::arrow)) {
+return Style.SpaceBeforeAndAfterArrows;
+  }
+  if (Right.isOneOf(tok::arrowstar, tok::periodstar) ||
+  Left.isOneOf(tok::period, tok::arrowstar, tok::periodstar) ||
   (Right.is(tok::period) && Right.isNot(TT_DesignatedInitializerPeriod)))
 return false;
   if (!Style.SpaceBeforeAssignmentOperators && Left.isNot(TT_TemplateCloser) &&
@@ -3058,7 +3061,8 @@
   if (Right.is(tok::coloncolon) && Left.is(tok::identifier))
 // Generally don't remove existing spaces between an identifier and "::".
 // The identifier might actually be a macro name such as ALWAYS_INLINE. If
-// this turns out to be too lenient, add analysis of the identifier itself.
+// this turns out to be too lenient, add analysis of the identifier
+// itself.
 return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
   if (Right.is(tok::coloncolon) &&
   !Left.isOneOf(tok::l_brace, tok::comment, tok::l_paren))
@@ -3098,7 +3102,8 @@
   return spaceRequiredBetween(Line, Left, Right);
 }
 
-// Returns 'true' if 'Tok' is a brace we'd want to break before in Allman style.
+// Returns 'true' if 'Tok' is a brace we'd want to break before in Allman
+// style.
 static bool isAllmanBrace(const FormatToken &Tok) {
   return Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block &&
  !Tok.isOneOf(TT_ObjCBlockLBrace, TT_LambdaLBrace, TT_DictLiteral);
@@ -3122,8 +3127,9 @@
 // kw_var/kw_let are pseudo-tokens that are tok::identifier, so match
 // above.
 !Line.First->isOneOf(Keywords.kw_var, Keywords.kw_let))
-  // Object literals on the top level of a file are treated as "enum-style".
-  // Each key/value pair is put on a separate line, instead of bin-packing.
+  // Object literals on the top level of a file are treated as
+  // "enum-style". Each key/value pair is put on a separate line, instead
+  // of bin-packing.
   return true;
 if (Left.is(tok::l_brace) && Line.Level == 0 &&
 (Line.startsWith(tok::kw_enum) ||
@@ -3155,8 +3161,8 @@
   }
 
   // If the last token before a '}', ']', or ')' is a comma or a trailing
-  // comment, the intention is to insert a line break after it in order to make
-  // shuffling around entries easier. Import statements, especially in
+  // comment, the intention is to insert a line break after it in order to
+  // make shuffling around entries easier. Import statements, especially in
   // JavaScript, can be an exception to this rule.
   if (Style.JavaScriptWrapImports || Line.Type != LT_ImportStatement) {
 const FormatToken *BeforeClosingBrace = nullptr;
@@ -3261,18 +3267,17 @@
   if (Right.is(TT_ProtoExtensionLSquare))
 return true;
 
-  // In text proto instances if a submessage contains at least 2 entries and at
-  // least one of them is a submessage, like A { ... B { ... } ... },
-  // put all of the entries of A on separate lines by forcing the selector of
-  // the submessage B to be put on a newline.
+  // In text proto instances if a submessage contains at least 2 entries and
+  // at least one of them is a submessage, like A { ... B { ... } ... }, put
+  // all of the entries of A on separate lines by forcing the selector of the
+  // submessage B to be put on a newline.
   //
   // Example: these can stay on one line:
   // a { scalar_1: 1 scalar_2: 2 }
   // a { b { key: value } }
   //
-  // and these entries need to be on a new line even if putting them all in one
-  // line is under the column limit:
-  // a {
+  // and these entries need to be on a new line even if putting them all in
+  // one line is under the column limit: a {
   //   scalar: 1
   //   b { key: value }
   // }
@@ -3281,11 +3286,12 @@
   // siblings, *and* breaking before a field that follows a submessage field.
   //
   // Be careful to exclude the case  [proto.ext] { ... } since the `]` is
-  // the TT_SelectorName there, but we don't 

[PATCH] D71659: [clang-format] Added new option to allow setting spaces before and after the operator

2019-12-18 Thread Luis Pinto via Phabricator via cfe-commits
Luis added a comment.

In D71659#1789694 , @mitchell-stellar 
wrote:

> This feature is missing unit tests. Also, what is the reason for all the 
> comment changes? I don't think the changed comment lines originally exceeded 
> 80 characters.


Yup, I will add the unit-test when I have time, regarding the comments, it's 
really weird because I'm using clang-format to format the file on save, I'll 
double check and try to revert those comment changes!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71659



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