mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Move side-effect-free check for functions to a method.
This will in future allow us to check argument-dependent SEFness.
This commit is contained in:
parent
0bbfb08234
commit
22e057e2ec
1 changed files with 13 additions and 3 deletions
|
@ -168,6 +168,14 @@ class foldconst(object):
|
||||||
and self.CompareTrees(node1['ch'][0], node2['ch'][0])
|
and self.CompareTrees(node1['ch'][0], node2['ch'][0])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def FnSEF(self, node):
|
||||||
|
'''Applied to function call nodes, return whether the node corresponds
|
||||||
|
to a SEF function.
|
||||||
|
'''
|
||||||
|
assert node['nt'] == 'FNCALL'
|
||||||
|
sym = self.symtab[0][node['name']]
|
||||||
|
return 'SEF' in sym and sym['SEF'] is True
|
||||||
|
|
||||||
def FoldStmt(self, parent, index):
|
def FoldStmt(self, parent, index):
|
||||||
"""Simplify a statement."""
|
"""Simplify a statement."""
|
||||||
node = parent[index]
|
node = parent[index]
|
||||||
|
@ -198,7 +206,9 @@ class foldconst(object):
|
||||||
# If the statement is a function call and the function is marked as SEF
|
# If the statement is a function call and the function is marked as SEF
|
||||||
# at this point, it means the arguments are not SEF. Replace the node
|
# at this point, it means the arguments are not SEF. Replace the node
|
||||||
# in that case with a block.
|
# in that case with a block.
|
||||||
if node['nt'] == 'FNCALL' and 'SEF' in self.symtab[0][node['name']] and 'Loc' in self.symtab[0][node['name']]:
|
if (node['nt'] == 'FNCALL' and 'Loc' in self.symtab[0][node['name']]
|
||||||
|
and self.FnSEF(node)
|
||||||
|
):
|
||||||
parent[index] = {'nt':'{}', 't':None, 'ch':
|
parent[index] = {'nt':'{}', 't':None, 'ch':
|
||||||
[{'nt':'EXPR','t':x['t'],'ch':[x]} for x in node['ch']]}
|
[{'nt':'EXPR','t':x['t'],'ch':[x]} for x in node['ch']]}
|
||||||
self.FoldTree(parent, index)
|
self.FoldTree(parent, index)
|
||||||
|
@ -1314,7 +1324,7 @@ class foldconst(object):
|
||||||
sym = self.symtab[0][name]
|
sym = self.symtab[0][name]
|
||||||
OptimizeArgs(node, sym)
|
OptimizeArgs(node, sym)
|
||||||
try:
|
try:
|
||||||
if 'Fn' in sym and ('SEF' in sym or lslcommon.IsCalc):
|
if 'Fn' in sym and (self.FnSEF(node) or lslcommon.IsCalc):
|
||||||
# It's side-effect free if the children are and the function
|
# It's side-effect free if the children are and the function
|
||||||
# is marked as SEF.
|
# is marked as SEF.
|
||||||
if SEFargs:
|
if SEFargs:
|
||||||
|
@ -1383,7 +1393,7 @@ class foldconst(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == 'FNDEF':
|
if nt == 'FNDEF':
|
||||||
# used when folding llDetected* function calls
|
# CurEvent is needed when folding llDetected* function calls
|
||||||
if 'scope' in node:
|
if 'scope' in node:
|
||||||
# function definition
|
# function definition
|
||||||
self.CurEvent = None
|
self.CurEvent = None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue