diff --git a/poincare/Makefile b/poincare/Makefile index 4431bdaa6..a2ab91f89 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -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\ diff --git a/poincare/include/poincare/evaluation.h b/poincare/include/poincare/evaluation.h index 6709462a7..f7bdde0e0 100644 --- a/poincare/include/poincare/evaluation.h +++ b/poincare/include/poincare/evaluation.h @@ -6,8 +6,8 @@ extern "C" { #include } #include +#include #include -#include namespace Poincare { @@ -38,7 +38,7 @@ public: }; template -class Evaluation : public TreeByValue { +class Evaluation : public TreeByReference { public: Evaluation(); template explicit operator U() const { @@ -48,13 +48,13 @@ public: return *reinterpret_cast(const_cast *>(this)); } EvaluationNode * node() const { - assert(TreeByValue::node() == nullptr || !TreeByValue::node()->isGhost()); - return static_cast *>(TreeByValue::node()); + assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost()); + return static_cast *>(TreeByReference::node()); } /* Hierarchy */ Evaluation childAtIndex(int i) const { - return Evaluation(static_cast *>(TreeByValue::childAtIndex(i).node())); + return Evaluation(static_cast *>(TreeByReference::childAtIndex(i).node())); } typename Poincare::EvaluationNode::Type type() const { return node()->type(); } bool isUndefined() const { return node()->isUndefined(); } @@ -63,7 +63,7 @@ public: std::complex trace() const { return node()->trace(); } std::complex determinant() const { return node()->determinant(); } protected: - Evaluation(EvaluationNode * n) : TreeByValue(n) {} + Evaluation(EvaluationNode * n) : TreeByReference(n) {} }; } diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index e11a9d787..5b5d5fd78 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -1,7 +1,7 @@ #ifndef POINCARE_EXPRESSION_REFERENCE_H #define POINCARE_EXPRESSION_REFERENCE_H -#include +#include #include #include #include @@ -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(TreeByValue::node()); + assert(TreeByReference::node() == nullptr || !TreeByReference::node()->isGhost()); + return static_cast(TreeByReference::node()); } /* Hierarchy */ @@ -81,7 +81,7 @@ public: return Expression(static_cast(TreeByReference::parent().node())); } Expression childAtIndex(int i) const { - return Expression(static_cast(TreeByValue::childAtIndex(i).node())); + return Expression(static_cast(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 */ diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 9033dfcc6..a645c126d 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -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 */ diff --git a/poincare/include/poincare/tree_by_value.h b/poincare/include/poincare/tree_by_value.h deleted file mode 100644 index b1bcdd514..000000000 --- a/poincare/include/poincare/tree_by_value.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef POINCARE_TREE_BY_VALUE_H -#define POINCARE_TREE_BY_VALUE_H - -#include "tree_by_reference.h" -#include - -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 diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index a99031021..83163c29b 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -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; diff --git a/poincare/src/tree_by_value.cpp b/poincare/src/tree_by_value.cpp deleted file mode 100644 index 9944cbaa4..000000000 --- a/poincare/src/tree_by_value.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include - -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; -} - -} diff --git a/poincare/test/tree/blob_node.h b/poincare/test/tree/blob_node.h index f9ff9411e..07ad6e664 100644 --- a/poincare/test/tree/blob_node.h +++ b/poincare/test/tree/blob_node.h @@ -3,7 +3,6 @@ #include #include -#include namespace Poincare { @@ -64,18 +63,6 @@ private: BlobNode * node() const { return static_cast(TreeByReference::node()); } }; - -class BlobByValue : public TreeByValue { -public: - BlobByValue(int data = 0) : TreeByValue(TreePool::sharedPool()->createTreeNode()) { - node()->setData(data); - } - int data() { return node()->data(); } -private: - BlobNode * node() const { return static_cast(TreeByValue::node()); } -}; - - } #endif diff --git a/poincare/test/tree/pair_node.h b/poincare/test/tree/pair_node.h index 8d48ce211..49e2110a1 100644 --- a/poincare/test/tree/pair_node.h +++ b/poincare/test/tree/pair_node.h @@ -58,16 +58,6 @@ public: } }; - -class PairByValue : public TreeByValue { -public: - PairByValue(TreeByValue t1, TreeByValue t2) : TreeByValue(TreePool::sharedPool()->createTreeNode()) { - replaceChildAtIndexInPlace(0, t1); - replaceChildAtIndexInPlace(1, t2); - } -}; - - } #endif diff --git a/poincare/test/tree/tree_by_value.cpp b/poincare/test/tree/tree_by_value.cpp deleted file mode 100644 index 0b124fb8e..000000000 --- a/poincare/test/tree/tree_by_value.cpp +++ /dev/null @@ -1,65 +0,0 @@ -#include -#include -#include - -#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); -}