Misra: Add rule 8.12

This commit is contained in:
Daniel Marjamäki 2017-04-16 19:01:33 +02:00
parent b2a846dff0
commit ad8fef8a2f
2 changed files with 28 additions and 1 deletions

View File

@ -26,6 +26,11 @@ void misra_7_3() {
int x = 12lu; // 7.3
}
enum e812 {
A=3,
B=3 // 8.12
};
void misra_8_14(char * restrict str) {} // 8.14
void misra_9_5() {

View File

@ -275,6 +275,26 @@ def misra_7_3(rawTokens):
if re.match(r'^[0-9]+l', tok.str):
reportError(tok, 7, 3)
def misra_8_12(data):
for token in data.tokenlist:
if token.str != '{':
continue
if not token.scope or token.scope.type != 'Enum':
continue
etok = token
values = []
while etok:
if etok.str == '}':
break
if etok.str == '=':
rhsValues = etok.astOperand2.values
if rhsValues and len(rhsValues)==1:
if rhsValues[0].intvalue in values:
reportError(etok, 8, 12)
break
values.append(rhsValues[0].intvalue)
etok = etok.next
def misra_8_14(rawTokens):
for token in rawTokens:
if token.str == 'restrict':
@ -474,7 +494,7 @@ def misra_12_2(data):
def misra_12_3(data):
for token in data.tokenlist:
if token.str != ',':
if token.str != ',' or token.scope.type == 'Enum':
continue
if token.astParent and (token.astParent.str in ['(', ',', '{']):
continue
@ -882,6 +902,8 @@ for arg in sys.argv[1:]:
if cfgNumber == 1:
misra_7_1(data.rawTokens)
misra_7_3(data.rawTokens)
misra_8_12(cfg)
if cfgNumber == 1:
misra_8_14(data.rawTokens)
misra_9_5(data.rawTokens)
misra_10_4(cfg)