Committing changes to leftsize->rightSize, more comments, and handling
[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
12     public StandardCodeWriter(java.io.PrintWriter output) { this.output = output; }
13
14     public void startblock() {
15         indent();
16         outputline("{");
17     }
18
19     public void endblock() {
20         outputline("}");
21         unindent();
22     }
23     
24     public void indent() { 
25         indent++; 
26     }
27     
28     public void unindent() { 
29         indent--; 
30     }
31     
32     private void doindent() {
33         for (int i = 0; i < indent; i++) { 
34             output.print("  ");
35         }
36         linestarted = true;
37     }
38     
39     public void outputline(String s) {
40         if (!linestarted) {
41             doindent();
42         }
43         output.println(s);
44         linestarted = false;
45         output.flush();
46     }                 
47     
48     public void output(String s) {
49         if (!linestarted) {
50             doindent();
51         }
52         output.print(s);
53         output.flush(); 
54     }
55
56     public void pushSymbolTable(SymbolTable st) {
57         symboltables.push(st);
58     }
59
60     public SymbolTable popSymbolTable() {
61         return (SymbolTable) symboltables.pop();
62     }
63
64     public SymbolTable getSymbolTable() { 
65         if (symboltables.empty()) {
66             throw new IRException(); 
67         }
68         return (SymbolTable) symboltables.peek();
69     }
70     
71 }