From 6f8f3032bd897aff109b96af0a2f0d510e02ed57 Mon Sep 17 00:00:00 2001 From: Derval Guillaume <gderval@uliege.be> Date: Tue, 25 Apr 2023 15:56:50 +0200 Subject: [PATCH] Eq for expressions --- src/gboml/ast/expression_operators.py | 7 +++++++ src/gboml/ast/expressions.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/gboml/ast/expression_operators.py b/src/gboml/ast/expression_operators.py index 685e0eb..267ac57 100644 --- a/src/gboml/ast/expression_operators.py +++ b/src/gboml/ast/expression_operators.py @@ -41,6 +41,13 @@ class BoolExpressionComparison(BoolExpression): operator: Operator rhs: Expression + def __bool__(self): + """ Checks if lhs and rhs are *exactly* the same tree in an eq relation """ + #TODO improve me + if self.operator == Operator.equal: + return self.lhs is self.rhs + return False + @dataclass class ExpressionUseGenScope(ExpressionObj): diff --git a/src/gboml/ast/expressions.py b/src/gboml/ast/expressions.py index fc7e421..04d4494 100644 --- a/src/gboml/ast/expressions.py +++ b/src/gboml/ast/expressions.py @@ -5,7 +5,14 @@ from gboml.ast.base import GBOMLObject @dataclass class ExpressionObj(GBOMLObject): - pass + def __eq__(self, obj): + from gboml.ast.expression_operators import Operator, BoolExpressionComparison + # first: check type + if not isinstance(obj, Expression): + return False + if self is obj: + return True + return BoolExpressionComparison(self, Operator.equal, obj) Expression = int | float | ExpressionObj -- GitLab