More code to implement tags
[IRC.git] / Robust / src / IR / Flat / FlatFlagActionNode.java
1 package IR.Flat;
2 import IR.FlagDescriptor;
3 import IR.TagDescriptor;
4 import java.util.Hashtable;
5 import java.util.HashSet;
6 import java.util.Iterator;
7
8 public class FlatFlagActionNode extends FlatNode {
9     Hashtable tempflagpairs; 
10     Hashtable temptagpairs; 
11
12     int taskexit;
13     public static final int NEWOBJECT=0;
14     public static final int PRE=1;
15     public static final int TASKEXIT=2;
16
17
18     public FlatFlagActionNode(int taskexit) {
19         tempflagpairs=new Hashtable();
20         temptagpairs=new Hashtable();
21         this.taskexit=taskexit;
22     }
23
24     public int getTaskType() {
25         return taskexit;
26     }
27
28     public void addFlagAction(TempDescriptor td, FlagDescriptor fd, boolean status) {
29         TempFlagPair tfp=new TempFlagPair(td,fd);
30         if (tempflagpairs.containsKey(tfp)) {
31             throw new Error("Temp/Flag combination used twice: "+tfp);
32         }
33         tempflagpairs.put(tfp, new Boolean(status));
34     }
35
36     public void addTagAction(TempDescriptor td, TagDescriptor tagd, TempDescriptor tagt, boolean status) {
37         TempTagPair ttp=new TempTagPair(td,tagd, tagt);
38         if (temptagpairs.containsKey(ttp)) {
39             throw new Error("Temp/Tag combination used twice: "+ttp);
40         }
41         temptagpairs.put(ttp, new Boolean(status));
42     }
43
44     public int kind() {
45         return FKind.FlatFlagActionNode;
46     }
47     
48     /** This method returns an iterator over the Temp/Flag pairs. */
49     
50     public Iterator getTempFlagPairs() {
51         return tempflagpairs.keySet().iterator();
52     }
53
54     public Iterator getTempTagPairs() {
55         return temptagpairs.keySet().iterator();
56     }
57
58     public boolean getFlagChange(TempFlagPair tfp) {
59         return ((Boolean)tempflagpairs.get(tfp)).booleanValue();
60     }
61
62     public boolean getTagChange(TempTagPair ttp) {
63         return ((Boolean)temptagpairs.get(ttp)).booleanValue();
64     }
65
66     public TempDescriptor [] readsTemps() {
67         if (tempflagpairs.size()==0)
68             return new TempDescriptor [0];
69         else {
70             HashSet temps=new HashSet();
71             for(Iterator it=tempflagpairs.keySet().iterator();it.hasNext();) {
72                 TempFlagPair tfp=(TempFlagPair)it.next();
73                 temps.add(tfp.getTemp());
74             }
75             for(Iterator it=temptagpairs.keySet().iterator();it.hasNext();) {
76                 TempTagPair ttp=(TempTagPair)it.next();
77                 temps.add(ttp.getTemp());
78             }
79             return (TempDescriptor[]) temps.toArray(new TempDescriptor [temps.size()]);
80         }
81     }
82
83     public String toString() {
84         return "FlatFlagActionNode";
85     }
86 }