1 package Analysis.Pointer;
3 import Analysis.Disjoint.Alloc;
8 public class AllocFactory {
9 public static class AllocNode implements Alloc {
14 public AllocNode(int allocsite, FlatNew node, boolean summary) {
15 this.allocsite=allocsite;
20 public TypeDescriptor getType() {
21 return node.getType();
24 public FlatNew getFlatNew() {
28 public int getUniqueAllocSiteID() {
32 public boolean isSummary() {
36 public int hashCode() {
37 return allocsite<<1^(summary?0:1);
40 public boolean equals(Object o) {
41 if (o instanceof AllocNode) {
42 AllocNode an=(AllocNode)o;
43 return (allocsite==an.allocsite)&&(summary==an.summary);
48 public String toStringBrief() {
52 public String toString() {
56 public String getID() {
58 return "SUM"+allocsite;
60 return "SING"+allocsite;
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);
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);
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);
90 return allocNodeMap.get(key);
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);
100 return allocNodeMap.get(key);
103 HashMap<AllocNode, AllocNode> allocNodeMap;
104 HashMap<FlatNew, Integer> allocMap;
108 public AllocNode StringArray;
109 public AllocNode Strings;