MISRA 19 and 28
This commit is contained in:
parent
f67f2a2339
commit
6e0af5d01f
|
@ -515,15 +515,31 @@ class CppcheckData:
|
||||||
@endcode
|
@endcode
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
rawTokens = []
|
||||||
configurations = []
|
configurations = []
|
||||||
|
|
||||||
def __init__(self, filename):
|
def __init__(self, filename):
|
||||||
self.configurations = []
|
self.configurations = []
|
||||||
|
|
||||||
data = ET.parse(filename)
|
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.
|
# root is 'dumps' node, each config has its own 'dump' subnode.
|
||||||
for cfgnode in data.getroot():
|
for cfgnode in data.getroot():
|
||||||
self.configurations.append(Configuration(cfgnode))
|
if cfgnode.tag=='dump':
|
||||||
|
self.configurations.append(Configuration(cfgnode))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ void misra14() {
|
||||||
char c; // 14
|
char c; // 14
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void misra19() {
|
||||||
|
int x = 066; // 19
|
||||||
|
}
|
||||||
|
|
||||||
void misra28() {
|
void misra28() {
|
||||||
register int x = 3; // 28
|
register int x = 3; // 28
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ def misra3(data):
|
||||||
reportError(token, 'style', '3 break out inline assembler into separate function')
|
reportError(token, 'style', '3 break out inline assembler into separate function')
|
||||||
|
|
||||||
# 4 Provision should be made for appropriate run-time checking
|
# 4 Provision should be made for appropriate run-time checking
|
||||||
# STATUS: Checked by Cppcheck
|
# STATUS: Done. Checked by Cppcheck
|
||||||
def misra4(data):
|
def misra4(data):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ def misra11(data):
|
||||||
reportError(token, 'style', '11 Identifier is longer than 31 characters')
|
reportError(token, 'style', '11 Identifier is longer than 31 characters')
|
||||||
|
|
||||||
# 12 Identifiers in different namespace shall not have the same spelling
|
# 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):
|
def misra12(data):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -178,9 +178,11 @@ def misra18(data):
|
||||||
return
|
return
|
||||||
|
|
||||||
# 19 Octal constants shall not be used
|
# 19 Octal constants shall not be used
|
||||||
# STATUS: TODO
|
# STATUS: Done
|
||||||
def misra19(data):
|
def misra19(rawTokens):
|
||||||
return
|
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
|
# Declarations and Definitions
|
||||||
# ----------------------------
|
# ----------------------------
|
||||||
|
@ -227,8 +229,8 @@ def misra27(data):
|
||||||
|
|
||||||
# 28 The register storage class specifier should not be used
|
# 28 The register storage class specifier should not be used
|
||||||
# STATUS: Done
|
# STATUS: Done
|
||||||
def misra28(data):
|
def misra28(rawTokens):
|
||||||
for token in data.tokenlist:
|
for token in rawTokens:
|
||||||
if token.str == 'register':
|
if token.str == 'register':
|
||||||
reportError(token, 'style', '28 The register storage class specifier should not be used')
|
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:]:
|
for arg in sys.argv[1:]:
|
||||||
print('Checking ' + arg + '...')
|
print('Checking ' + arg + '...')
|
||||||
data = cppcheckdata.parsedump(arg)
|
data = cppcheckdata.parsedump(arg)
|
||||||
|
|
||||||
|
cfgNumber = 0
|
||||||
|
|
||||||
for cfg in data.configurations:
|
for cfg in data.configurations:
|
||||||
|
cfgNumber = cfgNumber + 1
|
||||||
if len(data.configurations) > 1:
|
if len(data.configurations) > 1:
|
||||||
print('Checking ' + arg + ', config "' + cfg.name + '"...')
|
print('Checking ' + arg + ', config "' + cfg.name + '"...')
|
||||||
misra1(cfg)
|
misra1(cfg)
|
||||||
|
@ -810,7 +816,8 @@ for arg in sys.argv[1:]:
|
||||||
misra16(cfg)
|
misra16(cfg)
|
||||||
misra17(cfg)
|
misra17(cfg)
|
||||||
misra18(cfg)
|
misra18(cfg)
|
||||||
misra19(cfg)
|
if cfgNumber == 1:
|
||||||
|
misra19(data.rawTokens)
|
||||||
misra20(cfg)
|
misra20(cfg)
|
||||||
misra21(cfg)
|
misra21(cfg)
|
||||||
misra22(cfg)
|
misra22(cfg)
|
||||||
|
@ -819,7 +826,8 @@ for arg in sys.argv[1:]:
|
||||||
misra25(cfg)
|
misra25(cfg)
|
||||||
misra26(cfg)
|
misra26(cfg)
|
||||||
misra27(cfg)
|
misra27(cfg)
|
||||||
misra28(cfg)
|
if cfgNumber == 1:
|
||||||
|
misra28(data.rawTokens)
|
||||||
misra29(cfg)
|
misra29(cfg)
|
||||||
misra30(cfg)
|
misra30(cfg)
|
||||||
misra31(cfg)
|
misra31(cfg)
|
||||||
|
|
|
@ -217,6 +217,17 @@ unsigned int CppCheck::processFile(const std::string& filename, const std::strin
|
||||||
if (fdump.is_open()) {
|
if (fdump.is_open()) {
|
||||||
fdump << "<?xml version=\"1.0\"?>" << std::endl;
|
fdump << "<?xml version=\"1.0\"?>" << std::endl;
|
||||||
fdump << "<dumps>" << 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue