Commit 82ee5ab3 authored by Sergio Costas's avatar Sergio Costas

Merge branch 'functions_to_vars'

parents 755093b0 9689bc44
......@@ -92,7 +92,6 @@ class crusty(object):
self.errors = []
self.debug = []
self._function_container = {}
with open(headerpath,"r") as header:
do_process = False
......@@ -226,17 +225,21 @@ class crusty(object):
self.errors.append( group )
def _find_variable(self,var_container,var_name,line_number):
def _find_variable(self,var_container,var_name,line_number,searching_function = False):
for var_group in var_container:
if var_name in var_group:
return var_group[var_name]
self._add_error(self.MSG_CRITICAL,"Unknown variable '{:s}' at line {:d}",str(var_name),line_number)
if not searching_function:
self._add_error(self.MSG_CRITICAL,"Unknown variable '{:s}' at line {:d}",str(var_name),line_number)
raise self.VarNotFoundException()
def _find_function(self,function_name,line_number):
if function_name in self._function_container:
return self._function_container[function_name]
def _find_function(self,var_container,function_name,line_number):
try:
function_name = self._find_variable(var_container,function_name,line_number,True)
return function_name["function_params"]
except:
pass
self._add_error(self.MSG_CRITICAL,"Calling function '{:s}' at line {:d}, but it is not declared or defined",function_name,line_number)
raise self.FunctionNotFoundException()
......@@ -329,7 +332,7 @@ class crusty(object):
return retvals
if assignment.type == "FUNCTION_CALL":
function_data = self._find_function(assignment.name,assignment.line)
function_data = self._find_function(var_container,assignment.name,assignment.line)
if function_data[0]["crust"] and (function_data[0]["pointer"] == 1):
retval_type = self.TYPE_CRUST
else:
......@@ -604,7 +607,7 @@ class crusty(object):
def _get_variable_properties(self,node, pointers, is_parameter, is_retval = False):
retval = {"crust": False, "borrowed": False, "recycle": False, "enum": False, "status": self.STATUS_UNINITIALIZED, "pointer": pointers, "struct": False, "array": False, "function": False, "function_params": None}
retval = {"crust": False, "borrowed": False, "recycle": False, "enum": False, "status": self.STATUS_UNINITIALIZED, "pointer": pointers, "struct": False, "array": False, "function": False, "function_pointer": False, "function_params": None}
if not isinstance(node,self.AST_node):
return retval
retval["function_params"] = node.function_params
......@@ -658,7 +661,6 @@ class crusty(object):
""" Process the main tree with the global variables and the function definitions and declarations """
var_container = [ {} ]
self._function_container = {}
# First fill all the global variables and the function declarations
for node in tree:
if (node.type == "TYPE_SPECIFIER"):
......@@ -693,11 +695,11 @@ class crusty(object):
if node.function_params is not None:
for parameter in node.function_params:
parameters.append( self._get_variable_properties(parameter,parameter.pointer,True) )
self._function_container[node.name] = parameters
# also add functions as variables to allow to assign them to function pointers
tmpparams = self._get_variable_properties(None,node.pointer,False)
tmpparams["function"] = True
tmpparams["status"] = crusty.STATUS_FUNCTION
tmpparams["function_params"] = parameters
var_container[0][node.name] = tmpparams
continue
if node.type == "CRUSTY_DEBUG":
......@@ -816,7 +818,7 @@ class crusty(object):
retvals += self._check_return_block(tree[1:],option[1])
return retvals
if node.type == "FUNCTION_CALL":
function_params = self._find_function(node.name,node.line)
function_params = self._find_function(var_container,node.name,node.line)
if function_params[0]["crust"] and (function_params[0]["pointer"] == 1):
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_assignment(node,var_container,False)
......
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