From 6ad2ef04d7efd0758f380c8663656b8f5d3345d6 Mon Sep 17 00:00:00 2001 From: Sei Lisa Date: Fri, 13 Oct 2017 00:30:47 +0200 Subject: [PATCH] Add support for function calls in CompareTrees. --- lslopt/lslfoldconst.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lslopt/lslfoldconst.py b/lslopt/lslfoldconst.py index 7163aa4..ee3d5ca 100644 --- a/lslopt/lslfoldconst.py +++ b/lslopt/lslfoldconst.py @@ -127,10 +127,17 @@ class foldconst(object): # They MUSt be SEF if 'SEF' not in node1 or 'SEF' not in node2: return False - # So far it's only accepted if both are identifiers. + # So far it's only accepted if both are identifiers or function calls, + # recursively. return (node1['nt'] == node2['nt'] == 'IDENT' and node1['name'] == node2['name'] - and node1['scope'] == node2['scope']) + and node1['scope'] == node2['scope'] + or node1['nt'] == node2['nt'] == 'FNCALL' + and node1['name'] == node2['name'] + and all(self.CompareTrees(node1['ch'][i], + node2['ch'][i]) + for i in xrange(len(node1['ch']))) + ) def FoldStmt(self, parent, index): """Simplify a statement."""