[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:57 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 610baef5b5a91e91aa387b26dea89ef4244961b1
Author: levin at chromium.org <levin at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Nov 15 01:17:36 2010 +0000

    2010-11-14  David Levin  <levin at chromium.org>
    
            Reviewed by Daniel Bates.
    
            check-webkit-style should detect PassRefPtr usage in functions.
            https://bugs.webkit.org/show_bug.cgi?id=49513
    
            * Scripts/webkitpy/style/checkers/cpp.py:
            (check_for_function_lengths): Revert a comment change that I
             accidentally made in r71986.
            (check_pass_ptr_usage): Added the code to do the check.
            (process_line): Added the call to check_pass_ptr_usage.
            (CppChecker): Added the new error category.
            * Scripts/webkitpy/style/checkers/cpp_unittest.py:
            (CppStyleTestBase::perform_pass_ptr_check): Runs the new check for
             testing purposes.
            (PassPtrTest::*): The class/functions to unit test the new
             functionality.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@71989 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 2035a29..1ef619e 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1,5 +1,24 @@
 2010-11-14  David Levin  <levin at chromium.org>
 
+        Reviewed by Daniel Bates.
+
+        check-webkit-style should detect PassRefPtr usage in functions.
+        https://bugs.webkit.org/show_bug.cgi?id=49513
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_for_function_lengths): Revert a comment change that I
+         accidentally made in r71986.
+        (check_pass_ptr_usage): Added the code to do the check.
+        (process_line): Added the call to check_pass_ptr_usage.
+        (CppChecker): Added the new error category.
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (CppStyleTestBase::perform_pass_ptr_check): Runs the new check for
+         testing purposes.
+        (PassPtrTest::*): The class/functions to unit test the new
+         functionality.
+
+2010-11-14  David Levin  <levin at chromium.org>
+
         Reviewed by Shinichiro Hamaji.
 
         check-webkit-style function detection and the line count style checks should be separate.
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
index d504e4a..590bba9 100644
--- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
+++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp.py
@@ -1224,7 +1224,7 @@ def detect_functions(clean_lines, line_number, function_state, error):
 
 
 def check_for_function_lengths(clean_lines, line_number, function_state, error):
-    """Reports for issues related to functions.
+    """Reports for long function bodies.
 
     For an overview why this is done, see:
     http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
@@ -1251,6 +1251,32 @@ def check_for_function_lengths(clean_lines, line_number, function_state, error):
         function_state.count(line_number)  # Count non-blank/non-comment lines.
 
 
+def check_pass_ptr_usage(clean_lines, line_number, function_state, error):
+    """Check for proper usage of Pass*Ptr.
+
+    Currently this is limited to detecting declarations of Pass*Ptr
+    variables inside of functions.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      function_state: Current function name and lines in body so far.
+      error: The function to call with any errors found.
+    """
+    if not function_state.in_a_function:
+        return
+
+    lines = clean_lines.lines
+    line = lines[line_number]
+    if line_number >= function_state.body_start_line_number:
+        matched_pass_ptr = match(r'^\s*Pass([A-Z][A-Za-z]*)Ptr<', line)
+        if matched_pass_ptr:
+            type_name = 'Pass%sPtr' % matched_pass_ptr.group(1)
+            error(line_number, 'readability/pass_ptr', 5,
+                  'Local variables should never be %s (see '
+                  'http://webkit.org/coding/RefPtr.html).' % type_name)
+
+
 def check_spacing(file_extension, clean_lines, line_number, error):
     """Checks for the correctness of various spacing issues in the code.
 
@@ -2933,6 +2959,7 @@ def process_line(filename, file_extension,
     check_for_function_lengths(clean_lines, line, function_state, error)
     if search(r'\bNOLINT\b', raw_lines[line]):  # ignore nolint lines
         return
+    check_pass_ptr_usage(clean_lines, line, function_state, error)
     check_for_multiline_comments_and_strings(clean_lines, line, error)
     check_style(clean_lines, line, file_extension, class_state, file_state, error)
     check_language(filename, clean_lines, line, file_extension, include_state,
@@ -3017,6 +3044,7 @@ class CppChecker(object):
         'readability/multiline_string',
         'readability/naming',
         'readability/null',
+        'readability/pass_ptr',
         'readability/streams',
         'readability/todo',
         'readability/utf8',
diff --git a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index 9031ed8..13b053c 100644
--- a/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/WebKitTools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -211,6 +211,21 @@ class CppStyleTestBase(unittest.TestCase):
                                                  function_state, error_collector)
         return error_collector.results()
 
+    # Similar to perform_function_lengths_check, but calls check_pass_ptr_usage
+    # instead of check_for_function_lengths.
+    def perform_pass_ptr_check(self, code):
+        error_collector = ErrorCollector(self.assert_)
+        function_state = cpp_style._FunctionState(self.min_confidence)
+        lines = code.split('\n')
+        cpp_style.remove_multi_line_comments(lines, error_collector)
+        lines = cpp_style.CleansedLines(lines)
+        for i in xrange(lines.num_lines()):
+            cpp_style.detect_functions(lines, i,
+                                       function_state, error_collector)
+            cpp_style.check_pass_ptr_usage(lines, i,
+                                           function_state, error_collector)
+        return error_collector.results()
+
     def perform_include_what_you_use(self, code, filename='foo.h', io=codecs):
         # First, build up the include state.
         error_collector = ErrorCollector(self.assert_)
@@ -2730,6 +2745,65 @@ class NoNonVirtualDestructorsTest(CppStyleTestBase):
              'virtual method(s), one declared at line 2.  [runtime/virtual] [4]'])
 
 
+class PassPtrTest(CppStyleTestBase):
+    # For http://webkit.org/coding/RefPtr.html
+
+    def assert_pass_ptr_check(self, code, expected_message):
+        """Check warnings for Pass*Ptr are as expected.
+
+        Args:
+          code: C++ source code expected to generate a warning message.
+          expected_message: Message expected to be generated by the C++ code.
+        """
+        self.assertEquals(expected_message,
+                          self.perform_pass_ptr_check(code))
+
+    def test_pass_ref_ptr_in_function(self):
+        # Local variables should never be PassRefPtr.
+        self.assert_pass_ptr_check(
+            'int myFunction()\n'
+            '{\n'
+            '    PassRefPtr<Type1> variable = variable2;\n'
+            '}',
+            'Local variables should never be PassRefPtr (see '
+            'http://webkit.org/coding/RefPtr.html).  [readability/pass_ptr] [5]')
+
+    def test_pass_own_ptr_in_function(self):
+        # Local variables should never be PassRefPtr.
+        self.assert_pass_ptr_check(
+            'int myFunction()\n'
+            '{\n'
+            '    PassOwnPtr<Type1> variable = variable2;\n'
+            '}',
+            'Local variables should never be PassOwnPtr (see '
+            'http://webkit.org/coding/RefPtr.html).  [readability/pass_ptr] [5]')
+
+    def test_pass_other_type_ptr_in_function(self):
+        # Local variables should never be PassRefPtr.
+        self.assert_pass_ptr_check(
+            'int myFunction()\n'
+            '{\n'
+            '    PassOtherTypePtr<Type1> variable;\n'
+            '}',
+            'Local variables should never be PassOtherTypePtr (see '
+            'http://webkit.org/coding/RefPtr.html).  [readability/pass_ptr] [5]')
+
+    def test_pass_ref_ptr_return_value(self):
+        self.assert_pass_ptr_check(
+            'PassRefPtr<Type1>\n'
+            'myFunction(int)\n'
+            '{\n'
+            '}',
+            '')
+
+    def test_pass_ref_ptr_parameter_value(self):
+        self.assert_pass_ptr_check(
+            'int myFunction(PassRefPtr<Type1>)\n'
+            '{\n'
+            '}',
+            '')
+
+
 class WebKitStyleTest(CppStyleTestBase):
 
     # for http://webkit.org/coding/coding-style.html

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list