misra.py: add rule 10.1, partial checking
This commit is contained in:
parent
ea5417b8af
commit
9f47d04af6
|
@ -113,7 +113,7 @@ KEYWORDS = {
|
|||
def getEssentialTypeCategory(expr):
|
||||
if not expr:
|
||||
return None
|
||||
if expr.valueType.typeScope:
|
||||
if expr.valueType and expr.valueType.typeScope:
|
||||
return "enum<" + expr.valueType.typeScope.className + ">"
|
||||
if expr.variable:
|
||||
typeToken = expr.variable.typeStartToken
|
||||
|
@ -128,6 +128,7 @@ def getEssentialTypeCategory(expr):
|
|||
typeToken = typeToken.next
|
||||
if expr.valueType:
|
||||
return expr.valueType.sign
|
||||
return None
|
||||
|
||||
|
||||
def getEssentialCategorylist(operand1, operand2):
|
||||
|
@ -692,6 +693,20 @@ def misra_9_5(rawTokens):
|
|||
reportError(token, 9, 5)
|
||||
|
||||
|
||||
def misra_10_1(data):
|
||||
for token in data.tokenlist:
|
||||
if not token.isOp:
|
||||
continue
|
||||
e1 = getEssentialTypeCategory(token.astOperand1)
|
||||
e2 = getEssentialTypeCategory(token.astOperand2)
|
||||
if not e1 or not e2:
|
||||
continue
|
||||
if token.str in ['<<', '>>']:
|
||||
if e1 != 'unsigned':
|
||||
reportError(token, 10, 1)
|
||||
elif e2 != 'unsigned' and not token.astOperand2.isNumber:
|
||||
reportError(token, 10, 1)
|
||||
|
||||
def misra_10_4(data):
|
||||
op = {'+', '-', '*', '/', '%', '&', '|', '^', '+=', '-=', '?', ':'}
|
||||
for token in data.tokenlist:
|
||||
|
@ -1668,6 +1683,7 @@ for arg in sys.argv[1:]:
|
|||
if cfgNumber == 1:
|
||||
misra_8_14(data.rawTokens)
|
||||
misra_9_5(data.rawTokens)
|
||||
misra_10_1(cfg)
|
||||
misra_10_4(cfg)
|
||||
misra_10_6(cfg)
|
||||
misra_10_8(cfg)
|
||||
|
|
|
@ -146,6 +146,11 @@ void misra_9_5() {
|
|||
int x[] = {[0]=23}; // 9.5
|
||||
}
|
||||
|
||||
void misra_10_1() {
|
||||
int32_t i;
|
||||
i = 3 << 1; // 10.1
|
||||
}
|
||||
|
||||
void misra_10_4(u32 x, s32 y) {
|
||||
z = x + 3; // 10.4
|
||||
enum misra_10_4_enuma { misra_10_4_A1, misra_10_4_A2, misra_10_4_A3 };
|
||||
|
|
Loading…
Reference in New Issue