Title: [107872] trunk/Tools
Revision
107872
Author
[email protected]
Date
2012-02-15 19:18:27 -0800 (Wed, 15 Feb 2012)

Log Message

Add style check for ctype functions that are generally frowned upon in WebKit
https://bugs.webkit.org/show_bug.cgi?id=78748

Patch by Sam Weinig <[email protected]> on 2012-02-15
Reviewed by Anders Carlsson.

Not every platform has DisallowCType.h to check for uses of the ctype.h
functions, so add a style check for them as well.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_ctype_functions):
(check_style):
(CppChecker):
Add check.

* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_ctype_fucntion):
Add checker.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (107871 => 107872)


--- trunk/Tools/ChangeLog	2012-02-16 03:16:48 UTC (rev 107871)
+++ trunk/Tools/ChangeLog	2012-02-16 03:18:27 UTC (rev 107872)
@@ -1,3 +1,23 @@
+2012-02-15  Sam Weinig  <[email protected]>
+
+        Add style check for ctype functions that are generally frowned upon in WebKit
+        https://bugs.webkit.org/show_bug.cgi?id=78748
+
+        Reviewed by Anders Carlsson.
+
+        Not every platform has DisallowCType.h to check for uses of the ctype.h
+        functions, so add a style check for them as well.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_ctype_functions):
+        (check_style):
+        (CppChecker):
+        Add check.
+
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_ctype_fucntion):
+        Add checker.
+
 2012-02-15  Szilard Ledan  <[email protected]>
 
         [Qt][WK2] WebKitTestRunner should use 480x360 sized view for W3C SVG tests

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py (107871 => 107872)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2012-02-16 03:16:48 UTC (rev 107871)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2012-02-16 03:18:27 UTC (rev 107872)
@@ -2077,6 +2077,29 @@
           % (max_min_macro_lower, max_min_macro_lower, max_min_macro))
 
 
+def check_ctype_functions(clean_lines, line_number, file_state, error):
+    """Looks for use of the standard functions in ctype.h and suggest they be replaced
+       by use of equivilent ones in <wtf/ASCIICType.h>?.
+
+    Args:
+      clean_lines: A CleansedLines instance containing the file.
+      line_number: The number of the line to check.
+      file_state: A _FileState instance which maintains information about
+                  the state of things in the file.
+      error: The function to call with any errors found.
+    """
+
+    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
+
+    ctype_function_search = search(r'\b(?P<ctype_function>(isalnum|isalpha|isascii|isblank|iscntrl|isdigit|isgraph|islower|isprint|ispunct|isspace|isupper|isxdigit|toascii|tolower|toupper))\s*\(', line)
+    if not ctype_function_search:
+        return
+
+    ctype_function = ctype_function_search.group('ctype_function')
+    error(line_number, 'runtime/ctype_function', 4,
+          'Use equivelent function in <wtf/ASCIICType.h> instead of the %s() function.'
+          % (ctype_function))
+
 def check_switch_indentation(clean_lines, line_number, error):
     """Looks for indentation errors inside of switch statements.
 
@@ -2540,6 +2563,7 @@
     check_namespace_indentation(clean_lines, line_number, file_extension, file_state, error)
     check_using_std(clean_lines, line_number, file_state, error)
     check_max_min_macros(clean_lines, line_number, file_state, error)
+    check_ctype_functions(clean_lines, line_number, file_state, error)
     check_switch_indentation(clean_lines, line_number, error)
     check_braces(clean_lines, line_number, error)
     check_exit_statement_simplifications(clean_lines, line_number, error)
@@ -3528,6 +3552,7 @@
         'runtime/arrays',
         'runtime/bitfields',
         'runtime/casting',
+        'runtime/ctype_function',
         'runtime/explicit',
         'runtime/init',
         'runtime/int',

Modified: trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py (107871 => 107872)


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2012-02-16 03:16:48 UTC (rev 107871)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2012-02-16 03:18:27 UTC (rev 107872)
@@ -4347,6 +4347,13 @@
             '  [runtime/max_min_macros] [4]',
             'foo.h')
 
+    def test_ctype_fucntion(self):
+        self.assert_lint(
+            'int i = isascii(8);',
+            'Use equivelent function in <wtf/ASCIICType.h> instead of the '
+            'isascii() function.  [runtime/ctype_function] [4]',
+            'foo.cpp')
+
     def test_names(self):
         name_underscore_error_message = " is incorrectly named. Don't use underscores in your identifier names.  [readability/naming] [4]"
         name_tooshort_error_message = " is incorrectly named. Don't use the single letter 'l' as an identifier name.  [readability/naming] [4]"
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to