[poincare] Fix Parenthesis

This commit is contained in:
Léa Saviot
2018-08-09 10:21:11 +02:00
parent 8f12995bfd
commit a53ebb122c
2 changed files with 7 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ public:
LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
// Simplification
Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) override;
Expression shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const override;
// Approximation
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
@@ -35,9 +35,10 @@ private:
template<typename T> Evaluation<T> templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const;
};
class ParenthesisReference : public Expression {
class Parenthesis : public Expression {
public:
ParenthesisReference(Expression exp) : Expression(TreePool::sharedPool()->createTreeNode<ParenthesisNode>()) {
Parenthesis(const ParenthesisNode * n) : Expression(n) {}
Parenthesis(Expression exp) : Expression(TreePool::sharedPool()->createTreeNode<ParenthesisNode>()) {
replaceChildAtIndexInPlace(0, exp);
}
// Expression

View File

@@ -1,6 +1,6 @@
#include <poincare/parenthesis.h>
#include <poincare/allocation_failure_expression_node.h>
#include <assert.h>
#include <poincare/serialization_helper.h>
namespace Poincare {
@@ -18,7 +18,7 @@ LayoutRef ParenthesisNode::createLayout(Preferences::PrintFloatMode floatDisplay
}
int ParenthesisNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return SerializationHelper::Prefix(Parenthesis(const_cast<ParenthesisNode *>(this)), buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "");
return SerializationHelper::Prefix(this, buffer, bufferSize, floatDisplayMode, numberOfSignificantDigits, "");
}
Expression ParenthesisNode::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const {
@@ -32,7 +32,7 @@ Evaluation<T> ParenthesisNode::templatedApproximate(Context& context, Preference
Expression Parenthesis::shallowReduce(Context& context, Preferences::AngleUnit angleUnit) const {
Expression e = Expression::shallowReduce(context, angleUnit);
if (e != *this) {
if (e.isUndefinedOrAllocationFailure()) {
return e;
}
return childAtIndex(0);