diff --git a/poincare/Makefile b/poincare/Makefile index 8aadb48bb..712e03e31 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -20,8 +20,15 @@ objs += $(addprefix poincare/src/,\ left_parenthesis_layout_node.o\ left_square_bracket_layout_node.o\ matrix_layout_node.o\ + nth_root_layout_node.o\ + parenthesis_layout_node.o\ + product_layout_node.o\ right_parenthesis_layout_node.o\ right_square_bracket_layout_node.o\ + sequence_layout_node.o\ + square_bracket_layout_node.o\ + sum_layout_node.o\ + vertical_offset_layout_node.o\ ) objs += $(addprefix poincare/src/,\ diff --git a/poincare/include/poincare/layout_reference.h b/poincare/include/poincare/layout_reference.h index 54a4eb180..fa20e7bd1 100644 --- a/poincare/include/poincare/layout_reference.h +++ b/poincare/include/poincare/layout_reference.h @@ -12,6 +12,7 @@ class LayoutReference : public TreeByReference { friend class GridLayoutNode; friend class HorizontalLayoutNode; friend class LayoutCursor; + friend class VerticalOffsetLayoutNode; public: using TreeByReference::operator==; using TreeByReference::operator!=; diff --git a/poincare/include/poincare/left_square_bracket_layout_node.h b/poincare/include/poincare/left_square_bracket_layout_node.h index ee3e17342..a75d66e9c 100644 --- a/poincare/include/poincare/left_square_bracket_layout_node.h +++ b/poincare/include/poincare/left_square_bracket_layout_node.h @@ -17,7 +17,8 @@ public: // TreeNode static LeftSquareBracketLayoutNode * FailedAllocationStaticNode(); - LeftSquareBracketLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); } size_t size() const override { return sizeof(LeftSquareBracketLayoutNode); } + LeftSquareBracketLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); } + size_t size() const override { return sizeof(LeftSquareBracketLayoutNode); } #if TREE_LOG const char * description() const override { return "LeftSquareBracketLayout"; } #endif diff --git a/poincare/include/poincare/matrix_layout_node.h b/poincare/include/poincare/matrix_layout_node.h index 26ee52a62..160153d87 100644 --- a/poincare/include/poincare/matrix_layout_node.h +++ b/poincare/include/poincare/matrix_layout_node.h @@ -74,7 +74,7 @@ public: addChildAtIndexInPlace(l4, 3, 3); setDimensions(2, 2); } - bool hasGreySquares() const { node()->hasGreySquares(); } + bool hasGreySquares() const { return node()->hasGreySquares(); } void addGreySquares() { node()->addGreySquares(); } void removeGreySquares() { node()->removeGreySquares(); } void setDimensions(int rows, int columns); diff --git a/poincare/include/poincare/nth_root_layout_node.h b/poincare/include/poincare/nth_root_layout_node.h index 104d928d3..cb4c6b12f 100644 --- a/poincare/include/poincare/nth_root_layout_node.h +++ b/poincare/include/poincare/nth_root_layout_node.h @@ -31,6 +31,8 @@ public: bool hasUpperLeftIndex() const override { return m_hasIndex; } // TreeNode + static NthRootLayoutNode * FailedAllocationStaticNode(); + NthRootLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); } size_t size() const override { return sizeof(NthRootLayoutNode); } int numberOfChildren() const override { return m_hasIndex ? 2 : 1; } #if TREE_LOG @@ -72,10 +74,8 @@ public: NthRootLayoutRef(LayoutRef radicand, LayoutRef index) : NthRootLayoutRef() { replaceChildAtIndexInPlace(0, radicand); - addChildTreeAtIndex(index, 1, 1); - if (!node()->isAllocationFailure()) { - static_cast(node())->setNumberOfChildren(2); - } + addChildAtIndexInPlace(index, 1, 1); + static_cast(node())->setNumberOfChildren(2); } private: diff --git a/poincare/include/poincare/product_layout_node.h b/poincare/include/poincare/product_layout_node.h index 7f7a762c8..f5b4ca7ba 100644 --- a/poincare/include/poincare/product_layout_node.h +++ b/poincare/include/poincare/product_layout_node.h @@ -10,6 +10,8 @@ class ProductLayoutNode : public SequenceLayoutNode { public: using SequenceLayoutNode::SequenceLayoutNode; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + static ProductLayoutNode * FailedAllocationStaticNode(); + ProductLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); } size_t size() const override { return sizeof(ProductLayoutNode); } #if TREE_LOG const char * description() const override { return "ProductLayout"; } diff --git a/poincare/include/poincare/sum_layout_node.h b/poincare/include/poincare/sum_layout_node.h index af5edc950..7c6276902 100644 --- a/poincare/include/poincare/sum_layout_node.h +++ b/poincare/include/poincare/sum_layout_node.h @@ -10,6 +10,8 @@ class SumLayoutNode : public SequenceLayoutNode { public: using SequenceLayoutNode::SequenceLayoutNode; int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override; + static SumLayoutNode * FailedAllocationStaticNode(); + SumLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); } private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override; }; diff --git a/poincare/src/nth_root_layout_node.cpp b/poincare/src/nth_root_layout_node.cpp index 880ac9890..d4e17bd29 100644 --- a/poincare/src/nth_root_layout_node.cpp +++ b/poincare/src/nth_root_layout_node.cpp @@ -1,5 +1,7 @@ #include +#include #include +#include #include #include @@ -18,6 +20,12 @@ const uint8_t radixPixel[NthRootLayoutNode::k_leftRadixHeight][NthRootLayoutNode {0xFF, 0xFF, 0xFF, 0xFF, 0x00}, }; +NthRootLayoutNode * NthRootLayoutNode::FailedAllocationStaticNode() { + static AllocationFailureLayoutNode failure; + TreePool::sharedPool()->registerStaticNodeIfRequired(&failure); + return &failure; +} + void NthRootLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { if (radicandLayout() && cursor->layoutNode() == radicandLayout() @@ -162,11 +170,11 @@ int NthRootLayoutNode::serialize(char * buffer, int bufferSize, Preferences::Pri && (const_cast(this))->indexLayout() && !(const_cast(this))->indexLayout()->isEmpty()) { - return SerializationHelper::Prefix(SerializableRef(this), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "root"); + return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "root"); } // Case: squareRoot(x) if (!m_hasIndex) { - return SerializationHelper::Prefix(SerializableRef(this), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "\x91"); + return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "\x91"); } // Case: root(x,empty) // Write "'SquareRootSymbol'('radicandLayout')". diff --git a/poincare/src/product_layout_node.cpp b/poincare/src/product_layout_node.cpp index f1e6a4060..2ff2e766d 100644 --- a/poincare/src/product_layout_node.cpp +++ b/poincare/src/product_layout_node.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,6 +7,12 @@ namespace Poincare { static inline KDCoordinate max(KDCoordinate x, KDCoordinate y) { return x > y ? x : y; } +ProductLayoutNode * ProductLayoutNode::FailedAllocationStaticNode() { + static AllocationFailureLayoutNode failure; + TreePool::sharedPool()->registerStaticNodeIfRequired(&failure); + return &failure; +} + int ProductLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return SequenceLayoutNode::writeDerivedClassInBuffer("product", buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); } diff --git a/poincare/src/sequence_layout_node.cpp b/poincare/src/sequence_layout_node.cpp index bb450a381..fa94feb65 100644 --- a/poincare/src/sequence_layout_node.cpp +++ b/poincare/src/sequence_layout_node.cpp @@ -13,8 +13,8 @@ constexpr char SequenceLayoutNode::k_nEquals[]; void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldRecomputeLayout) { if (cursor->position() == LayoutCursor::Position::Left - && ((lowerBoundLayout() && cursor->layoutReference() == lowerBoundLayout()) - || (upperBoundLayout() && cursor->layoutReference() == upperBoundLayout()))) + && ((lowerBoundLayout() && cursor->layoutNode() == lowerBoundLayout()) + || (upperBoundLayout() && cursor->layoutNode() == upperBoundLayout()))) { // Case: Left of the bounds. Go Left of the sequence. cursor->setLayoutNode(this); @@ -22,7 +22,7 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco } if (cursor->position() == LayoutCursor::Position::Left && argumentLayout() - && cursor->layoutReference() == argumentLayout()) + && cursor->layoutNode() == argumentLayout()) { // Case: Left of the argument. Go Right of the lower bound. assert(lowerBoundLayout() != nullptr); @@ -30,7 +30,7 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco cursor->setPosition(LayoutCursor::Position::Right); return; } - assert(cursor->layoutReference() == this); + assert(cursor->layoutNode() == this); if (cursor->position() == LayoutCursor::Position::Right) { // Case: Right. Go to the argument and move Left. assert(argumentLayout() != nullptr); @@ -48,8 +48,8 @@ void SequenceLayoutNode::moveCursorLeft(LayoutCursor * cursor, bool * shouldReco void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRecomputeLayout) { if (cursor->position() == LayoutCursor::Position::Right - && ((lowerBoundLayout() && cursor->layoutReference() == lowerBoundLayout()) - || (upperBoundLayout() && cursor->layoutReference() == upperBoundLayout()))) + && ((lowerBoundLayout() && cursor->layoutNode() == lowerBoundLayout()) + || (upperBoundLayout() && cursor->layoutNode() == upperBoundLayout()))) { // Case: Right of the bounds. Go Left of the argument. assert(argumentLayout() != nullptr); @@ -59,13 +59,13 @@ void SequenceLayoutNode::moveCursorRight(LayoutCursor * cursor, bool * shouldRec } if (cursor->position() == LayoutCursor::Position::Right && argumentLayout() - && cursor->layoutReference() == argumentLayout()) + && cursor->layoutNode() == argumentLayout()) { // Case: Right of the argument. Go Right. cursor->setLayoutNode(this); return; } - assert(cursor->layoutReference() == this); + assert(cursor->layoutNode() == this); if (cursor->position() == LayoutCursor::Position::Left) { // Case: Left. Go to the upper bound assert(upperBoundLayout() != nullptr); diff --git a/poincare/src/sum_layout_node.cpp b/poincare/src/sum_layout_node.cpp index b9186029a..17149032d 100644 --- a/poincare/src/sum_layout_node.cpp +++ b/poincare/src/sum_layout_node.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -25,6 +26,12 @@ const uint8_t symbolPixel[SumLayoutNode::k_symbolHeight][SumLayoutNode::k_symbol }; +SumLayoutNode * SumLayoutNode::FailedAllocationStaticNode() { + static AllocationFailureLayoutNode failure; + TreePool::sharedPool()->registerStaticNodeIfRequired(&failure); + return &failure; +} + int SumLayoutNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const { return SequenceLayoutNode::writeDerivedClassInBuffer("sum", buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits); } diff --git a/poincare/src/vertical_offset_layout_node.cpp b/poincare/src/vertical_offset_layout_node.cpp index 92158f4bb..85d43bae2 100644 --- a/poincare/src/vertical_offset_layout_node.cpp +++ b/poincare/src/vertical_offset_layout_node.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -190,7 +191,7 @@ int VerticalOffsetLayoutNode::serialize(char * buffer, int bufferSize, Preferenc } assert(m_type == Type::Superscript); // If the layout is a superscript, write "^(indice)" - int numberOfChar = SerializationHelper::Prefix(SerializableRef(this), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "^"); + int numberOfChar = SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "^"); if (numberOfChar >= bufferSize-1) { return bufferSize-1; } // Add a multiplication if omitted.