Misra: Add rule 8.11

This commit is contained in:
Daniel Marjamäki 2017-04-17 07:45:27 +02:00
parent 6c8712c57b
commit 4f64e67298
4 changed files with 14 additions and 2 deletions

View File

@ -345,6 +345,7 @@ class Variable:
isArgument Is this variable a function argument? isArgument Is this variable a function argument?
isArray Is this variable an array? isArray Is this variable an array?
isClass Is this variable a class or struct? isClass Is this variable a class or struct?
isExtern Is this variable an extern variable?
isLocal Is this variable a local variable? isLocal Is this variable a local variable?
isPointer Is this variable a pointer isPointer Is this variable a pointer
isReference Is this variable a reference isReference Is this variable a reference
@ -361,6 +362,7 @@ class Variable:
isArgument = False isArgument = False
isArray = False isArray = False
isClass = False isClass = False
isExtern = False
isLocal = False isLocal = False
isPointer = False isPointer = False
isReference = False isReference = False
@ -377,6 +379,7 @@ class Variable:
self.isArgument = element.get('isArgument') == 'true' self.isArgument = element.get('isArgument') == 'true'
self.isArray = element.get('isArray') == 'true' self.isArray = element.get('isArray') == 'true'
self.isClass = element.get('isClass') == 'true' self.isClass = element.get('isClass') == 'true'
self.isExtern = element.get('isExtern') == 'true'
self.isLocal = element.get('isLocal') == 'true' self.isLocal = element.get('isLocal') == 'true'
self.isPointer = element.get('isPointer') == 'true' self.isPointer = element.get('isPointer') == 'true'
self.isReference = element.get('isReference') == 'true' self.isReference = element.get('isReference') == 'true'

View File

@ -26,6 +26,8 @@ void misra_7_3() {
int x = 12lu; // 7.3 int x = 12lu; // 7.3
} }
extern int a811[]; // 8.11
enum e812 { enum e812 {
A=3, A=3,
B=3 // 8.12 B=3 // 8.12

View File

@ -283,6 +283,11 @@ def misra_7_3(rawTokens):
if re.match(r'^[0-9]+l', tok.str): if re.match(r'^[0-9]+l', tok.str):
reportError(tok, 7, 3) reportError(tok, 7, 3)
def misra_8_11(data):
for var in data.variables:
if var.isExtern and simpleMatch(var.nameToken.next, '[ ]') and var.nameToken.scope.type == 'Global':
reportError(var.nameToken, 8, 11)
def misra_8_12(data): def misra_8_12(data):
for token in data.tokenlist: for token in data.tokenlist:
if token.str != '{': if token.str != '{':
@ -780,9 +785,9 @@ def misra_18_5(data):
def misra_18_8(data): def misra_18_8(data):
for var in data.variables: for var in data.variables:
if not var.isArray: if not var.isArray or not var.isLocal:
continue continue
# TODO Array dimensions are not available in dump # TODO Array dimensions are not available in dump, must look in tokens
typetok = var.nameToken.next typetok = var.nameToken.next
if not typetok or typetok.str != '[': if not typetok or typetok.str != '[':
continue continue
@ -934,6 +939,7 @@ for arg in sys.argv[1:]:
if cfgNumber == 1: if cfgNumber == 1:
misra_7_1(data.rawTokens) misra_7_1(data.rawTokens)
misra_7_3(data.rawTokens) misra_7_3(data.rawTokens)
misra_8_11(cfg)
misra_8_12(cfg) misra_8_12(cfg)
if cfgNumber == 1: if cfgNumber == 1:
misra_8_14(data.rawTokens) misra_8_14(data.rawTokens)

View File

@ -2929,6 +2929,7 @@ void SymbolDatabase::printXml(std::ostream &out) const
out << " isArgument=\"" << var->isArgument() << '\"'; out << " isArgument=\"" << var->isArgument() << '\"';
out << " isArray=\"" << var->isArray() << '\"'; out << " isArray=\"" << var->isArray() << '\"';
out << " isClass=\"" << var->isClass() << '\"'; out << " isClass=\"" << var->isClass() << '\"';
out << " isExtern=\"" << var->isExtern() << '\"';
out << " isLocal=\"" << var->isLocal() << '\"'; out << " isLocal=\"" << var->isLocal() << '\"';
out << " isPointer=\"" << var->isPointer() << '\"'; out << " isPointer=\"" << var->isPointer() << '\"';
out << " isReference=\"" << var->isReference() << '\"'; out << " isReference=\"" << var->isReference() << '\"';