Changeset 47385 in webkit
- Timestamp:
- Aug 17, 2009 1:33:37 PM (15 years ago)
- Location:
- trunk/WebKitTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKitTools/ChangeLog
r47361 r47385 1 2009-08-17 David Kilzer <ddkilzer@apple.com> 2 3 <http://webkit.org/b/28393> check-webkit-style: add check for use of std::max()/std::min() instead of MAX()/MIN() 4 5 Reviewed by David Levin. 6 7 * Scripts/modules/cpp_style.py: 8 (_ERROR_CATEGORIES): Added 'runtime/max_min_macros'. 9 (check_max_min_macros): Added. Returns level 4 error when MAX() 10 and MIN() macros are used in header files and C++ source files. 11 (check_style): Added call to check_max_min_macros(). 12 * Scripts/modules/cpp_style_unittest.py: Added unit tests. 13 (test_max_macro): Added. 14 (test_min_macro): Added. 15 1 16 2009-08-13 Mike Fenton <mike.fenton@torchmobile.com> 2 17 -
trunk/WebKitTools/Scripts/modules/cpp_style.py
r47346 r47385 141 141 runtime/init 142 142 runtime/invalid_increment 143 runtime/max_min_macros 143 144 runtime/memset 144 145 runtime/printf … … 1769 1770 1770 1771 1772 def check_max_min_macros(filename, clean_lines, line_number, error): 1773 """Looks use of MAX() and MIN() macros that should be replaced with std::max() and std::min(). 1774 1775 Args: 1776 filename: The name of the current file. 1777 clean_lines: A CleansedLines instance containing the file. 1778 line_number: The number of the line to check. 1779 error: The function to call with any errors found. 1780 """ 1781 1782 # This check doesn't apply to C or Objective-C implementation files. 1783 if filename.endswith('.c') or filename.endswith('.m'): 1784 return 1785 1786 line = clean_lines.elided[line_number] # Get rid of comments and strings. 1787 1788 max_min_macros_search = search(r'\b(?P<max_min_macro>(MAX|MIN))\s*\(', line) 1789 if not max_min_macros_search: 1790 return 1791 1792 max_min_macro = max_min_macros_search.group('max_min_macro') 1793 max_min_macro_lower = max_min_macro.lower() 1794 error(filename, line_number, 'runtime/max_min_macros', 4, 1795 'Use std::%s() or std::%s<type>() instead of the %s() macro.' 1796 % (max_min_macro_lower, max_min_macro_lower, max_min_macro)) 1797 1798 1771 1799 def check_switch_indentation(filename, clean_lines, line_number, error): 1772 1800 """Looks for indentation errors inside of switch statements. … … 2203 2231 check_namespace_indentation(filename, clean_lines, line_number, file_extension, error) 2204 2232 check_using_std(filename, clean_lines, line_number, error) 2233 check_max_min_macros(filename, clean_lines, line_number, error) 2205 2234 check_switch_indentation(filename, clean_lines, line_number, error) 2206 2235 check_braces(filename, clean_lines, line_number, error) -
trunk/WebKitTools/Scripts/modules/cpp_style_unittest.py
r47346 r47385 3434 3434 'foo.cpp') 3435 3435 3436 def test_max_macro(self): 3437 self.assert_lint( 3438 'int i = MAX(0, 1);', 3439 '', 3440 'foo.c') 3441 3442 self.assert_lint( 3443 'int i = MAX(0, 1);', 3444 'Use std::max() or std::max<type>() instead of the MAX() macro.' 3445 ' [runtime/max_min_macros] [4]', 3446 'foo.cpp') 3447 3448 self.assert_lint( 3449 'inline int foo() { return MAX(0, 1); }', 3450 'Use std::max() or std::max<type>() instead of the MAX() macro.' 3451 ' [runtime/max_min_macros] [4]', 3452 'foo.h') 3453 3454 def test_min_macro(self): 3455 self.assert_lint( 3456 'int i = MIN(0, 1);', 3457 '', 3458 'foo.c') 3459 3460 self.assert_lint( 3461 'int i = MIN(0, 1);', 3462 'Use std::min() or std::min<type>() instead of the MIN() macro.' 3463 ' [runtime/max_min_macros] [4]', 3464 'foo.cpp') 3465 3466 self.assert_lint( 3467 'inline int foo() { return MIN(0, 1); }', 3468 'Use std::min() or std::min<type>() instead of the MIN() macro.' 3469 ' [runtime/max_min_macros] [4]', 3470 'foo.h') 3471 3436 3472 def test_names(self): 3437 3473 # FIXME: Implement this.
Note: See TracChangeset
for help on using the changeset viewer.