Commit 119c288d authored by Sergio Costas's avatar Sergio Costas

Now allows to set a value to a pointer to a function, both global and local

parent f021f2dd
......@@ -235,7 +235,8 @@ class crusty(object):
if variable["status"] == self.STATUS_GLOBAL:
return
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)
if variable["pointer"] == 0:
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
if (not force) and variable["crust"]:
status = variable["status"]
......@@ -583,7 +584,8 @@ class crusty(object):
for parameter in node.function_params:
parameters.append( self._get_variable_properties(parameter,parameter.pointer,True) )
self._function_container[node.name] = parameters
tmpparams = self._get_variable_properties(None,1,False)
# 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
var_container[0][node.name] = tmpparams
......@@ -659,6 +661,14 @@ class crusty(object):
var_container[0][node.name] = var_defined
if node.assignment is None:
return self._check_return_block(tree[1:],var_container)
if node.type == "FUNCTION_DECLARATION":
if not node.t_typedef:
# it is a function pointer
tmpparams = self._get_variable_properties(None,node.pointer,False)
tmpparams["function"] = True
tmpparams["status"] = crusty.STATUS_FUNCTION
var_container[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":
tmpnode = node.copy()
......
......@@ -225,8 +225,17 @@ class Test(unittest.TestCase):
def testPassBorrowToBorrow(self):
self._all_fine_test("unitest/test51.c")
def testPassBorrowToBorrow(self):
def testPassBorrowToBorrow2(self):
self._all_fine_test("unitest/test52.c")
def testAssignFunctionToFunctionPointerLocal(self):
self._all_fine_test("unitest/test53.c")
def testAssignFunctionToFunctionPointerGlobal(self):
self._all_fine_test("unitest/test54.c")
def testAssignFunctionPointerToFunctionName(self):
self._generic_test("unitest/test55.c",[ (crusty.crusty.MSG_CRITICAL,"Trying to assign a value to the function name '{:s}' at line {:d}",'test_function',10) ])
if __name__ == '__main__':
unittest.main()
......@@ -6,6 +6,6 @@ void test_function(crust_t __crust_borrow__ param) {
}
void main(crust_t __crust_borrow__ param) {
int prueba;
void (*prueba)(crust_t __crust_borrow__);
prueba = test_function;
}
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) {
void (*test2)(crust_t param);
test2 = test_function;
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void test_function(crust_t __crust_borrow__ param) {
}
void (*test2)(crust_t param);
void main(crust_t __crust_borrow__ param) {
test2 = test_function;
}
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) {
void (*test2)(crust_t param);
test_function = test2;
}
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