misra; improved essential type for composite expressions
This commit is contained in:
parent
41c94b656a
commit
4428efbd2b
|
@ -485,7 +485,7 @@ def getEssentialType(expr):
|
||||||
return 'char'
|
return 'char'
|
||||||
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
|
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
|
||||||
|
|
||||||
if expr.variable:
|
if expr.variable or isCast(expr):
|
||||||
if expr.valueType:
|
if expr.valueType:
|
||||||
if expr.valueType.type == 'bool':
|
if expr.valueType.type == 'bool':
|
||||||
return 'Boolean'
|
return 'Boolean'
|
||||||
|
@ -519,6 +519,13 @@ def getEssentialType(expr):
|
||||||
e2 = getEssentialType(expr.astOperand2)
|
e2 = getEssentialType(expr.astOperand2)
|
||||||
if not e1 or not e2:
|
if not e1 or not e2:
|
||||||
return None
|
return None
|
||||||
|
if is_constant_integer_expression(expr):
|
||||||
|
sign1 = e1.split(' ')[0]
|
||||||
|
sign2 = e1.split(' ')[0]
|
||||||
|
if sign1 == sign2 and sign1 in ('signed', 'unsigned'):
|
||||||
|
e = get_essential_type_from_value(expr.getKnownIntValue(), sign1 == 'signed')
|
||||||
|
if e:
|
||||||
|
return e
|
||||||
if bitsOfEssentialType(e2) >= bitsOfEssentialType(e1):
|
if bitsOfEssentialType(e2) >= bitsOfEssentialType(e1):
|
||||||
return e2
|
return e2
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -663,7 +663,10 @@ static void misra_10_2(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void misra_10_3(uint32_t u32a, uint32_t u32b) {
|
static void misra_10_3(uint32_t u32a, uint32_t u32b) {
|
||||||
uint8_t res = u32a + u32b; // 10.3
|
uint8_t res;
|
||||||
|
res = u32a + u32b; // 10.3
|
||||||
|
res = (uint16_t)(2U + 3U); // 10.3 10.8
|
||||||
|
res = (uint16_t)2U + (uint16_t)3U;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void misra_10_4(u32 x, s32 y) {
|
static void misra_10_4(u32 x, s32 y) {
|
||||||
|
|
Loading…
Reference in New Issue