[PATCH] D47515: [clang-format] Process line's children once in guessIsObjC

2018-05-30 Thread Attila via Phabricator via cfe-commits
Uran198 created this revision.
Uran198 added reviewers: djasper, klimek.

Repository:
  rC Clang

https://reviews.llvm.org/D47515

Files:
  lib/Format/Format.cpp


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1558,9 +1558,9 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-if (guessIsObjC(Line->Children, Keywords))
-  return true;
   }
+  if (guessIsObjC(Line->Children, Keywords))
+return true;
 }
 return false;
   }


Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -1558,9 +1558,9 @@
TT_ObjCMethodSpecifier, TT_ObjCProperty)) {
   return true;
 }
-if (guessIsObjC(Line->Children, Keywords))
-  return true;
   }
+  if (guessIsObjC(Line->Children, Keywords))
+return true;
 }
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47519: [clang-format] Detect amp type as TT_PointerOrReference in function annotations

2018-05-30 Thread Attila via Phabricator via cfe-commits
Uran198 created this revision.
Uran198 added reviewers: klimek, krasimir, djasper.

Repository:
  rC Clang

https://reviews.llvm.org/D47519

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6156,6 +6156,12 @@
"operator()() && {}");
   verifyGoogleFormat("template \n"
  "auto x() & -> int {}");
+  verifyGoogleFormat("template \n"
+ "auto x() const& noexcept -> bool {}");
+  verifyGoogleFormat("template \n"
+ "void f() &noexcept {}");
+  verifyGoogleFormat("template \n"
+ "auto operator+() &MACRO {}");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1563,7 +1563,7 @@
 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::coloncolon))
+if (PrevToken->isOneOf(tok::coloncolon, tok::kw_const))
   return TT_PointerOrReference;
 
 if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
@@ -1585,7 +1585,9 @@
   FormatToken *TokenBeforeMatchingParen =
   PrevToken->MatchingParen->getPreviousNonComment();
   if (TokenBeforeMatchingParen &&
-  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+  TokenBeforeMatchingParen->isOneOf(
+  tok::kw_typeof, tok::kw_decltype, TT_FunctionDeclarationName,
+  TT_StartOfName, TT_OverloadedOperator))
 return TT_PointerOrReference;
 }
 


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6156,6 +6156,12 @@
"operator()() && {}");
   verifyGoogleFormat("template \n"
  "auto x() & -> int {}");
+  verifyGoogleFormat("template \n"
+ "auto x() const& noexcept -> bool {}");
+  verifyGoogleFormat("template \n"
+ "void f() &noexcept {}");
+  verifyGoogleFormat("template \n"
+ "auto operator+() &MACRO {}");
 }
 
 TEST_F(FormatTest, UnderstandsAttributes) {
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1563,7 +1563,7 @@
 (NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
   return TT_PointerOrReference;
 
-if (PrevToken->is(tok::coloncolon))
+if (PrevToken->isOneOf(tok::coloncolon, tok::kw_const))
   return TT_PointerOrReference;
 
 if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
@@ -1585,7 +1585,9 @@
   FormatToken *TokenBeforeMatchingParen =
   PrevToken->MatchingParen->getPreviousNonComment();
   if (TokenBeforeMatchingParen &&
-  TokenBeforeMatchingParen->isOneOf(tok::kw_typeof, tok::kw_decltype))
+  TokenBeforeMatchingParen->isOneOf(
+  tok::kw_typeof, tok::kw_decltype, TT_FunctionDeclarationName,
+  TT_StartOfName, TT_OverloadedOperator))
 return TT_PointerOrReference;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47520: [clang-format] Allow break between question and lambda

2018-05-30 Thread Attila via Phabricator via cfe-commits
Uran198 created this revision.
Uran198 added reviewers: djasper, klimek.

Before the change clang-format would break and make no reformatting.


Repository:
  rC Clang

https://reviews.llvm.org/D47520

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4682,6 +4682,14 @@
   "aa =  ? aa ? 
a\n"
   "   : aa\n"
   "  : ;");
+  verifyFormat(
+  "aa =  ?\n"
+  "  [&]() { //\n"
+  "return true;\n"
+  "  }()\n"
+  "  ? \n"
+  "  : aaa\n"
+  "  : ;");
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackArguments = false;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3015,6 +3015,8 @@
 return false;
   if (Right.is(TT_ConditionalExpr) || Right.is(tok::question))
 return Style.BreakBeforeTernaryOperators;
+  if (Left.is(tok::question) && Right.is(TT_LambdaLSquare))
+return true;
   if (Left.is(TT_ConditionalExpr) || Left.is(tok::question))
 return !Style.BreakBeforeTernaryOperators;
   if (Right.is(TT_InheritanceColon))


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -4682,6 +4682,14 @@
   "aa =  ? aa ? a\n"
   "   : aa\n"
   "  : ;");
+  verifyFormat(
+  "aa =  ?\n"
+  "  [&]() { //\n"
+  "return true;\n"
+  "  }()\n"
+  "  ? \n"
+  "  : aaa\n"
+  "  : ;");
 
   FormatStyle NoBinPacking = getLLVMStyle();
   NoBinPacking.BinPackArguments = false;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3015,6 +3015,8 @@
 return false;
   if (Right.is(TT_ConditionalExpr) || Right.is(tok::question))
 return Style.BreakBeforeTernaryOperators;
+  if (Left.is(tok::question) && Right.is(TT_LambdaLSquare))
+return true;
   if (Left.is(TT_ConditionalExpr) || Left.is(tok::question))
 return !Style.BreakBeforeTernaryOperators;
   if (Right.is(TT_InheritanceColon))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47521: [clang-format] Fix parsing lambdas with noexcept

2018-05-30 Thread Attila via Phabricator via cfe-commits
Uran198 created this revision.
Uran198 added reviewers: klimek, djasper.

Repository:
  rC Clang

https://reviews.llvm.org/D47521

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11522,6 +11522,12 @@
"  ;\n"
"};");
 
+  verifyFormat("if (a && []() noexcept {\n"
+   "  doo_dah();\n"
+   "  doo_dah();\n"
+   "}()) {\n"
+   "}");
+
   // Lambdas with complex multiline introducers.
   verifyFormat(
   "a.(\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1387,6 +1387,7 @@
 case tok::amp:
 case tok::star:
 case tok::kw_const:
+case tok::kw_noexcept:
 case tok::comma:
 case tok::less:
 case tok::greater:


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -11522,6 +11522,12 @@
"  ;\n"
"};");
 
+  verifyFormat("if (a && []() noexcept {\n"
+   "  doo_dah();\n"
+   "  doo_dah();\n"
+   "}()) {\n"
+   "}");
+
   // Lambdas with complex multiline introducers.
   verifyFormat(
   "a.(\n"
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1387,6 +1387,7 @@
 case tok::amp:
 case tok::star:
 case tok::kw_const:
+case tok::kw_noexcept:
 case tok::comma:
 case tok::less:
 case tok::greater:
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47577: [clang-format] Separate block comments with CRLF correctly

2018-05-31 Thread Attila via Phabricator via cfe-commits
Uran198 created this revision.
Uran198 added a reviewer: alexfh.
Herald added subscribers: cfe-commits, klimek.

When formatting the following string:

  "/*\r\n"
  " * Comment with\r\n"
  "\r\n"
  " * blanks.\r\n"
  " */\r\n"

clang-format produced:

  "/*\r\n"
  " * Comment with\r\n"
  "\r\r\n"
  " * blanks.\r\n"
  " */\r\n"

And when formatting

  "#define A(\\\r\n"
  "x) /* \\\r\n"
  "a comment \\\r\n"
  "inside */ \\\r\n"
  "   f();"

with line length 17, clang-format produced:

  "#define A(  \\\r"
  "x) /* \\ \\\r"
  "a comment \\ \\\r"
  "inside */   \\\r"
  "   f();"

So in one case it added additional `\r` instead of replacing with the blank
line and in another it added additional newline escape character `\`.

After the change the result are respectively:

  "/*\r\n"
  " * Comment with\r\n"
  "\r\n"
  " * blanks
  .\r\
  n"
  " */\r\n"

and

  "#define A(x) /* \\\r\n"
  "  a comment \\\r\n"
  "  inside */ \\\r\n"
  "  f();"


Repository:
  rC Clang

https://reviews.llvm.org/D47577

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


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -472,6 +472,30 @@
  "  int jjj; /*b*/");
 }
 
+TEST_F(FormatTestComments, BlockCommentsWithCLRF) {
+  EXPECT_EQ("/*\r\n"
+" * Comment with\r\n"
+"\r\n"
+" * blanks.\r\n"
+" */\r\n"
+"void f() {}",
+format("/* \r\n"
+" * Comment with\r\n"
+" \r\n"
+" * blanks.\r\n"
+" */\r\n"
+"void f() {}"));
+  EXPECT_EQ("#define A(x) /* \\\r\n"
+"  a comment \\\r\n"
+"  inside */ \\\r\n"
+"  f();",
+format("#define A(x) /* \\\r\n"
+   "  a comment \\\r\n"
+   "  inside */ \\\r\n"
+   "  f();",
+   getLLVMStyleWithColumns(17)));
+}
+
 TEST_F(FormatTestComments, AlignsBlockComments) {
   EXPECT_EQ("/*\n"
 " * Really multi-line\n"
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -323,7 +323,8 @@
 
   StringRef TokenText(Tok.TokenText);
   assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
-  TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
+  TokenText.substr(2, TokenText.size() - 4)
+  .split(Lines, TokenText.count('\r') > 0 ? "\r\n" : "\n");
 
   int IndentDelta = StartColumn - OriginalStartColumn;
   Content.resize(Lines.size());


Index: unittests/Format/FormatTestComments.cpp
===
--- unittests/Format/FormatTestComments.cpp
+++ unittests/Format/FormatTestComments.cpp
@@ -472,6 +472,30 @@
  "  int jjj; /*b*/");
 }
 
+TEST_F(FormatTestComments, BlockCommentsWithCLRF) {
+  EXPECT_EQ("/*\r\n"
+" * Comment with\r\n"
+"\r\n"
+" * blanks.\r\n"
+" */\r\n"
+"void f() {}",
+format("/* \r\n"
+" * Comment with\r\n"
+" \r\n"
+" * blanks.\r\n"
+" */\r\n"
+"void f() {}"));
+  EXPECT_EQ("#define A(x) /* \\\r\n"
+"  a comment \\\r\n"
+"  inside */ \\\r\n"
+"  f();",
+format("#define A(x) /* \\\r\n"
+   "  a comment \\\r\n"
+   "  inside */ \\\r\n"
+   "  f();",
+   getLLVMStyleWithColumns(17)));
+}
+
 TEST_F(FormatTestComments, AlignsBlockComments) {
   EXPECT_EQ("/*\n"
 " * Really multi-line\n"
Index: lib/Format/BreakableToken.cpp
===
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -323,7 +323,8 @@
 
   StringRef TokenText(Tok.TokenText);
   assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
-  TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
+  TokenText.substr(2, TokenText.size() - 4)
+  .split(Lines, TokenText.count('\r') > 0 ? "\r\n" : "\n");
 
   int IndentDelta = StartColumn - OriginalStartColumn;
   Content.resize(Lines.size());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits