From 6693022dfbf16db83cdf364d93140d274e4f231b Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Mon, 14 Aug 2017 21:41:08 +0200 Subject: [PATCH] Add !llStringLength(s) -> s == "" optimization. --- lslopt/lslfoldconst.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 94ccab3..47f9a9f 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -371,6 +371,17 @@ class foldconst(object): # !! does *not* cancel out (unless in cond) subexpr = child[0] snt = subexpr['nt'] + + if snt == 'FNCALL' and subexpr['name'] == 'llStringLength': + # !llStringLength(expr) -> expr == "" + parent[index] = {'nt':'==', 't':'integer', + 'ch':[subexpr['ch'][0], + {'nt':'CONST', 't':'string', + 'value':u""}]} + # new node is SEF if the argument to llStringLength is + if 'SEF' in subexpr['ch'][0]: + parent[index]['SEF'] = True + return if 'SEF' in subexpr: node['SEF'] = True if subexpr['nt'] == 'CONST':