mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-20 22:30:30 +01:00
[poincare] Add UntypedBuilder Function and Symbol
UntypedBuilders moreover retrieve Expression value from context.
This commit is contained in:
committed by
Émilie Feral
parent
efde8c6c9e
commit
3bee0f35fa
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user