[poincare] UninitializedGhost node

Needed to look for its parent in replaceWithGhost
This commit is contained in:
Léa Saviot
2018-09-03 15:30:12 +02:00
parent 257052f424
commit 392fa7a43d
7 changed files with 53 additions and 3 deletions

View File

@@ -128,6 +128,7 @@ objs += $(addprefix poincare/src/,\
undefined.o\
uninitialized_evaluation_node.o\
uninitialized_expression_node.o\
uninitialized_ghost_node.o\
uninitialized_layout_node.o\
variable_context.o\
)

View File

@@ -22,7 +22,7 @@ public:
static GhostNode * FailedAllocationStaticNode();
TreeNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
// Uninitialized
TreeNode * uninitializedStaticNode() const override { assert(false); return nullptr; }
TreeNode * uninitializedStaticNode() const override;
};
class AllocationFailedGhostNode : public GhostNode {

View File

@@ -0,0 +1,30 @@
#ifndef POINCARE_UNINITIALIZED_GHOST_NODE_H
#define POINCARE_UNINITIALIZED_GHOST_NODE_H
#include <poincare/exception_node.h>
#include <poincare/ghost_node.h>
#include <stdio.h>
namespace Poincare {
class UninitializedGhostNode : public ExceptionNode<GhostNode> {
public:
static UninitializedGhostNode * UninitializedGhostStaticNode();
static int UninitializedGhostStaticNodeIdentifier() { return -3; }
// TreeNode
bool isUninitialized() const override { return true; }
/* There is only one static node, that should never be inserted in the pool,
* so no need for an allocation failure. */
TreeNode * failedAllocationStaticNode() override { assert(false); return nullptr; }
size_t size() const override { return sizeof(UninitializedGhostNode); }
#if POINCARE_TREE_LOG
virtual void logNodeName(std::ostream & stream) const override {
stream << "UninitializedGhost";
}
#endif
};
}
#endif

View File

@@ -244,7 +244,8 @@ Expression Addition::shallowReduce(Context & context, Preferences::AngleUnit ang
Expression result = squashUnaryHierarchy();
// Step 6: Last but not least, let's put everything under a common denominator
if (result == *this && parent().type() != ExpressionNode::Type::Addition) {
Expression p = parent();
if (result == *this && !p.isUninitialized() && p.type() != ExpressionNode::Type::Addition) {
// squashUnaryHierarchy didn't do anything: we're not an unary hierarchy
result = factorizeOnCommonDenominator(context, angleUnit);
}

View File

@@ -1,4 +1,5 @@
#include <poincare/ghost_node.h>
#include <poincare/uninitialized_ghost_node.h>
#include <poincare/tree_pool.h>
namespace Poincare {
@@ -9,4 +10,8 @@ GhostNode * GhostNode::FailedAllocationStaticNode() {
return &failure;
}
TreeNode * GhostNode::uninitializedStaticNode() const {
return UninitializedGhostNode::UninitializedGhostStaticNode();
}
}

View File

@@ -1,6 +1,7 @@
#include <poincare/init.h>
#include <poincare/tree_pool.h>
#include <poincare/uninitialized_expression_node.h>
#include <poincare/uninitialized_ghost_node.h>
namespace Poincare {
@@ -13,7 +14,9 @@ void init() {
pool.registerStaticNode(
UninitializedExpressionNode::UninitializedExpressionStaticNode(),
UninitializedExpressionNode::UninitializedExpressionStaticNodeIdentifier());
pool.registerStaticNode(
UninitializedGhostNode::UninitializedGhostStaticNode(),
UninitializedGhostNode::UninitializedGhostStaticNodeIdentifier());
}
}

View File

@@ -0,0 +1,10 @@
#include <poincare/uninitialized_ghost_node.h>
namespace Poincare {
UninitializedGhostNode * UninitializedGhostNode::UninitializedGhostStaticNode() {
static UninitializedGhostNode exception;
return &exception;
}
}