start of new file
[IRC.git] / Robust / src / IR / Flat / FlatFlagActionNode.java
1 package IR.Flat;
2 import Analysis.TaskStateAnalysis.FlagState;
3 import IR.ClassDescriptor;
4 import IR.FlagDescriptor;
5 import IR.TagDescriptor;
6 import java.util.Hashtable;
7 import java.util.HashSet;
8 import java.util.Iterator;
9 import java.util.Vector;
10
11 public class FlatFlagActionNode extends FlatNode {
12     Hashtable<TempFlagPair, Boolean> tempflagpairs; 
13     Hashtable<TempTagPair, Boolean> temptagpairs; 
14
15     int taskexit;
16     public static final int NEWOBJECT=0;
17     public static final int PRE=1;
18     public static final int TASKEXIT=2;
19     
20     Hashtable<ClassDescriptor, Vector<FlagState>> cd2initfs;
21     Hashtable<ClassDescriptor, Vector<FlagState>> cd2fs4new;
22     Hashtable<FlagState, Vector<FlagState>> fs2fs;
23
24
25     public FlatFlagActionNode(int taskexit) {
26         tempflagpairs=new Hashtable<TempFlagPair, Boolean>();
27         temptagpairs=new Hashtable<TempTagPair, Boolean>();
28         this.taskexit=taskexit;
29         
30         this.cd2initfs = null;
31         this.cd2fs4new = null;
32         this.fs2fs = null;
33     }
34
35     public int getTaskType() {
36         return taskexit;
37     }
38     
39     public Vector<FlagState> getInitFStates(ClassDescriptor cd) {
40         if(this.cd2initfs == null) {
41             this.cd2initfs = new Hashtable<ClassDescriptor, Vector<FlagState>>();
42         }
43         if(this.cd2initfs.get(cd) == null) {
44             this.cd2initfs.put(cd, new Vector<FlagState>());
45         }
46         return this.cd2initfs.get(cd);
47     }
48     
49     public Vector<FlagState> getTargetFStates4NewObj(ClassDescriptor cd) {
50         if(this.cd2fs4new == null) {
51             this.cd2fs4new = new Hashtable<ClassDescriptor, Vector<FlagState>>();
52         }
53         if(this.cd2fs4new.get(cd) == null) {
54             this.cd2fs4new.put(cd, new Vector<FlagState>());
55         }
56         return this.cd2fs4new.get(cd);
57     }
58     
59     public Vector<FlagState> getTargetFStates(FlagState fs) {
60         if(this.fs2fs == null) {
61             this.fs2fs = new Hashtable<FlagState, Vector<FlagState>>();
62         }
63         if(this.fs2fs.get(fs) == null) {
64             this.fs2fs.put(fs, new Vector<FlagState>());
65         }
66         return this.fs2fs.get(fs);
67     }
68
69     public void addFlagAction(TempDescriptor td, FlagDescriptor fd, boolean status) {
70         TempFlagPair tfp=new TempFlagPair(td,fd);
71         if (tempflagpairs.containsKey(tfp)) {
72             throw new Error("Temp/Flag combination used twice: "+tfp);
73         }
74         tempflagpairs.put(tfp, new Boolean(status));
75     }
76
77     public void addTagAction(TempDescriptor td, TagDescriptor tagd, TempDescriptor tagt, boolean status) {
78         TempTagPair ttp=new TempTagPair(td,tagd, tagt);
79         if (temptagpairs.containsKey(ttp)) {
80             throw new Error("Temp/Tag combination used twice: "+ttp);
81         }
82         temptagpairs.put(ttp, new Boolean(status));
83     }
84
85     public int kind() {
86         return FKind.FlatFlagActionNode;
87     }
88     
89     /** This method returns an iterator over the Temp/Flag pairs. */
90     
91     public Iterator<TempFlagPair> getTempFlagPairs() {
92         return tempflagpairs.keySet().iterator();
93     }
94
95     public Iterator<TempTagPair> getTempTagPairs() {
96         return temptagpairs.keySet().iterator();
97     }
98
99     public boolean getFlagChange(TempFlagPair tfp) {
100         return ((Boolean)tempflagpairs.get(tfp)).booleanValue();
101     }
102
103     public boolean getTagChange(TempTagPair ttp) {
104         return ((Boolean)temptagpairs.get(ttp)).booleanValue();
105     }
106
107     public TempDescriptor [] readsTemps() {
108         if (tempflagpairs.size()==0)
109             return new TempDescriptor [0];
110         else {
111             HashSet temps=new HashSet();
112             for(Iterator it=tempflagpairs.keySet().iterator();it.hasNext();) {
113                 TempFlagPair tfp=(TempFlagPair)it.next();
114                 temps.add(tfp.getTemp());
115             }
116             for(Iterator it=temptagpairs.keySet().iterator();it.hasNext();) {
117                 TempTagPair ttp=(TempTagPair)it.next();
118                 temps.add(ttp.getTemp());
119                 temps.add(ttp.getTagTemp());
120             }
121             return (TempDescriptor[]) temps.toArray(new TempDescriptor [temps.size()]);
122         }
123     }
124
125     public int getFFANType()
126     {
127         throw new Error("Use getTaskType() instead and remove this method");
128     }
129
130     public String toString() {
131         String st="FlatFlagActionNode_";
132         for(Iterator it=tempflagpairs.keySet().iterator();it.hasNext();) {
133             TempFlagPair tfp=(TempFlagPair)it.next();
134             st+=getFlagChange(tfp)?"":"!";
135             st+=tfp.getTemp()+" "+tfp.getFlag()+",";
136         }
137         for(Iterator it=temptagpairs.keySet().iterator();it.hasNext();) {
138             TempTagPair ttp=(TempTagPair)it.next();
139             st+=getTagChange(ttp)?"":"!";
140             st+=ttp.getTemp()+" "+ttp.getTag()+"("+ttp.getTagTemp()+"),";
141         }
142
143         return st;
144     }
145 }