[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da
levin at chromium.org
levin at chromium.org
Wed Dec 22 18:49:41 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit e8f82757a158c86b5ba05160e0382d58a0f774af
Author: levin at chromium.org <levin at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Mon Dec 20 19:38:49 2010 +0000
check-webkit-style should detect function declarations (and trivial functions).
https://bugs.webkit.org/show_bug.cgi?id=51303
Reviewed by Shinichiro Hamaji.
* Scripts/webkitpy/style/checkers/cpp.py:
(_FunctionState.begin): Add is_declaration and changed the line count
start to begin at -1 (which will keep the results consistent, since
the starting line number passed in is one less in this change).
(detect_functions): changed function detection to now catch trivial
functions and declarations.
(check_pass_ptr_usage): Don't check for Pass*Ptr on the first line
of the function as this may look at return values (when processing
a declaration).
* Scripts/webkitpy/style/checkers/cpp_unittest.py:
(FunctionDetectionTest.perform_function_detection): Basic mechanics
of testing the function detection.
(FunctionDetectionTest.test_basic_function_detection): Test a simple
function.
(FunctionDetectionTest.test_function_declaration_detection): Test a
declaration.
(FunctionDetectionTest.test_non_functions): A test case for a case
that caused the code to fail due to the { being in quotes.
(PassPtrTest.test_pass_ref_ptr_return_value): Added some more test
cases to help catch false alarms for return values.
(PassPtrTest.test_pass_ref_ptr_member_variable): Ensure that
we don't get false alarms for member variables either.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74356 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 635bcd5..1623974 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,33 @@
+2010-12-20 David Levin <levin at chromium.org>
+
+ Reviewed by Shinichiro Hamaji.
+
+ check-webkit-style should detect function declarations (and trivial functions).
+ https://bugs.webkit.org/show_bug.cgi?id=51303
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (_FunctionState.begin): Add is_declaration and changed the line count
+ start to begin at -1 (which will keep the results consistent, since
+ the starting line number passed in is one less in this change).
+ (detect_functions): changed function detection to now catch trivial
+ functions and declarations.
+ (check_pass_ptr_usage): Don't check for Pass*Ptr on the first line
+ of the function as this may look at return values (when processing
+ a declaration).
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py:
+ (FunctionDetectionTest.perform_function_detection): Basic mechanics
+ of testing the function detection.
+ (FunctionDetectionTest.test_basic_function_detection): Test a simple
+ function.
+ (FunctionDetectionTest.test_function_declaration_detection): Test a
+ declaration.
+ (FunctionDetectionTest.test_non_functions): A test case for a case
+ that caused the code to fail due to the { being in quotes.
+ (PassPtrTest.test_pass_ref_ptr_return_value): Added some more test
+ cases to help catch false alarms for return values.
+ (PassPtrTest.test_pass_ref_ptr_member_variable): Ensure that
+ we don't get false alarms for member variables either.
+
2010-12-20 Ryuan Choi <ryuan.choi at samsung.com>
Reviewed by Antonio Gomes.
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp.py b/Tools/Scripts/webkitpy/style/checkers/cpp.py
index e841029..3ffaeb9 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp.py
@@ -329,18 +329,21 @@ class _FunctionState(object):
self.body_start_line_number = -1000
self.ending_line_number = -1000
- def begin(self, function_name, body_start_line_number, ending_line_number):
+ def begin(self, function_name, body_start_line_number, ending_line_number, is_declaration):
"""Start analyzing function body.
Args:
function_name: The name of the function being tracked.
+ body_start_line_number: The line number of the { or the ; for a protoype.
ending_line_number: The line number where the function ends.
+ is_declaration: True if this is a prototype.
"""
self.in_a_function = True
- self.lines_in_function = 0
+ self.lines_in_function = -1 # Don't count the open brace line.
self.current_function = function_name
self.body_start_line_number = body_start_line_number
self.ending_line_number = ending_line_number
+ self.is_declaration = is_declaration
def count(self, line_number):
"""Count line in current function body."""
@@ -1205,12 +1208,9 @@ def detect_functions(clean_lines, line_number, function_state, error):
joined_line = ''
for start_line_number in xrange(line_number, clean_lines.num_lines()):
- start_line = lines[start_line_number]
+ start_line = clean_lines.elided[start_line_number]
joined_line += ' ' + start_line.lstrip()
- if search(r'(;|})', start_line): # Declarations and trivial functions
- return # ... ignore
-
- if search(r'{', start_line):
+ if search(r'{|;', start_line):
# Replace template constructs with _ so that no spaces remain in the function name,
# while keeping the column numbers of other characters the same as "line".
line_with_no_templates = iteratively_replace_matches_with_char(r'<[^<>]*>', '_', line)
@@ -1228,9 +1228,13 @@ def detect_functions(clean_lines, line_number, function_state, error):
function += parameter_regexp.group(1)
else:
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, start_line_number + 1, ending_line_number)
+ is_declaration = bool(search(r'^[^{]*;', start_line))
+ if is_declaration:
+ ending_line_number = start_line_number
+ else:
+ open_brace_index = start_line.find('{')
+ ending_line_number = close_expression(clean_lines, start_line_number, open_brace_index)[1]
+ function_state.begin(function, start_line_number, ending_line_number, is_declaration)
return
# No body for the function (or evidence of a non-function) was found.
@@ -1283,7 +1287,7 @@ def check_pass_ptr_usage(clean_lines, line_number, function_state, error):
lines = clean_lines.lines
line = lines[line_number]
- if line_number >= function_state.body_start_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)
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
index cdbc672..d2c2570 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -231,6 +231,54 @@ class CppStyleTestBase(unittest.TestCase):
' [whitespace/blank_line] [3]'))
+class FunctionDetectionTest(CppStyleTestBase):
+ def perform_function_detection(self, lines, function_information):
+ clean_lines = cpp_style.CleansedLines(lines)
+ function_state = cpp_style._FunctionState(5)
+ error_collector = ErrorCollector(self.assert_)
+ cpp_style.detect_functions(clean_lines, 0, function_state, error_collector)
+ if not function_information:
+ self.assertEquals(function_state.in_a_function, False)
+ return
+ self.assertEquals(function_state.in_a_function, True)
+ self.assertEquals(function_state.current_function, function_information['name'] + '()')
+ self.assertEquals(function_state.body_start_line_number, function_information['body_start_line_number'])
+ self.assertEquals(function_state.ending_line_number, function_information['ending_line_number'])
+ self.assertEquals(function_state.is_declaration, function_information['is_declaration'])
+
+ def test_basic_function_detection(self):
+ self.perform_function_detection(
+ ['void theTestFunctionName(int) {',
+ '}'],
+ {'name': 'theTestFunctionName',
+ 'body_start_line_number': 0,
+ 'ending_line_number': 1,
+ 'is_declaration': False})
+
+ def test_function_declaration_detection(self):
+ self.perform_function_detection(
+ ['void aFunctionName(int);'],
+ {'name': 'aFunctionName',
+ 'body_start_line_number': 0,
+ 'ending_line_number': 0,
+ 'is_declaration': True})
+
+ def test_non_functions(self):
+ # This case exposed an error because the open brace was in quotes.
+ self.perform_function_detection(
+ ['asm(',
+ ' "stmdb sp!, {r1-r3}" "\n"',
+ ');'],
+ # This isn't a function but it looks like one to our simple
+ # algorithm and that is ok.
+ {'name': 'asm',
+ 'body_start_line_number': 2,
+ 'ending_line_number': 2,
+ 'is_declaration': True})
+
+ # Simple test case with something that is not a function.
+ self.perform_function_detection(['class Stuff;'], None)
+
class CppStyleTest(CppStyleTestBase):
# Test get line width.
@@ -2770,6 +2818,14 @@ class PassPtrTest(CppStyleTestBase):
'{\n'
'}',
'')
+ self.assert_pass_ptr_check(
+ 'PassRefPtr<Type1> myFunction(int)\n'
+ '{\n'
+ '}',
+ '')
+ self.assert_pass_ptr_check(
+ 'PassRefPtr<Type1> myFunction();\n',
+ '')
def test_pass_ref_ptr_parameter_value(self):
self.assert_pass_ptr_check(
@@ -2778,6 +2834,13 @@ class PassPtrTest(CppStyleTestBase):
'}',
'')
+ def test_ref_ptr_member_variable(self):
+ self.assert_pass_ptr_check(
+ 'class Foo {'
+ ' RefPtr<Type1> m_other;\n'
+ '};\n',
+ '')
+
class WebKitStyleTest(CppStyleTestBase):
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list