mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
Associate identifiers with their direct location.
Instead of returning the scope level at which search can start, return the scope level at which the symbol actually is.
This commit is contained in:
parent
12a1245102
commit
cef3e626a9
1 changed files with 17 additions and 5 deletions
|
@ -190,6 +190,18 @@ class parser(object):
|
||||||
return None
|
return None
|
||||||
return self.globals[symbol]
|
return self.globals[symbol]
|
||||||
|
|
||||||
|
def FindScopeIndex(self, symbol, MustBeLabel = False):
|
||||||
|
"""Same as FindSymbolPartial, but stops at globals, and returns scope
|
||||||
|
level instead of symbol table entry.
|
||||||
|
"""
|
||||||
|
scope = self.scopeindex
|
||||||
|
while scope:
|
||||||
|
symtab = self.symtab[scope]
|
||||||
|
if symbol in symtab and (not MustBeLabel or symtab[symbol][1] == 'Label'):
|
||||||
|
return scope
|
||||||
|
scope = symtab[-1]
|
||||||
|
return scope
|
||||||
|
|
||||||
def ValidateField(self, typ, field):
|
def ValidateField(self, typ, field):
|
||||||
if typ == 'vector' and field in ('x', 'y', 'z') \
|
if typ == 'vector' and field in ('x', 'y', 'z') \
|
||||||
or typ == 'rotation' and field in ('x', 'y', 'z', 's'):
|
or typ == 'rotation' and field in ('x', 'y', 'z', 's'):
|
||||||
|
@ -634,7 +646,7 @@ class parser(object):
|
||||||
if typ not in self.types:
|
if typ not in self.types:
|
||||||
raise EParseTypeMismatch(self)
|
raise EParseTypeMismatch(self)
|
||||||
typ = S[typ]
|
typ = S[typ]
|
||||||
lvalue = [S['IDENT'], typ, name, self.scopeindex]
|
lvalue = [S['IDENT'], typ, name, self.FindScopeIndex(name)]
|
||||||
if tok0 == '.':
|
if tok0 == '.':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
self.expect('IDENT')
|
self.expect('IDENT')
|
||||||
|
@ -751,7 +763,7 @@ class parser(object):
|
||||||
raise EParseUndefined(self)
|
raise EParseUndefined(self)
|
||||||
typ = S[typ]
|
typ = S[typ]
|
||||||
|
|
||||||
ret = [S['IDENT'], typ, name, self.scopeindex]
|
ret = [S['IDENT'], typ, name, self.FindScopeIndex(name)]
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
if self.tok[0] == '.':
|
if self.tok[0] == '.':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
|
@ -1157,7 +1169,7 @@ class parser(object):
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
self.expect(';')
|
self.expect(';')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
return [S['JUMP'], None, ['IDENT', S['Label'], name, self.scopeindex]]
|
return [S['JUMP'], None, ['IDENT', S['Label'], name, self.FindScopeIndex(name, MustBeLabel=True)]]
|
||||||
if tok0 == 'STATE':
|
if tok0 == 'STATE':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
if self.tok[0] not in ('DEFAULT', 'IDENT'):
|
if self.tok[0] not in ('DEFAULT', 'IDENT'):
|
||||||
|
@ -1170,7 +1182,7 @@ class parser(object):
|
||||||
self.expect(';')
|
self.expect(';')
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
return [S['STATE'], None,
|
return [S['STATE'], None,
|
||||||
[S['IDENT'], S['State'], name, self.scopeindex] if name != 'default' else S['DEFAULT']]
|
[S['IDENT'], S['State'], name, 0] if name != 'default' else S['DEFAULT']]
|
||||||
if tok0 == 'RETURN':
|
if tok0 == 'RETURN':
|
||||||
self.NextToken()
|
self.NextToken()
|
||||||
if self.tok[0] == ';':
|
if self.tok[0] == ';':
|
||||||
|
@ -1317,7 +1329,7 @@ class parser(object):
|
||||||
if tmp is None or len(tmp) > 3 or tmp[1] not in self.types:
|
if tmp is None or len(tmp) > 3 or tmp[1] not in self.types:
|
||||||
raise EParseUndefined(self)
|
raise EParseUndefined(self)
|
||||||
#return tmp[2]
|
#return tmp[2]
|
||||||
return (S['IDENT'], S[tmp[1]], tok[1], self.scopeindex)
|
return (S['IDENT'], S[tmp[1]], tok[1], self.FindScopeIndex(tok[1]))
|
||||||
if tok[0] == '<':
|
if tok[0] == '<':
|
||||||
value = [self.Parse_simple_expr()]
|
value = [self.Parse_simple_expr()]
|
||||||
self.autocastcheck((0, self.PythonType2LSL[type(value[0])]), 'float')
|
self.autocastcheck((0, self.PythonType2LSL[type(value[0])]), 'float')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue