Patch in effects analysis hooks....have to add new accessor methods...add interface...
[IRC.git] / Robust / src / Analysis / Pointer / AllocFactory.java
1 package Analysis.Pointer;
2
3 import Analysis.Disjoint.Alloc;
4 import java.util.*;
5 import IR.*;
6 import IR.Flat.*;
7
8 public class AllocFactory {
9   public static class AllocNode implements Alloc {
10     int allocsite;
11     boolean summary;
12     FlatNew node;
13     
14     public AllocNode(int allocsite, FlatNew node, boolean summary) {
15       this.allocsite=allocsite;
16       this.summary=summary;
17       this.node=node;
18     }
19
20     public TypeDescriptor getType() {
21       return node.getType();
22     }
23
24     public FlatNew getFlatNew() {
25       return node;
26     }
27
28     public int getUniqueAllocSiteID() {
29       return allocsite;
30     }
31
32     public boolean isSummary() {
33       return summary;
34     }
35     
36     public int hashCode() {
37       return allocsite<<1^(summary?0:1);
38     }
39     
40     public boolean equals(Object o) {
41       if (o instanceof AllocNode) {
42         AllocNode an=(AllocNode)o;
43         return (allocsite==an.allocsite)&&(summary==an.summary);
44       }
45       return false;
46     }
47
48     public String toStringBrief() {
49       return getID();
50     }
51     
52     public String toString() {
53       return getID();
54     }
55
56     public String getID() {
57       if (summary)
58         return "SUM"+allocsite;
59       else
60         return "SING"+allocsite;
61     }
62   }
63
64   public AllocFactory(State state, TypeUtil typeUtil) {
65     allocMap=new HashMap<FlatNew, Integer>();
66     allocNodeMap=new HashMap<AllocNode, AllocNode>();
67     this.typeUtil=typeUtil;
68     ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass);
69     TypeDescriptor stringtd=new TypeDescriptor(stringcd);
70     TypeDescriptor stringarraytd=stringtd.makeArray(state);
71     StringArray=new AllocNode(0, new FlatNew(stringarraytd, null, false), false);
72     Strings=new AllocNode(1, new FlatNew(stringtd, null, false), true);
73   }
74
75   public int getSiteNumber(FlatNew node) {
76     if (allocMap.containsKey(node))
77       return allocMap.get(node);
78     int index=siteCounter++;
79     allocMap.put(node, index);
80     return index;
81   }
82
83   public AllocNode getAllocNode(FlatNew node, boolean isSummary) {
84     int site=getSiteNumber(node);
85     AllocNode key=new AllocNode(site, node, isSummary);
86     if (!allocNodeMap.containsKey(key)) {
87       allocNodeMap.put(key, key);
88       return key;
89     } else
90       return allocNodeMap.get(key);
91   }
92
93   public AllocNode getAllocNode(AllocNode node, boolean isSummary) {
94     int site=node.allocsite;
95     AllocNode key=new AllocNode(site, node.node, isSummary);
96     if (!allocNodeMap.containsKey(key)) {
97       allocNodeMap.put(key, key);
98       return key;
99     } else
100       return allocNodeMap.get(key);
101   }
102
103   HashMap<AllocNode, AllocNode> allocNodeMap;
104   HashMap<FlatNew, Integer> allocMap;
105   TypeUtil typeUtil;
106   int siteCounter=2;
107
108   public AllocNode StringArray;
109   public AllocNode Strings;
110 }