mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Remove TreeByValue
This commit is contained in:
@@ -124,7 +124,6 @@ objs += $(addprefix poincare/src/,\
|
||||
tree_node.o\
|
||||
tree_pool.o\
|
||||
tree_by_reference.o\
|
||||
tree_by_value.o\
|
||||
trigonometry.o\
|
||||
undefined.o\
|
||||
uninitialized_evaluation_node.o\
|
||||
|
||||
@@ -6,8 +6,8 @@ extern "C" {
|
||||
#include <stdint.h>
|
||||
}
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/tree_by_reference.h>
|
||||
#include <poincare/tree_node.h>
|
||||
#include <poincare/tree_by_value.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Evaluation : public TreeByValue {
|
||||
class Evaluation : public TreeByReference {
|
||||
public:
|
||||
Evaluation();
|
||||
template<class U> explicit operator U() const {
|
||||
@@ -48,13 +48,13 @@ public:
|
||||
return *reinterpret_cast<U *>(const_cast<Evaluation<T> *>(this));
|
||||
}
|
||||
EvaluationNode<T> * node() const {
|
||||
assert(TreeByValue::node() == nullptr || !TreeByValue::node()->isGhost());
|
||||
return static_cast<EvaluationNode<T> *>(TreeByValue::node());
|
||||
assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost());
|
||||
return static_cast<EvaluationNode<T> *>(TreeByReference::node());
|
||||
}
|
||||
|
||||
/* Hierarchy */
|
||||
Evaluation<T> childAtIndex(int i) const {
|
||||
return Evaluation<T>(static_cast<EvaluationNode<T> *>(TreeByValue::childAtIndex(i).node()));
|
||||
return Evaluation<T>(static_cast<EvaluationNode<T> *>(TreeByReference::childAtIndex(i).node()));
|
||||
}
|
||||
typename Poincare::EvaluationNode<T>::Type type() const { return node()->type(); }
|
||||
bool isUndefined() const { return node()->isUndefined(); }
|
||||
@@ -63,7 +63,7 @@ public:
|
||||
std::complex<T> trace() const { return node()->trace(); }
|
||||
std::complex<T> determinant() const { return node()->determinant(); }
|
||||
protected:
|
||||
Evaluation(EvaluationNode<T> * n) : TreeByValue(n) {}
|
||||
Evaluation(EvaluationNode<T> * n) : TreeByReference(n) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef POINCARE_EXPRESSION_REFERENCE_H
|
||||
#define POINCARE_EXPRESSION_REFERENCE_H
|
||||
|
||||
#include <poincare/tree_by_value.h>
|
||||
#include <poincare/tree_by_reference.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <poincare/print_float.h>
|
||||
#include <poincare/expression_node.h>
|
||||
@@ -12,7 +12,7 @@ namespace Poincare {
|
||||
|
||||
class Context;
|
||||
|
||||
class Expression : public TreeByValue {
|
||||
class Expression : public TreeByReference {
|
||||
friend class CosineNode;
|
||||
friend class SineNode;
|
||||
friend class ExpressionNode;
|
||||
@@ -72,8 +72,8 @@ public:
|
||||
|
||||
/* Reference */
|
||||
ExpressionNode * node() const {
|
||||
assert(TreeByValue::node() == nullptr || !TreeByValue::node()->isGhost());
|
||||
return static_cast<ExpressionNode *>(TreeByValue::node());
|
||||
assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost());
|
||||
return static_cast<ExpressionNode *>(TreeByReference::node());
|
||||
}
|
||||
|
||||
/* Hierarchy */
|
||||
@@ -81,7 +81,7 @@ public:
|
||||
return Expression(static_cast<ExpressionNode *>(TreeByReference::parent().node()));
|
||||
}
|
||||
Expression childAtIndex(int i) const {
|
||||
return Expression(static_cast<ExpressionNode *>(TreeByValue::childAtIndex(i).node()));
|
||||
return Expression(static_cast<ExpressionNode *>(TreeByReference::childAtIndex(i).node()));
|
||||
}
|
||||
void setChildrenInPlace(Expression other) { node()->setChildrenInPlace(other); }
|
||||
|
||||
@@ -171,12 +171,12 @@ public:
|
||||
Coordinate2D nextIntersection(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const;
|
||||
|
||||
protected:
|
||||
Expression(const ExpressionNode * n) : TreeByValue(n) {}
|
||||
Expression(const ExpressionNode * n) : TreeByReference(n) {}
|
||||
Expression defaultShallowReduce(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
Expression defaultShallowBeautify(Context & context, Preferences::AngleUnit angleUnit) const;
|
||||
|
||||
private:
|
||||
Expression(int nodeIdentifier) : TreeByValue(nodeIdentifier) {}
|
||||
Expression(int nodeIdentifier) : TreeByReference(nodeIdentifier) {}
|
||||
/* Hierarchy*/
|
||||
void defaultSetChildrenInPlace(Expression other);
|
||||
/* Properties */
|
||||
|
||||
@@ -79,10 +79,10 @@ public:
|
||||
void setDimensions(int rows, int columns);
|
||||
int numberOfRows() const { return node()->numberOfRows(); }
|
||||
int numberOfColumns() const { return node()->numberOfColumns(); }
|
||||
void addChildAtIndexInPlace(TreeByValue t, int index, int currentNumberOfChildren) {
|
||||
void addChildAtIndexInPlace(TreeByReference t, int index, int currentNumberOfChildren) {
|
||||
Expression::addChildAtIndexInPlace(t, index, currentNumberOfChildren);
|
||||
}
|
||||
void addChildrenAsRowInPlace(TreeByValue t, int i);
|
||||
void addChildrenAsRowInPlace(TreeByReference t, int i);
|
||||
Expression matrixChild(int i, int j) { return childAtIndex(i*numberOfColumns()+j); }
|
||||
|
||||
/* Operation on matrix */
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
#ifndef POINCARE_TREE_BY_VALUE_H
|
||||
#define POINCARE_TREE_BY_VALUE_H
|
||||
|
||||
#include "tree_by_reference.h"
|
||||
#include <stdio.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* When looking for information about a child, it must be passed by reference,
|
||||
* else it is copied so it is no longer a child. This is important for instance
|
||||
* in indexOfChild and in replaceChild. */
|
||||
|
||||
class TreeByValue : protected TreeByReference {
|
||||
public:
|
||||
/* Constructors */
|
||||
TreeByValue(const TreeByValue & tr);
|
||||
/* Operators */
|
||||
TreeByValue& operator=(const TreeByValue& tr);
|
||||
|
||||
virtual ~TreeByValue() = default;
|
||||
|
||||
bool isUninitialized() const { return TreeByReference::isUninitialized(); }
|
||||
bool isAllocationFailure() const { return TreeByReference::isAllocationFailure(); }
|
||||
|
||||
TreeNode * node() const { return TreeByReference::node(); }
|
||||
|
||||
/* Hierarchy */
|
||||
int numberOfChildren() const { return TreeByReference::numberOfChildren(); }
|
||||
TreeByValue parent() const { return TreeByValue(TreeByReference::parent()); }
|
||||
TreeByValue childAtIndex(int i) const { return TreeByValue(TreeByReference::childAtIndex(i)); }
|
||||
int indexOfChild(TreeByReference t) const { return TreeByReference::indexOfChild(t); }
|
||||
|
||||
/* Hierarchy operations */
|
||||
// Replace
|
||||
void replaceChildInPlace(TreeByReference oldChild, TreeByValue newChild) {
|
||||
TreeByReference::replaceChildInPlace(oldChild, newChild);
|
||||
}
|
||||
void replaceChildAtIndexInPlace(int oldChildIndex, TreeByValue newChild) {
|
||||
TreeByReference::replaceChildAtIndexInPlace(oldChildIndex, newChild);
|
||||
}
|
||||
void replaceWithInPlace(TreeByReference t) {
|
||||
TreeByReference::replaceWithInPlace(t);
|
||||
}
|
||||
|
||||
// Swap
|
||||
void swapChildrenInPlace(int i, int j) {
|
||||
TreeByReference::swapChildrenInPlace(i, j);
|
||||
}
|
||||
using TreeByReference::identifier;
|
||||
#if POINCARE_TREE_LOG
|
||||
using TreeByReference::log;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
/* Constructor */
|
||||
TreeByValue(TreeByReference t) : TreeByReference(t.node()) {}
|
||||
TreeByValue(const TreeNode * n) : TreeByReference(n) {}
|
||||
|
||||
/* Hierarchy operations */
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Woverloaded-virtual"
|
||||
void addChildAtIndexInPlace(TreeByValue t, int index, int currentNumberOfChildren) {
|
||||
TreeByReference::addChildAtIndexInPlace(t, index, currentNumberOfChildren);
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -101,7 +101,7 @@ void Matrix::setDimensions(int rows, int columns) {
|
||||
setNumberOfColumns(columns);
|
||||
}
|
||||
|
||||
void Matrix::addChildrenAsRowInPlace(TreeByValue t, int i) {
|
||||
void Matrix::addChildrenAsRowInPlace(TreeByReference t, int i) {
|
||||
if (t.isAllocationFailure()) {
|
||||
replaceWithAllocationFailureInPlace(numberOfChildren());
|
||||
return;
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include <poincare/tree_by_value.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
/* Constructors */
|
||||
|
||||
TreeByValue::TreeByValue(const TreeByValue & tr) :
|
||||
TreeByValue(tr.clone()) {}
|
||||
|
||||
/* Operators */
|
||||
TreeByValue& TreeByValue::operator=(const TreeByValue& tr) {
|
||||
TreeByReference t = tr.clone();
|
||||
setTo(t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <poincare/tree_node.h>
|
||||
#include <poincare/tree_by_reference.h>
|
||||
#include <poincare/tree_by_value.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -64,18 +63,6 @@ private:
|
||||
BlobNode * node() const { return static_cast<BlobNode *>(TreeByReference::node()); }
|
||||
};
|
||||
|
||||
|
||||
class BlobByValue : public TreeByValue {
|
||||
public:
|
||||
BlobByValue(int data = 0) : TreeByValue(TreePool::sharedPool()->createTreeNode<BlobNode>()) {
|
||||
node()->setData(data);
|
||||
}
|
||||
int data() { return node()->data(); }
|
||||
private:
|
||||
BlobNode * node() const { return static_cast<BlobNode *>(TreeByValue::node()); }
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -58,16 +58,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PairByValue : public TreeByValue {
|
||||
public:
|
||||
PairByValue(TreeByValue t1, TreeByValue t2) : TreeByValue(TreePool::sharedPool()->createTreeNode<PairNode>()) {
|
||||
replaceChildAtIndexInPlace(0, t1);
|
||||
replaceChildAtIndexInPlace(1, t2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
#include <quiz.h>
|
||||
#include <poincare.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "helpers.h"
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
QUIZ_CASE(tree_by_value_are_discared_after_block) {
|
||||
int initialPoolSize = pool_size();
|
||||
{
|
||||
BlobByValue b(0);
|
||||
assert_pool_size(initialPoolSize+1);
|
||||
}
|
||||
assert_pool_size(initialPoolSize);
|
||||
}
|
||||
|
||||
static void make_temp_blob() {
|
||||
BlobByValue b(5);
|
||||
}
|
||||
QUIZ_CASE(tree_by_value_are_discared_after_function_call) {
|
||||
int initialPoolSize = pool_size();
|
||||
make_temp_blob();
|
||||
assert_pool_size(initialPoolSize);
|
||||
}
|
||||
|
||||
QUIZ_CASE(tree_by_value_can_be_copied) {
|
||||
int initialPoolSize = pool_size();
|
||||
BlobByValue b(123);
|
||||
assert_pool_size(initialPoolSize+1);
|
||||
TreeByValue t = b;
|
||||
assert_pool_size(initialPoolSize + 2);
|
||||
}
|
||||
|
||||
static TreeByValue blob_with_data_3() {
|
||||
return BlobByValue(3);
|
||||
}
|
||||
QUIZ_CASE(tree_by_value_can_be_returned) {
|
||||
int initialPoolSize = pool_size();
|
||||
TreeByValue b = blob_with_data_3();
|
||||
assert_pool_size(initialPoolSize+1);
|
||||
}
|
||||
|
||||
QUIZ_CASE(tree_by_value_allocation_failures) {
|
||||
int initialPoolSize = pool_size();
|
||||
BlobByValue b(1);
|
||||
assert_pool_size(initialPoolSize+1);
|
||||
{
|
||||
BlobByValue array[10000];
|
||||
assert(pool_size() > 1);
|
||||
assert(pool_size() < 10000);
|
||||
}
|
||||
assert_pool_size(initialPoolSize+1);
|
||||
}
|
||||
|
||||
QUIZ_CASE(tree_by_value_deep_copies) {
|
||||
int initialPoolSize = pool_size();
|
||||
BlobByValue b1(1);
|
||||
BlobByValue b2(2);
|
||||
assert_pool_size(initialPoolSize+2);
|
||||
PairByValue p(b1, b2);
|
||||
assert_pool_size(initialPoolSize+5);
|
||||
PairByValue p2 = p;
|
||||
assert_pool_size(initialPoolSize+8);
|
||||
}
|
||||
Reference in New Issue
Block a user