a40ed70d3b675d649db6dff2b39baa82d6000fbd
[IRC.git] / Robust / src / IR / State.java
1 package IR;
2 import IR.Tree.*;
3 import IR.Flat.*;
4 import IR.*;
5 import java.util.*;
6
7 public class State {
8     public State() {
9         this.classes=new SymbolTable();
10         this.tasks=new SymbolTable();
11         this.treemethodmap=new Hashtable();
12         this.flatmethodmap=new Hashtable();
13         this.parsetrees=new HashSet();
14         this.arraytypes=new HashSet();
15         this.arraytonumber=new Hashtable();
16     }
17
18     public void addParseNode(ParseNode parsetree) {
19         parsetrees.add(parsetree);
20     }
21
22     /** Boolean flag which indicates whether compiler is compiling a task-based
23      * program. */
24     public boolean TASK;
25     public String structfile;
26     public String main;
27     public boolean CONSCHECK=false;
28
29     public SymbolTable classes;
30     public SymbolTable tasks;
31     public Set parsetrees;
32     public Hashtable treemethodmap;
33     public Hashtable flatmethodmap;
34     private HashSet arraytypes;
35     public Hashtable arraytonumber;
36     private int numclasses=0;
37     private int numtasks=0;
38     private int arraycount=0;
39
40     public void addArrayType(TypeDescriptor td) {
41         if (!arraytypes.contains(td)) {
42             arraytypes.add(td);
43             arraytonumber.put(td,new Integer(arraycount++));
44         }
45     }
46
47     public Iterator getArrayIterator() {
48         return arraytypes.iterator();
49     }
50
51     public int getArrayNumber(TypeDescriptor td) {
52         return ((Integer)arraytonumber.get(td)).intValue();
53     }
54
55     public int numArrays() {
56         return arraytypes.size();
57     }
58
59     public static TypeDescriptor getTypeDescriptor(int t) {
60         TypeDescriptor td=new TypeDescriptor(t);
61         return td;
62     }
63
64     public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
65         TypeDescriptor td=new TypeDescriptor(n);
66         return td;
67     }
68
69     public void addClass(ClassDescriptor tdn) {
70         if (classes.contains(tdn.getSymbol()))
71             throw new Error("Class "+tdn.getSymbol()+" defined twice");
72         classes.add(tdn);
73         numclasses++;
74     }
75
76     public int numClasses() {
77         return numclasses;
78     }
79
80     public BlockNode getMethodBody(MethodDescriptor md) {
81         return (BlockNode)treemethodmap.get(md);
82     }
83
84     public BlockNode getMethodBody(TaskDescriptor td) {
85         return (BlockNode)treemethodmap.get(td);
86     }
87
88     public SymbolTable getClassSymbolTable() {
89         return classes;
90     }
91
92     public SymbolTable getTaskSymbolTable() {
93         return tasks;
94     }
95
96     /** Returns Flat IR representation of MethodDescriptor md. */
97
98     public FlatMethod getMethodFlat(MethodDescriptor md) {
99         return (FlatMethod)flatmethodmap.get(md);
100     }
101
102     /** Returns Flat IR representation of TaskDescriptor td. */
103
104     public FlatMethod getMethodFlat(TaskDescriptor td) {
105         return (FlatMethod)flatmethodmap.get(td);
106     }
107
108     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
109         treemethodmap.put(md,bn);
110     }
111
112     public void addTreeCode(TaskDescriptor td, BlockNode bn) {
113         treemethodmap.put(td,bn);
114     }
115
116     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
117         flatmethodmap.put(md,bn);
118     }
119
120     public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
121         flatmethodmap.put(td,bn);
122     }
123
124     public void addTask(TaskDescriptor td) {
125         if (tasks.contains(td.getSymbol()))
126             throw new Error("Task "+td.getSymbol()+" defined twice");
127         tasks.add(td);
128         numtasks++;
129     }
130 }