Handle list+list more sanely.

This commit is contained in:
Sei Lisa 2017-11-04 22:49:02 +01:00
parent 0b1ad7c110
commit a4b3c1eadd

View file

@ -893,35 +893,52 @@ class foldconst(object):
if ltype == rtype == 'list': if ltype == rtype == 'list':
if (rnt == 'LIST' and len(rval['ch']) == 1 if (rnt == 'LIST' and len(rval['ch']) == 1
or rnt == 'CAST'): or rnt == 'CONST' and len(rval['value']) == 1
or rnt == 'CAST'
):
# list + (list)element -> list + element # list + (list)element -> list + element
# list + [element] -> list + element # list + [element] -> list + element
while True: while rnt == 'CAST' and rval['t'] == 'list':
# Remove nested typecasts: (list)(list)x -> x # Remove nested typecasts
# e.g. list + (list)((list)x) -> list + x
rval = parent[index]['ch'][1] = rval['ch'][0] rval = parent[index]['ch'][1] = rval['ch'][0]
if rval['nt'] != 'CAST' or rval['t'] != 'list': rnt = rval['nt']
break if (rnt == 'LIST' and len(rval['ch']) == 1
return and rval['ch'][0]['t'] != 'list'):
if rnt == 'CONST' and len(rval['value']) == 1: # Finally, remove [] wrapper if it's not
# list + [constant] -> list + constant # list within list
rval['value'] = rval['value'][0] rval = child[1] = rval['ch'][0]
rtype = rval['t'] = lslcommon.PythonType2LSL[type(rval['value'])] rnt = rval['nt']
if rnt == 'CONST' and len(rval['value']) == 1:
# list + [constant] -> list + constant
rval['value'] = rval['value'][0]
rtype = rval['t'] = lslcommon.PythonType2LSL[
type(rval['value'])]
return return
if (lnt == 'LIST' and len(lval['ch']) == 1 if (lnt == 'LIST' and len(lval['ch']) == 1
or lnt == 'CAST'): or lnt == 'CONST' and len(lval['value']) == 1
or lnt == 'CAST'
):
# (list)element + list -> element + list # (list)element + list -> element + list
# [element] + list -> element + list # [element] + list -> element + list
while True: # (list)[element] + list -> element + list
# Remove nested typecasts: (list)(list)x -> x while lnt == 'CAST' and lval['t'] == 'list':
# Remove nested typecasts
# e.g. (list)((list)x) + list -> x + list
lval = parent[index]['ch'][0] = lval['ch'][0] lval = parent[index]['ch'][0] = lval['ch'][0]
if lval['nt'] != 'CAST' or lval['t'] != 'list': lnt = lval['nt']
break if (lnt == 'LIST' and len(lval['ch']) == 1
return and lval['ch'][0]['t'] != 'list'):
if lnt == 'CONST' and len(lval['value']) == 1: # Finally, remove [] wrapper if it's not
# [constant] + list -> constant + list # list within list
lval['value'] = lval['value'][0] lval = child[0] = lval['ch'][0]
ltype = lval['t'] = lslcommon.PythonType2LSL[type(lval['value'])] lnt = lval['nt']
if lnt == 'CONST' and len(lval['value']) == 1:
# [constant] + list -> constant + list
lval['value'] = lval['value'][0]
ltype = lval['t'] = lslcommon.PythonType2LSL[
type(lval['value'])]
return return
return return