[PATCH] D50378: [clang-format] comment reflow: add last line's penalty when ending broken

2018-08-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: cfe-commits.

This fixes a bug in clang-format where the last line's penalty is not
taken into account when its ending is broken. Usually the last line's penalty
is handled by addNextStateToQueue, but in cases where the trailing `*/` is put
on a newline, the contents of the last line have to be considered for 
penalizing.


Repository:
  rC Clang

https://reviews.llvm.org/D50378

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+  format("a = function() {\n"
+ "  b = function() {\n"
+ "this.aaa[aaa] = .aa ? "
+ ".aa : /** @type "
+ "{..a.aaa} */\n"
+ "(..a.a.a);\n"
+ "  };\n"
+ "};"));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or 
when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - 
ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "Replacing whitespace after last line.\n");
+
+// We add the last line's penalty here, since that line is going to be 
split
+// now.
+Penalty += Style.PenaltyExcessCharacter *
+   (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
+
 if (!DryRun)
   Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,
 Whitespaces);


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+  format("a = function() {\n"
+ "  b = function() {\n"
+ "this.aaa[aaa] = .aa ? "
+ ".aa : /** @type "
+ "{..a.aaa} */\n"
+ "(..a.a.a);\n"
+ "  };\n"
+ "};"));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "

[PATCH] D50378: [clang-format] comment reflow: add last line's penalty when ending broken

2018-08-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC339123: [clang-format] comment reflow: add last line's 
penalty when ending broken (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50378?vs=159474&id=159476#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50378

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+  format("a = function() {\n"
+ "  b = function() {\n"
+ "this.aaa[aaa] = .aa ? "
+ ".aa : /** @type "
+ "{..a.aaa} */\n"
+ "(..a.a.a);\n"
+ "  };\n"
+ "};"));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or 
when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - 
ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "Replacing whitespace after last line.\n");
+
+// We add the last line's penalty here, since that line is going to be 
split
+// now.
+Penalty += Style.PenaltyExcessCharacter *
+   (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
+
 if (!DryRun)
   Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,
 Whitespaces);


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+  format("a = function() {\n"
+ "  b = function() {\n"
+ "this.aaa[aaa] = .aa ? "
+ ".aa : /** @type "
+ "{..a.aaa} */\n"
+ "(..a.a.a);\n"
+ "  };\n"
+ "};"));
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "Replacing whitespace after last line.\n");
+
+// We add the last line's penalty he

[PATCH] D50378: [clang-format] comment reflow: add last line's penalty when ending broken

2018-08-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339123: [clang-format] comment reflow: add last line's 
penalty when ending broken (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50378

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or 
when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - 
ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "Replacing whitespace after last line.\n");
+
+// We add the last line's penalty here, since that line is going to be 
split
+// now.
+Penalty += Style.PenaltyExcessCharacter *
+   (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
+
 if (!DryRun)
   Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,
 Whitespaces);
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+  format("a = function() {\n"
+ "  b = function() {\n"
+ "this.aaa[aaa] = .aa ? "
+ ".aa : /** @type "
+ "{..a.aaa} */\n"
+ "(..a.a.a);\n"
+ "  };\n"
+ "};"));
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1840,7 +1840,8 @@
 // No break opportunity - update the penalty and continue with the next
 // logical line.
 if (LineIndex < EndIndex - 1)
-  // The last line's penalty is handled in addNextStateToQueue().
+  // The last line's penalty is handled in addNextStateToQueue() or when
+  // calling replaceWhitespaceAfterLastLine below.
   Penalty += Style.PenaltyExcessCharacter *
  (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
 LLVM_DEBUG(llvm::dbgs() << "No break opportunity.\n");
@@ -2095,6 +2096,12 @@
   Token->getSplitAfterLastLine(TailOffset);
   if (SplitAfterLastLine.first != StringRef::npos) {
 LLVM_DEBUG(llvm::dbgs() << "Replacing whitespace after last line.\n");
+
+// We add the last line's penalty here, since that line is going to be split
+// now.
+Penalty += Style.PenaltyExcessCharacter *
+   (ContentStartColumn + RemainingTokenColumns - ColumnLimit);
+
 if (!DryRun)
   Token->replaceWhitespaceAfterLastLine(TailOffset, SplitAfterLastLine,
 Whitespaces);
Index: cfe/trunk/unittests/Format/FormatTestJS.cpp
===
--- cfe/trunk/unittests/Format/FormatTestJS.cpp
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp
@@ -2284,5 +2284,25 @@
"formatMe( );\n");
 }
 
+TEST_F(FormatTestJS, AddsLastLinePenaltyIfEndingIsBroken) {
+  EXPECT_EQ(
+  "a = function() {\n"
+  "  b = function() {\n"
+  "this.aaa[aaa] = .aa ?\n"
+  ".aa : /** @type "
+  "{..a.aaa} */\n"
+  "(..a.a.a);\n"
+  "  };\n"
+  "};",
+ 

[PATCH] D46519: [clang-format] Respect BreakBeforeClosingBrace while calculating length

2018-05-09 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC331857: [clang-format] Respect BreakBeforeClosingBrace while 
calculating length (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46519?vs=145677&id=145881#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46519

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -659,8 +659,8 @@
 static void printLineState(const LineState &State) {
   llvm::dbgs() << "State: ";
   for (const ParenState &P : State.Stack) {
-llvm::dbgs() << P.Indent << "|" << P.LastSpace << "|" << P.NestedBlockIndent
- << " ";
+llvm::dbgs() << (P.Tok ? P.Tok->TokenText : "F") << "|" << P.Indent << "|"
+ << P.LastSpace << "|" << P.NestedBlockIndent << " ";
   }
   llvm::dbgs() << State.NextToken->TokenText << "\n";
 }
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -200,16 +200,23 @@
 };
 
 struct ParenState {
-  ParenState(unsigned Indent, unsigned LastSpace, bool AvoidBinPacking,
- bool NoLineBreak)
-  : Indent(Indent), LastSpace(LastSpace), NestedBlockIndent(Indent),
-BreakBeforeClosingBrace(false), AvoidBinPacking(AvoidBinPacking),
-BreakBeforeParameter(false), NoLineBreak(NoLineBreak),
-NoLineBreakInOperand(false), LastOperatorWrapped(true),
-ContainsLineBreak(false), ContainsUnwrappedBuilder(false),
-AlignColons(true), ObjCSelectorNameFound(false),
-HasMultipleNestedBlocks(false), NestedBlockInlined(false),
-IsInsideObjCArrayLiteral(false) {}
+  ParenState(const FormatToken *Tok, unsigned Indent, unsigned LastSpace,
+ bool AvoidBinPacking, bool NoLineBreak)
+  : Tok(Tok), Indent(Indent), LastSpace(LastSpace),
+NestedBlockIndent(Indent), BreakBeforeClosingBrace(false),
+AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),
+NoLineBreak(NoLineBreak), NoLineBreakInOperand(false),
+LastOperatorWrapped(true), ContainsLineBreak(false),
+ContainsUnwrappedBuilder(false), AlignColons(true),
+ObjCSelectorNameFound(false), HasMultipleNestedBlocks(false),
+NestedBlockInlined(false), IsInsideObjCArrayLiteral(false) {}
+
+  /// \brief The token opening this parenthesis level, or nullptr if this level
+  /// is opened by fake parenthesis.
+  ///
+  /// Not considered for memoization as it will always have the same value at
+  /// the same token.
+  const FormatToken *Tok;
 
   /// The position to which a specific parenthesis level needs to be
   /// indented.
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -35,12 +35,70 @@
 
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
-static unsigned getLengthToMatchingParen(const FormatToken &Tok) {
+static unsigned getLengthToMatchingParen(const FormatToken &Tok,
+ const std::vector &Stack) {
+  // Normally whether or not a break before T is possible is calculated and
+  // stored in T.CanBreakBefore. Braces, array initializers and text proto
+  // messages like `key: < ... >` are an exception: a break is possible
+  // before a closing brace R if a break was inserted after the corresponding
+  // opening brace. The information about whether or not a break is needed
+  // before a closing brace R is stored in the ParenState field
+  // S.BreakBeforeClosingBrace where S is the state that R closes.
+  //
+  // In order to decide whether there can be a break before encountered right
+  // braces, this implementation iterates over the sequence of tokens and over
+  // the paren stack in lockstep, keeping track of the stack level which visited
+  // right braces correspond to in MatchingStackIndex.
+  //
+  // For example, consider:
+  // L. <- line number
+  // 1. {
+  // 2. {1},
+  // 3. {2},
+  // 4. {{3}}}
+  // ^ where we call this method with this token.
+  // The paren stack at this point contains 3 brace levels:
+  //  0. { at line 1, BreakBeforeClosingBrace: true
+  //  1. first { at line 4, BreakBeforeClosingBrace: false
+  //  2. second { at line 4, BreakBeforeClosingBrace: false,
+  //  where there might be fake parens levels in-between these levels.
+  // The algorithm will start at the first 

[PATCH] D46757: [clang-format] Break inside submessages containing a submessage and something else

2018-05-11 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

TODO


Repository:
  rC Clang

https://reviews.llvm.org/D46757

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -171,17 +171,48 @@
   verifyFormat("msg_field < field_a < field_b <> > >");
   verifyFormat("msg_field: < field_a < field_b: <> > >");
   verifyFormat("msg_field < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field < field_a { field_b: 1 }, field_c: < f_d: 2 > >");
   verifyFormat("msg_field: < field_a: OK, field_b: \"OK\" >");
-  verifyFormat("msg_field: < field_a: OK field_b: <>, field_c: OK >");
-  verifyFormat("msg_field: < field_a { field_b: 1 }, field_c: < fd_d: 2 > >");
-  verifyFormat("field_a: \"OK\", msg_field: < field_b: 123 >, field_c: {}");
-  verifyFormat("field_a < field_b: 1 >, msg_fid: < fiel_b: 123 >, field_c <>");
-  verifyFormat("field_a < field_b: 1 > msg_fied: < field_b: 123 > field_c <>");
-  verifyFormat("field < field < field: <> >, field <> > field: < field: 1 >");
-
   // Multiple lines tests
+  verifyFormat("msg_field <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < f_d: 2 >\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a: OK\n"
+   "  field_b: <>,\n"
+   "  field_c: OK\n"
+   ">");
+
+  verifyFormat("msg_field: <\n"
+   "  field_a { field_b: 1 },\n"
+   "  field_c: < fd_d: 2 >\n"
+   ">");
+
+  verifyFormat("field_a: \"OK\",\n"
+   "msg_field: < field_b: 123 >,\n"
+   "field_c: {}");
+
+  verifyFormat("field_a < field_b: 1 >,\n"
+   "msg_fid: < fiel_b: 123 >,\n" 
+   "field_c <>");
+
+  verifyFormat("field_a < field_b: 1 >\n"
+   "msg_fied: < field_b: 123 >\n"
+   "field_c <>");
+
+  verifyFormat("field <\n"
+   "  field < field: <> >,\n"
+   "  field <>\n"
+   ">\n"
+   "field: < field: 1 >");
+
   verifyFormat("msg_field <\n"
"  field_a: OK\n"
"  field_b: \"OK\"\n"
@@ -242,7 +273,10 @@
"  field_d: ok\n"
"}");
 
-  verifyFormat("field_a: < f1: 1, f2: <> >\n"
+  verifyFormat("field_a: <\n"
+   "  f1: 1,\n"
+   "  f2: <>\n"
+   ">\n"
"field_b <\n"
"  field_b1: <>\n"
"  field_b2: ok,\n"
@@ -507,5 +541,102 @@
">");
 }
 
+TEST_F(FormatTestTextProto, BreaksEntriesOfSubmessagesContainingSubmessages) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60;
+  // The column limit allows for the keys submessage to be put on 1 line, but we
+  // break it since it contains a submessage an another entry.
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub <>\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: ''\n"
+   "  sub {}\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  sub: <>\n"
+   "  sub: []\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: { msg: 1 }\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub < msg: 1 >\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  item: 'aaa'\n"
+   "  sub: [ msg: 1 ]\n"
+   "}");
+  verifyFormat("key: valu\n"
+   "keys: <\n"
+   "  item: 'aaa'\n"
+   "  sub: [ 1, 2 ]\n"
+   ">");
+  verifyFormat("key: valu\n"
+   "keys: {\n"
+   "  sub {}\n"
+   "  item: ''\n"
+   "}");
+  verifyFormat("key: valueee

[PATCH] D46824: [clang-format] Continue after non-scope-closers in getLengthToMatchingParen

2018-05-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This fixes a regression introduced by `r331857` where we stop the search for
the End token as soon as we hit a non-scope-closer, which prematurely stops 
before
semicolons for example, which should otherwise be considered as part of the 
unbreakable tail.


Repository:
  rC Clang

https://reviews.llvm.org/D46824

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1142,6 +1142,18 @@
"  @\"aa\"\n"
"];\n");
 }
+
+TEST_F(FormatTestObjC, BreaksCallStatementWhereSemiJustOverTheLimit) {
+  Style.ColumnLimit = 60;
+  // If the statement starting with 'a = ...' is put on a single line, the ';'
+  // is at line 61.
+  verifyFormat("int f(int a) {\n"
+   "  a = [self aa:b\n"
+   " c:\n"
+   "ee:fddd];\n"
+   "}");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -90,8 +90,10 @@
 return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
   };
   for (; End->Next; End = End->Next) {
-if (End->Next->CanBreakBefore || !End->Next->closesScope())
+if (End->Next->CanBreakBefore)
   break;
+if (!End->Next->closesScope())
+  continue;
 if (End->Next->MatchingParen->isOneOf(tok::l_brace,
   TT_ArrayInitializerLSquare,
   tok::less)) {


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1142,6 +1142,18 @@
"  @\"aa\"\n"
"];\n");
 }
+
+TEST_F(FormatTestObjC, BreaksCallStatementWhereSemiJustOverTheLimit) {
+  Style.ColumnLimit = 60;
+  // If the statement starting with 'a = ...' is put on a single line, the ';'
+  // is at line 61.
+  verifyFormat("int f(int a) {\n"
+   "  a = [self aa:b\n"
+   " c:\n"
+   "ee:fddd];\n"
+   "}");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -90,8 +90,10 @@
 return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
   };
   for (; End->Next; End = End->Next) {
-if (End->Next->CanBreakBefore || !End->Next->closesScope())
+if (End->Next->CanBreakBefore)
   break;
+if (!End->Next->closesScope())
+  continue;
 if (End->Next->MatchingParen->isOneOf(tok::l_brace,
   TT_ArrayInitializerLSquare,
   tok::less)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D46824: [clang-format] Continue after non-scope-closers in getLengthToMatchingParen

2018-05-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC332225: [clang-format] Continue after non-scope-closers in 
getLengthToMatchingParen (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D46824?vs=146569&id=146570#toc

Repository:
  rC Clang

https://reviews.llvm.org/D46824

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestObjC.cpp


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -90,8 +90,10 @@
 return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
   };
   for (; End->Next; End = End->Next) {
-if (End->Next->CanBreakBefore || !End->Next->closesScope())
+if (End->Next->CanBreakBefore)
   break;
+if (!End->Next->closesScope())
+  continue;
 if (End->Next->MatchingParen->isOneOf(tok::l_brace,
   TT_ArrayInitializerLSquare,
   tok::less)) {
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1142,6 +1142,18 @@
"  @\"aa\"\n"
"];\n");
 }
+
+TEST_F(FormatTestObjC, BreaksCallStatementWhereSemiJustOverTheLimit) {
+  Style.ColumnLimit = 60;
+  // If the statement starting with 'a = ...' is put on a single line, the ';'
+  // is at line 61.
+  verifyFormat("int f(int a) {\n"
+   "  a = [self aa:b\n"
+   " c:\n"
+   "ee:fddd];\n"
+   "}");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -90,8 +90,10 @@
 return MatchingStackIndex >= 0 ? &Stack[MatchingStackIndex] : nullptr;
   };
   for (; End->Next; End = End->Next) {
-if (End->Next->CanBreakBefore || !End->Next->closesScope())
+if (End->Next->CanBreakBefore)
   break;
+if (!End->Next->closesScope())
+  continue;
 if (End->Next->MatchingParen->isOneOf(tok::l_brace,
   TT_ArrayInitializerLSquare,
   tok::less)) {
Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -1142,6 +1142,18 @@
"  @\"aa\"\n"
"];\n");
 }
+
+TEST_F(FormatTestObjC, BreaksCallStatementWhereSemiJustOverTheLimit) {
+  Style.ColumnLimit = 60;
+  // If the statement starting with 'a = ...' is put on a single line, the ';'
+  // is at line 61.
+  verifyFormat("int f(int a) {\n"
+   "  a = [self aa:b\n"
+   " c:\n"
+   "ee:fddd];\n"
+   "}");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47191: [clang-format] Fix crash in getLengthToMatchingParen

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

Found by oss-fuzz:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8212


Repository:
  rC Clang

https://reviews.llvm.org/D47191

Files:
  lib/Format/ContinuationIndenter.cpp


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -94,9 +94,9 @@
   break;
 if (!End->Next->closesScope())
   continue;
-if (End->Next->MatchingParen->isOneOf(tok::l_brace,
-  TT_ArrayInitializerLSquare,
-  tok::less)) {
+if (End->Next->MatchingParen &&
+End->Next->MatchingParen->isOneOf(
+tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {
   const ParenState *State = FindParenState(End->Next->MatchingParen);
   if (State && State->BreakBeforeClosingBrace)
 break;


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -94,9 +94,9 @@
   break;
 if (!End->Next->closesScope())
   continue;
-if (End->Next->MatchingParen->isOneOf(tok::l_brace,
-  TT_ArrayInitializerLSquare,
-  tok::less)) {
+if (End->Next->MatchingParen &&
+End->Next->MatchingParen->isOneOf(
+tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {
   const ParenState *State = FindParenState(End->Next->MatchingParen);
   if (State && State->BreakBeforeClosingBrace)
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47191: [clang-format] Fix crash in getLengthToMatchingParen

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL332961: [clang-format] Fix crash in getLengthToMatchingParen 
(authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47191

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -94,9 +94,9 @@
   break;
 if (!End->Next->closesScope())
   continue;
-if (End->Next->MatchingParen->isOneOf(tok::l_brace,
-  TT_ArrayInitializerLSquare,
-  tok::less)) {
+if (End->Next->MatchingParen &&
+End->Next->MatchingParen->isOneOf(
+tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {
   const ParenState *State = FindParenState(End->Next->MatchingParen);
   if (State && State->BreakBeforeClosingBrace)
 break;


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -94,9 +94,9 @@
   break;
 if (!End->Next->closesScope())
   continue;
-if (End->Next->MatchingParen->isOneOf(tok::l_brace,
-  TT_ArrayInitializerLSquare,
-  tok::less)) {
+if (End->Next->MatchingParen &&
+End->Next->MatchingParen->isOneOf(
+tok::l_brace, TT_ArrayInitializerLSquare, tok::less)) {
   const ParenState *State = FindParenState(End->Next->MatchingParen);
   if (State && State->BreakBeforeClosingBrace)
 break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47191: [clang-format] Fix crash in getLengthToMatchingParen

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Added a test in  https://reviews.llvm.org/rL332974.
Didn't add a test case and didn't wait for review. Sorry about that!


Repository:
  rL LLVM

https://reviews.llvm.org/D47191



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


[PATCH] D47195: [clang-format] Fix ObjC message arguments handling

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:815
+
+  // No line break before closing receiver's scope.
+  verifyFormat("[[obj a:42] a:42\n"

What's the receiver's scope in this comment referring to?
Also, how would the old test cases be formatted?


Repository:
  rC Clang

https://reviews.llvm.org/D47195



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


[PATCH] D47195: [clang-format] Fix ObjC message arguments handling

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:815
+
+  // No line break before closing receiver's scope.
+  verifyFormat("[[obj a:42] a:42\n"

jolesiak wrote:
> krasimir wrote:
> > What's the receiver's scope in this comment referring to?
> > Also, how would the old test cases be formatted?
> For a receiver: `[obj a:42]` I meant `]` as a token closing the scope.
> I'll rephrase the comment to be more precise.
> 
> Old tests were introduced in D46879. After this change the formatting will be 
> the same as it was before D46879, i.e. the same as for last test touched in 
> this change:
> ```
> [[obj aa:42
>b:42]
> cc:42
>  d:42];
> ```
> even if
> ```
> [[obj aa:42
>b:42]
> cc:42 d:42];
> ```
> satisfies the column limit.
Ah, I think  get it now: the new code should only apply to after object blocks 
and not after object receivers? Is this the intention?


Repository:
  rC Clang

https://reviews.llvm.org/D47195



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


[PATCH] D47195: [clang-format] Fix putting ObjC message arguments in one line for multiline receiver

2018-05-22 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:815
+
+  // No line break before closing receiver's scope.
+  verifyFormat("[[obj a:42] a:42\n"

jolesiak wrote:
> krasimir wrote:
> > jolesiak wrote:
> > > krasimir wrote:
> > > > What's the receiver's scope in this comment referring to?
> > > > Also, how would the old test cases be formatted?
> > > For a receiver: `[obj a:42]` I meant `]` as a token closing the scope.
> > > I'll rephrase the comment to be more precise.
> > > 
> > > Old tests were introduced in D46879. After this change the formatting 
> > > will be the same as it was before D46879, i.e. the same as for last test 
> > > touched in this change:
> > > ```
> > > [[obj aa:42
> > >b:42]
> > > cc:42
> > >  d:42];
> > > ```
> > > even if
> > > ```
> > > [[obj aa:42
> > >b:42]
> > > cc:42 d:42];
> > > ```
> > > satisfies the column limit.
> > Ah, I think  get it now: the new code should only apply to after object 
> > blocks and not after object receivers? Is this the intention?
> The intention is to put arguments into one line if they fit but only in the 
> same line as last character of a receiver expression, e.g.:
> ```
> [[object block:^{
>   return 42;
> }] aa:42 bb:42];
> ```
> instead of
> ```
> [[object block:^{
>   return 42;
> }] aa:42
>bb:42];
> ```
> but not
> ```
> [[obj a:42]
> a:42 b:42];
> ```
> 
> I think it gets a little bit too complicated for no reason. Let me revert 
> D46879 and rebase this change.
In that case, would this be allowed?
```
//  limit:   V
[[obj a:42
  b:42
  c:42
  d:42] e:42 f:42]
```


Repository:
  rC Clang

https://reviews.llvm.org/D47195



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


[PATCH] D47257: [clang-format] Break template declarations followed by comments

2018-05-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch fixes two bugs in clang-format where the template wrapper doesn't 
skip over
comments causing a long template declaration to not be split into multiple 
lines.
These were latent and exposed by r332436.


Repository:
  rC Clang

https://reviews.llvm.org/D47257

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5521,6 +5521,58 @@
NeverBreak);
 }
 
+TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  Style.ColumnLimit = 60;
+  EXPECT_EQ(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test",
+format(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value> /* line */
+void f() {})test",
+format(R"test(
+template ::value>  /* line */
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+   // multiline
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+  // multiline
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template ::value>  // trailing lng
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing lng
+void f() {})test", Style));
+}
+
 TEST_F(FormatTest, WrapsTemplateParameters) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -405,7 +405,7 @@
   // If the template declaration spans multiple lines, force wrap before the
   // function/class declaration
   if (Previous.ClosesTemplateDeclaration &&
-  State.Stack.back().BreakBeforeParameter)
+  State.Stack.back().BreakBeforeParameter && Current.CanBreakBefore)
 return true;
 
   if (State.Column <= NewLineColumn)
@@ -804,7 +804,8 @@
!State.Stack.back().AvoidBinPacking) ||
   Previous.is(TT_BinaryOperator))
 State.Stack.back().BreakBeforeParameter = false;
-  if (Previous.isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
+  if (PreviousNonComment &&
+  PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
   Current.NestingLevel == 0)
 State.Stack.back().BreakBeforeParameter = false;
   if (NextNonComment->is(tok::question) ||


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -5521,6 +5521,58 @@
NeverBreak);
 }
 
+TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  Style.ColumnLimit = 60;
+  EXPECT_EQ(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test",
+format(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value> /* line */
+void f() {})test",
+format(R"test(
+template ::value>  /* line */
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+   // multiline
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+  // multiline
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template ::value>  // trailing lng
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing lng
+void f() {})test", Style));
+}
+
 TEST_F(FormatTest, WrapsTemplateParameters) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
Index: lib/Format/ContinuationIndenter.cpp
=

[PATCH] D47257: [clang-format] Break template declarations followed by comments

2018-05-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL333085: [clang-format] Break template declarations followed 
by comments (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D47257

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


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -405,7 +405,7 @@
   // If the template declaration spans multiple lines, force wrap before the
   // function/class declaration
   if (Previous.ClosesTemplateDeclaration &&
-  State.Stack.back().BreakBeforeParameter)
+  State.Stack.back().BreakBeforeParameter && Current.CanBreakBefore)
 return true;
 
   if (State.Column <= NewLineColumn)
@@ -804,7 +804,8 @@
!State.Stack.back().AvoidBinPacking) ||
   Previous.is(TT_BinaryOperator))
 State.Stack.back().BreakBeforeParameter = false;
-  if (Previous.isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
+  if (PreviousNonComment &&
+  PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
   Current.NestingLevel == 0)
 State.Stack.back().BreakBeforeParameter = false;
   if (NextNonComment->is(tok::question) ||
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -5521,6 +5521,58 @@
NeverBreak);
 }
 
+TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  Style.ColumnLimit = 60;
+  EXPECT_EQ(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test",
+format(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value> /* line */
+void f() {})test",
+format(R"test(
+template ::value>  /* line */
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename aa::value>  // trailing
+   // multiline
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing
+  // multiline
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template ::value>  // trailing lng
+void f() {})test",
+format(R"test(
+template <
+typename aa::value> // trailing lng
+void f() {})test", Style));
+}
+
 TEST_F(FormatTest, WrapsTemplateParameters) {
   FormatStyle Style = getLLVMStyle();
   Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -405,7 +405,7 @@
   // If the template declaration spans multiple lines, force wrap before the
   // function/class declaration
   if (Previous.ClosesTemplateDeclaration &&
-  State.Stack.back().BreakBeforeParameter)
+  State.Stack.back().BreakBeforeParameter && Current.CanBreakBefore)
 return true;
 
   if (State.Column <= NewLineColumn)
@@ -804,7 +804,8 @@
!State.Stack.back().AvoidBinPacking) ||
   Previous.is(TT_BinaryOperator))
 State.Stack.back().BreakBeforeParameter = false;
-  if (Previous.isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
+  if (PreviousNonComment &&
+  PreviousNonComment->isOneOf(TT_TemplateCloser, TT_JavaAnnotation) &&
   Current.NestingLevel == 0)
 State.Stack.back().BreakBeforeParameter = false;
   if (NextNonComment->is(tok::question) ||
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -5521,6 +5521,58 @@
NeverBreak);
 }
 
+TEST_F(FormatTest, WrapsTemplateDeclarationsWithComments) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Cpp);
+  Style.ColumnLimit = 60;
+  EXPECT_EQ(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test",
+format(R"test(
+// Baseline - no comments.
+template <
+typename aa::value>
+void f() {})test", Style));
+
+  EXPECT_EQ(R"test(
+template <
+typename a

[PATCH] D38243: [clang-format] Add ext/ to google include categories

2017-09-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This adds an ext/ header include category for google style.


https://reviews.llvm.org/D38243

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37695: [clang-format] Break non-trailing comments, try 2

2017-09-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

ping


https://reviews.llvm.org/D37695



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


[PATCH] D38243: [clang-format] Add ext/ to google include categories

2017-09-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314211: [clang-format] Add ext/ to google include categories 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D38243

Files:
  cfe/trunk/lib/Format/Format.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -665,7 +665,8 @@
   GoogleStyle.AlwaysBreakTemplateDeclarations = true;
   GoogleStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
   GoogleStyle.DerivePointerAlignment = true;
-  GoogleStyle.IncludeCategories = {{"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
+  GoogleStyle.IncludeCategories = {
+  {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37695: [clang-format] Break non-trailing comments, try 2

2017-09-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 116742.
krasimir added a comment.

- Change bool from Paren to Line and generalize it


https://reviews.llvm.org/D37695

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/ContinuationIndenter.h
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -65,6 +65,27 @@
 TEST_F(FormatTestJS, BlockComments) {
   verifyFormat("/* a */ aaa(\n"
"aaa);");
+  // Breaks after a single line block comment.
+  EXPECT_EQ("a = .ccc(\n"
+"/** @type_{!.rrr..LLL.lala} */\n"
+"mediaMessage);",
+format("a = .ccc(\n"
+   "/** "
+   "@type_{!.rrr..LLL.lala} */ "
+   "mediaMessage);",
+   getGoogleJSStyleWithColumns(70)));
+  // Breaks after a multiline block comment.
+  EXPECT_EQ(
+  "a = .ccc(\n"
+  "/**\n"
+  " * @type_{!.rrr..LLL.lala}\n"
+  " */\n"
+  "mediaMessage);",
+  format("a = .ccc(\n"
+ "/**\n"
+ " * @type_{!.rrr..LLL.lala}\n"
+ " */ mediaMessage);",
+ getGoogleJSStyleWithColumns(70)));
 }
 
 TEST_F(FormatTestJS, JSDocComments) {
Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -2407,6 +2407,57 @@
getLLVMStyleWithColumns(15)));
 }
 
+TEST_F(FormatTestComments, BreaksAfterMultilineBlockCommentsInParamLists) {
+  EXPECT_EQ("a = f(/* long\n"
+" long\n"
+"   */\n"
+"  a);",
+format("a = f(/* long long */ a);", getLLVMStyleWithColumns(15)));
+
+  EXPECT_EQ("a = f(/* long\n"
+" long\n"
+"   */\n"
+"  a);",
+format("a = f(/* long\n"
+   " long\n"
+   "   */a);",
+   getLLVMStyleWithColumns(15)));
+
+  EXPECT_EQ("a = f(/* long\n"
+" long\n"
+"   */\n"
+"  a);",
+format("a = f(/* long\n"
+   " long\n"
+   "   */ a);",
+   getLLVMStyleWithColumns(15)));
+
+  EXPECT_EQ("a = f(/* long\n"
+" long\n"
+"   */\n"
+"  (1 + 1));",
+format("a = f(/* long\n"
+   " long\n"
+   "   */ (1 + 1));",
+   getLLVMStyleWithColumns(15)));
+
+  EXPECT_EQ(
+  "a = f(a,\n"
+  "  /* long\n"
+  " long\n"
+  "   */\n"
+  "  b);",
+  format("a = f(a, /* long long */ b);", getLLVMStyleWithColumns(15)));
+
+  EXPECT_EQ(
+  "a = f(a,\n"
+  "  /* long\n"
+  " long\n"
+  "   */\n"
+  "  (1 + 1));",
+  format("a = f(a, /* long long */ (1 + 1));", getLLVMStyleWithColumns(15)));
+}
+
 TEST_F(FormatTestComments, IndentLineCommentsInStartOfBlockAtEndOfFile) {
   verifyFormat("{\n"
"  // a\n"
@@ -2805,6 +2856,22 @@
   getLLVMStyleWithColumns(80)));
   // clang-format on
 }
+
+TEST_F(FormatTestComments, NonTrailingBlockComments) {
+  verifyFormat("const /** comment comment */ A = B;",
+   getLLVMStyleWithColumns(40));
+
+  verifyFormat("const /** comment comment comment */ A =\n"
+   "B;",
+   getLLVMStyleWithColumns(40));
+
+  EXPECT_EQ("const /** comment comment comment\n"
+" comment */\n"
+"A = B;",
+format("const /** comment comment comment comment */\n"
+   "A = B;",
+   getLLVMStyleWithColumns(40)));
+}
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.h
===
--- lib/Format/ContinuationIndenter.h
+++ lib/Format/ContinuationIndenter.h
@@ -318,6 +318,9 @@
   /// \brief \c true if this line contains a continued for-loop section.
   bool LineContainsContinuedForLoopSection;
 
+  /// \brief \c true if \p NextToken should not continue this line.
+  bool NoContinuation;
+
   /// \brief The \c NestingLevel at the start of this line.
   unsigned StartOfLineLevel;
 
@@ -364,6 +367,8 @@
 if (LineContainsContinuedForLoop

[PATCH] D37904: [clang-format] Fix FixNamespaceComments when BraceWrapping AfterNamespace is true.

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

Looks good!

I must have gotten confused with my test suggestion.
Do you have commit access, or should I commit this for you?


https://reviews.llvm.org/D37904



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


[PATCH] D37973: [clang-format] Fix regression about short functions after #else

2017-10-02 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL314683: [clang-format] Fix regression about short functions 
after #else (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D37973

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


Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -466,8 +466,7 @@
 // Check that the current line allows merging. This depends on whether we
 // are in a control flow statements as well as several style flags.
 if (Line.First->isOneOf(tok::kw_else, tok::kw_case) ||
-(Line.First->Next && Line.First->Next->is(tok::kw_else)) ||
-(I != AnnotatedLines.begin() && I[-1]->Last->is(tok::kw_else)))
+(Line.First->Next && Line.First->Next->is(tok::kw_else)))
   return 0;
 if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try,
 tok::kw___try, tok::kw_catch, tok::kw___finally,
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -7102,6 +7102,16 @@
"}",
Style);
 }
+TEST_F(FormatTest, KeepShortFunctionAfterPPElse) {
+  FormatStyle Style = getLLVMStyle();
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  verifyFormat("#ifdef A\n"
+   "int f() {}\n"
+   "#else\n"
+   "int g() {}\n"
+   "#endif",
+   Style);
+}
 
 TEST_F(FormatTest, SplitEmptyClass) {
   FormatStyle Style = getLLVMStyle();


Index: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
@@ -466,8 +466,7 @@
 // Check that the current line allows merging. This depends on whether we
 // are in a control flow statements as well as several style flags.
 if (Line.First->isOneOf(tok::kw_else, tok::kw_case) ||
-(Line.First->Next && Line.First->Next->is(tok::kw_else)) ||
-(I != AnnotatedLines.begin() && I[-1]->Last->is(tok::kw_else)))
+(Line.First->Next && Line.First->Next->is(tok::kw_else)))
   return 0;
 if (Line.First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_do, tok::kw_try,
 tok::kw___try, tok::kw_catch, tok::kw___finally,
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -7102,6 +7102,16 @@
"}",
Style);
 }
+TEST_F(FormatTest, KeepShortFunctionAfterPPElse) {
+  FormatStyle Style = getLLVMStyle();
+  Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
+  verifyFormat("#ifdef A\n"
+   "int f() {}\n"
+   "#else\n"
+   "int g() {}\n"
+   "#endif",
+   Style);
+}
 
 TEST_F(FormatTest, SplitEmptyClass) {
   FormatStyle Style = getLLVMStyle();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37695: [clang-format] Break non-trailing comments, try 2

2017-10-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

ping


https://reviews.llvm.org/D37695



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


[PATCH] D37695: [clang-format] Break non-trailing comments, try 2

2017-10-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL315893: [clang-format] Break non-trailing comments, try 2 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D37695

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/BreakableToken.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/ContinuationIndenter.h
  cfe/trunk/unittests/Format/FormatTestComments.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp

Index: cfe/trunk/lib/Format/BreakableToken.h
===
--- cfe/trunk/lib/Format/BreakableToken.h
+++ cfe/trunk/lib/Format/BreakableToken.h
@@ -58,6 +58,8 @@
 /// operations that might be executed before the main line breaking occurs:
 /// - getSplitBefore, for finding a split such that the content preceding it
 ///   needs to be specially reflown,
+/// - introducesBreakBefore, for checking if reformatting the beginning
+///   of the content introduces a line break before it,
 /// - getLineLengthAfterSplitBefore, for calculating the line length in columns
 ///   of the remainder of the content after the beginning of the content has
 ///   been reformatted, and
@@ -135,6 +137,12 @@
 return Split(StringRef::npos, 0);
   }
 
+  /// \brief Returns if a break before the content at \p LineIndex will be
+  /// inserted after the whitespace preceding the content has been reformatted.
+  virtual bool introducesBreakBefore(unsigned LineIndex) const {
+return false;
+  }
+
   /// \brief Returns the number of columns required to format the piece of line
   /// at \p LineIndex after the content preceding the whitespace range specified
   /// \p SplitBefore has been reformatted, but before any breaks are made to
@@ -339,6 +347,7 @@
   Split getSplitBefore(unsigned LineIndex, unsigned PreviousEndColumn,
unsigned ColumnLimit,
llvm::Regex &CommentPragmasRegex) const override;
+  bool introducesBreakBefore(unsigned LineIndex) const override;
   unsigned getLineLengthAfterSplitBefore(unsigned LineIndex,
  unsigned TailOffset,
  unsigned PreviousEndColumn,
Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -599,6 +599,12 @@
   }
 }
 
+bool BreakableBlockComment::introducesBreakBefore(unsigned LineIndex) const {
+  // A break is introduced when we want delimiters on newline.
+  return LineIndex == 0 && DelimitersOnNewline &&
+ Lines[0].substr(1).find_first_not_of(Blanks) != StringRef::npos;
+}
+
 void BreakableBlockComment::replaceWhitespaceBefore(
 unsigned LineIndex, unsigned PreviousEndColumn, unsigned ColumnLimit,
 Split SplitBefore, WhitespaceManager &Whitespaces) {
Index: cfe/trunk/lib/Format/ContinuationIndenter.h
===
--- cfe/trunk/lib/Format/ContinuationIndenter.h
+++ cfe/trunk/lib/Format/ContinuationIndenter.h
@@ -318,6 +318,9 @@
   /// \brief \c true if this line contains a continued for-loop section.
   bool LineContainsContinuedForLoopSection;
 
+  /// \brief \c true if \p NextToken should not continue this line.
+  bool NoContinuation;
+
   /// \brief The \c NestingLevel at the start of this line.
   unsigned StartOfLineLevel;
 
@@ -364,6 +367,8 @@
 if (LineContainsContinuedForLoopSection !=
 Other.LineContainsContinuedForLoopSection)
   return LineContainsContinuedForLoopSection;
+if (NoContinuation != Other.NoContinuation)
+  return NoContinuation;
 if (StartOfLineLevel != Other.StartOfLineLevel)
   return StartOfLineLevel < Other.StartOfLineLevel;
 if (LowestLevelOnLine != Other.LowestLevelOnLine)
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -106,6 +106,7 @@
/*AvoidBinPacking=*/false,
/*NoLineBreak=*/false));
   State.LineContainsContinuedForLoopSection = false;
+  State.NoContinuation = false;
   State.StartOfStringLiteral = 0;
   State.StartOfLineLevel = 0;
   State.LowestLevelOnLine = 0;
@@ -322,6 +323,12 @@
  Previous.TokenText == "\'\\n\'"
 return true;
 
+  if (Previous.is(TT_BlockComment) && Previous.IsMultiline)
+return true;
+
+  if (State.NoContinuation)
+return true;
+
   return false;
 }
 
@@ -331,6 +338,8 @@
   const FormatToken &Current = *State.NextToken;
 
   assert(!State.Stack.empty());
+  State.NoContinuation = false;
+
   if ((Current.is(TT_ImplicitStringLiteral) &&
(Current.Previous->Tok.getIdentifierInfo() == nullptr ||

[PATCH] D38731: [clangd] Allow to pass code completion opts to ClangdServer.

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

Great! I like the unit testing approach a lot!


https://reviews.llvm.org/D38731



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


[PATCH] D39024: [clang-format] Sort whole block of using declarations while partially formatting

2017-10-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

This patch enables sorting the full block of using declarations when
some line is affected.


https://reviews.llvm.org/D39024

Files:
  lib/Format/UsingDeclarationsSorter.cpp
  unittests/Format/UsingDeclarationsSorterTest.cpp

Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- unittests/Format/UsingDeclarationsSorterTest.cpp
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+  "\n"
+  "using b;\n" // starts at offset 19
+  "using a;\n"
+  "\n"
+  "using f;\n"
+  "using e;",
+  {tooling::Range(19, 1)}));
 }
 
 } // end namespace
Index: lib/Format/UsingDeclarationsSorter.cpp
===
--- lib/Format/UsingDeclarationsSorter.cpp
+++ lib/Format/UsingDeclarationsSorter.cpp
@@ -74,37 +74,40 @@
 }
 
 void endUsingDeclarationBlock(
-SmallVectorImpl *UsingDeclarations,
+SmallVectorImpl *UsingDeclarations, bool *BlockAffected,
 const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
-  SmallVector SortedUsingDeclarations(
-  UsingDeclarations->begin(), UsingDeclarations->end());
-  std::stable_sort(SortedUsingDeclarations.begin(),
-   SortedUsingDeclarations.end());
-  for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) {
-if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line)
-  continue;
-auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation();
-auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
-auto SortedBegin =
-SortedUsingDeclarations[I].Line->First->Tok.getLocation();
-auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
-StringRef Text(SourceMgr.getCharacterData(SortedBegin),
-   SourceMgr.getCharacterData(SortedEnd) -
-   SourceMgr.getCharacterData(SortedBegin));
-DEBUG({
-  StringRef OldText(SourceMgr.getCharacterData(Begin),
-SourceMgr.getCharacterData(End) -
-SourceMgr.getCharacterData(Begin));
-  llvm::dbgs() << "Replacing '" << OldText << "' with '" << Text << "'\n";
-});
-auto Range = CharSourceRange::getCharRange(Begin, End);
-auto Err = Fixes->add(tooling::Replacement(SourceMgr, Range, Text));
-if (Err) {
-  llvm::errs() << "Error while sorting using declarations: "
-   << llvm::toString(std::move(Err)) << "\n";
+  if (*BlockAffected) {
+SmallVector SortedUsingDeclarations(
+UsingDeclarations->begin(), UsingDeclarations->end());
+std::stable_sort(SortedUsingDeclarations.begin(),
+ SortedUsingDeclarations.end());
+for (size_t I = 0, E = UsingDeclarations->size(); I < E; ++I) {
+  if ((*UsingDeclarations)[I].Line == SortedUsingDeclarations[I].Line)
+continue;
+  auto Begin = (*UsingDeclarations)[I].Line->First->Tok.getLocation();
+  auto End = (*UsingDeclarations)[I].Line->Last->Tok.getEndLoc();
+  auto SortedBegin =
+  SortedUsingDeclarations[I].Line->First->Tok.getLocation();
+  auto SortedEnd = SortedUsingDeclarations[I].Line->Last->Tok.getEndLoc();
+  StringRef Text(SourceMgr.getCharacterData(SortedBegin),
+ SourceMgr.getCharacterData(SortedEnd) -
+ SourceMgr.getCharacterData(SortedBegin));
+  DEBUG({
+StringRef OldText(SourceMgr.getCharacterData(Begin),
+   

[PATCH] D35541: [CMake] Use #cmakedefine01 for CLANG_ENABLE_(ARCMT|OBJC_REWRITER|STATIC_ANALYZER)

2017-10-17 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

How is this even reviewed?


Repository:
  rL LLVM

https://reviews.llvm.org/D35541



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


[PATCH] D39024: [clang-format] Sort whole block of using declarations while partially formatting

2017-10-18 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 119518.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D39024

Files:
  lib/Format/UsingDeclarationsSorter.cpp
  unittests/Format/UsingDeclarationsSorterTest.cpp


Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- unittests/Format/UsingDeclarationsSorterTest.cpp
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+  "\n"
+  "using b;\n" // starts at offset 19
+  "using a;\n"
+  "\n"
+  "using f;\n"
+  "using e;",
+  {tooling::Range(19, 1)}));
 }
 
 } // end namespace
Index: lib/Format/UsingDeclarationsSorter.cpp
===
--- lib/Format/UsingDeclarationsSorter.cpp
+++ lib/Format/UsingDeclarationsSorter.cpp
@@ -76,6 +76,17 @@
 void endUsingDeclarationBlock(
 SmallVectorImpl *UsingDeclarations,
 const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
+  bool BlockAffected = false;
+  for (const UsingDeclaration& Declaration : *UsingDeclarations) {
+if (Declaration.Line->Affected) {
+  BlockAffected = true;
+  break;
+}
+  }
+  if (!BlockAffected) {
+UsingDeclarations->clear();
+return;
+  }
   SmallVector SortedUsingDeclarations(
   UsingDeclarations->begin(), UsingDeclarations->end());
   std::stable_sort(SortedUsingDeclarations.begin(),
@@ -122,7 +133,7 @@
   tooling::Replacements Fixes;
   SmallVector UsingDeclarations;
   for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
-if (!AnnotatedLines[I]->Affected || AnnotatedLines[I]->InPPDirective ||
+if (AnnotatedLines[I]->InPPDirective ||
 !AnnotatedLines[I]->startsWith(tok::kw_using) ||
 AnnotatedLines[I]->First->Finalized) {
   endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);


Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- unittests/Format/UsingDeclarationsSorterTest.cpp
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+  "\n"
+  "using b;\n" // starts at offset 19
+  "using a;\n"
+  "\n"
+  "using f;\n"
+ 

[PATCH] D39024: [clang-format] Sort whole block of using declarations while partially formatting

2017-10-18 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL316130: [clang-format] Sort whole block of using 
declarations while partially formatting (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D39024

Files:
  cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
  cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp


Index: cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
+++ cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+  "\n"
+  "using b;\n" // starts at offset 19
+  "using a;\n"
+  "\n"
+  "using f;\n"
+  "using e;",
+  {tooling::Range(19, 1)}));
 }
 
 } // end namespace
Index: cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
===
--- cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
+++ cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
@@ -76,6 +76,17 @@
 void endUsingDeclarationBlock(
 SmallVectorImpl *UsingDeclarations,
 const SourceManager &SourceMgr, tooling::Replacements *Fixes) {
+  bool BlockAffected = false;
+  for (const UsingDeclaration& Declaration : *UsingDeclarations) {
+if (Declaration.Line->Affected) {
+  BlockAffected = true;
+  break;
+}
+  }
+  if (!BlockAffected) {
+UsingDeclarations->clear();
+return;
+  }
   SmallVector SortedUsingDeclarations(
   UsingDeclarations->begin(), UsingDeclarations->end());
   std::stable_sort(SortedUsingDeclarations.begin(),
@@ -122,7 +133,7 @@
   tooling::Replacements Fixes;
   SmallVector UsingDeclarations;
   for (size_t I = 0, E = AnnotatedLines.size(); I != E; ++I) {
-if (!AnnotatedLines[I]->Affected || AnnotatedLines[I]->InPPDirective ||
+if (AnnotatedLines[I]->InPPDirective ||
 !AnnotatedLines[I]->startsWith(tok::kw_using) ||
 AnnotatedLines[I]->First->Finalized) {
   endUsingDeclarationBlock(&UsingDeclarations, SourceMgr, &Fixes);


Index: cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
+++ cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -291,13 +291,41 @@
 }
 
 TEST_F(UsingDeclarationsSorterTest, SortsPartialRangeOfUsingDeclarations) {
-  EXPECT_EQ("using b;\n"
-"using a;\n"
+  // Sorts the whole block of using declarations surrounding the range.
+  EXPECT_EQ("using a;\n"
+"using b;\n"
 "using c;",
 sortUsingDeclarations("using b;\n"
   "using c;\n" // starts at offset 10
   "using a;",
   {tooling::Range(10, 15)}));
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using A = b;",
+sortUsingDeclarations("using b;\n"
+  "using c;\n" // starts at offset 10
+  "using a;\n"
+  "using A = b;",
+  {tooling::Range(10, 15)}));
+
+  EXPECT_EQ("using d;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using b;\n"
+"\n"
+"using f;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using c;\n"
+ 

[PATCH] D48098: clang-format-diff: Make it work with python3 too

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

MarcoFalke: do you need someone to submit this for you?


https://reviews.llvm.org/D48098



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


[PATCH] D48827: [clang-format ]Extend IncludeCategories regex documentation

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL337899: [clang-format ]Extend IncludeCategories regex 
documentation (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48827?vs=154176&id=157213#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48827

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/docs/tools/dump_format_style.py
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -1280,6 +1280,10 @@
   Regular expressions denoting the different ``#include`` categories
   used for ordering ``#includes``.
 
+  `POSIX extended
+  `_
+  regular expressions are supported.
+
   These regular expressions are matched against the filename of an include
   (including the <> or "") in order. The value belonging to the first
   matching regular expression is assigned and ``#includes`` are sorted first
@@ -1302,6 +1306,8 @@
 Priority:2
   - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
 Priority:3
+  - Regex:   '<[[:alnum:].]+>'
+Priority:4
   - Regex:   '.*'
 Priority:1
 
Index: cfe/trunk/docs/tools/dump_format_style.py
===
--- cfe/trunk/docs/tools/dump_format_style.py
+++ cfe/trunk/docs/tools/dump_format_style.py
@@ -10,6 +10,7 @@
 
 CLANG_DIR = os.path.join(os.path.dirname(__file__), '../..')
 FORMAT_STYLE_FILE = os.path.join(CLANG_DIR, 'include/clang/Format/Format.h')
+INCLUDE_STYLE_FILE = os.path.join(CLANG_DIR, 
'include/clang/Tooling/Inclusions/IncludeStyle.h')
 DOC_FILE = os.path.join(CLANG_DIR, 'docs/ClangFormatStyleOptions.rst')
 
 
@@ -115,7 +116,7 @@
   for line in header:
 line = line.strip()
 if state == State.BeforeStruct:
-  if line == 'struct FormatStyle {':
+  if line == 'struct FormatStyle {' or line == 'struct IncludeStyle {':
 state = State.InStruct
 elif state == State.InStruct:
   if line.startswith('///'):
@@ -188,6 +189,7 @@
   return options
 
 options = read_options(open(FORMAT_STYLE_FILE))
+options += read_options(open(INCLUDE_STYLE_FILE))
 
 options = sorted(options, key=lambda x: x.name)
 options_text = '\n\n'.join(map(str, options))
Index: cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
===
--- cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
+++ cfe/trunk/include/clang/Tooling/Inclusions/IncludeStyle.h
@@ -67,6 +67,10 @@
   /// Regular expressions denoting the different ``#include`` categories
   /// used for ordering ``#includes``.
   ///
+  /// `POSIX extended
+  /// 
`_
+  /// regular expressions are supported.
+  ///
   /// These regular expressions are matched against the filename of an include
   /// (including the <> or "") in order. The value belonging to the first
   /// matching regular expression is assigned and ``#includes`` are sorted 
first
@@ -87,6 +91,8 @@
   ///   Priority:2
   /// - Regex:   '^(<|"(gtest|gmock|isl|json)/)'
   ///   Priority:3
+  /// - Regex:   '<[[:alnum:].]+>'
+  ///   Priority:4
   /// - Regex:   '.*'
   ///   Priority:1
   /// \endcode
Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1296,7 +1296,7 @@
   /// If ``Never``, lays out Objective-C protocol conformance list items
   /// onto individual lines whenever they go over ``ColumnLimit``.
   ///
-  /// \code
+  /// \code{.objc}
   ///Always (or Auto, if BinPackParameters=true):
   ///@interface c () <
   ///c, c,


Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -1280,6 +1280,10 @@
   Regular expressions denoting the different ``#include`` categories
   used for ordering ``#includes``.
 
+  `POSIX extended
+  `_
+  regular expressions are supported.
+
   These regular expressions are matched against the filename of an include
   (including the <> or "") in order. The value belonging to the first
   matching regular expression is assigned and ``#includes`` 

[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-25 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, acoomans.

This patch makes clang-format indent the subsequent lines created by breaking a
long javadoc annotated line.


Repository:
  rC Clang

https://reviews.llvm.org/D49797

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2058,8 +2058,8 @@
   verifyFormat(
   "/**\n"
   " * @param This is a\n"
-  " * long comment but\n"
-  " * no type\n"
+  " * long comment\n"
+  " * but no type\n"
   " */",
   "/**\n"
   " * @param This is a long comment but no type\n"
Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -3105,6 +3105,87 @@
 // clang-format on
 }
 
+TEST_F(FormatTestComments, IndentsLongJavadocAnnotatedLines) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Java);
+  Style.ColumnLimit = 60;
+  FormatStyle Style20 = getGoogleStyle(FormatStyle::LK_Java);
+  Style20.ColumnLimit = 20;
+  EXPECT_EQ(
+  "/**\n"
+  " * @param x long long long long long long long long long\n"
+  " * long\n"
+  " */\n",
+  format("/**\n"
+ " * @param x long long long long long long long long long long\n"
+ " */\n",
+ Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" * long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ(
+  "/**\n"
+  " * Sentence that\n"
+  " * should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", format(
+  "/**\n"
+  " * Sentence that should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param l1 long1\n"
+" * to break\n"
+" * @param l2 long2\n"
+" * to break\n"
+" */\n",
+format("/**\n"
+   " * @param l1 long1 to break\n"
+   " * @param l2 long2 to break\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break\n"
+" * no reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * no reflow\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break yes\n"
+" * reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * yes reflow\n"
+   " */\n",
+   Style20));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -22,6 +22,11 @@
 #include "llvm/Support/Debug.h"
 
 #define DEBUG_TYPE "format-indenter"
+#define DBG(A) \
+  LLVM_DEBUG({ \
+llvm::errs() << __func__ << ":" << __LINE__ << ":" << #A << " = " << A \
+ << "\n";  \
+  })
 
 namespace clang {
 namespace format {
@@ -1782,6 +1787,7 @@
   if (!DryRun)
 Token->adaptStartOfLine(0, Whitespaces);
 
+  unsigned ContentIndent = 0;
   unsigned Penalty = 0;
   LLVM_DEBUG(llvm::dbgs() << "Breaking protruding token at column "
   << StartColumn << ".\n");
@@ -1903,8 +1909,15 @@
 }
   }
   LLVM_DEBUG(llvm::dbgs() << " 

[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-26 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 157452.
krasimir added a comment.

- Update tests


Repository:
  rC Clang

https://reviews.llvm.org/D49797

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2058,8 +2058,8 @@
   verifyFormat(
   "/**\n"
   " * @param This is a\n"
-  " * long comment but\n"
-  " * no type\n"
+  " * long comment\n"
+  " * but no type\n"
   " */",
   "/**\n"
   " * @param This is a long comment but no type\n"
Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -3105,6 +3105,87 @@
 // clang-format on
 }
 
+TEST_F(FormatTestComments, IndentsLongJavadocAnnotatedLines) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_Java);
+  Style.ColumnLimit = 60;
+  FormatStyle Style20 = getGoogleStyle(FormatStyle::LK_Java);
+  Style20.ColumnLimit = 20;
+  EXPECT_EQ(
+  "/**\n"
+  " * @param x long long long long long long long long long\n"
+  " * long\n"
+  " */\n",
+  format("/**\n"
+ " * @param x long long long long long long long long long long\n"
+ " */\n",
+ Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ("/**\n"
+" * @param x long long long long long long long long long\n"
+" * long long long long long long long long long long\n"
+" * long\n"
+" */\n",
+format("/**\n"
+   " * @param x long long long long long long long long long "
+   "long long long long long long long long long long long\n"
+   " */\n",
+   Style));
+  EXPECT_EQ(
+  "/**\n"
+  " * Sentence that\n"
+  " * should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", format(
+  "/**\n"
+  " * Sentence that should be broken.\n"
+  " * @param short\n"
+  " * keep indentation\n"
+  " */\n", Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param l1 long1\n"
+" * to break\n"
+" * @param l2 long2\n"
+" * to break\n"
+" */\n",
+format("/**\n"
+   " * @param l1 long1 to break\n"
+   " * @param l2 long2 to break\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break\n"
+" * no reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * no reflow\n"
+   " */\n",
+   Style20));
+
+  EXPECT_EQ("/**\n"
+" * @param xx to\n"
+" * break yes\n"
+" * reflow\n"
+" */\n",
+format("/**\n"
+   " * @param xx to break\n"
+   " * yes reflow\n"
+   " */\n",
+   Style20));
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1782,6 +1782,7 @@
   if (!DryRun)
 Token->adaptStartOfLine(0, Whitespaces);
 
+  unsigned ContentIndent = 0;
   unsigned Penalty = 0;
   LLVM_DEBUG(llvm::dbgs() << "Breaking protruding token at column "
   << StartColumn << ".\n");
@@ -1903,8 +1904,15 @@
 }
   }
   LLVM_DEBUG(llvm::dbgs() << "Breaking...\n");
-  ContentStartColumn =
-  Token->getContentStartColumn(LineIndex, /*Break=*/true);
+  // Update the ContentIndent only if the current line was not reflown with
+  // the previous line, since in that case the previous line should still
+  // determine the ContentIndent.
+  if (!Reflow) ContentIndent = Token->getContentIndent(LineIndex);
+  LLVM_DEBUG(llvm::dbgs()
+ << "ContentIndent: " << ContentIndent << "\n");
+  ContentStartColumn = ContentIndent + Token->getContentStartColumn(
+  

[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 157681.
krasimir marked 3 inline comments as done.
krasimir added a comment.

- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D49797

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -191,28 +191,38 @@
 
   // Break a single line long jsdoc comment pragma.
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12 */",
getGoogleJSStyleWithColumns(20)));
 
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12  */",
getGoogleJSStyleWithColumns(20)));
 
+  // FIXME: this overcounts the */ as a continuation of the 12 when breaking.
+  // Related to the FIXME in BreakableBlockComment::getRangeLength.
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line\n"
+" * 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12*/",
getGoogleJSStyleWithColumns(20)));
 
   // Fix a multiline jsdoc comment ending in a comment pragma.
   EXPECT_EQ("/**\n"
 " * line 1\n"
 " * line 2\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** line 1\n"
" * line 2\n"
@@ -2028,10 +2038,10 @@
 
 TEST_F(FormatTestJS, JSDocAnnotations) {
   verifyFormat("/**\n"
-   " * @export {this.is.a.long.path.to.a.Type}\n"
+   " * @exports {this.is.a.long.path.to.a.Type}\n"
" */",
"/**\n"
-   " * @export {this.is.a.long.path.to.a.Type}\n"
+   " * @exports {this.is.a.long.path.to.a.Type}\n"
" */",
getGoogleJSStyleWithColumns(20));
   verifyFormat("/**\n"
@@ -2042,7 +2052,8 @@
" */",
getGoogleJSStyleWithColumns(20));
   verifyFormat("/**\n"
-   " * @param {this.is.a.long.path.to.a.Type}\n"
+   " * @param\n"
+   " * {this.is.a.long.path.to.a.Type}\n"
" */",
"/**\n"
" * @param {this.is.a.long.path.to.a.Type}\n"
@@ -2058,34 +2069,36 @@
   verifyFormat(
   "/**\n"
   " * @param This is a\n"
-  " * long comment but\n"
-  " * no type\n"
+  " * long comment\n"
+  " * but no type\n"
   " */",
   "/**\n"
   " * @param This is a long comment but no type\n"
   " */",
   getGoogleJSStyleWithColumns(20));
-  // Don't break @param line, but reindent it and reflow unrelated lines.
-  verifyFormat("{\n"
-   "  /**\n"
-   "   * long long long\n"
-   "   * long\n"
-   "   * @param {this.is.a.long.path.to.a.Type} a\n"
-   "   * long long long\n"
-   "   * long long\n"
-   "   */\n"
-   "  function f(a) {}\n"
-   "}",
-   "{\n"
-   "/**\n"
-   " * long long long long\n"
-   " * @param {this.is.a.long.path.to.a.Type} a\n"
-   " * long long long long\n"
-   " * long\n"
-   " */\n"
-   "  function f(a) {}\n"
-   "}",
-   getGoogleJSStyleWithColumns(20));
+  // Break and reindent @param line and reflow unrelated lines.
+  EXPECT_EQ("{\n"
+"  /**\n"
+"   * long long long\n"
+"   * long\n"
+"   * @param\n"
+"   * {this.is.a.long.path.to.a.Type}\n"
+"   * a\n"
+"   * long long long\n"
+"   * long long\n"
+"   */\n"
+"  function f(a) {}\n"
+"}",
+format("{\n"
+   "/**\n"
+   " * long long long long\n"
+   " * @param {this.is.a.long.path.to.a.Type} a\n"
+   " * long long long long\n"
+   " * long\n"
+   " */\n"
+   "  function f(a) {}\n"
+   "}",
+   getGoogleJSStyleWithColumns(20)));
 }
 
 TEST_F(FormatTestJS, RequoteStringsS

[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked an inline comment as done.
krasimir added inline comments.



Comment at: lib/Format/BreakableToken.cpp:526
+  0, Content[LineIndex].find_first_of(Blanks));
+  if (FirstWord == "@param")
+return Style.ContinuationIndentWidth;

mprobst wrote:
> Shouldn't this check the set above?
ahahah, sure!



Comment at: unittests/Format/FormatTestComments.cpp:3154
+
+  EXPECT_EQ("/**\n"
+" * @param l1 long1\n"

mprobst wrote:
> do we already have a test that `@param {oh noes this is really long} foo` 
> isn't broken?
As discussed offline, we'll gonna go with breaking that.


Repository:
  rC Clang

https://reviews.llvm.org/D49797



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


[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/Format.cpp:814
+// by qualified identifiers.
+GoogleStyle.CommentPragmas = "(taze:|^/[ 
\t]*<|@see|@exports|@module|@mods)";
 GoogleStyle.MaxEmptyLinesToKeep = 3;

mprobst wrote:
> `@exports` isn't really a thing in JS, it is really `@export`.
> 
> But more generally, where do you get stuff like `@module` from, and what is 
> it supposed to do?
> 
> google3 has `@pintomodule`, `@mods` and `@modName`, but I don't think those 
> need special treatment.
> 
> I think I'd drop everything except the `@see` here.
There were existing tests having these.
I can find a reference to `@exports` and `@module` here: 
http://usejsdoc.org/tags-exports.html.
I think that in general if the annotation is supposed to only have the form 
`@tag some-long-path-separated-machine-readable-identifier`, that should be 
left on a single line.
For `@mods`, I vaguely remember adding that test case while fixing a bug that 
it shouldn't be broken.
Still, happy to remove these and we'll wait to see if anyone complains.


Repository:
  rC Clang

https://reviews.llvm.org/D49797



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


[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 157925.
krasimir added a comment.

- Address comments


Repository:
  rC Clang

https://reviews.llvm.org/D49797

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp

Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -191,28 +191,38 @@
 
   // Break a single line long jsdoc comment pragma.
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12 */",
getGoogleJSStyleWithColumns(20)));
 
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12  */",
getGoogleJSStyleWithColumns(20)));
 
+  // FIXME: this overcounts the */ as a continuation of the 12 when breaking.
+  // Related to the FIXME in BreakableBlockComment::getRangeLength.
   EXPECT_EQ("/**\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns\n"
+" * {string}\n"
+" * jsdoc line\n"
+" * 12\n"
 " */",
 format("/** @returns {string} jsdoc line 12*/",
getGoogleJSStyleWithColumns(20)));
 
   // Fix a multiline jsdoc comment ending in a comment pragma.
   EXPECT_EQ("/**\n"
 " * line 1\n"
 " * line 2\n"
-" * @returns {string} jsdoc line 12\n"
+" * @returns {string}\n"
+" * jsdoc line 12\n"
 " */",
 format("/** line 1\n"
" * line 2\n"
@@ -2028,21 +2038,24 @@
 
 TEST_F(FormatTestJS, JSDocAnnotations) {
   verifyFormat("/**\n"
-   " * @export {this.is.a.long.path.to.a.Type}\n"
+   " * @exports\n"
+   " * {this.is.a.long.path.to.a.Type}\n"
" */",
"/**\n"
-   " * @export {this.is.a.long.path.to.a.Type}\n"
+   " * @exports {this.is.a.long.path.to.a.Type}\n"
" */",
getGoogleJSStyleWithColumns(20));
   verifyFormat("/**\n"
-   " * @mods {this.is.a.long.path.to.a.Type}\n"
+   " * @mods\n"
+   " * {this.is.a.long.path.to.a.Type}\n"
" */",
"/**\n"
" * @mods {this.is.a.long.path.to.a.Type}\n"
" */",
getGoogleJSStyleWithColumns(20));
   verifyFormat("/**\n"
-   " * @param {this.is.a.long.path.to.a.Type}\n"
+   " * @param\n"
+   " * {this.is.a.long.path.to.a.Type}\n"
" */",
"/**\n"
" * @param {this.is.a.long.path.to.a.Type}\n"
@@ -2058,34 +2071,36 @@
   verifyFormat(
   "/**\n"
   " * @param This is a\n"
-  " * long comment but\n"
-  " * no type\n"
+  " * long comment\n"
+  " * but no type\n"
   " */",
   "/**\n"
   " * @param This is a long comment but no type\n"
   " */",
   getGoogleJSStyleWithColumns(20));
-  // Don't break @param line, but reindent it and reflow unrelated lines.
-  verifyFormat("{\n"
-   "  /**\n"
-   "   * long long long\n"
-   "   * long\n"
-   "   * @param {this.is.a.long.path.to.a.Type} a\n"
-   "   * long long long\n"
-   "   * long long\n"
-   "   */\n"
-   "  function f(a) {}\n"
-   "}",
-   "{\n"
-   "/**\n"
-   " * long long long long\n"
-   " * @param {this.is.a.long.path.to.a.Type} a\n"
-   " * long long long long\n"
-   " * long\n"
-   " */\n"
-   "  function f(a) {}\n"
-   "}",
-   getGoogleJSStyleWithColumns(20));
+  // Break and reindent @param line and reflow unrelated lines.
+  EXPECT_EQ("{\n"
+"  /**\n"
+"   * long long long\n"
+"   * long\n"
+"   * @param\n"
+"   * {this.is.a.long.path.to.a.Type}\n"
+"   * a\n"
+"   * long long long\n"
+"   * long long\n"
+"   */\n"
+"  function f(a) {}\n"
+"}",
+format("{\n"
+   "/**\n"
+   " * long long long long\n"
+   " * @param {this.is.a.long.path.to.a.Type} a\n"
+   " * long long long long\n"
+

[PATCH] D49797: [clang-format] Indent after breaking Javadoc annotated line

2018-07-30 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338232: [clang-format] Indent after breaking Javadoc 
annotated line (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D49797

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp
  cfe/trunk/lib/Format/BreakableToken.h
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/unittests/Format/FormatTestComments.cpp
  cfe/trunk/unittests/Format/FormatTestJS.cpp

Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1809,6 +1809,7 @@
   if (!DryRun)
 Token->adaptStartOfLine(0, Whitespaces);
 
+  unsigned ContentIndent = 0;
   unsigned Penalty = 0;
   LLVM_DEBUG(llvm::dbgs() << "Breaking protruding token at column "
   << StartColumn << ".\n");
@@ -1930,11 +1931,28 @@
 }
   }
   LLVM_DEBUG(llvm::dbgs() << "Breaking...\n");
-  ContentStartColumn =
-  Token->getContentStartColumn(LineIndex, /*Break=*/true);
+  // Update the ContentIndent only if the current line was not reflown with
+  // the previous line, since in that case the previous line should still
+  // determine the ContentIndent. Also never intent the last line.
+  if (!Reflow)
+ContentIndent = Token->getContentIndent(LineIndex);
+  LLVM_DEBUG(llvm::dbgs()
+ << "ContentIndent: " << ContentIndent << "\n");
+  ContentStartColumn = ContentIndent + Token->getContentStartColumn(
+   LineIndex, /*Break=*/true);
+
   unsigned NewRemainingTokenColumns = Token->getRemainingLength(
   LineIndex, TailOffset + Split.first + Split.second,
   ContentStartColumn);
+  if (NewRemainingTokenColumns == 0) {
+// No content to indent.
+ContentIndent = 0;
+ContentStartColumn =
+Token->getContentStartColumn(LineIndex, /*Break=*/true);
+NewRemainingTokenColumns = Token->getRemainingLength(
+LineIndex, TailOffset + Split.first + Split.second,
+ContentStartColumn);
+  }
 
   // When breaking before a tab character, it may be moved by a few columns,
   // but will still be expanded to the next tab stop, so we don't save any
@@ -1948,7 +1966,8 @@
   LLVM_DEBUG(llvm::dbgs() << "Breaking at: " << TailOffset + Split.first
   << ", " << Split.second << "\n");
   if (!DryRun)
-Token->insertBreak(LineIndex, TailOffset, Split, Whitespaces);
+Token->insertBreak(LineIndex, TailOffset, Split, ContentIndent,
+   Whitespaces);
 
   Penalty += NewBreakPenalty;
   TailOffset += Split.first + Split.second;
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -808,10 +808,9 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
 GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
 GoogleStyle.BreakBeforeTernaryOperators = false;
-// taze:, triple slash directives (`/// <...`), @tag followed by { for a lot
-// of JSDoc tags, and @see, which is commonly followed by overlong URLs.
-GoogleStyle.CommentPragmas =
-"(taze:|^/[ \t]*<|(@[A-Za-z_0-9-]+[ \\t]*{)|@see)";
+// taze:, triple slash directives (`/// <...`), @see, which is commonly
+// followed by overlong URLs.
+GoogleStyle.CommentPragmas = "(taze:|^/[ \t]*<|@see)";
 GoogleStyle.MaxEmptyLinesToKeep = 3;
 GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
 GoogleStyle.SpacesInContainerLiterals = false;
Index: cfe/trunk/lib/Format/BreakableToken.h
===
--- cfe/trunk/lib/Format/BreakableToken.h
+++ cfe/trunk/lib/Format/BreakableToken.h
@@ -21,6 +21,7 @@
 #include "Encoding.h"
 #include "TokenAnnotator.h"
 #include "WhitespaceManager.h"
+#include "llvm/ADT/StringSet.h"
 #include "llvm/Support/Regex.h"
 #include 
 
@@ -135,6 +136,19 @@
   virtual unsigned getContentStartColumn(unsigned LineIndex,
  bool Break) const = 0;
 
+  /// Returns additional content indent required for the second line after the
+  /// content at line \p LineIndex is broken.
+  ///
+  /// For example, Javadoc @param annotations require and indent of 4 spaces and
+  /// in this example getContentIndex(1) returns 4.
+  /// /**
+  ///  * @param loong line
+  ///  * continuation
+  ///  */
+  virtual unsigned getContentIndent(unsigned LineIndex) const {
+return 0;
+  }
+
   /// Returns a range (offset, length) at which to break the line at

[PATCH] D50132: [clang-format] Add some text proto functions to Google style

2018-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir added a reviewer: djasper.
Herald added subscribers: cfe-commits, acoomans.

Adds 2 functions taking a text proto argument.


Repository:
  rC Clang

https://reviews.llvm.org/D50132

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -777,9 +777,11 @@
   {
   "EqualsProto",
   "EquivToProto",
+  "PARSE_PARTIAL_TEXT_PROTO",
   "PARSE_TEST_PROTO",
   "PARSE_TEXT_PROTO",
   "ParseTextOrDie",
+  "ParseTextProtoOrDie",
   },
   /*CanonicalDelimiter=*/"",
   /*BasedOnStyle=*/"google",


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -777,9 +777,11 @@
   {
   "EqualsProto",
   "EquivToProto",
+  "PARSE_PARTIAL_TEXT_PROTO",
   "PARSE_TEST_PROTO",
   "PARSE_TEXT_PROTO",
   "ParseTextOrDie",
+  "ParseTextProtoOrDie",
   },
   /*CanonicalDelimiter=*/"",
   /*BasedOnStyle=*/"google",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50138: [clang-format] Add @private to the list of jsdoc annotations

2018-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir added a reviewer: mprobst.
Herald added subscribers: cfe-commits, acoomans.

Repository:
  rC Clang

https://reviews.llvm.org/D50138

Files:
  lib/Format/BreakableToken.cpp


Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -514,7 +514,7 @@
 const llvm::StringSet<>
 BreakableBlockComment::ContentIndentingJavadocAnnotations = {
 "@param", "@return", "@returns", "@throws",  "@type", "@template",
-"@see",   "@deprecated", "@define",  "@exports", "@mods",
+"@see",   "@deprecated", "@define",  "@exports", "@mods", "@private",
 };
 
 unsigned BreakableBlockComment::getContentIndent(unsigned LineIndex) const {


Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -514,7 +514,7 @@
 const llvm::StringSet<>
 BreakableBlockComment::ContentIndentingJavadocAnnotations = {
 "@param", "@return", "@returns", "@throws",  "@type", "@template",
-"@see",   "@deprecated", "@define",  "@exports", "@mods",
+"@see",   "@deprecated", "@define",  "@exports", "@mods", "@private",
 };
 
 unsigned BreakableBlockComment::getContentIndent(unsigned LineIndex) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50078: clang-format: support aligned nested conditionals formatting

2018-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Could you clarify how each piece is supposed to be aligned in these examples?
This is what makes me happy:

  // column  limit V
  int a = condition1 ? result1
: conditio2 ? result2
: loocondition 
  ? result2
  : dition3 ? resul3
: resul4;



  // column  limit V
  int a = condition1 
  ? loresult1
  : conditio2 ? result2
  : result4;

When BreakBeforeTernaryOperators is false:

  int a = condition1 ? result1 :
  conditio2 ? result2 :
  ditino3 ? resul3 :
result4;


Repository:
  rC Clang

https://reviews.llvm.org/D50078



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


[PATCH] D50138: [clang-format] Add @private to the list of jsdoc annotations

2018-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338519: [clang-format] Add @private to the list of jsdoc 
annotations (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50138

Files:
  cfe/trunk/lib/Format/BreakableToken.cpp


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -514,7 +514,7 @@
 const llvm::StringSet<>
 BreakableBlockComment::ContentIndentingJavadocAnnotations = {
 "@param", "@return", "@returns", "@throws",  "@type", "@template",
-"@see",   "@deprecated", "@define",  "@exports", "@mods",
+"@see",   "@deprecated", "@define",  "@exports", "@mods", "@private",
 };
 
 unsigned BreakableBlockComment::getContentIndent(unsigned LineIndex) const {


Index: cfe/trunk/lib/Format/BreakableToken.cpp
===
--- cfe/trunk/lib/Format/BreakableToken.cpp
+++ cfe/trunk/lib/Format/BreakableToken.cpp
@@ -514,7 +514,7 @@
 const llvm::StringSet<>
 BreakableBlockComment::ContentIndentingJavadocAnnotations = {
 "@param", "@return", "@returns", "@throws",  "@type", "@template",
-"@see",   "@deprecated", "@define",  "@exports", "@mods",
+"@see",   "@deprecated", "@define",  "@exports", "@mods", "@private",
 };
 
 unsigned BreakableBlockComment::getContentIndent(unsigned LineIndex) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50132: [clang-format] Add some text proto functions to Google style

2018-08-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338524: [clang-format] Add some text proto functions to 
Google style (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D50132

Files:
  cfe/trunk/lib/Format/Format.cpp


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -777,9 +777,11 @@
   {
   "EqualsProto",
   "EquivToProto",
+  "PARSE_PARTIAL_TEXT_PROTO",
   "PARSE_TEST_PROTO",
   "PARSE_TEXT_PROTO",
   "ParseTextOrDie",
+  "ParseTextProtoOrDie",
   },
   /*CanonicalDelimiter=*/"",
   /*BasedOnStyle=*/"google",


Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -777,9 +777,11 @@
   {
   "EqualsProto",
   "EquivToProto",
+  "PARSE_PARTIAL_TEXT_PROTO",
   "PARSE_TEST_PROTO",
   "PARSE_TEXT_PROTO",
   "ParseTextOrDie",
+  "ParseTextProtoOrDie",
   },
   /*CanonicalDelimiter=*/"",
   /*BasedOnStyle=*/"google",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D50177: clang-format: fix a crash in comment wraps.

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

Great! Thank you!


Repository:
  rC Clang

https://reviews.llvm.org/D50177



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


[PATCH] D50230: clang-format: [JS] don't break comments before any '{'

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

Great! Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D50230



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


[PATCH] D48098: clang-format-diff: Make it work with python3 too

2018-08-03 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL338839: clang-format-diff: Make it work with python3 too 
(authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48098?vs=152867&id=158961#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48098

Files:
  cfe/trunk/tools/clang-format/clang-format-diff.py


Index: cfe/trunk/tools/clang-format/clang-format-diff.py
===
--- cfe/trunk/tools/clang-format/clang-format-diff.py
+++ cfe/trunk/tools/clang-format/clang-format-diff.py
@@ -25,10 +25,12 @@
 import argparse
 import difflib
 import re
-import string
 import subprocess
-import StringIO
 import sys
+try:
+  from StringIO import StringIO
+except ImportError:
+   from io import StringIO
 
 
 def main():
@@ -84,36 +86,39 @@
 line_count = int(match.group(3))
   if line_count == 0:
 continue
-  end_line = start_line + line_count - 1;
+  end_line = start_line + line_count - 1
   lines_by_file.setdefault(filename, []).extend(
   ['-lines', str(start_line) + ':' + str(end_line)])
 
   # Reformat files containing changes in place.
-  for filename, lines in lines_by_file.iteritems():
+  for filename, lines in lines_by_file.items():
 if args.i and args.verbose:
-  print 'Formatting', filename
+  print('Formatting {}'.format(filename))
 command = [args.binary, filename]
 if args.i:
   command.append('-i')
 if args.sort_includes:
   command.append('-sort-includes')
 command.extend(lines)
 if args.style:
   command.extend(['-style', args.style])
-p = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=None, stdin=subprocess.PIPE)
+p = subprocess.Popen(command,
+ stdout=subprocess.PIPE,
+ stderr=None,
+ stdin=subprocess.PIPE,
+ universal_newlines=True)
 stdout, stderr = p.communicate()
 if p.returncode != 0:
-  sys.exit(p.returncode);
+  sys.exit(p.returncode)
 
 if not args.i:
   with open(filename) as f:
 code = f.readlines()
-  formatted_code = StringIO.StringIO(stdout).readlines()
+  formatted_code = StringIO(stdout).readlines()
   diff = difflib.unified_diff(code, formatted_code,
   filename, filename,
   '(before formatting)', '(after formatting)')
-  diff_string = string.join(diff, '')
+  diff_string = ''.join(diff)
   if len(diff_string) > 0:
 sys.stdout.write(diff_string)
 


Index: cfe/trunk/tools/clang-format/clang-format-diff.py
===
--- cfe/trunk/tools/clang-format/clang-format-diff.py
+++ cfe/trunk/tools/clang-format/clang-format-diff.py
@@ -25,10 +25,12 @@
 import argparse
 import difflib
 import re
-import string
 import subprocess
-import StringIO
 import sys
+try:
+  from StringIO import StringIO
+except ImportError:
+   from io import StringIO
 
 
 def main():
@@ -84,36 +86,39 @@
 line_count = int(match.group(3))
   if line_count == 0:
 continue
-  end_line = start_line + line_count - 1;
+  end_line = start_line + line_count - 1
   lines_by_file.setdefault(filename, []).extend(
   ['-lines', str(start_line) + ':' + str(end_line)])
 
   # Reformat files containing changes in place.
-  for filename, lines in lines_by_file.iteritems():
+  for filename, lines in lines_by_file.items():
 if args.i and args.verbose:
-  print 'Formatting', filename
+  print('Formatting {}'.format(filename))
 command = [args.binary, filename]
 if args.i:
   command.append('-i')
 if args.sort_includes:
   command.append('-sort-includes')
 command.extend(lines)
 if args.style:
   command.extend(['-style', args.style])
-p = subprocess.Popen(command, stdout=subprocess.PIPE,
- stderr=None, stdin=subprocess.PIPE)
+p = subprocess.Popen(command,
+ stdout=subprocess.PIPE,
+ stderr=None,
+ stdin=subprocess.PIPE,
+ universal_newlines=True)
 stdout, stderr = p.communicate()
 if p.returncode != 0:
-  sys.exit(p.returncode);
+  sys.exit(p.returncode)
 
 if not args.i:
   with open(filename) as f:
 code = f.readlines()
-  formatted_code = StringIO.StringIO(stdout).readlines()
+  formatted_code = StringIO(stdout).readlines()
   diff = difflib.unified_diff(code, formatted_code,
   filename, filename,
   '(before formatting)', '(after formatting)')
-  diff_string = string.join(diff, '')
+  diff_string = ''.join(diff)
   if len(diff_st

[PATCH] D42727: [clang-format] Adds space around angle brackets in text protos

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 132964.
krasimir marked an inline comment as done.
krasimir added a comment.

- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D42727

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -143,21 +143,21 @@
   // Single-line tests
   verifyFormat("msg_field <>");
   verifyFormat("msg_field: <>");
-  verifyFormat("msg_field ");
-  verifyFormat("msg_field: ");
-  verifyFormat("msg_field >");
-  verifyFormat("msg_field >>");
-  verifyFormat("msg_field: >>");
-  verifyFormat("msg_field ");
-  verifyFormat("msg_field , field_c: OK>");
-  verifyFormat("msg_field >");
-  verifyFormat("msg_field: ");
-  verifyFormat("msg_field: , field_c: OK>");
-  verifyFormat("msg_field: >");
-  verifyFormat("field_a: \"OK\", msg_field: , field_c: {}");
-  verifyFormat("field_a , msg_field: , field_c <>");
-  verifyFormat("field_a  msg_field:  field_c <>");
-  verifyFormat("field >, field <>> field: ");
+  verifyFormat("msg_field < field_a: OK >");
+  verifyFormat("msg_field: < field_a: 123 >");
+  verifyFormat("msg_field < field_a <> >");
+  verifyFormat("msg_field < field_a < field_b <> > >");
+  verifyFormat("msg_field: < field_a < field_b: <> > >");
+  verifyFormat("msg_field < field_a: OK, field_b: \"OK\" >");
+  verifyFormat("msg_field < field_a: OK field_b: <>, field_c: OK >");
+  verifyFormat("msg_field < field_a { field_b: 1 }, field_c: < f_d: 2 > >");
+  verifyFormat("msg_field: < field_a: OK, field_b: \"OK\" >");
+  verifyFormat("msg_field: < field_a: OK field_b: <>, field_c: OK >");
+  verifyFormat("msg_field: < field_a { field_b: 1 }, field_c: < fd_d: 2 > >");
+  verifyFormat("field_a: \"OK\", msg_field: < field_b: 123 >, field_c: {}");
+  verifyFormat("field_a < field_b: 1 >, msg_fid: < fiel_b: 123 >, field_c <>");
+  verifyFormat("field_a < field_b: 1 > msg_fied: < field_b: 123 > field_c <>");
+  verifyFormat("field < field < field: <> >, field <> > field: < field: 1 >");
 
   // Multiple lines tests
   verifyFormat("msg_field <\n"
@@ -170,31 +170,31 @@
 
   verifyFormat("msg_field: <>\n"
"field_c: \"OK\",\n"
-   "msg_field: \n"
+   "msg_field: < field_d: 123 >\n"
"field_e: OK\n"
-   "msg_field: ");
+   "msg_field: < field_d: 12 >");
 
   verifyFormat("field_a: OK,\n"
-   "field_b ,\n"
-   "field_d: <12.5>,\n"
+   "field_b < field_c: OK >,\n"
+   "field_d: < 12.5 >,\n"
"field_e: OK");
 
   verifyFormat("field_a: OK\n"
-   "field_b \n"
-   "field_d: <12.5>\n"
+   "field_b < field_c: OK >\n"
+   "field_d: < 12.5 >\n"
"field_e: OKOKOK");
 
   verifyFormat("msg_field <\n"
"  field_a: OK,\n"
-   "  field_b ,\n"
-   "  field_d: <12.5>,\n"
+   "  field_b < field_c: OK >,\n"
+   "  field_d: < 12.5 >,\n"
"  field_e: OK\n"
">");
 
   verifyFormat("msg_field <\n"
-   "  field_a: ,\n"
-   "  field_b ,\n"
-   "  field_d: <12.5>,\n"
+   "  field_a: < field: OK >,\n"
+   "  field_b < field_c: OK >,\n"
+   "  field_d: < 12.5 >,\n"
"  field_e: OK,\n"
">");
 
@@ -208,19 +208,19 @@
 
   verifyFormat("field_a {\n"
"  field_d: ok\n"
-   "  field_b: \n"
+   "  field_b: < field_c: 1 >\n"
"  field_d: ok\n"
"  field_d: ok\n"
"}");
 
   verifyFormat("field_a: {\n"
"  field_d: ok\n"
-   "  field_b: \n"
+   "  field_b: < field_c: 1 >\n"
"  field_d: ok\n"
"  field_d: ok\n"
"}");
 
-  verifyFormat("field_a: >\n"
+  verifyFormat("field_a: < f1: 1, f2: <> >\n"
"field_b <\n"
"  field_b1: <>\n"
"  field_b2: ok,\n"
@@ -231,63 +231,63 @@
"  >\n"
"  field {\n"
"field_x <>  // Comment\n"
-   "field_y: \n"
+   "field_y: < field_z: 1 >\n"
"field_w: ok\n"
"msg_field: <\n"
"  field: <>\n"
-   "  field: \n"
-   "  field: \n"
-   "  field: \n"
-   "  field: \n"
+   "  field: < field: 1 >\n"
+   "  field: < field: 2 >\n"
+   "  field: < field

[PATCH] D42727: [clang-format] Adds space around angle brackets in text protos

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324337: [clang-format] Adds space around angle brackets in 
text protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42727

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/FormatToken.h
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestRawStrings.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/lib/Format/FormatToken.h
===
--- cfe/trunk/lib/Format/FormatToken.h
+++ cfe/trunk/lib/Format/FormatToken.h
@@ -348,17 +348,23 @@
 Next->isObjCAtKeyword(tok::objc_private));
   }
 
-  /// \brief Returns whether \p Tok is ([{ or a template opening <.
+  /// \brief Returns whether \p Tok is ([{ or an opening < of a template or in
+  /// protos.
   bool opensScope() const {
 if (is(TT_TemplateString) && TokenText.endswith("${"))
   return true;
+if (is(TT_DictLiteral) && is(tok::less))
+  return true;
 return isOneOf(tok::l_paren, tok::l_brace, tok::l_square,
TT_TemplateOpener);
   }
-  /// \brief Returns whether \p Tok is )]} or a template closing >.
+  /// \brief Returns whether \p Tok is )]} or a closing > of a template or in
+  /// protos.
   bool closesScope() const {
 if (is(TT_TemplateString) && TokenText.startswith("}"))
   return true;
+if (is(TT_DictLiteral) && is(tok::greater))
+  return true;
 return isOneOf(tok::r_paren, tok::r_brace, tok::r_square,
TT_TemplateCloser);
   }
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -79,7 +79,17 @@
   if (CurrentToken->is(tok::greater)) {
 Left->MatchingParen = CurrentToken;
 CurrentToken->MatchingParen = Left;
-CurrentToken->Type = TT_TemplateCloser;
+// In TT_Proto, we must distignuish between:
+//   map
+//   msg < item: data >
+//   msg: < item: data >
+// In TT_TextProto, map does not occur.
+if (Style.Language == FormatStyle::LK_TextProto ||
+(Style.Language == FormatStyle::LK_Proto && Left->Previous &&
+ Left->Previous->isOneOf(TT_SelectorName, TT_DictLiteral)))
+  CurrentToken->Type = TT_DictLiteral;
+else
+  CurrentToken->Type = TT_TemplateCloser;
 next();
 return true;
   }
@@ -670,7 +680,15 @@
 case tok::less:
   if (parseAngle()) {
 Tok->Type = TT_TemplateOpener;
-if (Style.Language == FormatStyle::LK_TextProto) {
+// In TT_Proto, we must distignuish between:
+//   map
+//   msg < item: data >
+//   msg: < item: data >
+// In TT_TextProto, map does not occur.
+if (Style.Language == FormatStyle::LK_TextProto ||
+(Style.Language == FormatStyle::LK_Proto && Tok->Previous &&
+ Tok->Previous->isOneOf(TT_SelectorName, TT_DictLiteral))) {
+  Tok->Type = TT_DictLiteral;
   FormatToken *Previous = Tok->getPreviousNonComment();
   if (Previous && Previous->Type != TT_DictLiteral)
 Previous->Type = TT_SelectorName;
@@ -691,7 +709,8 @@
 return false;
   break;
 case tok::greater:
-  Tok->Type = TT_BinaryOperator;
+  if (Style.Language != FormatStyle::LK_TextProto)
+Tok->Type = TT_BinaryOperator;
   break;
 case tok::kw_operator:
   while (CurrentToken &&
@@ -1157,7 +1176,9 @@
 Current.Type = TT_ConditionalExpr;
   }
 } else if (Current.isBinaryOperator() &&
-   (!Current.Previous || Current.Previous->isNot(tok::l_square))) {
+   (!Current.Previous || Current.Previous->isNot(tok::l_square)) &&
+   (!Current.is(tok::greater) &&
+Style.Language != FormatStyle::LK_TextProto)) {
   Current.Type = TT_BinaryOperator;
 } else if (Current.is(tok::comment)) {
   if (Current.TokenText.startswith("/*")) {
@@ -2226,8 +2247,17 @@
 return !Left.is(TT_ObjCMethodExpr);
   if (Left.is(tok::coloncolon))
 return false;
-  if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less))
+  if (Left.is(tok::less) || Right.isOneOf(tok::greater, tok::less)) {
+if (Style.Language == FormatStyle::LK_TextProto ||
+(Style.Language == FormatStyle::LK_Proto &&
+ (Left.is(TT_DictLiteral) || Right.is(TT_DictLiteral {
+  // Format empty list as `<>`.
+  if (Left.is(tok::less) && Right.is(tok::greater))
+return false;
+  return !Style.Cpp11BracedListStyle;
+}
 return false;
+  }
   if (Right.is(tok::ellipsis))
 return Left.Tok.isL

[PATCH] D42901: Test commit - fixing a comment.

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Try committing it now!


Repository:
  rC Clang

https://reviews.llvm.org/D42901



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


[PATCH] D42957: [clang-format] Do not break before long string literals in protos

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch is a follow-up to r323319 (which disables string literal breaking for
text protos) and it disables breaking before long string literals.

For example this:

  key: "long string literal"

used to get broken into:

  key:
  "long string literal"

While at it, I also enabled it for LK_Proto and fixed a bug in the mustBreak 
code.


Repository:
  rC Clang

https://reviews.llvm.org/D42957

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -306,5 +306,12 @@
   "  }\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "foo: {\n"
+  "  text: 
\"aaasaa\"\n"
+  "}");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -412,5 +412,14 @@
"}");
 }
 
+TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "option (MyProto.options) = {\n"
+  "  foo: {\n"
+  "text: 
\"aaas\"\n"
+  "  }\n"
+  "}");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2820,11 +2820,17 @@
   if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
   Left.isNot(TT_SelectorName))
 return true;
+
   if (Right.is(tok::colon) &&
   !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))
 return false;
-  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr))
+  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Right.isStringLiteral())
+  return false;
 return true;
+  }
   if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
 Right.Next->is(TT_ObjCMethodExpr)))
 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -686,11 +686,6 @@
 FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);
 GoogleStyle.Language = FormatStyle::LK_TextProto;
 
-// Text protos are currently mostly formatted inside C++ raw string 
literals
-// and often the current breaking behavior of string literals is not
-// beneficial there. Investigate turning this on once proper string reflow
-// has been implemented.
-GoogleStyle.BreakStringLiterals = false;
 return GoogleStyle;
   }
 
@@ -761,6 +756,11 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
+// Text protos are currently mostly formatted inside C++ raw string 
literals
+// and often the current breaking behavior of string literals is not
+// beneficial there. Investigate turning this on once proper string reflow
+// has been implemented.
+GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
   }
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1988,7 +1988,7 @@
   if (Current.getNextNonComment() &&
   Current.getNextNonComment()->isStringLiteral())
 return true; // Implicit concatenation.
-  if (Style.ColumnLimit != 0 &&
+  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&
   State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
   Style.ColumnLimit)
 return true; // String will be split.


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -306,5 +306,12 @@
   "  }\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "foo: {\n"
+  "  text: \"a

[PATCH] D42957: [clang-format] Do not break before long string literals in protos

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 132978.
krasimir added a comment.

- Update comment


Repository:
  rC Clang

https://reviews.llvm.org/D42957

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -306,5 +306,12 @@
   "  }\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "foo: {\n"
+  "  text: \"aaasaa\"\n"
+  "}");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -412,5 +412,14 @@
"}");
 }
 
+TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "option (MyProto.options) = {\n"
+  "  foo: {\n"
+  "text: \"aaas\"\n"
+  "  }\n"
+  "}");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2820,11 +2820,17 @@
   if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
   Left.isNot(TT_SelectorName))
 return true;
+
   if (Right.is(tok::colon) &&
   !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))
 return false;
-  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr))
+  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Right.isStringLiteral())
+  return false;
 return true;
+  }
   if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
 Right.Next->is(TT_ObjCMethodExpr)))
 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -686,11 +686,6 @@
 FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);
 GoogleStyle.Language = FormatStyle::LK_TextProto;
 
-// Text protos are currently mostly formatted inside C++ raw string literals
-// and often the current breaking behavior of string literals is not
-// beneficial there. Investigate turning this on once proper string reflow
-// has been implemented.
-GoogleStyle.BreakStringLiterals = false;
 return GoogleStyle;
   }
 
@@ -761,6 +756,12 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
+// This affects protocol buffer options specifications and text protos.
+// Text protos are currently mostly formatted inside C++ raw string literals
+// and often the current breaking behavior of string literals is not
+// beneficial there. Investigate turning this on once proper string reflow
+// has been implemented.
+GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
   }
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1988,7 +1988,7 @@
   if (Current.getNextNonComment() &&
   Current.getNextNonComment()->isStringLiteral())
 return true; // Implicit concatenation.
-  if (Style.ColumnLimit != 0 &&
+  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&
   State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
   Style.ColumnLimit)
 return true; // String will be split.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42650: [clang-format] New format param ObjCBinPackProtocolList

2018-02-06 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I don't understand why do we introduce an enum option if we are keeping the 
default behavior for Google style. IMO we should have a single behavior for any 
style and enforce it.


Repository:
  rC Clang

https://reviews.llvm.org/D42650



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


[PATCH] D42787: clang-format: do not add extra indent when wrapping last parameter

2018-02-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

We could adapt the single-argument version instead, turning:

  foo(bb +
  c);

into:

  foo(bb +
  c);


Repository:
  rC Clang

https://reviews.llvm.org/D42787



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


[PATCH] D42957: [clang-format] Do not break before long string literals in protos

2018-02-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324591: [clang-format] Do not break before long string 
literals in protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D42957

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -306,5 +306,12 @@
   "  }\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "foo: {\n"
+  "  text: \"aaasaa\"\n"
+  "}");
+}
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -412,5 +412,14 @@
"}");
 }
 
+TEST_F(FormatTestProto, KeepsLongStringLiteralsOnSameLine) {
+  verifyFormat(
+  "option (MyProto.options) = {\n"
+  "  foo: {\n"
+  "text: \"aaas\"\n"
+  "  }\n"
+  "}");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2830,11 +2830,17 @@
   if (Right.is(TT_ObjCMethodExpr) && !Right.is(tok::r_square) &&
   Left.isNot(TT_SelectorName))
 return true;
+
   if (Right.is(tok::colon) &&
   !Right.isOneOf(TT_CtorInitializerColon, TT_InlineASMColon))
 return false;
-  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr))
+  if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+if ((Style.Language == FormatStyle::LK_Proto ||
+ Style.Language == FormatStyle::LK_TextProto) &&
+Right.isStringLiteral())
+  return false;
 return true;
+  }
   if (Right.is(TT_SelectorName) || (Right.is(tok::identifier) && Right.Next &&
 Right.Next->is(TT_ObjCMethodExpr)))
 return Left.isNot(tok::period); // FIXME: Properly parse ObjC calls.
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -1992,7 +1992,7 @@
   if (Current.getNextNonComment() &&
   Current.getNextNonComment()->isStringLiteral())
 return true; // Implicit concatenation.
-  if (Style.ColumnLimit != 0 &&
+  if (Style.ColumnLimit != 0 && Style.BreakStringLiterals &&
   State.Column + Current.ColumnWidth + Current.UnbreakableTailLength >
   Style.ColumnLimit)
 return true; // String will be split.
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -686,11 +686,6 @@
 FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_Proto);
 GoogleStyle.Language = FormatStyle::LK_TextProto;
 
-// Text protos are currently mostly formatted inside C++ raw string literals
-// and often the current breaking behavior of string literals is not
-// beneficial there. Investigate turning this on once proper string reflow
-// has been implemented.
-GoogleStyle.BreakStringLiterals = false;
 return GoogleStyle;
   }
 
@@ -762,6 +757,12 @@
 GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
 GoogleStyle.SpacesInContainerLiterals = false;
 GoogleStyle.Cpp11BracedListStyle = false;
+// This affects protocol buffer options specifications and text protos.
+// Text protos are currently mostly formatted inside C++ raw string literals
+// and often the current breaking behavior of string literals is not
+// beneficial there. Investigate turning this on once proper string reflow
+// has been implemented.
+GoogleStyle.BreakStringLiterals = false;
   } else if (Language == FormatStyle::LK_ObjC) {
 GoogleStyle.ColumnLimit = 100;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43121: clang-format: keep ObjC colon alignment with short object name

2018-02-09 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTestObjC.cpp:700
+   "withObjectOnMainThread:nil\n"
+   " waitUntilDone:false];");
+  }

Could you add an instance where the first one is the longest and is wrapped?


Repository:
  rC Clang

https://reviews.llvm.org/D43121



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


[PATCH] D43180: [clang-format] Support text proto extensions

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This adds support for text proto extensions, like:

  msg {
[type.type/ext] {
  key: value
}
  }


Repository:
  rC Clang

https://reviews.llvm.org/D43180

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,40 @@
   "  text: \"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, FormatsExtensions) {
+  verifyFormat("[type] { key: value }");
+  verifyFormat("[type] {\n"
+   "  key: value\n"
+   "}");
+  verifyFormat("[type.type] { key: value }");
+  verifyFormat("[type.type] < key: value >");
+  verifyFormat("[type.type/type.type] { key: value }");
+  verifyFormat("msg {\n"
+   "  [type.type] { key: value }\n"
+   "}");
+  verifyFormat("msg {\n"
+   "  [type.type] {\n"
+   "keyy: value\n"
+   "  }\n"
+   "}");
+  verifyFormat("key: value\n"
+   "[a.b] { key: value }");
+  verifyFormat("msg: <\n"
+   "  key: value\n"
+   "  [a.b.c/d.e]: < key: value >\n"
+   "  [f.g]: <\n"
+   "key: valuee\n"
+   "key: {}\n"
+   "  >\n"
+   "  key {}\n"
+   "  [h.i.j] < key: value >\n"
+   "  [a]: {\n"
+   "[b.c]: {}\n"
+   "[d] <>\n"
+   "[e/f]: 1\n"
+   "  }\n"
+   ">");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -421,5 +421,16 @@
   "}");
 }
 
+TEST_F(FormatTestProto, FormatsOptionsExtensions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  msg_field: { field_d: 123 }\n"
+   "  [ext.t/u] { key: value }\n"
+   "  key: value\n"
+   "  [t.u/v] <\n"
+   "[ext] { key: value }\n"
+   "  >\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -368,12 +368,35 @@
  Parent->is(TT_TemplateCloser)) {
 Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
- (!CppArrayTemplates && Parent &&
-  Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
-  tok::comma, tok::l_paren, tok::l_square,
-  tok::question, tok::colon, tok::kw_return,
-  // Should only be relevant to JavaScript:
-  tok::kw_default))) {
+ Style.Language == FormatStyle::LK_TextProto) {
+// Square braces in LK_Proto can either be message field attributes:
+//
+// optional Aaa aaa = 1 [
+//   (aaa) = aaa
+// ];
+//
+// or text proto extensions (in options):
+//
+// option (Aaa.options) = {
+//   [type.type/type] {
+// key: value
+//   }
+// }
+//
+// In the first case we want to spread the contents inside the square
+// braces; in the second we want to keep them inline.
+Left->Type = TT_ArrayInitializerLSquare;
+if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::equal)) {
+  Left->Type = TT_ProtoExtensionLSquare;
+  BindingIncrease = 10;
+}
+  } else if (!CppArrayTemplates && Parent &&
+ Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
+ tok::comma, tok::l_paren, tok::l_square,
+ tok::question, tok::colon, tok::kw_return,
+ // Should only be relevant to JavaScript:
+ tok::kw_default)) {
 Left->Type = TT_ArrayInitializerLSquare;
   } else {
 BindingIncrease = 10;
@@ -2396,6 +2419,12 @@
   return true;
 if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
   return true;
+// Slashes occur in 

[PATCH] D43194: [clang-format] Fix comment indentation in text protos

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch fixes a bug where the comment indent of comments in text protos gets 
messed up because by default paren states get created with AlignColons = true 
(which makes snese for ObjC).


Repository:
  rC Clang

https://reviews.llvm.org/D43194

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: 
\"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: \"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43194: [clang-format] Fix comment indentation in text protos

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324896: [clang-format] Fix comment indentation in text 
protos (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43194?vs=133863&id=133866#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43194

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: 
\"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: \"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43194: [clang-format] Fix comment indentation in text protos

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324896: [clang-format] Fix comment indentation in text 
protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43194

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: 
\"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -200,6 +200,7 @@
 // global scope.
 State.Stack.back().AvoidBinPacking = true;
 State.Stack.back().BreakBeforeParameter = true;
+State.Stack.back().AlignColons = false;
   }
 
   // The first token has already been indented and thus consumed.
Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,17 @@
   "  text: \"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, KeepsCommentsIndentedInList) {
+  verifyFormat("aa: 100\n"
+   "bbb: 200\n"
+   "# Single line comment for stuff here.\n"
+   ": 3849\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   "# Multiline comment for stuff here.\n"
+   ": 3849");
+}
+
 } // end namespace tooling
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43180: [clang-format] Support text proto extensions

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 133872.
krasimir added a comment.

- Add tests with long [...]


Repository:
  rC Clang

https://reviews.llvm.org/D43180

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -313,5 +313,67 @@
   "  text: \"aaasaa\"\n"
   "}");
 }
+
+TEST_F(FormatTestTextProto, FormatsExtensions) {
+  verifyFormat("[type] { key: value }");
+  verifyFormat("[type] {\n"
+   "  key: value\n"
+   "}");
+  verifyFormat("[type.type] { key: value }");
+  verifyFormat("[type.type] < key: value >");
+  verifyFormat("[type.type/type.type] { key: value }");
+  verifyFormat("msg {\n"
+   "  [type.type] { key: value }\n"
+   "}");
+  verifyFormat("msg {\n"
+   "  [type.type] {\n"
+   "keyy: value\n"
+   "  }\n"
+   "}");
+  verifyFormat("key: value\n"
+   "[a.b] { key: value }");
+  verifyFormat("msg: <\n"
+   "  key: value\n"
+   "  [a.b.c/d.e]: < key: value >\n"
+   "  [f.g]: <\n"
+   "key: valuee\n"
+   "key: {}\n"
+   "  >\n"
+   "  key {}\n"
+   "  [h.i.j] < key: value >\n"
+   "  [a]: {\n"
+   "[b.c]: {}\n"
+   "[d] <>\n"
+   "[e/f]: 1\n"
+   "  }\n"
+   ">");
+  verifyFormat("[longg.long.long.long.long.long.long.long.long.long.long\n"
+   " .longg.longlong] { key: value }");
+  verifyFormat("[longg.long.long.long.long.long.long.long.long.long.long\n"
+   " .longg.longlong] {\n"
+   "  key: value\n"
+   "  key: value\n"
+   "  key: value\n"
+   "  key: value\n"
+   "}");
+  verifyFormat("[longg.long.long.long.long.long.long.long.long.long\n"
+   " .long/longg.longlong] { key: value }");
+  verifyFormat("[aa/\n"
+   " bb] { key: value }");
+  verifyFormat("[\n"
+   "] { key: value }");
+  verifyFormat("[\n"
+   "] {\n"
+   "  [type.type] {\n"
+   "keyy: value\n"
+   "  }\n"
+   "}");
+  verifyFormat("[aaa/\n"
+   " bbb] {\n"
+   "  [type.type] {\n"
+   "keyy: value\n"
+   "  }\n"
+   "}");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -421,5 +421,16 @@
   "}");
 }
 
+TEST_F(FormatTestProto, FormatsOptionsExtensions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  msg_field: { field_d: 123 }\n"
+   "  [ext.t/u] { key: value }\n"
+   "  key: value\n"
+   "  [t.u/v] <\n"
+   "[ext] { key: value }\n"
+   "  >\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -368,12 +368,35 @@
  Parent->is(TT_TemplateCloser)) {
 Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
- (!CppArrayTemplates && Parent &&
-  Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
-  tok::comma, tok::l_paren, tok::l_square,
-  tok::question, tok::colon, tok::kw_return,
-  // Should only be relevant to JavaScript:
-  tok::kw_default))) {
+ Style.Language == FormatStyle::LK_TextProto) {
+// Square braces in LK_Proto can either be message field attributes:
+//
+// optional Aaa aaa = 1 [
+//   (aaa) = aaa
+// ];
+//
+// or text proto extensions (in options):
+  

[PATCH] D43180: [clang-format] Support text proto extensions

2018-02-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked an inline comment as done.
krasimir added inline comments.



Comment at: unittests/Format/FormatTestTextProto.cpp:317
+
+TEST_F(FormatTestTextProto, FormatsExtensions) {
+  verifyFormat("[type] { key: value }");

djasper wrote:
> It might be useful to attach a test case for what happens if the "[...]" does 
> not fit on one line. I don't even know how I would format that, but it seems 
> important to know and not accidentally modify the behavior.
I added some tests. The current behavior seems reasonable.


Repository:
  rC Clang

https://reviews.llvm.org/D43180



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


[PATCH] D43180: [clang-format] Support text proto extensions

2018-02-13 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC324995: [clang-format] Support text proto extensions 
(authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43180?vs=133872&id=134013#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43180

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -368,12 +368,35 @@
  Parent->is(TT_TemplateCloser)) {
 Left->Type = TT_ArraySubscriptLSquare;
   } else if (Style.Language == FormatStyle::LK_Proto ||
- (!CppArrayTemplates && Parent &&
-  Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
-  tok::comma, tok::l_paren, tok::l_square,
-  tok::question, tok::colon, tok::kw_return,
-  // Should only be relevant to JavaScript:
-  tok::kw_default))) {
+ Style.Language == FormatStyle::LK_TextProto) {
+// Square braces in LK_Proto can either be message field attributes:
+//
+// optional Aaa aaa = 1 [
+//   (aaa) = aaa
+// ];
+//
+// or text proto extensions (in options):
+//
+// option (Aaa.options) = {
+//   [type.type/type] {
+// key: value
+//   }
+// }
+//
+// In the first case we want to spread the contents inside the square
+// braces; in the second we want to keep them inline.
+Left->Type = TT_ArrayInitializerLSquare;
+if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::equal)) {
+  Left->Type = TT_ProtoExtensionLSquare;
+  BindingIncrease = 10;
+}
+  } else if (!CppArrayTemplates && Parent &&
+ Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,
+ tok::comma, tok::l_paren, tok::l_square,
+ tok::question, tok::colon, tok::kw_return,
+ // Should only be relevant to JavaScript:
+ tok::kw_default)) {
 Left->Type = TT_ArrayInitializerLSquare;
   } else {
 BindingIncrease = 10;
@@ -2396,6 +2419,12 @@
   return true;
 if (Right.isOneOf(tok::l_brace, tok::less) && Left.is(TT_SelectorName))
   return true;
+// Slashes occur in text protocol extension syntax: [type/type] { ... }.
+if (Left.is(tok::slash) || Right.is(tok::slash))
+  return false;
+if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
+Right.isOneOf(tok::l_brace, tok::less))
+  return !Style.Cpp11BracedListStyle;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
@@ -2732,6 +2761,9 @@
   (Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations))
 return true;
 
+  if (Right.is(TT_ProtoExtensionLSquare))
+return true;
+
   return false;
 }
 
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -943,6 +943,8 @@
   if (Previous.is(tok::r_paren) && !Current.isBinaryOperator() &&
   !Current.isOneOf(tok::colon, tok::comment))
 return ContinuationIndent;
+  if (Current.is(TT_ProtoExtensionLSquare))
+return State.Stack.back().Indent;
   if (State.Stack.back().Indent == State.FirstIndent && PreviousNonComment &&
   PreviousNonComment->isNot(tok::r_brace))
 // Ensure that we fall back to the continuation indent width instead of
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -88,6 +88,7 @@
   TYPE(TemplateCloser) \
   TYPE(TemplateOpener) \
   TYPE(TemplateString) \
+  TYPE(ProtoExtensionLSquare)  \
   TYPE(TrailingAnnotation) \
   TYPE(TrailingReturnArrow)\
   TYPE(TrailingUnaryOperator)  \
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+

[PATCH] D43231: [clang-format] Refactor ObjC tests

2018-02-13 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I don't believe this is needed: test fails before would fail at the line where 
test instance is checked, and after they will fail at the checkLanguage 
function.


Repository:
  rC Clang

https://reviews.llvm.org/D43231



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


[PATCH] D43294: [clang-format] Recognize percents as format specifiers in protos

2018-02-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
krasimir added a reviewer: djasper.
Herald added subscribers: cfe-commits, klimek.

Frequently, a percent in protos denotes a formatting specifier for string 
replacement.
Thus it is desirable to keep the percent together with what follows after it.


Repository:
  rC Clang

https://reviews.llvm.org/D43294

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) 
&&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch adds support for list initialization of proto repeated fields:

  keys: [1, 2, 3]


Repository:
  rC Clang

https://reviews.llvm.org/D43298

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
 return format(Code, 0, Code.size(), Style);
   }
 
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+
   static void verifyFormat(llvm::StringRef Code) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+verifyFormat(Code, Style);
   }
 };
 
@@ -386,5 +390,43 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+  verifyFormat("keys: []");
+  verifyFormat("keys: [ 1 ]");
+  verifyFormat("keys: [ 'ala', 'bala' ]");
+  verifyFormat("keys:\n"
+   "[ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+  verifyFormat("key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "key: item\n"
+   "msg {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "}\n"
+   "key: value"
+   );
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  Style.Cpp11BracedListStyle = true;
+  verifyFormat("keys: [1]", Style);
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,35 @@
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "  }\n"
+   "  key: value\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -383,11 +383,18 @@
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-tok::equal)) {
+tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingInc

[PATCH] D43294: [clang-format] Recognize percents as format specifiers in protos

2018-02-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325159: [clang-format] Recognize percents as format 
specifiers in protos (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43294?vs=134232&id=134286#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43294

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) 
&&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2425,6 +2425,9 @@
 if (Left.MatchingParen && Left.MatchingParen->is(TT_ProtoExtensionLSquare) &&
 Right.isOneOf(tok::l_brace, tok::less))
   return !Style.Cpp11BracedListStyle;
+// A percent is probably part of a formatting specification, such as %lld.
+if (Left.is(tok::percent))
+  return false;
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -386,5 +386,9 @@
"  }\n"
"}");
 }
+
+TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
+  verifyFormat("key: %d");
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -432,5 +432,11 @@
"};");
 }
 
+TEST_F(FormatTestProto, NoSpaceAfterPercent) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: %lld\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43312: [clang-format] fix handling of consecutive unary operators

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/TokenAnnotator.cpp:1497
+!(PrevToken->is(tok::exclaim) &&
+  Style.Language == FormatStyle::LK_JavaScript))
   // There aren't any trailing unary operators except for TypeScript's

I think that TypeScript has both `if (!cond)` and `x!`. I'd expect that `if 
(!+i) {\n}` is also handled in the TypeScript case. Could you add a test for 
this for TypeScript please.


Repository:
  rC Clang

https://reviews.llvm.org/D43312



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


[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 134427.
krasimir added a comment.

- Pull out check in lambda
- Address review comments


Repository:
  rC Clang

https://reviews.llvm.org/D43298

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
 return format(Code, 0, Code.size(), Style);
   }
 
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+
   static void verifyFormat(llvm::StringRef Code) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+verifyFormat(Code, Style);
   }
 };
 
@@ -390,5 +394,43 @@
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
   verifyFormat("key: %d");
 }
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+  verifyFormat("keys: []");
+  verifyFormat("keys: [ 1 ]");
+  verifyFormat("keys: [ 'ala', 'bala' ]");
+  verifyFormat("keys:\n"
+   "[ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+  verifyFormat("key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "key: item\n"
+   "msg {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "}\n"
+   "key: value"
+   );
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  Style.Cpp11BracedListStyle = true;
+  verifyFormat("keys: [1]", Style);
+}
 } // end namespace tooling
 } // end namespace clang
Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -438,5 +438,35 @@
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "  }\n"
+   "  key: value\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -383,11 +383,18 @@
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-tok::equal)) {
+tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;

[PATCH] D43298: [clang-format] Support repeated field lists in protos

2018-02-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325252: [clang-format] Support repeated field lists in 
protos (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43298

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTestProto.cpp
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp

Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -31,14 +31,18 @@
 return *Result;
   }
 
-  static std::string format(llvm::StringRef Code) {
-FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
-Style.ColumnLimit = 60; // To make writing tests easier.
+  static std::string format(llvm::StringRef Code, const FormatStyle &Style) {
 return format(Code, 0, Code.size(), Style);
   }
 
+  static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
+  }
+
   static void verifyFormat(llvm::StringRef Code) {
-EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+verifyFormat(Code, Style);
   }
 };
 
@@ -390,5 +394,43 @@
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
   verifyFormat("key: %d");
 }
+
+TEST_F(FormatTestTextProto, FormatsRepeatedListInitializers) {
+  verifyFormat("keys: []");
+  verifyFormat("keys: [ 1 ]");
+  verifyFormat("keys: [ 'ala', 'bala' ]");
+  verifyFormat("keys:\n"
+   "[ 'ala', 'bala', 'porto', 'kala', 'too', 'long', 'ng' ]");
+  verifyFormat("key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "key: item\n"
+   "msg {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "}\n"
+   "key: value"
+   );
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+  Style.ColumnLimit = 60; // To make writing tests easier.
+  Style.Cpp11BracedListStyle = true;
+  verifyFormat("keys: [1]", Style);
+}
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -438,5 +438,35 @@
"};");
 }
 
+TEST_F(FormatTestProto, FormatsRepeatedListInitializersInOptions) {
+  verifyFormat("option (MyProto.options) = {\n"
+   "  key: item\n"
+   "  keys: [\n"
+   "'ala',\n"
+   "'bala',\n"
+   "'porto',\n"
+   "'kala',\n"
+   "'too',\n"
+   "'long',\n"
+   "'long',\n"
+   "'long'\n"
+   "  ]\n"
+   "  key: [ item ]\n"
+   "  msg {\n"
+   "key: item\n"
+   "keys: [\n"
+   "  'ala',\n"
+   "  'bala',\n"
+   "  'porto',\n"
+   "  'kala',\n"
+   "  'too',\n"
+   "  'long',\n"
+   "  'long'\n"
+   "]\n"
+   "  }\n"
+   "  key: value\n"
+   "};");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -383,11 +383,18 @@
 //   }
 // }
 //
-// In the first case we want to spread the contents inside the square
-// braces; in the second we want to keep them inline.
+// or repeated fields (in options):
+//
+// option (Aaa.options) = {
+//   keys: [ 1, 2, 3 ]
+// }
+//
+// In the first and the third case we want to spread the contents inside
+// the square braces; in the second we want to keep them inline.
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
-   

[PATCH] D43312: [clang-format] fix handling of consecutive unary operators

2018-02-16 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.
This revision is now accepted and ready to land.

Thank you! Do you have commit access or should I commit this for you?


Repository:
  rC Clang

https://reviews.llvm.org/D43312



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


[PATCH] D43465: [clang-format] Fixup a case of text proto message attributes

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This patch fixes a case where a proto message attribute is wrongly identified 
as an text proto extension.


Repository:
  rC Clang

https://reviews.llvm.org/D43465

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


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43465: [clang-format] Fixup a case of text proto message attributes

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325509: [clang-format] Fixup a case of text proto message 
attributes (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43465

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


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;
Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43465: [clang-format] Fixup a case of text proto message attributes

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325509: [clang-format] Fixup a case of text proto message 
attributes (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43465?vs=134910&id=134912#toc

Repository:
  rC Clang

https://reviews.llvm.org/D43465

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


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;


Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -168,6 +168,16 @@
": true\n"
"  }\n"
"];");
+  verifyFormat("extensions 20 [(proto2.type) = 'Aaaa.'];");
+  verifyFormat("extensions 20\n"
+   "[(proto3.type) = 'Aaaa.', (aaa.Aaa) = 'aaa.bbb'];");
+  verifyFormat("extensions 123 [\n"
+   "  (aaa) = ,\n"
+   "  (bb) = {\n"
+   "a: true,\n"
+   ": true\n"
+   "  }\n"
+   "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -375,6 +375,10 @@
 //   (aaa) = aaa
 // ];
 //
+// extensions 123 [
+//   (aaa) = aaa
+// ];
+//
 // or text proto extensions (in options):
 //
 // option (Aaa.options) = {
@@ -394,6 +398,8 @@
 Left->Type = TT_ArrayInitializerLSquare;
 if (!Left->endsSequence(tok::l_square, tok::numeric_constant,
 tok::equal) &&
+!Left->endsSequence(tok::l_square, tok::numeric_constant,
+tok::identifier) &&
 !Left->endsSequence(tok::l_square, tok::colon, TT_SelectorName)) {
   Left->Type = TT_ProtoExtensionLSquare;
   BindingIncrease = 10;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43469: [clang-format] Fix text proto extension scope opening detection

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added subscribers: cfe-commits, klimek.

This fixes the detection of scope openers in text proto extensions; previously
they were not detected correctly leading to instances like:

  msg {
[aa.bb
  ] {
  key: value
  }
  }


Repository:
  rC Clang

https://reviews.llvm.org/D43469

Files:
  lib/Format/FormatToken.h
  unittests/Format/FormatTestTextProto.cpp


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||


Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43469: [clang-format] Fix text proto extension scope opening detection

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325513: [clang-format] Fix text proto extension scope 
opening detection (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43469?vs=134918&id=134921#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43469

Files:
  lib/Format/FormatToken.h
  unittests/Format/FormatTestTextProto.cpp


Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {


Index: lib/Format/FormatToken.h
===
--- lib/Format/FormatToken.h
+++ lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43469: [clang-format] Fix text proto extension scope opening detection

2018-02-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325513: [clang-format] Fix text proto extension scope 
opening detection (authored by krasimir, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D43469

Files:
  cfe/trunk/lib/Format/FormatToken.h
  cfe/trunk/unittests/Format/FormatTestTextProto.cpp


Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
Index: cfe/trunk/lib/Format/FormatToken.h
===
--- cfe/trunk/lib/Format/FormatToken.h
+++ cfe/trunk/lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||


Index: cfe/trunk/unittests/Format/FormatTestTextProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestTextProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestTextProto.cpp
@@ -389,6 +389,14 @@
"keyy: value\n"
"  }\n"
"}");
+  verifyFormat(
+  "aaa {\n"
+  "  bb {\n"
+  "[a.b/cy] {\n"
+  "  e: \"The lazy coo cat jumps over the lazy hot dog\"\n"
+  "}\n"
+  "  }\n"
+  "}");
 }
 
 TEST_F(FormatTestTextProto, NoSpaceAfterPercent) {
Index: cfe/trunk/lib/Format/FormatToken.h
===
--- cfe/trunk/lib/Format/FormatToken.h
+++ cfe/trunk/lib/Format/FormatToken.h
@@ -478,6 +478,7 @@
 if (is(TT_TemplateString) && opensScope())
   return true;
 return is(TT_ArrayInitializerLSquare) ||
+   is(TT_ProtoExtensionLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
  (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D33416: [clangd] Allow to use vfs::FileSystem for file accesses.

2017-05-24 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/clangd/ClangdTests.cpp:298
+  const auto SourceContents =
+  R"cpp(
+#include "foo.h"

Move this to the previous line.



Comment at: unittests/clangd/ClangdTests.cpp:336
+  const auto SourceContents =
+  R"cpp(
+#include "foo.h"

Move this to the previous line.


https://reviews.llvm.org/D33416



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


[PATCH] D33589: clang-format: consider not splitting tokens in optimization

2017-06-01 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

I think that what you're trying to solve is not practically that important, is 
unlikely to improve the handling of comments, and will add a lot of complexity.

From a usability perspective, I think that people are happy enough when their 
comments don't exceed the line limit. I personally wouldn't want the opposite 
to happen. I've even seen style guides that have 80 columns limit for comments 
and 100 for code.

Comments are treated in a somewhat ad-hoc style in clang-format, which is 
because they are inherently free text and don't have a specific format. People 
just expect comments to be handled quite differently than source code. There 
are at least three separate parts in clang-format that make up the formatting 
of comments: the normal parsing and optimization pipeline, the 
BreakableLineCommentSection / BreakableBlockComment classes that are 
responsible for breaking and reflowing inside comment sections, and the 
consecutive trailing comment alignment in the WhitespaceManager. This patch 
takes into account the first aspect but not the consequences for the other 
aspects: for example it allows for the first line comment token in a multiline 
line comment section to get out of the column limit, but will reflow the rest 
of the lines. A WhitespaceManager-related issue is that because a trailing line 
comment for some declaration might not get split, it might not be aligned with 
the surrounding trailing line comments, which I think is a less desirable 
effect.

Optimizing the layout in comment sections by using the optimizing formatter 
sounds good, but because comments mostly contain free text that can be 
structured in unexpected ways, I think that the ad-hoc approach works better. 
Think of not destroying ASCII art and supporting bulleted and numbered lists 
for example. We don't really want to leak lots of comment-related formatting 
tweaks into the general pipeline itself.

I see you point that PenaltyBreakComment and PenaltyExcessCharacter are not 
taken into account while comment placement, but they are taken into account at 
a higher level by treating the whole comment section as a unit. For example, if 
you have a long declaration that has multiple potential split points followed 
by a long trailing comment section, the penalty induced by the number of lines 
that are needed and the number of unbroken characters for the formatting of the 
comment section is taken into account while optimizing the layout of the whole 
code fragment.

The formatted currently supports somewhat limited version of allowing comment 
lines exceeding the column limit, like long hyperlinks for example. I think 
that if there are some other examples which are both widespread and super 
annoying, we may consider them separately.


https://reviews.llvm.org/D33589



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


[PATCH] D33982: [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 101734.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D33982

Files:
  lib/Format/WhitespaceManager.cpp
  unittests/Format/FormatTestComments.cpp


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ; // CC\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  EXPECT_EQ("#if A\n"
+"#else  // A1\n"
+"   // A2\n"
+"int ii;\n"
+"#endif // B",
+format("#if A\n"
+   "#else  // A1\n"
+   "   // A2\n"
+   "int ii;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestComments, CommentsInStaticInitializers) {
   EXPECT_EQ(
   "static SomeType type = {, /* comment */\n"
Index: lib/Format/WhitespaceManager.cpp
===
--- lib/Format/WhitespaceManager.cpp
+++ lib/Format/WhitespaceManager.cpp
@@ -100,14 +100,52 @@
   Changes[0].PreviousEndOfTokenColumn = 0;
   Change *LastOutsideTokenChange = &Changes[0];
   for (unsigned i = 1, e = Changes.size(); i != e; ++i) {
-unsigned OriginalWhitespaceStart =
-SourceMgr.getFileOffset(Changes[i].OriginalWhitespaceRange.getBegin());
-unsigned PreviousOriginalWhitespaceEnd = SourceMgr.getFileOffset(
-Changes[i - 1].OriginalWhitespaceRange.getEnd());
-Changes[i - 1].TokenLength = OriginalWhitespaceStart -
- PreviousOriginalWhitespaceEnd +
- Changes[i].PreviousLinePostfix.size() +
- Changes[i - 1].CurrentLinePrefix.size();
+SourceLocation OriginalWhitespaceStart =
+Changes[i].OriginalWhitespaceRange.getBegin();
+SourceLocation PreviousOriginalWhitespaceEnd =
+Changes[i - 1].OriginalWhitespaceRange.getEnd();
+unsigned OriginalWhitespaceStartOffset =
+SourceMgr.getFileOffset(OriginalWhitespaceStart);
+unsigned PreviousOriginalWhitespaceEndOffset =
+SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd);
+assert(PreviousOriginalWhitespaceEndOffset <=
+   OriginalWhitespaceStartOffset);
+const char *const PreviousOriginalWhitespaceEndData =
+SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd);
+StringRef Text(PreviousOriginalWhitespaceEndData,
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -
+   PreviousOriginalWhitespaceEndData);
+// Usually consecutive changes would occur in consecutive tokens. This is
+// not the case however when analyzing some preprocessor runs of the
+// annotated lines. For example, in this code:
+//
+// #if A // line 1
+// int i = 1;
+// #else B // line 2
+// int i = 2;
+// #endif // line 3
+//
+// one of the runs will produce the sequence of lines marked with line 1, 2
+// and 3. So the two consecutive whitespace changes just before '// line 2'
+// and before '#endif // line 3' span multiple lines and tokens:
+//
+// #else B{change X}[// line 2
+// int i = 2;
+// ]{change Y}#endif // line 3
+//
+// For this reason, if the text between consecutive changes spans multiple
+// newlines, the token length must be adjusted to the end of the original
+// line of the token.
+auto NewlinePos = Text.find_first_of('\n');
+if (NewlinePos == StringRef::npos) {
+  Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset -
+   PreviousOriginalWhitespaceEndOffset +
+   Changes[i].PreviousLinePostfix.size() +
+   Changes[i - 1].CurrentLinePrefix.size();
+} else {
+  Changes[i - 1].TokenLength =
+  NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
+}
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#el

[PATCH] D33982: [clang-format] Fix alignment of preprocessor trailing comments

2017-06-07 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304912: [clang-format] Fix alignment of preprocessor 
trailing comments (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D33982?vs=101734&id=101736#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33982

Files:
  cfe/trunk/lib/Format/WhitespaceManager.cpp
  cfe/trunk/unittests/Format/FormatTestComments.cpp


Index: cfe/trunk/lib/Format/WhitespaceManager.cpp
===
--- cfe/trunk/lib/Format/WhitespaceManager.cpp
+++ cfe/trunk/lib/Format/WhitespaceManager.cpp
@@ -100,14 +100,52 @@
   Changes[0].PreviousEndOfTokenColumn = 0;
   Change *LastOutsideTokenChange = &Changes[0];
   for (unsigned i = 1, e = Changes.size(); i != e; ++i) {
-unsigned OriginalWhitespaceStart =
-SourceMgr.getFileOffset(Changes[i].OriginalWhitespaceRange.getBegin());
-unsigned PreviousOriginalWhitespaceEnd = SourceMgr.getFileOffset(
-Changes[i - 1].OriginalWhitespaceRange.getEnd());
-Changes[i - 1].TokenLength = OriginalWhitespaceStart -
- PreviousOriginalWhitespaceEnd +
- Changes[i].PreviousLinePostfix.size() +
- Changes[i - 1].CurrentLinePrefix.size();
+SourceLocation OriginalWhitespaceStart =
+Changes[i].OriginalWhitespaceRange.getBegin();
+SourceLocation PreviousOriginalWhitespaceEnd =
+Changes[i - 1].OriginalWhitespaceRange.getEnd();
+unsigned OriginalWhitespaceStartOffset =
+SourceMgr.getFileOffset(OriginalWhitespaceStart);
+unsigned PreviousOriginalWhitespaceEndOffset =
+SourceMgr.getFileOffset(PreviousOriginalWhitespaceEnd);
+assert(PreviousOriginalWhitespaceEndOffset <=
+   OriginalWhitespaceStartOffset);
+const char *const PreviousOriginalWhitespaceEndData =
+SourceMgr.getCharacterData(PreviousOriginalWhitespaceEnd);
+StringRef Text(PreviousOriginalWhitespaceEndData,
+   SourceMgr.getCharacterData(OriginalWhitespaceStart) -
+   PreviousOriginalWhitespaceEndData);
+// Usually consecutive changes would occur in consecutive tokens. This is
+// not the case however when analyzing some preprocessor runs of the
+// annotated lines. For example, in this code:
+//
+// #if A // line 1
+// int i = 1;
+// #else B // line 2
+// int i = 2;
+// #endif // line 3
+//
+// one of the runs will produce the sequence of lines marked with line 1, 2
+// and 3. So the two consecutive whitespace changes just before '// line 2'
+// and before '#endif // line 3' span multiple lines and tokens:
+//
+// #else B{change X}[// line 2
+// int i = 2;
+// ]{change Y}#endif // line 3
+//
+// For this reason, if the text between consecutive changes spans multiple
+// newlines, the token length must be adjusted to the end of the original
+// line of the token.
+auto NewlinePos = Text.find_first_of('\n');
+if (NewlinePos == StringRef::npos) {
+  Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset -
+   PreviousOriginalWhitespaceEndOffset +
+   Changes[i].PreviousLinePostfix.size() +
+   Changes[i - 1].CurrentLinePrefix.size();
+} else {
+  Changes[i - 1].TokenLength =
+  NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
+}
 
 // If there are multiple changes in this token, sum up all the changes 
until
 // the end of the line.
Index: cfe/trunk/unittests/Format/FormatTestComments.cpp
===
--- cfe/trunk/unittests/Format/FormatTestComments.cpp
+++ cfe/trunk/unittests/Format/FormatTestComments.cpp
@@ -1052,6 +1052,30 @@
"}", getLLVMStyleWithColumns(80));
 }
 
+TEST_F(FormatTestComments, AlignsPPElseEndifComments) {
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  verifyFormat("#if A\n"
+   "#else  // A\n"
+   "int ; // CC\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20));
+  EXPECT_EQ("#if A\n"
+"#else  // A1\n"
+"   // A2\n"
+"int ii;\n"
+"#endif // B",
+format("#if A\n"
+   "#else  // A1\n"
+   "   // A2\n"
+   "int ii;\n"
+   "#endif // B",
+   getLLVMStyleWithColumns(20)));
+}
+
 TEST_F(FormatTestComments, CommentsInStaticInitializers) {
   EXPECT_EQ(
   "static SomeType type = {, /* comment */\n"


Index: cfe/trunk/lib/Format/WhitespaceManager.cpp

[PATCH] D34033: [clangd] Add parameter and return type information to completion results

2017-06-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 101919.
krasimir added a comment.

- Remove optional chunks. They might contain control characters


https://reviews.llvm.org/D34033

Files:
  clangd/ClangdUnit.cpp
  test/clangd/completion.test


Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -5,41 +5,40 @@
 
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  
fake f;\n  f.\n}\n"}}}
 
 Content-Length: 148
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # The order of results returned by ASTUnit CodeComplete seems to be
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) 
const","kind":2,"detail":"int","insertText":"f"}
 # CHECK: ]}
 Content-Length: 146
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:/main.cpp"},"position":{"line":3,"character":5}}}
 # Test authority-less URI
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","insertText":"a"}
 # CHECK: ]}
 
 Content-Length: 172
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
 # Test params parsing in the presence of a 1.x-compatible client (inlined 
"uri")
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","insertText":"a"}
 # CHECK: ]}
 Content-Length: 44
 
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -138,9 +138,21 @@
   CodeCompleteOpts.IncludeBriefComments);
   if (CCS) {
 CompletionItem Item;
+for (CodeCompletionString::Chunk C : *CCS) {
+  switch (C.Kind) {
+  case CodeCompletionString::CK_ResultType:
+Item.detail = C.Text;
+break;
+  case CodeCompletionString::CK_Optional:
+break;
+  default:
+Item.label += C.Text;
+break;
+  }
+}
 assert(CCS->getTypedText());
-Item.label = CCS->getTypedText();
 Item.kind = getKind(Result.CursorKind);
+Item.insertText = CCS->getTypedText();
 if (CCS->getBriefComment())
   Item.documentation = CCS->getBriefComment();
 Items->push_back(std::move(Item));


Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -5,41 +5,40 @@
 
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
 
 Content-Length: 148
 
 {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # The order of results returned b

[PATCH] D34033: [clangd] Add parameter and return type information to completion results

2017-06-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir marked an inline comment as done.
krasimir added inline comments.



Comment at: clangd/ClangdUnit.cpp:153
 Item.kind = getKind(Result.CursorKind);
+Item.insertText = CCS->getTypedText();
 if (CCS->getBriefComment())

ilya-biryukov wrote:
> Should we also update sortText and filterText, which use label by default, 
> just like insertText?
Good point!



Comment at: test/clangd/completion.test:32
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","insertText":"a"}
 # CHECK: ]}

ilya-biryukov wrote:
> Should we repeat repeat the checks added above here too?
This test case is about understanding 'file:/main.cpp', so I don't think 
repeating everything would be beneficial.


https://reviews.llvm.org/D34033



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


[PATCH] D34033: [clangd] Add parameter and return type information to completion results

2017-06-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 101921.
krasimir marked an inline comment as done.
krasimir added a comment.

- Add sortText and filterText


https://reviews.llvm.org/D34033

Files:
  clangd/ClangdUnit.cpp
  test/clangd/completion.test


Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -5,41 +5,40 @@
 
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  
fake f;\n  f.\n}\n"}}}
 
 Content-Length: 148
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # The order of results returned by ASTUnit CodeComplete seems to be
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: 
{"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: 
{"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) 
const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 Content-Length: 146
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:/main.cpp"},"position":{"line":3,"character":5}}}
 # Test authority-less URI
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 
 Content-Length: 172
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
 # Test params parsing in the presence of a 1.x-compatible client (inlined 
"uri")
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 Content-Length: 44
 
Index: clangd/ClangdUnit.cpp
===
--- clangd/ClangdUnit.cpp
+++ clangd/ClangdUnit.cpp
@@ -138,9 +138,21 @@
   CodeCompleteOpts.IncludeBriefComments);
   if (CCS) {
 CompletionItem Item;
+for (CodeCompletionString::Chunk C : *CCS) {
+  switch (C.Kind) {
+  case CodeCompletionString::CK_ResultType:
+Item.detail = C.Text;
+break;
+  case CodeCompletionString::CK_Optional:
+break;
+  default:
+Item.label += C.Text;
+break;
+  }
+}
 assert(CCS->getTypedText());
-Item.label = CCS->getTypedText();
 Item.kind = getKind(Result.CursorKind);
+Item.insertText = Item.sortText = Item.filterText = 
CCS->getTypedText();
 if (CCS->getBriefComment())
   Item.documentation = CCS->getBriefComment();
 Items->push_back(std::move(Item));


Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -5,41 +5,40 @@
 
 {"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","

[PATCH] D34033: [clangd] Add parameter and return type information to completion results

2017-06-08 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL304980: [clangd] Add parameter and return type information 
to completion results (authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D34033?vs=101921&id=101925#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34033

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/test/clangd/completion.test


Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -138,9 +138,21 @@
   CodeCompleteOpts.IncludeBriefComments);
   if (CCS) {
 CompletionItem Item;
+for (CodeCompletionString::Chunk C : *CCS) {
+  switch (C.Kind) {
+  case CodeCompletionString::CK_ResultType:
+Item.detail = C.Text;
+break;
+  case CodeCompletionString::CK_Optional:
+break;
+  default:
+Item.label += C.Text;
+break;
+  }
+}
 assert(CCS->getTypedText());
-Item.label = CCS->getTypedText();
 Item.kind = getKind(Result.CursorKind);
+Item.insertText = Item.sortText = Item.filterText = 
CCS->getTypedText();
 if (CCS->getBriefComment())
   Item.documentation = CCS->getBriefComment();
 Items->push_back(std::move(Item));
Index: clang-tools-extra/trunk/test/clangd/completion.test
===
--- clang-tools-extra/trunk/test/clangd/completion.test
+++ clang-tools-extra/trunk/test/clangd/completion.test
@@ -5,41 +5,40 @@
 
 
{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{},"trace":"off"}}
 
-Content-Length: 211
+Content-Length: 246
 
-{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; };\nint main() {\n  fake f;\n  f.\n}\n"}}}
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file:///main.cpp","languageId":"cpp","version":1,"text":"struct
 fake { int a, bb, ccc; int f(int i, const float f) const; };\nint main() {\n  
fake f;\n  f.\n}\n"}}}
 
 Content-Length: 148
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # The order of results returned by ASTUnit CodeComplete seems to be
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: 
{"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: 
{"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake 
&","sortText":"operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: 
{"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) 
const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 Content-Length: 146
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:/main.cpp"},"position":{"line":3,"character":5}}}
 # Test authority-less URI
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 
 Content-Length: 172
 
 
{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
 # Test params parsing in the presence of a 1.x-compatible client (inlined 
"uri")
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5}
-# CHECK-DAG: {"label":"bb","kind":5}
-# CHECK-DAG: {"label":"ccc","kind":5}
+# CHECK-DAG: 
{"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 Content-Length: 44
 


Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -138,9 +138,21 @@
   CodeCompleteOpts.IncludeBriefComments);
   if (CCS) {
 CompletionItem Item;
+  

[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

@klimek: ping


https://reviews.llvm.org/D33823



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


[PATCH] D34107: [clangd] Allow to override contents of the file during completion.

2017-06-12 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added inline comments.
This revision is now accepted and ready to land.



Comment at: unittests/clangd/ClangdTests.cpp:432
+  // size the same.
+  // We complete on the 3rd line(2nd in zero-based numbering), because raw
+  // string literal of the SourceContents starts with a newline(it's easy to

nit: add a space between `line` and `(`.



Comment at: unittests/clangd/ClangdTests.cpp:452
+  StringRef(OverridenSourceContents))
+.Value;
+EXPECT_TRUE(ContainsItem(CodeCompletionResultsOverriden, "cbc"));

Is this how clang-format formats this chain? :(


https://reviews.llvm.org/D34107



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


[PATCH] D34148: [clangd] Store references instead of unique_ptrs in ClangdServer.

2017-06-13 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: clangd/ClangdLSPServer.h:75
+  LSPDiagnosticsConsumer DiagConsumer;
+  RealFileSystemProvider FSProvider;
+

This approach is still inflexible. I'd make ClangdLSPServer : public 
DiagnosticsConsumer and pass references to the CompilationDatabase and to the 
FileSystemProvider to its constructor. I'd create these two in ClangdMain.cpp.


https://reviews.llvm.org/D34148



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


[PATCH] D34148: [clangd] Store references instead of unique_ptrs in ClangdServer.

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

But, of course, that can be done in a separate commit.


https://reviews.llvm.org/D34148



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


[PATCH] D34137: [clangd] Add priority to completion item sort text

2017-06-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 102522.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D34137

Files:
  clangd/ClangdUnit.cpp
  test/clangd/authority-less-uri.test
  test/clangd/completion.test

Index: test/clangd/completion.test
===
--- test/clangd/completion.test
+++ test/clangd/completion.test
@@ -16,25 +16,25 @@
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"99964ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"99965operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"99965~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"99964f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 Content-Length: 148
 
 {"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # Repeat the completion request, expect the same results.
 #
 # CHECK: {"jsonrpc":"2.0","id":2,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"99964ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"99965operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"99965~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"99964f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 # Update the source file and check for completions again.
 Content-Length: 226
@@ -47,7 +47,7 @@
 # Repeat the completion request, expect the same results.
 #
 # CHECK: {"jsonrpc":"2.0","id":3,"result":[
-# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"func","filterText":"func","insertText":"func"}
+# CHECK-DAG: {"label":"func()","kind":2,"detail":"int (*)(int, int)","sortText":"99965func","filterText":"func","insertText":"func"}
 # CHECK: ]}
 Content-Length: 44
 
Index: test/clangd/authority-less-uri.test
===
--- test/clangd/authority-less-uri.test
+++ test/clangd/authority-less-uri.test
@@ -16,16 +16,16 @@
 # Test authority-less URI
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
 # CHECK: ]}
 
 Content-Length: 172
 
 {"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"uri":"file:///main.cpp","position":{"line":3,"character":5}}}
 # Test params parsing in the presence of a 

[PATCH] D32480: clang-format: Add CompactNamespaces option

2017-06-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Looks good, except for the tests that actually add or fix namespace end 
comments should be moved to NamespaceEndCommentsFixerTest.cpp.


https://reviews.llvm.org/D32480



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


[PATCH] D32480: clang-format: Add CompactNamespaces option

2017-06-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: unittests/Format/FormatTest.cpp:1394
+   "int j;\n"
+  "}\n"
+   "}",

Re-indent this line.


https://reviews.llvm.org/D32480



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


[PATCH] D34201: [clangd] Move dependencies of ClangdLSPServer out of its implementation

2017-06-14 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir abandoned this revision.
krasimir added a comment.

On a second thought, meh :D


https://reviews.llvm.org/D34201



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


[PATCH] D34137: [clangd] Add priority to completion item sort text

2017-06-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305454: [clangd] Add priority to completion item sort text 
(authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D34137?vs=102522&id=102646#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34137

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/test/clangd/authority-less-uri.test
  clang-tools-extra/trunk/test/clangd/completion.test

Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -13,6 +13,7 @@
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/Utils.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/Support/Format.h"
 
 using namespace clang::clangd;
 using namespace clang;
@@ -153,7 +154,17 @@
 }
 assert(CCS->getTypedText());
 Item.kind = getKind(Result.CursorKind);
-Item.insertText = Item.sortText = Item.filterText = CCS->getTypedText();
+// Priority is a 16-bit integer, hence at most 5 digits.
+// Since identifiers with higher priority need to come first,
+// we subtract the priority from 9.
+// For example, the sort text of the identifier 'a' with priority 35
+// is 99964a.
+assert(CCS->getPriority() < 9 && "Expecting code completion result "
+ "priority to have at most "
+ "5-digits");
+llvm::raw_string_ostream(Item.sortText) << llvm::format(
+"%05d%s", 9 - CCS->getPriority(), CCS->getTypedText());
+Item.insertText = Item.filterText = CCS->getTypedText();
 if (CCS->getBriefComment())
   Item.documentation = CCS->getBriefComment();
 Items->push_back(std::move(Item));
Index: clang-tools-extra/trunk/test/clangd/completion.test
===
--- clang-tools-extra/trunk/test/clangd/completion.test
+++ clang-tools-extra/trunk/test/clangd/completion.test
@@ -16,25 +16,25 @@
 # nondeterministic, so we check regardless of order.
 #
 # CHECK: {"jsonrpc":"2.0","id":1,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964bb","filterText":"bb","insertText":"bb"}
+# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"99964ccc","filterText":"ccc","insertText":"ccc"}
+# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"99965operator=","filterText":"operator=","insertText":"operator="}
+# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"99965~fake","filterText":"~fake","insertText":"~fake"}
+# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"99964f","filterText":"f","insertText":"f"}
 # CHECK: ]}
 Content-Length: 148
 
 {"jsonrpc":"2.0","id":2,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///main.cpp"},"position":{"line":3,"character":5}}}
 # Repeat the completion request, expect the same results.
 #
 # CHECK: {"jsonrpc":"2.0","id":2,"result":[
-# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"a","filterText":"a","insertText":"a"}
-# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"bb","filterText":"bb","insertText":"bb"}
-# CHECK-DAG: {"label":"ccc","kind":5,"detail":"int","sortText":"ccc","filterText":"ccc","insertText":"ccc"}
-# CHECK-DAG: {"label":"operator=(const fake &)","kind":2,"detail":"fake &","sortText":"operator=","filterText":"operator=","insertText":"operator="}
-# CHECK-DAG: {"label":"~fake()","kind":4,"detail":"void","sortText":"~fake","filterText":"~fake","insertText":"~fake"}
-# CHECK-DAG: {"label":"f(int i, const float f) const","kind":2,"detail":"int","sortText":"f","filterText":"f","insertText":"f"}
+# CHECK-DAG: {"label":"a","kind":5,"detail":"int","sortText":"99964a","filterText":"a","insertText":"a"}
+# CHECK-DAG: {"label":"bb","kind":5,"detail":"int","sortText":"99964b

[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 103031.
krasimir marked 3 inline comments as done.
krasimir added a comment.

- Address review comments


https://reviews.llvm.org/D33823

Files:
  include/clang/Format/Format.h
  lib/Format/CMakeLists.txt
  lib/Format/Format.cpp
  lib/Format/UsingDeclarationsSorter.cpp
  lib/Format/UsingDeclarationsSorter.h
  unittests/Format/CMakeLists.txt
  unittests/Format/UsingDeclarationsSorterTest.cpp

Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- /dev/null
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -0,0 +1,234 @@
+//===- UsingDeclarationsSorterTest.cpp - Formatting unit tests ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "using-declarations-sorter-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class UsingDeclarationsSorterTest : public ::testing::Test {
+protected:
+  std::string sortUsingDeclarations(llvm::StringRef Code,
+const std::vector &Ranges,
+const FormatStyle &Style = getLLVMStyle()) {
+DEBUG(llvm::errs() << "---\n");
+DEBUG(llvm::errs() << Code << "\n\n");
+tooling::Replacements Replaces =
+clang::format::sortUsingDeclarations(Style, Code, Ranges, "");
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  std::string sortUsingDeclarations(llvm::StringRef Code,
+const FormatStyle &Style = getLLVMStyle()) {
+return sortUsingDeclarations(Code,
+ /*Ranges=*/{1, tooling::Range(0, Code.size())},
+ Style);
+  }
+};
+
+TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) {
+  EXPECT_EQ("using a;\n"
+"using b;",
+sortUsingDeclarations("using a;\n"
+  "using b;"));
+  EXPECT_EQ("using a;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a;"));
+  EXPECT_EQ("using ::a;\n"
+"using a;",
+sortUsingDeclarations("using a;\n"
+  "using ::a;"));
+
+  EXPECT_EQ("using a::bcd;\n"
+"using a::cd;",
+sortUsingDeclarations("using a::cd;\n"
+  "using a::bcd;"));
+
+  EXPECT_EQ("using a;\n"
+"using a::a;",
+sortUsingDeclarations("using a::a;\n"
+  "using a;"));
+
+  EXPECT_EQ("using a::ba::aa;\n"
+"using a::bb::ccc;",
+sortUsingDeclarations("using a::bb::ccc;\n"
+  "using a::ba::aa;"));
+
+  EXPECT_EQ("using a;\n"
+"using typename a;",
+sortUsingDeclarations("using typename a;\n"
+  "using a;"));
+
+  EXPECT_EQ("using typename z;\n"
+"using typenamea;",
+sortUsingDeclarations("using typenamea;\n"
+  "using typename z;"));
+
+  EXPECT_EQ("using a, b;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a, b;"));
+}
+
+TEST_F(UsingDeclarationsSorterTest, SortsMultipleTopLevelDeclarations) {
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using d;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using b;\n"
+  "using e;\n"
+  "using a;\n"
+  "using c;"));
+
+  EXPECT_EQ("#include \n"
+"using ::std::endl;\n"
+"using std::cin;\n"
+"using std::cout;\n"
+"int main();",
+sortUsingDeclarations("#include \n"
+  "using std::cout;\n"
+  "using std::cin;\n"
+  "using ::std::endl;\n"
+  "int main();"));
+}
+
+TEST_F(UsingDeclarationsSorterTest, BreaksOnEmptyLines) {
+  EXPECT_EQ("using b;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using d;",
+sortUsingDeclarations("using c;\n"
+  "using b;\n"
+  "\n"
+  "using d;\n"
+  "usin

[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 103032.
krasimir added a comment.

- Update test case


https://reviews.llvm.org/D33823

Files:
  include/clang/Format/Format.h
  lib/Format/CMakeLists.txt
  lib/Format/Format.cpp
  lib/Format/UsingDeclarationsSorter.cpp
  lib/Format/UsingDeclarationsSorter.h
  unittests/Format/CMakeLists.txt
  unittests/Format/UsingDeclarationsSorterTest.cpp

Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- /dev/null
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -0,0 +1,234 @@
+//===- UsingDeclarationsSorterTest.cpp - Formatting unit tests ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "clang/Format/Format.h"
+
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "using-declarations-sorter-test"
+
+namespace clang {
+namespace format {
+namespace {
+
+class UsingDeclarationsSorterTest : public ::testing::Test {
+protected:
+  std::string sortUsingDeclarations(llvm::StringRef Code,
+const std::vector &Ranges,
+const FormatStyle &Style = getLLVMStyle()) {
+DEBUG(llvm::errs() << "---\n");
+DEBUG(llvm::errs() << Code << "\n\n");
+tooling::Replacements Replaces =
+clang::format::sortUsingDeclarations(Style, Code, Ranges, "");
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  std::string sortUsingDeclarations(llvm::StringRef Code,
+const FormatStyle &Style = getLLVMStyle()) {
+return sortUsingDeclarations(Code,
+ /*Ranges=*/{1, tooling::Range(0, Code.size())},
+ Style);
+  }
+};
+
+TEST_F(UsingDeclarationsSorterTest, SwapsTwoConsecutiveUsingDeclarations) {
+  EXPECT_EQ("using a;\n"
+"using b;",
+sortUsingDeclarations("using a;\n"
+  "using b;"));
+  EXPECT_EQ("using a;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a;"));
+  EXPECT_EQ("using ::a;\n"
+"using a;",
+sortUsingDeclarations("using a;\n"
+  "using ::a;"));
+
+  EXPECT_EQ("using a::bcd;\n"
+"using a::cd;",
+sortUsingDeclarations("using a::cd;\n"
+  "using a::bcd;"));
+
+  EXPECT_EQ("using a;\n"
+"using a::a;",
+sortUsingDeclarations("using a::a;\n"
+  "using a;"));
+
+  EXPECT_EQ("using a::ba::aa;\n"
+"using a::bb::ccc;",
+sortUsingDeclarations("using a::bb::ccc;\n"
+  "using a::ba::aa;"));
+
+  EXPECT_EQ("using a;\n"
+"using typename a;",
+sortUsingDeclarations("using typename a;\n"
+  "using a;"));
+
+  EXPECT_EQ("using typename z;\n"
+"using typenamea;",
+sortUsingDeclarations("using typenamea;\n"
+  "using typename z;"));
+
+  EXPECT_EQ("using a, b;\n"
+"using aa;",
+sortUsingDeclarations("using aa;\n"
+  "using a, b;"));
+}
+
+TEST_F(UsingDeclarationsSorterTest, SortsMultipleTopLevelDeclarations) {
+  EXPECT_EQ("using a;\n"
+"using b;\n"
+"using c;\n"
+"using d;\n"
+"using e;",
+sortUsingDeclarations("using d;\n"
+  "using b;\n"
+  "using e;\n"
+  "using a;\n"
+  "using c;"));
+
+  EXPECT_EQ("#include \n"
+"using ::std::endl;\n"
+"using std::cin;\n"
+"using std::cout;\n"
+"int main();",
+sortUsingDeclarations("#include \n"
+  "using std::cout;\n"
+  "using std::cin;\n"
+  "using ::std::endl;\n"
+  "int main();"));
+}
+
+TEST_F(UsingDeclarationsSorterTest, BreaksOnEmptyLines) {
+  EXPECT_EQ("using b;\n"
+"using c;\n"
+"\n"
+"using a;\n"
+"using d;",
+sortUsingDeclarations("using c;\n"
+  "using b;\n"
+  "\n"
+  "using d;\n"
+  "using a;"));
+}
+
+TEST_F(UsingDeclarationsSorterTest,

[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added inline comments.



Comment at: lib/Format/UsingDeclarationsSorter.cpp:66
+  }
+  return HasIdentifier && Tok && Tok->isOneOf(tok::semi, tok::comma);
+}

Typz wrote:
> could also be followed by an assignment, in case of type alias:
> 
>   using foo = bar::foo;
Type aliases are in general not safe to permute, as in:
```
struct C {
  struct B {
struct A;
  };
};

using B = C::B;
using A = B::A;
```

Adding a test specifically for this.



https://reviews.llvm.org/D33823



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


[PATCH] D34351: Simplify TT_SelectorName assignment logic

2017-06-19 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: klimek.

While trying to understand TT_SelectorName, I found 2 redundant checks.
Removing them doesn't cause any tests to fail.


https://reviews.llvm.org/D34351

Files:
  lib/Format/TokenAnnotator.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -443,10 +443,9 @@
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
-(!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
+!Contexts.back().ColonIsDictLiteral) ||
Style.Language == FormatStyle::LK_Proto) &&
-  (Previous->Tok.getIdentifierInfo() ||
-   Previous->is(tok::string_literal)))
+  Previous->Tok.getIdentifierInfo())
 Previous->Type = TT_SelectorName;
   if (CurrentToken->is(tok::colon) ||
   Style.Language == FormatStyle::LK_JavaScript)


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -443,10 +443,9 @@
 if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
-(!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
+!Contexts.back().ColonIsDictLiteral) ||
Style.Language == FormatStyle::LK_Proto) &&
-  (Previous->Tok.getIdentifierInfo() ||
-   Previous->is(tok::string_literal)))
+  Previous->Tok.getIdentifierInfo())
 Previous->Type = TT_SelectorName;
   if (CurrentToken->is(tok::colon) ||
   Style.Language == FormatStyle::LK_JavaScript)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34441: [clang-format] Support text proto messages

2017-06-21 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 103352.
krasimir added a comment.

- Remove newline


https://reviews.llvm.org/D34441

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/CMakeLists.txt
  unittests/Format/FormatTestTextProto.cpp

Index: unittests/Format/FormatTestTextProto.cpp
===
--- /dev/null
+++ unittests/Format/FormatTestTextProto.cpp
@@ -0,0 +1,131 @@
+//===- unittest/Format/FormatTestProto.cpp ===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "FormatTestUtils.h"
+#include "clang/Format/Format.h"
+#include "llvm/Support/Debug.h"
+#include "gtest/gtest.h"
+
+#define DEBUG_TYPE "format-test"
+
+namespace clang {
+namespace format {
+
+class FormatTestTextProto : public ::testing::Test {
+protected:
+  static std::string format(llvm::StringRef Code, unsigned Offset,
+unsigned Length, const FormatStyle &Style) {
+DEBUG(llvm::errs() << "---\n");
+DEBUG(llvm::errs() << Code << "\n\n");
+std::vector Ranges(1, tooling::Range(Offset, Length));
+tooling::Replacements Replaces = reformat(Style, Code, Ranges);
+auto Result = applyAllReplacements(Code, Replaces);
+EXPECT_TRUE(static_cast(Result));
+DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+return *Result;
+  }
+
+  static std::string format(llvm::StringRef Code) {
+FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
+Style.ColumnLimit = 60; // To make writing tests easier.
+return format(Code, 0, Code.size(), Style);
+  }
+
+  static void verifyFormat(llvm::StringRef Code) {
+EXPECT_EQ(Code.str(), format(test::messUp(Code)));
+  }
+};
+
+TEST_F(FormatTestTextProto, KeepsTopLevelEntriesFittingALine) {
+  verifyFormat("field_a: OK field_b: OK field_c: OK field_d: OK field_e: OK");
+}
+
+TEST_F(FormatTestTextProto, SupportsMessageFields) {
+  verifyFormat("msg_field: {}");
+
+  verifyFormat("msg_field: {field_a: A}");
+
+  verifyFormat("msg_field: {field_a: \"OK\" field_b: 123}");
+
+  verifyFormat("msg_field: {\n"
+   "  field_a: 1\n"
+   "  field_b: OK\n"
+   "  field_c: \"OK\"\n"
+   "  field_d: 123\n"
+   "  field_e: 23\n"
+   "}");
+
+  verifyFormat("msg_field{}");
+
+  verifyFormat("msg_field{field_a: A}");
+
+  verifyFormat("msg_field{field_a: \"OK\" field_b: 123}");
+
+  verifyFormat("msg_field{\n"
+   "  field_a: 1\n"
+   "  field_b: OK\n"
+   "  field_c: \"OK\"\n"
+   "  field_d: 123\n"
+   "  field_e: 23.0\n"
+   "  field_f: false\n"
+   "  field_g: 'lala'\n"
+   "  field_h: 1234.567e-89\n"
+   "}");
+
+  verifyFormat("msg_field: {msg_field{field_a: 1}}");
+
+  verifyFormat("id: \"ala.bala\"\n"
+   "item{type: ITEM_A rank: 1 score: 90.0}\n"
+   "item{type: ITEM_B rank: 2 score: 70.5}\n"
+   "item{\n"
+   "  type: ITEM_A\n"
+   "  rank: 3\n"
+   "  score: 20.0\n"
+   "  description: \"the third item has a description\"\n"
+   "}");
+}
+
+TEST_F(FormatTestTextProto, AvoidsTopLevelBinPacking) {
+  verifyFormat("field_a: OK\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK");
+
+  verifyFormat("field_a: OK\n"
+   "field_b: \"OK\"\n"
+   "field_c: \"OK\"\n"
+   "msg_field: {field_d: 123}\n"
+   "field_e: OK\n"
+   "field_f: OK");
+
+  verifyFormat("field_a: OK\n"
+   "field_b: \"OK\"\n"
+   "field_c: \"OK\"\n"
+   "msg_field: {field_d: 123 field_e: OK}");
+}
+
+TEST_F(FormatTestTextProto, AddsNewlinesAfterTrailingComments) {
+  verifyFormat("field_a: OK  // Comment\n"
+   "field_b: 1");
+
+  verifyFormat("field_a: OK\n"
+   "msg_field: {\n"
+   "  field_b: OK  // Comment\n"
+   "}");
+
+  verifyFormat("field_a: OK\n"
+   "msg_field{\n"
+   "  field_b: OK  // Comment\n"
+   "}");
+}
+
+} // end namespace tooling
+} // end namespace clang
Index: unittests/Format/CMakeLists.txt
===
--- unittests/Format/CMakeLists.txt
+++ unittests/Format/CMakeLists.txt
@@ -11,6 +11,7 @@
   FormatTestObjC.cpp
   FormatTestProto.cpp
   FormatTestSelective.cpp
+  FormatTe

[PATCH] D34441: [clang-format] Support text proto messages

2017-06-21 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir added a comment.

Tests for `<>`-style message fields are missing because I discovered that they 
don't really work in a multiline setting in proto options anyways. I'll address 
this problem separately.


https://reviews.llvm.org/D34441



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


[PATCH] D33823: [clang-format] Support sorting using declarations

2017-06-21 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL305901: [clang-format] Support sorting using declarations 
(authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D33823?vs=103032&id=103359#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D33823

Files:
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/CMakeLists.txt
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
  cfe/trunk/lib/Format/UsingDeclarationsSorter.h
  cfe/trunk/unittests/Format/CMakeLists.txt
  cfe/trunk/unittests/Format/UsingDeclarationsSorterTest.cpp

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1641,6 +1641,16 @@
   ArrayRef Ranges,
   StringRef FileName = "");
 
+/// \brief Sort consecutive using declarations in the given \p Ranges in
+/// \p Code.
+///
+/// Returns the ``Replacements`` that sort the using declarations in all
+/// \p Ranges in \p Code.
+tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
+StringRef Code,
+ArrayRef Ranges,
+StringRef FileName = "");
+
 /// \brief Returns the ``LangOpts`` that the formatter expects you to set.
 ///
 /// \param Style determines specific settings for lexing mode.
Index: cfe/trunk/lib/Format/CMakeLists.txt
===
--- cfe/trunk/lib/Format/CMakeLists.txt
+++ cfe/trunk/lib/Format/CMakeLists.txt
@@ -13,6 +13,7 @@
   TokenAnnotator.cpp
   UnwrappedLineFormatter.cpp
   UnwrappedLineParser.cpp
+  UsingDeclarationsSorter.cpp
   WhitespaceManager.cpp
 
   LINK_LIBS
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -23,6 +23,7 @@
 #include "TokenAnnotator.h"
 #include "UnwrappedLineFormatter.h"
 #include "UnwrappedLineParser.h"
+#include "UsingDeclarationsSorter.h"
 #include "WhitespaceManager.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
@@ -1943,6 +1944,16 @@
   return Fix.process();
 }
 
+tooling::Replacements sortUsingDeclarations(const FormatStyle &Style,
+StringRef Code,
+ArrayRef Ranges,
+StringRef FileName) {
+  std::unique_ptr Env =
+  Environment::CreateVirtualEnvironment(Code, FileName, Ranges);
+  UsingDeclarationsSorter Sorter(*Env, Style);
+  return Sorter.process();
+}
+
 LangOptions getFormattingLangOpts(const FormatStyle &Style) {
   LangOptions LangOpts;
   LangOpts.CPlusPlus = 1;
Index: cfe/trunk/lib/Format/UsingDeclarationsSorter.h
===
--- cfe/trunk/lib/Format/UsingDeclarationsSorter.h
+++ cfe/trunk/lib/Format/UsingDeclarationsSorter.h
@@ -0,0 +1,37 @@
+//===--- UsingDeclarationsSorter.h --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///
+/// \file
+/// \brief This file declares UsingDeclarationsSorter, a TokenAnalyzer that
+/// sorts consecutive using declarations.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_LIB_FORMAT_USINGDECLARATIONSSORTER_H
+#define LLVM_CLANG_LIB_FORMAT_USINGDECLARATIONSSORTER_H
+
+#include "TokenAnalyzer.h"
+
+namespace clang {
+namespace format {
+
+class UsingDeclarationsSorter : public TokenAnalyzer {
+public:
+  UsingDeclarationsSorter(const Environment &Env, const FormatStyle &Style);
+
+  tooling::Replacements
+  analyze(TokenAnnotator &Annotator,
+  SmallVectorImpl &AnnotatedLines,
+  FormatTokenLexer &Tokens) override;
+};
+
+} // end namespace format
+} // end namespace clang
+
+#endif
Index: cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
===
--- cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
+++ cfe/trunk/lib/Format/UsingDeclarationsSorter.cpp
@@ -0,0 +1,144 @@
+//===--- UsingDeclarationsSorter.cpp *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+///

[PATCH] D34457: [clang-format] Update style documentation, NFC

2017-06-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306089: [clang-format] Update style documentation, NFC 
(authored by krasimir).

Changed prior to commit:
  https://reviews.llvm.org/D34457?vs=103399&id=103698#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34457

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/include/clang/Format/Format.h

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -652,12 +652,12 @@
 ///   struct foo
 ///   {
 /// int x;
-///   }
+///   };
 ///
 ///   false:
 ///   struct foo {
 /// int x;
-///   }
+///   };
 /// \endcode
 bool AfterStruct;
 /// \brief Wrap union definitions.
@@ -733,16 +733,15 @@
   ///? firstValue
   ///: SecondValueVeryVeryVeryVeryLong;
   ///
-  ///true:
+  ///false:
   ///veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ?
   ///firstValue :
   ///SecondValueVeryVeryVeryVeryLong;
   /// \endcode
   bool BreakBeforeTernaryOperators;
 
   /// \brief Different ways to break initializers.
-  enum BreakConstructorInitializersStyle
-  {
+  enum BreakConstructorInitializersStyle {
 /// Break constructor initializers before the colon and after the commas.
 /// \code
 /// Constructor()
@@ -767,7 +766,7 @@
 BCIS_AfterColon
   };
 
-  /// \brief The constructor initializers style to use..
+  /// \brief The constructor initializers style to use.
   BreakConstructorInitializersStyle BreakConstructorInitializers;
 
   /// \brief Break after each annotation on a field in Java files.
Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst
@@ -309,12 +309,28 @@
   * ``SFS_None`` (in configuration: ``None``)
 Never merge functions into a single line.
 
+  * ``SFS_InlineOnly`` (in configuration: ``InlineOnly``)
+Only merge functions defined inside a class. Same as "inline",
+except it does not implies "empty": i.e. top level empty functions
+are not merged either.
+
+.. code-block:: c++
+
+  class Foo {
+void f() { foo(); }
+  };
+  void f() {
+foo();
+  }
+  void f() {
+  }
+
   * ``SFS_Empty`` (in configuration: ``Empty``)
 Only merge empty functions.
 
 .. code-block:: c++
 
-  void f() { bar(); }
+  void f() {}
   void f2() {
 bar2();
   }
@@ -327,6 +343,10 @@
   class Foo {
 void f() { foo(); }
   };
+  void f() {
+foo();
+  }
+  void f() {}
 
   * ``SFS_All`` (in configuration: ``All``)
 Merge all functions fitting on a single line.
@@ -521,11 +541,11 @@
   .. code-block:: c++
 
 true:
-class foo
-{};
+class foo {};
 
 false:
-class foo {};
+class foo
+{};
 
   * ``bool AfterControlStatement`` Wrap control statements (``if``/``for``/``while``/``switch``/..).
 
@@ -659,6 +679,18 @@
 
   * ``bool IndentBraces`` Indent the wrapped braces themselves.
 
+  * ``bool SplitEmptyFunctionBody`` If ``false``, empty function body can be put on a single line.
+  This option is used only if the opening brace of the function has
+  already been wrapped, i.e. the `AfterFunction` brace wrapping mode is
+  set, and the function could/should not be put on a single line (as per
+  `AllowShortFunctionsOnASingleLine` and constructor formatting options).
+
+  .. code-block:: c++
+
+int f()   vs.   inf f()
+{}  {
+}
+
 
 **BreakAfterJavaFieldAnnotations** (``bool``)
   Break after each annotation on a field in Java files.
@@ -899,17 +931,40 @@
  firstValue :
  SecondValueVeryVeryVeryVeryLong;
 
-**BreakConstructorInitializersBeforeComma** (``bool``)
-  Always break constructor initializers before commas and align
-  the commas with the colon.
+**BreakConstructorInitializers** (``BreakConstructorInitializersStyle``)
+  The constructor initializers style to use.
+
+  Possible values:
+
+  * ``BCIS_BeforeColon`` (in configuration: ``BeforeColon``)
+Break constructor initializers before the colon and after the commas.
+
+.. code-block:: c++
+
+Constructor()
+: initializer1(),
+  initializer2()
+
+  * ``BCIS_BeforeComma`` (in configuration: ``BeforeComma``)
+Break constructor initializers before the colon and commas, and align
+the commas with the colon.
+
+.. code-block:: c++
+
+Constructor()
+: initializer1()
+, initializer2()
+
+  * ``BCIS_AfterColon`` (in configuration: ``AfterColon``)
+Break constructor initializers after the colon and commas.
+
+.. code-block:: c++
+
+Constructor() :
+initializer1(

  1   2   3   4   5   6   7   8   9   10   >