[poincare] Change default immediate simplify

Change-Id: I427b3b6d50bc47bf3fe2d64df263d40f9ecf79e0
This commit is contained in:
Émilie Feral
2017-10-12 14:09:44 +02:00
parent e9074b25ec
commit 2cfaed4366
3 changed files with 13 additions and 2 deletions

View File

@@ -135,7 +135,7 @@ public:
static void simplifyAndBeautify(Expression ** expressionAddress);
Expression * simplify();
// TODO: should be virtual pure
virtual Expression * immediateSimplify() { return this; };// = 0;
virtual Expression * immediateSimplify();
virtual Expression * immediateBeautify() { return this; };
/* Evaluation Engine

View File

@@ -6,6 +6,7 @@
#include <poincare/list_data.h>
#include <poincare/matrix_data.h>
#include <poincare/evaluation.h>
#include <poincare/undefined.h>
#include <cmath>
#include "expression_parser.hpp"
#include "expression_lexer.hpp"
@@ -78,6 +79,7 @@ public:
}
Expression * clone() const override { return nullptr; }
Type type() const override { return Expression::Type::Undefined; }
Expression * immediateSimplify() override { return this; }
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
return nullptr;
}
@@ -112,6 +114,15 @@ void Expression::beautify(Expression ** expressionAddress) {
}
}
Expression * Expression::immediateSimplify() {
for (int i = 0; i< numberOfOperands(); i++) {
if (operand(i)->type() == Type::Undefined) {
return replaceWith(new Undefined(), true);
}
}
return this;
}
bool Expression::hasAncestor(const Expression * e) const {
assert(m_parent != this);
if (m_parent == e) {

View File

@@ -218,7 +218,7 @@ Expression * Power::immediateSimplify() {
Multiplication * m = new Multiplication(multOperands, 2, false);
simplifyRationalRationalPower(p1, static_cast<Rational *>((Expression *)p1->operand(0)), static_cast<Rational *>((Expression *)(p1->operand(1)->operand(0))));
replaceWith(m, true);
return immediateSimplify();
return m->immediateSimplify();
}
}
return this;