summaryrefslogtreecommitdiff
path: root/pp2cc.py
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2011-12-03 13:55:31 +0000
committerPeter Wu <lekensteyn@gmail.com>2011-12-03 13:55:31 +0000
commitcbb589740133d53224fcd66c4c2decf43a7eca6e (patch)
tree3675a6cf2165af6d5c14b9bc6c5982facb7598cb /pp2cc.py
parent658bfe6c92b6dccea353da38a7651c61cd4ef1ce (diff)
downloadpp2cc-cbb589740133d53224fcd66c4c2decf43a7eca6e.tar.gz
Support multiple declarations in the global scope
Diffstat (limited to 'pp2cc.py')
-rwxr-xr-xpp2cc.py16
1 files changed, 13 insertions, 3 deletions
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