From 7146eff7ee2967155c6238d81a56adf819b9f8c2 Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Tue, 22 Dec 2020 13:05:40 +0100 Subject: [PATCH] [poincare/src] Use reduce before removeUnit With deepReduce(), when a simplifiaction was interrupted, expression could contain Undefined children, which would trigger the assert in removeUnit(). With reduce(), if a simplification is interrupted, the entire expression becomes Undefined, which is handled by removeUnits(). --- poincare/src/multiplication.cpp | 6 +++--- poincare/src/unit_convert.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 29f9860fc..1be7fa526 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -425,8 +425,8 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext * re Expression units; /* removeUnit has to be called on reduced expression but we want to modify * the least the expression so we use the uninvasive reduction context. */ - self = deepReduce(ExpressionNode::ReductionContext::NonInvasiveReductionContext(*reductionContext)); - self = removeUnit(&units); + self = self.reduce(ExpressionNode::ReductionContext::NonInvasiveReductionContext(*reductionContext)); + self = self.removeUnit(&units); if (self.isUndefined() || units.isUninitialized()) { // TODO: handle error "Invalid unit" @@ -501,7 +501,7 @@ Expression Multiplication::shallowBeautify(ExpressionNode::ReductionContext * re // Apply simplifications if (unitsAccu.numberOfChildren() > 0) { // Divide by derived units - units = Division::Builder(units, unitsAccu.clone()).deepReduce(*reductionContext); + units = Division::Builder(units, unitsAccu.clone()).reduce(*reductionContext); Expression newUnits; // Separate units and generated values units = units.removeUnit(&newUnits); diff --git a/poincare/src/unit_convert.cpp b/poincare/src/unit_convert.cpp index 86252bda4..76b384a16 100644 --- a/poincare/src/unit_convert.cpp +++ b/poincare/src/unit_convert.cpp @@ -50,7 +50,7 @@ void UnitConvert::deepReduceChildren(ExpressionNode::ReductionContext reductionC reductionContext.target(), ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithUndefined, ExpressionNode::UnitConversion::None); - // Don't transform the targetted unit + // Don't transform the targeted unit childAtIndex(1).deepReduce(reductionContextKeepUnitAsIs); } @@ -77,7 +77,7 @@ Expression UnitConvert::shallowBeautify(ExpressionNode::ReductionContext * reduc reductionContext->target(), ExpressionNode::SymbolicComputation::ReplaceAllSymbolsWithUndefined); Expression unit; - Expression childWithoutUnit = childAtIndex(1).clone().deepReduce(reductionContextWithUnits).removeUnit(&unit); + Expression childWithoutUnit = childAtIndex(1).clone().reduce(reductionContextWithUnits).removeUnit(&unit); if (childWithoutUnit.isUndefined() || unit.isUninitialized()) { // There is no unit on the right return replaceWithUndefinedInPlace(); @@ -104,7 +104,7 @@ Expression UnitConvert::shallowBeautify(ExpressionNode::ReductionContext * reduc // Divide the left member by the new unit Expression division = Division::Builder(childAtIndex(0), unit.clone()); - division = division.deepReduce(*reductionContext); + division = division.reduce(*reductionContext); Expression divisionUnit; division = division.removeUnit(&divisionUnit); if (!divisionUnit.isUninitialized()) {