From 9a820a62d051c7f243ae0a49b7d343cf60e07015 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Wed, 23 Aug 2017 11:58:05 +0200 Subject: [PATCH] Simplify (type)sametype_expr -> sametype_expr. --- lslopt/lslfoldconst.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 17eb06e..75f6a9a 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -344,6 +344,16 @@ class foldconst(object): parent[index] = {'nt':'CONST', 't':node['t'], 'SEF':True, 'value':lslfuncs.typecast( child[0]['value'], self.LSL2PythonType[node['t']])} + + # Remove casts of a type to the same type (NOP in Mono) + # This is not an optimization by itself, but it simplifies the job, + # by not needing to look into nested casts like (key)((key)...) + while node['nt'] == 'CAST' and child[0]['t'] == node['t']: + parent[index] = node = child[0] + if 'ch' not in node: + break + child = node['ch'] + return if nt == 'NEG':