Title: [171065] trunk/Tools
Revision
171065
Author
[email protected]
Date
2014-07-14 09:16:56 -0700 (Mon, 14 Jul 2014)

Log Message

Teach check-webkit-style to suggest WTF::move() when it sees std::move()
https://bugs.webkit.org/show_bug.cgi?id=134620

Reviewed by Joseph Pecoraro.

* Scripts/webkitpy/style/checkers/cpp.py:
(check_max_min_macros): Fix up comment so that it reads well.
(check_wtf_move): Added.
(check_style): Modified to call check_wtf_move().
(CppChecker): Add category "runtime/wtf_move".
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(WebKitStyleTest.test_wtf_move): Added.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (171064 => 171065)


--- trunk/Tools/ChangeLog	2014-07-14 10:56:00 UTC (rev 171064)
+++ trunk/Tools/ChangeLog	2014-07-14 16:16:56 UTC (rev 171065)
@@ -1,3 +1,18 @@
+2014-07-14  Daniel Bates  <[email protected]>
+
+        Teach check-webkit-style to suggest WTF::move() when it sees std::move()
+        https://bugs.webkit.org/show_bug.cgi?id=134620
+
+        Reviewed by Joseph Pecoraro.
+
+        * Scripts/webkitpy/style/checkers/cpp.py:
+        (check_max_min_macros): Fix up comment so that it reads well.
+        (check_wtf_move): Added.
+        (check_style): Modified to call check_wtf_move().
+        (CppChecker): Add category "runtime/wtf_move".
+        * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+        (WebKitStyleTest.test_wtf_move): Added.
+
 2014-07-12  Peter Szanka  <[email protected]>
 
         Style checker complains about namespace indentation when there is no namespace

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2014-07-14 10:56:00 UTC (rev 171064)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp.py	2014-07-14 16:16:56 UTC (rev 171065)
@@ -2244,7 +2244,7 @@
           "Do not use 'using namespace %s;'." % method_name)
 
 def check_max_min_macros(clean_lines, line_number, file_state, error):
-    """Looks use of MAX() and MIN() macros that should be replaced with std::max() and std::min().
+    """Looks for use of MAX() and MIN() macros that should be replaced with std::max() and std::min().
 
     Args:
       clean_lines: A CleansedLines instance containing the file.
@@ -2271,6 +2271,30 @@
           % (max_min_macro_lower, max_min_macro_lower, max_min_macro))
 
 
+def check_wtf_move(clean_lines, line_number, file_state, error):
+    """Looks for use of 'std::move()' which should be replaced with 'WTF::move()'.
+
+    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.
+    """
+
+    # This check doesn't apply to C or Objective-C implementation files.
+    if file_state.is_c_or_objective_c():
+        return
+
+    line = clean_lines.elided[line_number]  # Get rid of comments and strings.
+
+    using_std_move = search(r'\bstd::move\s*\(', line)
+    if not using_std_move:
+        return
+
+    error(line_number, 'runtime/wtf_move', 4, "Use 'WTF::move()' instead of 'std::move()'.")
+
+
 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>?.
@@ -2759,6 +2783,7 @@
     check_using_std(clean_lines, line_number, file_state, error)
     check_using_namespace(clean_lines, line_number, file_extension, error)
     check_max_min_macros(clean_lines, line_number, file_state, error)
+    check_wtf_move(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)
@@ -3813,6 +3838,7 @@
         'runtime/threadsafe_fn',
         'runtime/unsigned',
         'runtime/virtual',
+        'runtime/wtf_move',
         'whitespace/blank_line',
         'whitespace/braces',
         'whitespace/colon',

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


--- trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2014-07-14 10:56:00 UTC (rev 171064)
+++ trunk/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py	2014-07-14 16:16:56 UTC (rev 171065)
@@ -4719,6 +4719,18 @@
             '  [runtime/max_min_macros] [4]',
             'foo.h')
 
+    def test_wtf_move(self):
+        self.assert_lint(
+             'A a = WTF::move(b);',
+             '',
+             'foo.cpp')
+
+        self.assert_lint(
+            'A a = std::move(b);',
+            "Use 'WTF::move()' instead of 'std::move()'."
+            "  [runtime/wtf_move] [4]",
+            'foo.cpp')
+
     def test_ctype_fucntion(self):
         self.assert_lint(
             'int i = isascii(8);',
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to