diff --git a/poincare/include/poincare/function.h b/poincare/include/poincare/function.h index 781324826..c1109f0bd 100644 --- a/poincare/include/poincare/function.h +++ b/poincare/include/poincare/function.h @@ -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); diff --git a/poincare/include/poincare/symbol.h b/poincare/include/poincare/symbol.h index fbe668d84..3c4c93ec4 100644 --- a/poincare/include/poincare/symbol.h +++ b/poincare/include/poincare/symbol.h @@ -67,14 +67,8 @@ public: static Symbol Builder(const char * name, int length) { return SymbolAbstract::Builder(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); diff --git a/poincare/src/function.cpp b/poincare/src/function.cpp index ec7910c85..50ed7e0b2 100644 --- a/poincare/src/function.cpp +++ b/poincare/src/function.cpp @@ -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); diff --git a/poincare/src/symbol.cpp b/poincare/src/symbol.cpp index f4225c05a..0428218eb 100644 --- a/poincare/src/symbol.cpp +++ b/poincare/src/symbol.cpp @@ -139,6 +139,15 @@ Evaluation 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') {