Commit 68d32111 authored by Sergio Costas's avatar Sergio Costas

Now detects when a function hasn't been defined

parent e2a91641
......@@ -13,4 +13,6 @@ try:
lib.process_functions(tree,variables,functions)
except crusty.crusty.VarNotFoundException:
pass
except crusty.crusty.FunctionNotFoundException:
pass
lib.print_errors()
......@@ -45,6 +45,9 @@ class crusty(object):
class VarNotFoundException(Exception):
pass
class FunctionNotFoundException(Exception):
pass
class AST_leaf(Structure):
pass
......@@ -219,6 +222,14 @@ class crusty(object):
raise self.VarNotFoundException()
def _find_function(self,function_container,function_name,line_number):
if function_name in function_container:
return function_container[function_name]
self._add_error(self.MSG_CRITICAL,"Unknown function '{:s}' at line {:d}",str(function_name),line_number)
raise self.FunctionNotFoundException()
def _set_var_value(self,var_container,var_name,value,line_number,force = False, force_init_line = False):
variable = self._find_variable(var_container, var_name, line_number)
if variable["status"] == self.STATUS_GLOBAL:
......@@ -305,7 +316,7 @@ class crusty(object):
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, node.name) ]
function_data = function_container[node.name]
function_data = self._find_function(function_container,node.name,node.line)
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)
......@@ -598,7 +609,8 @@ class crusty(object):
self._set_var_value(var_container,varname,options[0][0],node.line)
continue
if node.type == "FUNCTION_CALL":
if (function_container[node.name][0] & self.PROPERTY_CRUST_VARIABLE) != 0:
function_params = self._find_function(function_container,node.name,node.line)
if (function_params[0] & self.PROPERTY_CRUST_VARIABLE) != 0:
self._add_error(self.MSG_ERROR,"Calling the function '{:s}' at line {:d}, but ignoring the crust-type return value",node.name,node.line)
options = self._eval_function_call(node,var_container,function_container)
if len(options) > 1:
......
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