mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-22 07:10:40 +01:00
[poincare] UninitializedGhost node
Needed to look for its parent in replaceWithGhost
This commit is contained in:
@@ -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\
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
30
poincare/include/poincare/uninitialized_ghost_node.h
Normal file
30
poincare/include/poincare/uninitialized_ghost_node.h
Normal 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
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
10
poincare/src/uninitialized_ghost_node.cpp
Normal file
10
poincare/src/uninitialized_ghost_node.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <poincare/uninitialized_ghost_node.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
UninitializedGhostNode * UninitializedGhostNode::UninitializedGhostStaticNode() {
|
||||
static UninitializedGhostNode exception;
|
||||
return &exception;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user