[poincare] Un-inline Symbol and Function UntypedBuilder

This commit is contained in:
Émilie Feral
2019-02-21 10:47:39 +01:00
committed by LeaNumworks
parent 24c9617a89
commit 8ca4094e13
4 changed files with 22 additions and 17 deletions

View File

@@ -53,15 +53,7 @@ friend class FunctionNode;
public:
Function(const FunctionNode * n) : SymbolAbstract(n) {}
static Function Builder(const char * name, size_t length, Expression child = Expression());
static Expression UntypedBuilder(const char * name, size_t length, Expression child, Context * context) {
/* Create an expression only if it is not in the context or defined as a
* function */
Function f = Function::Builder(name, length, child);
if (SymbolAbstract::ValidInContext(f, context)) {
return f;
}
return Expression();
}
static Expression UntypedBuilder(const char * name, size_t length, Expression child, Context * context);
// Simplification
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);

View File

@@ -67,14 +67,8 @@ public:
static Symbol Builder(const char * name, int length) { return SymbolAbstract::Builder<Symbol, SymbolNode>(name, length); }
static Symbol Builder(char name) { return Symbol::Builder(&name, 1); }
static Symbol Ans() { return Symbol::Builder(k_ans, k_ansLength); }
static Expression UntypedBuilder(const char * name, size_t length, Context * context) {
// create an expression only if it is not in the context or defined as a symbol
Symbol s = Symbol::Builder(name, length);
if (SymbolAbstract::ValidInContext(s, context)) {
return s;
}
return Expression();
}
static Expression UntypedBuilder(const char * name, size_t length, Context * context);
// Symbol properties
bool isSystemSymbol() const { return name()[0] == SpecialSymbols::UnknownX && name()[1] == 0; }
static bool isSeriesSymbol(const char * c);

View File

@@ -100,6 +100,16 @@ Function Function::Builder(const char * name, size_t length, Expression child) {
return f;
}
Expression Function::UntypedBuilder(const char * name, size_t length, Expression child, Context * context) {
/* Create an expression only if it is not in the context or defined as a
* function */
Function f = Function::Builder(name, length, child);
if (SymbolAbstract::ValidInContext(f, context)) {
return f;
}
return Expression();
}
Expression Function::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
// Replace the symbol in the child
childAtIndex(0).replaceSymbolWithExpression(symbol, expression);

View File

@@ -139,6 +139,15 @@ Evaluation<T> SymbolNode::templatedApproximate(Context& context, Preferences::Co
return e.node()->approximate(T(), context, complexFormat, angleUnit);
}
Expression Symbol::UntypedBuilder(const char * name, size_t length, Context * context) {
// create an expression only if it is not in the context or defined as a symbol
Symbol s = Symbol::Builder(name, length);
if (SymbolAbstract::ValidInContext(s, context)) {
return s;
}
return Expression();
}
bool Symbol::isSeriesSymbol(const char * c) {
// [NV][1-3]
if (c[2] == 0 && (c[0] == 'N' || c[0] == 'V') && c[1] >= '1' && c[1] <= '3') {