changeset 32:be67b0312bea

Convert "showTrace" function to CodeSegment
author Yasutaka Higa <e115763@ie.u-ryukyu.ac.jp>
date Tue, 07 Jun 2016 15:12:18 +0900
parents d2073e23f206
children c056a6a70c7e
files src/insert_verification/akashaLLRBContext.c src/insert_verification/include/akashaLLRBContext.h src/insert_verification/main.c src/insert_verification/verifySpecification.c
diffstat 4 files changed, 23 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/insert_verification/akashaLLRBContext.c	Tue Jun 07 14:39:07 2016 +0900
+++ b/src/insert_verification/akashaLLRBContext.c	Tue Jun 07 15:12:18 2016 +0900
@@ -6,6 +6,7 @@
 extern __code showTree_stub(struct Context*);
 extern __code iterateInsertion_stub(struct Context*);
 extern __code putAndGoToNextDepth_stub (struct Context*);
+extern __code showTrace_stub(struct Context*);
 extern __code verifySpecification_stub (struct Context*);
 extern __code duplicateIterator_stub(struct Context*);
 extern __code duplicateIteratorElem_stub(struct Context*);
@@ -69,7 +70,8 @@
     context->code[ShowTree]              = showTree_stub;
     context->code[IterateInsertion]      = iterateInsertion_stub;
     context->code[PutAndGoToNextDepth]   = putAndGoToNextDepth_stub;
-    context->code[VerifySpecification]   = verifySpecification_stub;;
+    context->code[ShowTrace]             = showTrace_stub;
+    context->code[VerifySpecification]   = verifySpecification_stub;
     context->code[DuplicateIterator]     = duplicateIterator_stub;
     context->code[DuplicateIteratorElem] = duplicateIteratorElem_stub;
     context->code[DuplicateTree]         = duplicateTree_stub;
--- a/src/insert_verification/include/akashaLLRBContext.h	Tue Jun 07 14:39:07 2016 +0900
+++ b/src/insert_verification/include/akashaLLRBContext.h	Tue Jun 07 15:12:18 2016 +0900
@@ -8,6 +8,7 @@
     ShowTree,
     IterateInsertion,
     PutAndGoToNextDepth,
+    ShowTrace,
     VerifySpecification,
     DuplicateIterator,
     DuplicateIteratorElem,
--- a/src/insert_verification/main.c	Tue Jun 07 14:39:07 2016 +0900
+++ b/src/insert_verification/main.c	Tue Jun 07 15:12:18 2016 +0900
@@ -96,6 +96,10 @@
     goto meta(context, Put);
 }
 
+__code showTrace_stub(struct Context* context) {
+    goto showTrace(context, &context->data[Iter]->iterator);
+}
+
 __code verifySpecification_stub(struct Context* context) {
     goto verifySpecification(context, &context->data[Tree]->tree, &context->data[Iter]->iterator);
 }
--- a/src/insert_verification/verifySpecification.c	Tue Jun 07 14:39:07 2016 +0900
+++ b/src/insert_verification/verifySpecification.c	Tue Jun 07 15:12:18 2016 +0900
@@ -1,16 +1,7 @@
-/* C functions (TODO: convert to code segment) */
-
 #include <stdio.h>
 #include "akashaLLRBContext.h"
 
-void showTrace(struct Iterator* iter) {
-    printf("show trace(reversed):");
-
-    for (; iter != NULL; iter = iter->previousDepth) {
-        printf("%u ", iter->iteratedValue);
-    }
-    printf("\n");
-}
+/* C functions (TODO: convert to code segment) */
 
 unsigned int min_height(struct Node* node, unsigned int height) {
     if ((node->left == NULL) && (node->right == NULL)) return height;
@@ -53,6 +44,17 @@
 
 /* Code Segments */
 
+__code showTrace(struct Context* context, struct Iterator* iter) {
+    printf("show trace(reversed):");
+
+    for (; iter != NULL; iter = iter->previousDepth) {
+        printf("%u ", iter->iteratedValue);
+    }
+    printf("\n");
+
+    goto meta(context, context->next);
+}
+
 __code verifySpecification(struct Context* context, struct Tree* tree, struct Iterator* iter) {
     unsigned const int min_h = min_height(tree->root, 1);
     unsigned const int max_h = max_height(tree->root, 1);
@@ -61,8 +63,9 @@
         printf("llrb-condition violated.\n");
         printf("\tmin-height %u\n", min_h);
         printf("\tmax-height %u\n", max_h);
-        showTrace(iter);
-        exit(1);
+
+        context->next = Exit;
+        goto meta(context, ShowTrace);
     }
 
     goto meta(context, DuplicateIterator);