Poincare: Expression::isIdenticalTo

Change-Id: I4a28b5b771efc5a00f49aeaa725c264e87e96c88
This commit is contained in:
Romain Goyet
2016-03-24 15:51:22 +01:00
parent 32745b9fe4
commit c43211cb45
2 changed files with 12 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ class Expression {
/* identicalTo means strictly the same tree. For example, 3+5 is NOT identi-
* cal to 5+3. Those are equal, but not identical. */
//virtual bool identicalTo(Expression * e);
bool isIdenticalTo(Expression * e);
Expression * simplify();
virtual Type type() = 0;

View File

@@ -43,3 +43,14 @@ Expression * Expression::simplify() {
return result;
}
bool Expression::isIdenticalTo(Expression * e) {
if (e->type() != this->type() || e->numberOfOperands() != this->numberOfOperands()) {
return false;
}
for (int i=0; i<this->numberOfOperands(); i++) {
if (!e->operand(i)->isIdenticalTo(this->operand(i))) {
return false;
}
}
return true;
}