[poincare] Clean Symbol

This commit is contained in:
Émilie Feral
2018-11-16 16:34:30 +01:00
parent ac6f7346e0
commit 05083e76af
2 changed files with 12 additions and 11 deletions

View File

@@ -82,6 +82,7 @@ public:
Expression replaceReplaceableSymbols(Context & context);
private:
SymbolNode * node() const { return static_cast<SymbolNode *>(Expression::node()); }
Expression expand(Context & context) const;
};
}

View File

@@ -126,10 +126,7 @@ Expression SymbolNode::replaceReplaceableSymbols(Context & context) {
template<typename T>
Evaluation<T> 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);
Expression e = Symbol(this).expand(context);
if (e.isUninitialized()) {
return Complex<T>::Undefined();
}
@@ -159,8 +156,7 @@ bool Symbol::isRegressionSymbol(const char * c) {
}
bool Symbol::matches(ExpressionTest test, Context & context) const {
Expression e = context.expressionForSymbol(*this);
e = ExpressionWithoutSymbols(e, context);
Expression e = expand(context);
return !e.isUninitialized() && test(e, context, true);
}
@@ -168,15 +164,12 @@ Expression Symbol::shallowReduce(Context & context, Preferences::AngleUnit angle
if (!replaceSymbols) {
return *this;
}
Expression result = context.expressionForSymbol(*this);
/* 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);
Expression result = expand(context);
if (result.isUninitialized()) {
return *this;
}
replaceWithInPlace(result);
// The stored expression is as entered by the user, so we need to call reduce
return result.deepReduce(context, angleUnit);
}
@@ -215,4 +208,11 @@ Expression Symbol::replaceReplaceableSymbols(Context & context) {
return e;
}
Expression Symbol::expand(Context & context) const {
/* Replace all the symbols iteratively. This prevents a memory failure when
* symbols are defined circularly. */
Expression e = context.expressionForSymbol(*this);
return ExpressionWithoutSymbols(e, context);
}
}