blob: b0ad39bd1212eeaa805478595c1595f4b30d5dfd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
/* ___ ____ ___ __ ___ ___
** / _// __// _ | / / / _ | / _ \ Scala classfile decoder
** __\ \/ /__/ __ |/ /__/ __ |/ ___/ (c) 2003-2006, LAMP/EPFL
** /____/\___/_/ |_/____/_/ |_/_/
**
*/
// $Id: CodeWriter.scala 5837 2006-02-23 17:37:25 +0000 (Thu, 23 Feb 2006) michelou $
package scala.tools.scalap
import java.io._
class CodeWriter(writer: Writer) {
private val nl = System.getProperty("line.separator")
private var step = " "
private var level = 0
private var align = false
private var space = false
private var line = false
def getWriter = writer
def getIndentLevel = level
def setIndentLevel(level: Int): CodeWriter = {
this.level = level
this
}
def getIndentWidth = if (step == null) -1 else step.length()
def setIndentWidth(width: Int): CodeWriter = {
val buffer = new StringBuffer(width)
var i = 0
while (i < width)
buffer.append(' ')
setIndentString(buffer.toString())
}
def getIndentString = step;
def setIndentString(step: String): CodeWriter = {
this.step = step
this
}
def indent: CodeWriter = {
level = level + 1
this
}
def undent: CodeWriter = {
level = level - 1
this
}
def newline: CodeWriter = {
if (step == null)
newspace
else if (!line) {
try {
writer.write(nl)
} catch {
case e => error("IO error")
}
line = align
align = true
space = false
this
} else
this
}
def newspace: CodeWriter = {
space = !align
this
}
def * : Unit = {}
def println: CodeWriter = newline
def println(value: Boolean): CodeWriter = print(value).newline
def println(value: Byte): CodeWriter = print(value).newline
def println(value: Short): CodeWriter = print(value).newline
def println(value: Char): CodeWriter = print(value).newline
def println(value: Int): CodeWriter = print(value).newline
def println(value: Long): CodeWriter = print(value).newline
def println(value: Float): CodeWriter = print(value).newline
def println(value: Double): CodeWriter = print(value).newline
def println(value: String): CodeWriter = print(value).newline
def print(value: Boolean): CodeWriter = print(String.valueOf(value))
def print(value: Byte): CodeWriter = print(String.valueOf(value))
def print(value: Short): CodeWriter = print(String.valueOf(value))
def print(value: Char): CodeWriter = print(String.valueOf(value))
def print(value: Int): CodeWriter = print(String.valueOf(value))
def print(value: Long): CodeWriter = print(String.valueOf(value))
def print(value: Float): CodeWriter = print(String.valueOf(value))
def print(value: Double): CodeWriter = print(String.valueOf(value))
def print(value: String): CodeWriter = try {
if (align) {
var i = 0
while (i < level) {
writer.write(step)
i = i + 1
}
}
if (space)
writer.write(" ")
writer.write(value)
align = false
space = false
line = false
this
} catch {
case e => error("IO error")
}
override def toString(): String = writer.toString()
}
|