mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Remove duplicate check for '|'
Removed the 'if' and applied an indentation change; no further changes are done.
This commit is contained in:
parent
be767f24f0
commit
2bee2db148
1 changed files with 39 additions and 40 deletions
|
@ -348,48 +348,47 @@ class foldconst(object):
|
|||
del val1, val2
|
||||
del a, b, c, d, and1, and2
|
||||
|
||||
if nt == '|':
|
||||
# Absorb further flags, to allow chaining of &&
|
||||
# If ~r and s are constants, and s is a power of two:
|
||||
# (!~(x|~r) && x&s) -> !~(x|(~r&~s))
|
||||
# This is implemented as:
|
||||
# ~(x|~r) | !(x&s) -> ~(x|~(r|s))
|
||||
# because that's the intermediate result after conversion of &&.
|
||||
# a and b are going to be the children of the main |
|
||||
# a is going to be child that has the ~
|
||||
# b is the other child (with the !)
|
||||
# c is the child of ~ which has x
|
||||
# d is the child of ~ with the constant ~r
|
||||
# e is the child of ! which has x
|
||||
# f is the child of ! with the constant s
|
||||
a, b = 0, 1
|
||||
if child[a]['nt'] != '~':
|
||||
a, b = b, a
|
||||
c, d = 0, 1
|
||||
if child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|':
|
||||
if child[a]['ch'][0]['ch'][d]['nt'] != 'CONST':
|
||||
c, d = d, c
|
||||
e, f = 0, 1
|
||||
if child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&':
|
||||
if child[b]['ch'][0]['ch'][f]['nt'] != 'CONST':
|
||||
e, f = f, e
|
||||
# All pointers are ready to check applicability.
|
||||
if (child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|'
|
||||
and child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&'
|
||||
# Absorb further flags, to allow chaining of &&
|
||||
# If ~r and s are constants, and s is a power of two:
|
||||
# (!~(x|~r) && x&s) -> !~(x|(~r&~s))
|
||||
# This is implemented as:
|
||||
# ~(x|~r) | !(x&s) -> ~(x|~(r|s))
|
||||
# because that's the intermediate result after conversion of &&.
|
||||
# a and b are going to be the children of the main |
|
||||
# a is going to be child that has the ~
|
||||
# b is the other child (with the !)
|
||||
# c is the child of ~ which has x
|
||||
# d is the child of ~ with the constant ~r
|
||||
# e is the child of ! which has x
|
||||
# f is the child of ! with the constant s
|
||||
a, b = 0, 1
|
||||
if child[a]['nt'] != '~':
|
||||
a, b = b, a
|
||||
c, d = 0, 1
|
||||
if child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|':
|
||||
if child[a]['ch'][0]['ch'][d]['nt'] != 'CONST':
|
||||
c, d = d, c
|
||||
e, f = 0, 1
|
||||
if child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&':
|
||||
if child[b]['ch'][0]['ch'][f]['nt'] != 'CONST':
|
||||
e, f = f, e
|
||||
# All pointers are ready to check applicability.
|
||||
if (child[a]['nt'] == '~' and child[a]['ch'][0]['nt'] == '|'
|
||||
and child[b]['nt'] == '!' and child[b]['ch'][0]['nt'] == '&'
|
||||
):
|
||||
ch1 = child[a]['ch'][0]['ch']
|
||||
ch2 = child[b]['ch'][0]['ch']
|
||||
if (ch1[d]['nt'] == 'CONST' and ch2[f]['nt'] == 'CONST'
|
||||
and (ch2[f]['value'] & (ch2[f]['value'] - 1)) == 0
|
||||
):
|
||||
ch1 = child[a]['ch'][0]['ch']
|
||||
ch2 = child[b]['ch'][0]['ch']
|
||||
if (ch1[d]['nt'] == 'CONST' and ch2[f]['nt'] == 'CONST'
|
||||
and (ch2[f]['value'] & (ch2[f]['value'] - 1)) == 0
|
||||
):
|
||||
if self.CompareTrees(ch1[c], ch2[e]):
|
||||
# We're in that case. Apply optimization.
|
||||
parent[index] = child[a]
|
||||
ch1[d]['value'] &= ~ch2[f]['value']
|
||||
return
|
||||
del ch1, ch2
|
||||
if self.CompareTrees(ch1[c], ch2[e]):
|
||||
# We're in that case. Apply optimization.
|
||||
parent[index] = child[a]
|
||||
ch1[d]['value'] &= ~ch2[f]['value']
|
||||
return
|
||||
del ch1, ch2
|
||||
|
||||
del a, b, c, d, e, f
|
||||
del a, b, c, d, e, f
|
||||
|
||||
|
||||
# Check if the operands are a negation ('!') or can be inverted
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue