diff --git a/poincare/src/simplify/Makefile b/poincare/src/simplify/Makefile index 71f40aaed..15b521f6f 100644 --- a/poincare/src/simplify/Makefile +++ b/poincare/src/simplify/Makefile @@ -9,7 +9,6 @@ $(dir)/rules.cpp: $(RULEGEN) $(dir)/rules.pr products += $(dir)/rules.cpp objs += $(addprefix $(dir)/,\ - contiguous_tree.o\ expression_builder.o\ expression_match.o\ expression_selector.o\ diff --git a/poincare/src/simplify/contiguous_tree.cpp b/poincare/src/simplify/contiguous_tree.cpp deleted file mode 100644 index d432cc03d..000000000 --- a/poincare/src/simplify/contiguous_tree.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "contiguous_tree.h" -extern "C" { -#include -} - -ContiguousTree * ContiguousTree::child(uint8_t index) { - assert(index>=0 && indexchild(index-1); - return previousChild+previousChild->m_numberOfChildren+1; // Pointer arithm. - } -} diff --git a/poincare/src/simplify/contiguous_tree.h b/poincare/src/simplify/contiguous_tree.h deleted file mode 100644 index 6a4896f8d..000000000 --- a/poincare/src/simplify/contiguous_tree.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef POINCARE_SIMPLIFY_CONTIGUOUS_TREE_H -#define POINCARE_SIMPLIFY_CONTIGUOUS_TREE_H - -extern "C" { -#include -} - -class ContiguousTree { -public: - constexpr ContiguousTree(uint8_t numberOfChildren); - ContiguousTree * child(uint8_t i); -protected: - uint8_t m_numberOfChildren; -}; - -constexpr ContiguousTree::ContiguousTree(uint8_t numberOfChildren) : - m_numberOfChildren(numberOfChildren) { -} - -#endif diff --git a/poincare/src/simplify/expression_builder.cpp b/poincare/src/simplify/expression_builder.cpp index ebaa109eb..bab34ca4c 100644 --- a/poincare/src/simplify/expression_builder.cpp +++ b/poincare/src/simplify/expression_builder.cpp @@ -16,7 +16,7 @@ Expression * ExpressionBuilder::build(ExpressionMatch matches[]) { int numberOfChildrenExpressions = 0; for (int i=0; ichild(i); + ExpressionBuilder * child = this->child(i); if (child->m_action == ExpressionBuilder::Action::BringUpWildcard) { for (int j=0; jm_matchIndex].numberOfExpressions(); j++) { children_expressions[numberOfChildrenExpressions++] = @@ -68,3 +68,13 @@ Expression * ExpressionBuilder::build(ExpressionMatch matches[]) { } return result; } + +ExpressionBuilder * ExpressionBuilder::child(int index) { + assert(index>=0 && indexchild(index-1); + return previousChild+previousChild->m_numberOfChildren+1; // Pointer arithm. + } +} diff --git a/poincare/src/simplify/expression_builder.h b/poincare/src/simplify/expression_builder.h index 7b59a9b09..2d2202a6a 100644 --- a/poincare/src/simplify/expression_builder.h +++ b/poincare/src/simplify/expression_builder.h @@ -2,14 +2,12 @@ #define POINCARE_SIMPLIFY_EXPRESSION_BUILDER_H #include -#include "contiguous_tree.h" #include "expression_match.h" extern "C" { #include } - -class ExpressionBuilder : public ContiguousTree { +class ExpressionBuilder { public: static constexpr ExpressionBuilder BuildFromType(Expression::Type type, uint8_t numberOfChildren); static constexpr ExpressionBuilder BuildFromTypeAndValue(Expression::Type type, int32_t value, uint8_t numberOfChildren); @@ -32,9 +30,9 @@ private: constexpr ExpressionBuilder(Expression::Type type, int32_t integerValue, uint8_t numberOfChildren); constexpr ExpressionBuilder(Action action, uint8_t matchIndex, uint8_t numberOfChildren); constexpr ExpressionBuilder(ExternalGenerator * generator, uint8_t numberOfChildren); + ExpressionBuilder * child(int index); Action m_action; - union { // m_action == BuildFromType and BuildFromTypeAndValue struct { @@ -51,6 +49,7 @@ private: // m_action == CallExternalGenerator ExternalGenerator * m_generator; }; + uint8_t m_numberOfChildren; }; /* Since they have to be evaluated at compile time, constexpr functions are @@ -91,27 +90,27 @@ constexpr ExpressionBuilder::ExpressionBuilder(Expression::Type type, int32_t integerValue, uint8_t numberOfChildren) : - ContiguousTree(numberOfChildren), m_action(ExpressionBuilder::Action::BuildFromTypeAndValue), m_expressionType(type), - m_integerValue(integerValue) { + m_integerValue(integerValue), + m_numberOfChildren(numberOfChildren) { } constexpr ExpressionBuilder::ExpressionBuilder(Action action, uint8_t matchIndex, uint8_t numberOfChildren) : - ContiguousTree(numberOfChildren), m_action(action), - m_matchIndex(matchIndex) { + m_matchIndex(matchIndex), + m_numberOfChildren(numberOfChildren) { } constexpr ExpressionBuilder::ExpressionBuilder(ExternalGenerator * generator, uint8_t numberOfChildren) : - ContiguousTree(numberOfChildren), m_action(ExpressionBuilder::Action::CallExternalGenerator), - m_generator(generator) { + m_generator(generator), + m_numberOfChildren(numberOfChildren) { } #endif diff --git a/poincare/src/simplify/expression_selector.cpp b/poincare/src/simplify/expression_selector.cpp index b7477f078..3f84b7751 100644 --- a/poincare/src/simplify/expression_selector.cpp +++ b/poincare/src/simplify/expression_selector.cpp @@ -69,7 +69,7 @@ int ExpressionSelector::match(Expression * e, ExpressionMatch * matches) { matches[numberOfMatches++] = ExpressionMatch(&e, 1); - if (this->m_numberOfChildren != 0) { + if (m_numberOfChildren != 0) { int numberOfChildMatches = 0; if (!e->isCommutative()) { numberOfChildMatches = sequentialMatch(e, matches+numberOfMatches); @@ -292,8 +292,6 @@ bool ExpressionSelector::canCommutativelyMatch(Expression * e, ExpressionMatch * return false; } -// Extrude in a class impossible otherwise ExpressionBuilder is not aggregate -// and cannot be initialized statically ExpressionSelector * ExpressionSelector::child(int index) { assert(index>=0 && index -#include "contiguous_tree.h" #include "expression_match.h" extern "C" { #include } -class ExpressionSelector : public ContiguousTree { +class ExpressionSelector { public: static constexpr ExpressionSelector Any(uint8_t numberOfChildren) { return ExpressionSelector(Match::Any, (Expression::Type)0, 0, numberOfChildren); @@ -23,7 +22,6 @@ public: return ExpressionSelector(Match::TypeAndValue, type, value, numberOfChildren); } - ExpressionSelector * child(int i); /* The match function is interesting * - It returns 0 if the selector didn't match the expression * - Otherwise, it returns the number of captured matches and sets *matches @@ -44,10 +42,10 @@ private: int32_t integerValue, uint8_t numberOfChildren) : - ContiguousTree(numberOfChildren), m_match(match), m_expressionType(type), - m_integerValue(integerValue) + m_integerValue(integerValue), + m_numberOfChildren(numberOfChildren) { } @@ -56,6 +54,7 @@ private: uint8_t * selectorMatched, int leftToMatch); int commutativeMatch(Expression * e, ExpressionMatch * matches); int sequentialMatch(Expression * e, ExpressionMatch * matches); + ExpressionSelector * child(int index); Match m_match; union { @@ -72,6 +71,7 @@ private: }; }; }; + uint8_t m_numberOfChildren; }; #endif