Add scope field to {} nodes

Since we need to add variables, we need to know which scope to add them to. Add this information to the {} node, which is what creates a new scope.

An alternative would be to scan for any variable or label declaration within the braces and use that or create a new one if none, which is more expensive and may waste symbol tables.
This commit is contained in:
Sei Lisa 2018-12-26 19:47:22 +01:00
parent 3542824d51
commit 76f483fc11
3 changed files with 32 additions and 14 deletions

View file

@ -124,7 +124,9 @@ class lastpass(object):
# function (must be the result of optimization).
# Insert dummy IF(1){...} statement covering the whole function
# (if it returs a value, insert a return statement too).
child[0] = nr(nt='{}', t=None, ch=[
scope = len(self.symtab)
self.symtab.append({})
child[0] = nr(nt='{}', t=None, scope=scope, ch=[
nr(nt='IF', t=None, ch=[
nr(nt='CONST', t='integer', value=1, SEF=True),
child[0]