| 25 | return False |
| 26 | |
| 27 | class CommonChecks: |
| 28 | def __init__(self, c, path, cpp_class_map, fix=False, slow=False): |
| 29 | self.c = c |
| 30 | self.path = path |
| 31 | self.fix = fix |
| 32 | self.map = cpp_class_map |
| 33 | |
| 34 | def run(self): |
| 35 | self.void_params() |
| 36 | self.consistent_float_literals() |
| 37 | self.absolute_include_paths() |
| 38 | self.newline_after_last_include() |
| 39 | self.newline_eof() |
| 40 | return self.c |
| 41 | |
| 42 | def void_params(self): |
| 43 | lines = self.c.splitlines() |
| 44 | new_lines = [] |
| 45 | changed = False |
| 46 | for line in lines: |
| 47 | original_line = line |
| 48 | if "(void);" in line or "(void) {" in line or "(void) const" in line: |
| 49 | FAIL("Function parameters should be empty instead of \"(void)\"!", original_line, self.path) |
| 50 | # FIX |
| 51 | if self.fix: |
| 52 | line = line.replace("(void);", "();") |
| 53 | line = line.replace("(void) {", "() {") |
| 54 | line = line.replace("(void) const", "() const") |
| 55 | changed = True |
| 56 | new_lines.append(line) |
| 57 | |
| 58 | if changed: |
| 59 | self.c = "\n".join(new_lines) |
| 60 | |
| 61 | def consistent_float_literals(self): |
| 62 | lines = self.c.splitlines() |
| 63 | new_lines = [] |
| 64 | changed = False |
| 65 | # float value = 1.f; becomes |
| 66 | # float value = 1.0f; |
| 67 | pattern = re.compile(r'\.f(?![a-zA-Z])') |
| 68 | for line in lines: |
| 69 | original_line = line |
| 70 | if pattern.search(line): |
| 71 | FAIL(" '.f' is not allowed, use '.0f' instead!", original_line, self.path) |
| 72 | # FIX |
| 73 | if self.fix: |
| 74 | line = pattern.sub('.0f', line) |
| 75 | changed = True |
| 76 | new_lines.append(line) |
| 77 | |
| 78 | if changed: |
| 79 | self.c = "\n".join(new_lines) |
| 80 | |
| 81 | def newline_eof(self): |
| 82 | lines = self.c.splitlines() |
| 83 | new_lines = lines[:] |
| 84 | changed = False |