Modified rule 10.6 (#1263)

* Modified rule 10.6

* Improved rule 10.6
This commit is contained in:
Swasti Shrivastava 2018-05-25 01:58:36 +05:30 committed by Daniel Marjamäki
parent 9bf604c46c
commit 742d6513a1
2 changed files with 18 additions and 4 deletions

View File

@ -170,7 +170,11 @@ def getEssentialType(expr):
return typeToken.str return typeToken.str
typeToken = typeToken.next typeToken = typeToken.next
elif expr.astOperand1 and expr.astOperand2 and expr.str in {'+', '-', '*', '/', '%', '&', '|', '^'}: elif expr.astOperand1 and expr.astOperand2 and expr.str in {'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":"}:
if expr.astOperand1.valueType and expr.astOperand1.valueType.pointer > 0:
return None
if expr.astOperand2.valueType and expr.astOperand2.valueType.pointer > 0:
return None
e1 = getEssentialType(expr.astOperand1) e1 = getEssentialType(expr.astOperand1)
e2 = getEssentialType(expr.astOperand2) e2 = getEssentialType(expr.astOperand2)
if not e1 or not e2: if not e1 or not e2:
@ -184,6 +188,9 @@ def getEssentialType(expr):
return types[i1] return types[i1]
except ValueError: except ValueError:
return None return None
elif expr.str == "~":
e1 = getEssentialType(expr.astOperand1)
return e1
return None return None
@ -767,6 +774,9 @@ def misra_10_6(data):
for token in data.tokenlist: for token in data.tokenlist:
if token.str != '=' or not token.astOperand1 or not token.astOperand2: if token.str != '=' or not token.astOperand1 or not token.astOperand2:
continue continue
if (token.astOperand2.str not in {'+', '-', '*', '/', '%', '&', '|', '^', '>>', "<<", "?", ":", '~'} and
not isCast(token.astOperand2)):
continue
vt1 = token.astOperand1.valueType vt1 = token.astOperand1.valueType
vt2 = token.astOperand2.valueType vt2 = token.astOperand2.valueType
if not vt1 or vt1.pointer > 0: if not vt1 or vt1.pointer > 0:
@ -776,6 +786,9 @@ def misra_10_6(data):
try: try:
intTypes = ['char', 'short', 'int', 'long', 'long long'] intTypes = ['char', 'short', 'int', 'long', 'long long']
index1 = intTypes.index(vt1.type) index1 = intTypes.index(vt1.type)
if isCast(token.astOperand2):
e = vt2.type
else:
e = getEssentialType(token.astOperand2) e = getEssentialType(token.astOperand2)
if not e: if not e:
continue continue
@ -785,7 +798,6 @@ def misra_10_6(data):
except ValueError: except ValueError:
pass pass
def misra_10_8(data): def misra_10_8(data):
for token in data.tokenlist: for token in data.tokenlist:
if not isCast(token): if not isCast(token):

View File

@ -162,8 +162,10 @@ void misra_10_4(u32 x, s32 y) {
z = x + y; //10.4 z = x + y; //10.4
} }
void misra_10_6(u8 x) { void misra_10_6(u8 x, u32 a, u32 b) {
u16 y = x+x; // 10.6 u16 y = x+x; // 10.6
u16 z = ~u8 x ;//10.6
u32 c = ( u16) ( u32 a + u32 b ); //10.6
} }
void misra_10_8(u8 x) { void misra_10_8(u8 x) {