misra; update essential type for variables
This commit is contained in:
parent
657d530fa1
commit
d467505696
|
@ -458,12 +458,15 @@ def getEssentialCategorylist(operand1, operand2):
|
||||||
def getEssentialType(expr):
|
def getEssentialType(expr):
|
||||||
if not expr:
|
if not expr:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if expr.variable:
|
if expr.variable:
|
||||||
typeToken = expr.variable.typeStartToken
|
if expr.valueType:
|
||||||
while typeToken and typeToken.isName:
|
if expr.valueType.type == 'bool':
|
||||||
if typeToken.str in INT_TYPES + STDINT_TYPES + ['float', 'double']:
|
return 'Boolean'
|
||||||
return typeToken.str
|
if expr.valueType.isFloat():
|
||||||
typeToken = typeToken.next
|
return expr.valueType.type
|
||||||
|
if expr.valueType.isIntegral():
|
||||||
|
return '%s %s' % (expr.valueType.sign, expr.valueType.type)
|
||||||
|
|
||||||
elif expr.astOperand1 and expr.astOperand2 and expr.str in (
|
elif expr.astOperand1 and expr.astOperand2 and expr.str in (
|
||||||
'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":"):
|
'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":"):
|
||||||
|
@ -489,6 +492,7 @@ def getEssentialType(expr):
|
||||||
def bitsOfEssentialType(ty):
|
def bitsOfEssentialType(ty):
|
||||||
if ty is None:
|
if ty is None:
|
||||||
return 0
|
return 0
|
||||||
|
ty = ty.split(' ')[-1]
|
||||||
if ty == 'char':
|
if ty == 'char':
|
||||||
return typeBits['CHAR']
|
return typeBits['CHAR']
|
||||||
if ty == 'short':
|
if ty == 'short':
|
||||||
|
@ -1953,8 +1957,8 @@ class MisraChecker:
|
||||||
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
|
elif not isUnsignedType(e2) and not token.astOperand2.isNumber:
|
||||||
self.reportError(token, 10, 1)
|
self.reportError(token, 10, 1)
|
||||||
elif token.str in ('~', '&', '|', '^'):
|
elif token.str in ('~', '&', '|', '^'):
|
||||||
e1_et = getEssentialType(token.astOperand1)
|
e1_et = getEssentialType(token.astOperand1).split(' ')[-1]
|
||||||
e2_et = getEssentialType(token.astOperand2)
|
e2_et = getEssentialType(token.astOperand2).split(' ')[-1]
|
||||||
if e1_et == 'char' and e2_et == 'char':
|
if e1_et == 'char' and e2_et == 'char':
|
||||||
self.reportError(token, 10, 1)
|
self.reportError(token, 10, 1)
|
||||||
|
|
||||||
|
@ -1967,7 +1971,7 @@ class MisraChecker:
|
||||||
|
|
||||||
def isEssentiallyChar(op):
|
def isEssentiallyChar(op):
|
||||||
if op.isName:
|
if op.isName:
|
||||||
return getEssentialType(op) == 'char'
|
return getEssentialType(op).split(' ')[-1] == 'char'
|
||||||
return op.isChar
|
return op.isChar
|
||||||
|
|
||||||
for token in data.tokenlist:
|
for token in data.tokenlist:
|
||||||
|
|
|
@ -590,7 +590,7 @@ static void misra_9_5(void) {
|
||||||
|
|
||||||
typedef char misra_10_1_char_t;
|
typedef char misra_10_1_char_t;
|
||||||
#define MISRA_10_1_CHAR char
|
#define MISRA_10_1_CHAR char
|
||||||
static void misra_10_1(uint8_t u, char c1, char c2) {
|
static void misra_10_1(uint32_t u, char c1, char c2) {
|
||||||
int32_t i;
|
int32_t i;
|
||||||
char c;
|
char c;
|
||||||
enum { E1 = 1 };
|
enum { E1 = 1 };
|
||||||
|
|
Loading…
Reference in New Issue