From df31a694654dcf2bc2546d646289442f5a30930a Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Fri, 13 Mar 2015 23:46:23 +0100 Subject: [PATCH] In functions that end in 'return;', remove the 'return;'. This allows better side-effect analysis, because 'return' is not side-effect free unless it's the last statement. But that's better handled in the dead code removal module, as the comment specifies. --- lslopt/lslfoldconst.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 70ff2b6..8c5f85c 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -812,6 +812,13 @@ class foldconst(object): # event definition self.CurEvent = node['name'] self.FoldTree(child, 0) + # TODO: This works, but analysis of code paths is DCR's thing + # and this is incomplete, e.g. x(){{return;}} is not detected. + while 'ch' in child[0] and child[0]['ch']: + last = child[0]['ch'][-1] + if last['nt'] != 'RETURN' or 'ch' in last: + break + del child[0]['ch'][-1] if 'SEF' in child[0]: node['SEF'] = True if node['name'] in self.symtab[0]: