diff --git a/apps/shared/expression_model.cpp b/apps/shared/expression_model.cpp index ea2ef122a..d572d59cb 100644 --- a/apps/shared/expression_model.cpp +++ b/apps/shared/expression_model.cpp @@ -21,7 +21,7 @@ const char * ExpressionModel::text() const { Poincare::Expression ExpressionModel::expression(Poincare::Context * context) const { if (m_expression.isUninitialized()) { - m_expression = PoincareHelpers::ParseAndSimplify(m_text, *context); + m_expression = Expression::parse(m_text); } return m_expression; } diff --git a/apps/shared/storage_expression_model.cpp b/apps/shared/storage_expression_model.cpp index 59f9a8a32..ee64e4154 100644 --- a/apps/shared/storage_expression_model.cpp +++ b/apps/shared/storage_expression_model.cpp @@ -69,11 +69,8 @@ Ion::Storage::Record::ErrorStatus StorageExpressionModel::setContent(const char Expression expressionToStore; // if c = "", we want to reinit the Expression if (c && *c != 0) { - /* We do not want to replace any symbols in the stored expression, so we don't - * need the current context. */ - GlobalContext context; - // Compute the expression to store - expressionToStore = PoincareHelpers::ParseAndSimplify(c, context, false); + // Compute the expression to store, without replacing symbols + expressionToStore = Expression::parse(c); if (!expressionToStore.isUninitialized()) { Symbol xUnknown = Symbol(Symbol::SpecialSymbols::UnknownX); expressionToStore = expressionToStore.replaceSymbolWithExpression(Symbol("x", 1), xUnknown); diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 3dac5e16e..161ff1ed0 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -16,11 +16,11 @@ extern "C" { namespace Poincare { void StoreNode::reduceChildren(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols) { - Expression(this).defaultReduceChildren(context, angleUnit, false); + return; } void StoreNode::deepReduceChildren(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols) { - Expression(this).defaultDeepReduceChildren(context, angleUnit, false); + return; } Expression StoreNode::shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols) { @@ -45,11 +45,8 @@ Evaluation StoreNode::templatedApproximate(Context& context, Preferences::Ang * Otherwise, it would have been replaced by its symbol. We thus have to * setExpressionForSymbol. */ Store s(this); - Expression expressionToStore = s.value().clone().simplify(context, angleUnit, false); - if (expressionToStore.isUninitialized() || expressionToStore.isUndefined()) { - expressionToStore = s.value(); - } - context.setExpressionForSymbol(expressionToStore, s.symbol(), context); + assert(!s.value().isUninitialized()); + context.setExpressionForSymbol(s.value(), s.symbol(), context); Expression e = context.expressionForSymbol(s.symbol()); if (e.isUninitialized()) { return Complex::Undefined(); @@ -69,11 +66,8 @@ Expression Store::shallowReduce(Context & context, Preferences::AngleUnit angleU assert(symbol().type() == ExpressionNode::Type::Symbol); finalValue = childAtIndex(0); } - Expression expressionToStore = finalValue.clone().simplify(context, angleUnit, false); - if (expressionToStore.isUninitialized() || expressionToStore.isUndefined()) { - expressionToStore = finalValue; - } - context.setExpressionForSymbol(expressionToStore, symbol(), context); + assert(!finalValue.isUninitialized()); + context.setExpressionForSymbol(finalValue, symbol(), context); Expression e = context.expressionForSymbol(symbol()); if (e.isUninitialized()) { return Undefined(); diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index 118c5d771..189deb357 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -127,6 +127,8 @@ Expression SymbolNode::replaceReplaceableSymbols(Context & context) { template Evaluation SymbolNode::templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const { Expression e = context.expressionForSymbol(Symbol(this)); + /* Replace all the symbols iteratively. This prevents a memory failure when + * symbols are defined circularly. */ e = Expression::ExpressionWithoutSymbols(e, context); if (e.isUninitialized()) { return Complex::Undefined(); @@ -168,9 +170,9 @@ Expression Symbol::shallowReduce(Context & context, Preferences::AngleUnit angle return *this; } Expression result = context.expressionForSymbol(*this); - // The stored expression is beautified, so we need to call reduce - /* First, replace all the symbols iteratively. This prevents a memory - * failure symbols are defined circularly. */ + /* The stored expression is as entered by the user, so we need to call reduce + * First, replace all the symbols iteratively. This prevents a memory failure + * when symbols are defined circularly. */ result = ExpressionWithoutSymbols(result, context); if (result.isUninitialized()) { return *this;