misra.py - rule 8.12 fixed for enums depending on other enums values (#1287)

This commit is contained in:
Konrad Grochowski 2018-06-13 06:54:30 +02:00 committed by Daniel Marjamäki
parent 8925a0fd81
commit 3702c477c0
2 changed files with 12 additions and 9 deletions

View File

@ -737,20 +737,22 @@ def misra_8_11(data):
def misra_8_12(data):
for scope in data.scopes:
enum = []
implicit_enum = []
enum_values = []
implicit_enum_values = []
if scope.type != 'Enum':
continue
e_token = scope.bodyStart.next
while e_token != scope.bodyEnd:
if e_token.values:
enum.append(e_token.str)
if (e_token.values and e_token.isName and e_token.next.str != "="):
for v in e_token.values:
implicit_enum.append(v.intvalue)
if e_token.isName and \
e_token.values and \
e_token.valueType and e_token.valueType.typeScope == scope:
token_values = [v.intvalue for v in e_token.values]
enum_values += token_values
if e_token.next.str != "=":
implicit_enum_values += token_values
e_token = e_token.next
for implicit_enum_value in implicit_enum:
if str(implicit_enum_value) in enum:
for implicit_enum_value in implicit_enum_values:
if enum_values.count(implicit_enum_value) != 1:
reportError(scope.bodyStart, 8, 12)

View File

@ -139,6 +139,7 @@ extern int a811[]; // 8.11
enum misra_8_12_a { misra_a1 = 1, misra_a2 = 2, misra_a3, misra_a4 = 3 }; //8.12
enum misra_8_12_b { misra_b1, misra_b2, misra_b3 = 3, misra_b4 = 3 }; // no-warning
enum misra_8_12_c { misra_c1 = misra_a1, misra_c2 = 1 }; // no-warning
void misra_8_14(char * restrict str) {} // 8.14