Rule 5.3 modified along with test suite (#1227)
* Added rule 5.2 * updated 5.2 request-checks: true * Added rule 5.3 * Changed rule 5.4, 5.5 * Updated test suite for Rule 5.2 * Changes in Rule 5.4 and 5.5 * Change in function name in test suite and removed type from class token in cppcheck * Changed the name of function in misra-test.c * Modified rule 5.3 * Modified misra-test.c for rule 5.3
This commit is contained in:
parent
d2d1bf900b
commit
4b873ed573
|
@ -467,36 +467,56 @@ def misra_5_2(data):
|
|||
reportError(scopename2.bodyStart, 5, 2)
|
||||
|
||||
def misra_5_3(data):
|
||||
enum = []
|
||||
scopeVars = {}
|
||||
for var in data.variables:
|
||||
if var.isArgument:
|
||||
# TODO
|
||||
continue
|
||||
if var.nameToken.scope not in scopeVars:
|
||||
scopeVars[var.nameToken.scope] = []
|
||||
scopeVars[var.nameToken.scope].append(var)
|
||||
|
||||
for innerScope in data.scopes:
|
||||
if innerScope.type == 'Global':
|
||||
if innerScope.type == "Enum":
|
||||
enum_token = innerScope.bodyStart.next
|
||||
while enum_token != innerScope.bodyEnd:
|
||||
if enum_token.values and enum_token.isName:
|
||||
enum.append(enum_token.str)
|
||||
enum_token = enum_token.next
|
||||
continue
|
||||
if innerScope not in scopeVars:
|
||||
continue
|
||||
if innerScope.type == "Global":
|
||||
continue
|
||||
for innerVar in scopeVars[innerScope]:
|
||||
outerScope = innerScope.nestedIn
|
||||
while outerScope:
|
||||
if outerScope not in scopeVars:
|
||||
outerScope = outerScope.nestedIn
|
||||
continue
|
||||
found = False
|
||||
for outerVar in scopeVars[outerScope]:
|
||||
if innerVar.nameToken.str == outerVar.nameToken.str:
|
||||
found = True
|
||||
break
|
||||
if found:
|
||||
if innerVar.nameToken.str[:31] == outerVar.nameToken.str[:31]:
|
||||
if outerVar.isArgument and outerScope.type == "Global" and not innerVar.isArgument:
|
||||
continue
|
||||
if int(innerVar.nameToken.linenr) > int(outerVar.nameToken.linenr):
|
||||
reportError(innerVar.nameToken, 5, 3)
|
||||
break
|
||||
else:
|
||||
reportError(outerVar.nameToken, 5, 3)
|
||||
outerScope = outerScope.nestedIn
|
||||
for scope in data.scopes:
|
||||
if (scope.className and innerVar.nameToken.str[:31] == scope.className[:31]):
|
||||
if int(innerVar.nameToken.linenr) > int(scope.bodyStart.linenr):
|
||||
reportError(innerVar.nameToken, 5, 3)
|
||||
else:
|
||||
reportError(scope.bodyStart, 5, 3)
|
||||
|
||||
for e in enum:
|
||||
if scope.className and innerVar.nameToken.str[:31] == e[:31]:
|
||||
if int(innerVar.nameToken.linenr) > int(innerScope.bodyStart.linenr):
|
||||
reportError(innerVar.nameToken, 5, 3)
|
||||
else:
|
||||
reportError(innerScope.bodyStart, 5, 3)
|
||||
for e in enum:
|
||||
for scope in data.scopes:
|
||||
if (scope.className and scope.className[:31] == e[:31]):
|
||||
reportError(scope.bodyStart, 5, 3)
|
||||
|
||||
def misra_5_4(data):
|
||||
macro = {}
|
||||
|
|
|
@ -58,12 +58,33 @@ void misra_5_1() {
|
|||
int a1234567890123456789012345678901; // 5.1 ,5.2
|
||||
}
|
||||
|
||||
void misra_5_3() {
|
||||
u8 x=1;
|
||||
if (y!=0) {
|
||||
u8 x=2; // 5.3
|
||||
} else {}
|
||||
extern int misra_5_3_var_hides_var______31x;
|
||||
void misra_5_3_var_hides_function_31x (void) {}
|
||||
enum misra_5_3_Enum {
|
||||
misra_5_3_var_hidesenumconst_31x = 2,misra_5_3_enum_hidesfunction_31x = 5
|
||||
};
|
||||
void misra_5_3_func1(void)
|
||||
{
|
||||
int misra_5_3_var_hides_var______31y; //5.3
|
||||
int misra_5_3_var_hides_function_31y; //5.3
|
||||
int misra_5_3_var_hidesenumconst_31y; //5.3
|
||||
switch(misra_5_3_func2())
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
do
|
||||
{
|
||||
int misra_5_3_var_hides_var_1____31x;
|
||||
if(misra_5_3_func3())
|
||||
{
|
||||
int misra_5_3_var_hides_var_1____31y = 1; //5.3
|
||||
}
|
||||
} while(misra_5_3_func2());
|
||||
}
|
||||
}
|
||||
}
|
||||
void misra_5_3_enum_hidesfunction_31y(void) {} //5.3
|
||||
|
||||
|
||||
#define misra_5_4_macro_hides_macro__31x 1
|
||||
#define misra_5_4_param_hides_macro__31x 1
|
||||
|
|
Loading…
Reference in New Issue