mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Use SymbolAbstract::hasSameNameAs
This commit is contained in:
committed by
EmilieNumworks
parent
169d6bf94d
commit
620ef3f570
@@ -62,7 +62,6 @@ public:
|
||||
|
||||
// Symbol properties
|
||||
bool isSystemSymbol() const { return node()->isUnknown(); }
|
||||
bool hasSameNameAs(Symbol & other) const;
|
||||
const char * name() const { return node()->name(); }
|
||||
// IsVariable tests
|
||||
static bool isSeriesSymbol(const char * c, Poincare::Context * context);
|
||||
|
||||
@@ -66,6 +66,7 @@ class SymbolAbstract : public Expression {
|
||||
friend class SymbolAbstractNode;
|
||||
public:
|
||||
const char * name() const { return node()->name(); }
|
||||
bool hasSameNameAs(const SymbolAbstract & other) const;
|
||||
static size_t TruncateExtension(char * dst, const char * src, size_t len);
|
||||
static bool matches(const SymbolAbstract & symbol, ExpressionTest test, Context * context);
|
||||
constexpr static size_t k_maxNameSize = 8;
|
||||
|
||||
@@ -102,7 +102,7 @@ Function Function::Builder(const char * name, size_t length, Expression child) {
|
||||
Expression Function::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
|
||||
// Replace the symbol in the child
|
||||
childAtIndex(0).replaceSymbolWithExpression(symbol, expression);
|
||||
if (symbol.type() == ExpressionNode::Type::Function && strcmp(name(), symbol.name()) == 0) {
|
||||
if (symbol.type() == ExpressionNode::Type::Function && hasSameNameAs(symbol)) {
|
||||
Expression value = expression.clone();
|
||||
Expression p = parent();
|
||||
if (!p.isUninitialized() && p.node()->childAtIndexNeedsUserParentheses(value, p.indexOfChild(*this))) {
|
||||
|
||||
@@ -44,9 +44,7 @@ int ParameteredExpressionNode::getVariables(Context * context, isVariableTest is
|
||||
}
|
||||
|
||||
Expression ParameteredExpression::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
|
||||
if (symbol.type() != ExpressionNode::Type::Symbol
|
||||
|| !parameter().hasSameNameAs(static_cast<Symbol&>(symbol)))
|
||||
{
|
||||
if (symbol.type() != ExpressionNode::Type::Symbol || !parameter().hasSameNameAs(symbol)) {
|
||||
// If the symbol is not the parameter, replace normally
|
||||
return defaultReplaceSymbolWithExpression(symbol, expression);
|
||||
}
|
||||
|
||||
@@ -134,10 +134,6 @@ Symbol Symbol::Builder(CodePoint name) {
|
||||
return Symbol::Builder(buffer, codePointLength);
|
||||
}
|
||||
|
||||
bool Symbol::hasSameNameAs(Symbol & other) const {
|
||||
return (strcmp(other.name(), name()) == 0);
|
||||
}
|
||||
|
||||
bool Symbol::isSeriesSymbol(const char * c, Poincare::Context * context) {
|
||||
// [NV][1-3]
|
||||
if (c[2] == 0 && (c[0] == 'N' || c[0] == 'V') && c[1] >= '1' && c[1] <= '3') {
|
||||
@@ -197,7 +193,7 @@ Expression Symbol::shallowReduce(ExpressionNode::ReductionContext reductionConte
|
||||
}
|
||||
|
||||
Expression Symbol::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
|
||||
if (symbol.type() == ExpressionNode::Type::Symbol && strcmp(name(), symbol.name()) == 0) {
|
||||
if (symbol.type() == ExpressionNode::Type::Symbol && hasSameNameAs(symbol)) {
|
||||
Expression value = expression.clone();
|
||||
Expression p = parent();
|
||||
if (!p.isUninitialized() && p.node()->childAtIndexNeedsUserParentheses(value, p.indexOfChild(*this))) {
|
||||
|
||||
@@ -53,6 +53,10 @@ T SymbolAbstract::Builder(const char * name, int length) {
|
||||
return static_cast<T &>(h);
|
||||
}
|
||||
|
||||
bool SymbolAbstract::hasSameNameAs(const SymbolAbstract & other) const {
|
||||
return strcmp(other.name(), name()) == 0;
|
||||
}
|
||||
|
||||
size_t SymbolAbstract::TruncateExtension(char * dst, const char * src, size_t len) {
|
||||
return UTF8Helper::CopyUntilCodePoint(dst, len, src, '.');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user