Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
2188 views
1
/*
2
* Main developer: Nico Van Cleemput
3
* In collaboration with: Craig Larson
4
*
5
* Copyright (C) 2014 Nico Van Cleemput.
6
* Licensed under the GNU GPL, read the file LICENSE.txt for details.
7
*/
8
9
#include "bintrees.h"
10
#include "util.h"
11
#include "printing_pb.h"
12
13
#define INVARIANT_LABEL 0
14
#define UNARY_LABEL 1
15
#define COMM_BINARY_LABEL 2
16
#define NON_COMM_BINARY_LABEL 3
17
18
void printComparator_propertyBased(int id, FILE *f){
19
if(id==0){
20
fprintf(f, "<-");
21
} else if(id==2){
22
fprintf(f, "->");
23
} else {
24
BAILOUT("Unknown comparator ID")
25
}
26
}
27
28
void printUnaryOperator_left_propertyBased(int id, FILE *f){
29
if(id==0){
30
fprintf(f, "~(");
31
} else {
32
BAILOUT("Unknown unary operator ID")
33
}
34
}
35
36
void printUnaryOperator_right_propertyBased(int id, FILE *f){
37
if(id==0){
38
fprintf(f, ")");
39
} else {
40
BAILOUT("Unknown unary operator ID")
41
}
42
}
43
44
void printCommutativeBinaryOperator_left_propertyBased(int id, FILE *f){
45
if(id==0 || id==1 || id==2){
46
fprintf(f, "(");
47
} else {
48
BAILOUT("Unknown commutative binary operator ID")
49
}
50
}
51
52
void printCommutativeBinaryOperator_middle_propertyBased(int id, FILE *f){
53
if(id==0){
54
fprintf(f, ") & (");
55
} else if(id==1){
56
fprintf(f, ") | (");
57
} else if(id==2){
58
fprintf(f, ") ^ (");
59
} else {
60
BAILOUT("Unknown commutative binary operator ID")
61
}
62
}
63
64
void printCommutativeBinaryOperator_right_propertyBased(int id, FILE *f){
65
if(id==0 || id==1 || id==2){
66
fprintf(f, ")");
67
} else {
68
BAILOUT("Unknown commutative binary operator ID")
69
}
70
}
71
72
void printNonCommutativeBinaryOperator_left_propertyBased(int id, FILE *f){
73
if(id==0){
74
fprintf(f, "(");
75
} else {
76
BAILOUT("Unknown commutative binary operator ID")
77
}
78
}
79
80
void printNonCommutativeBinaryOperator_middle_propertyBased(int id, FILE *f){
81
if(id==0){
82
fprintf(f, ") -> (");
83
} else {
84
BAILOUT("Unknown commutative binary operator ID")
85
}
86
}
87
88
void printNonCommutativeBinaryOperator_right_propertyBased(int id, FILE *f){
89
if(id==0){
90
fprintf(f, ")");
91
} else {
92
BAILOUT("Unknown commutative binary operator ID")
93
}
94
}
95
96
void printNode_propertyBased(NODE *node, FILE *f, char **invariantNamePointers){
97
int type = node->contentLabel[0];
98
int id = node->contentLabel[1];
99
if (type==INVARIANT_LABEL) {
100
if(invariantNamePointers==NULL){
101
fprintf(f, "I%d", id + 1);
102
} else {
103
fprintf(f, "%s", invariantNamePointers[id]);
104
}
105
} else if (type==UNARY_LABEL) {
106
printUnaryOperator_left_propertyBased(id, f);
107
printNode_propertyBased(node->left, f, invariantNamePointers);
108
printUnaryOperator_right_propertyBased(id, f);
109
} else if (type==NON_COMM_BINARY_LABEL){
110
printNonCommutativeBinaryOperator_left_propertyBased(id, f);
111
printNode_propertyBased(node->left, f, invariantNamePointers);
112
printNonCommutativeBinaryOperator_middle_propertyBased(id, f);
113
printNode_propertyBased(node->right, f, invariantNamePointers);
114
printNonCommutativeBinaryOperator_right_propertyBased(id, f);
115
} else if (type==COMM_BINARY_LABEL){
116
printCommutativeBinaryOperator_left_propertyBased(id, f);
117
printNode_propertyBased(node->left, f, invariantNamePointers);
118
printCommutativeBinaryOperator_middle_propertyBased(id, f);
119
printNode_propertyBased(node->right, f, invariantNamePointers);
120
printCommutativeBinaryOperator_right_propertyBased(id, f);
121
} else {
122
BAILOUT("Unknown content label type")
123
}
124
}
125
126
void printUnaryOperator_single_propertyBased(int id, FILE *f){
127
if(id==0){
128
fprintf(f, "~");
129
} else {
130
BAILOUT("Unknown unary operator ID")
131
}
132
}
133
134
void printCommutativeBinaryOperator_single_propertyBased(int id, FILE *f){
135
if(id==0){
136
fprintf(f, "&"); //AND
137
} else if(id==1){
138
fprintf(f, "|"); //OR
139
} else if(id==2){
140
fprintf(f, "^"); //XOR
141
} else {
142
BAILOUT("Unknown commutative binary operator ID")
143
}
144
}
145
146
void printNonCommutativeBinaryOperator_single_propertyBased(int id, FILE *f){
147
if(id==0){
148
fprintf(f, "->");
149
} else {
150
BAILOUT("Unknown commutative binary operator ID")
151
}
152
}
153
154
void printSingleNode_propertyBased(NODE *node, FILE *f, char **invariantNamePointers){
155
int type = node->contentLabel[0];
156
int id = node->contentLabel[1];
157
if (type==INVARIANT_LABEL) {
158
if(invariantNamePointers==NULL){
159
fprintf(f, "I%d", id + 1);
160
} else {
161
fprintf(f, "%s", invariantNamePointers[id]);
162
}
163
} else if (type==UNARY_LABEL) {
164
printUnaryOperator_single_propertyBased(id, f);
165
} else if (type==NON_COMM_BINARY_LABEL){
166
printNonCommutativeBinaryOperator_single_propertyBased(id, f);
167
} else if (type==COMM_BINARY_LABEL){
168
printCommutativeBinaryOperator_single_propertyBased(id, f);
169
} else {
170
BAILOUT("Unknown content label type")
171
}
172
}
173
174