[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

levin at chromium.org levin at chromium.org
Wed Dec 22 15:50:13 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 6ffd7a359855c0bf81f14659ccb1e6511f707261
Author: levin at chromium.org <levin at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Nov 14 04:11:00 2010 +0000

    check-webkit-style function detection doesn't detect indented functions declaractions.
    https://bugs.webkit.org/show_bug.cgi?id=49446
    
    Reviewed by Shinichiro Hamaji.
    
    Indented function declarations occur inside class definitions, so
    they are a pretty common (and worth detecting).
    
    * Scripts/webkitpy/style/checkers/cpp.py:
      Changed regex to allow indentation.
      Changed the function start detection to only happen when not in a
      function.
      Changed function end detection to work based on matching braces
      instead of finding a close brace at the beginning of the line.
      Fixed close_expression to do what it says when it doesn't find
      the close.
    * Scripts/webkitpy/style/checkers/cpp_unittest.py: Indented function test.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71976 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index d532e8f..bc707a6 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,3 +1,23 @@
+2010-11-12  David Levin  <levin at chromium.org>
+
+        Reviewed by Shinichiro Hamaji.
+
+        check-webkit-style function detection doesn't detect indented functions declaractions.
+        https://bugs.webkit.org/show_bug.cgi?id=49446
+
+        Indented function declarations occur inside class definitions, so
+        they are a pretty common (and worth detecting).
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+          Changed regex to allow indentation.
+          Changed the function start detection to only happen when not in a
+          function.
+          Changed function end detection to work based on matching braces
+          instead of finding a close brace at the beginning of the line.
+          Fixed close_expression to do what it says when it doesn't find
+          the close.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py: Indented function test.
+
 2010-11-12  Daniel Bates  <dbates at rim.com>
 
         Rubber-stamped by Nikolas Zimmermann.
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
index 1dcc047..4f7c4ec 100644
--- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
+++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
@@ -316,16 +316,19 @@ class _FunctionState(object):
         self.current_function = ''
         self.in_a_function = False
         self.lines_in_function = 0
+        self.ending_line_number = 0
 
-    def begin(self, function_name):
+    def begin(self, function_name, ending_line_number):
         """Start analyzing function body.
 
         Args:
             function_name: The name of the function being tracked.
+            ending_line_number: The line number where the function ends.
         """
         self.in_a_function = True
         self.lines_in_function = 0
         self.current_function = function_name
+        self.ending_line_number = ending_line_number
 
     def count(self):
         """Count line in current function body."""
@@ -609,8 +612,8 @@ class CleansedLines(object):
 def close_expression(clean_lines, line_number, pos):
     """If input points to ( or { or [, finds the position that closes it.
 
-    If lines[line_number][pos] points to a '(' or '{' or '[', finds the the
-    line_number/pos that correspond to the closing of the expression.
+    If clean_lines.elided[line_number][pos] points to a '(' or '{' or '[', finds
+    the line_number/pos that correspond to the closing of the expression.
 
     Args:
       clean_lines: A CleansedLines instance containing the file.
@@ -619,8 +622,8 @@ def close_expression(clean_lines, line_number, pos):
 
     Returns:
       A tuple (line, line_number, pos) pointer *past* the closing brace, or
-      (line, len(lines), -1) if we never find a close.  Note we ignore
-      strings and comments when matching; and the line we return is the
+      ('', len(clean_lines.elided), -1) if we never find a close.  Note we
+      ignore strings and comments when matching; and the line we return is the
       'cleansed' line at line_number.
     """
 
@@ -636,8 +639,10 @@ def close_expression(clean_lines, line_number, pos):
         end_character = '}'
 
     num_open = line.count(start_character) - line.count(end_character)
-    while line_number < clean_lines.num_lines() and num_open > 0:
+    while num_open > 0:
         line_number += 1
+        if line_number >= clean_lines.num_lines():
+            return ('', len(clean_lines.elided), -1)
         line = clean_lines.elided[line_number]
         num_open += line.count(start_character) - line.count(end_character)
     # OK, now find the end_character that actually got us back to even
@@ -1149,7 +1154,6 @@ def check_for_function_lengths(clean_lines, line_number, function_state, error):
 
     Uses a simplistic algorithm assuming other style guidelines
     (especially spacing) are followed.
-    Only checks unindented functions, so class members are unchecked.
     Trivial bodies are unchecked, so constructors with huge initializer lists
     may be missed.
     Blank/comment lines are not counted so as to avoid encouraging the removal
@@ -1169,8 +1173,10 @@ def check_for_function_lengths(clean_lines, line_number, function_state, error):
     joined_line = ''
 
     starting_func = False
-    regexp = r'(\w(\w|::|\*|\&|\s|<|>|,|~)*)\('  # decls * & space::name( ...
-    match_result = match(regexp, line)
+    regexp = r'\s*(\w(\w|::|\*|\&|\s|<|>|,|~)*)\('  # decls * & space::name( ...
+    match_result = None
+    if not function_state.in_a_function:
+        match_result = match(regexp, line)
     if match_result:
         # If the name is all caps and underscores, figure it's a macro and
         # ignore it, unless it's TEST or TEST_F.
@@ -1200,13 +1206,15 @@ def check_for_function_lengths(clean_lines, line_number, function_state, error):
                         function += parameter_regexp.group(1)
                 else:
                     function += '()'
-                function_state.begin(function)
+                open_brace_index = start_line.find('{')
+                ending_line_number = close_expression(clean_lines, start_line_number, open_brace_index)[1]
+                function_state.begin(function, ending_line_number)
                 break
         else:
             # No body for the function (or evidence of a non-function) was found.
             error(line_number, 'readability/fn_size', 5,
                   'Lint failed to find start of function body.')
-    elif match(r'^\}\s*$', line):  # function end
+    elif function_state.in_a_function and function_state.ending_line_number == line_number:  # function end
         if not search(r'\bNOLINT\b', raw_line):
             function_state.check(error, line_number)
         function_state.end()
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index 9b4de27..bb4f351 100644
--- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -2432,6 +2432,20 @@ class CheckForFunctionLengthsTest(CppStyleTestBase):
     def test_function_length_check_definition_above_severity1(self):
         self.assert_function_length_check_above_error_level(1)
 
+    def test_function_length_check_definition_severity1_plus_indented(self):
+        error_level = 1
+        error_lines = self.trigger_lines(error_level) + 1
+        trigger_level = self.trigger_lines(self.min_confidence)
+        indent_spaces = '    '
+        self.assert_function_lengths_check(
+            re.sub(r'(?m)^(.)', indent_spaces + r'\1',
+                   'void test_indent(int x)\n' + self.function_body(error_lines)),
+            ('Small and focused functions are preferred: '
+             'test_indent() has %d non-comment lines '
+             '(error triggered by exceeding %d lines).'
+             '  [readability/fn_size] [%d]')
+            % (error_lines + 1, trigger_level, error_level))
+
     def test_function_length_check_definition_severity1_plus_blanks(self):
         error_level = 1
         error_lines = self.trigger_lines(error_level) + 1

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list