misra.py: Added rule 20.10

This commit is contained in:
Daniel Marjamäki 2019-04-11 10:50:07 +02:00
parent 3e3c805a66
commit a1c30b834c
2 changed files with 34 additions and 21 deletions

View File

@ -1631,27 +1631,36 @@ class MisraChecker:
d = Define(directive) d = Define(directive)
exp = '(' + d.expansionList + ')' exp = '(' + d.expansionList + ')'
for arg in d.args: for arg in d.args:
pos = exp.find(arg) pos = 0
if pos < 0: while pos < len(exp):
continue pos = exp.find(arg, pos)
pos1 = pos - 1 if pos < 0:
pos2 = pos + len(arg) break
if isalnum(exp[pos1]) or exp[pos1]=='_': pos1 = pos - 1
continue pos2 = pos + len(arg)
if isalnum(exp[pos2]) or exp[pos2]=='_': pos = pos2
continue if isalnum(exp[pos1]) or exp[pos1]=='_':
while exp[pos1] == ' ': continue
pos1 -= 1 if isalnum(exp[pos2]) or exp[pos2]=='_':
if exp[pos1] != '(' and exp[pos1] != '[': continue
self.reportError(directive, 20, 7); while exp[pos1] == ' ':
break pos1 -= 1
while exp[pos2] == ' ': if exp[pos1] != '(' and exp[pos1] != '[':
pos2 += 1 self.reportError(directive, 20, 7);
if exp[pos2] != ')' and exp[pos2] != ']': break
self.reportError(directive, 20, 7); while exp[pos2] == ' ':
break pos2 += 1
if exp[pos2] != ')' and exp[pos2] != ']':
self.reportError(directive, 20, 7);
break
def misra_20_10(self, data):
for directive in data.directives:
d = Define(directive)
if d.expansionList.find('#') >= 0:
self.reportError(directive, 20, 10);
def misra_20_13(self, data): def misra_20_13(self, data):
dir_pattern = re.compile(r'#[ ]*([^ (<]*)') dir_pattern = re.compile(r'#[ ]*([^ (<]*)')
for directive in data.directives: for directive in data.directives:
@ -2185,6 +2194,7 @@ class MisraChecker:
self.misra_20_4(cfg) self.misra_20_4(cfg)
self.misra_20_5(cfg) self.misra_20_5(cfg)
self.misra_20_7(cfg) self.misra_20_7(cfg)
self.misra_20_10(cfg)
self.misra_20_13(cfg) self.misra_20_13(cfg)
self.misra_20_14(cfg) self.misra_20_14(cfg)
self.misra_21_3(cfg) self.misra_21_3(cfg)

View File

@ -498,8 +498,11 @@ union misra_19_2 { }; // 19.2
#define int short // 20.4 #define int short // 20.4
#undef X // 20.5 #undef X // 20.5
#define M1(A) (A+1) // 20.7 #define M_20_7_1(A) (A+1) // 20.7
#define M2(A,B) (1+AB+2) #define M_20_7_2(A,B) (1+AB+2) // no warning
#define M_20_7_3(A) ((A)+A) // 20.7
#define STRINGIFY(a) (#a) // 20.7 20.10
#else1 // 20.13 #else1 // 20.13