[poincare] Add an assertion in deepReduce/ deepBeautify, this must have

a parent

Change-Id: Ia23be0c62734811923133793dd5bee0859b64ca8
This commit is contained in:
Émilie Feral
2017-11-06 10:32:38 +01:00
parent f0af91321a
commit b1567cf9f3
2 changed files with 6 additions and 4 deletions

View File

@@ -126,18 +126,19 @@ void Expression::Simplify(Expression ** expressionAddress, Context & context, An
angleUnit = Preferences::sharedPreferences()->angleUnit();
}
SimplificationRoot root(*expressionAddress);
root.deepReduce(context, angleUnit);
root.deepBeautify(context, angleUnit);
root.editableOperand(0)->deepReduce(context, angleUnit);
root.editableOperand(0)->deepBeautify(context, angleUnit);
*expressionAddress = root.editableOperand(0);
}
void Expression::Reduce(Expression ** expressionAddress, Context & context, AngleUnit angleUnit) {
SimplificationRoot root(*expressionAddress);
root.deepReduce(context, angleUnit);
root.editableOperand(0)->deepReduce(context, angleUnit);
*expressionAddress = root.editableOperand(0);
}
Expression * Expression::deepReduce(Context & context, AngleUnit angleUnit) {
assert(parent() != nullptr);
for (int i = 0; i < numberOfOperands(); i++) {
if ((editableOperand(i))->deepReduce(context, angleUnit)->type() == Type::Undefined && this->type() != Type::SimplificationRoot) {
return replaceWith(new Undefined(), true);
@@ -147,6 +148,7 @@ Expression * Expression::deepReduce(Context & context, AngleUnit angleUnit) {
}
Expression * Expression::deepBeautify(Context & context, AngleUnit angleUnit) {
assert(parent() != nullptr);
Expression * e = shallowBeautify(context, angleUnit);
for (int i = 0; i < e->numberOfOperands(); i++) {
e->editableOperand(i)->deepBeautify(context, angleUnit);

View File

@@ -44,7 +44,7 @@ void Hierarchy::replaceOperand(const Expression * oldOperand, Expression * newOp
Expression ** op = const_cast<Expression **>(operands());
for (int i=0; i<numberOfOperands(); i++) {
if (op[i] == oldOperand) {
if (oldOperand != nullptr) {
if (oldOperand != nullptr && oldOperand->parent() == this) {
const_cast<Expression *>(oldOperand)->setParent(nullptr);
}
if (deleteOldOperand) {