r239531 - clang-format: Make SFS_Inline imply SFS_Empty.

Daniel Jasper djasper at google.com
Thu Jun 11 06:31:45 PDT 2015


Author: djasper
Date: Thu Jun 11 08:31:45 2015
New Revision: 239531

URL: http://llvm.org/viewvc/llvm-project?rev=239531&view=rev
Log:
clang-format: Make SFS_Inline imply SFS_Empty.

In the long run, these two might be independent or we might to only
allow specific combinations. Until we have a corresponding request,
however, it is hard to do the right thing and choose the right
configuration options. Thus, just don't touch the options yet and
just modify the behavior slightly.

Modified:
    cfe/trunk/docs/ClangFormatStyleOptions.rst
    cfe/trunk/include/clang/Format/Format.h
    cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/docs/ClangFormatStyleOptions.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ClangFormatStyleOptions.rst?rev=239531&r1=239530&r2=239531&view=diff
==============================================================================
--- cfe/trunk/docs/ClangFormatStyleOptions.rst (original)
+++ cfe/trunk/docs/ClangFormatStyleOptions.rst Thu Jun 11 08:31:45 2015
@@ -155,23 +155,21 @@ the configuration (without a prefix: ``A
 
   This applies to round brackets (parentheses), angle brackets and square
   brackets. This will result in formattings like
-
-  .. code-block:: c++
-
-    someLongFunction(argument1,
-    argument2);
+  \code
+  someLongFunction(argument1,
+  argument2);
+  \endcode
 
 **AlignConsecutiveAssignments** (``bool``)
   If ``true``, aligns consecutive assignments.
 
   This will align the assignment operators of consecutive lines. This
   will result in formattings like
-
-  .. code-block:: c++
-
-    int aaaa = 12;
-    int b    = 23;
-    int ccc  = 23;
+  \code
+  int aaaa = 12;
+  int b    = 23;
+  int ccc  = 23;
+  \endcode
 
 **AlignEscapedNewlinesLeft** (``bool``)
   If ``true``, aligns escaped newlines as far left as possible.
@@ -204,10 +202,10 @@ the configuration (without a prefix: ``A
 
   * ``SFS_None`` (in configuration: ``None``)
     Never merge functions into a single line.
-  * ``SFS_Inline`` (in configuration: ``Inline``)
-    Only merge functions defined inside a class.
   * ``SFS_Empty`` (in configuration: ``Empty``)
     Only merge empty functions.
+  * ``SFS_Inline`` (in configuration: ``Inline``)
+    Only merge functions defined inside a class. Implies "empty".
   * ``SFS_All`` (in configuration: ``All``)
     Merge all functions fitting on a single line.
 
@@ -343,11 +341,10 @@ the configuration (without a prefix: ``A
   instead of as function calls.
 
   These are expected to be macros of the form:
-
-    .. code-block:: c++
-
-      FOREACH(<variable-declaration>, ...)
-      <loop-body>
+  \code
+  FOREACH(<variable-declaration>, ...)
+  <loop-body>
+  \endcode
 
   For example: BOOST_FOREACH.
 

Modified: cfe/trunk/include/clang/Format/Format.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=239531&r1=239530&r2=239531&view=diff
==============================================================================
--- cfe/trunk/include/clang/Format/Format.h (original)
+++ cfe/trunk/include/clang/Format/Format.h Thu Jun 11 08:31:45 2015
@@ -210,10 +210,10 @@ struct FormatStyle {
   enum ShortFunctionStyle {
     /// \brief Never merge functions into a single line.
     SFS_None,
-    /// \brief Only merge functions defined inside a class.
-    SFS_Inline,
     /// \brief Only merge empty functions.
     SFS_Empty,
+    /// \brief Only merge functions defined inside a class. Implies "empty".
+    SFS_Inline,
     /// \brief Merge all functions fitting on a single line.
     SFS_All,
   };

Modified: cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp?rev=239531&r1=239530&r2=239531&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineFormatter.cpp Thu Jun 11 08:31:45 2015
@@ -189,7 +189,7 @@ private:
     // If necessary, change to something smarter.
     bool MergeShortFunctions =
         Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_All ||
-        (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Empty &&
+        (Style.AllowShortFunctionsOnASingleLine >= FormatStyle::SFS_Empty &&
          I[1]->First->is(tok::r_brace)) ||
         (Style.AllowShortFunctionsOnASingleLine == FormatStyle::SFS_Inline &&
          TheLine->Level != 0);

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=239531&r1=239530&r2=239531&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jun 11 08:31:45 2015
@@ -252,6 +252,7 @@ TEST_F(FormatTestJS, FormatsFreestanding
                "  function inner2(a, b) { return a; }\n"
                "  inner2(a, b);\n"
                "}");
+  verifyFormat("function f() {}");
 }
 
 TEST_F(FormatTestJS, ArrayLiterals) {
@@ -707,12 +708,9 @@ TEST_F(FormatTestJS, Modules) {
   verifyFormat("export function fn() {\n"
                "  return 'fn';\n"
                "}");
-  verifyFormat("export function A() {\n"
-               "}\n"
-               "export default function B() {\n"
-               "}\n"
-               "export function C() {\n"
-               "}");
+  verifyFormat("export function A() {}\n"
+               "export default function B() {}\n"
+               "export function C() {}");
   verifyFormat("export const x = 12;");
   verifyFormat("export default class X {}");
   verifyFormat("export {X, Y} from 'some/module.js';");
@@ -819,12 +817,12 @@ TEST_F(FormatTestJS, TypeArguments) {
   verifyFormat("foo<Y>(a);");
   verifyFormat("var x: X<Y>[];");
   verifyFormat("class C extends D<E> implements F<G>, H<I> {}");
-  verifyFormat("function f(a: List<any> = null) {\n}");
-  verifyFormat("function f(): List<any> {\n}");
+  verifyFormat("function f(a: List<any> = null) {}");
+  verifyFormat("function f(): List<any> {}");
 }
 
 TEST_F(FormatTestJS, OptionalTypes) {
-  verifyFormat("function x(a?: b, c?, d?) {\n}");
+  verifyFormat("function x(a?: b, c?, d?) {}");
   verifyFormat("class X {\n"
                "  y?: z;\n"
                "  z?;\n"
@@ -838,8 +836,7 @@ TEST_F(FormatTestJS, OptionalTypes) {
                "  aaaaaaaa?: string,\n"
                "  aaaaaaaaaaaaaaa?: boolean,\n"
                "  aaaaaa?: List<string>\n"
-               "}) {\n"
-               "}");
+               "}) {}");
 }
 
 TEST_F(FormatTestJS, IndexSignature) {





More information about the cfe-commits mailing list