From ed49170d87a5237196aabb50d7e01225304e4a88 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Mon, 30 Oct 2017 16:55:00 +0100 Subject: [PATCH] Remove empty SEF events. If the state becomes empty, add an empty timer() event. timer() is the parameter-less event with the shortest name. --- lslopt/lslfoldconst.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 510e319..f8b73f7 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -1497,6 +1497,15 @@ class foldconst(object): # event definition self.CurEvent = node['name'] self.FoldTree(child, 0) + + # Test if the event is empty and SEF, and remove it if so. + if ('scope' not in node and not self.DoesSomething(child[0], + labels = False) and 'SEF' in self.events[node['name']] + ): + # Delete ourselves. + del parent[index] + return + # 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']: @@ -1534,8 +1543,14 @@ class foldconst(object): return if nt == 'STDEF': - for idx in xrange(len(child)): + for idx in xrange(len(child) - 1, -1, -1): self.FoldTree(child, idx) + if not child: + # All events removed - add a dummy timer() + child.append({'nt':'FNDEF', 't':None, 'name':'timer', + 'pscope':0, 'ptypes':[], 'pnames':[], + 'ch':[{'nt':'{}', 't':None, 'ch':[]}] + }) return if nt == '{}':