From 4cbdbefe1bcd0718b69cf66f9518d721d2933f02 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Tue, 17 Oct 2017 23:28:14 +0200 Subject: [PATCH] Fold again after applying distributibity or absortion. Failure to do so was blocking some constant folding, like in: if (a&1 || a&2 || a&4) -> if (a&(3|4)) Fixed. Now it correctly outputs if (a&7). --- lslopt/lslfoldconst.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 18b7022..e003d15 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -1125,6 +1125,7 @@ class foldconst(object): parent[index] = child[b] # Apply boolean distributivity + applied = False opposite = '&' if nt == '|' else '|' if child[0]['nt'] == child[1]['nt'] == opposite: left = child[0]['ch'] @@ -1136,6 +1137,7 @@ class foldconst(object): opposite = child[1]['nt'] right[d] = left[1 - c] child[0] = left[c] + applied = True break # Apply absorption, possibly after distributivity @@ -1148,8 +1150,13 @@ class foldconst(object): node = parent[index] = child[c] nt = node['nt'] child = node['ch'] if 'ch' in node else None + applied = True break + if applied: + # Re-fold + self.FoldTree(parent, index) + return if nt == '^':