[poincare/parametered_expression] Use parameter()

This commit is contained in:
Léa Saviot
2020-03-31 12:17:39 +02:00
committed by EmilieNumworks
parent 94fb5815f9
commit 169d6bf94d
2 changed files with 9 additions and 16 deletions

View File

@@ -21,11 +21,9 @@ int ParameteredExpressionNode::getVariables(Context * context, isVariableTest is
}
/* Remove the parameter symbol from the list of variable if it was added at
* the previous line */
// Get the parameter symbol
assert(childAtIndex(ParameteredExpression::ParameterChildIndex())->type() == ExpressionNode::Type::Symbol);
SymbolNode * parameterChild = static_cast<SymbolNode *>(childAtIndex(ParameteredExpression::ParameterChildIndex()));
const char * parameterName = ParameteredExpression(this).parameter().name();
for (int i = nextVariableIndex; i < numberOfVariables; i++) {
if (strcmp(parameterChild->name(), &variables[i]) == 0) {
if (strcmp(parameterName, &variables[i]) == 0) {
variables[i] = 0;
numberOfVariables--;
break;
@@ -46,11 +44,9 @@ int ParameteredExpressionNode::getVariables(Context * context, isVariableTest is
}
Expression ParameteredExpression::replaceSymbolWithExpression(const SymbolAbstract & symbol, const Expression & expression) {
Expression c = childAtIndex(ParameterChildIndex());
assert(c.type() == ExpressionNode::Type::Symbol);
Symbol& parameterChild = static_cast<Symbol &>(c);
if (symbol.type() != ExpressionNode::Type::Symbol ||
strcmp(symbol.name(), parameterChild.name()) != 0) {
if (symbol.type() != ExpressionNode::Type::Symbol
|| !parameter().hasSameNameAs(static_cast<Symbol&>(symbol)))
{
// If the symbol is not the parameter, replace normally
return defaultReplaceSymbolWithExpression(symbol, expression);
}

View File

@@ -173,13 +173,10 @@ Expression Symbol::shallowReduce(ExpressionNode::ReductionContext reductionConte
// The symbol is a paremetered expression's parameter
return *this;
}
if (index == ParameteredExpression::ParameteredChildIndex()) {
assert(p.childAtIndex(ParameteredExpression::ParameterChildIndex()).type() == ExpressionNode::Type::Symbol);
Expression untypedParameter = p.childAtIndex(ParameteredExpression::ParameterChildIndex());
Symbol parameter = static_cast<Symbol &>(untypedParameter);
if (strcmp(parameter.name(), name()) == 0) {
return *this;
}
if (index == ParameteredExpression::ParameteredChildIndex()
&& hasSameNameAs(static_cast<ParameteredExpression&>(p).parameter()))
{
return *this;
}
}
current = p;