Commit d292075c authored by Sergio Costas's avatar Sergio Costas

Better messages

Now specifies the incorrect variable or function being assigned to a crust-type variable, or vice-versa
parent ae7569cd
......@@ -299,15 +299,15 @@ class crusty(object):
def _eval_function_call(self,node,var_container,function_container):
if node.name not in function_container:
self._add_error(self.MSG_CRITICAL,"Calling function '{:s}' at line {:d}, but it is not declared or defined",node.name,node.line)
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, node.name) ]
function_data = function_container[node.name]
retval_type = self.TYPE_CRUST if ((function_data[0] & self.PROPERTY_CRUST_VARIABLE) != 0) else self.TYPE_NO_CRUST
if ((node.function_params is None) and ((len(function_data)) > 1)):
self._add_error(self.MSG_CRITICAL,"Calling function '{:s}' at line {:d} with an incorrect number of parameters",node.name,node.line)
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type, node.name) ]
if ((node.function_params is not None) and (len(function_data) - 1) != len(node.function_params)):
self._add_error(self.MSG_CRITICAL,"Calling function '{:s}' at line {:d} with an incorrect number of parameters",node.name,node.line)
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type, node.name) ]
error_found = False
newvar_container = self._copy_container(var_container)
retval = self.STATUS_NOT_NULL_OR_NULL
......@@ -350,27 +350,27 @@ class crusty(object):
if not param_is_borrowed:
self._set_var_value(newvar_container,variable.name,self.STATUS_FREED,node.line,True,True)
if error_found:
return [ (self.STATUS_NOT_NULL_OR_NULL, newvar_container, retval_type) ]
return [ (retval, newvar_container, retval_type) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, newvar_container, retval_type, node.name) ]
return [ (retval, newvar_container, retval_type, node.name) ]
def _eval_assignment(self,assignment,var_container,function_container):
if assignment is None:
return [ (crusty.STATUS_UNINITIALIZED, self._copy_container(var_container), self.TYPE_NO_MATTER) ]
return [ (crusty.STATUS_UNINITIALIZED, self._copy_container(var_container), self.TYPE_NO_MATTER, None) ]
assignment = assignment[0]
valuetype = self.TYPE_CRUST if assignment.t_crusty else self.TYPE_NO_CRUST
if assignment.type == "CONSTANT":
if (assignment.t_null) or (assignment.intval == 0):
return [ (self.STATUS_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER) ]
return [ (self.STATUS_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, None) ]
else:
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype) ]
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype, None) ]
elif assignment.type == "FCONSTANT":
if assignment.floatval == 0.0:
return [ (self.STATUS_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER) ]
return [ (self.STATUS_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, None) ]
else:
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype) ]
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype, None) ]
elif assignment.type == "STRING_LITERAL":
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype) ]
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), valuetype, None) ]
elif assignment.type == "?":
states = self._eval_condition(assignment.condition,var_container,function_container)
retvals = []
......@@ -393,18 +393,18 @@ class crusty(object):
retval_type = valuetype
if vardata["status"] == self.STATUS_UNINITIALIZED:
self._add_error(self.MSG_ERROR,"Using the value of '{:s}' at line {:d} in an assignment, but it is uninitialized",assignment.name,assignment.line)
return [ (self.STATUS_UNINITIALIZED, self._copy_container(var_container), retval_type) ]
return [ (self.STATUS_UNINITIALIZED, self._copy_container(var_container), retval_type, assignment.name) ]
elif vardata["status"] == self.STATUS_FREED:
self._add_error(self.MSG_ERROR,"Using the value of '{:s}' at line {:d} in an assignment, but it was freed at line {:d}",assignment.name,assignment.line,vardata["init_line"])
return [ (self.STATUS_FREED, self._copy_container(var_container), retval_type) ]
return [ (self.STATUS_FREED, self._copy_container(var_container), retval_type, assignment.name) ]
elif vardata["status"] == self.STATUS_GLOBAL:
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type, assignment.name) ]
newstatus = vardata["status"]
self._set_var_value(var_container,assignment.name,self.STATUS_FREED,assignment.line,True,True)
return [ (newstatus, self._copy_container(var_container), retval_type) ]
return [ (newstatus, self._copy_container(var_container), retval_type, assignment.name) ]
else:
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) ]
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), self.TYPE_NO_MATTER, assignment.name) ]
def _get_next_block(self,current_block):
......@@ -568,16 +568,28 @@ class crusty(object):
self._process_block(tree[counter+1:],newvar_container,function_container)
if (option[2] != self.TYPE_NO_MATTER) and (option[2] != this_is_crust):
if this_is_crust == self.TYPE_CRUST:
self._add_error(self.MSG_CRITICAL,"Assigning a non-crust pointer to the crust variable '{:s}' at line {:d}",varname,node.line)
if option[3] is None:
self._add_error(self.MSG_CRITICAL,"Assigning a non-crust value to the crust variable '{:s}' at line {:d}",varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}",option[3],varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}",varname,node.line)
if option[3] is None:
self._add_error(self.MSG_CRITICAL,"Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}",varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning the crust pointer '{:s}' to the non-crust variable '{:s}' at line {:d}",option[3],varname,node.line)
var_container = options[0][1]
self._set_var_value(var_container,varname,options[0][0],node.line)
if (options[0][2] != self.TYPE_NO_MATTER) and (options[0][2] != this_is_crust):
if this_is_crust == self.TYPE_CRUST:
self._add_error(self.MSG_CRITICAL,"Assigning a non-crust pointer to the crust variable '{:s}' at line {:d}",varname,node.line)
if options[0][3] is None:
self._add_error(self.MSG_CRITICAL,"Assigning a non-crust value to the crust variable '{:s}' at line {:d}",varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}",options[0][3],varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}",varname,node.line)
if options[0][3] is None:
self._add_error(self.MSG_CRITICAL,"Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}",varname,node.line)
else:
self._add_error(self.MSG_CRITICAL,"Assigning the crust pointer '{:s}' to the non-crust variable '{:s}' at line {:d}",options[0][3],varname,node.line)
continue
# if node.type == "FOR":
# print("Tipo: {:s}; Nombre: {:s}".format(str(node.type),str(node.name)))
......
......@@ -116,14 +116,17 @@ class Test(unittest.TestCase):
self._generic_test("unitest/test23.c",False,crusty.crusty.MSG_ERROR,"Using the value of '{:s}' at line {:d} in an assignment, but it is uninitialized","param4",5)
def testAssignNonCrustToCrust(self):
self._generic_test("unitest/test24.c",False,crusty.crusty.MSG_CRITICAL,"Assigning a non-crust pointer to the crust variable '{:s}' at line {:d}","param5",5)
self._generic_test("unitest/test24.c",False,crusty.crusty.MSG_CRITICAL,"Assigning the non-crust variable '{:s}' to the crust variable '{:s}' at line {:d}","param4","param5",5)
def testAssignCrustToNonCrust(self):
self._generic_test("unitest/test25.c",False,crusty.crusty.MSG_CRITICAL,"Assigning a crust pointer to the non-crust variable '{:s}' at line {:d}","param5",5)
self._generic_test("unitest/test25.c",False,crusty.crusty.MSG_CRITICAL,"Assigning the crust pointer '{:s}' to the non-crust variable '{:s}' at line {:d}","param4","param5",5)
def testTypeCast(self):
self._all_fine_test("unitest/test26.c")
def testAssignNonCrustToCrust2(self):
self._generic_test("unitest/test27.c",True,crusty.crusty.MSG_CRITICAL,"Assigning a non-crust value to the crust variable '{:s}' at line {:d}","param",5)
if __name__ == '__main__':
unittest.main()
# 1 "test11.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "test11.c"
typedef __crust_t__ unsigned char crust_t;
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param3) {
crust_t *param = 5;
}
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