| 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 1475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1486 if args: | 1486 if args: |
| 1487 classinfo.unsigned_bitfields.append('%d: %s' % (line_number, args.group(
1))) | 1487 classinfo.unsigned_bitfields.append('%d: %s' % (line_number, args.group(
1))) |
| 1488 well_typed_bitfield = True | 1488 well_typed_bitfield = True |
| 1489 | 1489 |
| 1490 # Look for other bitfield declarations. We don't care about those in | 1490 # Look for other bitfield declarations. We don't care about those in |
| 1491 # size-matching structs. | 1491 # size-matching structs. |
| 1492 if not (well_typed_bitfield or classinfo.name.startswith('SameSizeAs') or | 1492 if not (well_typed_bitfield or classinfo.name.startswith('SameSizeAs') or |
| 1493 classinfo.name.startswith('Expected')): | 1493 classinfo.name.startswith('Expected')): |
| 1494 args = match(r'\s*(\S+)\s+(\S+)\s*:\s*\d+\s*;', line) | 1494 args = match(r'\s*(\S+)\s+(\S+)\s*:\s*\d+\s*;', line) |
| 1495 if args: | 1495 if args: |
| 1496 error(line_number, 'runtime/bitfields', 4, | 1496 field_type = args.group(1) |
| 1497 'Member %s of class %s defined as a bitfield of type %s. ' | 1497 field_name = args.group(2) |
| 1498 'Please declare all bitfields as unsigned.' | 1498 |
| 1499 % (args.group(2), classinfo.name, args.group(1))) | 1499 # Look for an unsigned assert for this type in this file. |
| 1500 has_assert = False |
| 1501 for other_line in clean_lines.lines: |
| 1502 if match(r'\bstatic_assert(\s*IsEnumSafeToStoreInBitfield\s*<\s*
(\S+)?' + field_type + r'>::value\s*);', other_line): |
| 1503 has_assert = True |
| 1504 break |
| 1505 |
| 1506 if not has_assert: |
| 1507 error(line_number, 'runtime/bitfields', 4, |
| 1508 'Member %s of class %s defined as a bitfield of type %s. ' |
| 1509 'Please declare all bitfields as unsigned, or add ' |
| 1510 'static_assert(IsEnumSafeToStoreInBitfield<%s>::value).' |
| 1511 % (field_name, classinfo.name, field_type, field_type)) |
| 1500 | 1512 |
| 1501 | 1513 |
| 1502 def check_spacing_for_function_call(line, line_number, error): | 1514 def check_spacing_for_function_call(line, line_number, error): |
| 1503 """Checks for the correctness of various spacing around function calls. | 1515 """Checks for the correctness of various spacing around function calls. |
| 1504 | 1516 |
| 1505 Args: | 1517 Args: |
| 1506 line: The text of the line to check. | 1518 line: The text of the line to check. |
| 1507 line_number: The number of the line to check. | 1519 line_number: The number of the line to check. |
| 1508 error: The function to call with any errors found. | 1520 error: The function to call with any errors found. |
| 1509 """ | 1521 """ |
| (...skipping 2698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4208 | 4220 |
| 4209 def check(self, lines): | 4221 def check(self, lines): |
| 4210 _process_lines(self.file_path, self.file_extension, lines, | 4222 _process_lines(self.file_path, self.file_extension, lines, |
| 4211 self.handle_style_error, self.min_confidence) | 4223 self.handle_style_error, self.min_confidence) |
| 4212 | 4224 |
| 4213 | 4225 |
| 4214 # FIXME: Remove this function (requires refactoring unit tests). | 4226 # FIXME: Remove this function (requires refactoring unit tests). |
| 4215 def process_file_data(filename, file_extension, lines, error, min_confidence, fs
=None): | 4227 def process_file_data(filename, file_extension, lines, error, min_confidence, fs
=None): |
| 4216 checker = CppChecker(filename, file_extension, error, min_confidence, fs) | 4228 checker = CppChecker(filename, file_extension, error, min_confidence, fs) |
| 4217 checker.check(lines) | 4229 checker.check(lines) |
| OLD | NEW |