[poincare] Use POINCARE_TREE_LOG

This commit is contained in:
Romain Goyet
2018-08-10 10:52:15 +02:00
parent 61648d643f
commit 817511fcf7
4 changed files with 55 additions and 17 deletions

View File

@@ -16,8 +16,10 @@ public:
// TreeNode
size_t size() const override { return sizeof(InfinityNode); }
#if TREE_LOG
const char * description() const override { return "Infinity"; }
#if POINCARE_TREE_LOG
virtual void logNodeName(std::ostream stream) {
stream << "Infinity";
}
#endif
// Properties

View File

@@ -152,6 +152,30 @@ public:
return node;
}
#if POINCARE_TREE_LOG
virtual void logNodeName(std::ostream stream) = 0;
virtual void logAttributes(std::ostream stream) {
}
void log(std::ostream stream, bool recursive = true) {
stream << "<";
logNodeName(stream);
stream << " id=\"" << m_identifier << "\"";
stream << " refCount=\"" << m_referenceCounter << "\"";
stream << " size=\"" << size() << "\"";
logAttributes(stream);
stream << ">";
if (recursive) {
for (TreeNode * child : node->depthFirstChildren()) {
t->log(stream, recursive);
}
}
stream << "</";
logNodeName(stream);
stream << ">"
}
#endif
protected:
TreeNode();

View File

@@ -5,6 +5,9 @@
#include <stddef.h>
#include <string.h>
#include <new>
#if POINCARE_TREE_LOG
#include <ostream>
#endif
namespace Poincare {
@@ -94,8 +97,10 @@ void TreeByReference::buildGhostChildren() {
return identifierOfStaticNodeAtIndex(nodeID);
}
// Debug
void log();
#if POINCARE_TREE_LOG
void flatLog(std::ostream stream);
void treeLog(std::ostream stream);
#endif
int numberOfNodes() const {
int count = 0;

View File

@@ -2,6 +2,10 @@
#include <string.h>
#include <stdint.h>
#if POINCARE_TREE_LOG
#include <iostream>
#endif
namespace Poincare {
TreePool * TreePool::sharedPool() {
@@ -94,22 +98,25 @@ void TreePool::moveNodes(TreeNode * destination, TreeNode * source, size_t moveS
}
}
#include <stdio.h>
void TreePool::log() {
#if TREE_LOG
printf("POOL:");
for (TreeNode * node : *this) {
printf("|(%03d|%s|%03d|%p)\n", node->m_identifier, node->description(), node->retainCount(), node);
#if POINCARE_TREE_LOG
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);
}
printf("|\n");
//logNodeForIdentifierArray();
#endif
stream << "</TreePool>";
}
void TreePool::treeLog() {
stream << "<TreePool format=\"tree\" size=\"" << (int)(m_cursor-m_buffer) << "\">";
for (TreeNode * node : roots()) {
node->log(stream, true);
}
stream << "</TreePool>";
}
#endif
void * TreePool::alloc(size_t size) {
if (m_cursor >= m_buffer + BufferSize || m_cursor + size > m_buffer + BufferSize) {
return nullptr;