Modified rule 8.12 (#1233)

This commit is contained in:
Swasti Shrivastava 2018-05-15 16:48:55 +05:30 committed by Daniel Marjamäki
parent f7746e4fb6
commit bb7ffd123d
2 changed files with 19 additions and 23 deletions

View File

@ -594,24 +594,22 @@ def misra_8_11(data):
def misra_8_12(data): def misra_8_12(data):
for token in data.tokenlist: for scope in data.scopes:
if token.str != '{': enum = []
implicit_enum = []
if scope.type != 'Enum':
continue continue
if not token.scope or token.scope.type != 'Enum': e_token = scope.bodyStart.next
continue while e_token != scope.bodyEnd:
etok = token if e_token.values:
values = [] enum.append(e_token.str)
while etok: if (e_token.values and e_token.isName and e_token.next.str != "="):
if etok.str == '}': for v in e_token.values:
break implicit_enum.append(v.intvalue)
if etok.str == '=': e_token = e_token.next
rhsValues = etok.astOperand2.values for implicit_enum_value in implicit_enum:
if rhsValues and len(rhsValues) == 1: if str(implicit_enum_value) in enum:
if rhsValues[0].intvalue in values: reportError(scope.bodyStart, 8, 12)
reportError(etok, 8, 12)
break
values.append(rhsValues[0].intvalue)
etok = etok.next
def misra_8_14(rawTokens): def misra_8_14(rawTokens):

View File

@ -55,7 +55,7 @@ const char *s41_2 = "\x41\x42";
void misra_5_1() { void misra_5_1() {
int a123456789012345678901234567890; // no-warning int a123456789012345678901234567890; // no-warning
int a1234567890123456789012345678901; // 5.1 ,5.2 int a1234567890123456789012345678901; // 5.1 5.2
} }
extern int misra_5_3_var_hides_var______31x; extern int misra_5_3_var_hides_var______31x;
@ -127,15 +127,13 @@ void misra_7_1() {
void misra_7_3() { void misra_7_3() {
int x = 12l; // 7.3 int x = 12l; // 7.3
int x = 12lu; // 7.3, 5.2 int x = 12lu; // 7.3 5.2
} }
extern int a811[]; // 8.11 extern int a811[]; // 8.11
enum e812 { enum misra_8_12_a { misra_a1 = 1, misra_a2 = 2, misra_a3, misra_a4 = 3 }; //8.12
A=3, enum misra_8_12_b { misra_b1, misra_b2, misra_b3 = 3, misra_b4 = 3 }; // no-warning
B=3 // 8.12
};
void misra_8_14(char * restrict str) {} // 8.14 void misra_8_14(char * restrict str) {} // 8.14