Checked in code to:
[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 SymbolTable getClassSymbolTable() {
80         return classes;
81     }
82
83     public SymbolTable getTaskSymbolTable() {
84         return tasks;
85     }
86
87     public FlatMethod getMethodFlat(MethodDescriptor md) {
88         return (FlatMethod)flatmethodmap.get(md);
89     }
90
91     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
92         treemethodmap.put(md,bn);
93     }
94
95     public void addTreeCode(TaskDescriptor td, BlockNode bn) {
96         treemethodmap.put(td,bn);
97     }
98
99     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
100         flatmethodmap.put(md,bn);
101     }
102
103     public void addTask(TaskDescriptor td) {
104         if (tasks.contains(td.getSymbol()))
105             throw new Error("Task "+td.getSymbol()+" defined twice");
106         tasks.add(td);
107         numtasks++;
108     }
109 }