Fix CompareTrees to not compare unstable functions as equal.

This commit is contained in:
Sei Lisa 2017-10-21 10:44:09 +02:00
parent 4d92cc8838
commit e6b23a2d7a

View file

@ -149,10 +149,7 @@ class foldconst(object):
def CompareTrees(self, node1, node2): def CompareTrees(self, node1, node2):
"""Try to compare two subtrees to see if they are equivalent.""" """Try to compare two subtrees to see if they are equivalent."""
# They MUST be SEF # They MUST be SEF and stable.
# FIXME: They must also be stable, i.e. return the same value
# in two successive calls with a certain degree of certainty.
# Counterexamples are llFrand, llGetTimestamp.
if 'SEF' not in node1 or 'SEF' not in node2: if 'SEF' not in node1 or 'SEF' not in node2:
return False return False
# So far it's only accepted if both are identifiers or function calls, # So far it's only accepted if both are identifiers or function calls,
@ -162,6 +159,7 @@ class foldconst(object):
and node1['scope'] == node2['scope'] and node1['scope'] == node2['scope']
or node1['nt'] == node2['nt'] == 'FNCALL' or node1['nt'] == node2['nt'] == 'FNCALL'
and node1['name'] == node2['name'] and node1['name'] == node2['name']
and 'uns' not in self.symtab[0][node1['name']]
and all(self.CompareTrees(node1['ch'][i], and all(self.CompareTrees(node1['ch'][i],
node2['ch'][i]) node2['ch'][i])
for i in xrange(len(node1['ch']))) for i in xrange(len(node1['ch'])))