Misra: Add rule 16.2

This commit is contained in:
Daniel Marjamäki 2017-04-14 08:17:32 +02:00
parent 0052ef7437
commit aa2d1fd683
2 changed files with 16 additions and 0 deletions

View File

@ -113,3 +113,12 @@ void misra_15_7() {
if (x!=0){} // 15.7 if (x!=0){} // 15.7
} }
void misra_16_2() {
switch (x) {
case 1:
while (y>4) {
case 2: break; // 16.2
}
break;
}
}

View File

@ -412,6 +412,12 @@ def misra_15_7(data):
if not else_ or else_.str != 'else': if not else_ or else_.str != 'else':
reportError(token, 15, 7) reportError(token, 15, 7)
# TODO add 16.1 rule
def misra_16_2(data):
for token in data.tokenlist:
if token.str == 'case' and token.scope.type != 'Switch':
reportError(token, 16, 2)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
print('Checking ' + arg + '...') print('Checking ' + arg + '...')
@ -448,4 +454,5 @@ for arg in sys.argv[1:]:
if cfgNumber == 1: if cfgNumber == 1:
misra_15_6(data.rawTokens) misra_15_6(data.rawTokens)
misra_15_7(cfg) misra_15_7(cfg)
misra_16_2(cfg)