[poincare] Add UntypedBuilder Function and Symbol

UntypedBuilders moreover retrieve Expression value from context.
This commit is contained in:
Ruben Dashyan
2018-11-02 18:15:07 +01:00
committed by Émilie Feral
parent efde8c6c9e
commit 3bee0f35fa
3 changed files with 22 additions and 0 deletions

View File

@@ -51,6 +51,15 @@ public:
Function(const char * name, size_t length, Expression child) : Function(name, length) {
replaceChildAtIndexInPlace(0, child);
}
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(name, length, child);
if (SymbolAbstract::ValidInContext(f, context)) {
return f;
}
return Expression();
}
Expression replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression);
Expression shallowReduce(Context & context, Preferences::AngleUnit angleUnit, bool replaceSymbols = true);

View File

@@ -57,6 +57,14 @@ public:
Symbol(char name);
Symbol(const SymbolNode * node) : SymbolAbstract(node) {}
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(name, length);
if (SymbolAbstract::ValidInContext(s, context)) {
return s;
}
return Expression();
}
// Symbol properties
static bool isSeriesSymbol(const char * c);
static bool isRegressionSymbol(const char * c);

View File

@@ -56,6 +56,11 @@ class SymbolAbstract : public Expression {
public:
const char * name() const { return node()->name(); }
static size_t TruncateExtension(char * dst, const char * src, size_t len);
static bool ValidInContext(SymbolAbstract & s, Context * context) {
// Retrive from context the expression corresponding to s
Expression f = context ? context->expressionForSymbol(s) : Expression();
return f.isUninitialized() || f.type() == s.type();
}
constexpr static size_t k_maxNameSize = 8;
protected:
SymbolAbstract(const SymbolAbstractNode * node) : Expression(node) {}