[SCM] WebKit Debian packaging branch, webkit-1.1, updated. upstream/1.1.19-706-ge5415e9

eric at webkit.org eric at webkit.org
Thu Feb 4 21:30:48 UTC 2010


The following commit has been merged in the webkit-1.1 branch:
commit 80d99a97767a9df31d30797f261087483e851dcc
Author: eric at webkit.org <eric at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jan 28 08:29:05 2010 +0000

    2010-01-28  Anton Muhin  <antonm at chromium.org>
    
            Reviewed by Shinichiro Hamaji.
    
            Improve treatment of conditions and rest of the line for if, else, switch and alikes
            https://bugs.webkit.org/show_bug.cgi?id=34173
    
            * Scripts/webkitpy/style/cpp_style.py:
            * Scripts/webkitpy/style/cpp_style_unittest.py:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@53989 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 6cc26f3..f28c2b3 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,13 @@
+2010-01-28  Anton Muhin  <antonm at chromium.org>
+
+        Reviewed by Shinichiro Hamaji.
+
+        Improve treatment of conditions and rest of the line for if, else, switch and alikes
+        https://bugs.webkit.org/show_bug.cgi?id=34173
+
+        * Scripts/webkitpy/style/cpp_style.py:
+        * Scripts/webkitpy/style/cpp_style_unittest.py:
+
 2010-01-28  Joe Mason  <jmason at rim.com>
 
         Reviewed by Adam Barth.
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/cpp.py b/WebKitTools/Scripts/webkitpy/style/processors/cpp.py
index 95360f7..0ae2f6b 100644
--- a/WebKitTools/Scripts/webkitpy/style/processors/cpp.py
+++ b/WebKitTools/Scripts/webkitpy/style/processors/cpp.py
@@ -152,6 +152,31 @@ def subn(pattern, replacement, s):
     return _regexp_compile_cache[pattern].subn(replacement, s)
 
 
+def up_to_unmatched_closing_paren(s):
+    """Splits a string into two parts up to first unmatched ')'.
+
+    Args:
+      s: a string which is a substring of line after '('
+      (e.g., "a == (b + c))").
+
+    Returns:
+      A pair of strings (prefix before first unmatched ')',
+      reminder of s after first unmatched ')'), e.g.,
+      up_to_unmatched_closing_paren("a == (b + c)) { ")
+      returns "a == (b + c)", " {".
+      Returns None, None if there is no unmatched ')'
+
+    """
+    i = 1
+    for pos, c in enumerate(s):
+      if c == '(':
+        i += 1
+      elif c == ')':
+        i -= 1
+        if i == 0:
+          return s[:pos], s[pos + 1:]
+    return None, None
+
 class _IncludeState(dict):
     """Tracks line numbers for includes, and the order in which includes appear.
 
@@ -1309,19 +1334,32 @@ def check_spacing(filename, clean_lines, line_number, error):
     # there should either be zero or one spaces inside the parens.
     # We don't want: "if ( foo)" or "if ( foo   )".
     # Exception: "for ( ; foo; bar)" and "for (foo; bar; )" are allowed.
-    matched = search(r'\b(if|for|foreach|while|switch)\s*\(([ ]*)(.).*[^ ]+([ ]*)\)\s*{\s*$',
-                     line)
+    matched = search(r'\b(?P<statement>if|for|foreach|while|switch)\s*\((?P<reminder>.*)$', line)
     if matched:
-        if len(matched.group(2)) != len(matched.group(4)):
-            if not (matched.group(3) == ';'
-                    and len(matched.group(2)) == 1 + len(matched.group(4))
-                    or not matched.group(2) and search(r'\bfor\s*\(.*; \)', line)):
-                error(line_number, 'whitespace/parens', 5,
-                      'Mismatching spaces inside () in %s' % matched.group(1))
-        if not len(matched.group(2)) in [0, 1]:
-            error(line_number, 'whitespace/parens', 5,
-                  'Should have zero or one spaces inside ( and ) in %s' %
-                  matched.group(1))
+        statement = matched.group('statement')
+        condition, rest = up_to_unmatched_closing_paren(matched.group('reminder'))
+        if condition is not None:
+            condition_match = search(r'(?P<leading>[ ]*)(?P<separator>.).*[^ ]+(?P<trailing>[ ]*)', condition)
+            if condition_match:
+                n_leading = len(condition_match.group('leading'))
+                n_trailing = len(condition_match.group('trailing'))
+                if n_leading != n_trailing:
+                    for_exception = statement == 'for' and (
+                        (condition.startswith(' ;') and n_trailing == 0) or
+                        (condition.endswith('; ')   and n_leading == 0))
+                    if not for_exception:
+                        error(line_number, 'whitespace/parens', 5,
+                              'Mismatching spaces inside () in %s' % statement)
+                if n_leading > 1:
+                    error(line_number, 'whitespace/parens', 5,
+                          'Should have zero or one spaces inside ( and ) in %s' %
+                          statement)
+
+            # Do not check for more than one command in macros
+            in_macro = match(r'\s*#define', line)
+            if not in_macro and not match(r'((\s*{\s*}?)|(\s*;?))\s*\\?$', rest):
+                error(line_number, 'whitespace/parens', 4,
+                      'More than one command on the same line in %s' % statement)
 
     # You should always have a space after a comma (either as fn arg or operator)
     if search(r',[^\s]', line):
diff --git a/WebKitTools/Scripts/webkitpy/style/processors/cpp_unittest.py b/WebKitTools/Scripts/webkitpy/style/processors/cpp_unittest.py
index 568ac16..2aa38f3 100644
--- a/WebKitTools/Scripts/webkitpy/style/processors/cpp_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/processors/cpp_unittest.py
@@ -1167,10 +1167,16 @@ class CppStyleTest(CppStyleTestBase):
                          '  [whitespace/parens] [5]')
         self.assert_lint('for (foo; ba; bar ) {', 'Mismatching spaces inside () in for'
                          '  [whitespace/parens] [5]')
+        self.assert_lint('for ((foo); (ba); (bar) ) {', 'Mismatching spaces inside () in for'
+                         '  [whitespace/parens] [5]')
         self.assert_lint('for (; foo; bar) {', '')
+        self.assert_lint('for (; (foo); (bar)) {', '')
         self.assert_lint('for ( ; foo; bar) {', '')
+        self.assert_lint('for ( ; (foo); (bar)) {', '')
         self.assert_lint('for ( ; foo; bar ) {', '')
+        self.assert_lint('for ( ; (foo); (bar) ) {', '')
         self.assert_lint('for (foo; bar; ) {', '')
+        self.assert_lint('for ((foo); (bar); ) {', '')
         self.assert_lint('foreach (foo, foos ) {', 'Mismatching spaces inside () in foreach'
                          '  [whitespace/parens] [5]')
         self.assert_lint('foreach ( foo, foos) {', 'Mismatching spaces inside () in foreach'
@@ -2998,12 +3004,15 @@ class WebKitStyleTest(CppStyleTestBase):
             '        doIt();\n',
             '')
         self.assert_multi_line_lint(
+            '    if (condition) \\\n'
+            '        doIt();\n',
+            '')
+        self.assert_multi_line_lint(
             '    x++; y++;',
             'More than one command on the same line  [whitespace/newline] [4]')
-        # FIXME: Make this fail.
-        # self.assert_multi_line_lint(
-        #     '    if (condition) doIt();\n',
-        #     '')
+        self.assert_multi_line_lint(
+            '    if (condition) doIt();\n',
+            'More than one command on the same line in if  [whitespace/parens] [4]')
 
         # 2. An else statement should go on the same line as a preceding
         #   close brace if one is present, else it should line up with the
@@ -3035,6 +3044,13 @@ class WebKitStyleTest(CppStyleTestBase):
             '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsController::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n',
             '')
         self.assert_multi_line_lint(
+            '#define TEST_ASSERT(expression) do { if ( !(expression)) { TestsController::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0)\n',
+            'Mismatching spaces inside () in if  [whitespace/parens] [5]')
+        # FIXME: currently we only check first conditional, so we cannot detect errors in next ones.
+        # self.assert_multi_line_lint(
+        #     '#define TEST_ASSERT(expression) do { if (!(expression)) { TestsController::shared().testFailed(__FILE__, __LINE__, #expression); return; } } while (0 )\n',
+        #     'Mismatching spaces inside () in if  [whitespace/parens] [5]')
+        self.assert_multi_line_lint(
             'if (condition) {\n'
             '    doSomething();\n'
             '    doSomethingAgain();\n'
@@ -3047,13 +3063,14 @@ class WebKitStyleTest(CppStyleTestBase):
         self.assert_multi_line_lint(
             'if (condition) doSomething(); else doSomethingElse();\n',
             ['More than one command on the same line  [whitespace/newline] [4]',
-             'Else clause should never be on same line as else (use 2 lines)  [whitespace/newline] [4]'])
-        # FIXME: Make this fail.
-        # self.assert_multi_line_lint(
-        #     'if (condition) doSomething(); else {\n'
-        #     '    doSomethingElse();\n'
-        #     '}\n',
-        #     '')
+             'Else clause should never be on same line as else (use 2 lines)  [whitespace/newline] [4]',
+             'More than one command on the same line in if  [whitespace/parens] [4]'])
+        self.assert_multi_line_lint(
+            'if (condition) doSomething(); else {\n'
+            '    doSomethingElse();\n'
+            '}\n',
+            ['More than one command on the same line in if  [whitespace/parens] [4]',
+             'One line control clauses should not use braces.  [whitespace/braces] [4]'])
 
         # 3. An else if statement should be written as an if statement
         #    when the prior if concludes with a return statement.

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list