Re: [PATCH] D11837: Add WebKit brace style configuration option.
lifted added a comment. In http://reviews.llvm.org/D11837#220408, @klimek wrote: Can you also fix the current code in getWebKitStyle? Yep, I've already done it. http://reviews.llvm.org/D11837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D11837: Add Qt brace style configuration option.
lifted added a comment. Hm, the referenced style guide doesn't say anything about namespaces. You're right. Futhermore, it's hard to find any namespaces in qt repos at all - Qt uses a macro for conditional compilation with namespaces. I also couldn't find anything in the qt source repo (just took a quick look though). Hm, I've just browsed through the qtcore and seen no evidence that qt uses attached braces everywhere but after classes and function. Qt use of style is inconsistent (sometimes even within a single file), and few examples I've looked at actually use something close to Mozilla style - they break on structs, enums, classes, and functions (http://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/tools/qchar.h?id=13c16bbd06e0034210ba2164f1be208c49a6e3a7). My bad, I read the Qt Brace style description and decided that it could fit my current project style (we break after functions, and some people also break after classes). But it turned out that Qt style is not as well defined as I thought, so I'm out of luck. I believe it's better to abandon this patch. I hope I will find some time to introduce extra configuration options to override pre-defined brace styles, as it was discussed long time ago. http://reviews.llvm.org/D11837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D11837: Add WebKit brace style configuration option.
lifted added a comment. I had commit access earlier, but I haven't tried it for long time. I'll ask for help if there are any problems. http://reviews.llvm.org/D11837 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D11837: Add WebKit brace style configuration option.
This revision was automatically updated to reflect the committed changes. Closed by commit rL26: Add WebKit brace style configuration option. (authored by lifted). Changed prior to commit: http://reviews.llvm.org/D11837?vs=31660id=31665#toc Repository: rL LLVM http://reviews.llvm.org/D11837 Files: cfe/trunk/docs/ClangFormatStyleOptions.rst cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTest.cpp Index: cfe/trunk/docs/ClangFormatStyleOptions.rst === --- cfe/trunk/docs/ClangFormatStyleOptions.rst +++ cfe/trunk/docs/ClangFormatStyleOptions.rst @@ -279,13 +279,15 @@ Like ``Attach``, but break before braces on enum, function, and record definitions. * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) -Like ``Attach``, but break before function definitions, and 'else'. +Like ``Attach``, but break before function definitions, 'catch', and 'else'. * ``BS_Allman`` (in configuration: ``Allman``) Always break before braces. * ``BS_GNU`` (in configuration: ``GNU``) Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions. + * ``BS_WebKit`` (in configuration: ``WebKit``) +Like ``Attach``, but break before functions. **BreakBeforeTernaryOperators** (``bool``) Index: cfe/trunk/include/clang/Format/Format.h === --- cfe/trunk/include/clang/Format/Format.h +++ cfe/trunk/include/clang/Format/Format.h @@ -169,14 +169,16 @@ /// Like ``Attach``, but break before braces on enum, function, and record /// definitions. BS_Mozilla, -/// Like \c Attach, but break before function definitions, and 'else'. +/// Like \c Attach, but break before function definitions, 'catch', and 'else'. BS_Stroustrup, /// Always break before braces. BS_Allman, /// Always break before braces and add an extra level of indentation to /// braces of control statements, not to those of class, function /// or other definitions. -BS_GNU +BS_GNU, +/// Like ``Attach``, but break before functions. +BS_WebKit }; /// \brief The brace breaking style to use. Index: cfe/trunk/lib/Format/Format.cpp === --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -98,6 +98,7 @@ IO.enumCase(Value, Stroustrup, FormatStyle::BS_Stroustrup); IO.enumCase(Value, Allman, FormatStyle::BS_Allman); IO.enumCase(Value, GNU, FormatStyle::BS_GNU); +IO.enumCase(Value, WebKit, FormatStyle::BS_WebKit); } }; @@ -504,7 +505,7 @@ Style.AlignOperands = false; Style.AlignTrailingComments = false; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; - Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup; + Style.BreakBeforeBraces = FormatStyle::BS_WebKit; Style.BreakConstructorInitializersBeforeComma = true; Style.Cpp11BracedListStyle = false; Style.ColumnLimit = 0; Index: cfe/trunk/unittests/Format/FormatTest.cpp === --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -2329,13 +2329,16 @@ TEST_F(FormatTest, FormatTryCatchBraceStyles) { FormatStyle Style = getLLVMStyle(); - Style.BreakBeforeBraces = FormatStyle::BS_Attach; - verifyFormat(try {\n - // something\n - } catch (...) {\n - // something\n - }, - Style); + for (auto BraceStyle : + {FormatStyle::BS_Attach, FormatStyle::BS_Mozilla, FormatStyle::BS_WebKit}) { +Style.BreakBeforeBraces = BraceStyle; +verifyFormat(try {\n + // something\n + } catch (...) {\n + // something\n + }, + Style); + } Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup; verifyFormat(try {\n // something\n @@ -9060,6 +9063,45 @@ #endif, GNUBraceStyle); } + +TEST_F(FormatTest, WebKitBraceBreaking) { + FormatStyle WebKitBraceStyle = getLLVMStyle(); + WebKitBraceStyle.BreakBeforeBraces = FormatStyle::BS_WebKit; + verifyFormat(namespace a {\n + class A {\n + void f()\n + {\n + if (true) {\n + a();\n + b();\n + }\n + }\n + void g() { return; }\n + };\n + enum E {\n + A,\n + // foo\n + B,\n + C\n + };\n + struct B {\n + int x;\n + };\n + }\n, +
r244446 - Add WebKit brace style configuration option.
Author: lifted Date: Mon Aug 10 08:43:19 2015 New Revision: 26 URL: http://llvm.org/viewvc/llvm-project?rev=26view=rev Log: Add WebKit brace style configuration option. Summary: Add brace style `BS_WebKit` as described on https://www.webkit.org/coding/coding-style.html: * Function definitions: place each brace on its own line. * Other braces: place the open brace on the line preceding the code block; place the close brace on its own line. Set brace style used in `getWebKitStyle()` to the newly added `BS_WebKit`. Reviewers: djasper, klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D11837 Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=26r1=25r2=26view=diff == --- cfe/trunk/docs/ClangFormatStyleOptions.rst (original) +++ cfe/trunk/docs/ClangFormatStyleOptions.rst Mon Aug 10 08:43:19 2015 @@ -279,13 +279,15 @@ the configuration (without a prefix: ``A Like ``Attach``, but break before braces on enum, function, and record definitions. * ``BS_Stroustrup`` (in configuration: ``Stroustrup``) -Like ``Attach``, but break before function definitions, and 'else'. +Like ``Attach``, but break before function definitions, 'catch', and 'else'. * ``BS_Allman`` (in configuration: ``Allman``) Always break before braces. * ``BS_GNU`` (in configuration: ``GNU``) Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions. + * ``BS_WebKit`` (in configuration: ``WebKit``) +Like ``Attach``, but break before functions. **BreakBeforeTernaryOperators** (``bool``) Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=26r1=25r2=26view=diff == --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Mon Aug 10 08:43:19 2015 @@ -169,14 +169,16 @@ struct FormatStyle { /// Like ``Attach``, but break before braces on enum, function, and record /// definitions. BS_Mozilla, -/// Like \c Attach, but break before function definitions, and 'else'. +/// Like \c Attach, but break before function definitions, 'catch', and 'else'. BS_Stroustrup, /// Always break before braces. BS_Allman, /// Always break before braces and add an extra level of indentation to /// braces of control statements, not to those of class, function /// or other definitions. -BS_GNU +BS_GNU, +/// Like ``Attach``, but break before functions. +BS_WebKit }; /// \brief The brace breaking style to use. Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=26r1=25r2=26view=diff == --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Mon Aug 10 08:43:19 2015 @@ -98,6 +98,7 @@ template struct ScalarEnumerationTrai IO.enumCase(Value, Stroustrup, FormatStyle::BS_Stroustrup); IO.enumCase(Value, Allman, FormatStyle::BS_Allman); IO.enumCase(Value, GNU, FormatStyle::BS_GNU); +IO.enumCase(Value, WebKit, FormatStyle::BS_WebKit); } }; @@ -504,7 +505,7 @@ FormatStyle getWebKitStyle() { Style.AlignOperands = false; Style.AlignTrailingComments = false; Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All; - Style.BreakBeforeBraces = FormatStyle::BS_Stroustrup; + Style.BreakBeforeBraces = FormatStyle::BS_WebKit; Style.BreakConstructorInitializersBeforeComma = true; Style.Cpp11BracedListStyle = false; Style.ColumnLimit = 0; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=26r1=25r2=26view=diff == --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Aug 10 08:43:19 2015 @@ -2329,13 +2329,16 @@ TEST_F(FormatTest, IncompleteTryCatchBlo TEST_F(FormatTest, FormatTryCatchBraceStyles) { FormatStyle Style = getLLVMStyle(); - Style.BreakBeforeBraces = FormatStyle::BS_Attach; - verifyFormat(try {\n - // something\n - } catch (...) {\n - // something\n - }, - Style); + for (auto BraceStyle : +