misra.py: Check switch-clauses in R15.3 (#2538)
* misra.py: Check switch-clauses in R15.3 * break on violation
This commit is contained in:
parent
320cb9008f
commit
9155f3a83a
|
@ -1877,6 +1877,26 @@ class MisraChecker:
|
|||
scope = scope.nestedIn
|
||||
if not scope:
|
||||
self.reportError(token, 15, 3)
|
||||
# Jump crosses from one switch-clause to another is non-compliant
|
||||
elif scope.type == 'Switch':
|
||||
# Search for start of a current case block
|
||||
tcase_start = token
|
||||
while tcase_start and tcase_start.str not in ('case', 'default'):
|
||||
tcase_start = tcase_start.previous
|
||||
# Make sure that goto label doesn't occurs in the other
|
||||
# switch-clauses
|
||||
if tcase_start:
|
||||
t = scope.bodyStart
|
||||
in_this_case = False
|
||||
while t and t != scope.bodyEnd:
|
||||
if t == tcase_start:
|
||||
in_this_case = True
|
||||
if in_this_case and t.str not in ('case', 'default'):
|
||||
in_this_case = False
|
||||
if t == tok and not in_this_case:
|
||||
self.reportError(token, 15, 3)
|
||||
break
|
||||
t = t.next
|
||||
|
||||
def misra_15_5(self, data):
|
||||
for token in data.tokenlist:
|
||||
|
|
|
@ -696,6 +696,28 @@ void misra_15_3() {
|
|||
L1:
|
||||
} else {}
|
||||
} else {}
|
||||
|
||||
switch (x) {
|
||||
case 0:
|
||||
if (x == y) {
|
||||
goto L2; // 15.3 15.1
|
||||
}
|
||||
goto L2; // 15.3 15.1
|
||||
L3:
|
||||
foo();
|
||||
if (a == 0x42) {
|
||||
// Compliant:
|
||||
goto L3; // 15.1 15.2
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
y = x;
|
||||
L2:
|
||||
++x;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int misra_15_5() {
|
||||
|
|
Loading…
Reference in New Issue