1 package Analysis.Pointer;
7 public class AllocFactory {
8 public static class AllocNode {
13 public AllocNode(int allocsite, TypeDescriptor type, boolean summary) {
14 this.allocsite=allocsite;
19 public TypeDescriptor getType() {
23 public boolean isSummary() {
27 public int hashCode() {
28 return allocsite<<1^(summary?0:1);
31 public boolean equals(Object o) {
32 if (o instanceof AllocNode) {
33 AllocNode an=(AllocNode)o;
34 return (allocsite==an.allocsite)&&(summary==an.summary);
40 public AllocFactory(State state, TypeUtil typeUtil) {
41 allocMap=new HashMap<FlatNew, Integer>();
42 allocNodeMap=new HashMap<AllocNode, AllocNode>();
43 this.typeUtil=typeUtil;
44 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass);
45 TypeDescriptor stringtd=new TypeDescriptor(stringcd);
46 TypeDescriptor stringarraytd=stringtd.makeArray(state);
47 StringArray=new AllocNode(0, stringarraytd, false);
48 Strings=new AllocNode(1, stringtd, true);
51 public int getSiteNumber(FlatNew node) {
52 if (allocMap.containsKey(node))
53 return allocMap.get(node);
54 int index=siteCounter++;
55 allocMap.put(node, index);
59 public AllocNode getAllocNode(FlatNew node, boolean isSummary) {
60 int site=getSiteNumber(node);
61 AllocNode key=new AllocNode(site, node.getType(), isSummary);
62 if (!allocNodeMap.containsKey(key)) {
63 allocNodeMap.put(key, key);
66 return allocNodeMap.get(key);
69 public AllocNode getAllocNode(AllocNode node, boolean isSummary) {
70 int site=node.allocsite;
71 AllocNode key=new AllocNode(site, node.getType(), isSummary);
72 if (!allocNodeMap.containsKey(key)) {
73 allocNodeMap.put(key, key);
76 return allocNodeMap.get(key);
79 HashMap<AllocNode, AllocNode> allocNodeMap;
80 HashMap<FlatNew, Integer> allocMap;
84 public AllocNode StringArray;
85 public AllocNode Strings;