[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Great! I will work on it :)


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

BraceWrapping.AfterExternC makes sense to me.


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

A new style, e.g. **BraceWrapping.AfterExternC** option is what we are 
considering right now. It would probably handle the problem. Leaving the line 
break as is might be indeed a bad idea :)


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Daniel Jasper via Phabricator via cfe-commits
djasper added a comment.

I am very strongly against a flag that just leaves the line break as is. What's 
the motivation?


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

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

Yes, I meant that it should at least be controlled by a flag. However, adding 
flags to clang-format requires careful consideration, we usually would accept 
options that are necessary for commonly used styles with style guides and with 
a community willing to support these options.

So, I'd like to get the feedback from @djasper about it.


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-11 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

ping


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-01 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a reviewer: krasimir.
PriMee added a subscriber: krasimir.
PriMee added a comment.

@krasimir Could you please tell me what did you mean in the comment:

> I am still not convinced about the extern part: some clients might prefer the 
> other style.

Do you suggest adding a new option, new style, like 
**BraceWrapping.AfterExtern** flag?


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: klimek.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **"extern C part"**

**Problem:**

Due to the lack of "brace wrapping extern" flag, clang format does parse the 
block after **extern** keyword moving the opening bracket to the header line 
**always**!

**Patch description:**

Added if statement handling the case when our **"extern block"** has the 
opening bracket in "non-header" line. Then forcing break before bracket.

**After fix:**

**CONFIG:**

  BreakBeforeBraces: Custom
  BraceWrapping: { 
  AfterClass: true, AfterControlStatement: true, AfterEnum: true, 
AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: 
true, BeforeCatch: true, BeforeElse: true 
  }

**BEFORE:**

  extern "C" 
  {
  #include 
  }

**AFTER:**

  extern "C" 
  {
  #include 
  }

**Remains the same!**

There is no brace wrapping flag that let us control opening brace's position. 
In case of other keywords (class, function, control statement etc.) we have 
opportunity to decide how should it look like. Here, we can't do it similarly. 
What we want is leaving braces **unformatted** (leave them as in the input), 
but what's more we still want to call **parseBlock** function. The only option 
is to set **MustBreakBefore** flag manually (only when needed, when the left 
brace is on non-header line, parseBlock does move it by default).


https://reviews.llvm.org/D37260

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


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1595,7 +1595,24 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {};");
+  EXPECT_EQ("extern \"C\" {\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\" {\n"
+   "int i = 42;\n"
+   "}"));
+  EXPECT_EQ("extern \"C\"\n" 
+"{\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\"\n" 
+   "{\n"
+   "int i = 42;\n"
+   "}"));
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  FormatTok->MustBreakBefore = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1595,7 +1595,24 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {};");
+  EXPECT_EQ("extern \"C\" {\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\" {\n"
+   "int i = 42;\n"
+   "}"));
+  EXPECT_EQ("extern \"C\"\n" 
+"{\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\"\n" 
+   "{\n"
+   "int i = 42;\n"
+   "}"));
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  FormatTok->MustBreakBefore = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits