Commit a0904278 authored by Sergio Costas's avatar Sergio Costas

Now doesn't fail when an struct is initialized inside a function

parent 7287e442
......@@ -547,7 +547,12 @@ class crust(object):
if statement.type == "=":
threads = self._eval_statement(statement.child2[0], self._copy_status(thread_status)) # evaluate the right part of the assignment
if (statement.child1[0].t_struct and (not statement.child1[0].right) and (statement.child1[0].pointer == 0)):
# static initialization of this struct
threads = [{ "thread_status": thread_status, "value": self.VALUE_NOT_NULL, "type": self.TYPE_NO_MATTER, "condition":self.CONDITION_TRUE, "node": statement.child1[0], "pure": True}]
else:
threads = self._eval_statement(statement.child2[0], self._copy_status(thread_status)) # evaluate the right part of the assignment
dest_eval = self._eval_statement(statement.child1[0], thread_status)[0]
dest_var = dest_eval["node"]
......@@ -1209,11 +1214,11 @@ class crust(object):
thread_status["variables"][0][function_name] = tmpparams
def process_tree(self, tree, verbose = False):
def process_tree(self, tree, filename, verbose = False):
""" Process the main tree with the global variables and the function definitions and declarations """
self.verbose = verbose
thread_status = { "variables": [ {} ], "debug_level": 0, "loop_level": 0, "find_label": None, "return_is_crust": False, "return_is_borrowed": False, "return_cant_null": False, "returned_something": None, "current_function": "" }
thread_status = { "variables": [ {} ], "debug_level": 0, "loop_level": 0, "find_label": None, "return_is_crust": False, "return_is_borrowed": False, "return_cant_null": False, "returned_something": None, "current_function": "", "filename": filename }
# Set the GCC builtin functions
......@@ -1823,7 +1828,7 @@ def process_file(lib, filename, parameters):
tree = lib.read_file(filename, False, parameters["includes"], parameters["defines"], parameters["include_files"], parameters["nocpp"], parameters["preprocessed"])
if tree is None:
return
variables = lib.process_tree(tree, parameters["verbose"])
variables = lib.process_tree(tree, filename, parameters["verbose"])
lib.process_functions(tree, variables)
except crust.VarNotFoundException:
pass
......
......@@ -801,6 +801,7 @@ designator_list
designator
: '[' constant_expression ']' { $$ = $1; show_error(__LINE__, $$); }
| '.' IDENTIFIER { $$ = $1; /* For designated initializers in structs */
$$->right = $2;
show_debug(__LINE__, $$, "designator");}
;
......
......@@ -70,7 +70,7 @@ class Test(unittest.TestCase):
lib = self.open_crust()
tree = lib.read_file(filename, False, [], [], [])
self.assertIsNot(tree, None)
variables = lib.process_tree(tree)
variables = lib.process_tree(tree, filename)
lib.process_functions(tree, variables)
self._print_errors(filename, lib)
self.assertEqual(len(lib.errors), len(params))
......@@ -88,7 +88,7 @@ class Test(unittest.TestCase):
lib = self.open_crust()
tree = lib.read_file(filename, False, [], [], [])
self.assertIsNot(tree, None)
variables = lib.process_tree(tree)
variables = lib.process_tree(tree, filename)
lib.process_functions(tree, variables)
self._print_errors(filename, lib)
self.assertEqual(len(lib.errors), 0)
......@@ -100,7 +100,7 @@ class Test(unittest.TestCase):
lib = self.open_crust()
tree = lib.read_file(filename, False, [], [], [])
self.assertIsNot(tree, None)
variables = lib.process_tree(tree)
variables = lib.process_tree(tree, filename)
with self.assertRaises(exception_class):
lib.process_functions(tree, variables)
self._print_errors(filename, lib)
......@@ -913,6 +913,9 @@ class Test(unittest.TestCase):
def test213InitializedNoSizeArrays(self):
self._all_fine_test("unitest/test213.c")
def test214InitializeStructs(self):
self._all_fine_test("unitest/test214.c")
if __name__ == '__main__':
try:
os.remove("error_list.txt")
......
void main() {
struct test_t {
int v;
char b;
} test = {
.v = 1,
.b = 0
};
int f;
test.v++;
f = test.b;
}
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