[poincare] EmptyExpression

This commit is contained in:
Léa Saviot
2018-08-27 14:41:17 +02:00
parent 0404b38c94
commit 8f22c7eaa1
5 changed files with 40 additions and 21 deletions

View File

@@ -54,6 +54,7 @@ objs += $(addprefix poincare/src/,\
division.o\
division_quotient.o\
division_remainder.o\
empty_expression.o\
evaluation.o\
expression.o\
expression_lexer.o\

View File

@@ -120,6 +120,7 @@
#include <poincare/determinant.h>
#include <poincare/division_quotient.h>
#include <poincare/division_remainder.h>
#include <poincare/empty_expression.h>
#include <poincare/sine.h>
#include <poincare/tangent.h>
#include <poincare/hyperbolic_arc_cosine.h>

View File

@@ -1,28 +1,45 @@
#ifndef POINCARE_EMPTY_EXPRESSION_H
#define POINCARE_EMPTY_EXPRESSION_H
#include <poincare/static_hierarchy.h>
#include <poincare/evaluation.h>
#include <poincare/expression.h>
namespace Poincare {
/* An empty expression awaits completion by the user. */
// An empty expression awaits completion by the user.
class EmptyExpression : public StaticHierarchy<0> {
class EmptyExpressionNode : public ExpressionNode {
public:
Type type() const override {
return Type::EmptyExpression;
// Allocation Failure
static EmptyExpressionNode * FailedAllocationStaticNode();
EmptyExpressionNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
// TreeNode
size_t size() const override { return sizeof(EmptyExpressionNode); }
int numberOfChildren() const override { return 0; }
#if POINCARE_TREE_LOG
virtual void logNodeName(std::ostream & stream) const override {
stream << "EmptyExpression";
}
#endif
// Properties
Type type() const override { return Type::EmptyExpression; }
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
private:
/* Layout */
LayoutRef createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
/* Evaluation */
// Layout
LayoutReference createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
// Evaluation
Evaluation<float> approximate(SinglePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<float>(context, angleUnit); }
Evaluation<double> approximate(DoublePrecision p, Context& context, Preferences::AngleUnit angleUnit) const override { return templatedApproximate<double>(context, angleUnit); }
template<typename T> Evaluation<T> templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const;
};
class EmptyExpression : public Expression {
public:
EmptyExpression() : Expression(TreePool::sharedPool()->createTreeNode<EmptyExpressionNode>()) {}
EmptyExpression(const EmptyExpressionNode * n) : Expression(n) {}
};
}
#endif

View File

@@ -1,25 +1,28 @@
#include <poincare/empty_expression.h>
#include <poincare/allocation_failure_expression_node.h>
#include <poincare/complex.h>
#include <poincare/empty_layout_node.h>
#include <poincare/layout_helper.h>
#include <poincare/serialization_helper.h>
#include <ion/charset.h>
#include <math.h>
namespace Poincare {
Expression * EmptyExpression::clone() const {
return new EmptyExpression();
EmptyExpressionNode * EmptyExpressionNode::FailedAllocationStaticNode() {
static AllocationFailureExpressionNode<EmptyExpressionNode> failure;
TreePool::sharedPool()->registerStaticNodeIfRequired(&failure);
return &failure;
}
int EmptyExpression::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
int EmptyExpressionNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return SerializationHelper::Char(buffer, bufferSize, Ion::Charset::Empty);
}
LayoutRef EmptyExpression::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
LayoutRef EmptyExpressionNode::createLayout(Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const {
return EmptyLayoutRef();
}
template<typename T> Complex<T> * EmptyExpression::templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const {
return new Complex<T>(Complex<T>::Undefined());
template<typename T> Evaluation<T> EmptyExpressionNode::templatedApproximate(Context& context, Preferences::AngleUnit angleUnit) const {
return Complex<T>::Undefined();
}
}

View File

@@ -189,10 +189,7 @@ inf { poincare_expression_yylval.expression = Undefined(); return UNDEFINED; }
\] { return RIGHT_BRACKET; }
\, { return COMMA; }
\_ { return UNDERSCORE; }
/*
\x97 { poincare_expression_yylval.expression = new EmptyExpression(); return EMPTY; }
*/
\x97 { poincare_expression_yylval.expression = EmptyExpression(); return EMPTY; }
[ ]+ /* Ignore whitespaces */
. { return UNDEFINED_SYMBOL; }