-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignDomainTest.Java
More file actions
278 lines (259 loc) · 6.52 KB
/
SignDomainTest.Java
File metadata and controls
278 lines (259 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
package it.unive.lisa.analysis.nonrelational.value.impl;
import it.unive.lisa.analysis.SemanticDomain.Satisfiability;
import it.unive.lisa.analysis.SemanticException;
import it.unive.lisa.analysis.nonrelational.value.BaseNonRelationalValueDomain;
import it.unive.lisa.analysis.nonrelational.value.NonRelationalValueDomain;
import it.unive.lisa.analysis.nonrelational.value.ValueEnvironment;
import it.unive.lisa.program.cfg.ProgramPoint;
import it.unive.lisa.symbolic.value.BinaryOperator;
import it.unive.lisa.symbolic.value.Constant;
import it.unive.lisa.symbolic.value.TernaryOperator;
import it.unive.lisa.symbolic.value.UnaryOperator;
import it.unive.lisa.symbolic.value.ValueExpression;
public class SignDomain extends BaseNonRelationalValueDomain<SignDomain> {
enum Sign {
PLUS, MINUS, ZERO, TOP, BOTTOM
}
private final Sign sign;
public SignDomain() {
this(Sign.TOP);
}
private SignDomain(Sign sign) {
this.sign = sign;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sign == null) ? 0 : sign.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SignDomain other = (SignDomain) obj;
if (sign != other.sign)
return false;
return true;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return sign.name();
}
@Override
public SignDomain lub(SignDomain other) throws SemanticException {
// TODO Auto-generated method stub
return null;
}
@Override
public SignDomain widening(SignDomain other) throws SemanticException {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean lessOrEqual(SignDomain other) throws SemanticException {
// TODO Auto-generated method stub
return false;
}
@Override
public SignDomain top() {
return new SignDomain(Sign.TOP);
}
@Override
public SignDomain bottom() {
return new SignDomain(Sign.BOTTOM);
}
@Override
public boolean isTop() {
return this.sign == Sign.TOP;
}
@Override
public boolean isBottom() {
return this.sign == Sign.BOTTOM;
}
@Override
public SignDomain eval(ValueExpression expression, ValueEnvironment<SignDomain> environment, ProgramPoint pp) {
// TODO Auto-generated method stub
return null;
}
@Override
public Satisfiability satisfies(ValueExpression expression, ValueEnvironment<SignDomain> environment,
ProgramPoint pp) {
// TODO Auto-generated method stub
return null;
}
@Override
public String representation() {
// TODO Auto-generated method stub
return this.sign.name();
}
@Override
protected SignDomain evalNullConstant(ProgramPoint pp) {
return top();
}
@Override
protected SignDomain evalNonNullConstant(Constant constant, ProgramPoint pp) {
if (constant.getValue() instanceof Integer) {
int c = (int) constant.getValue();
if (c == 0)
return new SignDomain(Sign.ZERO);
else if (c > 0)
return new SignDomain(Sign.PLUS);
else
return new SignDomain(Sign.MINUS);
}
return top();
}
@Override
protected SignDomain evalUnaryExpression(UnaryOperator operator, SignDomain arg, ProgramPoint pp) {
switch(operator) {
case NUMERIC_NEG:
if (arg.sign == Sign.PLUS) {
return new SignDomain(Sign.MINUS);
} else if (arg.sign == Sign.ZERO) {
return new SignDomain(Sign.ZERO);
} else if (arg.sign == Sign.MINUS) {
return new SignDomain(Sign.PLUS);
}
case LOGICAL_NOT:
case STRING_LENGTH:
case TYPEOF:
default:
return top();
}
}
@Override
protected SignDomain evalBinaryExpression(BinaryOperator operator, SignDomain left, SignDomain right,
ProgramPoint pp) {
switch(operator) {
case COMPARISON_EQ:
case COMPARISON_GE:
case COMPARISON_GT:
case COMPARISON_LE:
case COMPARISON_LT:
case COMPARISON_NE:
return top();
case LOGICAL_AND:
case LOGICAL_OR:
return top();
case NUMERIC_ADD:
switch(left.sign) {
case MINUS:
switch(right.sign) {
case MINUS:
return left;
case PLUS:
return top();
case ZERO:
return left;
case TOP:
case BOTTOM:
default:
return top();
}
case PLUS:
switch(right.sign) {
case MINUS:
return top();
case PLUS:
return left;
case ZERO:
return left;
case TOP:
case BOTTOM:
default:
return top();
}
case ZERO:
switch(right.sign) {
case MINUS:
return right;
case PLUS:
return right;
case ZERO:
return left;
case TOP:
case BOTTOM:
default:
return top();
}
case BOTTOM:
case TOP:
default:
return top();
}
case NUMERIC_DIV:
case NUMERIC_MOD:
case NUMERIC_MUL:
case NUMERIC_SUB:
return top();
case STRING_CONCAT:
case STRING_CONTAINS:
case STRING_ENDS_WITH:
case STRING_EQUALS:
case STRING_INDEX_OF:
case STRING_STARTS_WITH:
return top();
case TYPE_CAST:
case TYPE_CHECK:
return top();
default:
return top();
}
}
@Override
protected SignDomain evalTernaryExpression(TernaryOperator operator, SignDomain left, SignDomain middle,
SignDomain right, ProgramPoint pp) {
switch(operator) {
case STRING_REPLACE:
case STRING_SUBSTRING:
default:
return top();
}
}
@Override
protected Satisfiability satisfiesAbstractValue(SignDomain value, ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected Satisfiability satisfiesNullConstant(ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected Satisfiability satisfiesNonNullConstant(Constant constant, ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected Satisfiability satisfiesUnaryExpression(UnaryOperator operator, SignDomain arg, ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected Satisfiability satisfiesBinaryExpression(BinaryOperator operator, SignDomain left, SignDomain right,
ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected Satisfiability satisfiesTernaryExpression(TernaryOperator operator, SignDomain left, SignDomain middle,
SignDomain right, ProgramPoint pp) {
return Satisfiability.UNKNOWN;
}
@Override
protected SignDomain lubAux(SignDomain other) throws SemanticException {
return top();
}
@Override
protected SignDomain wideningAux(SignDomain other) throws SemanticException {
return lubAux(other);
}
@Override
protected boolean lessOrEqualAux(SignDomain other) throws SemanticException {
// TODO Auto-generated method stub
return false;
}
}