From fa0ed41ea40549b39f99bdcd96d23b99475ba941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 7 Aug 2018 15:45:21 +0200 Subject: [PATCH] [poincare] Fix evaluation --- .../poincare/allocation_failed_evaluation.h | 13 +++---------- poincare/include/poincare/complex.h | 19 +++++++++---------- poincare/include/poincare/evaluation.h | 2 +- .../include/poincare/serializable_reference.h | 4 +--- poincare/include/poincare/tree_by_value.h | 1 + poincare/src/allocation_failed_evaluation.cpp | 6 +++--- poincare/src/evaluation.cpp | 4 ++-- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/poincare/include/poincare/allocation_failed_evaluation.h b/poincare/include/poincare/allocation_failed_evaluation.h index dd41570cf..5683f39d0 100644 --- a/poincare/include/poincare/allocation_failed_evaluation.h +++ b/poincare/include/poincare/allocation_failed_evaluation.h @@ -13,11 +13,11 @@ public: typename EvaluationNode::Type type() const override { return EvaluationNode::Type::AllocationFailure; } bool isUndefined() const override { return true; } T toScalar() const override{ return NAN; } - ExpressionReference complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const override; + Expression complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const override; std::complex trace() const override { return std::complex(NAN); } std::complex determinant() const override { return std::complex(NAN); } - EvaluationReference inverse() const override { return ComplexReference::Undefined(); } - virtual EvaluationReference transpose() const override { return ComplexReference::Undefined(); } + Evaluation inverse() const override { return Complex::Undefined(); } + virtual Evaluation transpose() const override { return Complex::Undefined(); } // TreeNode size_t size() const override { return sizeof(AllocationFailedEvaluationNode); } #if TREE_LOG @@ -26,13 +26,6 @@ public: bool isAllocationFailure() const override { return true; } }; -template -class AllocationFailedEvaluationReference : public EvaluationReference { -public: - AllocationFailedEvaluationReference() : EvaluationReference(TreePool::sharedPool()->createTreeNode >(), true) {} - AllocationFailedEvaluationReference(TreeNode * n) : EvaluationReference(n) {} -}; - } #endif diff --git a/poincare/include/poincare/complex.h b/poincare/include/poincare/complex.h index f002898a9..0ff9dd302 100644 --- a/poincare/include/poincare/complex.h +++ b/poincare/include/poincare/complex.h @@ -6,7 +6,7 @@ namespace Poincare { template -class ComplexReference; +class Complex; template class ComplexNode : public std::complex, public EvaluationNode { @@ -24,21 +24,20 @@ public: return (std::isnan(this->real()) && std::isnan(this->imag())); } T toScalar() const override; - ExpressionReference complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const override; + Expression complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const override; std::complex trace() const override { return *this; } std::complex determinant() const override { return *this; } - EvaluationReference inverse() const override; - EvaluationReference transpose() const override { return ComplexReference(*this); } + Evaluation inverse() const override; + Evaluation transpose() const override { return Complex(*this); } }; template -class ComplexReference : public std::complex, public EvaluationReference { +class Complex : public std::complex, public Evaluation { public: - ComplexReference(TreeNode * t) : EvaluationReference(t) {} - ComplexReference(T a, T b = 0.0) : ComplexReference(std::complex(a, b)) {} - ComplexReference(std::complex c); - static ComplexReference Undefined() { - return ComplexReference(NAN, NAN); + Complex(T a, T b = 0.0) : Complex(std::complex(a, b)) {} + Complex(std::complex c); + static Complex Undefined() { + return Complex(NAN, NAN); } }; diff --git a/poincare/include/poincare/evaluation.h b/poincare/include/poincare/evaluation.h index 64a2a6e52..700e863d4 100644 --- a/poincare/include/poincare/evaluation.h +++ b/poincare/include/poincare/evaluation.h @@ -42,7 +42,6 @@ public: template class Evaluation : public TreeByValue { public: - //Evaluation(TreeNode * n, bool isCreatingNode = false) : TreeByValue(n, isCreatingNode) {} EvaluationNode * node() const override { assert(!TreeByValue::node().isGhost()); return static_cast *>(TreeByValue::node()); @@ -56,6 +55,7 @@ public: Evaluation inverse() const { return node()->inverse(); } Evaluation transpose() const { return node()->transpose(); } protected: + //Evaluation(EvaluationNode * n) : TreeByValue(n) {} //Evaluation() : TreeByValue() {} }; diff --git a/poincare/include/poincare/serializable_reference.h b/poincare/include/poincare/serializable_reference.h index 5716f2625..9c8271fb5 100644 --- a/poincare/include/poincare/serializable_reference.h +++ b/poincare/include/poincare/serializable_reference.h @@ -9,8 +9,6 @@ namespace Poincare { class SerializableReference : virtual public TreeByReference { public: - using TreeByReference::TreeByReference; - SerializableNode * node() const override { return static_cast(TreeByReference::node()); } // Serialization bool needsParenthesisWithParent(SerializableReference parentRef) { @@ -25,7 +23,7 @@ public: // Tree SerializableReference serializableChildAtIndex(int i) { TreeByReference treeRefChild = TreeByReference::treeChildAtIndex(i); - return SerializableReference(treeRefChild.node()); + return SerializableReference(static_cast(treeRefChild.node())); } protected: SerializableReference(SerializableNode * n) : TreeByReference(n) {} diff --git a/poincare/include/poincare/tree_by_value.h b/poincare/include/poincare/tree_by_value.h index f328c13f8..f048e2ba9 100644 --- a/poincare/include/poincare/tree_by_value.h +++ b/poincare/include/poincare/tree_by_value.h @@ -33,6 +33,7 @@ public: protected: /* Constructor */ TreeByValue(TreeByReference t) : TreeByReference(node()) {} + TreeByValue(TreeNode * n) : TreeByReference(n) {} /* Hierarchy operations */ // Add diff --git a/poincare/src/allocation_failed_evaluation.cpp b/poincare/src/allocation_failed_evaluation.cpp index 1d3e40c01..da4e4af05 100644 --- a/poincare/src/allocation_failed_evaluation.cpp +++ b/poincare/src/allocation_failed_evaluation.cpp @@ -1,12 +1,12 @@ #include -#include +#include #include namespace Poincare { template -ExpressionReference AllocationFailedEvaluationNode::complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const { - return UndefinedReference(); +Expression AllocationFailedEvaluationNode::complexToExpression(Preferences::Preferences::ComplexFormat complexFormat) const { + return Undefined(); } } diff --git a/poincare/src/evaluation.cpp b/poincare/src/evaluation.cpp index 295288d90..2998e22b6 100644 --- a/poincare/src/evaluation.cpp +++ b/poincare/src/evaluation.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include namespace Poincare { @@ -12,7 +12,7 @@ TreeNode * EvaluationNode::FailedAllocationStaticNode() { } template -ExpressionReference EvaluationReference::complexToExpression(Preferences::ComplexFormat complexFormat) const { +Expression Evaluation::complexToExpression(Preferences::ComplexFormat complexFormat) const { return node()->complexToExpression(complexFormat); }