-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathProgramState.java
More file actions
692 lines (578 loc) · 24.7 KB
/
ProgramState.java
File metadata and controls
692 lines (578 loc) · 24.7 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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
package de.peeeq.wurstscript.intermediatelang.interpreter;
import com.google.common.collect.Lists;
import de.peeeq.wurstio.jassinterpreter.InterpreterException;
import de.peeeq.wurstscript.WLogger;
import de.peeeq.wurstscript.ast.Element;
import de.peeeq.wurstscript.attributes.CompileError;
import de.peeeq.wurstscript.gui.WurstGui;
import de.peeeq.wurstscript.intermediatelang.*;
import de.peeeq.wurstscript.jassIm.*;
import de.peeeq.wurstscript.parser.WPos;
import de.peeeq.wurstscript.translation.imtojass.ImAttrType;
import de.peeeq.wurstscript.utils.LineOffsets;
import de.peeeq.wurstscript.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import org.eclipse.jdt.annotation.Nullable;
import java.io.PrintStream;
import java.util.*;
public class ProgramState extends State {
public static final int GENERATED_BY_WURST = 42;
private de.peeeq.wurstscript.jassIm.Element lastStatement;
protected WurstGui gui;
private PrintStream outStream = System.err;
private final List<NativesProvider> nativeProviders = Lists.newArrayList();
private ImProg prog;
private int objectIdCounter;
private final Int2ObjectOpenHashMap<ILconstObject> indexToObject = new Int2ObjectOpenHashMap<>();
private final Int2ObjectOpenHashMap<IlConstHandle> handleMap = new Int2ObjectOpenHashMap<>();
private final Deque<ILStackFrame> stackFrames = new ArrayDeque<>();
private final Deque<de.peeeq.wurstscript.jassIm.Element> lastStatements = new ArrayDeque<>();
private final boolean isCompiletime;
private final Map<ImVar, ImClass> genericStaticOwner = new HashMap<>();
private final Object2ObjectOpenHashMap<String, ILconstArray> genericStaticArrays = new Object2ObjectOpenHashMap<>();
private final IdentityHashMap<ImVar, Object2ObjectOpenHashMap<String, ILconst>> genericStaticVals = new IdentityHashMap<>();
private final Object2ObjectOpenHashMap<String, ILconst> genericStaticScalarVals = new Object2ObjectOpenHashMap<>();
private static boolean containsTypeVariable(ImType type) {
return type.match(new ImType.Matcher<Boolean>() {
@Override public Boolean case_ImTypeVarRef(ImTypeVarRef t) { return true; }
@Override public Boolean case_ImArrayType(ImArrayType t) { return containsTypeVariable(t.getEntryType()); }
@Override public Boolean case_ImArrayTypeMulti(ImArrayTypeMulti t) { return containsTypeVariable(t.getEntryType()); }
@Override public Boolean case_ImClassType(ImClassType t) {
for (ImTypeArgument a : t.getTypeArguments()) {
if (containsTypeVariable(a.getType())) return true;
}
return false;
}
@Override public Boolean case_ImTupleType(ImTupleType t) {
for (ImType x : t.getTypes()) if (containsTypeVariable(x)) return true;
return false;
}
@Override public Boolean case_ImSimpleType(ImSimpleType t) { return false; }
@Override public Boolean case_ImVoid(ImVoid t) { return false; }
@Override public Boolean case_ImAnyType(ImAnyType t) { return false; }
});
}
private String instantiationKey(ImType t) {
if (t instanceof ImClassType) {
ImClassType ct = (ImClassType) t;
StringBuilder sb = new StringBuilder();
sb.append(ct.getClassDef().getName());
if (!ct.getTypeArguments().isEmpty()) {
sb.append('<');
boolean first = true;
for (ImTypeArgument ta : ct.getTypeArguments()) {
if (!first) sb.append(',');
first = false;
sb.append(ta.getType().toString());
}
sb.append('>');
}
return sb.toString();
}
return t.toString();
}
public ProgramState(WurstGui gui, ImProg prog, boolean isCompiletime) {
this.gui = gui;
this.prog = prog;
this.isCompiletime = isCompiletime;
identifyGenericStaticGlobals();
}
private void identifyGenericStaticGlobals() {
Map<String, ImClass> classMap = new HashMap<>();
for (ImClass c : prog.getClasses()) {
classMap.put(c.getName(), c);
}
for (ImVar global : prog.getGlobals()) {
String n = global.getName();
// longest prefix ending at an underscore that matches a class name
int pos = n.lastIndexOf('_');
while (pos > 0) {
String className = n.substring(0, pos);
ImClass owner = classMap.get(className);
if (owner != null && !owner.getTypeVariables().isEmpty()) {
genericStaticOwner.put(global, owner);
break;
}
pos = n.lastIndexOf('_', pos - 1);
}
}
WLogger.trace("[GENSTATIC] owners detected: " + genericStaticOwner.size());
for (var e : genericStaticOwner.entrySet()) {
WLogger.trace("[GENSTATIC] " + e.getKey().getName() + " -> " + e.getValue().getName());
}
}
public void setLastStatement(ImStmt s) {
lastStatement = s;
}
public de.peeeq.wurstscript.jassIm.Element getLastStatement() {
return lastStatement;
}
public WurstGui getGui() {
return gui;
}
public void writeBack(boolean injectObjects) {
}
public PrintStream getOutStream() {
return outStream;
}
public void setOutStream(PrintStream os) {
outStream = os;
for (NativesProvider natives : nativeProviders) {
natives.setOutStream(os);
}
}
public void addNativeProvider(NativesProvider np) {
np.setOutStream(outStream);
nativeProviders.add(np);
}
public Iterable<NativesProvider> getNativeProviders() {
return nativeProviders;
}
public ProgramState setProg(ImProg p) {
prog = p;
return this;
}
public ImProg getProg() {
return prog;
}
public ILconstObject allocate(ImClassType clazz, Element trace) {
objectIdCounter++;
ILconstObject res = new ILconstObject(clazz, objectIdCounter, trace);
indexToObject.put(objectIdCounter, res);
WLogger.trace("alloc objId=" + objectIdCounter + " type=" + clazz + " trace=" + trace);
return res;
}
protected Object classKey(ImClass clazz) {
return clazz;
}
public void deallocate(ILconstObject obj, ImClass clazz, Element trace) {
assertAllocated(obj, trace);
obj.destroy();
// TODO recycle ids
}
public void assertAllocated(ILconstObject obj, Element trace) {
if (obj == null) {
throw new InterpreterException(trace, "Null pointer dereference. The interpreter expected an object here, but found null.");
}
if (obj.isDestroyed()) {
throw new InterpreterException(trace, "Object already destroyed");
}
}
public boolean isInstanceOf(ILconstObject obj, ImClass clazz, Element trace) {
if (obj == null) {
return false;
}
assertAllocated(obj, trace);
return obj.getImClass().isSubclassOf(clazz); // TODO more efficient check
}
public int getTypeId(ILconstObject obj, Element trace) {
assertAllocated(obj, trace);
return obj.getImClass().attrTypeId();
}
private ImClass findClazz(Object key) {
for (ImClass c : prog.getClasses()) {
if (classKey(c).equals(key)) {
return c;
}
}
throw new Error("no class found for key " + key);
}
public void pushStackframeWithTypes(ImFunction f, @Nullable ILconstObject receiver,
ILconst[] args, WPos trace,
Map<ImTypeVar, ImType> typeSubstitutions) {
// normalize the incoming map: RHS = fully resolved type
Map<ImTypeVar, ImType> normalized = new HashMap<>();
for (Map.Entry<ImTypeVar, ImType> e : typeSubstitutions.entrySet()) {
ImType rhs = resolveType(e.getValue()); // resolve through existing frames
// skip self-maps (T -> T)
if (rhs instanceof ImTypeVarRef &&
((ImTypeVarRef) rhs).getTypeVariable() == e.getKey()) {
continue;
}
normalized.put(e.getKey(), rhs);
}
WLogger.trace("pushStackframe " + f + " with receiver " + receiver
+ " and args " + Arrays.toString(args) + " and typesubst " + normalized);
// new Exception().printStackTrace(System.out);
stackFrames.push(new ILStackFrame(f, receiver, args, trace, normalized));
de.peeeq.wurstscript.jassIm.Element stmt = this.lastStatement;
if (stmt == null) stmt = f;
lastStatements.push(stmt);
}
private @Nullable String ownerInstantiationKeyFromTypeSubst(ImClass owner) {
if (owner.getTypeVariables().isEmpty()) return owner.getName();
StringBuilder sb = new StringBuilder();
sb.append(owner.getName()).append('<');
boolean first = true;
boolean anyConcrete = false;
for (ImTypeVar tv : owner.getTypeVariables()) {
if (!first) sb.append(',');
first = false;
// resolve T -> concrete type using current stack substitutions
ImType resolved = resolveType(JassIm.ImTypeVarRef(tv));
sb.append(resolved.toString());
if (!(resolved instanceof ImTypeVarRef)) {
anyConcrete = true;
}
}
sb.append('>');
// If nothing was resolved (still just type vars), let caller fallback.
return anyConcrete ? sb.toString() : null;
}
private @Nullable String genericStaticKey(ImVar v) {
ImClass owner = genericStaticOwner.get(v);
if (owner == null) return null;
String ownerInst = ownerInstantiationKeyFromTypeSubst(owner);
WLogger.trace("[GENSTATIC] key for " + v.getName()
+ " owner=" + owner.getName()
+ " ownerInstFromSubst=" + ownerInst
+ " receiver=" + (stackFrames.peek() == null ? null : stackFrames.peek().receiver));
if (ownerInst != null) {
return v.getName() + "|" + ownerInst;
}
// fallback: previous receiver-based logic
ImClassType inst = currentReceiverInstantiationFor(owner);
WLogger.trace("[GENSTATIC] key for " + v.getName()
+ " owner=" + owner.getName()
+ " ownerInstFromSubst=" + ownerInst
+ " receiver=" + (stackFrames.peek() == null ? null : stackFrames.peek().receiver));
if (inst != null) {
return v.getName() + "|" + instantiationKey(inst);
}
return v.getName() + "|<no-receiver>";
}
private @Nullable ImClassType currentReceiverInstantiationFor(ImClass owner) {
ILStackFrame top = stackFrames.peek();
if (top == null || top.receiver == null) return null;
ImClassType rt = top.receiver.getType();
// resolve possible type vars inside type args
ImType resolved = resolveType(rt);
if (resolved instanceof ImClassType) {
rt = (ImClassType) resolved;
}
ImClassType adapted = adaptToSuperclass(rt, owner);
return adapted != null ? adapted : rt;
}
private @Nullable ImClassType adaptToSuperclass(ImClassType ct, ImClass owner) {
if (ct.getClassDef() == owner) return ct;
// Walk super types, substituting this ct's type args into the superclass types
List<ImTypeVar> tvs = ct.getClassDef().getTypeVariables();
ImTypeArguments tas = ct.getTypeArguments();
for (ImClassType scRaw : ct.getClassDef().getSuperClasses()) {
ImType scSubst = ImAttrType.substituteType(scRaw, tas, tvs);
scSubst = resolveType(scSubst);
if (scSubst instanceof ImClassType) {
ImClassType r = adaptToSuperclass((ImClassType) scSubst, owner);
if (r != null) return r;
}
}
return null;
}
public ImType resolveType(ImType t) {
return resolveTypeDeep(t, 32); // small budget to avoid cycles
}
private ImType resolveTypeDeep(ImType t, int budget) {
if (budget <= 0 || t == null) return t;
return t.match(new ImType.Matcher<ImType>() {
@Override
public ImType case_ImTypeVarRef(ImTypeVarRef tvr) {
// search from top-most frame down
for (ILStackFrame sf : stackFrames) { /* we iterate deque top-first: use an iterator if needed */
ImType mapped = sf.typeSubstitutions.get(tvr.getTypeVariable());
if (mapped != null) {
ImType resolved = resolveTypeDeep(mapped, budget - 1);
return resolved;
}
}
// no mapping anywhere -> keep the type var
return tvr;
}
@Override
public ImType case_ImClassType(ImClassType ct) {
if (ct.getTypeArguments().isEmpty()) return ct;
ImTypeArguments newArgs = JassIm.ImTypeArguments();
boolean changed = false;
for (ImTypeArgument ta : ct.getTypeArguments()) {
ImType rt = resolveTypeDeep(ta.getType(), budget - 1);
newArgs.add(JassIm.ImTypeArgument(rt, ta.getTypeClassBinding()));
changed |= (rt != ta.getType());
}
return changed ? JassIm.ImClassType(ct.getClassDef(), newArgs) : ct;
}
@Override
public ImType case_ImArrayType(ImArrayType at) {
ImType et = resolveTypeDeep(at.getEntryType(), budget - 1);
return et == at.getEntryType() ? at : JassIm.ImArrayType(et);
}
@Override
public ImType case_ImArrayTypeMulti(ImArrayTypeMulti at) {
ImType et = resolveTypeDeep(at.getEntryType(), budget - 1);
return et == at.getEntryType() ? at : JassIm.ImArrayTypeMulti(et, at.getArraySize());
}
@Override
public ImType case_ImTupleType(ImTupleType tt) {
List<ImType> nts = new ArrayList<>();
List<String> names = new ArrayList<>();
boolean changed = false;
var i = 0;
for (ImType it : tt.getTypes()) {
ImType rt = resolveTypeDeep(it, budget - 1);
nts.add(rt);
changed |= (rt != it);
i++;
names.add(i + "");
}
return changed ? JassIm.ImTupleType(nts, names) : tt;
}
@Override public ImType case_ImSimpleType(ImSimpleType st) { return st; }
@Override public ImType case_ImAnyType(ImAnyType at) { return at; }
@Override public ImType case_ImVoid(ImVoid v) { return v; }
});
}
// Helper method to substitute type variables
private ImType substituteTypeVars(ImType type, Map<ImTypeVar, ImType> substitutions) {
return type.match(new ImType.Matcher<ImType>() {
@Override
public ImType case_ImTypeVarRef(ImTypeVarRef typeVarRef) {
ImType concrete = substitutions.get(typeVarRef.getTypeVariable());
return concrete != null ? concrete : typeVarRef;
}
@Override
public ImType case_ImClassType(ImClassType classType) {
// Recursively substitute in type arguments
ImTypeArguments newArgs = JassIm.ImTypeArguments();
for (ImTypeArgument arg : classType.getTypeArguments()) {
ImType substituted = substituteTypeVars(arg.getType(), substitutions);
newArgs.add(JassIm.ImTypeArgument(substituted, arg.getTypeClassBinding()));
}
return JassIm.ImClassType(classType.getClassDef(), newArgs);
}
// For other types, return as-is
@Override
public ImType case_ImSimpleType(ImSimpleType t) {
return t;
}
@Override
public ImType case_ImArrayType(ImArrayType t) {
return t;
}
@Override
public ImType case_ImTupleType(ImTupleType t) {
return t;
}
@Override
public ImType case_ImVoid(ImVoid t) {
return t;
}
@Override
public ImType case_ImAnyType(ImAnyType t) {
return t;
}
@Override
public ImType case_ImArrayTypeMulti(ImArrayTypeMulti t) {
return t;
}
});
}
public void pushStackframe(ImCompiletimeExpr f, WPos trace) {
WLogger.trace("pushStackframe compiletime expr " + f);
stackFrames.push(new ILStackFrame(f, trace));
de.peeeq.wurstscript.jassIm.Element stmt = this.lastStatement;
if (stmt == null) {
stmt = f;
}
lastStatements.push(stmt);
}
public void popStackframe() {
// new Exception().printStackTrace(System.out);
WLogger.trace("popStackframe " + (stackFrames.isEmpty() ? "empty" : stackFrames.peek().f));
if (!stackFrames.isEmpty()) {
stackFrames.pop();
}
if (!lastStatements.isEmpty()) {
lastStatement = lastStatements.pop();
}
}
public void resetStackframes() {
stackFrames.clear();
lastStatements.clear();
}
public StackTrace getStackFrames() {
return new StackTrace(stackFrames);
}
public void compilationError(String errorMessage) {
de.peeeq.wurstscript.jassIm.Element lastStatement = getLastStatement();
if (lastStatement != null) {
WPos source = lastStatement.attrTrace().attrSource();
getGui().sendError(new CompileError(source, errorMessage));
} else {
getGui().sendError(new CompileError(new WPos("", new LineOffsets(), 0, 0), errorMessage));
}
for (ILStackFrame sf : Utils.iterateReverse(getStackFrames().getStackFrames())) {
getGui().sendError(sf.makeCompileError());
}
}
public ILconst getObjectByIndex(int val) {
return indexToObject.get(val);
}
public Map<Integer, IlConstHandle> getHandleMap() {
return handleMap;
}
public ILconst getHandleByIndex(int val) {
return handleMap.get(val);
}
public ILconstObject ensureObject(ImClassType clazz, int objectId, Element trace) {
ILconstObject existing = indexToObject.get(objectId);
if (existing != null) {
return existing;
}
ILconstObject res = new ILconstObject(clazz, objectId, trace);
indexToObject.put(objectId, res);
return res;
}
public ILconstObject toObject(ILconst val) {
if (val instanceof ILconstObject) {
return (ILconstObject) val;
} else if (val instanceof ILconstInt) {
return indexToObject.get(((ILconstInt) val).getVal());
}
throw new InterpreterException(this, "Value " + val + " (" + val.getClass().getSimpleName() + ") cannot be cast to object.");
}
public static class StackTrace {
private final List<ILStackFrame> stackFrames;
public StackTrace(Deque<ILStackFrame> frames) {
// copy once into an array-backed list
this.stackFrames = Collections.unmodifiableList(new ArrayList<>(frames));
}
public void appendTo(StringBuilder sb) {
for (ILStackFrame sf : stackFrames) {
sb.append(sf.getMessage()).append('\n');
}
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(stackFrames.size() * 32);
appendTo(sb);
return sb.toString();
}
public List<ILStackFrame> getStackFrames() {
return stackFrames;
}
public Iterable<ILStackFrame> getStackFramesReversed() {
return () -> new Iterator<ILStackFrame>() {
int i = stackFrames.size() - 1;
@Override
public boolean hasNext() {
return i >= 0;
}
@Override
public ILStackFrame next() {
return stackFrames.get(i--);
}
};
}
}
public String instantiationKey(ImClassType ct) {
StringBuilder sb = new StringBuilder();
sb.append(ct.getClassDef().getName());
if (!ct.getTypeArguments().isEmpty()) {
sb.append('<');
boolean first = true;
for (ImTypeArgument ta : ct.getTypeArguments()) {
if (!first) sb.append(',');
first = false;
sb.append(ta.toString()); // or your own stable printer
}
sb.append('>');
}
return sb.toString();
}
private static String vid(ImVar v) {
return v.getName() + "@" + System.identityHashCode(v);
}
@Override
public void setVal(ImVar v, ILconst val) {
String key = genericStaticKey(v);
if (key != null) {
WLogger.trace("[GENSTATIC] set " + key + " = " + val);
genericStaticScalarVals.put(key, val);
return;
}
super.setVal(v, val);
}
@Override
public @Nullable ILconst getVal(ImVar v) {
String key = genericStaticKey(v);
if (key != null) {
ILconst existing = genericStaticScalarVals.get(key);
if (existing != null) {
WLogger.trace("[GENSTATIC] get " + key + " -> (cached) " + existing);
return existing;
}
// lazy init from global inits (e.g. foo = 1)
List<ImSet> inits = prog.getGlobalInits().get(v);
if (inits != null && !inits.isEmpty()) {
ILconst initVal = inits.get(inits.size() - 1).getRight().evaluate(this, EMPTY_LOCAL_STATE);
genericStaticScalarVals.put(key, initVal);
System.out.println("[GENSTATIC] get " + key + " -> (init) " + initVal);
return initVal;
}
// fallback: default semantics (if your interpreter expects “unset = null/0”)
System.out.println("[GENSTATIC] get " + key + " -> (unset) null");
return null;
}
return super.getVal(v);
}
public boolean isCompiletime() {
return isCompiletime;
}
// Reuse a shared, empty LocalState (ensure it's safe/side-effect free)
private static final LocalState EMPTY_LOCAL_STATE = new LocalState();
@Override
protected ILconstArray getArray(ImVar v) {
String key = genericStaticKey(v);
if (key != null) {
ILconstArray arr = genericStaticArrays.get(key);
if (arr != null) return arr;
ILconstArray r = createArrayConstantFromType(v.getType());
genericStaticArrays.put(key, r);
List<ImSet> inits = prog.getGlobalInits().get(v);
if (inits != null && !inits.isEmpty()) {
final LocalState ls = EMPTY_LOCAL_STATE;
for (int i = 0; i < inits.size(); i++) {
ILconst val = inits.get(i).getRight().evaluate(this, ls);
r.set(i, val);
}
}
return r;
}
// non-generic case = your existing logic
Object2ObjectOpenHashMap<ImVar, ILconstArray> arrayValues = ensureArrayValues();
ILconstArray r = arrayValues.get(v);
if (r != null) return r;
r = createArrayConstantFromType(v.getType());
arrayValues.put(v, r);
List<ImSet> inits = prog.getGlobalInits().get(v);
if (inits != null && !inits.isEmpty()) {
final LocalState ls = EMPTY_LOCAL_STATE;
for (int i = 0; i < inits.size(); i++) {
ILconst val = inits.get(i).getRight().evaluate(this, ls);
r.set(i, val);
}
}
return r;
}
public Collection<ILconstObject> getAllObjects() {
return indexToObject.values();
}
public Map<ImTypeVar, ImType> snapshotResolvedTypeSubstitutions() {
Map<ImTypeVar, ImType> res = new HashMap<>();
for (ILStackFrame sf : stackFrames) { // top-first
for (Map.Entry<ImTypeVar, ImType> e : sf.typeSubstitutions.entrySet()) {
res.putIfAbsent(e.getKey(), resolveType(e.getValue()));
}
}
return res;
}
}