Minor details

Assert that it can't be key where we say it can't, and that it is integer where we say it must.

Adjust some comments.
This commit is contained in:
Sei Lisa 2018-06-02 17:28:09 +02:00
parent a33dc8540f
commit ac254efb77

View file

@ -857,9 +857,11 @@ class foldconst(object):
return return
# Can't be key, as no combo of addition operands returns key # Can't be key, as no combo of addition operands returns key
# All these types evaluate to boolean False when they are assert optype != 'key'
# the neutral addition element.
if optype in ('string', 'float', 'list'): if optype in ('string', 'float', 'list'):
# All these types evaluate to boolean False when they are
# the neutral addition element.
if lnt == 'CONST' and not lval.value: if lnt == 'CONST' and not lval.value:
# 0. + expr -> expr # 0. + expr -> expr
# "" + expr -> expr # "" + expr -> expr
@ -928,12 +930,15 @@ class foldconst(object):
type(lval.value)] type(lval.value)]
return return
# Nothing else to do with addition of float, string or list
return return
# Must be two integers. This allows for a number of # Must be two integers. This allows for a number of
# optimizations. First the most obvious ones. # optimizations. First the most obvious ones.
assert optype == 'integer' # just to make sure
if lnt == 'CONST' and lval.value == 0: if lnt == 'CONST' and lval.value == 0:
# 0 + x = x
parent[index] = rval parent[index] = rval
return return