More pieces for new version of analysis
[IRC.git] / Robust / src / Analysis / MLP / MethodSummary.java
1 package Analysis.MLP;
2
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
6 import java.util.Set;
7
8 public class MethodSummary {
9         
10         public static final Integer VOID=new Integer(0);
11         public static final Integer ACCESSIBLE = new Integer(1);
12         public static final Integer INACCESSIBLE=new Integer(2);
13
14         private int childSESECount;
15         private HashSet<PreEffectsKey> effectsSet;
16         private Integer accessibility;
17         private StallSite returnStallSite;
18         
19         private Hashtable<Integer, HashSet<StallTag>> mapParamIndexToRelatedStallTag;
20         
21         public MethodSummary() {
22                 effectsSet = new HashSet<PreEffectsKey>();
23                 accessibility = MethodSummary.VOID;
24                 childSESECount = 0;
25                 returnStallSite=null;
26                 mapParamIndexToRelatedStallTag=new Hashtable<Integer, HashSet<StallTag>>();
27         }
28         
29         public void addStallParamIdxSet(Set<Integer> paramIdxSet, HashSet<StallTag> stallTagSet){
30                 
31                 if(paramIdxSet!=null){
32                         for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
33                                 Integer paramIdx = (Integer) iterator.next();
34                                 mapParamIndexToRelatedStallTag.put(paramIdx, stallTagSet);
35                         }
36                 }
37         }
38         
39         public HashSet<StallTag> getStallTagByParamIdx(Integer paramIdx){
40                 return mapParamIndexToRelatedStallTag.get(paramIdx);
41         }
42         
43         
44         public Set<Integer> getStallParamIdxSet(){
45                 return mapParamIndexToRelatedStallTag.keySet();
46         }
47         
48         public void setReturnStallSite(StallSite ss){
49                 returnStallSite=ss;
50         }
51         
52         public StallSite getReturnStallSite(){
53                 return returnStallSite;
54         }
55
56         public void increaseChildSESECount() {
57                 childSESECount++;
58         }
59
60         public int getChildSESECount() {
61                 return childSESECount;
62         }
63
64         public Integer getReturnValueAccessibility() {
65                 return accessibility;
66         }
67
68         public void setReturnValueAccessibility(Integer accessibility) {
69                 this.accessibility = accessibility;
70         }
71
72         public HashSet<PreEffectsKey> getEffectsSet() {
73                 return effectsSet;
74         }
75
76         @Override
77         public String toString() {
78                 return "MethodSummary [accessibility=" + accessibility
79                                 + ", childSESECount=" + childSESECount + ", effectsSet="
80                                 + effectsSet + "]";
81         }
82         
83         public HashSet<PreEffectsKey> getEffectsSetByParamIdx(int paramIdx){
84                 
85                 HashSet<PreEffectsKey> returnSet=new HashSet<PreEffectsKey>();
86
87                 for (Iterator iterator = effectsSet.iterator(); iterator.hasNext();) {
88                         PreEffectsKey preEffectsKey = (PreEffectsKey) iterator.next();
89                         if(preEffectsKey.getParamIndex().equals(new Integer(paramIdx))){
90                                 returnSet.add(preEffectsKey);
91                         }
92                 }
93                 
94                 return returnSet;
95         }
96         
97 }
98
99 class PreEffectsKey {
100
101         public static final Integer READ_EFFECT = new Integer(1);
102         public static final Integer WRITE_EFFECT = new Integer(2);
103
104         private String type;
105         private String field;
106         private Integer effectType;
107         private Integer paramIndex;
108
109         public PreEffectsKey(Integer paramIndex, String field, String type,
110                         Integer effectType) {
111                 this.paramIndex = paramIndex;
112                 this.field = field;
113                 this.type = type;
114                 this.effectType = effectType;
115         }
116
117         public String getType() {
118                 return type;
119         }
120
121         public String getField() {
122                 return field;
123         }
124
125         public Integer getEffectType() {
126                 return effectType;
127         }
128
129         public Integer getParamIndex() {
130                 return paramIndex;
131         }
132
133         public String toString() {
134                 return "PreEffectsKey [effectType=" + effectType + ", field=" + field
135                                 + ", paramIndex=" + paramIndex + ", type=" + type + "]";
136         }
137
138         public boolean equals(Object o) {
139
140                 if (o == null) {
141                         return false;
142                 }
143
144                 if (!(o instanceof PreEffectsKey)) {
145                         return false;
146                 }
147
148                 PreEffectsKey in = (PreEffectsKey) o;
149
150                 if (paramIndex.equals(in.getParamIndex())
151                                 && field.equals(in.getField()) && type.equals(in.getType())
152                                 && effectType.equals(in.getEffectType())) {
153                         return true;
154                 } else {
155                         return false;
156                 }
157
158         }
159
160 }