adding support for consistency checking
[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
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     /** Returns Flat IR representation of MethodDescriptor md. */
96
97     public FlatMethod getMethodFlat(MethodDescriptor md) {
98         return (FlatMethod)flatmethodmap.get(md);
99     }
100
101     /** Returns Flat IR representation of TaskDescriptor td. */
102
103     public FlatMethod getMethodFlat(TaskDescriptor td) {
104         return (FlatMethod)flatmethodmap.get(td);
105     }
106
107     public void addTreeCode(MethodDescriptor md, BlockNode bn) {
108         treemethodmap.put(md,bn);
109     }
110
111     public void addTreeCode(TaskDescriptor td, BlockNode bn) {
112         treemethodmap.put(td,bn);
113     }
114
115     public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
116         flatmethodmap.put(md,bn);
117     }
118
119     public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
120         flatmethodmap.put(td,bn);
121     }
122
123     public void addTask(TaskDescriptor td) {
124         if (tasks.contains(td.getSymbol()))
125             throw new Error("Task "+td.getSymbol()+" defined twice");
126         tasks.add(td);
127         numtasks++;
128     }
129 }