Commit 5654f93c authored by Sergio Costas's avatar Sergio Costas

Added extra tests

Now accepts fine when assigning a crust element into an struct node
parent e063ba8d
......@@ -25,22 +25,24 @@ class crusty(object):
# the variable is a pointer to a function defined in this source file
STATUS_FUNCTION = 6
CONDITION_FALSE = 0
CONDITION_TRUE = 1
CONDITION_FALSE = 0
CONDITION_TRUE = 1
CONDITION_FALSE_TRUE = 2
PROPERTY_CRUST_VARIABLE = 1
PROPERTY_BORROWED = 2
PROPERTY_RECYCLED = 4
MSG_NORMAL = 0
MSG_WARNING = 1
MSG_ERROR = 2
PROPERTY_BORROWED = 2
PROPERTY_RECYCLED = 4
PROPERTY_ARRAY = 8
PROPERTY_STRUCT = 16
MSG_NORMAL = 0
MSG_WARNING = 1
MSG_ERROR = 2
MSG_CRITICAL = 3
TYPE_NO_MATTER = 0
TYPE_NO_CRUST = 1
TYPE_CRUST = 2
TYPE_NO_CRUST = 1
TYPE_CRUST = 2
class VarNotFoundException(Exception):
pass
......@@ -407,7 +409,7 @@ class crusty(object):
retval_type = self.TYPE_CRUST if (((vardata["properties"] & self.PROPERTY_CRUST_VARIABLE) != 0) and (vardata["pointer"] == 1)) else self.TYPE_NO_CRUST
else:
retval_type = valuetype
if assignment.right is not None:
if (assignment.arrays is not None) or (assignment.right is not None):
# for structs and arrays
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, assignment.name) ]
if vardata["status"] == self.STATUS_UNINITIALIZED:
......@@ -487,6 +489,10 @@ class crusty(object):
retval += crusty.PROPERTY_BORROWED
if node.t_crusty_recycle:
retval += crusty.PROPERTY_RECYCLED
if (node.arrays is not None):
retval += crusty.PROPERTY_ARRAY
if (node.t_struct):
retval += crusty.PROPERTY_STRUCT
return retval
......@@ -556,17 +562,19 @@ class crusty(object):
def _check_assignment(self,var_defined,options,varname,node,tree,counter,function_container):
this_is_crust = self.TYPE_CRUST if ((var_defined["properties"] & self.PROPERTY_CRUST_VARIABLE) != 0) else self.TYPE_NO_CRUST
this_is_crust = self.TYPE_CRUST if self._check_variable_properties(var_defined, self.PROPERTY_CRUST_VARIABLE) else self.TYPE_NO_CRUST
if self._check_variable_properties(var_defined,self.PROPERTY_ARRAY) or self._check_variable_properties(var_defined,self.PROPERTY_STRUCT):
this_is_crust = self.TYPE_NO_MATTER
error_list = []
if len(options) > 1:
for option in options[1:]:
# create a new "execution thread" for each possible assignment value
if (option[2] != self.TYPE_NO_MATTER) and (option[2] != this_is_crust):
if (option[2] != self.TYPE_NO_MATTER) and (this_is_crust != self.TYPE_NO_MATTER) and (option[2] != this_is_crust):
error_list.append( (this_is_crust,option[3],varname,node.line) )
newvar_container = option[1]
self._set_var_value(newvar_container,varname,option[0],node.line)
self._process_block(tree[counter+1:],newvar_container,function_container)
if (options[0][2] != self.TYPE_NO_MATTER) and (options[0][2] != this_is_crust):
if (options[0][2] != self.TYPE_NO_MATTER) and (this_is_crust != self.TYPE_NO_MATTER) and (options[0][2] != this_is_crust):
error_list.append( (this_is_crust,options[0][3],varname,node.line) )
for error_element in error_list:
if error_element[0] == self.TYPE_CRUST:
......
......@@ -163,5 +163,12 @@ class Test(unittest.TestCase):
def testArrayAssign(self):
self._generic_test("unitest/test39.c",False,[ (crusty.crusty.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}","test","param4",6) ])
def testStructAssignment(self):
self._all_fine_test("unitest/test40.c")
def testUsePostStructAssignment(self):
self._generic_test("unitest/test41.c",False,[ (crusty.crusty.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}",1,"function",9,8) ])
if __name__ == '__main__':
unittest.main()
typedef __crust_t__ unsigned char *crust_t;
struct {
crust_t value;
} test;
int function(crust_t param3) {
test.value = param3; // this is legal
}
typedef __crust_t__ unsigned char *crust_t;
struct {
crust_t value;
} test;
int function(crust_t param3) {
test.value = param3; // this is legal
function(param3); // ERROR: param3 was freed at line 8
}
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