|
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 |
| package koala.dynamicjava.interpreter; |
|
30 |
| |
|
31 |
| import koala.dynamicjava.interpreter.error.ExecutionError; |
|
32 |
| import koala.dynamicjava.tree.Node; |
|
33 |
| import koala.dynamicjava.tree.Expression; |
|
34 |
| import edu.rice.cs.dynamicjava.interpreter.TypeContext; |
|
35 |
| import edu.rice.cs.dynamicjava.symbol.*; |
|
36 |
| import edu.rice.cs.dynamicjava.symbol.type.Type; |
|
37 |
| import edu.rice.cs.dynamicjava.symbol.type.VariableType; |
|
38 |
| import edu.rice.cs.plt.lambda.Thunk; |
|
39 |
| import edu.rice.cs.plt.lambda.Lambda; |
|
40 |
| import edu.rice.cs.plt.lambda.Lambda2; |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| public class NodeProperties { |
|
49 |
| |
|
50 |
| |
|
51 |
| public final static String TYPE = "type"; |
|
52 |
| |
|
53 |
12701
| public static Type getType(Node n) {
|
|
54 |
12701
| return (Type)n.getProperty(TYPE);
|
|
55 |
| } |
|
56 |
| |
|
57 |
9890
| public static Type setType(Node n, Type t) {
|
|
58 |
9890
| n.setProperty(TYPE, t);
|
|
59 |
9890
| return t;
|
|
60 |
| } |
|
61 |
| |
|
62 |
0
| public static boolean hasType(Node n) {
|
|
63 |
0
| return n.hasProperty(TYPE);
|
|
64 |
| } |
|
65 |
| |
|
66 |
| public static final Lambda<Node, Type> NODE_TYPE = new Lambda<Node, Type>() { |
|
67 |
78
| public Type value(Node n) { return getType(n); }
|
|
68 |
| }; |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| public final static String VARIABLE_TYPE = "variableType"; |
|
73 |
| |
|
74 |
1807
| public static Type getVariableType(Node n) {
|
|
75 |
1807
| return (Type)n.getProperty(VARIABLE_TYPE);
|
|
76 |
| } |
|
77 |
| |
|
78 |
3431
| public static Type setVariableType(Node n, Type t) {
|
|
79 |
3431
| n.setProperty(VARIABLE_TYPE, t);
|
|
80 |
3431
| return t;
|
|
81 |
| } |
|
82 |
| |
|
83 |
1935
| public static boolean hasVariableType(Node n) {
|
|
84 |
1935
| return n.hasProperty(VARIABLE_TYPE);
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| public final static String SUPER_TYPE = "superType"; |
|
93 |
| |
|
94 |
0
| public static Type getSuperType(Node n) {
|
|
95 |
0
| return (Type)n.getProperty(SUPER_TYPE);
|
|
96 |
| } |
|
97 |
| |
|
98 |
0
| public static Type setSuperType(Node n, Type t) {
|
|
99 |
0
| n.setProperty(SUPER_TYPE, t);
|
|
100 |
0
| return t;
|
|
101 |
| } |
|
102 |
| |
|
103 |
0
| public static boolean hasSuperType(Node n) {
|
|
104 |
0
| return n.hasProperty(SUPER_TYPE);
|
|
105 |
| } |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| public final static String CONVERTED_TYPE = "convertedType"; |
|
110 |
| |
|
111 |
26
| @SuppressWarnings("unchecked")
|
|
112 |
| public static Thunk<Class<?>> getConvertedType(Node n) { |
|
113 |
26
| return (Thunk<Class<?>>) n.getProperty(CONVERTED_TYPE);
|
|
114 |
| } |
|
115 |
| |
|
116 |
35
| public static Thunk<Class<?>> setConvertedType(Node n, Thunk<Class<?>> c) {
|
|
117 |
35
| n.setProperty(CONVERTED_TYPE, c);
|
|
118 |
35
| return c;
|
|
119 |
| } |
|
120 |
| |
|
121 |
3297
| public static boolean hasConvertedType(Node n) {
|
|
122 |
3297
| return n.hasProperty(CONVERTED_TYPE);
|
|
123 |
| } |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| public final static String ASSERTED_TYPE = "assertedType"; |
|
128 |
| |
|
129 |
0
| @SuppressWarnings("unchecked")
|
|
130 |
| public static Thunk<Class<?>> getAssertedType(Node n) { |
|
131 |
0
| return (Thunk<Class<?>>) n.getProperty(ASSERTED_TYPE);
|
|
132 |
| } |
|
133 |
| |
|
134 |
0
| public static Thunk<Class<?>> setAssertedType(Node n, Thunk<Class<?>> c) {
|
|
135 |
0
| n.setProperty(ASSERTED_TYPE, c);
|
|
136 |
0
| return c;
|
|
137 |
| } |
|
138 |
| |
|
139 |
0
| public static boolean hasAssertedType(Node n) {
|
|
140 |
0
| return n.hasProperty(ASSERTED_TYPE);
|
|
141 |
| } |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| public final static String CHECKED_TYPE = "checkedType"; |
|
146 |
| |
|
147 |
3
| @SuppressWarnings("unchecked")
|
|
148 |
| public static Thunk<Class<?>> getCheckedType(Node n) { |
|
149 |
3
| return (Thunk<Class<?>>) n.getProperty(CHECKED_TYPE);
|
|
150 |
| } |
|
151 |
| |
|
152 |
3
| public static Thunk<Class<?>> setCheckedType(Node n, Thunk<Class<?>> c) {
|
|
153 |
3
| n.setProperty(CHECKED_TYPE, c);
|
|
154 |
3
| return c;
|
|
155 |
| } |
|
156 |
| |
|
157 |
3297
| public static boolean hasCheckedType(Node n) {
|
|
158 |
3297
| return n.hasProperty(CHECKED_TYPE);
|
|
159 |
| } |
|
160 |
| |
|
161 |
| |
|
162 |
| |
|
163 |
| public final static String ERASED_TYPE = "erasedType"; |
|
164 |
| |
|
165 |
511
| @SuppressWarnings("unchecked")
|
|
166 |
| public static Thunk<Class<?>> getErasedType(Node n) { |
|
167 |
511
| return (Thunk<Class<?>>) n.getProperty(ERASED_TYPE);
|
|
168 |
| } |
|
169 |
| |
|
170 |
1076
| public static Thunk<Class<?>> setErasedType(Node n, Thunk<Class<?>> c) {
|
|
171 |
1076
| n.setProperty(ERASED_TYPE, c);
|
|
172 |
1076
| return c;
|
|
173 |
| } |
|
174 |
| |
|
175 |
0
| public static boolean hasErasedType(Node n) {
|
|
176 |
0
| return n.hasProperty(ERASED_TYPE);
|
|
177 |
| } |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
| |
|
183 |
| |
|
184 |
| |
|
185 |
| public final static String LEFT_EXPRESSION = "leftExpression"; |
|
186 |
| |
|
187 |
115
| public static Expression getLeftExpression(Node n) {
|
|
188 |
115
| return (Expression) n.getProperty(LEFT_EXPRESSION);
|
|
189 |
| } |
|
190 |
| |
|
191 |
128
| public static Expression setLeftExpression(Node n, Expression exp) {
|
|
192 |
128
| n.setProperty(LEFT_EXPRESSION, exp);
|
|
193 |
128
| return exp;
|
|
194 |
| } |
|
195 |
| |
|
196 |
0
| public static boolean hasLeftExpression(Node n) {
|
|
197 |
0
| return n.hasProperty(LEFT_EXPRESSION);
|
|
198 |
| } |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| public final static String TRANSLATION = "translation"; |
|
205 |
| |
|
206 |
1019
| public static Expression getTranslation(Node n) {
|
|
207 |
1019
| return (Expression) n.getProperty(TRANSLATION);
|
|
208 |
| } |
|
209 |
| |
|
210 |
1625
| public static Expression setTranslation(Node n, Expression exp) {
|
|
211 |
1625
| n.setProperty(TRANSLATION, exp);
|
|
212 |
1625
| return exp;
|
|
213 |
| } |
|
214 |
| |
|
215 |
2792
| public static boolean hasTranslation(Node n) {
|
|
216 |
2792
| return n.hasProperty(TRANSLATION);
|
|
217 |
| } |
|
218 |
| |
|
219 |
| |
|
220 |
| |
|
221 |
| |
|
222 |
| public final static String STATEMENT_TRANSLATION = "statementTranslation"; |
|
223 |
| |
|
224 |
0
| public static Node getStatementTranslation(Node n) {
|
|
225 |
0
| return (Node) n.getProperty(STATEMENT_TRANSLATION);
|
|
226 |
| } |
|
227 |
| |
|
228 |
0
| public static Node setStatementTranslation(Node n, Node s) {
|
|
229 |
0
| n.setProperty(STATEMENT_TRANSLATION, s);
|
|
230 |
0
| return s;
|
|
231 |
| } |
|
232 |
| |
|
233 |
374
| public static boolean hasStatementTranslation(Node n) {
|
|
234 |
374
| return n.hasProperty(STATEMENT_TRANSLATION);
|
|
235 |
| } |
|
236 |
| |
|
237 |
| |
|
238 |
| |
|
239 |
| public final static String VALUE = "value"; |
|
240 |
| |
|
241 |
566
| public static Object getValue(Node n) {
|
|
242 |
566
| return n.getProperty(VALUE);
|
|
243 |
| } |
|
244 |
| |
|
245 |
963
| public static Object setValue(Node n, Object o) {
|
|
246 |
963
| n.setProperty(VALUE, o);
|
|
247 |
963
| return o;
|
|
248 |
| } |
|
249 |
| |
|
250 |
5299
| public static boolean hasValue(Node n) {
|
|
251 |
5299
| return n.hasProperty(VALUE);
|
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
| |
|
256 |
| |
|
257 |
| |
|
258 |
| public final static String ERROR_STRINGS = "errorStrings"; |
|
259 |
| |
|
260 |
123
| public static String[] getErrorStrings(Node n) {
|
|
261 |
123
| return (String[]) n.getProperty(ERROR_STRINGS);
|
|
262 |
| } |
|
263 |
| |
|
264 |
41
| public static String[] setErrorStrings(Node n, String... strings) {
|
|
265 |
41
| n.setProperty(ERROR_STRINGS, strings);
|
|
266 |
41
| return strings;
|
|
267 |
| } |
|
268 |
| |
|
269 |
141
| public static boolean hasErrorStrings(Node n) {
|
|
270 |
141
| return n.hasProperty(ERROR_STRINGS);
|
|
271 |
| } |
|
272 |
| |
|
273 |
| |
|
274 |
| |
|
275 |
| public final static String VARIABLE = "variable"; |
|
276 |
| |
|
277 |
5798
| public static LocalVariable getVariable(Node n) {
|
|
278 |
5798
| return (LocalVariable) n.getProperty(VARIABLE);
|
|
279 |
| } |
|
280 |
| |
|
281 |
4050
| public static LocalVariable setVariable(Node n, LocalVariable v) {
|
|
282 |
4050
| n.setProperty(VARIABLE, v);
|
|
283 |
4050
| return v;
|
|
284 |
| } |
|
285 |
| |
|
286 |
1807
| public static boolean hasVariable(Node n) {
|
|
287 |
1807
| return n.hasProperty(VARIABLE);
|
|
288 |
| } |
|
289 |
| |
|
290 |
| public static final Lambda<Node, LocalVariable> NODE_VARIABLE = new Lambda<Node, LocalVariable>() { |
|
291 |
2275
| public LocalVariable value(Node n) { return getVariable(n); }
|
|
292 |
| }; |
|
293 |
| |
|
294 |
| |
|
295 |
| |
|
296 |
| public final static String CONSTRUCTOR = "constructor"; |
|
297 |
| |
|
298 |
286
| public static DJConstructor getConstructor(Node n) {
|
|
299 |
286
| return (DJConstructor) n.getProperty(CONSTRUCTOR);
|
|
300 |
| } |
|
301 |
| |
|
302 |
620
| public static DJConstructor setConstructor(Node n, DJConstructor c) {
|
|
303 |
620
| n.setProperty(CONSTRUCTOR, c);
|
|
304 |
620
| return c;
|
|
305 |
| } |
|
306 |
| |
|
307 |
0
| public static boolean hasConstructor(Node n) {
|
|
308 |
0
| return n.hasProperty(CONSTRUCTOR);
|
|
309 |
| } |
|
310 |
| |
|
311 |
| |
|
312 |
| |
|
313 |
| public final static String FIELD = "field"; |
|
314 |
| |
|
315 |
295
| public static DJField getField(Node n) {
|
|
316 |
295
| return (DJField) n.getProperty(FIELD);
|
|
317 |
| } |
|
318 |
| |
|
319 |
379
| public static DJField setField(Node n, DJField f) {
|
|
320 |
379
| n.setProperty(FIELD, f);
|
|
321 |
379
| return f;
|
|
322 |
| } |
|
323 |
| |
|
324 |
1807
| public static boolean hasField(Node n) {
|
|
325 |
1807
| return n.hasProperty(FIELD);
|
|
326 |
| } |
|
327 |
| |
|
328 |
| |
|
329 |
| public final static String METHOD = "method"; |
|
330 |
| |
|
331 |
561
| public static DJMethod getMethod(Node n) {
|
|
332 |
561
| return (DJMethod) n.getProperty(METHOD);
|
|
333 |
| } |
|
334 |
| |
|
335 |
422
| public static DJMethod setMethod(Node n, DJMethod m) {
|
|
336 |
422
| n.setProperty(METHOD, m);
|
|
337 |
422
| return m;
|
|
338 |
| } |
|
339 |
| |
|
340 |
0
| public static boolean hasMethod(Node n) {
|
|
341 |
0
| return n.hasProperty(METHOD);
|
|
342 |
| } |
|
343 |
| |
|
344 |
| |
|
345 |
| |
|
346 |
| public final static String DJCLASS = "djclass"; |
|
347 |
| |
|
348 |
33
| public static DJClass getDJClass(Node n) {
|
|
349 |
33
| return (DJClass) n.getProperty(DJCLASS);
|
|
350 |
| } |
|
351 |
| |
|
352 |
158
| public static DJClass setDJClass(Node n, DJClass c) {
|
|
353 |
158
| n.setProperty(DJCLASS, c);
|
|
354 |
158
| return c;
|
|
355 |
| } |
|
356 |
| |
|
357 |
141
| public static boolean hasDJClass(Node n) {
|
|
358 |
141
| return n.hasProperty(DJCLASS);
|
|
359 |
| } |
|
360 |
| |
|
361 |
| |
|
362 |
| |
|
363 |
| public final static String ENCLOSING_THIS = "enclosingThis"; |
|
364 |
| |
|
365 |
0
| public static DJClass getEnclosingThis(Node n) {
|
|
366 |
0
| return (DJClass) n.getProperty(ENCLOSING_THIS);
|
|
367 |
| } |
|
368 |
| |
|
369 |
0
| public static DJClass setEnclosingThis(Node n, DJClass c) {
|
|
370 |
0
| n.setProperty(ENCLOSING_THIS, c);
|
|
371 |
0
| return c;
|
|
372 |
| } |
|
373 |
| |
|
374 |
141
| public static boolean hasEnclosingThis(Node n) {
|
|
375 |
141
| return n.hasProperty(ENCLOSING_THIS);
|
|
376 |
| } |
|
377 |
| |
|
378 |
| |
|
379 |
| |
|
380 |
| public final static String TYPE_VARIABLE = "typeVariable"; |
|
381 |
| |
|
382 |
2146
| public static VariableType getTypeVariable(Node n) {
|
|
383 |
2146
| return (VariableType) n.getProperty(TYPE_VARIABLE);
|
|
384 |
| } |
|
385 |
| |
|
386 |
138
| public static VariableType setTypeVariable(Node n, VariableType v) {
|
|
387 |
138
| n.setProperty(TYPE_VARIABLE, v);
|
|
388 |
138
| return v;
|
|
389 |
| } |
|
390 |
| |
|
391 |
0
| public static boolean hasTypeVariable(Node n) {
|
|
392 |
0
| return n.hasProperty(TYPE_VARIABLE);
|
|
393 |
| } |
|
394 |
| |
|
395 |
| public static final Lambda<Node, VariableType> NODE_TYPE_VARIABLE = new Lambda<Node, VariableType>() { |
|
396 |
1989
| public VariableType value(Node n) { return getTypeVariable(n); }
|
|
397 |
| }; |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
| public final static String ERROR = "error"; |
|
402 |
| |
|
403 |
0
| public static ExecutionError getError(Node n) {
|
|
404 |
0
| return (ExecutionError) n.getProperty(ERROR);
|
|
405 |
| } |
|
406 |
| |
|
407 |
47
| public static ExecutionError setError(Node n, ExecutionError e) {
|
|
408 |
47
| n.setProperty(ERROR, e);
|
|
409 |
47
| return e;
|
|
410 |
| } |
|
411 |
| |
|
412 |
0
| public static boolean hasError(Node n) {
|
|
413 |
0
| return n.hasProperty(ERROR);
|
|
414 |
| } |
|
415 |
| |
|
416 |
| |
|
417 |
| public final static String ERROR_CONTEXT = "errorContext"; |
|
418 |
| |
|
419 |
27
| public static TypeContext getErrorContext(Node n) {
|
|
420 |
27
| return (TypeContext) n.getProperty(ERROR_CONTEXT);
|
|
421 |
| } |
|
422 |
| |
|
423 |
27
| public static TypeContext setErrorContext(Node n, TypeContext c) {
|
|
424 |
27
| n.setProperty(ERROR_CONTEXT, c);
|
|
425 |
27
| return c;
|
|
426 |
| } |
|
427 |
| |
|
428 |
47
| public static boolean hasErrorContext(Node n) {
|
|
429 |
47
| return n.hasProperty(ERROR_CONTEXT);
|
|
430 |
| } |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
| |
|
435 |
| |
|
436 |
| public final static String OPERATION = "operation"; |
|
437 |
| |
|
438 |
129
| @SuppressWarnings("unchecked")
|
|
439 |
| public static Lambda2<Object, Object, Object> getOperation(Node n) { |
|
440 |
129
| return (Lambda2<Object, Object, Object>) n.getProperty(OPERATION);
|
|
441 |
| } |
|
442 |
| |
|
443 |
180
| public static Lambda2<Object, Object, Object> setOperation(Node n,
|
|
444 |
| Lambda2<Object, Object, Object> f) { |
|
445 |
180
| n.setProperty(OPERATION, f);
|
|
446 |
180
| return f;
|
|
447 |
| } |
|
448 |
| |
|
449 |
0
| public static boolean hasOperation(Node n) {
|
|
450 |
0
| return n.hasProperty(OPERATION);
|
|
451 |
| } |
|
452 |
| |
|
453 |
| |
|
454 |
| |
|
455 |
| |
|
456 |
| |
|
457 |
0
| protected NodeProperties() {
|
|
458 |
| } |
|
459 |
| } |