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