1 package spoon.reflect.eval; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 import java.util.Map.Entry; 6 7 import spoon.reflect.reference.CtTypeReference; 8 9 12 public class SymbolicHeap { 13 14 17 public SymbolicHeap() { 18 } 19 20 23 @SuppressWarnings ("unchecked") 24 public SymbolicHeap(SymbolicHeap heap) { 25 statelessAbstractInstances.putAll(heap.statelessAbstractInstances); 26 for (Entry<String , SymbolicInstance> e : heap.statefullAbstractInstances 27 .entrySet()) { 28 statefullAbstractInstances.put(e.getKey(), new SymbolicInstance(e 29 .getValue())); 30 } 31 } 32 33 36 @Override 37 public String toString() { 38 return "stateful=" + statefullAbstractInstances + " stateless=" 39 + statelessAbstractInstances; 40 } 41 42 45 public void dump() { 46 System.out.println("\tHeap:"); 47 System.out.println("\t - stateful: " + statefullAbstractInstances); 48 System.out.println("\t - stateless: " + statelessAbstractInstances); 49 } 50 51 private Map <String , SymbolicInstance> statefullAbstractInstances = new HashMap <String , SymbolicInstance>(); 52 53 private Map <String , SymbolicInstance> statelessAbstractInstances = new HashMap <String , SymbolicInstance>(); 54 55 65 public <T> SymbolicInstance<T> getType(SymbolicEvaluator evaluator, 66 CtTypeReference<T> concreteType) { 67 SymbolicInstance<T> type = get(SymbolicInstance.getSymbolId( 68 concreteType, "type")); 69 if (type == null) { 70 type = new SymbolicInstance<T>(evaluator, concreteType, true); 71 store(type); 72 } 73 return type; 74 } 75 76 79 public void store(SymbolicInstance instance) { 80 if (instance.isStateful()) { 81 statefullAbstractInstances.put(instance.getId(), instance); 82 } else { 83 statelessAbstractInstances.put(instance.getId(), instance); 84 } 85 } 86 87 90 @SuppressWarnings ("unchecked") 91 public <T> SymbolicInstance<T> get(String id) { 92 SymbolicInstance<T> i = (SymbolicInstance<T>) statelessAbstractInstances 93 .get(id); 94 if (i == null) { 95 i = (SymbolicInstance<T>) statefullAbstractInstances.get(id); 96 } 97 return i; 98 } 99 100 103 public void clear() { 104 statefullAbstractInstances.clear(); 105 } 106 107 } 108 | Popular Tags |