From 95c72358315ea3100fca6d00a9aab93bfd1b9dc2 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Tue, 19 Nov 2019 10:59:54 +0100 Subject: [PATCH] [poincare] Align implementation of shallowReduce in Symbol and Function --- poincare/src/function.cpp | 18 +++++++++--------- poincare/src/symbol.cpp | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index 706bad731..e222c4e16 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -112,16 +112,16 @@ Expression Function::replaceSymbolWithExpression(const SymbolAbstract & symbol, } Expression Function::shallowReduce(ExpressionNode::ReductionContext reductionContext) { - Function f(*this); - Expression e = SymbolAbstract::Expand(f, reductionContext.context(), true); - if (!e.isUninitialized()) { - replaceWithInPlace(e); - return e.deepReduce(reductionContext); + Expression result = SymbolAbstract::Expand(*this, reductionContext.context(), true); + if (result.isUninitialized()) { + if (reductionContext.symbolicComputation()) { + return *this; + } + result = Undefined::Builder(); } - if (!reductionContext.symbolicComputation()) { - return replaceWithUndefinedInPlace(); - } - return *this; + replaceWithInPlace(result); + // The stored expression is as entered by the user, so we need to call reduce + return result.deepReduce(reductionContext); } Expression Function::deepReplaceReplaceableSymbols(Context * context, bool * didReplace) { diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index aad298986..1ac631ffe 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -175,8 +175,7 @@ Expression Symbol::shallowReduce(ExpressionNode::ReductionContext reductionConte } } - Symbol s = *this; - Expression result = SymbolAbstract::Expand(s, reductionContext.context(), true); + Expression result = SymbolAbstract::Expand(*this, reductionContext.context(), true); if (result.isUninitialized()) { if (reductionContext.symbolicComputation()) { return *this;