Commit fb7bcc2c authored by Sergio Costas's avatar Sergio Costas

Now doesn't fail in more cases with functions without parameters

Added more tests
parent 1900c7c1
......@@ -286,55 +286,60 @@ class crusty(object):
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)) ]
function_data = function_container[node.name]
if (len(function_data) - 1) != len(node.function_params):
if ((node.function_params is None) and ((len(function_data)) > 1)):
#added
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)) ]
if ((node.function_params is not None) and (len(function_data) - 1) != len(node.function_params)):
#added
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)) ]
error_found = False
newvar_container = self._copy_container(var_container)
retval = self.STATUS_NOT_NULL_OR_NULL
for pos in range(len(node.function_params)):
variable = node.function_params[pos]
if variable.type != "IDENTIFIER":
if ((function_data[pos+1] & self.PROPERTY_CRUST_VARIABLE) != 0) and (not variable.t_null):
if node.function_params is not None:
for pos in range(len(node.function_params)):
variable = node.function_params[pos]
if variable.type != "IDENTIFIER":
if ((function_data[pos+1] & self.PROPERTY_CRUST_VARIABLE) != 0) and (not variable.t_null):
#added
self._add_error(self.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}",pos+1,node.name,node.line)
error_found = True
continue
node_var = self._find_variable(newvar_container,variable.name,node.line)
var_is_crusty = self._check_variable_properties(node_var,self.PROPERTY_CRUST_VARIABLE)
param_is_crusty = (function_data[pos+1] & self.PROPERTY_CRUST_VARIABLE) != 0
param_is_borrowed = (function_data[pos+1] & self.PROPERTY_BORROWED) != 0
param_is_recycled = (function_data[pos+1] & self.PROPERTY_RECYCLED) != 0
if (not var_is_crusty) and param_is_crusty:
#added
self._add_error(self.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}",pos+1,node.name,node.line)
self._add_error(self.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable",pos+1,node.name,node.line)
error_found = True
continue
node_var = self._find_variable(newvar_container,variable.name,node.line)
var_is_crusty = self._check_variable_properties(node_var,self.PROPERTY_CRUST_VARIABLE)
param_is_crusty = (function_data[pos+1] & self.PROPERTY_CRUST_VARIABLE) != 0
param_is_borrowed = (function_data[pos+1] & self.PROPERTY_BORROWED) != 0
param_is_recycled = (function_data[pos+1] & self.PROPERTY_RECYCLED) != 0
if (not var_is_crusty) and param_is_crusty:
#added
self._add_error(self.MSG_CRITICAL,"Expected a __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed non __crust_t__ variable",pos+1,node.name,node.line)
error_found = True
continue
if var_is_crusty and (not param_is_crusty):
#added
self._add_error(self.MSG_CRITICAL,"Expected a non __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable",pos+1,node.name,node.line)
error_found = True
continue
if not param_is_crusty:
continue
if node_var["status"] == self.STATUS_UNINITIALIZED:
#added
self._add_error(self.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} isn't initialized",pos+1,node.name,node.line)
error_found = True
continue
if node_var["status"] == self.STATUS_FREED:
#added
self._add_error(self.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}",pos+1,node.name,node.line,node_var["init_line"])
error_found = True
continue
if param_is_recycled:
if node_var["status"] == self.STATUS_NULL:
retval = self.STATUS_NOT_NULL_OR_NULL
else:
retval = node_var["status"]
if not param_is_borrowed:
self._set_var_value(newvar_container,variable.name,self.STATUS_FREED,node.line,True,True)
continue
if var_is_crusty and (not param_is_crusty):
#added
self._add_error(self.MSG_CRITICAL,"Expected a non __crust_t__ variable at parameter {:d} when calling function '{:s}' at line {:d}, but passed a __crust_t__ variable",pos+1,node.name,node.line)
error_found = True
continue
if not param_is_crusty:
continue
if node_var["status"] == self.STATUS_UNINITIALIZED:
#added
self._add_error(self.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} isn't initialized",pos+1,node.name,node.line)
error_found = True
continue
if node_var["status"] == self.STATUS_FREED:
#added
self._add_error(self.MSG_ERROR,"Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}",pos+1,node.name,node.line,node_var["init_line"])
error_found = True
continue
if param_is_recycled:
if node_var["status"] == self.STATUS_NULL:
retval = self.STATUS_NOT_NULL_OR_NULL
else:
retval = node_var["status"]
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) ]
return [ (retval, newvar_container) ]
......@@ -408,6 +413,7 @@ class crusty(object):
#added
self._add_error(self.MSG_CRITICAL,"A parameter is defined as __crust_t__ type at line {:d}, but it is not a pointer",node.line)
else:
#added
self._add_error(self.MSG_CRITICAL,"Parameter '{:s}' defined as __crust_t__ type at line {:d}, but it is not a pointer",node.name,node.line)
else:
if is_retval:
......
......@@ -79,5 +79,8 @@ class Test(unittest.TestCase):
def testCrustNamedParameterNotPointer(self):
self._generic_test("unitest/test12.c",False,crusty.crusty.MSG_CRITICAL,"Parameter '{:s}' defined as __crust_t__ type at line {:d}, but it is not a pointer","parameter",1)
def testCrustRetvalNotPointer(self):
self._generic_test("unitest/test13.c",False,crusty.crusty.MSG_CRITICAL,"Variable '{:s}' is defined as __crust_t__ type at line {:d}, but it is not a pointer","retval",5)
if __name__ == '__main__':
unittest.main()
typedef __crust_t__ unsigned char crust_t;
int function() {
crust_t retval = function();
}
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