misra; implement rule 20.11

This commit is contained in:
Daniel Marjamäki 2021-07-22 16:11:25 +02:00
parent 3ba4696f4f
commit a65fa9b682
2 changed files with 11 additions and 0 deletions

View File

@ -3231,6 +3231,14 @@ class MisraChecker:
if d.expansionList.find('#') >= 0: if d.expansionList.find('#') >= 0:
self.reportError(directive, 20, 10) self.reportError(directive, 20, 10)
def misra_20_11(self, cfg):
for directive in cfg.directives:
d = Define(directive)
for arg in d.args:
res = re.search(r'[^#]#[ ]*%s[ ]*##' % arg, ' ' + d.expansionList)
if res:
self.reportError(directive, 20, 11)
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:
@ -3904,6 +3912,7 @@ class MisraChecker:
self.executeCheck(2008, self.misra_20_8, cfg) self.executeCheck(2008, self.misra_20_8, cfg)
self.executeCheck(2009, self.misra_20_9, cfg) self.executeCheck(2009, self.misra_20_9, cfg)
self.executeCheck(2010, self.misra_20_10, cfg) self.executeCheck(2010, self.misra_20_10, cfg)
self.executeCheck(2011, self.misra_20_11, cfg)
self.executeCheck(2013, self.misra_20_13, cfg) self.executeCheck(2013, self.misra_20_13, cfg)
self.executeCheck(2014, self.misra_20_14, cfg) self.executeCheck(2014, self.misra_20_14, cfg)
self.executeCheck(2101, self.misra_21_1, cfg) self.executeCheck(2101, self.misra_21_1, cfg)

View File

@ -1569,6 +1569,8 @@ struct { int a; } struct_20_7_s;
#define M_20_10(a) (#a) // 20.10 #define M_20_10(a) (#a) // 20.10
#define M_20_11(a) # a ## 1 // 20.11 20.10
#else1 // 20.13 #else1 // 20.13
#ifdef A #ifdef A