Fix crash when variables appear inside global lists.

Fixes #3.
This commit is contained in:
Sei Lisa 2017-10-16 01:20:01 +02:00
parent cc96850f66
commit 82081b2206

View file

@ -223,8 +223,19 @@ class deadcode(object):
node['X'] = True node['X'] = True
if child is not None: if child is not None:
if 'orig' in child[0]: if 'orig' in child[0]:
self.MarkReferences(child[0]['orig']) orig = child[0]['orig']
child[0]['X'] = child[0]['orig']['X'] self.MarkReferences(orig)
child[0]['X'] = orig['X']
if orig['nt'] == 'LIST':
# Add fake writes to variables used in list elements in
# 'orig', so they don't get deleted (Issue #3)
for subnode in orig['ch']:
if subnode['nt'] == 'IDENT':
# can only happen in globals
assert subnode['scope'] == 0
sym = self.symtab[0][subnode['name']]
sym['W'] = False
self.tree[sym['Loc']]['X'] = True
else: else:
self.MarkReferences(child[0]) self.MarkReferences(child[0])
return True return True