c893c20ee70e0ceb9c1579297fe01a869074a4f0
[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     public SymbolTable classes;
25     public SymbolTable tasks;
26     public Set parsetrees;
27     public Hashtable treemethodmap;
28     public Hashtable flatmethodmap;
29     private HashSet arraytypes;
30     public Hashtable arraytonumber;
31     private int numclasses=0;
32     private int numtasks=0;
33     private int arraycount=0;
34
35     public void addArrayType(TypeDescriptor td) {
36         if (!arraytypes.contains(td)) {
37             arraytypes.add(td);
38             arraytonumber.put(td,new Integer(arraycount++));
39         }
40     }
41
42     public Iterator getArrayIterator() {
43         return arraytypes.iterator();
44     }
45
46     public int getArrayNumber(TypeDescriptor td) {
47         return ((Integer)arraytonumber.get(td)).intValue();
48     }
49
50     public int numArrays() {
51         return arraytypes.size();
52     }
53
54     public static TypeDescriptor getTypeDescriptor(int t) {
55         TypeDescriptor td=new TypeDescriptor(t);
56         return td;
57     }
58
59     public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
60         TypeDescriptor td=new TypeDescriptor(n);
61         return td;
62     }
63
64     public void addClass(ClassDescriptor tdn) {
65         if (classes.contains(tdn.getSymbol()))
66             throw new Error("Class "+tdn.getSymbol()+" defined twice");
67         classes.add(tdn);
68         numclasses++;
69     }
70
71     public int numClasses() {
72         return numclasses;
73     }
74
75     public BlockNode getMethodBody(MethodDescriptor md) {
76         return (BlockNode)treemethodmap.get(md);
77     }
78
79     public BlockNode getMethodBody(TaskDescriptor td) {
80         return (BlockNode)treemethodmap.get(td);
81     }
82
83     public SymbolTable getClassSymbolTable() {
84         return classes;
85     }
86
87     public SymbolTable getTaskSymbolTable() {
88         return tasks;
89     }
90
91     public FlatMethod getMethodFlat(MethodDescriptor md) {
92         return (FlatMethod)flatmethodmap.get(md);
93     }
94
95     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
96         treemethodmap.put(md,bn);
97     }
98
99     public void addTreeCode(TaskDescriptor td, BlockNode bn) {
100         treemethodmap.put(td,bn);
101     }
102
103     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
104         flatmethodmap.put(md,bn);
105     }
106
107     public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
108         flatmethodmap.put(td,bn);
109     }
110
111     public void addTask(TaskDescriptor td) {
112         if (tasks.contains(td.getSymbol()))
113             throw new Error("Task "+td.getSymbol()+" defined twice");
114         tasks.add(td);
115         numtasks++;
116     }
117 }