[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198
levin at chromium.org
levin at chromium.org
Sun Feb 20 22:56:34 UTC 2011
The following commit has been merged in the webkit-1.3 branch:
commit 2021db24c2ae48191da7eec3a1fb28ae86799b8d
Author: levin at chromium.org <levin at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Jan 14 06:58:16 2011 +0000
2011-01-13 David Levin <levin at chromium.org>
Reviewed by Shinichiro Hamaji.
check-webkit-style: _FunctionState should use Position to know where items are.
https://bugs.webkit.org/show_bug.cgi?id=52424
* Scripts/webkitpy/style/checkers/cpp.py:
(_FunctionState.*): Changed _FunctionState to use Position instead of line numbers.
(detect_functions): Changed to pass Position's to _FunctionState.begin and
did some minor clean-up.
(*): Other changes are simply about converting to use the Position's in_FunctionState
instead of line numbers.
* Scripts/webkitpy/style/checkers/cpp_unittest.py: Changed the test code
to verify the positions stored in _FunctionState.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@75772 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 7169dde..3590016 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,19 @@
+2011-01-13 David Levin <levin at chromium.org>
+
+ Reviewed by Shinichiro Hamaji.
+
+ check-webkit-style: _FunctionState should use Position to know where items are.
+ https://bugs.webkit.org/show_bug.cgi?id=52424
+
+ * Scripts/webkitpy/style/checkers/cpp.py:
+ (_FunctionState.*): Changed _FunctionState to use Position instead of line numbers.
+ (detect_functions): Changed to pass Position's to _FunctionState.begin and
+ did some minor clean-up.
+ (*): Other changes are simply about converting to use the Position's in_FunctionState
+ instead of line numbers.
+ * Scripts/webkitpy/style/checkers/cpp_unittest.py: Changed the test code
+ to verify the positions stored in _FunctionState.
+
2011-01-13 Eric Seidel <eric at webkit.org>
Reviewed by David Levin.
diff --git a/Tools/Scripts/webkitpy/style/checkers/cpp.py b/Tools/Scripts/webkitpy/style/checkers/cpp.py
index bc1fabd..61a3dbd 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp.py
@@ -492,30 +492,29 @@ class _FunctionState(object):
self.current_function = ''
self.in_a_function = False
self.lines_in_function = 0
- # Make sure these will not be mistaken for real lines (even when a
+ # Make sure these will not be mistaken for real positions (even when a
# small amount is added to them).
- self.body_start_line_number = -1000
- self.ending_line_number = -1000
+ self.body_start_position = Position(-1000, 0)
+ self.end_position = Position(-1000, 0)
- def begin(self, function_name, body_start_line_number, ending_line_number, is_declaration,
+ def begin(self, function_name, body_start_position, end_position,
parameter_start_position, parameter_end_position, clean_lines):
"""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.
- parameter_start_position: position in elided of the '(' for the parameters.
- parameter_end_position: position in elided of the ')' for the parameters.
+ body_start_position: Position in elided of the { or the ; for a prototype.
+ end_position: Position in elided just after the final } (or ; is.
+ parameter_start_position: Position in elided of the '(' for the parameters.
+ parameter_end_position: Position in elided just after the ')' for the parameters.
clean_lines: A CleansedLines instance containing the file.
"""
self.in_a_function = True
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
+ self.body_start_position = body_start_position
+ self.end_position = end_position
+ self.is_declaration = clean_lines.elided[body_start_position.row][body_start_position.column] == ';'
self.parameter_start_position = parameter_start_position
self.parameter_end_position = parameter_end_position
self._clean_lines = clean_lines
@@ -530,7 +529,7 @@ class _FunctionState(object):
def count(self, line_number):
"""Count line in current function body."""
- if self.in_a_function and line_number >= self.body_start_line_number:
+ if self.in_a_function and line_number >= self.body_start_position.row:
self.lines_in_function += 1
def check(self, error, line_number):
@@ -1393,7 +1392,7 @@ def detect_functions(clean_lines, line_number, function_state, error):
error: The function to call with any errors found.
"""
# Are we now past the end of a function?
- if function_state.ending_line_number + 1 == line_number:
+ if function_state.end_position.row + 1 == line_number:
function_state.end()
# If we're in a function, don't try to detect a new one.
@@ -1424,7 +1423,10 @@ def detect_functions(clean_lines, line_number, function_state, error):
for start_line_number in xrange(line_number, clean_lines.num_lines()):
start_line = clean_lines.elided[start_line_number]
joined_line += ' ' + start_line.lstrip()
- if search(r'{|;', start_line):
+ body_match = search(r'{|;', start_line)
+ if body_match:
+ body_start_position = Position(start_line_number, body_match.start(0))
+
# 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)
@@ -1449,13 +1451,16 @@ def detect_functions(clean_lines, line_number, function_state, error):
# No end was found.
return
- is_declaration = bool(search(r'^[^{]*;', start_line))
- if is_declaration:
- ending_line_number = start_line_number
+ if start_line[body_start_position.column] == ';':
+ end_position = Position(body_start_position.row, body_start_position.column + 1)
else:
- open_brace_index = start_line.find('{')
- ending_line_number = close_expression(clean_lines.elided, Position(start_line_number, open_brace_index)).row
- function_state.begin(function, start_line_number, ending_line_number, is_declaration,
+ end_position = close_expression(clean_lines.elided, body_start_position)
+
+ # Check for nonsensical positions. (This happens in test cases which check code snippets.)
+ if parameter_end_position > body_start_position:
+ return
+
+ function_state.begin(function, body_start_position, end_position,
parameter_start_position, parameter_end_position, clean_lines)
return
@@ -1485,7 +1490,7 @@ def check_for_function_lengths(clean_lines, line_number, function_state, error):
raw = clean_lines.raw_lines
raw_line = raw[line_number]
- if function_state.ending_line_number == line_number: # last line
+ if function_state.end_position.row == line_number: # last line
if not search(r'\bNOLINT\b', raw_line):
function_state.check(error, line_number)
elif not match(r'^\s*$', line):
@@ -1531,7 +1536,7 @@ def check_function_definition(clean_lines, line_number, function_state, error):
error: The function to call with any errors found.
"""
# Only do checks when we have a function declaration.
- if line_number != function_state.body_start_line_number or not function_state.is_declaration:
+ if line_number != function_state.body_start_position.row or not function_state.is_declaration:
return
parameter_list = function_state.parameter_list()
@@ -1567,7 +1572,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_position.row:
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 614445f..1596771 100644
--- a/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
+++ b/Tools/Scripts/webkitpy/style/checkers/cpp_unittest.py
@@ -362,9 +362,11 @@ class FunctionDetectionTest(CppStyleTestBase):
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'])
+ self.assert_positions_equal(function_state.parameter_start_position, function_information['parameter_start_position'])
+ self.assert_positions_equal(function_state.parameter_end_position, function_information['parameter_end_position'])
+ self.assert_positions_equal(function_state.body_start_position, function_information['body_start_position'])
+ self.assert_positions_equal(function_state.end_position, function_information['end_position'])
expected_parameters = function_information.get('parameter_list')
if expected_parameters:
actual_parameters = function_state.parameter_list()
@@ -381,44 +383,56 @@ class FunctionDetectionTest(CppStyleTestBase):
['void theTestFunctionName(int) {',
'}'],
{'name': 'theTestFunctionName',
- 'body_start_line_number': 0,
- 'ending_line_number': 1,
+ 'parameter_start_position': (0, 24),
+ 'parameter_end_position': (0, 29),
+ 'body_start_position': (0, 30),
+ 'end_position': (1, 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,
+ 'parameter_start_position': (0, 18),
+ 'parameter_end_position': (0, 23),
+ 'body_start_position': (0, 23),
+ 'end_position': (0, 24),
'is_declaration': True})
self.perform_function_detection(
['CheckedInt<T> operator /(const CheckedInt<T> &lhs, const CheckedInt<T> &rhs);'],
{'name': 'operator /',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 24),
+ 'parameter_end_position': (0, 76),
+ 'body_start_position': (0, 76),
+ 'end_position': (0, 77),
'is_declaration': True})
self.perform_function_detection(
['CheckedInt<T> operator -(const CheckedInt<T> &lhs, const CheckedInt<T> &rhs);'],
{'name': 'operator -',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
- 'is_declaration': True})
+ 'parameter_start_position': (0, 24),
+ 'parameter_end_position': (0, 76),
+ 'body_start_position': (0, 76),
+ 'end_position': (0, 77),
+ 'is_declaration': True})
self.perform_function_detection(
['CheckedInt<T> operator !=(const CheckedInt<T> &lhs, const CheckedInt<T> &rhs);'],
{'name': 'operator !=',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 25),
+ 'parameter_end_position': (0, 77),
+ 'body_start_position': (0, 77),
+ 'end_position': (0, 78),
'is_declaration': True})
self.perform_function_detection(
['CheckedInt<T> operator +(const CheckedInt<T> &lhs, const CheckedInt<T> &rhs);'],
{'name': 'operator +',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 24),
+ 'parameter_end_position': (0, 76),
+ 'body_start_position': (0, 76),
+ 'end_position': (0, 77),
'is_declaration': True})
def test_ignore_macros(self):
@@ -433,8 +447,10 @@ class FunctionDetectionTest(CppStyleTestBase):
# 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,
+ 'parameter_start_position': (0, 3),
+ 'parameter_end_position': (2, 1),
+ 'body_start_position': (2, 1),
+ 'end_position': (2, 2),
'is_declaration': True})
# Simple test case with something that is not a function.
@@ -445,8 +461,10 @@ class FunctionDetectionTest(CppStyleTestBase):
function_state = self.perform_function_detection(
['void functionName();'],
{'name': 'functionName',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 17),
+ 'parameter_end_position': (0, 19),
+ 'body_start_position': (0, 19),
+ 'end_position': (0, 20),
'is_declaration': True,
'parameter_list': ()})
@@ -454,8 +472,10 @@ class FunctionDetectionTest(CppStyleTestBase):
function_state = self.perform_function_detection(
['void functionName(int);'],
{'name': 'functionName',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 17),
+ 'parameter_end_position': (0, 22),
+ 'body_start_position': (0, 22),
+ 'end_position': (0, 23),
'is_declaration': True,
'parameter_list':
({'type': 'int', 'name': '', 'row': 0},)})
@@ -464,8 +484,10 @@ class FunctionDetectionTest(CppStyleTestBase):
function_state = self.perform_function_detection(
['void functionName(unsigned a, short b, long c, long long short unsigned int);'],
{'name': 'functionName',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 17),
+ 'parameter_end_position': (0, 76),
+ 'body_start_position': (0, 76),
+ 'end_position': (0, 77),
'is_declaration': True,
'parameter_list':
({'type': 'unsigned', 'name': 'a', 'row': 0},
@@ -477,8 +499,10 @@ class FunctionDetectionTest(CppStyleTestBase):
function_state = self.perform_function_detection(
['virtual void determineARIADropEffects(Vector<String>*&, const unsigned long int*&, const MediaPlayer::Preload, Other<Other2, Other3<P1, P2> >, int);'],
{'name': 'determineARIADropEffects',
- 'body_start_line_number': 0,
- 'ending_line_number': 0,
+ 'parameter_start_position': (0, 37),
+ 'parameter_end_position': (0, 147),
+ 'body_start_position': (0, 147),
+ 'end_position': (0, 148),
'is_declaration': True,
'parameter_list':
({'type': 'Vector<String>*&', 'name': '', 'row': 0},
@@ -494,8 +518,10 @@ class FunctionDetectionTest(CppStyleTestBase):
'const ComplexTemplate<Class1, NestedTemplate<P1, P2> >* const * param = new ComplexTemplate<Class1, NestedTemplate<P1, P2> >(34, 42),',
'int* myCount = 0);'],
{'name': 'aFunctionName',
- 'body_start_line_number': 3,
- 'ending_line_number': 3,
+ 'parameter_start_position': (0, 45),
+ 'parameter_end_position': (3, 17),
+ 'body_start_position': (3, 17),
+ 'end_position': (3, 18),
'is_declaration': True,
'parameter_list':
({'type': 'PassRefPtr<MyClass>', 'name': 'paramName', 'row': 0},
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list