Commit 17bd7cf7 authored by Sergio Costas's avatar Sergio Costas

Added support for NOT in evaluations

parent 08508d66
......@@ -150,13 +150,15 @@ class crusty(object):
retval = self.libcrusty.parse_data(c_bool(verbose),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
if retval:
tree = self._fix_tree(retval)
self.libcrusty.free_all()
retval = None
else:
# If there is an error, run again the parsing with VERBOSE = True to show the error to the user
#self.libcrusty.parse_data(c_bool(True),c_char_p(filename.encode("utf8")),rv.stdout,datasize)
sys.exit(-1)
return tree
def free_all(self):
self.libcrusty.free_all()
def _fix_tree(self,node):
""" Creates a list with each statement in order, ready to be "executed" """
......@@ -493,16 +495,16 @@ class crusty(object):
retvals += [ (self.STATUS_NOT_NULL, op2[1], self.TYPE_NO_CRUST,None, crusty.CONDITION_TRUE), (self.STATUS_NULL, op2[1], self.TYPE_NO_CRUST,None, crusty.CONDITION_FALSE) ]
return retvals
if (assignment.type == "GE_OP") or (assignment.type == "LE_OP") or (assignment.type == "<") or (assignment.type == ">") or (assignment.type == "|"):
retvals = []
op1list = self._eval_assignment(assignment.child1[0],var_container,True)
for op1 in op1list:
op2list = self._eval_assignment(assignment.child2[0],op1[1],True)
for op2 in op2list:
retvals += [(self.STATUS_NOT_NULL_OR_NULL, op2[1], self.TYPE_NO_CRUST,None, crusty.CONDITION_FALSE_TRUE) ]
return retvals
if (assignment.type == "+") or (assignment.type == "-") or (assignment.type == "&") or (assignment.type == "MUL_ASSIGN"):
if ((assignment.type == "GE_OP") or
(assignment.type == "LE_OP") or
(assignment.type == "<") or
(assignment.type == ">") or
(assignment.type == "|") or
(assignment.type == "+") or
(assignment.type == "-") or
(assignment.type == "&") or
(assignment.type == "MUL_ASSIGN") or
(assignment.type == "LEFT_OP")):
child1 = assignment.child1
child2 = assignment.child2
if child1 is None:
......@@ -517,6 +519,23 @@ class crusty(object):
retvals += [(self.STATUS_NOT_NULL_OR_NULL, op2[1], self.TYPE_NO_CRUST,None, crusty.CONDITION_FALSE_TRUE) ]
return retvals
if assignment.type == "!":
oplist = self._eval_assignment(assignment.child1[0],var_container,True)
retval = []
for op in oplist:
status = op[0]
condition = op[4]
if status == self.STATUS_NULL:
status = self.STATUS_NOT_NULL
elif status == self.STATUS_NOT_NULL:
status = self.STATUS_NULL
if condition == self.CONDITION_FALSE:
condition = self.CONDITION_TRUE
elif condition == self.CONDITION_TRUE:
condition = self.CONDITION_FALSE
retval += [ (status, op[1], op[2], op[3], condition) ]
return retval
print("assignment type unknown '{:s}' at line {:d}".format(assignment.type,assignment.line))
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, assignment.name, self.CONDITION_FALSE_TRUE) ]
......
......@@ -694,11 +694,9 @@ labeled_statement
| CASE constant_expression ':' statement { $$ = $1;
$$->condition = $2;
append_next($$,$4);
append_next_leaf($$,END_CASE);
free_tree($3); }
| DEFAULT ':' statement { $$ = $1;
append_next($$,$3);
append_next_leaf($$,END_DEFAULT);
free_tree($2); }
;
......
......@@ -249,5 +249,11 @@ class Test(unittest.TestCase):
def testNestedComparisonWithBraces(self):
self._all_fine_test("unitest/test59.c")
def testIfWithNot(self):
self._all_fine_test("unitest/test60.c")
def testIfWithNot2(self):
self._generic_test("unitest/test61.c",[ (crusty.crusty.MSG_ERROR,"Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}","param",9,5) ])
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment