Commit f021f2dd authored by Sergio Costas's avatar Sergio Costas

Now doesn't fail when using function pointers

parent 2675d6e7
...@@ -22,7 +22,7 @@ class crusty(object): ...@@ -22,7 +22,7 @@ class crusty(object):
STATUS_FREED = 4 STATUS_FREED = 4
# the variable is global, so it is presumed that, when used, it is INITIALIZED_OR_NULL, and when assigned is FREED # the variable is global, so it is presumed that, when used, it is INITIALIZED_OR_NULL, and when assigned is FREED
STATUS_GLOBAL = 5 STATUS_GLOBAL = 5
# the variable is a pointer to a function defined in this source file # the variable is a function
STATUS_FUNCTION = 6 STATUS_FUNCTION = 6
CONDITION_FALSE = 0 CONDITION_FALSE = 0
...@@ -234,7 +234,7 @@ class crusty(object): ...@@ -234,7 +234,7 @@ class crusty(object):
variable = self._find_variable(var_container, var_name, line_number) variable = self._find_variable(var_container, var_name, line_number)
if variable["status"] == self.STATUS_GLOBAL: if variable["status"] == self.STATUS_GLOBAL:
return return
if variable["status"] == self.STATUS_FUNCTION: if variable["function"]:
self._add_error(self.MSG_CRITICAL,"Trying to assign a value to the function name '{:s}' at line {:d}",str(var_name),line_number) self._add_error(self.MSG_CRITICAL,"Trying to assign a value to the function name '{:s}' at line {:d}",str(var_name),line_number)
return return
if (not force) and variable["crust"]: if (not force) and variable["crust"]:
...@@ -267,7 +267,6 @@ class crusty(object): ...@@ -267,7 +267,6 @@ class crusty(object):
var_container = self._copy_container(var_container) var_container = self._copy_container(var_container)
condition = condition[0] condition = condition[0]
#print("Condicion: {:s}".format(condition.type))
if (condition.type == "CONSTANT"): if (condition.type == "CONSTANT"):
if condition.intval == 0: if condition.intval == 0:
return [ (crusty.CONDITION_FALSE, var_container) ] return [ (crusty.CONDITION_FALSE, var_container) ]
...@@ -312,6 +311,7 @@ class crusty(object): ...@@ -312,6 +311,7 @@ class crusty(object):
self._set_var_value(var1,op1.name,crusty.STATUS_NULL,0,True) self._set_var_value(var1,op1.name,crusty.STATUS_NULL,0,True)
self._set_var_value(var2,op1.name,crusty.STATUS_NOT_NULL,0,True) self._set_var_value(var2,op1.name,crusty.STATUS_NOT_NULL,0,True)
return [ (crusty.CONDITION_FALSE, var1), (crusty.CONDITION_TRUE, var2) ] return [ (crusty.CONDITION_FALSE, var1), (crusty.CONDITION_TRUE, var2) ]
print("Unknown condition: {:s} at line {:d}".format(condition.type,condition.line))
return [ (crusty.CONDITION_FALSE_TRUE, var_container) ] return [ (crusty.CONDITION_FALSE_TRUE, var_container) ]
...@@ -441,6 +441,8 @@ class crusty(object): ...@@ -441,6 +441,8 @@ class crusty(object):
return [ (self.STATUS_FREED, self._copy_container(var_container), retval_type, assignment.name) ] return [ (self.STATUS_FREED, self._copy_container(var_container), retval_type, assignment.name) ]
elif vardata["status"] == self.STATUS_GLOBAL: elif vardata["status"] == self.STATUS_GLOBAL:
return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type, assignment.name) ] return [ (self.STATUS_NOT_NULL_OR_NULL, self._copy_container(var_container), retval_type, assignment.name) ]
elif vardata["status"] == self.STATUS_FUNCTION:
return [ (self.STATUS_NOT_NULL, self._copy_container(var_container), retval_type, assignment.name) ]
newstatus = vardata["status"] newstatus = vardata["status"]
self._set_var_value(var_container,assignment.name,self.STATUS_FREED,assignment.line,True,True) self._set_var_value(var_container,assignment.name,self.STATUS_FREED,assignment.line,True,True)
return [ (newstatus, self._copy_container(var_container), retval_type, assignment.name) ] return [ (newstatus, self._copy_container(var_container), retval_type, assignment.name) ]
...@@ -495,7 +497,7 @@ class crusty(object): ...@@ -495,7 +497,7 @@ class crusty(object):
def _get_variable_properties(self,node, pointers, is_parameter, is_retval = False): 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} retval = {"crust": False, "borrowed": False, "recycle": False, "enum": False, "status": self.STATUS_UNINITIALIZED, "pointer": pointers, "struct": False, "array": False, "function": False}
if not isinstance(node,self.AST_node): if not isinstance(node,self.AST_node):
return retval return retval
if node.t_crusty: if node.t_crusty:
...@@ -534,7 +536,11 @@ class crusty(object): ...@@ -534,7 +536,11 @@ class crusty(object):
def _process_enum(self,enum_node,var_container): def _process_enum(self,enum_node,var_container):
counter = 0 counter = 0
for node in enum_node.enum_data: for node in enum_node.enum_data:
var_container[0][node.name] = {"properties": 0, "status":crusty.STATUS_GLOBAL, "init_line": node.line, "pointer": 0, "enum": True } tmpdata = self._get_variable_properties(None,0,False)
tmpdata["status"] = crusty.STATUS_GLOBAL
tmpdata["init_line"] = node.line
tmpdata["enum"] = True
var_container[0][node.name] = tmpdata
def process_tree(self,tree): def process_tree(self,tree):
...@@ -578,6 +584,7 @@ class crusty(object): ...@@ -578,6 +584,7 @@ class crusty(object):
parameters.append( self._get_variable_properties(parameter,parameter.pointer,True) ) parameters.append( self._get_variable_properties(parameter,parameter.pointer,True) )
self._function_container[node.name] = parameters self._function_container[node.name] = parameters
tmpparams = self._get_variable_properties(None,1,False) tmpparams = self._get_variable_properties(None,1,False)
tmpparams["function"] = True
tmpparams["status"] = crusty.STATUS_FUNCTION tmpparams["status"] = crusty.STATUS_FUNCTION
var_container[0][node.name] = tmpparams var_container[0][node.name] = tmpparams
continue continue
......
...@@ -225,5 +225,8 @@ class Test(unittest.TestCase): ...@@ -225,5 +225,8 @@ class Test(unittest.TestCase):
def testPassBorrowToBorrow(self): def testPassBorrowToBorrow(self):
self._all_fine_test("unitest/test51.c") self._all_fine_test("unitest/test51.c")
def testPassBorrowToBorrow(self):
self._all_fine_test("unitest/test52.c")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void test_function(crust_t __crust_borrow__ param) {
}
void main(crust_t __crust_borrow__ param) {
int prueba;
prueba = test_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