annotate src/SingleLinkedStack.cbc @ 86:765449889623

fix translate interface routine
author anatofuz
date Tue, 15 Oct 2019 20:03:48 +0900
parents d419660ad71d
children 822d74c14f38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
80
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
1 #include "../context.h"
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
2 #interface "Stack.h"
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
3
82
d419660ad71d tweak generate_stub.pl
anatofuz
parents: 80
diff changeset
4 Stack* createSingleLinkedStack(struct Context* cbc_context) {
80
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
5 struct Stack* stack = new Stack();
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
6 struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack();
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
7 stack->stack = (union Data*)singleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
8 singleLinkedStack->top = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
9 stack->push = C_pushSingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
10 stack->pop = C_popSingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
11 stack->pop2 = C_pop2SingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
12 stack->get = C_getSingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
13 stack->get2 = C_get2SingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
14 stack->isEmpty = C_isEmptySingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
15 stack->clear = C_clearSingleLinkedStack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
16 return stack;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
17 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
18
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
19 void printStack1(union Data* data) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
20 struct Node* node = &data->Element.data->Node;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
21 // if (node == NULL) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
22 // printf("NULL");
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
23 // } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
24 // printf("key = %d ,", node->key);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
25 // printStack1((union Data*)data->Element.next);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
26 // }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
27 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
28
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
29 void printStack(union Data* data) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
30 printStack1(data);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
31 // printf("\n");
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
32 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
33
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
34 __code clearSingleLinkedStack(struct SingleLinkedStack* stack,__code next(...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
35 stack->top = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
36 goto next(...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
37 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
38
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
39 __code pushSingleLinkedStack(struct SingleLinkedStack* stack, union Data* data, __code next(...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
40 Element* element = new Element();
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
41 element->next = stack->top;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
42 element->data = data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
43 stack->top = element;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
44 goto next(...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
45 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
46
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
47 __code popSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
48 if (stack->top) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
49 data = stack->top->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
50 stack->top = stack->top->next;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
51 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
52 data = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
53 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
54 goto next(data, ...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
55 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
56
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
57 __code pop2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
58 if (stack->top) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
59 data = stack->top->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
60 stack->top = stack->top->next;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
61 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
62 data = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
63 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
64 if (stack->top) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
65 data1 = stack->top->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
66 stack->top = stack->top->next;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
67 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
68 data1 = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
69 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
70 goto next(data, data1, ...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
71 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
72
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
73
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
74 __code getSingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, ...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
75 if (stack->top)
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
76 data = stack->top->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
77 else
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
78 data = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
79 goto next(data, ...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
80 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
81
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
82 __code get2SingleLinkedStack(struct SingleLinkedStack* stack, __code next(union Data* data, union Data* data1, ...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
83 if (stack->top) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
84 data = stack->top->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
85 if (stack->top->next) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
86 data1 = stack->top->next->data;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
87 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
88 data1 = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
89 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
90 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
91 data = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
92 data1 = NULL;
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
93 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
94 goto next(data, data1, ...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
95 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
96
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
97 __code isEmptySingleLinkedStack(struct SingleLinkedStack* stack, __code next(...), __code whenEmpty(...)) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
98 if (stack->top) {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
99 goto next(...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
100 } else {
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
101 goto whenEmpty(...);
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
102 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
103 }
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
104
c976a8bbe8c5 add stac.h and Stac.cbc
tobaru
parents:
diff changeset
105