From 02c17907686eac21dc25787aab155bb8349e4a40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Mon, 2 Jul 2018 15:59:43 +0200 Subject: [PATCH] [tree] Finish the merge --- apps/Makefile | 1 + apps/main.cpp | 9 +++++++++ apps/tree/Makefile | 11 +++++++++++ apps/tree/expression_node.h | 1 + apps/tree/layout_cursor.h | 2 ++ apps/tree/test.cpp | 30 ++++++++++++++++++++++++++++++ apps/tree/tree_pool.cpp | 5 +++++ apps/tree/tree_pool.h | 3 ++- apps/tree/tree_reference.h | 15 ++++++++------- 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 apps/tree/Makefile diff --git a/apps/Makefile b/apps/Makefile index 6249c5f29..ab85bc844 100644 --- a/apps/Makefile +++ b/apps/Makefile @@ -3,6 +3,7 @@ include apps/home/Makefile include apps/on_boarding/Makefile include apps/hardware_test/Makefile include apps/usb/Makefile +include apps/tree/Makefile snapshots = # All selected apps are included. Each Makefile below is responsible for setting diff --git a/apps/main.cpp b/apps/main.cpp index 9c2adde8b..17641bbb9 100644 --- a/apps/main.cpp +++ b/apps/main.cpp @@ -1,6 +1,14 @@ #include "apps_container_storage.h" #include "global_preferences.h" +#include "tree/test.cpp" + + +void ion_main(int argc, char * argv[]) { + Test::main(); +} + +#if 0 void ion_main(int argc, char * argv[]) { #if EPSILON_GETOPT for (int i=1; irun(); } +#endif diff --git a/apps/tree/Makefile b/apps/tree/Makefile new file mode 100644 index 000000000..8366d07be --- /dev/null +++ b/apps/tree/Makefile @@ -0,0 +1,11 @@ +app_objs = $(addprefix apps/tree/,\ + addition_node.o\ + expression_node.o\ + expression_reference.o\ + layout_cursor.o\ + layout_node.o\ + layout_reference.o\ + tree_node.o\ + tree_pool.o\ +) + diff --git a/apps/tree/expression_node.h b/apps/tree/expression_node.h index a28355874..536fa8f37 100644 --- a/apps/tree/expression_node.h +++ b/apps/tree/expression_node.h @@ -2,6 +2,7 @@ #define EXPRESSION_NODE_H #include "tree_node.h" +#include class ExpressionNode : public TreeNode { public: diff --git a/apps/tree/layout_cursor.h b/apps/tree/layout_cursor.h index 9d7eaa6f8..0376c24bd 100644 --- a/apps/tree/layout_cursor.h +++ b/apps/tree/layout_cursor.h @@ -16,6 +16,7 @@ public: /* Debug */ void log() { +#if TREE_LOG printf("Pointed Layout id %d, cursor position ", m_layoutRef.identifier()); if (m_position == Position::Left) { printf("Left"); @@ -23,6 +24,7 @@ public: printf("Right"); } printf("\n"); +#endif } bool isDefined() const { return m_layoutRef.isDefined(); } diff --git a/apps/tree/test.cpp b/apps/tree/test.cpp index e8b39ba1d..42d7ca923 100644 --- a/apps/tree/test.cpp +++ b/apps/tree/test.cpp @@ -1,6 +1,8 @@ #include "refs.h" #include +namespace Test { + void logPool() { TreePool::sharedPool()->log(); } @@ -24,7 +26,9 @@ AdditionRef buildAddition() { } void testAddition() { +#if TREE_LOG printf("Addition test\n"); +#endif int initialNumberOfNodes = TreePool::sharedPool()->numberOfNodes(); AdditionRef a = buildAddition(); assert(TreePool::sharedPool()->numberOfNodes() == initialNumberOfNodes + 3); @@ -52,14 +56,18 @@ void createNodes() { } void testPoolEmpties() { +#if TREE_LOG printf("Pool empties test\n"); +#endif int initialNumberOfNodes = TreePool::sharedPool()->numberOfNodes(); createNodes(); assert(TreePool::sharedPool()->numberOfNodes() == initialNumberOfNodes); } void testCursorCreateAndRetain() { +#if TREE_LOG printf("Cursor create and retain test\n"); +#endif int initialNumberOfNodes = TreePool::sharedPool()->numberOfNodes(); CharLayoutRef aChar('a'); CharLayoutRef bChar('b'); @@ -88,7 +96,9 @@ void testCursorCreateAndRetain() { } void testCursorMoveLeft() { +#if TREE_LOG printf("Cursor move left test\n"); +#endif CharLayoutRef aChar('a'); CharLayoutRef bChar('b'); HorizontalLayoutRef h(aChar, bChar); @@ -112,7 +122,9 @@ void testCursorMoveLeft() { } void testPoolExpressionAllocationFail() { +#if TREE_LOG printf("Pool expression allocation fail test\n"); +#endif // Fill the pool for size 256 FloatRef f1(0.0f); @@ -141,7 +153,9 @@ void testPoolExpressionAllocationFail() { } void testPoolExpressionAllocationFail2() { +#if TREE_LOG printf("Pool expression allocation multiple fail test\n"); +#endif // Fill the pool for size 256 FloatRef f1(0.0f); @@ -175,7 +189,9 @@ void testPoolExpressionAllocationFail2() { } void testPoolExpressionAllocationFailOnImbricatedAdditions() { +#if TREE_LOG printf("Pool expression allocation fail second test\n"); +#endif // Fill the pool for size 256 FloatRef f1(0.0f); @@ -206,7 +222,9 @@ void testPoolExpressionAllocationFailOnImbricatedAdditions() { } void testStealOperand() { +#if TREE_LOG printf("Steal operand test\n"); +#endif FloatRef f1(0.0f); FloatRef f2(1.0f); @@ -227,7 +245,9 @@ void testStealOperand() { } void testSimplify() { +#if TREE_LOG printf("Simplify test\n"); +#endif AdditionRef a( AdditionRef( FloatRef(0.0f), @@ -244,7 +264,9 @@ void testSimplify() { } void testChildSort() { +#if TREE_LOG printf("Child sort test\n"); +#endif AdditionRef a( AdditionRef( @@ -266,7 +288,9 @@ void testChildSort() { void testPoolLayoutAllocationFail() { +#if TREE_LOG printf("Pool layout allocation fail test\n"); +#endif // Fill the pool for size 256 CharLayoutRef char1('a'); @@ -293,7 +317,9 @@ void runTest(test t) { } int main() { +#if TREE_LOG printf("\n*******************\nStart running tests\n*******************\n\n"); +#endif assert(TreePool::sharedPool()->numberOfNodes() == 0); runTest(testAddition); runTest(testPoolEmpties); @@ -306,6 +332,10 @@ int main() { runTest(testSimplify); runTest(testChildSort); runTest(testPoolLayoutAllocationFail); +#if TREE_LOG printf("\n*******************\nEnd of tests\n*******************\n\n"); +#endif return 0; } + +} diff --git a/apps/tree/tree_pool.cpp b/apps/tree/tree_pool.cpp index bd4b4b669..245d87da1 100644 --- a/apps/tree/tree_pool.cpp +++ b/apps/tree/tree_pool.cpp @@ -1,5 +1,6 @@ #include "tree_pool.h" #include +#include TreePool * TreePool::sharedPool() { static TreePool pool; @@ -31,6 +32,7 @@ static void memmove32(uint32_t * dst, uint32_t * src, size_t len) { } void TreePool::logNodeForIdentifierArray() { +#if TREE_LOG printf("\n\n"); for (int i = 0; i < MaxNumberOfNodes; i++) { if (m_nodeForIdentifier[i] != nullptr) { @@ -38,6 +40,7 @@ void TreePool::logNodeForIdentifierArray() { } } printf("\n\n"); +#endif } void TreePool::move(TreeNode * source, TreeNode * destination) { @@ -83,6 +86,7 @@ void TreePool::moveNodes(TreeNode * source, TreeNode * destination, size_t moveS #include void TreePool::log() { +#if TREE_LOG printf("POOL:"); for (TreeNode * node : *this) { printf("|(%03d|%s|%03d|%p)", node->m_identifier, node->description(), node->retainCount(), node); @@ -90,6 +94,7 @@ void TreePool::log() { printf("|\n"); //logNodeForIdentifierArray(); +#endif } void * TreePool::alloc(size_t size) { diff --git a/apps/tree/tree_pool.h b/apps/tree/tree_pool.h index 11d8c71de..6f6b40c90 100644 --- a/apps/tree/tree_pool.h +++ b/apps/tree/tree_pool.h @@ -1,8 +1,9 @@ #ifndef TREE_POOL_H #define TREE_POOL_H -#include #include "tree_node.h" +#include +#include #include class TreePool { diff --git a/apps/tree/tree_reference.h b/apps/tree/tree_reference.h index e6a69afd7..f8386b470 100644 --- a/apps/tree/tree_reference.h +++ b/apps/tree/tree_reference.h @@ -221,19 +221,20 @@ public: node()->incrementNumberOfChildren(numberOfNewChildren); } -protected: - TreeReference() { - TreeNode * node = TreePool::sharedPool()->createTreeNode(); - m_identifier = node->identifier(); - } - - TreeReference(TreeNode * node) { + TreeReference(TreeNode * node) { // TODO Make this protected if (node == nullptr) { m_identifier = -1; } else { setIdentifierAndRetain(node->identifier()); } } + +protected: + TreeReference() { + TreeNode * node = TreePool::sharedPool()->createTreeNode(); + m_identifier = node->identifier(); + } + void setIdentifierAndRetain(int newId) { m_identifier = newId; node()->retain();