mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[poincare] Fix TreeNode logging
This commit is contained in:
@@ -20,8 +20,10 @@ public:
|
||||
static AbsoluteValueLayoutNode * FailedAllocationStaticNode();
|
||||
AbsoluteValueLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(AbsoluteValueLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "AbsoluteValueLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "AbsoluteValueLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
@@ -23,8 +23,10 @@ public:
|
||||
static AdditionNode * FailedAllocationStaticNode();
|
||||
AdditionNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(AdditionNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Addition"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Addition";
|
||||
}
|
||||
#endif
|
||||
|
||||
// ExpressionNode
|
||||
|
||||
@@ -13,11 +13,15 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(AllocationFailureNode<T>); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "AllocationFailure"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 0; }
|
||||
bool isAllocationFailure() const override { return true; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "AllocationFailure[";
|
||||
T::logNodeName(stream);
|
||||
stream << "]";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,10 @@ public:
|
||||
BinomialCoefficientLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(BinomialCoefficientLayoutNode); }
|
||||
int numberOfChildren() const override { return 2; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "BinomialCoefficientLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "BinomialCoefficientLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -17,8 +17,10 @@ public:
|
||||
static CeilingLayoutNode * FailedAllocationStaticNode();
|
||||
CeilingLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(CeilingLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "CeilingLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "CeilingLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -33,11 +33,12 @@ public:
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(CharLayoutNode); }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override {
|
||||
static char Description[] = "Char a";
|
||||
Description[5] = m_char;
|
||||
return Description;
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "CharLayout";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
stream << " char=\"" << m_char << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,10 +18,16 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(ComplexNode<T>); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Evaluation complex"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Complex";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
stream << " real=\"" << this->real() << "\"";
|
||||
stream << " imag=\"" << this->imag() << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
void setComplex(std::complex<T> c);
|
||||
typename Poincare::EvaluationNode<T>::Type type() const override { return Poincare::EvaluationNode<T>::Type::Complex; }
|
||||
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
CondensedSumLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(CondensedSumLayoutNode); }
|
||||
int numberOfChildren() const override { return 3; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override {
|
||||
return "CondensedSumLayout";
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "CondensedSumLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -22,9 +22,9 @@ public:
|
||||
ConjugateLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(ConjugateLayoutNode); }
|
||||
int numberOfChildren() const override { return 1; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override {
|
||||
return "ConjugateLayout";
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "ConjugateLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -30,8 +30,15 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(DecimalNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Decimal"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Decimal";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
char buffer[256];
|
||||
serialize(buffer, sizeof(buffer));
|
||||
stream << " value=\"" << buffer << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
|
||||
@@ -17,10 +17,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(DivisionNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Division"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 2; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Division";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Division; }
|
||||
|
||||
@@ -42,8 +42,10 @@ public:
|
||||
EmptyLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(EmptyLayoutNode); }
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Empty"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "EmptyLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -30,8 +30,13 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(FloatNode<T>); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Float"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Float";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
stream << " value=\"" << m_value << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
|
||||
@@ -18,8 +18,10 @@ public:
|
||||
static FloorLayoutNode * FailedAllocationStaticNode();
|
||||
FloorLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(FloorLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "FloorLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "FloorLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -38,8 +38,10 @@ public:
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(FractionLayoutNode); }
|
||||
int numberOfChildren() const override { return 2; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "FractionLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "FractionLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -12,9 +12,12 @@ public:
|
||||
// TreeNode
|
||||
int numberOfChildren() const override { return 0; }
|
||||
size_t size() const override { return sizeof(GhostNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Ghost"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Ghost";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Ghost
|
||||
bool isGhost() const override { return true; }
|
||||
// Allocation Failure
|
||||
|
||||
@@ -43,8 +43,10 @@ public:
|
||||
m_numberOfChildren-= decrement;
|
||||
}
|
||||
void eraseNumberOfChildren() override { m_numberOfChildren = 0; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Horizontal Layout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "HorizontalLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(InfinityNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream stream) {
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Infinity";
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -133,8 +133,15 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override;
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Integer"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Integer";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
char buffer[256];
|
||||
serialize(buffer, sizeof(buffer));
|
||||
stream << " value=\"" << buffer << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
// ExpressionNode
|
||||
|
||||
@@ -33,8 +33,10 @@ public:
|
||||
IntegralLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(IntegralLayoutNode); }
|
||||
int numberOfChildren() const override { return 3; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "IntegralLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "IntegralLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -25,8 +25,10 @@ public:
|
||||
// TreeNode
|
||||
static LeftParenthesisLayoutNode * FailedAllocationStaticNode();
|
||||
LeftParenthesisLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Left parenthesis"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "LeftParenthesisLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -19,9 +19,12 @@ public:
|
||||
static LeftSquareBracketLayoutNode * FailedAllocationStaticNode();
|
||||
LeftSquareBracketLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(LeftSquareBracketLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "LeftSquareBracketLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "LeftSquareBracketLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
};
|
||||
|
||||
@@ -26,10 +26,16 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(MatrixComplexNode<T>); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Evaluation matrix complex"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return m_numberOfRows*m_numberOfColumns; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "MatrixComplex";
|
||||
}
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
stream << " rows=\"" << m_numberOfRows << "\"";
|
||||
stream << " columns=\"" << m_numberOfColumns << "\"";
|
||||
}
|
||||
#endif
|
||||
|
||||
// EvaluationNode
|
||||
typename EvaluationNode<T>::Type type() const override { return EvaluationNode<T>::Type::MatrixComplex; }
|
||||
|
||||
@@ -33,8 +33,10 @@ public:
|
||||
static MatrixLayoutNode * FailedAllocationStaticNode();
|
||||
MatrixLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(MatrixLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "MatrixLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "MatrixLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,8 +23,10 @@ public:
|
||||
static MultiplicationNode * FailedAllocationStaticNode();
|
||||
MultiplicationNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(MultiplicationNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Multiplication"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Multiplication";
|
||||
}
|
||||
#endif
|
||||
|
||||
Type type() const override { return Type::Multiplication; }
|
||||
|
||||
@@ -35,8 +35,10 @@ public:
|
||||
NthRootLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(NthRootLayoutNode); }
|
||||
int numberOfChildren() const override { return m_hasIndex ? 2 : 1; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "NthRootLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "NthRootLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -18,10 +18,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(OppositeNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Opposite"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Opposite";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Opposite; }
|
||||
|
||||
@@ -13,10 +13,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(ParenthesisNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Parenthesis"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 1; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Parenthesis";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Parenthesis; }
|
||||
|
||||
@@ -18,10 +18,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(PowerNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Power"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 2; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Power";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
Type type() const override { return Type::Power; }
|
||||
|
||||
@@ -13,8 +13,10 @@ public:
|
||||
static ProductLayoutNode * FailedAllocationStaticNode();
|
||||
ProductLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(ProductLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "ProductLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "ProductLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -23,8 +23,10 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override;
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Rational"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Rational";
|
||||
}
|
||||
#endif
|
||||
|
||||
// SerializationHelperInterface
|
||||
|
||||
@@ -26,8 +26,10 @@ public:
|
||||
static RightParenthesisLayoutNode * FailedAllocationStaticNode();
|
||||
RightParenthesisLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(RightParenthesisLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "RightParenthesisLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "RightParenthesisLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -19,8 +19,10 @@ public:
|
||||
static RightSquareBracketLayoutNode * FailedAllocationStaticNode();
|
||||
RightSquareBracketLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(RightSquareBracketLayoutNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "RightSquareBracketLayout"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "RightSquareBracketLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
@@ -27,11 +27,7 @@ public:
|
||||
char XNTChar() const override { return 'n'; }
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(SequenceLayoutNode); }
|
||||
int numberOfChildren() const override { return 3; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Sequence Layout"; }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
constexpr static KDCoordinate k_boundHeightMargin = 2;
|
||||
|
||||
@@ -14,8 +14,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(SubtractionNode); }
|
||||
const char * description() const override { return "Subtraction"; }
|
||||
int numberOfChildren() const override { return 2; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Subtraction";
|
||||
}
|
||||
#endif
|
||||
|
||||
// ExpressionNode
|
||||
|
||||
|
||||
@@ -12,6 +12,13 @@ public:
|
||||
int serialize(char * buffer, int bufferSize, Preferences::PrintFloatMode floatDisplayMode, int numberOfSignificantDigits) const override;
|
||||
static SumLayoutNode * FailedAllocationStaticNode();
|
||||
SumLayoutNode * failedAllocationStaticNode() override { return FailedAllocationStaticNode(); }
|
||||
size_t size() const override { return sizeof(SumLayoutNode); }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "SumLayout";
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void render(KDContext * ctx, KDPoint p, KDColor expressionColor, KDColor backgroundColor) override;
|
||||
};
|
||||
|
||||
@@ -18,10 +18,12 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(SymbolNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Symbol"; }
|
||||
#endif
|
||||
int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Symbol";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Expression Properties
|
||||
Type type() const override { return Type::Symbol; }
|
||||
|
||||
@@ -59,6 +59,11 @@ protected:
|
||||
void addChildAtIndexInPlace(TreeByValue t, int index, int currentNumberOfChildren) {
|
||||
TreeByReference::addChildAtIndexInPlace(t, index, currentNumberOfChildren);
|
||||
}
|
||||
/*
|
||||
private:
|
||||
// Fix
|
||||
using TreeByReference::addChildAtIndexInPlace;
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
#ifndef POINCARE_TREE_NODE_H
|
||||
#define POINCARE_TREE_NODE_H
|
||||
|
||||
#define POINCARE_TREE_LOG 1
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#if POINCARE_TREE_LOG
|
||||
#include <ostream>
|
||||
#endif
|
||||
|
||||
/* What's in a TreeNode, really?
|
||||
* - a vtable pointer
|
||||
* - an identifier
|
||||
* - a reference counter
|
||||
*/
|
||||
#define TREE_LOG 0
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -41,8 +43,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual const char * description() const { return "UNKNOWN";}
|
||||
|
||||
// Ghost
|
||||
virtual bool isGhost() const { return false; }
|
||||
|
||||
@@ -153,11 +153,11 @@ public:
|
||||
}
|
||||
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream stream) = 0;
|
||||
virtual void logAttributes(std::ostream stream) {
|
||||
virtual void logNodeName(std::ostream & stream) const = 0;
|
||||
virtual void logAttributes(std::ostream & stream) const {
|
||||
}
|
||||
|
||||
void log(std::ostream stream, bool recursive = true) {
|
||||
void log(std::ostream & stream, bool recursive = true) {
|
||||
stream << "<";
|
||||
logNodeName(stream);
|
||||
stream << " id=\"" << m_identifier << "\"";
|
||||
@@ -166,13 +166,13 @@ public:
|
||||
logAttributes(stream);
|
||||
stream << ">";
|
||||
if (recursive) {
|
||||
for (TreeNode * child : node->depthFirstChildren()) {
|
||||
t->log(stream, recursive);
|
||||
for (TreeNode * child : depthFirstChildren()) {
|
||||
child->log(stream, recursive);
|
||||
}
|
||||
}
|
||||
stream << "</";
|
||||
logNodeName(stream);
|
||||
stream << ">"
|
||||
stream << ">";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -98,8 +98,8 @@ void TreeByReference::buildGhostChildren() {
|
||||
}
|
||||
|
||||
#if POINCARE_TREE_LOG
|
||||
void flatLog(std::ostream stream);
|
||||
void treeLog(std::ostream stream);
|
||||
void flatLog(std::ostream & stream);
|
||||
void treeLog(std::ostream & stream);
|
||||
#endif
|
||||
|
||||
int numberOfNodes() const {
|
||||
|
||||
@@ -13,8 +13,10 @@ public:
|
||||
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(UndefinedNode); }
|
||||
#if TREE_LOG
|
||||
const char * description() const override { return "Undefined"; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Undefined";
|
||||
}
|
||||
#endif
|
||||
|
||||
// Properties
|
||||
|
||||
@@ -40,9 +40,9 @@ public:
|
||||
// TreeNode
|
||||
size_t size() const override { return sizeof(VerticalOffsetLayoutNode); }
|
||||
int numberOfChildren() const override { return 1; }
|
||||
#if TREE_LOG
|
||||
const char * description() const override {
|
||||
return m_type == Type::Subscript ? "Subscript" : "Superscript";
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << (m_type == Type::Subscript ? "Subscript" : "Superscript");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if POINCARE_TREE_LOG
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
TreePool * TreePool::sharedPool() {
|
||||
@@ -99,8 +95,8 @@ void TreePool::moveNodes(TreeNode * destination, TreeNode * source, size_t moveS
|
||||
}
|
||||
|
||||
#if POINCARE_TREE_LOG
|
||||
void TreePool::flatLog(std::ostream stream) {
|
||||
size_t size static_cast<char *>(m_cursor) - static_cast<char *>(m_buffer);
|
||||
void TreePool::flatLog(std::ostream & stream) {
|
||||
size_t size = static_cast<char *>(m_cursor) - static_cast<char *>(m_buffer);
|
||||
stream << "<TreePool format=\"flat\" size=\"" << size << "\">";
|
||||
for (TreeNode * node : allNodes()) {
|
||||
node->log(stream, false);
|
||||
@@ -108,7 +104,7 @@ void TreePool::flatLog(std::ostream stream) {
|
||||
stream << "</TreePool>";
|
||||
}
|
||||
|
||||
void TreePool::treeLog() {
|
||||
void TreePool::treeLog(std::ostream & stream) {
|
||||
stream << "<TreePool format=\"tree\" size=\"" << (int)(m_cursor-m_buffer) << "\">";
|
||||
for (TreeNode * node : roots()) {
|
||||
node->log(stream, true);
|
||||
|
||||
@@ -22,6 +22,11 @@ public:
|
||||
int data() { return m_data; }
|
||||
void setData(int data) { m_data = data; }
|
||||
virtual int numberOfChildren() const override { return 0; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Blob";
|
||||
}
|
||||
#endif
|
||||
private:
|
||||
int m_data;
|
||||
};
|
||||
|
||||
51
poincare/test/tree/pair_node.h
Normal file
51
poincare/test/tree/pair_node.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef POINCARE_TEST_PAIR_NODE_H
|
||||
#define POINCARE_TEST_PAIR_NODE_H
|
||||
|
||||
#include <poincare/tree_node.h>
|
||||
#include <poincare/allocation_failure_node.h>
|
||||
#include <poincare/tree_by_reference.h>
|
||||
#include <poincare/tree_by_value.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
|
||||
class PairNode : public TreeNode {
|
||||
public:
|
||||
static PairNode * FailedAllocationStaticNode() {
|
||||
static AllocationFailureNode<PairNode> failureNode;
|
||||
return &failureNode;
|
||||
}
|
||||
virtual PairNode * failedAllocationStaticNode() override {
|
||||
return PairNode::FailedAllocationStaticNode();
|
||||
}
|
||||
virtual size_t size() const override { return sizeof(PairNode); }
|
||||
virtual int numberOfChildren() const override { return 2; }
|
||||
#if POINCARE_TREE_LOG
|
||||
virtual void logNodeName(std::ostream & stream) const {
|
||||
stream << "Pair";
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
class PairByReference : public TreeByReference {
|
||||
public:
|
||||
PairByReference(TreeByReference t1, TreeByReference t2) : TreeByReference(TreePool::sharedPool()->createTreeNode<PairNode>()) {
|
||||
replaceChildAtIndexInPlace(0, t1); // TODO: Is that the correct way to do this?
|
||||
replaceChildAtIndexInPlace(1, t2); // TODO: Is that the correct way to do this?
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class PairByValue : public TreeByValue {
|
||||
public:
|
||||
PairByValue(TreeByValue t1, TreeByValue t2) : TreeByValue(TreePool::sharedPool()->createTreeNode<PairNode>()) {
|
||||
replaceChildAtIndexInPlace(0, t1);
|
||||
replaceChildAtIndexInPlace(1, t2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include "blob_node.h"
|
||||
#include "pair_node.h"
|
||||
|
||||
using namespace Poincare;
|
||||
|
||||
@@ -23,6 +24,15 @@ QUIZ_CASE(tree_by_values_are_stored_in_pool) {
|
||||
assert_pool_size(0);
|
||||
}
|
||||
|
||||
TreeByValue blob_with_data_3() {
|
||||
return BlobByValue(3);
|
||||
}
|
||||
QUIZ_CASE(tree_by_values_can_be_returned) {
|
||||
assert_pool_size(0);
|
||||
TreeByValue b = blob_with_data_3();
|
||||
assert_pool_size(1);
|
||||
}
|
||||
|
||||
QUIZ_CASE(tree_by_values_allocation_failures) {
|
||||
assert_pool_size(0);
|
||||
BlobByValue b(1);
|
||||
@@ -34,3 +44,13 @@ QUIZ_CASE(tree_by_values_allocation_failures) {
|
||||
}
|
||||
assert_pool_size(1);
|
||||
}
|
||||
|
||||
QUIZ_CASE(tree_by_value_deep_copies) {
|
||||
assert_pool_size(0);
|
||||
BlobByValue b1(1);
|
||||
BlobByValue b2(2);
|
||||
PairByValue p(b1, b2);
|
||||
assert_pool_size(3);
|
||||
PairByValue p2 = p;
|
||||
assert_pool_size(6);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user