This commit was manufactured by cvs2svn to create tag 'buildscript'.
[IRC.git] /
1 package Analysis.Locality;
2 import IR.MethodDescriptor;
3
4 public class LocalityBinding {
5   private MethodDescriptor md;
6   private Integer[] isglobal;
7   private boolean isatomic;
8   private Integer isglobalreturn;
9   private Integer isglobalthis;
10   private LocalityBinding parent;
11   private boolean hasatomic;
12
13   public LocalityBinding(MethodDescriptor md, boolean atomic) {
14     this.md=md;
15     isglobal=new Integer[md.numParameters()];
16     isatomic=atomic;
17   }
18
19   public void setHasAtomic() {
20     hasatomic=true;
21   }
22
23   public boolean getHasAtomic() {
24     return hasatomic;
25   }
26
27   private static String globalToString(Integer g) {
28     if (g==LocalityAnalysis.GLOBAL)
29       return "G";
30     else if (g==LocalityAnalysis.LOCAL)
31       return "L";
32     else if (g==LocalityAnalysis.EITHER)
33       return "E";
34     else if (g==LocalityAnalysis.CONFLICT)
35       return "C";
36     else throw new Error();
37   }
38
39   public String getSignature() {
40     if (md.getModifiers().isNative())
41       return "";
42     String st="_";
43     if (isatomic) {
44       st+="A";
45     } else
46       st+="N";
47     if (isglobalthis==null)
48       st+="N";
49     else
50       st+=globalToString(isglobalthis);
51     for(int i=0; i<isglobal.length; i++) {
52       st+=globalToString(isglobal[i]);
53     }
54     st+="_";
55     return st;
56   }
57
58   /* Use this for an explanation */
59   public void setParent(LocalityBinding lb) {
60     parent=lb;
61   }
62
63   public String getExplanation() {
64     if (parent==null)
65       return toString();
66     else
67       return parent.getExplanation()+"\n"+toString();
68   }
69
70   public String toString() {
71     String st=md.toString()+" ";
72     if (isglobalthis==null) {
73       st+="[static] ";
74     } else {
75       if (isglobalthis.equals(LocalityAnalysis.LOCAL))
76         st+="[local] ";
77       else if (isglobalthis.equals(LocalityAnalysis.GLOBAL))
78         st+="[global] ";
79       else if (isglobalthis.equals(LocalityAnalysis.EITHER))
80         st+="[either] ";
81       else if (isglobalthis.equals(LocalityAnalysis.CONFLICT))
82         st+="[conflict] ";
83     }
84     for(int i=0; i<isglobal.length; i++)
85       if (isglobal[i].equals(LocalityAnalysis.LOCAL))
86         st+="local ";
87       else if (isglobal[i].equals(LocalityAnalysis.GLOBAL))
88         st+="global ";
89       else if (isglobal[i].equals(LocalityAnalysis.EITHER))
90         st+="either ";
91       else if (isglobal[i].equals(LocalityAnalysis.CONFLICT))
92         st+="conflict ";
93     return st;
94   }
95
96   public void setGlobal(int i, Integer global) {
97     isglobal[i]=global;
98   }
99
100   public Integer isGlobal(int i) {
101     return isglobal[i];
102   }
103
104   public void setGlobalReturn(Integer global) {
105     isglobalreturn=global;
106   }
107
108   public Integer getGlobalReturn() {
109     return isglobalreturn;
110   }
111
112   public void setGlobalThis(Integer global) {
113     isglobalthis=global;
114   }
115
116   public Integer getGlobalThis() {
117     return isglobalthis;
118   }
119
120   public MethodDescriptor getMethod() {
121     return md;
122   }
123
124   public boolean isAtomic() {
125     return isatomic;
126   }
127
128   public boolean contextMatches(LocalityBinding lb) {
129     if (isglobal.length!=lb.isglobal.length)
130       return false;
131     for(int i=0; i<isglobal.length; i++)
132       if (!isglobal[i].equals(lb.isglobal[i]))
133         return false;
134
135     if (isglobalthis==null) {
136       if (lb.isglobalthis!=null)
137         return false;
138     } else
139     if (!isglobalthis.equals(lb.isglobalthis))
140       return false;
141     return (isatomic==lb.isatomic);
142   }
143
144   public boolean equals(Object o) {
145     if (o instanceof LocalityBinding) {
146       LocalityBinding lb=(LocalityBinding)o;
147       if (md!=lb.md)
148         return false;
149
150       for(int i=0; i<isglobal.length; i++)
151         if (!isglobal[i].equals(lb.isglobal[i]))
152           return false;
153
154       if (isglobalthis==null) {
155         if (lb.isglobalthis!=null)
156           return false;
157       } else
158       if (!isglobalthis.equals(lb.isglobalthis))
159         return false;
160       return (isatomic==lb.isatomic);
161     }
162     return false;
163   }
164
165   public int hashCode() {
166     int hashcode=md.hashCode();
167     for(int i=0; i<isglobal.length; i++) {
168       hashcode=hashcode*31+(isglobal[i].intValue());
169     }
170     hashcode=hashcode*31+(isatomic ? 1 : 0);
171     return hashcode;
172   }
173 }