Fixed some analysis problems...
[repair.git] / Repair / RepairCompiler / MCC / IR / StandardCodeWriter.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class StandardCodeWriter implements CodeWriter { 
6
7     boolean linestarted = false;
8     int indent = 0;
9     java.io.PrintWriter output;
10     Stack symboltables = new Stack();
11     InvariantValue ivalue;
12
13     public StandardCodeWriter(java.io.PrintWriter output) { this.output = output; }
14
15     public void startblock() {
16         indent();
17         outputline("{");
18     }
19
20     public void endblock() {
21         outputline("}");
22         unindent();
23     }
24     
25     public void indent() { 
26         indent++; 
27     }
28     
29     public void unindent() { 
30         indent--; 
31     }
32     
33     private void doindent() {
34         for (int i = 0; i < indent; i++) { 
35             output.print("  ");
36         }
37         linestarted = true;
38     }
39     
40     public void outputline(String s) {
41         if (!linestarted) {
42             doindent();
43         }
44         output.println(s);
45         linestarted = false;
46         output.flush();
47     }                 
48     
49     public void output(String s) {
50         if (!linestarted) {
51             doindent();
52         }
53         output.print(s);
54         output.flush(); 
55     }
56
57     public void pushSymbolTable(SymbolTable st) {
58         symboltables.push(st);
59     }
60
61     public SymbolTable popSymbolTable() {
62         return (SymbolTable) symboltables.pop();
63     }
64
65     public SymbolTable getSymbolTable() { 
66         if (symboltables.empty()) {
67             throw new IRException(); 
68         }
69         return (SymbolTable) symboltables.peek();
70     }
71
72     public InvariantValue getInvariantValue() {
73         return ivalue;
74     }
75
76     public void setInvariantValue(InvariantValue iv) {
77         ivalue=iv;
78     }
79 }