misra.py - rule 8.12 fixed for enums depending on other enums values (#1287)
This commit is contained in:
parent
8925a0fd81
commit
3702c477c0
|
@ -737,20 +737,22 @@ def misra_8_11(data):
|
||||||
|
|
||||||
def misra_8_12(data):
|
def misra_8_12(data):
|
||||||
for scope in data.scopes:
|
for scope in data.scopes:
|
||||||
enum = []
|
enum_values = []
|
||||||
implicit_enum = []
|
implicit_enum_values = []
|
||||||
if scope.type != 'Enum':
|
if scope.type != 'Enum':
|
||||||
continue
|
continue
|
||||||
e_token = scope.bodyStart.next
|
e_token = scope.bodyStart.next
|
||||||
while e_token != scope.bodyEnd:
|
while e_token != scope.bodyEnd:
|
||||||
if e_token.values:
|
if e_token.isName and \
|
||||||
enum.append(e_token.str)
|
e_token.values and \
|
||||||
if (e_token.values and e_token.isName and e_token.next.str != "="):
|
e_token.valueType and e_token.valueType.typeScope == scope:
|
||||||
for v in e_token.values:
|
token_values = [v.intvalue for v in e_token.values]
|
||||||
implicit_enum.append(v.intvalue)
|
enum_values += token_values
|
||||||
|
if e_token.next.str != "=":
|
||||||
|
implicit_enum_values += token_values
|
||||||
e_token = e_token.next
|
e_token = e_token.next
|
||||||
for implicit_enum_value in implicit_enum:
|
for implicit_enum_value in implicit_enum_values:
|
||||||
if str(implicit_enum_value) in enum:
|
if enum_values.count(implicit_enum_value) != 1:
|
||||||
reportError(scope.bodyStart, 8, 12)
|
reportError(scope.bodyStart, 8, 12)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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_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_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
|
void misra_8_14(char * restrict str) {} // 8.14
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue