Commit 08f23f10 authored by Sergio's avatar Sergio

Now checks that the signatures of previous function declarations match the...

Now checks that the signatures of previous function declarations match the signatures of the function definition
parent 2b86a7ee
......@@ -890,7 +890,7 @@ class crust(object):
print("statement type unknown '{:s}' at line {:d}".format(statement.type, statement.line))
return [ {"thread_status":thread_status, "value":self.VALUE_NOT_NULL_OR_NULL, "type":self.TYPE_NO_CRUST, "condition":self.CONDITION_FALSE_TRUE, "node":None} ]
#assignment
def _get_next_block(self, current_block):
......@@ -1070,7 +1070,24 @@ class crust(object):
tmpparams["function_params"] = parameters
tmpparams["name"] = node.name
tmpparams["ellipsis"] = node.t_ellipsis
thread_status["variables"][0][node.name] = tmpparams
tmpparams["definition_line"] = node.line
tmpparams["definition_file"] = node.filename
if node.name in thread_status["variables"][0]:
function_data = thread_status["variables"][0][node.name]
differ = False
if function_data["ellipsis"] != tmpparams["ellipsis"]:
differ = True
elif len(function_data["function_params"]) != len(tmpparams["function_params"]):
differ = True
else:
for c in range(len(function_data["function_params"])):
if not self._compare_types(function_data["function_params"][c],tmpparams["function_params"][c]):
differ = True
break
if differ:
self._add_error(thread_status,self.MSG_CRITICAL,"Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'",node.name, node.line, node.filename, function_data["definition_line"], function_data["definition_file"])
else:
thread_status["variables"][0][node.name] = tmpparams
continue
if node.type == "CRUST_DEBUG":
self._do_debug(thread_status)
......
......@@ -698,6 +698,12 @@ class Test(unittest.TestCase):
def test142Switc3(self):
self._generic_test("unitest/test142.c", [ (crust.crust.MSG_ERROR, "Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 17, 15), (crust.crust.MSG_ERROR, "Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 17, 13), (crust.crust.MSG_ERROR, "Parameter {:d} when calling function '{:s}' at line {:d} was freed at line {:d}", 1, "function", 15, 13) ])
def test143CheckSignatures(self):
self._generic_test("unitest/test143.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "main", 7, "unitest/test143.c", 5, "unitest/test143.c") ])
def test144CheckSignatures(self):
self._generic_test("unitest/test144.c", [ (crust.crust.MSG_CRITICAL, "Function definition for '{:s}' at line {:d}, file '{:s}' differs from definition at line {:d}, file '{:s}'", "main", 7, "unitest/test144.c", 5, "unitest/test144.c") ])
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t);
void main(crust_t param1, int) { // ERROR: number of parameters differ from previous definition
int a = 5;
main(param1);
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
void main(crust_t);
void main(int param1) { // ERROR: the type of the parameters differ from the previous definition
int a = 5;
}
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