| OLD | NEW |
| 1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
| 2 # | 2 # |
| 3 # Copyright (C) 2009, 2010, 2012 Google Inc. All rights reserved. | 3 # Copyright (C) 2009, 2010, 2012 Google Inc. All rights reserved. |
| 4 # Copyright (C) 2009 Torch Mobile Inc. | 4 # Copyright (C) 2009 Torch Mobile Inc. |
| 5 # Copyright (C) 2009 Apple Inc. All rights reserved. | 5 # Copyright (C) 2009 Apple Inc. All rights reserved. |
| 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) | 6 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org) |
| 7 # | 7 # |
| 8 # Redistribution and use in source and binary forms, with or without | 8 # Redistribution and use in source and binary forms, with or without |
| 9 # modification, are permitted provided that the following conditions are | 9 # modification, are permitted provided that the following conditions are |
| 10 # met: | 10 # met: |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 """Convert the column number from the single line into the original | 434 """Convert the column number from the single line into the original |
| 435 line number. | 435 line number. |
| 436 | 436 |
| 437 Special cases: | 437 Special cases: |
| 438 * Columns in the added spaces are considered part of the previous line. | 438 * Columns in the added spaces are considered part of the previous line. |
| 439 * Columns beyond the end of the line are consider part the last line | 439 * Columns beyond the end of the line are consider part the last line |
| 440 in the view. | 440 in the view. |
| 441 """ | 441 """ |
| 442 total_columns = 0 | 442 total_columns = 0 |
| 443 row_offset = 0 | 443 row_offset = 0 |
| 444 while row_offset < len(self._row_lengths) - 1 and single_line_column_num
ber >= total_columns + self._row_lengths[row_offset]: | 444 while (row_offset < len(self._row_lengths) - 1 and |
| 445 single_line_column_number >= total_columns + self._row_lengths[ro
w_offset]): |
| 445 total_columns += self._row_lengths[row_offset] | 446 total_columns += self._row_lengths[row_offset] |
| 446 row_offset += 1 | 447 row_offset += 1 |
| 447 return self._starting_row + row_offset | 448 return self._starting_row + row_offset |
| 448 | 449 |
| 449 | 450 |
| 450 def create_skeleton_parameters(all_parameters): | 451 def create_skeleton_parameters(all_parameters): |
| 451 """Converts a parameter list to a skeleton version. | 452 """Converts a parameter list to a skeleton version. |
| 452 | 453 |
| 453 The skeleton only has one word for the parameter name, one word for the type
, | 454 The skeleton only has one word for the parameter name, one word for the type
, |
| 454 and commas after each parameter and only there. Everything in the skeleton | 455 and commas after each parameter and only there. Everything in the skeleton |
| (...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2019 matched = search(r'^\s*(?P<token1>[a-zA-Z0-9_\*&]+)\s\s+(?P<token2>[a-zA-Z0-
9_\*&]+)', line) | 2020 matched = search(r'^\s*(?P<token1>[a-zA-Z0-9_\*&]+)\s\s+(?P<token2>[a-zA-Z0-
9_\*&]+)', line) |
| 2020 if matched: | 2021 if matched: |
| 2021 error(line_number, 'whitespace/declaration', 3, | 2022 error(line_number, 'whitespace/declaration', 3, |
| 2022 'Extra space between %s and %s' % (matched.group('token1'), matche
d.group('token2'))) | 2023 'Extra space between %s and %s' % (matched.group('token1'), matche
d.group('token2'))) |
| 2023 | 2024 |
| 2024 if file_extension == 'cpp': | 2025 if file_extension == 'cpp': |
| 2025 # C++ should have the & or * beside the type not the variable name. | 2026 # C++ should have the & or * beside the type not the variable name. |
| 2026 matched = match(r'\s*\w+(?<!\breturn|\bdelete)\s+(?P<pointer_operator>\*
|\&)\w+', line) | 2027 matched = match(r'\s*\w+(?<!\breturn|\bdelete)\s+(?P<pointer_operator>\*
|\&)\w+', line) |
| 2027 if matched: | 2028 if matched: |
| 2028 error(line_number, 'whitespace/declaration', 3, | 2029 error(line_number, 'whitespace/declaration', 3, |
| 2029 'Declaration has space between type name and %s in %s' % (matc
hed.group('pointer_operator'), matched.group(0).strip())) | 2030 'Declaration has space between type name and %s in %s' % ( |
| 2031 matched.group('pointer_operator'), matched.group(0).strip(
))) |
| 2030 | 2032 |
| 2031 elif file_extension == 'c': | 2033 elif file_extension == 'c': |
| 2032 # C Pointer declaration should have the * beside the variable not the ty
pe name. | 2034 # C Pointer declaration should have the * beside the variable not the ty
pe name. |
| 2033 matched = search(r'^\s*\w+\*\s+\w+', line) | 2035 matched = search(r'^\s*\w+\*\s+\w+', line) |
| 2034 if matched: | 2036 if matched: |
| 2035 error(line_number, 'whitespace/declaration', 3, | 2037 error(line_number, 'whitespace/declaration', 3, |
| 2036 'Declaration has space between * and variable name in %s' % ma
tched.group(0).strip()) | 2038 'Declaration has space between * and variable name in %s' % ma
tched.group(0).strip()) |
| 2037 | 2039 |
| 2038 # Next we will look for issues with function calls. | 2040 # Next we will look for issues with function calls. |
| 2039 check_spacing_for_function_call(line, line_number, error) | 2041 check_spacing_for_function_call(line, line_number, error) |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2283 clean_lines: A CleansedLines instance containing the file. | 2285 clean_lines: A CleansedLines instance containing the file. |
| 2284 line_number: The number of the line to check. | 2286 line_number: The number of the line to check. |
| 2285 file_state: A _FileState instance which maintains information about | 2287 file_state: A _FileState instance which maintains information about |
| 2286 the state of things in the file. | 2288 the state of things in the file. |
| 2287 error: The function to call with any errors found. | 2289 error: The function to call with any errors found. |
| 2288 """ | 2290 """ |
| 2289 | 2291 |
| 2290 line = clean_lines.elided[line_number] # Get rid of comments and strings. | 2292 line = clean_lines.elided[line_number] # Get rid of comments and strings. |
| 2291 | 2293 |
| 2292 ctype_function_search = search( | 2294 ctype_function_search = search( |
| 2293 r'\b(?P<ctype_function>(isalnum|isalpha|isascii|isblank|iscntrl|isdigit|
isgraph|islower|isprint|ispunct|isspace|isupper|isxdigit|toascii|tolower|toupper
))\s*\(', line) | 2295 (r'\b(?P<ctype_function>(isalnum|isalpha|isascii|isblank|iscntrl|isdigit
|isgraph|' |
| 2296 r'islower|isprint|ispunct|isspace|isupper|isxdigit|toascii|tolower|toup
per))\s*\('), line) |
| 2294 if not ctype_function_search: | 2297 if not ctype_function_search: |
| 2295 return | 2298 return |
| 2296 | 2299 |
| 2297 ctype_function = ctype_function_search.group('ctype_function') | 2300 ctype_function = ctype_function_search.group('ctype_function') |
| 2298 error(line_number, 'runtime/ctype_function', 4, | 2301 error(line_number, 'runtime/ctype_function', 4, |
| 2299 'Use equivalent function in <wtf/ASCIICType.h> instead of the %s() fun
ction.' | 2302 'Use equivalent function in <wtf/ASCIICType.h> instead of the %s() fun
ction.' |
| 2300 % (ctype_function)) | 2303 % (ctype_function)) |
| 2301 | 2304 |
| 2302 | 2305 |
| 2303 def check_switch_indentation(clean_lines, line_number, error): | 2306 def check_switch_indentation(clean_lines, line_number, error): |
| (...skipping 1874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4178 | 4181 |
| 4179 def check(self, lines): | 4182 def check(self, lines): |
| 4180 _process_lines(self.file_path, self.file_extension, lines, | 4183 _process_lines(self.file_path, self.file_extension, lines, |
| 4181 self.handle_style_error, self.min_confidence) | 4184 self.handle_style_error, self.min_confidence) |
| 4182 | 4185 |
| 4183 | 4186 |
| 4184 # FIXME: Remove this function (requires refactoring unit tests). | 4187 # FIXME: Remove this function (requires refactoring unit tests). |
| 4185 def process_file_data(filename, file_extension, lines, error, min_confidence, fs
=None): | 4188 def process_file_data(filename, file_extension, lines, error, min_confidence, fs
=None): |
| 4186 checker = CppChecker(filename, file_extension, error, min_confidence, fs) | 4189 checker = CppChecker(filename, file_extension, error, min_confidence, fs) |
| 4187 checker.check(lines) | 4190 checker.check(lines) |
| OLD | NEW |