mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Apply an associativity rule to strings
It's not general associativity, it just folds CONST + (CONST + expr). Some day we'll implement sum flattening, to make this possible.
This commit is contained in:
parent
e2d01e7825
commit
0a6155bb13
1 changed files with 15 additions and 2 deletions
|
@ -939,6 +939,20 @@ class foldconst(object):
|
||||||
lnt, rnt = rnt, lnt
|
lnt, rnt = rnt, lnt
|
||||||
ltype, rtype = rtype, ltype
|
ltype, rtype = rtype, ltype
|
||||||
|
|
||||||
|
if (self.addstrings and optype == 'string' and rnt == '+'
|
||||||
|
and rval.ch[0].nt == 'CONST' and lnt == 'CONST'
|
||||||
|
):
|
||||||
|
# We have CONST + (CONST + expr) of strings.
|
||||||
|
# Apply associativity to merge both constants.
|
||||||
|
|
||||||
|
# Add the constants
|
||||||
|
child[0].value = lslfuncs.add(child[0].value,
|
||||||
|
rval.ch[0].value)
|
||||||
|
# Prune the expr and graft it as RHS
|
||||||
|
child[1] = rval.ch[1]
|
||||||
|
# Re-optimize this node to apply it recursively
|
||||||
|
return self.FoldTree(parent, index)
|
||||||
|
|
||||||
# Nothing else to do with addition of float, string or list
|
# Nothing else to do with addition of float, string or list
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -963,8 +977,7 @@ class foldconst(object):
|
||||||
# Apply associativity to merge both constants.
|
# Apply associativity to merge both constants.
|
||||||
|
|
||||||
# Add the constants
|
# Add the constants
|
||||||
child[0].value = lslfuncs.S32(child[0].value
|
lval.value = lslfuncs.add(lval.value, rval.ch[0].value)
|
||||||
+ rval.ch[0].value)
|
|
||||||
# Prune the expr and graft it as RHS
|
# Prune the expr and graft it as RHS
|
||||||
child[1] = rval.ch[1]
|
child[1] = rval.ch[1]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue