Skip to content
Snippets Groups Projects
Commit 5cd44205 authored by Xun Yang's avatar Xun Yang
Browse files

fix local var init inside loops

parent 1a834774
No related branches found
No related tags found
2 merge requests!30New new string,!20Master
This commit is part of merge request !30. Comments created here will be created in the context of that merge request.
......@@ -357,14 +357,24 @@ def getNameNodes(node):
# Output: A list of local var dcl to be pushed onto the stack
def getVarDclNodes(node):
result = []
for s in node.statements:
if s.__class__.__name__ == 'VarDclNode':
result += [s]
if s.__class__.__name__ == 'BlockNode':
result += getVarDclNodes(node)
if s.__class__.__name__ == 'ForNode' and s.forInit:
result += [s.forInit]
if node.__class__.__name__ == 'VarDclNode':
return [node]
elif node.__class__.__name__ == 'BlockNode':
for s in node.statements:
if s.__class__.__name__ == 'VarDclNode':
result += [s]
if s.__class__.__name__ == 'BlockNode':
result += getVarDclNodes(node)
if s.__class__.__name__ == 'ForNode':
if s.forInit:
result += [s.forInit]
if s.bodyStatement:
result += getVarDclNodes(s.bodyStatement)
if s.__class__.__name__ =='WhileNode' and s.whileBody:
result += getVarDclNodes(s.whileBody)
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment