Fix MISRA 58

This commit is contained in:
Daniel Marjamäki 2017-04-08 19:33:26 +02:00
parent 8846077caa
commit 8755023c1c
3 changed files with 17 additions and 1 deletions

View File

@ -236,6 +236,8 @@ class Scope:
classEndId = None
classEnd = None
className = None
nestedInId = None
nestedIn = None
type = None
def __init__(self, element):

View File

@ -41,3 +41,10 @@ void misra56() {
void misra57() {
continue; // 57
}
void misra58() {
while (1) {
if(x)
break; // 58
}
}

View File

@ -409,7 +409,14 @@ def misra57(data):
# 58 The break statement shall not be used, except to terminate the cases of a switch statement
# STATUS: TODO
def misra58(data):
return
for token in data.tokenlist:
if token.str != "break":
continue
s = token.scope
while s and s.type == 'If':
s = s.nestedIn
if s and s.type in ['While', 'For']:
reportError(token, 'style', '58 The break statement shall not be used, except to terminate the cases of a switch statement')
# 59 The statements forming the body of an if, else, else if, .. shall always be enclosed in braces
# STATUS: TODO