Misra: updated 12.1 check

This commit is contained in:
Daniel Marjamäki 2017-04-12 16:19:13 +02:00
parent d252a64ec8
commit f6afbbe65d
2 changed files with 20 additions and 1 deletions

View File

@ -17,7 +17,7 @@ void misra_7_3() {
}
void misra_12_1() {
// TODO sz = sizeof x + y; // 12.1
sz = sizeof x + y; // 12.1
a = (b * c) + d;
a = b << c + d; // 12.1
}

View File

@ -86,6 +86,24 @@ def misra_7_3(rawTokens):
reportError(tok, 7, 3)
def misra_12_1_sizeof(rawTokens):
state = 0
for tok in rawTokens:
if tok.str.startswith('//') or tok.str.startswith('/*'):
continue
if tok.str == 'sizeof':
state = 1
elif state == 1:
if re.match(r'^[a-zA-Z_]',tok.str):
state = 2
else:
state = 0
elif state == 2:
if tok.str in ['+','-','*','/','%']:
reportError(tok, 12, 1)
else:
state = 0
def misra_12_1(data):
for token in data.tokenlist:
p = getPrecedence(token)
@ -136,6 +154,7 @@ for arg in sys.argv[1:]:
if cfgNumber == 1:
misra_7_1(data.rawTokens)
misra_7_3(data.rawTokens)
misra_12_1_sizeof(data.rawTokens)
misra_12_1(cfg)
misra_13_5(cfg)
misra_14_4(cfg)