[poincare] When building hierarchical expression, give a parent to

children

Change-Id: Ibeadbe98dc1ecde29be3b3c5e5d1cc9537c3c38a
This commit is contained in:
Émilie Feral
2017-09-29 16:33:39 +02:00
parent 29f10251a1
commit 0a6ff2edb0
7 changed files with 6 additions and 20 deletions

View File

@@ -150,7 +150,6 @@ private:
/* Evaluation Engine */
virtual Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const = 0;
virtual Evaluation<double> * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const = 0;
void recursivelySetAsParentOfChildren();
private:
Expression * m_parent;
};

View File

@@ -12,7 +12,7 @@ class Complex;
class MatrixData {
public:
MatrixData(ListData * listData, bool clone);
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfRows, int m_numberOfColumns, bool cloneOperands);
MatrixData(Expression ** newOperands, int numberOfOperands, int m_numberOfRows, int m_numberOfColumns, bool cloneOperands, Expression * parent);
~MatrixData();
MatrixData(const MatrixData& other) = delete;
MatrixData(MatrixData&& other) = delete;

View File

@@ -21,6 +21,7 @@ ComplexMatrix<T>::ComplexMatrix(const Complex<T> * complexes, int numberOfRows,
m_values = new Complex<T>[numberOfRows*numberOfColumns];
for (int i = 0; i < numberOfRows*numberOfColumns; i++) {
m_values[i] = complexes[i];
m_values[i].setParent(this);
}
}

View File

@@ -32,9 +32,6 @@ Expression * Expression::parse(char const * string) {
}
poincare_expression_yy_delete_buffer(buf);
if (expression) {
expression->recursivelySetAsParentOfChildren();
}
return expression;
}
@@ -152,18 +149,6 @@ template<typename T> T Expression::epsilon() {
return epsilon;
}
void Expression::recursivelySetAsParentOfChildren() {
if (this->type() == Type::Complex) {
// TODO: this case should be useless once complex is a leaf expression!
return;
}
for (int i=0; i<numberOfOperands(); i++) {
Expression * child = const_cast<Expression *>(operand(i));
child->setParent(this);
child->recursivelySetAsParentOfChildren();
}
}
}
template Poincare::Evaluation<double> * Poincare::Expression::evaluate<double>(Context& context, AngleUnit angleUnit) const;

View File

@@ -18,7 +18,7 @@ ExpressionMatrix::ExpressionMatrix(MatrixData * matrixData) :
ExpressionMatrix::ExpressionMatrix(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands)
{
m_matrixData = new MatrixData(newOperands, numberOfOperands, numberOfRows, numberOfColumns, cloneOperands);
m_matrixData = new MatrixData(newOperands, numberOfOperands, numberOfRows, numberOfColumns, cloneOperands, this);
}
ExpressionMatrix::~ExpressionMatrix() {

View File

@@ -23,7 +23,7 @@ MatrixData::MatrixData(ListData * listData, bool clone) :
}
}
MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands) :
MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands, Expression * parent) :
m_numberOfRows(numberOfRows),
m_numberOfColumns(numberOfColumns)
{
@@ -35,6 +35,7 @@ MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numb
} else {
m_operands[i] = i < numberOfOperands ? newOperands[i] : defaultExpression();
}
const_cast<Expression *>(m_operands[i])->setParent(parent);
}
}

View File

@@ -44,12 +44,12 @@ void StaticHierarchy<T>::build(const Expression * const * operands, int numberOf
assert(numberOfOperands <= T);
for (int i=0; i < numberOfOperands; i++) {
assert(operands[i] != nullptr);
const_cast<Expression *>(operands[i])->setParent(this);
if (cloneOperands) {
m_operands[i] = operands[i]->clone();
} else {
m_operands[i] = operands[i];
}
const_cast<Expression *>(m_operands[i])->setParent(this);
}
}