MISRA 19 and 28

This commit is contained in:
Daniel Marjamäki 2017-04-09 10:11:54 +02:00
parent f67f2a2339
commit 6e0af5d01f
4 changed files with 49 additions and 10 deletions

View File

@ -515,15 +515,31 @@ class CppcheckData:
@endcode
"""
rawTokens = []
configurations = []
def __init__(self, filename):
self.configurations = []
data = ET.parse(filename)
for rawTokensNode in data.getroot():
if rawTokensNode.tag != 'rawtokens':
continue
files = []
for node in rawTokensNode:
if node.tag == 'file':
files.append(node.get('name'))
elif node.tag == 'tok':
tok = Token(node)
tok.file = files[int(node.get('fileIndex'))]
self.rawTokens.append(tok)
# root is 'dumps' node, each config has its own 'dump' subnode.
for cfgnode in data.getroot():
self.configurations.append(Configuration(cfgnode))
if cfgnode.tag=='dump':
self.configurations.append(Configuration(cfgnode))

View File

@ -22,6 +22,10 @@ void misra14() {
char c; // 14
}
void misra19() {
int x = 066; // 19
}
void misra28() {
register int x = 3; // 28
}

View File

@ -77,7 +77,7 @@ def misra3(data):
reportError(token, 'style', '3 break out inline assembler into separate function')
# 4 Provision should be made for appropriate run-time checking
# STATUS: Checked by Cppcheck
# STATUS: Done. Checked by Cppcheck
def misra4(data):
return
@ -128,7 +128,7 @@ def misra11(data):
reportError(token, 'style', '11 Identifier is longer than 31 characters')
# 12 Identifiers in different namespace shall not have the same spelling
# STATUS: Use compiler (-Wshadow etc)
# STATUS: Done. Use compiler (-Wshadow etc)
def misra12(data):
return
@ -178,9 +178,11 @@ def misra18(data):
return
# 19 Octal constants shall not be used
# STATUS: TODO
def misra19(data):
return
# STATUS: Done
def misra19(rawTokens):
for tok in rawTokens:
if re.match(r'0[0-6]+', tok.str):
reportError(tok, 'style', '19 Octal constants shall not be used')
# Declarations and Definitions
# ----------------------------
@ -227,8 +229,8 @@ def misra27(data):
# 28 The register storage class specifier should not be used
# STATUS: Done
def misra28(data):
for token in data.tokenlist:
def misra28(rawTokens):
for token in rawTokens:
if token.str == 'register':
reportError(token, 'style', '28 The register storage class specifier should not be used')
@ -789,7 +791,11 @@ def misra127(data):
for arg in sys.argv[1:]:
print('Checking ' + arg + '...')
data = cppcheckdata.parsedump(arg)
cfgNumber = 0
for cfg in data.configurations:
cfgNumber = cfgNumber + 1
if len(data.configurations) > 1:
print('Checking ' + arg + ', config "' + cfg.name + '"...')
misra1(cfg)
@ -810,7 +816,8 @@ for arg in sys.argv[1:]:
misra16(cfg)
misra17(cfg)
misra18(cfg)
misra19(cfg)
if cfgNumber == 1:
misra19(data.rawTokens)
misra20(cfg)
misra21(cfg)
misra22(cfg)
@ -819,7 +826,8 @@ for arg in sys.argv[1:]:
misra25(cfg)
misra26(cfg)
misra27(cfg)
misra28(cfg)
if cfgNumber == 1:
misra28(data.rawTokens)
misra29(cfg)
misra30(cfg)
misra31(cfg)

View File

@ -217,6 +217,17 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
if (fdump.is_open()) {
fdump << "<?xml version=\"1.0\"?>" << std::endl;
fdump << "<dumps>" << std::endl;
fdump << " <rawtokens>" << std::endl;
for (unsigned int i = 0; i < files.size(); ++i)
fdump << " <file index=\"" << i << "\" name=\"" << ErrorLogger::toxml(files[i]) << "\"/>" << std::endl;
for (const simplecpp::Token *tok = tokens1.cfront(); tok; tok = tok->next) {
fdump << " <tok "
<< "fileIndex=\"" << tok->location.fileIndex << "\" "
<< "linenr=\"" << tok->location.line << "\" "
<< "str=\"" << ErrorLogger::toxml(tok->str) << "\""
<< "/>" << std::endl;
}
fdump << " </rawtokens>" << std::endl;
}
}