From 24c9617a8966d11f1e1ae5a0a984113f9dd024e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 21 Feb 2019 10:31:05 +0100 Subject: [PATCH] [poincare] Templatize TreeHandle Builders --- apps/regression/model/cubic_model.cpp | 2 +- apps/regression/model/exponential_model.cpp | 2 +- apps/regression/model/linear_model.cpp | 2 +- apps/regression/model/logarithmic_model.cpp | 2 +- apps/regression/model/logistic_model.cpp | 4 +- apps/regression/model/power_model.cpp | 2 +- apps/regression/model/quadratic_model.cpp | 2 +- apps/regression/model/quartic_model.cpp | 2 +- apps/regression/model/trigonometric_model.cpp | 2 +- poincare/Makefile | 3 - poincare/include/poincare/absolute_value.h | 2 +- .../include/poincare/absolute_value_layout.h | 2 +- poincare/include/poincare/addition.h | 5 +- poincare/include/poincare/arc_cosine.h | 2 +- poincare/include/poincare/arc_sine.h | 2 +- poincare/include/poincare/arc_tangent.h | 2 +- .../include/poincare/binomial_coefficient.h | 2 +- .../poincare/binomial_coefficient_layout.h | 2 +- poincare/include/poincare/ceiling.h | 2 +- poincare/include/poincare/ceiling_layout.h | 2 +- poincare/include/poincare/complex_argument.h | 2 +- poincare/include/poincare/complex_cartesian.h | 4 +- .../include/poincare/condensed_sum_layout.h | 2 +- .../include/poincare/confidence_interval.h | 4 +- poincare/include/poincare/conjugate.h | 2 +- poincare/include/poincare/conjugate_layout.h | 2 +- poincare/include/poincare/cosine.h | 2 +- poincare/include/poincare/derivative.h | 11 +- poincare/include/poincare/determinant.h | 2 +- poincare/include/poincare/division.h | 4 +- poincare/include/poincare/division_quotient.h | 2 +- .../include/poincare/division_remainder.h | 2 +- poincare/include/poincare/empty_expression.h | 2 +- poincare/include/poincare/equal.h | 2 +- poincare/include/poincare/expression.h | 1 + poincare/include/poincare/factor.h | 2 +- poincare/include/poincare/factorial.h | 3 +- poincare/include/poincare/floor.h | 2 +- poincare/include/poincare/floor_layout.h | 2 +- poincare/include/poincare/frac_part.h | 2 +- poincare/include/poincare/fraction_layout.h | 2 +- poincare/include/poincare/ghost.h | 7 +- .../include/poincare/great_common_divisor.h | 2 +- poincare/include/poincare/grid_layout.h | 3 +- poincare/include/poincare/horizontal_layout.h | 11 +- .../include/poincare/hyperbolic_arc_cosine.h | 2 +- .../include/poincare/hyperbolic_arc_sine.h | 2 +- .../include/poincare/hyperbolic_arc_tangent.h | 2 +- poincare/include/poincare/hyperbolic_cosine.h | 2 +- poincare/include/poincare/hyperbolic_sine.h | 2 +- .../include/poincare/hyperbolic_tangent.h | 2 +- poincare/include/poincare/imaginary_part.h | 2 +- poincare/include/poincare/integral.h | 12 +- poincare/include/poincare/integral_layout.h | 2 +- poincare/include/poincare/layout.h | 1 + .../include/poincare/least_common_multiple.h | 2 +- .../poincare/left_parenthesis_layout.h | 2 +- .../poincare/left_square_bracket_layout.h | 2 +- poincare/include/poincare/logarithm.h | 4 +- poincare/include/poincare/matrix.h | 2 +- poincare/include/poincare/matrix_complex.h | 2 +- poincare/include/poincare/matrix_dimension.h | 2 +- poincare/include/poincare/matrix_inverse.h | 2 +- poincare/include/poincare/matrix_layout.h | 12 +- poincare/include/poincare/matrix_trace.h | 2 +- poincare/include/poincare/matrix_transpose.h | 2 +- poincare/include/poincare/multiplication.h | 5 +- .../include/poincare/naperian_logarithm.h | 2 +- poincare/include/poincare/nth_root.h | 2 +- poincare/include/poincare/opposite.h | 4 +- poincare/include/poincare/parenthesis.h | 2 +- .../include/poincare/permute_coefficient.h | 2 +- poincare/include/poincare/power.h | 2 +- .../include/poincare/prediction_interval.h | 2 +- poincare/include/poincare/product.h | 12 +- poincare/include/poincare/product_layout.h | 2 +- poincare/include/poincare/randint.h | 2 +- poincare/include/poincare/random.h | 2 +- poincare/include/poincare/real_part.h | 2 +- .../poincare/right_parenthesis_layout.h | 2 +- .../poincare/right_square_bracket_layout.h | 2 +- poincare/include/poincare/round.h | 2 +- poincare/include/poincare/sign_function.h | 2 +- poincare/include/poincare/sine.h | 2 +- poincare/include/poincare/square_root.h | 2 +- poincare/include/poincare/store.h | 2 +- poincare/include/poincare/subtraction.h | 4 +- poincare/include/poincare/sum.h | 12 +- poincare/include/poincare/sum_layout.h | 2 +- poincare/include/poincare/tangent.h | 2 +- poincare/include/poincare/tree_handle.h | 13 +- poincare/include/poincare/undefined.h | 2 +- poincare/include/poincare/unreal.h | 2 +- poincare/src/absolute_value.cpp | 6 - poincare/src/absolute_value_layout.cpp | 12 -- poincare/src/addition.cpp | 15 --- poincare/src/arc_cosine.cpp | 6 - poincare/src/arc_sine.cpp | 6 - poincare/src/arc_tangent.cpp | 6 - poincare/src/binomial_coefficient.cpp | 7 - poincare/src/binomial_coefficient_layout.cpp | 10 +- poincare/src/ceiling.cpp | 6 - poincare/src/ceiling_layout.cpp | 12 -- poincare/src/char_layout.cpp | 2 +- poincare/src/complex.cpp | 2 +- poincare/src/complex_argument.cpp | 6 - poincare/src/complex_cartesian.cpp | 14 -- poincare/src/condensed_sum_layout.cpp | 7 - poincare/src/confidence_interval.cpp | 12 -- poincare/src/conjugate.cpp | 6 - poincare/src/conjugate_layout.cpp | 7 - poincare/src/cosine.cpp | 6 - poincare/src/decimal.cpp | 2 +- poincare/src/derivative.cpp | 12 +- poincare/src/determinant.cpp | 6 - poincare/src/division.cpp | 14 -- poincare/src/division_quotient.cpp | 6 - poincare/src/division_remainder.cpp | 6 - poincare/src/empty_expression.cpp | 7 - poincare/src/empty_layout.cpp | 2 +- poincare/src/equal.cpp | 6 - poincare/src/factor.cpp | 6 - poincare/src/factorial.cpp | 6 - poincare/src/float.cpp | 2 +- poincare/src/floor.cpp | 6 - poincare/src/floor_layout.cpp | 12 -- poincare/src/frac_part.cpp | 6 - poincare/src/fraction_layout.cpp | 9 +- poincare/src/great_common_divisor.cpp | 8 +- poincare/src/grid_layout.cpp | 9 +- poincare/src/horizontal_layout.cpp | 7 - poincare/src/hyperbolic_arc_cosine.cpp | 6 - poincare/src/hyperbolic_arc_sine.cpp | 6 - poincare/src/hyperbolic_arc_tangent.cpp | 6 - poincare/src/hyperbolic_cosine.cpp | 6 - poincare/src/hyperbolic_sine.cpp | 6 - poincare/src/hyperbolic_tangent.cpp | 6 - poincare/src/imaginary_part.cpp | 6 - poincare/src/infinity.cpp | 2 +- poincare/src/integer.cpp | 2 +- poincare/src/integral.cpp | 14 +- poincare/src/integral_layout.cpp | 7 - poincare/src/least_common_multiple.cpp | 6 - poincare/src/left_parenthesis_layout.cpp | 7 - poincare/src/left_square_bracket_layout.cpp | 7 - poincare/src/logarithm.cpp | 16 +-- poincare/src/matrix.cpp | 7 - poincare/src/matrix_complex.cpp | 8 -- poincare/src/matrix_dimension.cpp | 6 - poincare/src/matrix_inverse.cpp | 6 - poincare/src/matrix_layout.cpp | 9 +- poincare/src/matrix_trace.cpp | 6 - poincare/src/matrix_transpose.cpp | 6 - poincare/src/multiplication.cpp | 15 --- poincare/src/naperian_logarithm.cpp | 6 - poincare/src/nth_root.cpp | 6 - poincare/src/nth_root_layout.cpp | 7 +- poincare/src/opposite.cpp | 13 -- poincare/src/parenthesis.cpp | 6 - poincare/src/permute_coefficient.cpp | 6 - poincare/src/power.cpp | 7 - poincare/src/prediction_interval.cpp | 6 - poincare/src/product.cpp | 12 +- poincare/src/product_layout.cpp | 7 - poincare/src/randint.cpp | 6 - poincare/src/random.cpp | 7 - poincare/src/rational.cpp | 2 +- poincare/src/real_part.cpp | 6 - poincare/src/right_parenthesis_layout.cpp | 7 - poincare/src/right_square_bracket_layout.cpp | 7 - poincare/src/round.cpp | 6 - poincare/src/sign_function.cpp | 6 - poincare/src/sine.cpp | 6 - poincare/src/square_root.cpp | 6 - poincare/src/store.cpp | 7 - poincare/src/subtraction.cpp | 14 -- poincare/src/sum.cpp | 12 +- poincare/src/sum_layout.cpp | 7 - poincare/src/symbol_abstract.cpp | 2 +- poincare/src/tangent.cpp | 6 - poincare/src/tree_handle.cpp | 123 ++++++++++++++++-- poincare/src/undefined.cpp | 7 - poincare/src/unreal.cpp | 7 - poincare/src/vertical_offset_layout.cpp | 3 +- poincare/test/tree/blob_node.h | 2 +- poincare/test/tree/pair_node.h | 6 +- 186 files changed, 292 insertions(+), 766 deletions(-) delete mode 100644 poincare/src/absolute_value_layout.cpp delete mode 100644 poincare/src/ceiling_layout.cpp delete mode 100644 poincare/src/floor_layout.cpp diff --git a/apps/regression/model/cubic_model.cpp b/apps/regression/model/cubic_model.cpp index da7fc39c6..5147ff5f5 100644 --- a/apps/regression/model/cubic_model.cpp +++ b/apps/regression/model/cubic_model.cpp @@ -19,7 +19,7 @@ namespace Regression { Layout CubicModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont), diff --git a/apps/regression/model/exponential_model.cpp b/apps/regression/model/exponential_model.cpp index 52492b4fe..320d99b45 100644 --- a/apps/regression/model/exponential_model.cpp +++ b/apps/regression/model/exponential_model.cpp @@ -11,7 +11,7 @@ namespace Regression { Layout ExponentialModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('e', KDFont::SmallFont), diff --git a/apps/regression/model/linear_model.cpp b/apps/regression/model/linear_model.cpp index 272505f6c..92e03af93 100644 --- a/apps/regression/model/linear_model.cpp +++ b/apps/regression/model/linear_model.cpp @@ -11,7 +11,7 @@ namespace Regression { Layout LinearModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont), diff --git a/apps/regression/model/logarithmic_model.cpp b/apps/regression/model/logarithmic_model.cpp index bb585ea59..fb7563928 100644 --- a/apps/regression/model/logarithmic_model.cpp +++ b/apps/regression/model/logarithmic_model.cpp @@ -11,7 +11,7 @@ namespace Regression { Layout LogarithmicModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('l', KDFont::SmallFont), diff --git a/apps/regression/model/logistic_model.cpp b/apps/regression/model/logistic_model.cpp index c3f91bf95..ad0ea7503 100644 --- a/apps/regression/model/logistic_model.cpp +++ b/apps/regression/model/logistic_model.cpp @@ -12,13 +12,13 @@ namespace Regression { Layout LogisticModel::layout() { if (m_layout.isUninitialized()) { - const Layout exponentLayoutChildren[] = { + Layout exponentLayoutChildren[] = { CharLayout::Builder('-', KDFont::SmallFont), CharLayout::Builder('b', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont) }; - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('1', KDFont::SmallFont), CharLayout::Builder('+', KDFont::SmallFont), CharLayout::Builder('a', KDFont::SmallFont), diff --git a/apps/regression/model/power_model.cpp b/apps/regression/model/power_model.cpp index 4f341c4bf..bd790d815 100644 --- a/apps/regression/model/power_model.cpp +++ b/apps/regression/model/power_model.cpp @@ -12,7 +12,7 @@ namespace Regression { Layout PowerModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont), diff --git a/apps/regression/model/quadratic_model.cpp b/apps/regression/model/quadratic_model.cpp index 0babfe9d6..0ee0b1764 100644 --- a/apps/regression/model/quadratic_model.cpp +++ b/apps/regression/model/quadratic_model.cpp @@ -19,7 +19,7 @@ namespace Regression { Layout QuadraticModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont), diff --git a/apps/regression/model/quartic_model.cpp b/apps/regression/model/quartic_model.cpp index c1dbd87ca..3f7a4395a 100644 --- a/apps/regression/model/quartic_model.cpp +++ b/apps/regression/model/quartic_model.cpp @@ -19,7 +19,7 @@ namespace Regression { Layout QuarticModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('X', KDFont::SmallFont), diff --git a/apps/regression/model/trigonometric_model.cpp b/apps/regression/model/trigonometric_model.cpp index ed919a59e..2a605cdde 100644 --- a/apps/regression/model/trigonometric_model.cpp +++ b/apps/regression/model/trigonometric_model.cpp @@ -20,7 +20,7 @@ namespace Regression { Layout TrigonometricModel::layout() { if (m_layout.isUninitialized()) { - const Layout layoutChildren[] = { + Layout layoutChildren[] = { CharLayout::Builder('a', KDFont::SmallFont), CharLayout::Builder(Ion::Charset::MiddleDot, KDFont::SmallFont), CharLayout::Builder('s', KDFont::SmallFont), diff --git a/poincare/Makefile b/poincare/Makefile index 7fbd144c1..28c3096e6 100644 --- a/poincare/Makefile +++ b/poincare/Makefile @@ -3,16 +3,13 @@ SFLAGS += -Ipoincare/include #include poincare/src/simplify/Makefile #include poincare/src/simplification/Makefile objs += $(addprefix poincare/src/,\ - absolute_value_layout.o\ binomial_coefficient_layout.o\ bracket_layout.o\ bracket_pair_layout.o\ - ceiling_layout.o\ char_layout.o\ condensed_sum_layout.o\ conjugate_layout.o\ empty_layout.o\ - floor_layout.o\ fraction_layout.o\ grid_layout.o\ horizontal_layout.o\ diff --git a/poincare/include/poincare/absolute_value.h b/poincare/include/poincare/absolute_value.h index 66d4b8d4c..07c5f1bbf 100644 --- a/poincare/include/poincare/absolute_value.h +++ b/poincare/include/poincare/absolute_value.h @@ -49,7 +49,7 @@ class AbsoluteValue final : public Expression { friend class AbsoluteValueNode; public: AbsoluteValue(const AbsoluteValueNode * n) : Expression(n) {} - static AbsoluteValue Builder(Expression child); + static AbsoluteValue Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("abs", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/absolute_value_layout.h b/poincare/include/poincare/absolute_value_layout.h index 42510c6b0..5a909f36d 100644 --- a/poincare/include/poincare/absolute_value_layout.h +++ b/poincare/include/poincare/absolute_value_layout.h @@ -33,7 +33,7 @@ private: class AbsoluteValueLayout final : public Layout { public: - static AbsoluteValueLayout Builder(Layout l); + static AbsoluteValueLayout Builder(Layout child) { return TreeHandle::FixedArityBuilder(&child, 1); } AbsoluteValueLayout() = delete; }; diff --git a/poincare/include/poincare/addition.h b/poincare/include/poincare/addition.h index 07d482e46..6a0c3d44b 100644 --- a/poincare/include/poincare/addition.h +++ b/poincare/include/poincare/addition.h @@ -2,7 +2,6 @@ #define POINCARE_ADDITION_H #include -#include #include #include @@ -61,10 +60,10 @@ private: class Addition final : public NAryExpression { public: Addition(const AdditionNode * n) : NAryExpression(n) {} - static Addition Builder(); + static Addition Builder() { return TreeHandle::NAryBuilder(); } static Addition Builder(Expression e1) { return Addition::Builder(&e1, 1); } static Addition Builder(Expression e1, Expression e2) { return Addition::Builder(ArrayBuilder(e1, e2).array(), 2); } - static Addition Builder(Expression * children, size_t numberOfChildren); + static Addition Builder(Expression * children, size_t numberOfChildren) { return TreeHandle::NAryBuilder(children, numberOfChildren); } // Expression Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); Expression shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); diff --git a/poincare/include/poincare/arc_cosine.h b/poincare/include/poincare/arc_cosine.h index ee29beacb..89a976098 100644 --- a/poincare/include/poincare/arc_cosine.h +++ b/poincare/include/poincare/arc_cosine.h @@ -41,7 +41,7 @@ private: class ArcCosine final : public Expression { public: ArcCosine(const ArcCosineNode * n) : Expression(n) {} - static ArcCosine Builder(Expression child); + static ArcCosine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acos", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/arc_sine.h b/poincare/include/poincare/arc_sine.h index 7ae261b42..2cdf8626f 100644 --- a/poincare/include/poincare/arc_sine.h +++ b/poincare/include/poincare/arc_sine.h @@ -40,7 +40,7 @@ private: class ArcSine final : public Expression { public: ArcSine(const ArcSineNode * n) : Expression(n) {} - static ArcSine Builder(Expression child); + static ArcSine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asin", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/arc_tangent.h b/poincare/include/poincare/arc_tangent.h index a0d6218f4..b61438e64 100644 --- a/poincare/include/poincare/arc_tangent.h +++ b/poincare/include/poincare/arc_tangent.h @@ -44,7 +44,7 @@ private: class ArcTangent final : public Expression { public: ArcTangent(const ArcTangentNode * n) : Expression(n) {} - static ArcTangent Builder(Expression child); + static ArcTangent Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atan", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/binomial_coefficient.h b/poincare/include/poincare/binomial_coefficient.h index 3c3315fff..6eeb90dd4 100644 --- a/poincare/include/poincare/binomial_coefficient.h +++ b/poincare/include/poincare/binomial_coefficient.h @@ -39,7 +39,7 @@ private: class BinomialCoefficient final : public Expression { public: BinomialCoefficient(const BinomialCoefficientNode * n) : Expression(n) {} - static BinomialCoefficient Builder(Expression child0, Expression child1); + static BinomialCoefficient Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("binomial", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/binomial_coefficient_layout.h b/poincare/include/poincare/binomial_coefficient_layout.h index b094b5b53..2187496ce 100644 --- a/poincare/include/poincare/binomial_coefficient_layout.h +++ b/poincare/include/poincare/binomial_coefficient_layout.h @@ -43,7 +43,7 @@ private: class BinomialCoefficientLayout final : public Layout { public: - static BinomialCoefficientLayout Builder(Layout n, Layout k); + static BinomialCoefficientLayout Builder(Layout child0, Layout child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } BinomialCoefficientLayout() = delete; }; diff --git a/poincare/include/poincare/ceiling.h b/poincare/include/poincare/ceiling.h index f8b75112c..a0f9cb615 100644 --- a/poincare/include/poincare/ceiling.h +++ b/poincare/include/poincare/ceiling.h @@ -42,7 +42,7 @@ private: class Ceiling final : public Expression { public: Ceiling(const CeilingNode * n) : Expression(n) {} - static Ceiling Builder(Expression child); + static Ceiling Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ceil", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/ceiling_layout.h b/poincare/include/poincare/ceiling_layout.h index 8b06304e7..6a3755175 100644 --- a/poincare/include/poincare/ceiling_layout.h +++ b/poincare/include/poincare/ceiling_layout.h @@ -30,7 +30,7 @@ protected: class CeilingLayout final : public Layout { public: - static CeilingLayout Builder(Layout l); + static CeilingLayout Builder(Layout child) { return TreeHandle::FixedArityBuilder(&child, 1); } CeilingLayout() = delete; }; diff --git a/poincare/include/poincare/complex_argument.h b/poincare/include/poincare/complex_argument.h index bdbcb3c72..b6a9b9fad 100644 --- a/poincare/include/poincare/complex_argument.h +++ b/poincare/include/poincare/complex_argument.h @@ -41,7 +41,7 @@ private: class ComplexArgument final : public Expression { public: ComplexArgument(const ComplexArgumentNode * n) : Expression(n) {} - static ComplexArgument Builder(Expression child); + static ComplexArgument Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("arg", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/complex_cartesian.h b/poincare/include/poincare/complex_cartesian.h index 4a6db764f..2ac6e865f 100644 --- a/poincare/include/poincare/complex_cartesian.h +++ b/poincare/include/poincare/complex_cartesian.h @@ -38,8 +38,8 @@ class ComplexCartesian final : public Expression { public: ComplexCartesian() : Expression() {} ComplexCartesian(const ComplexCartesianNode * node) : Expression(node) {} - static ComplexCartesian Builder(); - static ComplexCartesian Builder(Expression child0, Expression child1); + static ComplexCartesian Builder() { return TreeHandle::FixedArityBuilder(); } + static ComplexCartesian Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } // Getters Expression real() { return childAtIndex(0); } diff --git a/poincare/include/poincare/condensed_sum_layout.h b/poincare/include/poincare/condensed_sum_layout.h index 9c95a20d9..93c8ca9f9 100644 --- a/poincare/include/poincare/condensed_sum_layout.h +++ b/poincare/include/poincare/condensed_sum_layout.h @@ -51,7 +51,7 @@ private: class CondensedSumLayout final : public Layout { public: - static CondensedSumLayout Builder(Layout base, Layout subscript, Layout superscript); + static CondensedSumLayout Builder(Layout base, Layout subscript, Layout superscript) { return TreeHandle::FixedArityBuilder(ArrayBuilder(base, subscript, superscript).array(), 3); } CondensedSumLayout() = delete; }; diff --git a/poincare/include/poincare/confidence_interval.h b/poincare/include/poincare/confidence_interval.h index a030d0998..8f9652b89 100644 --- a/poincare/include/poincare/confidence_interval.h +++ b/poincare/include/poincare/confidence_interval.h @@ -45,7 +45,7 @@ class ConfidenceInterval : public Expression { friend class SimplePredictionInterval; public: ConfidenceInterval(const ConfidenceIntervalNode * n) : Expression(n) {} - static ConfidenceInterval Builder(Expression child0, Expression child1); + static ConfidenceInterval Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("confidence", 2, &UntypedBuilderTwoChildren); // Expression @@ -57,7 +57,7 @@ private: class SimplePredictionInterval final : public ConfidenceInterval { public: SimplePredictionInterval(const SimplePredictionIntervalNode * n) : ConfidenceInterval(n) {} - static SimplePredictionInterval Builder(Expression child0, Expression child1); + static SimplePredictionInterval Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("prediction", 2, &UntypedBuilderTwoChildren); }; diff --git a/poincare/include/poincare/conjugate.h b/poincare/include/poincare/conjugate.h index af45d709b..f2324c1f4 100644 --- a/poincare/include/poincare/conjugate.h +++ b/poincare/include/poincare/conjugate.h @@ -41,7 +41,7 @@ private: class Conjugate final : public Expression { public: Conjugate(const ConjugateNode * n) : Expression(n) {} - static Conjugate Builder(Expression child); + static Conjugate Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("conj", 1, &UntypedBuilderOneChild);; diff --git a/poincare/include/poincare/conjugate_layout.h b/poincare/include/poincare/conjugate_layout.h index fe0bf5ea9..8dabdf3cf 100644 --- a/poincare/include/poincare/conjugate_layout.h +++ b/poincare/include/poincare/conjugate_layout.h @@ -40,7 +40,7 @@ private: class ConjugateLayout final : public Layout { public: - static ConjugateLayout Builder(Layout child); + static ConjugateLayout Builder(Layout child) { return TreeHandle::FixedArityBuilder(&child, 1); } ConjugateLayout() = delete; }; diff --git a/poincare/include/poincare/cosine.h b/poincare/include/poincare/cosine.h index 532abf06f..8617103ee 100644 --- a/poincare/include/poincare/cosine.h +++ b/poincare/include/poincare/cosine.h @@ -46,7 +46,7 @@ private: class Cosine final : public Expression { public: Cosine(const CosineNode * n) : Expression(n) {} - static Cosine Builder(Expression child); + static Cosine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cos", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/derivative.h b/poincare/include/poincare/derivative.h index e2bd29ad1..b4a76a19b 100644 --- a/poincare/include/poincare/derivative.h +++ b/poincare/include/poincare/derivative.h @@ -51,15 +51,8 @@ private: class Derivative final : public Expression { public: Derivative(const DerivativeNode * n) : Expression(n) {} - static Derivative Builder(Expression child0, Symbol child1, Expression child2); - static Expression UntypedBuilder(Expression children) { - assert(children.type() == ExpressionNode::Type::Matrix); - if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { - // Second parameter must be a Symbol. - return Expression(); - } - return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2)); - } + static Derivative Builder(Expression child0, Symbol child1, Expression child2) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1, child2).array(), 3); } + static Expression UntypedBuilder(Expression children); static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("diff", 3, &UntypedBuilder); Expression shallowReduce(); diff --git a/poincare/include/poincare/determinant.h b/poincare/include/poincare/determinant.h index d4a392d76..e80c2ceb3 100644 --- a/poincare/include/poincare/determinant.h +++ b/poincare/include/poincare/determinant.h @@ -35,7 +35,7 @@ private: class Determinant final : public Expression { public: Determinant(const DeterminantNode * n) : Expression(n) {} - static Determinant Builder(Expression child); + static Determinant Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("det", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/division.h b/poincare/include/poincare/division.h index c1bf207b5..e73617d7c 100644 --- a/poincare/include/poincare/division.h +++ b/poincare/include/poincare/division.h @@ -61,8 +61,8 @@ private: class Division final : public Expression { public: Division(const DivisionNode * n) : Expression(n) {} - static Division Builder(); - static Division Builder(Expression numerator, Expression denominator); + static Division Builder() { return TreeHandle::FixedArityBuilder(); } + static Division Builder(Expression numerator, Expression denominator) { return TreeHandle::FixedArityBuilder(ArrayBuilder(numerator, denominator).array(), 2); } Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; diff --git a/poincare/include/poincare/division_quotient.h b/poincare/include/poincare/division_quotient.h index e74f8c8a3..f68c03b81 100644 --- a/poincare/include/poincare/division_quotient.h +++ b/poincare/include/poincare/division_quotient.h @@ -38,7 +38,7 @@ private: class DivisionQuotient final : public Expression { public: DivisionQuotient(const DivisionQuotientNode * n) : Expression(n) {} - static DivisionQuotient Builder(Expression child0, Expression child1); + static DivisionQuotient Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("quo", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/division_remainder.h b/poincare/include/poincare/division_remainder.h index 9a4033005..9089fa60a 100644 --- a/poincare/include/poincare/division_remainder.h +++ b/poincare/include/poincare/division_remainder.h @@ -39,7 +39,7 @@ private: class DivisionRemainder final : public Expression { public: DivisionRemainder(const DivisionRemainderNode * n) : Expression(n) {} - static DivisionRemainder Builder(Expression child0, Expression child1); + static DivisionRemainder Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("rem", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/empty_expression.h b/poincare/include/poincare/empty_expression.h index 332430992..80b83ead8 100644 --- a/poincare/include/poincare/empty_expression.h +++ b/poincare/include/poincare/empty_expression.h @@ -33,7 +33,7 @@ private: class EmptyExpression final : public Expression { public: - static EmptyExpression Builder(); + static EmptyExpression Builder() { return TreeHandle::FixedArityBuilder(); } EmptyExpression(const EmptyExpressionNode * n) : Expression(n) {} }; diff --git a/poincare/include/poincare/equal.h b/poincare/include/poincare/equal.h index e191b12ba..7a7b87303 100644 --- a/poincare/include/poincare/equal.h +++ b/poincare/include/poincare/equal.h @@ -35,7 +35,7 @@ private: class Equal final : public Expression { public: Equal(const EqualNode * n) : Expression(n) {} - static Equal Builder(Expression child0, Expression child1); + static Equal Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } // For the equation A = B, create the reduced expression A-B Expression standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; diff --git a/poincare/include/poincare/expression.h b/poincare/include/poincare/expression.h index b250a00cb..e5c20b901 100644 --- a/poincare/include/poincare/expression.h +++ b/poincare/include/poincare/expression.h @@ -1,6 +1,7 @@ #ifndef POINCARE_EXPRESSION_REFERENCE_H #define POINCARE_EXPRESSION_REFERENCE_H +#include #include #include #include diff --git a/poincare/include/poincare/factor.h b/poincare/include/poincare/factor.h index 84d300a5d..8ca451238 100644 --- a/poincare/include/poincare/factor.h +++ b/poincare/include/poincare/factor.h @@ -37,7 +37,7 @@ private: class Factor final : public Expression { public: Factor(const FactorNode * n) : Expression(n) {} - static Factor Builder(Expression child); + static Factor Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("factor", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/factorial.h b/poincare/include/poincare/factorial.h index c76129c69..2ea2ddb59 100644 --- a/poincare/include/poincare/factorial.h +++ b/poincare/include/poincare/factorial.h @@ -52,8 +52,7 @@ private: class Factorial final : public Expression { public: Factorial(const FactorialNode * n) : Expression(n) {} - static Factorial Builder(); - static Factorial Builder(Expression child); + static Factorial Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } Expression shallowReduce(); Expression shallowBeautify(); diff --git a/poincare/include/poincare/floor.h b/poincare/include/poincare/floor.h index c1c7736ee..a7a06be5a 100644 --- a/poincare/include/poincare/floor.h +++ b/poincare/include/poincare/floor.h @@ -44,7 +44,7 @@ private: class Floor final : public Expression { public: Floor(const FloorNode * n) : Expression(n) {} - static Floor Builder(Expression child); + static Floor Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("floor", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/floor_layout.h b/poincare/include/poincare/floor_layout.h index 77ee2b986..0e560a917 100644 --- a/poincare/include/poincare/floor_layout.h +++ b/poincare/include/poincare/floor_layout.h @@ -29,7 +29,7 @@ protected: class FloorLayout final : public Layout { public: - static FloorLayout Builder(Layout child); + static FloorLayout Builder(Layout child) { return TreeHandle::FixedArityBuilder(&child, 1); } FloorLayout() = delete; }; diff --git a/poincare/include/poincare/frac_part.h b/poincare/include/poincare/frac_part.h index 3858deeec..d4ea74b51 100644 --- a/poincare/include/poincare/frac_part.h +++ b/poincare/include/poincare/frac_part.h @@ -44,7 +44,7 @@ private: class FracPart final : public Expression { public: FracPart(const FracPartNode * n) : Expression(n) {} - static FracPart Builder(Expression child); + static FracPart Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("frac", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/fraction_layout.h b/poincare/include/poincare/fraction_layout.h index 17df46c28..03b3979b0 100644 --- a/poincare/include/poincare/fraction_layout.h +++ b/poincare/include/poincare/fraction_layout.h @@ -58,7 +58,7 @@ private: class FractionLayout final : public Layout { public: - static FractionLayout Builder(Layout numerator, Layout denominator); + static FractionLayout Builder(Layout child0, Layout child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } FractionLayout() = delete; }; diff --git a/poincare/include/poincare/ghost.h b/poincare/include/poincare/ghost.h index da30640df..1c7d3b56c 100644 --- a/poincare/include/poincare/ghost.h +++ b/poincare/include/poincare/ghost.h @@ -12,12 +12,7 @@ namespace Poincare { class Ghost final : public TreeHandle { public: - static Ghost Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(GhostNode)); - GhostNode * node = new (bufferNode) GhostNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); - } + static Ghost Builder() { return TreeHandle::FixedArityBuilder(); } }; } diff --git a/poincare/include/poincare/great_common_divisor.h b/poincare/include/poincare/great_common_divisor.h index 318b78d93..89ffdb891 100644 --- a/poincare/include/poincare/great_common_divisor.h +++ b/poincare/include/poincare/great_common_divisor.h @@ -37,7 +37,7 @@ private: class GreatCommonDivisor final : public Expression { public: GreatCommonDivisor(const GreatCommonDivisorNode * n) : Expression(n) {} - static GreatCommonDivisor Builder(Expression child0, Expression child1); + static GreatCommonDivisor Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("gcd", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/grid_layout.h b/poincare/include/poincare/grid_layout.h index 9510c75f9..d6f8f8f70 100644 --- a/poincare/include/poincare/grid_layout.h +++ b/poincare/include/poincare/grid_layout.h @@ -89,7 +89,8 @@ private: class GridLayout : public Layout { public: GridLayout(const GridLayoutNode * n) : Layout(n) {} - static GridLayout Builder(); + static GridLayout Builder() { return TreeHandle::NAryBuilder(); } + void setDimensions(int rows, int columns); void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor) { Layout::addChildAtIndex(l, index, currentNumberOfChildren, cursor); diff --git a/poincare/include/poincare/horizontal_layout.h b/poincare/include/poincare/horizontal_layout.h index 2b39ecd29..6f11a7b78 100644 --- a/poincare/include/poincare/horizontal_layout.h +++ b/poincare/include/poincare/horizontal_layout.h @@ -1,7 +1,6 @@ #ifndef POINCARE_HORIZONTAL_LAYOUT_NODE_H #define POINCARE_HORIZONTAL_LAYOUT_NODE_H -#include #include #include @@ -68,18 +67,12 @@ class HorizontalLayout final : public Layout { public: // Constructors HorizontalLayout(HorizontalLayoutNode * n) : Layout(n) {} - static HorizontalLayout Builder(); + static HorizontalLayout Builder() { return TreeHandle::NAryBuilder(); } static HorizontalLayout Builder(Layout l) { return HorizontalLayout::Builder(&l, 1); } static HorizontalLayout Builder(Layout l1, Layout l2) { return HorizontalLayout::Builder(ArrayBuilder(l1, l2).array(), 2); } static HorizontalLayout Builder(Layout l1, Layout l2, Layout l3) { return HorizontalLayout::Builder(ArrayBuilder(l1, l2, l3).array(), 3); } static HorizontalLayout Builder(Layout l1, Layout l2, Layout l3, Layout l4) { return HorizontalLayout::Builder(ArrayBuilder(l1, l2, l3, l4).array(), 4); } - static HorizontalLayout Builder(const Layout * children, size_t numberOfChildren) { - HorizontalLayout h = HorizontalLayout::Builder(); - for (size_t i = 0; i < numberOfChildren; i++) { - h.addChildAtIndexInPlace(children[i], i, i); - } - return h; - } + static HorizontalLayout Builder(Layout * children, size_t numberOfChildren) { return TreeHandle::NAryBuilder(static_cast(children), numberOfChildren); } void addChildAtIndex(Layout l, int index, int currentNumberOfChildren, LayoutCursor * cursor, bool removeEmptyChildren = false); // Remove puts a child at the end of the pool diff --git a/poincare/include/poincare/hyperbolic_arc_cosine.h b/poincare/include/poincare/hyperbolic_arc_cosine.h index 3ebeccbd8..59f6e725f 100644 --- a/poincare/include/poincare/hyperbolic_arc_cosine.h +++ b/poincare/include/poincare/hyperbolic_arc_cosine.h @@ -36,7 +36,7 @@ private: class HyperbolicArcCosine final : public HyperbolicTrigonometricFunction { public: HyperbolicArcCosine(const HyperbolicArcCosineNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicArcCosine Builder(Expression child); + static HyperbolicArcCosine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("acosh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/hyperbolic_arc_sine.h b/poincare/include/poincare/hyperbolic_arc_sine.h index 464235abe..5f8b4d4b7 100644 --- a/poincare/include/poincare/hyperbolic_arc_sine.h +++ b/poincare/include/poincare/hyperbolic_arc_sine.h @@ -36,7 +36,7 @@ private: class HyperbolicArcSine final : public HyperbolicTrigonometricFunction { public: HyperbolicArcSine(const HyperbolicArcSineNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicArcSine Builder(Expression child); + static HyperbolicArcSine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("asinh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/hyperbolic_arc_tangent.h b/poincare/include/poincare/hyperbolic_arc_tangent.h index 16b08b342..2244efbf5 100644 --- a/poincare/include/poincare/hyperbolic_arc_tangent.h +++ b/poincare/include/poincare/hyperbolic_arc_tangent.h @@ -36,7 +36,7 @@ private: class HyperbolicArcTangent final : public HyperbolicTrigonometricFunction { public: HyperbolicArcTangent(const HyperbolicArcTangentNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicArcTangent Builder(Expression child); + static HyperbolicArcTangent Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("atanh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/hyperbolic_cosine.h b/poincare/include/poincare/hyperbolic_cosine.h index 2704a87a0..67ab4cf80 100644 --- a/poincare/include/poincare/hyperbolic_cosine.h +++ b/poincare/include/poincare/hyperbolic_cosine.h @@ -36,7 +36,7 @@ private: class HyperbolicCosine final : public HyperbolicTrigonometricFunction { public: HyperbolicCosine(const HyperbolicCosineNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicCosine Builder(Expression child); + static HyperbolicCosine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("cosh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/hyperbolic_sine.h b/poincare/include/poincare/hyperbolic_sine.h index 8aeadd16e..6686b4647 100644 --- a/poincare/include/poincare/hyperbolic_sine.h +++ b/poincare/include/poincare/hyperbolic_sine.h @@ -36,7 +36,7 @@ private: class HyperbolicSine final : public HyperbolicTrigonometricFunction { public: HyperbolicSine(const HyperbolicSineNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicSine Builder(Expression child); + static HyperbolicSine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sinh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/hyperbolic_tangent.h b/poincare/include/poincare/hyperbolic_tangent.h index 321f5581e..ba6ec8693 100644 --- a/poincare/include/poincare/hyperbolic_tangent.h +++ b/poincare/include/poincare/hyperbolic_tangent.h @@ -36,7 +36,7 @@ private: class HyperbolicTangent final : public HyperbolicTrigonometricFunction { public: HyperbolicTangent(const HyperbolicTangentNode * n) : HyperbolicTrigonometricFunction(n) {} - static HyperbolicTangent Builder(Expression child); + static HyperbolicTangent Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tanh", 1, &UntypedBuilderOneChild); }; diff --git a/poincare/include/poincare/imaginary_part.h b/poincare/include/poincare/imaginary_part.h index 882d9ebfa..c26367424 100644 --- a/poincare/include/poincare/imaginary_part.h +++ b/poincare/include/poincare/imaginary_part.h @@ -45,7 +45,7 @@ private: class ImaginaryPart final : public Expression { public: ImaginaryPart(const ImaginaryPartNode * n) : Expression(n) {} - static ImaginaryPart Builder(Expression child); + static ImaginaryPart Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("im", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/integral.h b/poincare/include/poincare/integral.h index 1ebefe772..241521fc2 100644 --- a/poincare/include/poincare/integral.h +++ b/poincare/include/poincare/integral.h @@ -55,15 +55,9 @@ private: class Integral final : public Expression { public: Integral(const IntegralNode * n) : Expression(n) {} - static Integral Builder(Expression child0, Symbol child1, Expression child2, Expression child3); - static Expression UntypedBuilder(Expression children) { - assert(children.type() == ExpressionNode::Type::Matrix); - if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { - // Second parameter must be a Symbol. - return Expression(); - } - return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); - } + static Integral Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1, child2, child3).array(), 4); } + static Expression UntypedBuilder(Expression children); + static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("int", 4, &UntypedBuilder); // Expression diff --git a/poincare/include/poincare/integral_layout.h b/poincare/include/poincare/integral_layout.h index 79f6e8a73..30b8901cf 100644 --- a/poincare/include/poincare/integral_layout.h +++ b/poincare/include/poincare/integral_layout.h @@ -56,7 +56,7 @@ private: class IntegralLayout final : public Layout { public: - static IntegralLayout Builder(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound); + static IntegralLayout Builder(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound) { return TreeHandle::FixedArityBuilder(ArrayBuilder(integrand, differential, lowerBound, upperBound).array(), 4); } IntegralLayout() = delete; }; diff --git a/poincare/include/poincare/layout.h b/poincare/include/poincare/layout.h index 53d3dda14..2dfffdcd9 100644 --- a/poincare/include/poincare/layout.h +++ b/poincare/include/poincare/layout.h @@ -1,6 +1,7 @@ #ifndef POINCARE_LAYOUT_REFERENCE_H #define POINCARE_LAYOUT_REFERENCE_H +#include #include #include diff --git a/poincare/include/poincare/least_common_multiple.h b/poincare/include/poincare/least_common_multiple.h index 0155895b5..1fc06b42a 100644 --- a/poincare/include/poincare/least_common_multiple.h +++ b/poincare/include/poincare/least_common_multiple.h @@ -37,7 +37,7 @@ private: class LeastCommonMultiple final : public Expression { public: LeastCommonMultiple(const LeastCommonMultipleNode * n) : Expression(n) {} - static LeastCommonMultiple Builder(Expression child0, Expression child1); + static LeastCommonMultiple Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("lcm", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/left_parenthesis_layout.h b/poincare/include/poincare/left_parenthesis_layout.h index 66f52047b..ffc0fe6df 100644 --- a/poincare/include/poincare/left_parenthesis_layout.h +++ b/poincare/include/poincare/left_parenthesis_layout.h @@ -35,7 +35,7 @@ protected: class LeftParenthesisLayout final : public Layout { public: - static LeftParenthesisLayout Builder(); + static LeftParenthesisLayout Builder() { return TreeHandle::FixedArityBuilder(); } LeftParenthesisLayout() = delete; }; diff --git a/poincare/include/poincare/left_square_bracket_layout.h b/poincare/include/poincare/left_square_bracket_layout.h index 558e69e3b..00720398a 100644 --- a/poincare/include/poincare/left_square_bracket_layout.h +++ b/poincare/include/poincare/left_square_bracket_layout.h @@ -29,7 +29,7 @@ protected: class LeftSquareBracketLayout final : public Layout { public: - static LeftSquareBracketLayout Builder(); + static LeftSquareBracketLayout Builder() { return TreeHandle::FixedArityBuilder(); } LeftSquareBracketLayout() = delete; }; diff --git a/poincare/include/poincare/logarithm.h b/poincare/include/poincare/logarithm.h index eede67cea..0826fe76e 100644 --- a/poincare/include/poincare/logarithm.h +++ b/poincare/include/poincare/logarithm.h @@ -44,7 +44,7 @@ public: class Logarithm final : public Expression { public: Logarithm(const LogarithmNode<2> * n) : Expression(n) {} - static Logarithm Builder(Expression child0, Expression child1); + static Logarithm Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder>(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 2, &UntypedBuilderTwoChildren); Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); @@ -60,7 +60,7 @@ private: class CommonLogarithm : public Expression { public: CommonLogarithm(const LogarithmNode<1> * n) : Expression(n) {} - static CommonLogarithm Builder(Expression child); + static CommonLogarithm Builder(Expression child) { return TreeHandle::FixedArityBuilder>(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("log", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/matrix.h b/poincare/include/poincare/matrix.h index 790d7b556..96188ed5a 100644 --- a/poincare/include/poincare/matrix.h +++ b/poincare/include/poincare/matrix.h @@ -63,7 +63,7 @@ class Matrix final : public Expression { friend class GlobalContext; public: Matrix(const MatrixNode * node) : Expression(node) {} - static Matrix Builder(); + static Matrix Builder() { return TreeHandle::NAryBuilder(); } void setDimensions(int rows, int columns); int numberOfRows() const { return node()->numberOfRows(); } diff --git a/poincare/include/poincare/matrix_complex.h b/poincare/include/poincare/matrix_complex.h index 73a750a88..2566b1d44 100644 --- a/poincare/include/poincare/matrix_complex.h +++ b/poincare/include/poincare/matrix_complex.h @@ -57,7 +57,7 @@ class MatrixComplex final : public Evaluation { friend class MatrixComplexNode; public: MatrixComplex(MatrixComplexNode * node) : Evaluation(node) {} - static MatrixComplex Builder(); + static MatrixComplex Builder() { return TreeHandle::NAryBuilder, MatrixComplexNode>(); } static MatrixComplex Builder(std::complex * operands, int numberOfRows, int numberOfColumns); static MatrixComplex Undefined(); static MatrixComplex createIdentity(int dim); diff --git a/poincare/include/poincare/matrix_dimension.h b/poincare/include/poincare/matrix_dimension.h index 99dab0e30..ec1aa0663 100644 --- a/poincare/include/poincare/matrix_dimension.h +++ b/poincare/include/poincare/matrix_dimension.h @@ -35,7 +35,7 @@ private: class MatrixDimension final : public Expression { public: MatrixDimension(const MatrixDimensionNode * n) : Expression(n) {} - static MatrixDimension Builder(Expression child); + static MatrixDimension Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("dim", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/matrix_inverse.h b/poincare/include/poincare/matrix_inverse.h index ea3ca6ce2..cd551cf21 100644 --- a/poincare/include/poincare/matrix_inverse.h +++ b/poincare/include/poincare/matrix_inverse.h @@ -34,7 +34,7 @@ private: class MatrixInverse final : public Expression { public: MatrixInverse(const MatrixInverseNode * n) : Expression(n) {} - static MatrixInverse Builder(Expression child); + static MatrixInverse Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("inverse", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/matrix_layout.h b/poincare/include/poincare/matrix_layout.h index 519c6c585..21cf04985 100644 --- a/poincare/include/poincare/matrix_layout.h +++ b/poincare/include/poincare/matrix_layout.h @@ -58,16 +58,8 @@ class MatrixLayout /*final*/ : public GridLayout { friend class MatrixLayoutNode; public: MatrixLayout(const MatrixLayoutNode * n) : GridLayout(n) {} - static MatrixLayout Builder(); - static MatrixLayout Builder(Layout l1, Layout l2, Layout l3, Layout l4) { - MatrixLayout m = MatrixLayout::Builder(); - m.addChildAtIndexInPlace(l1, 0, 0); - m.addChildAtIndexInPlace(l2, 1, 1); - m.addChildAtIndexInPlace(l3, 2, 2); - m.addChildAtIndexInPlace(l4, 3, 3); - m.setDimensions(2, 2); - return m; - } + static MatrixLayout Builder() { return TreeHandle::NAryBuilder(); } + static MatrixLayout Builder(Layout l1, Layout l2, Layout l3, Layout l4); bool hasGreySquares() const { return node()->hasGreySquares(); } void addGreySquares() { node()->addGreySquares(); } diff --git a/poincare/include/poincare/matrix_trace.h b/poincare/include/poincare/matrix_trace.h index 9f729a09c..2192d36c9 100644 --- a/poincare/include/poincare/matrix_trace.h +++ b/poincare/include/poincare/matrix_trace.h @@ -34,7 +34,7 @@ private: class MatrixTrace final : public Expression { public: MatrixTrace(const MatrixTraceNode * n) : Expression(n) {} - static MatrixTrace Builder(Expression child); + static MatrixTrace Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("trace", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/matrix_transpose.h b/poincare/include/poincare/matrix_transpose.h index 9f5951d9d..25e35102d 100644 --- a/poincare/include/poincare/matrix_transpose.h +++ b/poincare/include/poincare/matrix_transpose.h @@ -34,7 +34,7 @@ private: class MatrixTranspose final : public Expression { public: MatrixTranspose(const MatrixTransposeNode * n) : Expression(n) {} - static MatrixTranspose Builder(Expression child); + static MatrixTranspose Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("transpose", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/multiplication.h b/poincare/include/poincare/multiplication.h index 9b4dba610..e2a191c6f 100644 --- a/poincare/include/poincare/multiplication.h +++ b/poincare/include/poincare/multiplication.h @@ -2,7 +2,6 @@ #define POINCARE_MULTIPLICATION_H #include -#include #include namespace Poincare { @@ -67,7 +66,7 @@ class Multiplication final : public NAryExpression { friend class Power; public: Multiplication(const MultiplicationNode * n) : NAryExpression(n) {} - static Multiplication Builder(); + static Multiplication Builder() { return TreeHandle::NAryBuilder(); } static Multiplication Builder(Expression e1) { return Multiplication::Builder(&e1, 1); } static Multiplication Builder(Expression e1, Expression e2) { return Multiplication::Builder(ArrayBuilder(e1, e2).array(), 2); } static Multiplication Builder(Expression e1, Expression e2, Expression e3) { return Multiplication::Builder(ArrayBuilder(e1, e2, e3).array(), 3); } @@ -81,7 +80,7 @@ public: Expression denominator(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const; private: // Constructors - static Multiplication Builder(Expression * children, size_t numberOfChildren); + static Multiplication Builder(Expression * children, size_t numberOfChildren) { return TreeHandle::NAryBuilder(children, numberOfChildren); } // Simplification Expression privateShallowReduce(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target, bool expand, bool canBeInterrupted); diff --git a/poincare/include/poincare/naperian_logarithm.h b/poincare/include/poincare/naperian_logarithm.h index 712b85f27..acb96931d 100644 --- a/poincare/include/poincare/naperian_logarithm.h +++ b/poincare/include/poincare/naperian_logarithm.h @@ -44,7 +44,7 @@ private: class NaperianLogarithm final : public Expression { public: NaperianLogarithm(const NaperianLogarithmNode * n) : Expression(n) {} - static NaperianLogarithm Builder(Expression child); + static NaperianLogarithm Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("ln", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/nth_root.h b/poincare/include/poincare/nth_root.h index f0d637622..a043a7e2c 100644 --- a/poincare/include/poincare/nth_root.h +++ b/poincare/include/poincare/nth_root.h @@ -35,7 +35,7 @@ private: class NthRoot final : public Expression { public: NthRoot(const NthRootNode * n) : Expression(n) {} - static NthRoot Builder(Expression child0, Expression child1); + static NthRoot Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("root", 2, &UntypedBuilderTwoChildren); Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); diff --git a/poincare/include/poincare/opposite.h b/poincare/include/poincare/opposite.h index 424486585..40bbdd5a1 100644 --- a/poincare/include/poincare/opposite.h +++ b/poincare/include/poincare/opposite.h @@ -47,8 +47,8 @@ public: class Opposite final : public Expression { public: Opposite(const OppositeNode * n) : Expression(n) {} - static Opposite Builder(); - static Opposite Builder(Expression child); + static Opposite Builder() { return TreeHandle::FixedArityBuilder(); } + static Opposite Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); }; diff --git a/poincare/include/poincare/parenthesis.h b/poincare/include/poincare/parenthesis.h index ba8b2197e..bf1aa5c23 100644 --- a/poincare/include/poincare/parenthesis.h +++ b/poincare/include/poincare/parenthesis.h @@ -38,7 +38,7 @@ private: class Parenthesis final : public Expression { public: Parenthesis(const ParenthesisNode * n) : Expression(n) {} - static Parenthesis Builder(Expression child); + static Parenthesis Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } // Expression Expression shallowReduce(); }; diff --git a/poincare/include/poincare/permute_coefficient.h b/poincare/include/poincare/permute_coefficient.h index 8ec9da24a..f80b81096 100644 --- a/poincare/include/poincare/permute_coefficient.h +++ b/poincare/include/poincare/permute_coefficient.h @@ -41,7 +41,7 @@ private: class PermuteCoefficient final : public Expression { public: PermuteCoefficient(const PermuteCoefficientNode * n) : Expression(n) {} - static PermuteCoefficient Builder(Expression child0, Expression child1); + static PermuteCoefficient Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("permute", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/power.h b/poincare/include/poincare/power.h index 2c30a77ff..3799bec05 100644 --- a/poincare/include/poincare/power.h +++ b/poincare/include/poincare/power.h @@ -67,7 +67,7 @@ class Power final : public Expression { friend class Round; public: Power(const PowerNode * n) : Expression(n) {} - static Power Builder(Expression base, Expression exponent); + static Power Builder(Expression base, Expression exponent) { return TreeHandle::FixedArityBuilder(ArrayBuilder(base, exponent).array(), 2); } Expression setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); int getPolynomialCoefficients(Context & context, const char * symbolName, Expression coefficients[]) const; diff --git a/poincare/include/poincare/prediction_interval.h b/poincare/include/poincare/prediction_interval.h index 69da94c98..a664cfcea 100644 --- a/poincare/include/poincare/prediction_interval.h +++ b/poincare/include/poincare/prediction_interval.h @@ -37,7 +37,7 @@ private: class PredictionInterval final : public Expression { public: PredictionInterval(const PredictionIntervalNode * n) : Expression(n) {} - static PredictionInterval Builder(Expression child0, Expression child1); + static PredictionInterval Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("prediction95", 2, &UntypedBuilderTwoChildren); // Expression diff --git a/poincare/include/poincare/product.h b/poincare/include/poincare/product.h index 9a37e7868..c9dbaeb66 100644 --- a/poincare/include/poincare/product.h +++ b/poincare/include/poincare/product.h @@ -35,15 +35,9 @@ class Product final : public Expression { friend class ProductNode; public: Product(const ProductNode * n) : Expression(n) {} - static Product Builder(Expression child0, Symbol child1, Expression child2, Expression child3); - static Expression UntypedBuilder(Expression children) { - assert(children.type() == ExpressionNode::Type::Matrix); - if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { - // Second parameter must be a Symbol. - return Expression(); - } - return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); - } + static Product Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1, child2, child3).array(), 4); } + static Expression UntypedBuilder(Expression children); + static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("product", 4, &UntypedBuilder); }; diff --git a/poincare/include/poincare/product_layout.h b/poincare/include/poincare/product_layout.h index eeb28ec79..3ea063232 100644 --- a/poincare/include/poincare/product_layout.h +++ b/poincare/include/poincare/product_layout.h @@ -25,7 +25,7 @@ private: class ProductLayout final : public Layout { public: - static ProductLayout Builder(Layout argument, Layout variable, Layout lowerB, Layout upperB); + static ProductLayout Builder(Layout argument, Layout variable, Layout lowerB, Layout upperB) { return TreeHandle::FixedArityBuilder(ArrayBuilder(argument, variable, lowerB, upperB).array(), 4); } ProductLayout() = delete; }; diff --git a/poincare/include/poincare/randint.h b/poincare/include/poincare/randint.h index 292dc33cd..6d1b93516 100644 --- a/poincare/include/poincare/randint.h +++ b/poincare/include/poincare/randint.h @@ -41,7 +41,7 @@ class Randint final : public Expression { friend class RandintNode; public: Randint(const RandintNode * n) : Expression(n) {} - static Randint Builder(Expression child0, Expression child1); + static Randint Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("randint", 2, &UntypedBuilderTwoChildren); }; diff --git a/poincare/include/poincare/random.h b/poincare/include/poincare/random.h index 0446a25f9..b1982bceb 100644 --- a/poincare/include/poincare/random.h +++ b/poincare/include/poincare/random.h @@ -43,7 +43,7 @@ class Random final : public Expression { friend class RandomNode; public: Random(const RandomNode * n) : Expression(n) {} - static Random Builder(); + static Random Builder() { return TreeHandle::FixedArityBuilder(); } static Expression UntypedBuilder(Expression children) { assert(children.type() == ExpressionNode::Type::Matrix); return Builder(); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("random", 0, &UntypedBuilder); diff --git a/poincare/include/poincare/real_part.h b/poincare/include/poincare/real_part.h index 79b9cfd38..eefdc61eb 100644 --- a/poincare/include/poincare/real_part.h +++ b/poincare/include/poincare/real_part.h @@ -45,7 +45,7 @@ private: class RealPart final : public Expression { public: RealPart(const RealPartNode * n) : Expression(n) {} - static RealPart Builder(Expression child); + static RealPart Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("re", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/right_parenthesis_layout.h b/poincare/include/poincare/right_parenthesis_layout.h index 779039803..2f3f03d9f 100644 --- a/poincare/include/poincare/right_parenthesis_layout.h +++ b/poincare/include/poincare/right_parenthesis_layout.h @@ -36,7 +36,7 @@ protected: class RightParenthesisLayout final : public Layout { public: - static RightParenthesisLayout Builder(); + static RightParenthesisLayout Builder() { return TreeHandle::FixedArityBuilder(); } RightParenthesisLayout() = delete; }; diff --git a/poincare/include/poincare/right_square_bracket_layout.h b/poincare/include/poincare/right_square_bracket_layout.h index 8c7ff1332..161ade869 100644 --- a/poincare/include/poincare/right_square_bracket_layout.h +++ b/poincare/include/poincare/right_square_bracket_layout.h @@ -29,7 +29,7 @@ protected: class RightSquareBracketLayout final : public Layout { public: - static RightSquareBracketLayout Builder(); + static RightSquareBracketLayout Builder() { return TreeHandle::FixedArityBuilder(); } RightSquareBracketLayout() = delete; }; diff --git a/poincare/include/poincare/round.h b/poincare/include/poincare/round.h index 2fc0075b6..f08c6ee41 100644 --- a/poincare/include/poincare/round.h +++ b/poincare/include/poincare/round.h @@ -38,7 +38,7 @@ private: class Round final : public Expression { public: Round(const RoundNode * n) : Expression(n) {} - static Round Builder(Expression child0, Expression child1); + static Round Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("round", 2, &UntypedBuilderTwoChildren); Expression shallowReduce(); diff --git a/poincare/include/poincare/sign_function.h b/poincare/include/poincare/sign_function.h index 2a4889e45..23d197933 100644 --- a/poincare/include/poincare/sign_function.h +++ b/poincare/include/poincare/sign_function.h @@ -45,7 +45,7 @@ private: class SignFunction final : public Expression { public: SignFunction(const SignFunctionNode * n) : Expression(n) {} - static SignFunction Builder(Expression child); + static SignFunction Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sign", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/sine.h b/poincare/include/poincare/sine.h index 75d65d604..5137f0b5f 100644 --- a/poincare/include/poincare/sine.h +++ b/poincare/include/poincare/sine.h @@ -48,7 +48,7 @@ private: class Sine final : public Expression { public: Sine(const SineNode * n) : Expression(n) {} - static Sine Builder(Expression child); + static Sine Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sin", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/square_root.h b/poincare/include/poincare/square_root.h index bf9629e62..4ea8737d1 100644 --- a/poincare/include/poincare/square_root.h +++ b/poincare/include/poincare/square_root.h @@ -41,7 +41,7 @@ private: class SquareRoot final : public Expression { public: SquareRoot(const SquareRootNode * n) : Expression(n) {} - static SquareRoot Builder(Expression child); + static SquareRoot Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static_assert('\x91' == Ion::Charset::Root, "Charset error"); static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("\x91", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/store.h b/poincare/include/poincare/store.h index e9db5570b..dbedd4df0 100644 --- a/poincare/include/poincare/store.h +++ b/poincare/include/poincare/store.h @@ -40,7 +40,7 @@ class Store final : public Expression { friend class StoreNode; public: Store(const StoreNode * n) : Expression(n) {} - static Store Builder(Expression value, SymbolAbstract symbol); + static Store Builder(Expression value, SymbolAbstract symbol) { return TreeHandle::FixedArityBuilder(ArrayBuilder(value, symbol).array(), 2); } // Store const SymbolAbstract symbol() const { diff --git a/poincare/include/poincare/subtraction.h b/poincare/include/poincare/subtraction.h index 3fd149bcc..9c43f93af 100644 --- a/poincare/include/poincare/subtraction.h +++ b/poincare/include/poincare/subtraction.h @@ -55,8 +55,8 @@ private: class Subtraction final : public Expression { public: Subtraction(const SubtractionNode * n) : Expression(n) {} - static Subtraction Builder(); - static Subtraction Builder(Expression child0, Expression child1); + static Subtraction Builder() { return TreeHandle::FixedArityBuilder(); } + static Subtraction Builder(Expression child0, Expression child1) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1).array(), 2); } // Expression Expression shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target); diff --git a/poincare/include/poincare/sum.h b/poincare/include/poincare/sum.h index 503591c84..4256a18c5 100644 --- a/poincare/include/poincare/sum.h +++ b/poincare/include/poincare/sum.h @@ -35,15 +35,9 @@ class Sum final : public Expression { friend class SumNode; public: Sum(const SumNode * n) : Expression(n) {} - static Sum Builder(Expression child0, Symbol child1, Expression child2, Expression child3); - static Expression UntypedBuilder(Expression children) { - assert(children.type() == ExpressionNode::Type::Matrix); - if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { - // Second parameter must be a Symbol. - return Expression(); - } - return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); - } + static Sum Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { return TreeHandle::FixedArityBuilder(ArrayBuilder(child0, child1, child2, child3).array(), 4); } + static Expression UntypedBuilder(Expression children); + static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("sum", 4, &UntypedBuilder); }; diff --git a/poincare/include/poincare/sum_layout.h b/poincare/include/poincare/sum_layout.h index b7999571e..57c6206db 100644 --- a/poincare/include/poincare/sum_layout.h +++ b/poincare/include/poincare/sum_layout.h @@ -23,7 +23,7 @@ private: class SumLayout final : public Layout { public: - static SumLayout Builder(Layout argument, Layout variable, Layout lowerB, Layout upperB); + static SumLayout Builder(Layout argument, Layout variable, Layout lowerB, Layout upperB) { return TreeHandle::FixedArityBuilder(ArrayBuilder(argument, variable, lowerB, upperB).array(), 4); } SumLayout() = delete; }; diff --git a/poincare/include/poincare/tangent.h b/poincare/include/poincare/tangent.h index ea04dd640..ee1ff3ec4 100644 --- a/poincare/include/poincare/tangent.h +++ b/poincare/include/poincare/tangent.h @@ -46,7 +46,7 @@ private: class Tangent final : public Expression { public: Tangent(const TangentNode * n) : Expression(n) {} - static Tangent Builder(Expression child); + static Tangent Builder(Expression child) { return TreeHandle::FixedArityBuilder(&child, 1); } static constexpr Expression::FunctionHelper s_functionHelper = Expression::FunctionHelper("tan", 1, &UntypedBuilderOneChild); diff --git a/poincare/include/poincare/tree_handle.h b/poincare/include/poincare/tree_handle.h index 881d95206..5fd9ca72e 100644 --- a/poincare/include/poincare/tree_handle.h +++ b/poincare/include/poincare/tree_handle.h @@ -20,6 +20,8 @@ namespace Poincare { * equivalent to Logarithm l = Logarithm(clone())). */ class TreeHandle { + template + friend class ArrayBuilder; friend class TreeNode; friend class TreePool; public: @@ -108,8 +110,14 @@ protected: node()->retain(); } } + // WARNING: if the children table is the result of a cast, the object downcasted has to be the same size as a TreeHandle. - static TreeHandle BuildWithBasicChildren(TreeNode * node, TreeHandle * children = nullptr, int numberOfChildren = 0); + template + static T NAryBuilder(TreeHandle * children = nullptr, size_t numberOfChildren = 0); + template + static T FixedArityBuilder(TreeHandle * children = nullptr, size_t numberOfChildren = 0); + + static TreeHandle BuildWithGhostChildren(TreeNode * node); void setIdentifierAndRetain(int newId); void setTo(const TreeHandle & tr); @@ -127,6 +135,9 @@ protected: int m_identifier; private: + template + static TreeHandle Builder(); + void detachFromParent(); // Add ghost children on layout construction void buildGhostChildren(); diff --git a/poincare/include/poincare/undefined.h b/poincare/include/poincare/undefined.h index 8891fe236..3413d8bd9 100644 --- a/poincare/include/poincare/undefined.h +++ b/poincare/include/poincare/undefined.h @@ -42,7 +42,7 @@ protected: class Undefined final : public Number { public: Undefined(const UndefinedNode * n) : Number(n) {} - static Undefined Builder(); + static Undefined Builder() { return TreeHandle::FixedArityBuilder(); } static const char * Name() { return "undef"; } diff --git a/poincare/include/poincare/unreal.h b/poincare/include/poincare/unreal.h index 232f3607d..fdc54ac68 100644 --- a/poincare/include/poincare/unreal.h +++ b/poincare/include/poincare/unreal.h @@ -39,7 +39,7 @@ private: class Unreal final : public Number { public: - static Unreal Builder(); + static Unreal Builder() { return TreeHandle::FixedArityBuilder(); } Unreal() = delete; static const char * Name() { return "unreal"; diff --git a/poincare/src/absolute_value.cpp b/poincare/src/absolute_value.cpp index 2999aef0f..a1053c10b 100644 --- a/poincare/src/absolute_value.cpp +++ b/poincare/src/absolute_value.cpp @@ -31,12 +31,6 @@ Expression AbsoluteValueNode::shallowReduce(Context & context, Preferences::Comp return AbsoluteValue(this).shallowReduce(context, complexFormat, angleUnit, target); } -AbsoluteValue AbsoluteValue::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(AbsoluteValueNode)); - AbsoluteValueNode * node = new (bufferNode) AbsoluteValueNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression AbsoluteValue::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(s == ExpressionNode::Sign::Positive); diff --git a/poincare/src/absolute_value_layout.cpp b/poincare/src/absolute_value_layout.cpp deleted file mode 100644 index 0d445c654..000000000 --- a/poincare/src/absolute_value_layout.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -namespace Poincare { - -AbsoluteValueLayout AbsoluteValueLayout::Builder(Layout child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(AbsoluteValueLayoutNode)); - AbsoluteValueLayoutNode * node = new (bufferNode) AbsoluteValueLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} - -} diff --git a/poincare/src/addition.cpp b/poincare/src/addition.cpp index 21a12a206..d9ae3cae6 100644 --- a/poincare/src/addition.cpp +++ b/poincare/src/addition.cpp @@ -87,21 +87,6 @@ int Addition::getPolynomialCoefficients(Context & context, const char * symbolNa return deg; } -Addition Addition::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(AdditionNode)); - AdditionNode * node = new (bufferNode) AdditionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -Addition Addition::Builder(Expression * children, size_t numberOfChildren) { - Addition a = Addition::Builder(); - for (size_t i = 0; i < numberOfChildren; i++) { - a.addChildAtIndexInPlace(children[i], i, i); - } - return a; -} - Expression Addition::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { /* Beautifying AdditionNode essentially consists in adding Subtractions if * needed. diff --git a/poincare/src/arc_cosine.cpp b/poincare/src/arc_cosine.cpp index f32d5f6c5..f0895fe00 100644 --- a/poincare/src/arc_cosine.cpp +++ b/poincare/src/arc_cosine.cpp @@ -48,12 +48,6 @@ Complex ArcCosineNode::computeOnComplex(const std::complex c, Preferences: return Complex::Builder(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit)); } -ArcCosine ArcCosine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ArcCosineNode)); - ArcCosineNode * node = new (bufferNode) ArcCosineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression ArcCosine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/arc_sine.cpp b/poincare/src/arc_sine.cpp index 450c8df5f..eb2fc0d21 100644 --- a/poincare/src/arc_sine.cpp +++ b/poincare/src/arc_sine.cpp @@ -48,12 +48,6 @@ Complex ArcSineNode::computeOnComplex(const std::complex c, Preferences::C return Complex::Builder(Trigonometry::ConvertRadianToAngleUnit(result, angleUnit)); } -ArcSine ArcSine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ArcSineNode)); - ArcSineNode * node = new (bufferNode) ArcSineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression ArcSine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/arc_tangent.cpp b/poincare/src/arc_tangent.cpp index 71fae7d4c..c63d9c7f6 100644 --- a/poincare/src/arc_tangent.cpp +++ b/poincare/src/arc_tangent.cpp @@ -48,12 +48,6 @@ Expression ArcTangentNode::shallowReduce(Context & context, Preferences::Complex return ArcTangent(this).shallowReduce(context, complexFormat, angleUnit, target); } -ArcTangent ArcTangent::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ArcTangentNode)); - ArcTangentNode * node = new (bufferNode) ArcTangentNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression ArcTangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/binomial_coefficient.cpp b/poincare/src/binomial_coefficient.cpp index 5a039966d..0c77913ff 100644 --- a/poincare/src/binomial_coefficient.cpp +++ b/poincare/src/binomial_coefficient.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -54,12 +53,6 @@ T BinomialCoefficientNode::compute(T k, T n) { return std::round(result); } -BinomialCoefficient BinomialCoefficient::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(BinomialCoefficientNode)); - BinomialCoefficientNode * node = new (bufferNode) BinomialCoefficientNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression BinomialCoefficient::shallowReduce() { { diff --git a/poincare/src/binomial_coefficient_layout.cpp b/poincare/src/binomial_coefficient_layout.cpp index dc7b95788..410861766 100644 --- a/poincare/src/binomial_coefficient_layout.cpp +++ b/poincare/src/binomial_coefficient_layout.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -107,11 +106,4 @@ void BinomialCoefficientLayoutNode::render(KDContext * ctx, KDPoint p, KDColor e RightParenthesisLayoutNode::RenderWithChildHeight(childHeight, ctx, p.translatedBy(KDPoint(rightParenthesisPointX, 0)), expressionColor, backgroundColor); } -BinomialCoefficientLayout BinomialCoefficientLayout::Builder(Layout n, Layout k) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(BinomialCoefficientLayoutNode)); - BinomialCoefficientLayoutNode * node = new (bufferNode) BinomialCoefficientLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(n,k).array(), 2); - return static_cast(h); -} - -} +} \ No newline at end of file diff --git a/poincare/src/ceiling.cpp b/poincare/src/ceiling.cpp index 9742abffe..7dfeaef7f 100644 --- a/poincare/src/ceiling.cpp +++ b/poincare/src/ceiling.cpp @@ -35,12 +35,6 @@ Expression CeilingNode::shallowReduce(Context & context, Preferences::ComplexFor return Ceiling(this).shallowReduce(); } -Ceiling Ceiling::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(CeilingNode)); - CeilingNode * node = new (bufferNode) CeilingNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Ceiling::shallowReduce() { { diff --git a/poincare/src/ceiling_layout.cpp b/poincare/src/ceiling_layout.cpp deleted file mode 100644 index 0c2c679f7..000000000 --- a/poincare/src/ceiling_layout.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -namespace Poincare { - -CeilingLayout CeilingLayout::Builder(Layout child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(CeilingLayoutNode)); - CeilingLayoutNode * node = new (bufferNode) CeilingLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} - -} diff --git a/poincare/src/char_layout.cpp b/poincare/src/char_layout.cpp index d303a5b89..c938c06ff 100644 --- a/poincare/src/char_layout.cpp +++ b/poincare/src/char_layout.cpp @@ -99,7 +99,7 @@ bool CharLayoutNode::isMultiplicationChar() const { CharLayout CharLayout::Builder(char c, const KDFont * font) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(CharLayoutNode)); CharLayoutNode * node = new (bufferNode) CharLayoutNode(c, font); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/complex.cpp b/poincare/src/complex.cpp index 7ea64fee8..1dc2cca01 100644 --- a/poincare/src/complex.cpp +++ b/poincare/src/complex.cpp @@ -71,7 +71,7 @@ template Complex Complex::Builder(std::complex c) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ComplexNode)); ComplexNode * node = new (bufferNode) ComplexNode(c); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast &>(h); } diff --git a/poincare/src/complex_argument.cpp b/poincare/src/complex_argument.cpp index 9ac1de038..eb6983ec3 100644 --- a/poincare/src/complex_argument.cpp +++ b/poincare/src/complex_argument.cpp @@ -33,12 +33,6 @@ Complex ComplexArgumentNode::computeOnComplex(const std::complex c, Prefer return Complex::Builder(std::arg(c)); } -ComplexArgument ComplexArgument::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ComplexArgumentNode)); - ComplexArgumentNode * node = new (bufferNode) ComplexArgumentNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression ComplexArgument::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/complex_cartesian.cpp b/poincare/src/complex_cartesian.cpp index ccf3d88f1..ce0416d42 100644 --- a/poincare/src/complex_cartesian.cpp +++ b/poincare/src/complex_cartesian.cpp @@ -52,20 +52,6 @@ Complex ComplexCartesianNode::templatedApproximate(Context& context, Preferen return Complex::Builder(a.real(), b.real()); } -ComplexCartesian ComplexCartesian::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ComplexCartesianNode)); - ComplexCartesianNode * node = new (bufferNode) ComplexCartesianNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -ComplexCartesian ComplexCartesian::Builder(Expression real, Expression imag) { - ComplexCartesian c = ComplexCartesian::Builder(); - c.replaceChildAtIndexInPlace(0, real); - c.replaceChildAtIndexInPlace(1, imag); - return c; -} - Expression ComplexCartesian::shallowReduce() { if (imag().isRationalZero()) { Expression r = real(); diff --git a/poincare/src/condensed_sum_layout.cpp b/poincare/src/condensed_sum_layout.cpp index a658e5d5d..c6c60bb14 100644 --- a/poincare/src/condensed_sum_layout.cpp +++ b/poincare/src/condensed_sum_layout.cpp @@ -37,11 +37,4 @@ KDPoint CondensedSumLayoutNode::positionOfChild(LayoutNode * child) { return KDPoint(x,y); } -CondensedSumLayout CondensedSumLayout::Builder(Layout base, Layout subscript, Layout superscript) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(CondensedSumLayoutNode)); - CondensedSumLayoutNode * node = new (bufferNode) CondensedSumLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(base, subscript, superscript).array(), 3); - return static_cast(h); -} - } diff --git a/poincare/src/confidence_interval.cpp b/poincare/src/confidence_interval.cpp index cc47829ac..1f7716e57 100644 --- a/poincare/src/confidence_interval.cpp +++ b/poincare/src/confidence_interval.cpp @@ -52,12 +52,6 @@ int SimplePredictionIntervalNode::serialize(char * buffer, int bufferSize, Prefe return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, SimplePredictionInterval::s_functionHelper.name()); } -ConfidenceInterval ConfidenceInterval::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ConfidenceIntervalNode)); - ConfidenceIntervalNode * node = new (bufferNode) ConfidenceIntervalNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { @@ -105,11 +99,5 @@ Expression ConfidenceInterval::shallowReduce(Context & context, Preferences::Com return matrix; } -SimplePredictionInterval SimplePredictionInterval::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SimplePredictionIntervalNode)); - SimplePredictionIntervalNode * node = new (bufferNode) SimplePredictionIntervalNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} } diff --git a/poincare/src/conjugate.cpp b/poincare/src/conjugate.cpp index a5f40eabf..ba6bfe143 100644 --- a/poincare/src/conjugate.cpp +++ b/poincare/src/conjugate.cpp @@ -64,11 +64,5 @@ Expression Conjugate::shallowReduce(Context & context, Preferences::ComplexForma return *this; } -Conjugate Conjugate::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ConjugateNode)); - ConjugateNode * node = new (bufferNode) ConjugateNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} } diff --git a/poincare/src/conjugate_layout.cpp b/poincare/src/conjugate_layout.cpp index 2522718aa..ac636dcad 100644 --- a/poincare/src/conjugate_layout.cpp +++ b/poincare/src/conjugate_layout.cpp @@ -104,11 +104,4 @@ bool ConjugateLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * n return true; } -ConjugateLayout ConjugateLayout::Builder(Layout child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ConjugateLayoutNode)); - ConjugateLayoutNode * node = new (bufferNode) ConjugateLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} - } diff --git a/poincare/src/cosine.cpp b/poincare/src/cosine.cpp index 46e0a90eb..3f904d83a 100644 --- a/poincare/src/cosine.cpp +++ b/poincare/src/cosine.cpp @@ -50,11 +50,5 @@ Expression Cosine::shallowReduce(Context & context, Preferences::ComplexFormat c return Trigonometry::shallowReduceDirectFunction(*this, context, complexFormat, angleUnit, target); } -Cosine Cosine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(CosineNode)); - CosineNode * node = new (bufferNode) CosineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} } diff --git a/poincare/src/decimal.cpp b/poincare/src/decimal.cpp index f883333c1..1e88397e9 100644 --- a/poincare/src/decimal.cpp +++ b/poincare/src/decimal.cpp @@ -332,7 +332,7 @@ Decimal Decimal::Builder(Integer m, int e) { Decimal Decimal::Builder(size_t size, const Integer & m, int e) { void * bufferNode = TreePool::sharedPool()->alloc(size); DecimalNode * node = new (bufferNode) DecimalNode(m.digits(), m.numberOfDigits(), e, m.isNegative()); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/derivative.cpp b/poincare/src/derivative.cpp index 426878745..cb6f1de12 100644 --- a/poincare/src/derivative.cpp +++ b/poincare/src/derivative.cpp @@ -156,11 +156,13 @@ Expression Derivative::shallowReduce() { return *this; } -Derivative Derivative::Builder(Expression child0, Symbol child1, Expression child2) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(DerivativeNode)); - DerivativeNode * node = new (bufferNode) DerivativeNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1, child2).array(), 3); - return static_cast(h); +Expression Derivative::UntypedBuilder(Expression children) { + assert(children.type() == ExpressionNode::Type::Matrix); + if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { + // Second parameter must be a Symbol. + return Expression(); + } + return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2)); } } diff --git a/poincare/src/determinant.cpp b/poincare/src/determinant.cpp index e0b973e25..7a4a7b110 100644 --- a/poincare/src/determinant.cpp +++ b/poincare/src/determinant.cpp @@ -32,12 +32,6 @@ Expression DeterminantNode::shallowReduce(Context & context, Preferences::Comple return Determinant(this).shallowReduce(context); } -Determinant Determinant::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(DeterminantNode)); - DeterminantNode * node = new (bufferNode) DeterminantNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Determinant::shallowReduce(Context & context) { { diff --git a/poincare/src/division.cpp b/poincare/src/division.cpp index 8a6f5bb49..ae63cb861 100644 --- a/poincare/src/division.cpp +++ b/poincare/src/division.cpp @@ -70,20 +70,6 @@ template MatrixComplex DivisionNode::computeOnMatrices(const Matr // Division -Division Division::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(DivisionNode)); - DivisionNode * node = new (bufferNode) DivisionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -Division Division::Builder(Expression numerator, Expression denominator) { - Division d = Division::Builder(); - d.replaceChildAtIndexInPlace(0, numerator); - d.replaceChildAtIndexInPlace(1, denominator); - return d; -} - Expression Division::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { Expression e = Expression::defaultShallowReduce(); diff --git a/poincare/src/division_quotient.cpp b/poincare/src/division_quotient.cpp index b382a54cc..853eb1b56 100644 --- a/poincare/src/division_quotient.cpp +++ b/poincare/src/division_quotient.cpp @@ -35,12 +35,6 @@ Evaluation DivisionQuotientNode::templatedApproximate(Context& context, Prefe return Complex::Builder(std::floor(f1/f2)); } -DivisionQuotient DivisionQuotient::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(DivisionQuotientNode)); - DivisionQuotientNode * node = new (bufferNode) DivisionQuotientNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression DivisionQuotient::shallowReduce() { { diff --git a/poincare/src/division_remainder.cpp b/poincare/src/division_remainder.cpp index 030fb33ca..f4334e0ee 100644 --- a/poincare/src/division_remainder.cpp +++ b/poincare/src/division_remainder.cpp @@ -36,12 +36,6 @@ Evaluation DivisionRemainderNode::templatedApproximate(Context& context, Pref return Complex::Builder(std::round(f1-f2*std::floor(f1/f2))); } -DivisionRemainder DivisionRemainder::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(DivisionRemainderNode)); - DivisionRemainderNode * node = new (bufferNode) DivisionRemainderNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression DivisionRemainder::shallowReduce() { { diff --git a/poincare/src/empty_expression.cpp b/poincare/src/empty_expression.cpp index cf007c671..882d6311f 100644 --- a/poincare/src/empty_expression.cpp +++ b/poincare/src/empty_expression.cpp @@ -18,11 +18,4 @@ template Evaluation EmptyExpressionNode::templatedApproximate(Con return Complex::Undefined(); } -EmptyExpression EmptyExpression::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(EmptyExpressionNode)); - EmptyExpressionNode * node = new (bufferNode) EmptyExpressionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/empty_layout.cpp b/poincare/src/empty_layout.cpp index f8a0f8f3b..4bed5b777 100644 --- a/poincare/src/empty_layout.cpp +++ b/poincare/src/empty_layout.cpp @@ -99,7 +99,7 @@ EmptyLayout::EmptyLayout(const EmptyLayoutNode * n) : Layout(n) {} EmptyLayout EmptyLayout::Builder(EmptyLayoutNode::Color color, bool visible, const KDFont * font, bool margins) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(EmptyLayoutNode)); EmptyLayoutNode * node = new (bufferNode) EmptyLayoutNode(color, visible, font, margins); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/equal.cpp b/poincare/src/equal.cpp index e3f9f0c3d..0f8c758fe 100644 --- a/poincare/src/equal.cpp +++ b/poincare/src/equal.cpp @@ -41,12 +41,6 @@ Evaluation EqualNode::templatedApproximate(Context& context, Preferences::Com return Complex::Undefined(); } -Equal Equal::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(EqualNode)); - EqualNode * node = new (bufferNode) EqualNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression Equal::standardEquation(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { Expression sub = Subtraction::Builder(childAtIndex(0).clone(), childAtIndex(1).clone()); diff --git a/poincare/src/factor.cpp b/poincare/src/factor.cpp index dd8e005c0..910ce935c 100644 --- a/poincare/src/factor.cpp +++ b/poincare/src/factor.cpp @@ -30,12 +30,6 @@ Expression FactorNode::shallowBeautify(Context & context, Preferences::ComplexFo return Factor(this).shallowBeautify(context, complexFormat, angleUnit); } -Factor Factor::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FactorNode)); - FactorNode * node = new (bufferNode) FactorNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Factor::shallowBeautify(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { Expression c = childAtIndex(0); diff --git a/poincare/src/factorial.cpp b/poincare/src/factorial.cpp index 47786a22b..643d24001 100644 --- a/poincare/src/factorial.cpp +++ b/poincare/src/factorial.cpp @@ -89,12 +89,6 @@ int FactorialNode::serialize(char * buffer, int bufferSize, Preferences::PrintFl return numberOfChar; } -Factorial Factorial::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FactorialNode)); - FactorialNode * node = new (bufferNode) FactorialNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Factorial::shallowReduce() { { diff --git a/poincare/src/float.cpp b/poincare/src/float.cpp index 1a37e4107..3b5f0c453 100644 --- a/poincare/src/float.cpp +++ b/poincare/src/float.cpp @@ -45,7 +45,7 @@ template Float Float::Builder(T value) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FloatNode)); FloatNode * node = new (bufferNode) FloatNode(value); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/floor.cpp b/poincare/src/floor.cpp index 207e1c28e..12cc0cd91 100644 --- a/poincare/src/floor.cpp +++ b/poincare/src/floor.cpp @@ -35,12 +35,6 @@ Expression FloorNode::shallowReduce(Context & context, Preferences::ComplexForma return Floor(this).shallowReduce(); } -Floor Floor::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FloorNode)); - FloorNode * node = new (bufferNode) FloorNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Floor::shallowReduce() { { diff --git a/poincare/src/floor_layout.cpp b/poincare/src/floor_layout.cpp deleted file mode 100644 index d0c04a6dc..000000000 --- a/poincare/src/floor_layout.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -namespace Poincare { - -FloorLayout FloorLayout::Builder(Layout child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FloorLayoutNode)); - FloorLayoutNode * node = new (bufferNode) FloorLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} - -} diff --git a/poincare/src/frac_part.cpp b/poincare/src/frac_part.cpp index 20da772b0..e2877b965 100644 --- a/poincare/src/frac_part.cpp +++ b/poincare/src/frac_part.cpp @@ -31,12 +31,6 @@ Complex FracPartNode::computeOnComplex(const std::complex c, Preferences:: return Complex::Builder(c.real()-std::floor(c.real())); } -FracPart FracPart::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FracPartNode)); - FracPartNode * node = new (bufferNode) FracPartNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression FracPart::shallowReduce() { { diff --git a/poincare/src/fraction_layout.cpp b/poincare/src/fraction_layout.cpp index d9e15d9bd..2b615d11a 100644 --- a/poincare/src/fraction_layout.cpp +++ b/poincare/src/fraction_layout.cpp @@ -216,11 +216,4 @@ void FractionLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo ctx->fillRect(KDRect(p.x()+Metric::FractionAndConjugateHorizontalMargin, fractionLineY, layoutSize().width()-2*Metric::FractionAndConjugateHorizontalMargin, k_fractionLineHeight), expressionColor); } -FractionLayout FractionLayout::Builder(Layout numerator, Layout denominator) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(FractionLayoutNode)); - FractionLayoutNode * node = new (bufferNode) FractionLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(numerator, denominator).array(), 2); - return static_cast(h); -} - -} +} \ No newline at end of file diff --git a/poincare/src/great_common_divisor.cpp b/poincare/src/great_common_divisor.cpp index b07b8242f..7e27cb55c 100644 --- a/poincare/src/great_common_divisor.cpp +++ b/poincare/src/great_common_divisor.cpp @@ -1,5 +1,5 @@ #include -#include + #include #include #include @@ -49,12 +49,6 @@ Evaluation GreatCommonDivisorNode::templatedApproximate(Context& context, Pre return Complex::Builder(std::round((T)a)); } -GreatCommonDivisor GreatCommonDivisor::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(GreatCommonDivisorNode)); - GreatCommonDivisorNode * node = new (bufferNode) GreatCommonDivisorNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression GreatCommonDivisor::shallowReduce() { { diff --git a/poincare/src/grid_layout.cpp b/poincare/src/grid_layout.cpp index e96115515..0907208c7 100644 --- a/poincare/src/grid_layout.cpp +++ b/poincare/src/grid_layout.cpp @@ -268,11 +268,4 @@ void GridLayout::setDimensions(int rows, int columns) { setNumberOfColumns(columns); } -GridLayout GridLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(GridLayoutNode)); - GridLayoutNode * node = new (bufferNode) GridLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -} +} \ No newline at end of file diff --git a/poincare/src/horizontal_layout.cpp b/poincare/src/horizontal_layout.cpp index 8ebb7dd9f..10dc63766 100644 --- a/poincare/src/horizontal_layout.cpp +++ b/poincare/src/horizontal_layout.cpp @@ -353,13 +353,6 @@ bool HorizontalLayoutNode::willReplaceChild(LayoutNode * oldChild, LayoutNode * // HorizontalLayout -HorizontalLayout HorizontalLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HorizontalLayoutNode)); - HorizontalLayoutNode * node = new (bufferNode) HorizontalLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - void HorizontalLayout::addOrMergeChildAtIndex(Layout l, int index, bool removeEmptyChildren, LayoutCursor * cursor) { if (l.isHorizontal()) { mergeChildrenAtIndex(HorizontalLayout(static_cast(l.node())), index, removeEmptyChildren, cursor); diff --git a/poincare/src/hyperbolic_arc_cosine.cpp b/poincare/src/hyperbolic_arc_cosine.cpp index 59f74b32c..b52aa2383 100644 --- a/poincare/src/hyperbolic_arc_cosine.cpp +++ b/poincare/src/hyperbolic_arc_cosine.cpp @@ -26,12 +26,6 @@ Complex HyperbolicArcCosineNode::computeOnComplex(const std::complex c, Pr return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(result, c)); } -HyperbolicArcCosine HyperbolicArcCosine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicArcCosineNode)); - HyperbolicArcCosineNode * node = new (bufferNode) HyperbolicArcCosineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicArcCosineNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicArcCosineNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/hyperbolic_arc_sine.cpp b/poincare/src/hyperbolic_arc_sine.cpp index 38fba0d13..a2c95af34 100644 --- a/poincare/src/hyperbolic_arc_sine.cpp +++ b/poincare/src/hyperbolic_arc_sine.cpp @@ -29,12 +29,6 @@ Complex HyperbolicArcSineNode::computeOnComplex(const std::complex c, Pref return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(result, c)); } -HyperbolicArcSine HyperbolicArcSine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicArcSineNode)); - HyperbolicArcSineNode * node = new (bufferNode) HyperbolicArcSineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicArcSineNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicArcSineNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/hyperbolic_arc_tangent.cpp b/poincare/src/hyperbolic_arc_tangent.cpp index 83b52592b..099835978 100644 --- a/poincare/src/hyperbolic_arc_tangent.cpp +++ b/poincare/src/hyperbolic_arc_tangent.cpp @@ -30,12 +30,6 @@ Complex HyperbolicArcTangentNode::computeOnComplex(const std::complex c, P return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(result, c)); } -HyperbolicArcTangent HyperbolicArcTangent::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicArcTangentNode)); - HyperbolicArcTangentNode * node = new (bufferNode) HyperbolicArcTangentNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicArcTangentNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicArcTangentNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/hyperbolic_cosine.cpp b/poincare/src/hyperbolic_cosine.cpp index cfa001d4a..30f564714 100644 --- a/poincare/src/hyperbolic_cosine.cpp +++ b/poincare/src/hyperbolic_cosine.cpp @@ -18,12 +18,6 @@ Complex HyperbolicCosineNode::computeOnComplex(const std::complex c, Prefe return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(std::cosh(c), c)); } -HyperbolicCosine HyperbolicCosine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicCosineNode)); - HyperbolicCosineNode * node = new (bufferNode) HyperbolicCosineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicCosineNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicCosineNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/hyperbolic_sine.cpp b/poincare/src/hyperbolic_sine.cpp index ef3064d2d..d30b18b82 100644 --- a/poincare/src/hyperbolic_sine.cpp +++ b/poincare/src/hyperbolic_sine.cpp @@ -18,12 +18,6 @@ Complex HyperbolicSineNode::computeOnComplex(const std::complex c, Prefere return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(std::sinh(c), c)); } -HyperbolicSine HyperbolicSine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicSineNode)); - HyperbolicSineNode * node = new (bufferNode) HyperbolicSineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicSineNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicSineNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/hyperbolic_tangent.cpp b/poincare/src/hyperbolic_tangent.cpp index 2f7b3cec8..df19fe5e3 100644 --- a/poincare/src/hyperbolic_tangent.cpp +++ b/poincare/src/hyperbolic_tangent.cpp @@ -18,12 +18,6 @@ Complex HyperbolicTangentNode::computeOnComplex(const std::complex c, Pref return Complex::Builder(Trigonometry::RoundToMeaningfulDigits(std::tanh(c), c)); } -HyperbolicTangent HyperbolicTangent::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(HyperbolicTangentNode)); - HyperbolicTangentNode * node = new (bufferNode) HyperbolicTangentNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} template Complex Poincare::HyperbolicTangentNode::computeOnComplex(std::complex, Preferences::ComplexFormat, Preferences::AngleUnit); template Complex Poincare::HyperbolicTangentNode::computeOnComplex(std::complex, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit); diff --git a/poincare/src/imaginary_part.cpp b/poincare/src/imaginary_part.cpp index 439900869..f50138ddf 100644 --- a/poincare/src/imaginary_part.cpp +++ b/poincare/src/imaginary_part.cpp @@ -24,12 +24,6 @@ Expression ImaginaryPartNode::shallowReduce(Context & context, Preferences::Comp return ImaginaryPart(this).shallowReduce(context, complexFormat, angleUnit, target); } -ImaginaryPart ImaginaryPart::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ImaginaryPartNode)); - ImaginaryPartNode * node = new (bufferNode) ImaginaryPartNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression ImaginaryPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/infinity.cpp b/poincare/src/infinity.cpp index 71eb0287b..a8dc2a552 100644 --- a/poincare/src/infinity.cpp +++ b/poincare/src/infinity.cpp @@ -34,7 +34,7 @@ template Evaluation InfinityNode::templatedApproximate() const { Infinity Infinity::Builder(bool negative) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(InfinityNode)); InfinityNode * node = new (bufferNode) InfinityNode(negative); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/integer.cpp b/poincare/src/integer.cpp index 67fd3e295..51ed772b6 100644 --- a/poincare/src/integer.cpp +++ b/poincare/src/integer.cpp @@ -104,7 +104,7 @@ Integer Integer::BuildInteger(native_uint_t * digits, uint16_t numberOfDigits, b Integer::Integer(native_uint_t * digits, uint16_t numberOfDigits, bool negative) { void * bufferNode = TreePool::sharedPool()->alloc(IntegerSize(numberOfDigits)); IntegerNode * node = new (bufferNode) IntegerNode(digits, numberOfDigits); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); /* Integer is a TreeHandle that keeps an extra integer. We cannot just cast * the TreeHandle in Integer, we have to build a new Integer. To do so, we * pilfer the TreeHandle identifier. */ diff --git a/poincare/src/integral.cpp b/poincare/src/integral.cpp index 91816bb9b..96c565d87 100644 --- a/poincare/src/integral.cpp +++ b/poincare/src/integral.cpp @@ -1,5 +1,5 @@ #include -#include + #include #include #include @@ -210,11 +210,13 @@ T IntegralNode::adaptiveQuadrature(T a, T b, T eps, int numberOfIterations, Cont } #endif -Integral Integral::Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(IntegralNode)); - IntegralNode * node = new (bufferNode) IntegralNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1, child2, child3).array(), 4); - return static_cast(h); +Expression Integral::UntypedBuilder(Expression children) { + assert(children.type() == ExpressionNode::Type::Matrix); + if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { + // Second parameter must be a Symbol. + return Expression(); + } + return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); } Expression Integral::shallowReduce() { diff --git a/poincare/src/integral_layout.cpp b/poincare/src/integral_layout.cpp index 43e366540..b53035fa6 100644 --- a/poincare/src/integral_layout.cpp +++ b/poincare/src/integral_layout.cpp @@ -247,11 +247,4 @@ void IntegralLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCo ctx->drawString("d", dPosition, k_font, expressionColor, backgroundColor); } -IntegralLayout IntegralLayout::Builder(Layout integrand, Layout differential, Layout lowerBound, Layout upperBound) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(IntegralLayoutNode)); - IntegralLayoutNode * node = new (bufferNode) IntegralLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(integrand, differential, lowerBound, upperBound).array(), 4); - return static_cast(h); -} - } diff --git a/poincare/src/least_common_multiple.cpp b/poincare/src/least_common_multiple.cpp index 6096658d7..cc28523fb 100644 --- a/poincare/src/least_common_multiple.cpp +++ b/poincare/src/least_common_multiple.cpp @@ -53,12 +53,6 @@ Evaluation LeastCommonMultipleNode::templatedApproximate(Context& context, Pr return Complex::Builder(product/a); } -LeastCommonMultiple LeastCommonMultiple::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(LeastCommonMultipleNode)); - LeastCommonMultipleNode * node = new (bufferNode) LeastCommonMultipleNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression LeastCommonMultiple::shallowReduce() { { diff --git a/poincare/src/left_parenthesis_layout.cpp b/poincare/src/left_parenthesis_layout.cpp index 1ec811828..8ddd2dea5 100644 --- a/poincare/src/left_parenthesis_layout.cpp +++ b/poincare/src/left_parenthesis_layout.cpp @@ -59,11 +59,4 @@ void LeftParenthesisLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expre RenderWithChildHeight(ParenthesisLayoutNode::ChildHeightGivenLayoutHeight(layoutSize().height()), ctx, p, expressionColor, backgroundColor); } -LeftParenthesisLayout LeftParenthesisLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(LeftParenthesisLayoutNode)); - LeftParenthesisLayoutNode * node = new (bufferNode) LeftParenthesisLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/left_square_bracket_layout.cpp b/poincare/src/left_square_bracket_layout.cpp index 7a64a0253..2a8d85c92 100644 --- a/poincare/src/left_square_bracket_layout.cpp +++ b/poincare/src/left_square_bracket_layout.cpp @@ -8,11 +8,4 @@ void LeftSquareBracketLayoutNode::render(KDContext * ctx, KDPoint p, KDColor exp ctx->fillRect(KDRect(p.x()+k_externWidthMargin, p.y() + childHeight(), k_bracketWidth, k_lineThickness), expressionColor); } -LeftSquareBracketLayout LeftSquareBracketLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(LeftSquareBracketLayoutNode)); - LeftSquareBracketLayoutNode * node = new (bufferNode) LeftSquareBracketLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/logarithm.cpp b/poincare/src/logarithm.cpp index a2ed4480c..4301d3c07 100644 --- a/poincare/src/logarithm.cpp +++ b/poincare/src/logarithm.cpp @@ -1,5 +1,5 @@ #include -#include + #include #include #include @@ -86,13 +86,6 @@ template Evaluation LogarithmNode<2>::templatedApproximate(Contex return Complex::Builder(result); } -CommonLogarithm CommonLogarithm::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(LogarithmNode<1>)); - LogarithmNode<1> * node = new (bufferNode) LogarithmNode<1>(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} - Expression CommonLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ { Expression e = Expression::defaultShallowReduce(); @@ -113,13 +106,6 @@ Expression CommonLogarithm::shallowReduce(Context & context, Preferences::Comple return log.shallowReduce(context, complexFormat, angleUnit, target); } -Logarithm Logarithm::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(LogarithmNode<2>)); - LogarithmNode<2> * node = new (bufferNode) LogarithmNode<2>(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} - Expression Logarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target){ { Expression e = Expression::defaultShallowReduce(); diff --git a/poincare/src/matrix.cpp b/poincare/src/matrix.cpp index 42e0bfad8..f2faeef90 100644 --- a/poincare/src/matrix.cpp +++ b/poincare/src/matrix.cpp @@ -89,13 +89,6 @@ Evaluation MatrixNode::templatedApproximate(Context& context, Preferences::Co // MATRIX -Matrix Matrix::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixNode)); - MatrixNode * node = new (bufferNode) MatrixNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - void Matrix::setDimensions(int rows, int columns) { assert(rows * columns == numberOfChildren()); setNumberOfRows(rows); diff --git a/poincare/src/matrix_complex.cpp b/poincare/src/matrix_complex.cpp index 416b194ea..76eb28e57 100644 --- a/poincare/src/matrix_complex.cpp +++ b/poincare/src/matrix_complex.cpp @@ -130,14 +130,6 @@ MatrixComplex MatrixComplex::Builder(std::complex * operands, int numbe return m; } -template -MatrixComplex MatrixComplex::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixComplexNode)); - MatrixComplexNode * node = new (bufferNode) MatrixComplexNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast &>(h); -} - template MatrixComplex MatrixComplex::Undefined() { std::complex undef = std::complex(NAN, NAN); diff --git a/poincare/src/matrix_dimension.cpp b/poincare/src/matrix_dimension.cpp index 24e1e273e..5390a43d0 100644 --- a/poincare/src/matrix_dimension.cpp +++ b/poincare/src/matrix_dimension.cpp @@ -37,12 +37,6 @@ Evaluation MatrixDimensionNode::templatedApproximate(Context& context, Prefer return MatrixComplex::Builder(operands, 1, 2); } -MatrixDimension MatrixDimension::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixDimensionNode)); - MatrixDimensionNode * node = new (bufferNode) MatrixDimensionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression MatrixDimension::shallowReduce() { { diff --git a/poincare/src/matrix_inverse.cpp b/poincare/src/matrix_inverse.cpp index d12e8164d..24aba3623 100644 --- a/poincare/src/matrix_inverse.cpp +++ b/poincare/src/matrix_inverse.cpp @@ -42,12 +42,6 @@ Evaluation MatrixInverseNode::templatedApproximate(Context& context, Preferen return inverse; } -MatrixInverse MatrixInverse::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixInverseNode)); - MatrixInverseNode * node = new (bufferNode) MatrixInverseNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression MatrixInverse::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/matrix_layout.cpp b/poincare/src/matrix_layout.cpp index e184fc8f1..e7223c3e7 100644 --- a/poincare/src/matrix_layout.cpp +++ b/poincare/src/matrix_layout.cpp @@ -266,11 +266,10 @@ void MatrixLayoutNode::didReplaceChildAtIndex(int index, LayoutCursor * cursor, } } -MatrixLayout MatrixLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixLayoutNode)); - MatrixLayoutNode * node = new (bufferNode) MatrixLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); +MatrixLayout MatrixLayout::Builder(Layout l1, Layout l2, Layout l3, Layout l4) { + MatrixLayout m = TreeHandle::NAryBuilder(ArrayBuilder(l1,l2,l3,l4).array(), 4); + m.setDimensions(2, 2); + return m; } } diff --git a/poincare/src/matrix_trace.cpp b/poincare/src/matrix_trace.cpp index 1ff3c58a1..dbe915cd7 100644 --- a/poincare/src/matrix_trace.cpp +++ b/poincare/src/matrix_trace.cpp @@ -32,12 +32,6 @@ Evaluation MatrixTraceNode::templatedApproximate(Context& context, Preference return result; } -MatrixTrace MatrixTrace::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixTraceNode)); - MatrixTraceNode * node = new (bufferNode) MatrixTraceNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression MatrixTrace::shallowReduce() { { diff --git a/poincare/src/matrix_transpose.cpp b/poincare/src/matrix_transpose.cpp index c7e01c7be..8e8805d98 100644 --- a/poincare/src/matrix_transpose.cpp +++ b/poincare/src/matrix_transpose.cpp @@ -37,12 +37,6 @@ Evaluation MatrixTransposeNode::templatedApproximate(Context& context, Prefer return transpose; } -MatrixTranspose MatrixTranspose::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(MatrixTransposeNode)); - MatrixTransposeNode * node = new (bufferNode) MatrixTransposeNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression MatrixTranspose::shallowReduce() { { diff --git a/poincare/src/multiplication.cpp b/poincare/src/multiplication.cpp index 52efbe73d..29aceb262 100644 --- a/poincare/src/multiplication.cpp +++ b/poincare/src/multiplication.cpp @@ -108,21 +108,6 @@ Expression MultiplicationNode::denominator(Context & context, Preferences::Compl /* Multiplication */ -Multiplication Multiplication::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(AdditionNode)); - MultiplicationNode * node = new (bufferNode) MultiplicationNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -Multiplication Multiplication::Builder(Expression * children, size_t numberOfChildren) { - Multiplication m = Multiplication::Builder(); - for (size_t i = 0; i < numberOfChildren; i++) { - m.addChildAtIndexInPlace(children[i], i, i); - } - return m; -} - template void Multiplication::computeOnArrays(T * m, T * n, T * result, int mNumberOfColumns, int mNumberOfRows, int nNumberOfColumns) { for (int i = 0; i < mNumberOfRows; i++) { diff --git a/poincare/src/naperian_logarithm.cpp b/poincare/src/naperian_logarithm.cpp index 520dd5f3d..29ea6cb9b 100644 --- a/poincare/src/naperian_logarithm.cpp +++ b/poincare/src/naperian_logarithm.cpp @@ -22,12 +22,6 @@ Expression NaperianLogarithmNode::shallowReduce(Context & context, Preferences:: return NaperianLogarithm(this).shallowReduce(context, complexFormat, angleUnit, target); } -NaperianLogarithm NaperianLogarithm::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(NaperianLogarithmNode)); - NaperianLogarithmNode * node = new (bufferNode) NaperianLogarithmNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression NaperianLogarithm::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/nth_root.cpp b/poincare/src/nth_root.cpp index ecb3b2b18..b7cbe9566 100644 --- a/poincare/src/nth_root.cpp +++ b/poincare/src/nth_root.cpp @@ -63,12 +63,6 @@ Evaluation NthRootNode::templatedApproximate(Context& context, Preferences::C return result; } -NthRoot NthRoot::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(NthRootNode)); - NthRootNode * node = new (bufferNode) NthRootNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression NthRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/nth_root_layout.cpp b/poincare/src/nth_root_layout.cpp index 59cab9af3..4e7dd4573 100644 --- a/poincare/src/nth_root_layout.cpp +++ b/poincare/src/nth_root_layout.cpp @@ -273,14 +273,17 @@ void NthRootLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCol NthRootLayout NthRootLayout::Builder(Layout child) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(NthRootLayoutNode)); NthRootLayoutNode * node = new (bufferNode) NthRootLayoutNode(false); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); + h.replaceChildAtIndexInPlace(0, child); return static_cast(h); } NthRootLayout NthRootLayout::Builder(Layout child, Layout index) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(NthRootLayoutNode)); NthRootLayoutNode * node = new (bufferNode) NthRootLayoutNode(true); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child, index).array(), 2); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); + h.replaceChildAtIndexInPlace(0, child); + h.replaceChildAtIndexInPlace(1, index); return static_cast(h); } diff --git a/poincare/src/opposite.cpp b/poincare/src/opposite.cpp index 9d2d33613..ec4665c05 100644 --- a/poincare/src/opposite.cpp +++ b/poincare/src/opposite.cpp @@ -69,19 +69,6 @@ Expression OppositeNode::shallowReduce(Context & context, Preferences::ComplexFo /* Simplification */ -Opposite Opposite::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(OppositeNode)); - OppositeNode * node = new (bufferNode) OppositeNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -Opposite Opposite::Builder(Expression child) { - Opposite d = Opposite::Builder(); - d.replaceChildAtIndexInPlace(0, child); - return d; -} - Expression Opposite::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression result = Expression::defaultShallowReduce(); if (result.isUndefined()) { diff --git a/poincare/src/parenthesis.cpp b/poincare/src/parenthesis.cpp index ce87f1b89..3ad088ca9 100644 --- a/poincare/src/parenthesis.cpp +++ b/poincare/src/parenthesis.cpp @@ -25,12 +25,6 @@ Evaluation ParenthesisNode::templatedApproximate(Context& context, Preference return childAtIndex(0)->approximate(T(), context, complexFormat, angleUnit); } -Parenthesis Parenthesis::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ParenthesisNode)); - ParenthesisNode * node = new (bufferNode) ParenthesisNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Parenthesis::shallowReduce() { Expression e = Expression::defaultShallowReduce(); diff --git a/poincare/src/permute_coefficient.cpp b/poincare/src/permute_coefficient.cpp index 767295862..2e01cd395 100644 --- a/poincare/src/permute_coefficient.cpp +++ b/poincare/src/permute_coefficient.cpp @@ -49,12 +49,6 @@ Evaluation PermuteCoefficientNode::templatedApproximate(Context& context, Pre return Complex::Builder(std::round(result)); } -PermuteCoefficient PermuteCoefficient::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(PermuteCoefficientNode)); - PermuteCoefficientNode * node = new (bufferNode) PermuteCoefficientNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression PermuteCoefficient::shallowReduce() { { diff --git a/poincare/src/power.cpp b/poincare/src/power.cpp index 2384d25f9..4c90df701 100644 --- a/poincare/src/power.cpp +++ b/poincare/src/power.cpp @@ -234,13 +234,6 @@ template MatrixComplex PowerNode::computeOnMatrices(const MatrixC // Power -Power Power::Builder(Expression base, Expression exponent) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(PowerNode)); - PowerNode * node = new (bufferNode) PowerNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(base, exponent).array(), 2); - return static_cast(h); -} - Expression Power::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { assert(s == ExpressionNode::Sign::Positive); if (childAtIndex(0).sign(context) == ExpressionNode::Sign::Negative) { diff --git a/poincare/src/prediction_interval.cpp b/poincare/src/prediction_interval.cpp index 7f95e0f84..ac894f92b 100644 --- a/poincare/src/prediction_interval.cpp +++ b/poincare/src/prediction_interval.cpp @@ -46,12 +46,6 @@ Evaluation PredictionIntervalNode::templatedApproximate(Context& context, Pre return MatrixComplex::Builder(operands, 1, 2); } -PredictionInterval PredictionInterval::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(PredictionIntervalNode)); - PredictionIntervalNode * node = new (bufferNode) PredictionIntervalNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression PredictionInterval::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/product.cpp b/poincare/src/product.cpp index bb422b85d..ff6d7a8e0 100644 --- a/poincare/src/product.cpp +++ b/poincare/src/product.cpp @@ -46,11 +46,13 @@ Evaluation ProductNode::templatedApproximateWithNextTerm(Evaluation a, Eva return MultiplicationNode::computeOnMatrices(m, n, complexFormat); } -Product Product::Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ProductNode)); - ProductNode * node = new (bufferNode) ProductNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1, child2, child3).array(), 4); - return static_cast(h); +Expression Product::UntypedBuilder(Expression children) { + assert(children.type() == ExpressionNode::Type::Matrix); + if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { + // Second parameter must be a Symbol. + return Expression(); + } + return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); } } diff --git a/poincare/src/product_layout.cpp b/poincare/src/product_layout.cpp index 3685b81f9..8be05d651 100644 --- a/poincare/src/product_layout.cpp +++ b/poincare/src/product_layout.cpp @@ -30,11 +30,4 @@ void ProductLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionCol SequenceLayoutNode::render(ctx, p, expressionColor, backgroundColor); } -ProductLayout ProductLayout::Builder(Layout argument, Layout variable, Layout lowerB, Layout upperB) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(ProductLayoutNode)); - ProductLayoutNode * node = new (bufferNode) ProductLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(argument, variable, lowerB, upperB).array(), 4); - return static_cast(h); -} - } diff --git a/poincare/src/randint.cpp b/poincare/src/randint.cpp index 645e1ca88..47d20058b 100644 --- a/poincare/src/randint.cpp +++ b/poincare/src/randint.cpp @@ -37,11 +37,5 @@ template Evaluation RandintNode::templateApproximate(Context & c return Complex::Builder(result); } -Randint Randint::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RandintNode)); - RandintNode * node = new (bufferNode) RandintNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} } diff --git a/poincare/src/random.cpp b/poincare/src/random.cpp index 3d8e0e546..cd5e309a0 100644 --- a/poincare/src/random.cpp +++ b/poincare/src/random.cpp @@ -29,13 +29,6 @@ template Evaluation RandomNode::templateApproximate() const { return Complex::Builder(Random::random()); } -Random Random::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RandomNode)); - RandomNode * node = new (bufferNode) RandomNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - Expression Random::setSign(ExpressionNode::Sign s, Context * context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) { assert(s == ExpressionNode::Sign::Positive); return *this; diff --git a/poincare/src/rational.cpp b/poincare/src/rational.cpp index 3247d5c2d..fa86aba96 100644 --- a/poincare/src/rational.cpp +++ b/poincare/src/rational.cpp @@ -220,7 +220,7 @@ Rational Rational::IntegerPower(const Rational & i, const Integer & j) { Rational Rational::Builder(const native_uint_t * i, uint8_t numeratorSize, const native_uint_t * j, uint8_t denominatorSize, bool negative) { void * bufferNode = TreePool::sharedPool()->alloc(RationalSize(numeratorSize, denominatorSize)); RationalNode * node = new (bufferNode) RationalNode(i, numeratorSize, j, denominatorSize, negative); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/real_part.cpp b/poincare/src/real_part.cpp index 95cf8534b..3fc75d22f 100644 --- a/poincare/src/real_part.cpp +++ b/poincare/src/real_part.cpp @@ -24,12 +24,6 @@ Expression RealPartNode::shallowReduce(Context & context, Preferences::ComplexFo return RealPart(this).shallowReduce(context, complexFormat, angleUnit, target); } -RealPart RealPart::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RealPartNode)); - RealPartNode * node = new (bufferNode) RealPartNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression RealPart::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/right_parenthesis_layout.cpp b/poincare/src/right_parenthesis_layout.cpp index 68a267f96..d38345f20 100644 --- a/poincare/src/right_parenthesis_layout.cpp +++ b/poincare/src/right_parenthesis_layout.cpp @@ -59,11 +59,4 @@ void RightParenthesisLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expr RenderWithChildHeight(ParenthesisLayoutNode::ChildHeightGivenLayoutHeight(layoutSize().height()), ctx, p, expressionColor, backgroundColor); } -RightParenthesisLayout RightParenthesisLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RightParenthesisLayoutNode)); - RightParenthesisLayoutNode * node = new (bufferNode) RightParenthesisLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/right_square_bracket_layout.cpp b/poincare/src/right_square_bracket_layout.cpp index 3707312fe..cd1608a02 100644 --- a/poincare/src/right_square_bracket_layout.cpp +++ b/poincare/src/right_square_bracket_layout.cpp @@ -8,11 +8,4 @@ void RightSquareBracketLayoutNode::render(KDContext * ctx, KDPoint p, KDColor ex ctx->fillRect(KDRect(p.x()+k_widthMargin-k_bracketWidth+1, p.y() + childHeight(), k_bracketWidth, k_lineThickness), expressionColor); } -RightSquareBracketLayout RightSquareBracketLayout::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RightSquareBracketLayoutNode)); - RightSquareBracketLayoutNode * node = new (bufferNode) RightSquareBracketLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/round.cpp b/poincare/src/round.cpp index 5fc95311c..416bd2037 100644 --- a/poincare/src/round.cpp +++ b/poincare/src/round.cpp @@ -38,12 +38,6 @@ Evaluation RoundNode::templatedApproximate(Context& context, Preferences::Com return Complex::Builder(std::round(f1*err)/err); } -Round Round::Builder(Expression child0, Expression child1) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(RoundNode)); - RoundNode * node = new (bufferNode) RoundNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1).array(), 2); - return static_cast(h); -} Expression Round::shallowReduce() { { diff --git a/poincare/src/sign_function.cpp b/poincare/src/sign_function.cpp index 0099b02c7..cc8a8bf09 100644 --- a/poincare/src/sign_function.cpp +++ b/poincare/src/sign_function.cpp @@ -51,12 +51,6 @@ Complex SignFunctionNode::computeOnComplex(const std::complex c, Preferenc return Complex::Builder(1.0); } -SignFunction SignFunction::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SignFunctionNode)); - SignFunctionNode * node = new (bufferNode) SignFunctionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression SignFunction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/sine.cpp b/poincare/src/sine.cpp index 5099382d2..7241efff2 100644 --- a/poincare/src/sine.cpp +++ b/poincare/src/sine.cpp @@ -34,12 +34,6 @@ Expression SineNode::shallowReduce(Context & context, Preferences::ComplexFormat return Sine(this).shallowReduce(context, complexFormat, angleUnit, target); } -Sine Sine::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SineNode)); - SineNode * node = new (bufferNode) SineNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Sine::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/square_root.cpp b/poincare/src/square_root.cpp index 747d48c51..243bbc37a 100644 --- a/poincare/src/square_root.cpp +++ b/poincare/src/square_root.cpp @@ -42,12 +42,6 @@ Expression SquareRootNode::shallowReduce(Context & context, Preferences::Complex return SquareRoot(this).shallowReduce(context, complexFormat, angleUnit, target); } -SquareRoot SquareRoot::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SquareRootNode)); - SquareRootNode * node = new (bufferNode) SquareRootNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression SquareRoot::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/store.cpp b/poincare/src/store.cpp index 4eb0830b0..0c085733d 100644 --- a/poincare/src/store.cpp +++ b/poincare/src/store.cpp @@ -69,13 +69,6 @@ Expression Store::shallowReduce(Context & context, Preferences::ComplexFormat co return storedExpression; } -Store Store::Builder(Expression value, SymbolAbstract symbol) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(StoreNode)); - StoreNode * node = new (bufferNode) StoreNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(value, symbol).array(), 2); - return static_cast(h); -} - Expression Store::storeValueForSymbol(Context& context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit) const { Expression finalValue; if (symbol().type() == ExpressionNode::Type::Function) { diff --git a/poincare/src/subtraction.cpp b/poincare/src/subtraction.cpp index 8978925b0..44f670cf2 100644 --- a/poincare/src/subtraction.cpp +++ b/poincare/src/subtraction.cpp @@ -56,20 +56,6 @@ Expression SubtractionNode::shallowReduce(Context & context, Preferences::Comple return Subtraction(this).shallowReduce(context, complexFormat, angleUnit, target); } -Subtraction Subtraction::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SubtractionNode)); - SubtractionNode * node = new (bufferNode) SubtractionNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - -Subtraction Subtraction::Builder(Expression child0, Expression child1) { - Subtraction d = Subtraction::Builder(); - d.replaceChildAtIndexInPlace(0, child0); - d.replaceChildAtIndexInPlace(1, child1); - return d; -} - Expression Subtraction::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { Expression e = Expression::defaultShallowReduce(); if (e.isUndefined()) { diff --git a/poincare/src/sum.cpp b/poincare/src/sum.cpp index e8bdeac55..549cfdba9 100644 --- a/poincare/src/sum.cpp +++ b/poincare/src/sum.cpp @@ -46,11 +46,13 @@ Evaluation SumNode::templatedApproximateWithNextTerm(Evaluation a, Evaluat return AdditionNode::computeOnMatrices(m, n, complexFormat); } -Sum Sum::Builder(Expression child0, Symbol child1, Expression child2, Expression child3) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SumNode)); - SumNode * node = new (bufferNode) SumNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1, child2, child3).array(), 4); - return static_cast(h); +Expression Sum::UntypedBuilder(Expression children) { + assert(children.type() == ExpressionNode::Type::Matrix); + if (children.childAtIndex(1).type() != ExpressionNode::Type::Symbol) { + // Second parameter must be a Symbol. + return Expression(); + } + return Builder(children.childAtIndex(0), children.childAtIndex(1).convert(), children.childAtIndex(2), children.childAtIndex(3)); } } diff --git a/poincare/src/sum_layout.cpp b/poincare/src/sum_layout.cpp index 1297b124a..9c9a079e8 100644 --- a/poincare/src/sum_layout.cpp +++ b/poincare/src/sum_layout.cpp @@ -45,11 +45,4 @@ void SumLayoutNode::render(KDContext * ctx, KDPoint p, KDColor expressionColor, SequenceLayoutNode::render(ctx, p, expressionColor, backgroundColor); } -SumLayout SumLayout::Builder(Layout child0, Layout child1, Layout child2, Layout child3) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(SumLayoutNode)); - SumLayoutNode * node = new (bufferNode) SumLayoutNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, ArrayBuilder(child0, child1, child2, child3).array(), 4); - return static_cast(h); -} - } diff --git a/poincare/src/symbol_abstract.cpp b/poincare/src/symbol_abstract.cpp index 59bdf55f6..9e9a518ad 100644 --- a/poincare/src/symbol_abstract.cpp +++ b/poincare/src/symbol_abstract.cpp @@ -41,7 +41,7 @@ T SymbolAbstract::Builder(const char * name, int length) { size_t size = sizeof(U) + length + 1; void * bufferNode = TreePool::sharedPool()->alloc(size); U * node = new (bufferNode) U(name, length); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } diff --git a/poincare/src/tangent.cpp b/poincare/src/tangent.cpp index cb162eb5a..afb372d38 100644 --- a/poincare/src/tangent.cpp +++ b/poincare/src/tangent.cpp @@ -37,12 +37,6 @@ Expression TangentNode::shallowReduce(Context & context, Preferences::ComplexFor return Tangent(this).shallowReduce(context, complexFormat, angleUnit, target); } -Tangent Tangent::Builder(Expression child) { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(TangentNode)); - TangentNode * node = new (bufferNode) TangentNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &child, 1); - return static_cast(h); -} Expression Tangent::shallowReduce(Context & context, Preferences::ComplexFormat complexFormat, Preferences::AngleUnit angleUnit, ExpressionNode::ReductionTarget target) { { diff --git a/poincare/src/tree_handle.cpp b/poincare/src/tree_handle.cpp index 15dcbd51c..25b2aef27 100644 --- a/poincare/src/tree_handle.cpp +++ b/poincare/src/tree_handle.cpp @@ -1,4 +1,6 @@ #include +#include +#include #include #if POINCARE_TREE_LOG #include @@ -185,7 +187,32 @@ TreeHandle::TreeHandle(const TreeNode * node) : TreeHandle() { } } -TreeHandle TreeHandle::BuildWithBasicChildren(TreeNode * node, TreeHandle * children, int numberOfChildren) { +template +TreeHandle TreeHandle::Builder() { + void * bufferNode = TreePool::sharedPool()->alloc(sizeof(U)); + U * node = new (bufferNode) U(); + return TreeHandle::BuildWithGhostChildren(node); +} + +template +T TreeHandle::NAryBuilder(TreeHandle * children, size_t numberOfChildren) { + TreeHandle h = Builder(); + for (size_t i = 0; i < numberOfChildren; i++) { + h.addChildAtIndexInPlace(children[i], i, i); + } + return static_cast(h); +} + +template +T TreeHandle::FixedArityBuilder(TreeHandle * children, size_t numberOfChildren) { + TreeHandle h = Builder(); + for (size_t i = 0; i < numberOfChildren; i++) { + h.replaceChildAtIndexInPlace(i, children[i]); + } + return static_cast(h); +} + +TreeHandle TreeHandle::BuildWithGhostChildren(TreeNode * node) { assert(node != nullptr); TreePool * pool = TreePool::sharedPool(); int expectedNumberOfChildren = node->numberOfChildren(); @@ -198,17 +225,7 @@ TreeHandle TreeHandle::BuildWithBasicChildren(TreeNode * node, TreeHandle * chil assert((char *)ghost == (char *)node->next() + i*sizeof(GhostNode)); } node->rename(pool->generateIdentifier(), false); - TreeHandle h = TreeHandle(node); - /* Add or replace ghost children by the children given as arguments if - * possible. */ - for (int i = 0; i < numberOfChildren; i++) { - if (i < expectedNumberOfChildren) { - h.replaceChildAtIndexInPlace(i, children[i]); - } else { - h.addChildAtIndexInPlace(children[i], i, i); - } - } - return h; + return TreeHandle(node); } void TreeHandle::setIdentifierAndRetain(int newId) { @@ -243,4 +260,86 @@ void TreeHandle::release(int identifier) { node->release(node->numberOfChildren()); } +template AbsoluteValue TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template AbsoluteValueLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Addition TreeHandle::NAryBuilder(TreeHandle*, size_t); +template ArcCosine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ArcSine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ArcTangent TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template BinomialCoefficient TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template BinomialCoefficientLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Ceiling TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template CeilingLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template CommonLogarithm TreeHandle::FixedArityBuilder >(TreeHandle*, size_t); +template ComplexArgument TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ComplexCartesian TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template CondensedSumLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ConfidenceInterval TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Conjugate TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ConjugateLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Cosine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Derivative TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Determinant TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Division TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template DivisionQuotient TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template DivisionRemainder TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template EmptyExpression TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Equal TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Factor TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Factorial TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Floor TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template FloorLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template FracPart TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template FractionLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template GreatCommonDivisor TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HorizontalLayout TreeHandle::NAryBuilder(TreeHandle*, size_t); +template HyperbolicArcCosine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HyperbolicArcSine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HyperbolicArcTangent TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HyperbolicCosine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HyperbolicSine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template HyperbolicTangent TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ImaginaryPart TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Integral TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template IntegralLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template LeastCommonMultiple TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template LeftParenthesisLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template LeftSquareBracketLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Logarithm TreeHandle::FixedArityBuilder >(TreeHandle*, size_t); +template Matrix TreeHandle::NAryBuilder(TreeHandle*, size_t); +template MatrixComplex TreeHandle::NAryBuilder, MatrixComplexNode >(TreeHandle*, size_t); +template MatrixComplex TreeHandle::NAryBuilder, MatrixComplexNode >(TreeHandle*, size_t); +template MatrixDimension TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template MatrixInverse TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template MatrixTrace TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template MatrixTranspose TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Multiplication TreeHandle::NAryBuilder(TreeHandle*, size_t); +template NaperianLogarithm TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template NthRoot TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Opposite TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Parenthesis TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template PermuteCoefficient TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Power TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template PredictionInterval TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Product TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template ProductLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Randint TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Random TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template RealPart TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template RightParenthesisLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template RightSquareBracketLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Round TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template SignFunction TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template SimplePredictionInterval TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Sine TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template SquareRoot TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Store TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Subtraction TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Sum TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template SumLayout TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Tangent TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Undefined TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template Unreal TreeHandle::FixedArityBuilder(TreeHandle*, size_t); +template MatrixLayout TreeHandle::NAryBuilder(TreeHandle*, size_t); + } diff --git a/poincare/src/undefined.cpp b/poincare/src/undefined.cpp index 0615d830e..7031aec61 100644 --- a/poincare/src/undefined.cpp +++ b/poincare/src/undefined.cpp @@ -34,13 +34,6 @@ template Evaluation UndefinedNode::templatedApproximate() const { return Complex::Undefined(); } -Undefined Undefined::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(UndefinedNode)); - UndefinedNode * node = new (bufferNode) UndefinedNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - template Evaluation UndefinedNode::templatedApproximate() const; template Evaluation UndefinedNode::templatedApproximate() const; } diff --git a/poincare/src/unreal.cpp b/poincare/src/unreal.cpp index d8d45a25e..e60d16bd4 100644 --- a/poincare/src/unreal.cpp +++ b/poincare/src/unreal.cpp @@ -20,11 +20,4 @@ int UnrealNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat return min(Unreal::NameSize(), bufferSize) - 1; } -Unreal Unreal::Builder() { - void * bufferNode = TreePool::sharedPool()->alloc(sizeof(UnrealNode)); - UnrealNode * node = new (bufferNode) UnrealNode(); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); - return static_cast(h); -} - } diff --git a/poincare/src/vertical_offset_layout.cpp b/poincare/src/vertical_offset_layout.cpp index 5686e6f16..5b41e6282 100644 --- a/poincare/src/vertical_offset_layout.cpp +++ b/poincare/src/vertical_offset_layout.cpp @@ -269,7 +269,8 @@ LayoutNode * VerticalOffsetLayoutNode::baseLayout() { VerticalOffsetLayout VerticalOffsetLayout::Builder(Layout l, VerticalOffsetLayoutNode::Type type) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(VerticalOffsetLayoutNode)); VerticalOffsetLayoutNode * node = new (bufferNode) VerticalOffsetLayoutNode(type); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, &l, 1); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); + h.replaceChildAtIndexInPlace(0, l); return static_cast(h); } diff --git a/poincare/test/tree/blob_node.h b/poincare/test/tree/blob_node.h index e2a0c907d..6bbd86395 100644 --- a/poincare/test/tree/blob_node.h +++ b/poincare/test/tree/blob_node.h @@ -26,7 +26,7 @@ public: static BlobByReference Builder(int data = 0) { void * bufferNode = TreePool::sharedPool()->alloc(sizeof(BlobNode)); BlobNode * node = new (bufferNode) BlobNode(data); - TreeHandle h = TreeHandle::BuildWithBasicChildren(node); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); return static_cast(h); } BlobByReference() = delete; diff --git a/poincare/test/tree/pair_node.h b/poincare/test/tree/pair_node.h index c041e186b..a6eb9dd06 100644 --- a/poincare/test/tree/pair_node.h +++ b/poincare/test/tree/pair_node.h @@ -3,7 +3,7 @@ #include #include -#include + namespace Poincare { @@ -24,7 +24,9 @@ public: void * bufferNode = TreePool::sharedPool()->alloc(sizeof(PairNode)); PairNode * node = new (bufferNode) PairNode(); TreeHandle children[2] = {t1, t2}; - TreeHandle h = TreeHandle::BuildWithBasicChildren(node, children, 2); + TreeHandle h = TreeHandle::BuildWithGhostChildren(node); + h.replaceChildAtIndexInPlace(0, t1); + h.replaceChildAtIndexInPlace(1, t2); return static_cast(h); } PairByReference() = delete;