Fix bug where folding a FOR loop with const false cond produced bad code.

More precisely, the initializator list was not wrapped into EXPR nodes. Now it is.

While on it, fix a minor bug (the substitutive of a FOR statement should produce no output type), and change order of execution to the actual one (iterators come last).
This commit is contained in:
Sei Lisa 2014-08-04 02:19:36 +02:00
parent 17e94a0d0f
commit 24a32c30e3

View file

@ -567,19 +567,23 @@ class optimizer(renamer, deadcode):
if lslfuncs.cond(child[1]['value']):
# Endless loop. Just replace the constant and traverse the rest.
child[1].update({'t':'integer', 'value':-1})
self.FoldAndRemoveEmptyStmts(child[2]['ch'])
self.FoldTree(child, 3)
self.FoldStmt(child, 3)
elif len(child[0]['ch']) > 1:
parent[index] = {'nt':'{}', 't':None, 'ch':child[0]['ch']}
self.FoldAndRemoveEmptyStmts(child[2]['ch'])
elif child[0]['ch']:
parent[index] = child[0]['ch'][0]
# Convert expression list to code block.
exprlist = []
for expr in child[0]['ch']:
# Fold into expression statements.
exprlist.append({'nt':'EXPR', 't':expr['t'], 'ch':[expr]})
# returns type None, as FOR does
parent[index] = {'nt':'{}', 't':None, 'ch':exprlist}
else:
parent[index] = {'nt':';', 't':None}
else:
self.FoldAndRemoveEmptyStmts(child[2]['ch'])
self.FoldTree(child, 3)
self.FoldStmt(child, 3)
self.FoldAndRemoveEmptyStmts(child[2]['ch'])
return
if nt == 'RETURN':