From c154d5eb0da92164578f12064f6d3fe261d75fbc Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Sat, 28 Mar 2015 20:23:47 +0100 Subject: [PATCH] Deal with a number of issues in some expressions. - Move TODO of <0 to !=-1 to boolean, as it's counter-productive otherwise. - All a!=b except list!=list are equivalent to !(a==b). - Change a>b to b=') or nt == '!=' \ - and child[0]['t'] in ('float', 'integer') \ - and child[1]['t'] in ('float', 'integer'): + if nt in ('<=', '>=') or nt == '!=' and child[0]['t'] != 'list': + # Except for list != list, all these comparisons are compiled + # as !(a>b) etc. so we transform them here in order to reduce + # the number of cases to check. + # a<=b --> !(a>b); a>=b --> !(a !(a==b) SEF = 'SEF' in node node['nt'] = {'<=':'>', '>=':'<', '!=':'=='}[nt] node = parent[index] = {'nt':'!', 't':node['t'], 'ch':[node]} if SEF: node['SEF'] = True - # Fold the new node - self.FoldTree(parent, index) - return + # Fall through to optimize as '<' or '>' or '==' - if nt in ('<', '>'): - # TODO: If function domain is -1..INT_MAX, treat <0 as !=-1 + if nt == '>': + # Invert the inequalities to avoid doubling the cases to check. + # a>b --> b2147483647 to FALSE if SEF, otherwise convert to a&0 - # i<-2147483648 to FALSE if SEF, otherwise convert to a&0 - a, b = 0, 1 - if child[a]['nt'] == 'CONST': - a,b = 1,0 - if child[b]['nt'] == 'CONST' and child[a]['t'] == child[b]['t'] == 'integer' \ - and (nt == '>' and child[b]['value'] == 2147483647 - or nt == '<' and child[b]['value'] == -2147483648): - if 'SEF' in child[a]: - parent[index] = node = child[b] - node['value'] = 0 - return + if nt == '<': + # Convert 2147483647 0 if a is SEF if 'SEF' in child[a]: parent[index] = child[b] - return + return if nt == '^': a, b = 0, 1