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