diff --git a/apps/calculation/history_view_cell.cpp b/apps/calculation/history_view_cell.cpp index b6e4a645a..21bd7f2f8 100644 --- a/apps/calculation/history_view_cell.cpp +++ b/apps/calculation/history_view_cell.cpp @@ -9,9 +9,9 @@ namespace Calculation { HistoryViewCell::HistoryViewCell(Responder * parentResponder) : Responder(parentResponder), - m_inputLayout(nullptr), - m_exactOutputLayout(nullptr), - m_approximateOutputLayout(nullptr), + m_inputLayout(), + m_exactOutputLayout(), + m_approximateOutputLayout(), m_inputView(this), m_scrollableOutputView(this), m_selectedSubviewType(HistoryViewCell::SubviewType::Output) @@ -101,7 +101,7 @@ void HistoryViewCell::setCalculation(Calculation * calculation) { * when updating one layout, if the second one still points to a deleted * layout, calling to layoutSubviews() would fail. */ if (m_exactOutputLayout.isDefined()) { - m_exactOutputLayout = Poincare::LayoutRef(nullptr); + m_exactOutputLayout = Poincare::LayoutRef(); } if (!calculation->shouldOnlyDisplayApproximateOutput(calculationApp->localContext())) { m_exactOutputLayout = calculation->createExactOutputLayout(calculationApp->localContext()); diff --git a/apps/shared/expression_model.cpp b/apps/shared/expression_model.cpp index 6d27a6797..984ce6e85 100644 --- a/apps/shared/expression_model.cpp +++ b/apps/shared/expression_model.cpp @@ -50,7 +50,7 @@ void ExpressionModel::setContent(const char * c) { // TODO: the previous expression and layout are going to be destroyed as soon as we call expression(). Should we optimize this? #if 0 if (m_layoutRef.isDefined()) { - m_layoutRef = LayoutRef(nullptr); + m_layoutRef = LayoutRef(); } if (m_expression != nullptr) { delete m_expression; @@ -67,7 +67,7 @@ void ExpressionModel::tidy() { if (m_layoutRef.isDefined()) { - m_layoutRef = LayoutRef(nullptr); + m_layoutRef = LayoutRef(); } if (m_expression != nullptr) { delete m_expression; diff --git a/apps/shared/sum_graph_controller.cpp b/apps/shared/sum_graph_controller.cpp index 1fd0c32fd..77025580f 100644 --- a/apps/shared/sum_graph_controller.cpp +++ b/apps/shared/sum_graph_controller.cpp @@ -202,7 +202,7 @@ bool SumGraphController::handleEnter() { SumGraphController::LegendView::LegendView(SumGraphController * controller, char sumSymbol) : m_sum(0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), - m_sumLayoutRef(nullptr), + m_sumLayoutRef(), m_legend(KDText::FontSize::Small, I18n::Message::Default, 0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), m_editableZone(controller, m_draftText, m_draftText, TextField::maxBufferSize(), controller, false, KDText::FontSize::Small, 0.0f, 0.5f, KDColorBlack, Palette::GreyMiddle), m_sumSymbol(sumSymbol) diff --git a/apps/variable_box_controller.cpp b/apps/variable_box_controller.cpp index 15f48f88e..1218a07bc 100644 --- a/apps/variable_box_controller.cpp +++ b/apps/variable_box_controller.cpp @@ -159,7 +159,7 @@ void VariableBoxController::ContentViewController::willDisplayCellForIndex(Highl PrintFloat::convertFloatToText(matrixEvaluation.numberOfColumns(), buffer+numberOfChars, PrintFloat::bufferSizeForFloatsWithPrecision(2), 2, Preferences::PrintFloatMode::Decimal); myCell->setSubtitle(buffer); } else { - myCell->setLayoutRef(LayoutRef(nullptr)); + myCell->setLayoutRef(LayoutRef()); myCell->setSubtitle(I18n::translate(I18n::Message::Empty)); } } @@ -261,10 +261,10 @@ LayoutRef VariableBoxController::ContentViewController::layoutRefForIndex(int in } #if LIST_VARIABLES if (m_currentPage == Page::List) { - return nullptr; + return LayoutRef(); } #endif - return nullptr; + return LayoutRef(); } VariableBoxController::VariableBoxController(GlobalContext * context) : diff --git a/escher/include/escher/highlight_cell.h b/escher/include/escher/highlight_cell.h index a9ad67969..3a1e8caea 100644 --- a/escher/include/escher/highlight_cell.h +++ b/escher/include/escher/highlight_cell.h @@ -19,7 +19,7 @@ public: return nullptr; } virtual Poincare::LayoutRef layoutRef() const { - return Poincare::LayoutRef(nullptr); + return Poincare::LayoutRef(); } protected: bool m_highlighted; diff --git a/escher/src/expression_view.cpp b/escher/src/expression_view.cpp index ea177c735..e716cebcf 100644 --- a/escher/src/expression_view.cpp +++ b/escher/src/expression_view.cpp @@ -3,7 +3,7 @@ using namespace Poincare; ExpressionView::ExpressionView(float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor) : - m_layoutRef(nullptr), + m_layoutRef(), m_horizontalAlignment(horizontalAlignment), m_verticalAlignment(verticalAlignment), m_textColor(textColor), diff --git a/escher/src/layout_field.cpp b/escher/src/layout_field.cpp index 0685c127d..5e59484ae 100644 --- a/escher/src/layout_field.cpp +++ b/escher/src/layout_field.cpp @@ -87,7 +87,7 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool return true; } // Find the pointed layout. - LayoutRef pointedLayoutRef(nullptr); + LayoutRef pointedLayoutRef(); if (strcmp(text, I18n::translate(I18n::Message::RandomCommandWithArg)) == 0) { /* Special case: if the text is "random()", the cursor should not be set * inside the parentheses. */ @@ -103,8 +103,8 @@ bool LayoutField::handleEventWithText(const char * text, bool indentation, bool } } } - /* Insert the layout. If pointedLayout is nullptr, the cursor will be on the - * right of the inserted layout. */ + /* Insert the layout. If pointedLayout is uninitialized, the cursor will + * be on the right of the inserted layout. */ insertLayoutAtCursor(resultLayoutRef, pointedLayoutRef, forceCursorRightOfText); } } @@ -256,7 +256,7 @@ void LayoutField::insertLayoutAtCursor(LayoutRef layoutR, LayoutRef pointedLayou m_contentView.cursor()->showEmptyLayoutIfNeeded(); bool layoutWillBeMerged = layoutR.isHorizontal(); - LayoutRef lastMergedLayoutChild = layoutWillBeMerged ? layoutR.childAtIndex(layoutR.numberOfChildren()-1) : LayoutRef(nullptr); + LayoutRef lastMergedLayoutChild = layoutWillBeMerged ? layoutR.childAtIndex(layoutR.numberOfChildren()-1) : LayoutRef(); // Add the layout m_contentView.cursor()->addLayoutAndMoveCursor(layoutR); @@ -266,7 +266,7 @@ void LayoutField::insertLayoutAtCursor(LayoutRef layoutR, LayoutRef pointedLayou m_contentView.cursor()->setLayoutReference(layoutRef()); } else if(!forceCursorRightOfLayout) { if (pointedLayoutR.isDefined() && (!layoutWillBeMerged || pointedLayoutR != layoutR)) { - // Make sure the layout was inserted (its parent is not nullptr) + // Make sure the layout was inserted (its parent is not uninitialized) m_contentView.cursor()->setLayoutReference(pointedLayoutR); m_contentView.cursor()->setPosition(LayoutCursor::Position::Right); } else if (!layoutWillBeMerged) { diff --git a/poincare/include/poincare/evaluation.h b/poincare/include/poincare/evaluation.h index ec25a0dcb..78960b168 100644 --- a/poincare/include/poincare/evaluation.h +++ b/poincare/include/poincare/evaluation.h @@ -37,11 +37,12 @@ public: template class Evaluation : public TreeByValue { public: + Evaluation(); EvaluationNode * node() const override { assert(TreeByValue::node() == nullptr || !TreeByValue::node()->isGhost()); return static_cast *>(TreeByValue::node()); } - Evaluation() : Evaluation(nullptr) {} + /* Hierarchy */ Evaluation childAtIndex(int i) const { return Evaluation(static_cast *>(TreeByValue::childAtIndex(i).node())); diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index 20c12dce6..0e31c36c1 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -28,7 +28,7 @@ class Expression : public TreeByValue { friend class Matrix; public: /* Constructor & Destructor */ - Expression() : Expression(nullptr) {} + Expression(); virtual ~Expression() = default; static Expression parse(char const * string); Expression replaceSymbolWithExpression(char symbol, Expression expression) const { return node()->replaceSymbolWithExpression(symbol, expression); } @@ -154,9 +154,9 @@ private: constexpr static double k_goldenRatio = 0.381966011250105151795413165634361882279690820194237137864; // (3-sqrt(5))/2 constexpr static double k_maxFloat = 1e100; typedef double (*EvaluationAtAbscissa)(char symbol, double abscissa, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1); - Coordinate2D nextMinimumOfExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression(nullptr), bool lookForRootMinimum = false) const; - void bracketMinimum(char symbol, double start, double step, double max, double result[3], EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression(nullptr)) const; - Coordinate2D brentMinimum(char symbol, double ax, double bx, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression(nullptr)) const; + Coordinate2D nextMinimumOfExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression(), bool lookForRootMinimum = false) const; + void bracketMinimum(char symbol, double start, double step, double max, double result[3], EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression()) const; + Coordinate2D brentMinimum(char symbol, double ax, double bx, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression = Expression()) const; double nextIntersectionWithExpression(char symbol, double start, double step, double max, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const; void bracketRoot(char symbol, double start, double step, double max, double result[2], EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const; double brentRoot(char symbol, double ax, double bx, double precision, EvaluationAtAbscissa evaluation, Context & context, Preferences::AngleUnit angleUnit, const Expression expression) const; diff --git a/poincare/include/poincare/layout_cursor.h b/poincare/include/poincare/layout_cursor.h index 60a9eb785..d82a32739 100644 --- a/poincare/include/poincare/layout_cursor.h +++ b/poincare/include/poincare/layout_cursor.h @@ -29,7 +29,7 @@ public: }; LayoutCursor() : - m_layoutRef(nullptr), + m_layoutRef(), m_position(Position::Right) {} diff --git a/poincare/include/poincare/layout_reference.h b/poincare/include/poincare/layout_reference.h index baf74f221..554e8302b 100644 --- a/poincare/include/poincare/layout_reference.h +++ b/poincare/include/poincare/layout_reference.h @@ -18,7 +18,9 @@ public: using TreeByReference::operator==; using TreeByReference::operator!=; - LayoutReference(const LayoutNode * node = nullptr) : + LayoutReference(); + + LayoutReference(const LayoutNode * node) : TreeByReference(node) {} LayoutReference clone() const { diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index e8790b89d..a067e9dec 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -104,7 +104,7 @@ private: void setNumberOfRows(int rows) { assert(rows >= 0); node()->setNumberOfRows(rows); } void setNumberOfColumns(int columns) { assert(columns >= 0); node()->setNumberOfColumns(columns); } /* rowCanonize turns a matrix in its reduced row echelon form. */ - Matrix rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication(nullptr)); + Matrix rowCanonize(Context & context, Preferences::AngleUnit angleUnit, Multiplication m = Multiplication()); // Row canonize the array in place template static void ArrayRowCanonize(T * array, int numberOfRows, int numberOfColumns, T * c = nullptr); }; diff --git a/poincare/include/poincare/uninitialized_evaluation_node.h b/poincare/include/poincare/uninitialized_evaluation_node.h index 087e247b8..48eebb964 100644 --- a/poincare/include/poincare/uninitialized_evaluation_node.h +++ b/poincare/include/poincare/uninitialized_evaluation_node.h @@ -13,6 +13,7 @@ namespace Poincare { template class UninitializedEvaluationNode : public ExceptionEvaluationNode { public: + static UninitializedEvaluationNode * UninitializedEvaluationStaticNode(); // TreeNode bool isUninitialized() const override { return true; } TreeNode * failedAllocationStaticNode() override { /*TODO*/ assert(false); return nullptr; /* Or call parent method ?*/ } @@ -24,14 +25,6 @@ public: #endif }; -template -class UninitializedEvaluation : public Expression { -public: - UninitializedEvaluation() : Expression(UninitializedEvaluationStaticNode()) {} -private: - static UninitializedEvaluationNode * UninitializedEvaluationStaticNode(); -}; - } #endif diff --git a/poincare/include/poincare/uninitialized_expression_node.h b/poincare/include/poincare/uninitialized_expression_node.h index 6dc20fa69..27e064c2d 100644 --- a/poincare/include/poincare/uninitialized_expression_node.h +++ b/poincare/include/poincare/uninitialized_expression_node.h @@ -11,6 +11,8 @@ namespace Poincare { class UninitializedExpressionNode : public ExceptionExpressionNode { public: + static UninitializedExpressionNode * UninitializedExpressionStaticNode(); + // ExpressionNode ExpressionNode::Sign sign() const override { assert(false); return ExceptionExpressionNode::sign(); } ExpressionNode::Type type() const override { assert(false); return ExpressionNode::Type::Uninitialized; } // TODO assert(false) ? @@ -33,13 +35,6 @@ public: #endif }; -class UninitializedExpression : public Expression { -public: - UninitializedExpression() : Expression(UninitializedExpressionStaticNode()) {} -private: - static UninitializedExpressionNode * UninitializedExpressionStaticNode(); -}; - } #endif diff --git a/poincare/include/poincare/uninitialized_layout_node.h b/poincare/include/poincare/uninitialized_layout_node.h index 094fa96bd..646b38e6e 100644 --- a/poincare/include/poincare/uninitialized_layout_node.h +++ b/poincare/include/poincare/uninitialized_layout_node.h @@ -11,6 +11,8 @@ namespace Poincare { class UninitializedLayoutNode : public ExceptionLayoutNode { public: + static UninitializedLayoutNode * UninitializedLayoutStaticNode(); + // LayoutNode // Rendering void invalidAllSizesPositionsAndBaselines() override { assert(false); ExceptionLayoutNode::invalidAllSizesPositionsAndBaselines(); } @@ -79,13 +81,6 @@ private: void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override { assert(false); ExceptionLayoutNode::render(ctx, p, expressionColor, backgroundColor); } }; -class UninitializedLayoutReference : public LayoutReference { -public: - UninitializedLayoutReference() : LayoutReference(UninitializedLayoutStaticNode()) {} -private: - static UninitializedLayoutNode * UninitializedLayoutStaticNode(); -}; - } #endif diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index c52fcc4ec..f1282f001 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -248,7 +248,7 @@ int Decimal::Exponent(const char * integralPart, int integralPartLength, const c return exp; } -Decimal::Decimal(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative, int exponent) : Number(nullptr) { +Decimal::Decimal(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative, int exponent) : Number() { Integer zero(0); Integer base(10); Integer numerator(integralPart, integralPartLength, negative); @@ -261,7 +261,7 @@ Decimal::Decimal(const char * integralPart, int integralPartLength, const char * } template -Decimal::Decimal(T f) : Number(nullptr) { +Decimal::Decimal(T f) : Number() { assert(!std::isnan(f) && !std::isinf(f)); int exp = IEEE754::exponentBase10(f); int64_t mantissaf = std::round((double)f * std::pow((double)10.0, (double)(-exp+PrintFloat::k_numberOfStoredSignificantDigits+1))); diff --git a/poincare/src/evaluation.cpp b/poincare/src/evaluation.cpp index 6f5a5809b..bffdf1afe 100644 --- a/poincare/src/evaluation.cpp +++ b/poincare/src/evaluation.cpp @@ -1,8 +1,12 @@ #include #include +#include namespace Poincare { +template +Evaluation::Evaluation() : Evaluation(UninitializedEvaluationNode::UninitializedEvaluationStaticNode()) {} + template Expression Evaluation::complexToExpression(Preferences::ComplexFormat complexFormat) const { return node()->complexToExpression(complexFormat); diff --git a/poincare/src/expression.cpp b/poincare/src/expression.cpp index 8ff365bfb..36650c25f 100644 --- a/poincare/src/expression.cpp +++ b/poincare/src/expression.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -20,16 +21,17 @@ namespace Poincare { #include /* Constructor & Destructor */ +Expression::Expression() : Expression(UninitializedExpressionNode:UninitializedExpressionStaticNode) {} Expression Expression::parse(char const * string) { if (string[0] == 0) { return nullptr; } YY_BUFFER_STATE buf = poincare_expression_yy_scan_string(string); - Expression expression(nullptr); + Expression expression(); if (poincare_expression_yyparse(&expression) != 0) { // Parsing failed because of invalid input or memory exhaustion - expression = Expression(nullptr); + expression = Expression(); } poincare_expression_yy_delete_buffer(buf); @@ -126,9 +128,9 @@ bool Expression::getLinearCoefficients(char * variables, Expression coefficients } if (isMultivariablePolynomial) { for (int i = 0; i < index; i++) { - coefficients[i] = Expression(nullptr); + coefficients[i] = Expression(); } - constant[0] = Expression(nullptr); + constant[0] = Expression(); return false; } return true; @@ -220,7 +222,7 @@ Expression Expression::simplify(Context & context, Preferences::AngleUnit angleU Expression e = deepReduce(context, angleUnit); e = e.deepBeautify(context, angleUnit); if (sSimplificationHasBeenInterrupted) { - e = Expression(nullptr); + e = Expression(); } return e; } @@ -283,20 +285,20 @@ U Expression::epsilon() { /* Expression roots/extrema solver*/ typename Expression::Coordinate2D Expression::nextMinimum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - return nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { + return nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = Expression()) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit); } typename Expression::Coordinate2D Expression::nextMaximum(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - Coordinate2D minimumOfOpposite = nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { + Coordinate2D minimumOfOpposite = nextMinimumOfExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = Expression()) { return -expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit); return {.abscissa = minimumOfOpposite.abscissa, .value = -minimumOfOpposite.value}; } double Expression::nextRoot(char symbol, double start, double step, double max, Context & context, Preferences::AngleUnit angleUnit) const { - return nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = nullptr) { + return nextIntersectionWithExpression(symbol, start, step, max, [](char symbol, double x, Context & context, Preferences::AngleUnit angleUnit, const Expression expression0, const Expression expression1 = Expression()) { return expression0.approximateWithValueForSymbol(symbol, x, context, angleUnit); }, context, angleUnit, nullptr); } diff --git a/poincare/src/expression_node.cpp b/poincare/src/expression_node.cpp index 6ab368cca..ebe5a3de2 100644 --- a/poincare/src/expression_node.cpp +++ b/poincare/src/expression_node.cpp @@ -10,7 +10,7 @@ Expression ExpressionNode::replaceSymbolWithExpression(char symbol, Expression e Expression ExpressionNode::setSign(Sign s, Context & context, Preferences::AngleUnit angleUnit) const { assert(false); - return Expression(nullptr); + return Expression(); } int ExpressionNode::polynomialDegree(char symbolName) const { @@ -94,7 +94,7 @@ bool ExpressionNode::isOfType(Type * types, int length) const { } Expression ExpressionNode::denominator(Context & context, Preferences::AngleUnit angleUnit) const { - return Expression(nullptr); + return Expression(); } } diff --git a/poincare/src/horizontal_layout_node.cpp b/poincare/src/horizontal_layout_node.cpp index 6ac8f849d..bd1e2039b 100644 --- a/poincare/src/horizontal_layout_node.cpp +++ b/poincare/src/horizontal_layout_node.cpp @@ -381,7 +381,7 @@ void HorizontalLayoutRef::mergeChildrenAtIndex(HorizontalLayoutRef h, int index, int newIndex = index; removeEmptyChildBeforeInsertionAtIndex(&newIndex, nullptr, shouldRemoveOnLeft); - LayoutRef nextPointedLayout(nullptr); + LayoutRef nextPointedLayout; LayoutCursor::Position nextPosition = LayoutCursor::Position::Left; if (newIndex < numberOfChildren()) { nextPointedLayout = childAtIndex(newIndex); diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 2e0ed5784..6b9d3e65e 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -476,9 +476,7 @@ Integer::Integer(const NaturalIntegerAbstract * naturalInteger) : { } -Integer::Integer(native_int_t i) : - Number(nullptr) -{ +Integer::Integer(native_int_t i) : Number() { if (i == 0) { new (this) Integer((const native_uint_t *)nullptr, 0, false); return; @@ -488,9 +486,7 @@ Integer::Integer(native_int_t i) : new (this) Integer(digits, 1, i < 0); } -Integer::Integer(double_native_int_t i) : - Number(nullptr) -{ +Integer::Integer(double_native_int_t i) : Number() { if (i == 0) { new (this) Integer((const native_uint_t *)nullptr, 0, false); return; diff --git a/poincare/src/layout_cursor.cpp b/poincare/src/layout_cursor.cpp index b2e60d78b..43c614514 100644 --- a/poincare/src/layout_cursor.cpp +++ b/poincare/src/layout_cursor.cpp @@ -162,8 +162,8 @@ void LayoutCursor::insertText(const char * text) { if (textLength <= 0) { return; } - LayoutRef newChild(nullptr); - LayoutRef pointedChild(nullptr); + LayoutRef newChild; + LayoutRef pointedChild; bool specialUnderScore = false; for (int i = 0; i < textLength; i++) { if (text[i] == Ion::Charset::Empty) { @@ -292,7 +292,7 @@ bool LayoutCursor::privateShowHideEmptyLayoutIfNeeded(bool show) { } /* Find Empty layouts adjacent to the cursor: Check the pointed layout and the * equivalent cursor positions */ - LayoutRef adjacentEmptyLayout(nullptr); + LayoutRef adjacentEmptyLayout; if (m_layoutRef.isEmpty()) { // Check the pointed layout diff --git a/poincare/src/layout_node.cpp b/poincare/src/layout_node.cpp index 5861adf11..8c204a54b 100644 --- a/poincare/src/layout_node.cpp +++ b/poincare/src/layout_node.cpp @@ -162,7 +162,7 @@ void LayoutNode::moveCursorVertically(VerticalDirection direction, LayoutCursor } LayoutNode * p = parent(); if (p == nullptr) { - cursor->setLayoutNode(nullptr); + cursor->setLayoutReference(LayoutReference()); return; } if (direction == VerticalDirection::Up) { diff --git a/poincare/src/layout_reference.cpp b/poincare/src/layout_reference.cpp index 39748a009..b0685ec26 100644 --- a/poincare/src/layout_reference.cpp +++ b/poincare/src/layout_reference.cpp @@ -1,14 +1,16 @@ #include -#include #include +#include #include +#include #include #include -#include -#include +#include namespace Poincare { +LayoutReference::LayoutReference() : LayoutReference(UninitializedLayoutNode::UninitializedLayoutStaticNode()) {} + // Cursor LayoutCursor LayoutReference::cursor() const { return LayoutCursor(const_cast(this)->node()); @@ -95,7 +97,7 @@ void LayoutReference::addChildAtIndex(LayoutRef l, int index, int currentNumberO if (!node()->willAddChildAtIndex(l.node(), &newIndex, &newCurrentNumberOfChildren, cursor)) { return; } - LayoutRef nextPointedLayout(nullptr); + LayoutRef nextPointedLayout; LayoutCursor::Position nextPosition = LayoutCursor::Position::Left; if (cursor != nullptr) { if (newIndex < this->numberOfChildren()) { @@ -137,7 +139,7 @@ void LayoutReference::addSibling(LayoutCursor * cursor, LayoutReference sibling, * handle the insertion of the new sibling. Do not enter the special case if * "this" is a VerticalOffsetLayout, to avoid an infinite loop. */ if (!isVerticalOffset()) { - LayoutRef neighbour(nullptr); + LayoutRef neighbour; if (cursor->position() == LayoutCursor::Position::Left && indexInParent > 0) { neighbour = p.childAtIndex(indexInParent - 1); } else if (cursor->position() == LayoutCursor::Position::Right && indexInParent < p.numberOfChildren() - 1) { @@ -211,7 +213,7 @@ void LayoutReference::collapseOnDirection(HorizontalDirection direction, int abs if (direction == HorizontalDirection::Right && idxInParent < numberOfSiblings - 1) { canCollapse = !(p.childAtIndex(idxInParent+1).mustHaveLeftSibling()); } - LayoutRef sibling(nullptr); + LayoutRef sibling; bool forceCollapse = false; while (canCollapse) { if (direction == HorizontalDirection::Right && idxInParent == numberOfSiblings - 1) { diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index ceeb2a56a..20df07a01 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -154,9 +154,7 @@ Expression RationalNode::denominator(Context & context, Preferences::AngleUnit a // Constructors -Rational::Rational(Integer numerator, Integer denominator) : - Number(nullptr) -{ +Rational::Rational(Integer numerator, Integer denominator) : Number() { assert(!denominator.isZero()); if (!numerator.isOne() && !denominator.isOne()) { // Avoid computing GCD if possible @@ -175,16 +173,14 @@ Rational::Rational(Integer numerator, Integer denominator) : new (this) Rational(size, numerator.node()->digits(), numerator.node()->numberOfDigits(), denominator.node()->digits(), denominator.node()->numberOfDigits(), negative); } -Rational::Rational(const Integer numerator) : - Number(nullptr) -{ +Rational::Rational(const Integer numerator) : Number() { if (numerator.node()->isAllocationFailure()) { new (this) Rational(RationalNode::FailedAllocationStaticNode()); } new (this) Rational(numerator.node(), numerator.sign() == ExpressionNode::Sign::Negative); } -Rational::Rational(const NaturalIntegerAbstract * numerator, bool negative) : Number(nullptr) { +Rational::Rational(const NaturalIntegerAbstract * numerator, bool negative) : Number() { native_uint_t one = 1; size_t size = sizeof(RationalNode) + sizeof(native_uint_t); size += numerator->isInfinity() ? sizeof(native_uint_t)*numerator->numberOfDigits() : 0; @@ -192,13 +188,13 @@ Rational::Rational(const NaturalIntegerAbstract * numerator, bool negative) : Nu return; } -Rational::Rational(native_int_t i) : Number(nullptr) { +Rational::Rational(native_int_t i) : Number() { native_uint_t absI = i < 0 ? -i : i; native_uint_t one = 1; new (this) Rational(sizeof(RationalNode)+sizeof(native_uint_t)*2, &absI, 1, &one, 1, i < 0); } -Rational::Rational(native_int_t i, native_int_t j) : Number(nullptr) { +Rational::Rational(native_int_t i, native_int_t j) : Number() { assert(j != 0); native_uint_t absI = i < 0 ? -i : i; native_uint_t absJ = j < 0 ? -j : j; diff --git a/poincare/src/tree_by_reference.cpp b/poincare/src/tree_by_reference.cpp index 6d045e5b9..dd55b5424 100644 --- a/poincare/src/tree_by_reference.cpp +++ b/poincare/src/tree_by_reference.cpp @@ -19,7 +19,7 @@ TreeByReference::~TreeByReference() { TreeByReference TreeByReference::clone() const { if (!isDefined()){ - return TreeByReference(nullptr); + return TreeByReference(); } TreeNode * myNode = node(); if (myNode->isAllocationFailure()) { diff --git a/poincare/src/uninitialized_evaluation_node.cpp b/poincare/src/uninitialized_evaluation_node.cpp index 80eb323fe..2d32451e4 100644 --- a/poincare/src/uninitialized_evaluation_node.cpp +++ b/poincare/src/uninitialized_evaluation_node.cpp @@ -3,7 +3,7 @@ namespace Poincare { template -UninitializedEvaluationNode * UninitializedEvaluation::UninitializedEvaluationStaticNode() { +UninitializedEvaluationNode * UninitializedEvaluationNode::UninitializedEvaluationStaticNode() { static UninitializedEvaluationNode exception; TreePool::sharedPool()->registerStaticNodeIfRequired(&exception); return &exception; diff --git a/poincare/src/uninitialized_expression_node.cpp b/poincare/src/uninitialized_expression_node.cpp index 749e9d16d..9c9ae0475 100644 --- a/poincare/src/uninitialized_expression_node.cpp +++ b/poincare/src/uninitialized_expression_node.cpp @@ -2,7 +2,7 @@ namespace Poincare { -UninitializedExpressionNode * UninitializedExpression::UninitializedExpressionStaticNode() { +UninitializedExpressionNode * UninitializedExpressionNode::UninitializedExpressionStaticNode() { static UninitializedExpressionNode exception; TreePool::sharedPool()->registerStaticNodeIfRequired(&exception); return &exception; diff --git a/poincare/src/uninitialized_layout_node.cpp b/poincare/src/uninitialized_layout_node.cpp index 7575a044b..409308412 100644 --- a/poincare/src/uninitialized_layout_node.cpp +++ b/poincare/src/uninitialized_layout_node.cpp @@ -2,7 +2,7 @@ namespace Poincare { -UninitializedLayoutNode * UninitializedLayoutReference::UninitializedLayoutStaticNode() { +UninitializedLayoutNode * UninitializedLayoutNode::UninitializedLayoutStaticNode() { static UninitializedLayoutNode exception; TreePool::sharedPool()->registerStaticNodeIfRequired(&exception); return &exception;