Commit 74e56d13 authored by Sergio Costas's avatar Sergio Costas

Now allows to add more status values, like the debug level (which will be...

Now allows to add more status values, like the debug level (which will be useful to disable and enable the error messages
parent 82ee5ab3
......@@ -199,12 +199,12 @@ class crusty(object):
def _copy_container(self,container):
""" Fully copies a var_container to allow several parallel emulations """
retval = []
for element in container:
retval = {"debug_level": container["debug_level"], "variables": []}
for element in container["variables"]:
vargroup = {}
for varname in element:
vargroup[varname] = element[varname].copy()
retval.append(vargroup)
retval["variables"].append(vargroup)
return retval
......@@ -226,7 +226,7 @@ class crusty(object):
def _find_variable(self,var_container,var_name,line_number,searching_function = False):
for var_group in var_container:
for var_group in var_container["variables"]:
if var_name in var_group:
return var_group[var_name]
if not searching_function:
......@@ -654,13 +654,13 @@ class crusty(object):
tmpdata["status"] = crusty.STATUS_GLOBAL
tmpdata["init_line"] = node.line
tmpdata["enum"] = True
var_container[0][node.name] = tmpdata
var_container["variables"][0][node.name] = tmpdata
def process_tree(self,tree):
""" Process the main tree with the global variables and the function definitions and declarations """
var_container = [ {} ]
var_container = { "variables": [ {} ], "debug_level": 0}
# First fill all the global variables and the function declarations
for node in tree:
if (node.type == "TYPE_SPECIFIER"):
......@@ -677,7 +677,7 @@ class crusty(object):
pointers += 1
tmpparams = self._get_variable_properties(node,pointers,False)
tmpparams["status"] = crusty.STATUS_GLOBAL
var_container[0][node.name] = tmpparams
var_container["variables"][0][node.name] = tmpparams
continue
if (node.type == "FUNCTION_DECLARATION") or (node.type == "FUNCTION_DEFINITION"):
counter = 0
......@@ -700,7 +700,7 @@ class crusty(object):
tmpparams["function"] = True
tmpparams["status"] = crusty.STATUS_FUNCTION
tmpparams["function_params"] = parameters
var_container[0][node.name] = tmpparams
var_container["variables"][0][node.name] = tmpparams
continue
if node.type == "CRUSTY_DEBUG":
self._do_debug(var_container)
......@@ -712,14 +712,15 @@ class crusty(object):
for node in tree:
if node.type == "FUNCTION_DEFINITION":
tmpvars = self._copy_container(var_container)
tmpvars.insert(0,{})
tmpvars["variables"].insert(0,{})
tmpvars["debug_level"] = 0
if node.function_params is not None:
for element in node.function_params:
params = self._get_variable_properties(element,element.pointer,True)
params["status"] = crusty.STATUS_NOT_NULL_OR_NULL
params["init_line"] = element.line
params["enum"] = False
tmpvars[0][element.name] = params
tmpvars["variables"][0][element.name] = params
self._process_block(node.child1,tmpvars)
......@@ -776,13 +777,13 @@ class crusty(object):
return self._check_return_block(tree[1:],var_container)
if node.type == "START_BLOCK":
# append a new block for the variables created inside this block
var_container.insert(0,{})
var_container["variables"].insert(0,{})
return self._check_return_block(tree[1:],var_container)
if node.type == "END_BLOCK":
# check if there are blocks in use at the end of the block
self._check_blocks_in_use(var_container[0],node.line)
self._check_blocks_in_use(var_container["variables"][0],node.line)
# remove the last block of variables
var_container = var_container[1:]
var_container["variables"] = var_container["variables"][1:]
return self._check_return_block(tree[1:],var_container)
if node.type == "EMPTY_DECLARATOR":
return self._check_return_block(tree[1:],var_container)
......@@ -794,7 +795,7 @@ class crusty(object):
var_defined["status"] = crusty.STATUS_UNINITIALIZED
var_defined["init_line"] = None
var_defined["enum"] = False
var_container[0][node.name] = var_defined
var_container["variables"][0][node.name] = var_defined
if node.assignment is None:
return self._check_return_block(tree[1:],var_container)
if node.type == "FUNCTION_DECLARATION":
......@@ -803,7 +804,7 @@ class crusty(object):
tmpparams = self._get_variable_properties(None,node.pointer,False)
tmpparams["function"] = True
tmpparams["status"] = crusty.STATUS_FUNCTION
var_container[0][node.name] = tmpparams
var_container["variables"][0][node.name] = tmpparams
return self._check_return_block(tree[1:],var_container)
if (node.type == "=") or (node.type == "VARIABLE_DEFINITION"):
if node.type == "VARIABLE_DEFINITION":
......@@ -867,9 +868,9 @@ class crusty(object):
if node.child1 is not None:
self._eval_assignment(node.child1[0],var_container,False)
# check if there are blocks in use
while(len(var_container) > 1):
self._check_blocks_in_use(var_container[0],node.line)
var_container = var_container[1:]
while(len(var_container["variables"]) > 1):
self._check_blocks_in_use(var_container["variables"][0],node.line)
var_container["variables"] = var_container["variables"][1:]
return [(None,None)]
print("Tipo: {:s}; Nombre: {:s}; Linea: {:s}".format(str(node.type),str(node.name),str(node.line)))
......
......@@ -12,7 +12,7 @@ from crusty import crusty
class Test(unittest.TestCase):
def _find_variable(self,var_container,var_name):
for var_group in var_container:
for var_group in var_container["variables"]:
if var_name in var_group:
return var_group[var_name]
return None
......
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