From cbb589740133d53224fcd66c4c2decf43a7eca6e Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Sat, 3 Dec 2011 13:55:31 +0000 Subject: Support multiple declarations in the global scope --- pp2cc.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'pp2cc.py') diff --git a/pp2cc.py b/pp2cc.py index 03a57a1..190f10a 100755 --- a/pp2cc.py +++ b/pp2cc.py @@ -988,7 +988,7 @@ class Parse(object): if not linked_type.node.type.names[0] in ("int", "void"): self.logger.warning("Only void and int types are supported", linked_node) elif linked_type.type == "FuncDecl": - # a function declaration does not accept an initializaer, but it's + # a function declaration does not accept an initializer, but it's # still special because it has params return self.parseStatement(linked_type.node, linked_node) else: @@ -1000,8 +1000,11 @@ class Parse(object): size += 1 try: - is_static = "static" in linked_node.node.storage - linked_node.variables.declName(name, size, is_static=is_static) + # global variables may be declared multiple times, local variables + # are not allowed for that + if in_function or not linked_node.variables.isDeclared(name): + is_static = "static" in linked_node.node.storage + linked_node.variables.declName(name, size, is_static=is_static) # address of variable split up in register and displacement var_reg, var_disp = linked_node.variables.getAddress(name) except RuntimeError as errmsg: @@ -1020,6 +1023,13 @@ class Parse(object): var_reg + "+" + var_disp + "]")) # if the declaration also has a definition if linked_node.node.init: + # global variables needs to be marked as defined + if not in_function: + try: + linked_node.variables.defName(name) + except RuntimeError as errmsg: + self.logger.error(errmsg, linked_node=linked_node) + init_vals = [] linked_init = LinkedNode(linked_node.node.init, linked_node) if (linked_type.type == "ArrayDecl" and -- cgit v1.2.1