Repository navigation
Expand file tree
/
Copy pathtypes.rs
More file actions
265 lines (236 loc) · 4.97 KB
/
Copy pathtypes.rs
File metadata and controls
265 lines (236 loc) · 4.97 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#[deriving(Clone)]
pub enum Global {
GType(@mut TypeInfo),
GComp(@mut CompInfo),
GCompDecl(@mut CompInfo),
GEnum(@mut EnumInfo),
GEnumDecl(@mut EnumInfo),
GVar(@mut VarInfo),
GFunc(@mut VarInfo),
GOther
}
impl Global {
pub fn compinfo(&self) -> @mut CompInfo {
match *self {
GComp(i) => return i,
GCompDecl(i) => return i,
_ => fail!(~"global_compinfo")
}
}
pub fn enuminfo(&self) -> @mut EnumInfo {
match *self {
GEnum(i) => return i,
GEnumDecl(i) => return i,
_ => fail!(~"global_enuminfo")
}
}
pub fn typeinfo(&self) -> @mut TypeInfo {
match *self {
GType(i) => return i,
_ => fail!(~"global_typeinfo")
}
}
pub fn varinfo(&self) -> @mut VarInfo {
match *self {
GVar(i) => i,
GFunc(i) => i,
_ => fail!(~"global_varinfo")
}
}
}
impl ToStr for Global {
fn to_str(&self) -> ~str {
match *self {
GType(ti) => ti.to_str(),
GComp(ci) => ci.to_str(),
GCompDecl(ci) => ci.to_str(),
GEnum(ei) => ei.to_str(),
GEnumDecl(ei) => ei.to_str(),
GVar(vi) => vi.to_str(),
GFunc(vi) => vi.to_str(),
GOther => ~"*"
}
}
}
#[deriving(Clone, Eq)]
pub enum Type {
TVoid,
TInt(IKind, Layout),
TFloat(FKind, Layout),
TPtr(~Type, bool, Layout),
TArray(~Type, uint, Layout),
TFunc(~Type, ~[(~str, Type)], bool),
TNamed(@mut TypeInfo),
TComp(@mut CompInfo),
TEnum(@mut EnumInfo)
}
impl Type {
pub fn size(&self) -> uint {
match *self {
TInt(_, l) => l.size,
TFloat(_, l) => l.size,
TPtr(_, _, l) => l.size,
TArray(_, _, l) => l.size,
TNamed(ref t) => t.ty.size(),
TComp(ref ci) => ci.layout.size,
TEnum(ref ei) => ei.layout.size,
TVoid => 0,
TFunc(..) => 0,
}
}
pub fn align(&self) -> uint {
match *self {
TInt(_, l) => l.align,
TFloat(_, l) => l.align,
TPtr(_, _, l) => l.align,
TArray(_, _, l) => l.align,
TNamed(ref t) => t.ty.align(),
TComp(ref ci) => ci.layout.align,
TEnum(ref ei) => ei.layout.align,
TVoid => 0,
TFunc(..) => 0,
}
}
}
#[deriving(Clone, Eq)]
pub struct Layout {
size: uint,
align: uint,
}
impl Layout {
pub fn new(size: uint, align: uint) -> Layout {
Layout { size: size, align: align }
}
pub fn zero() -> Layout {
Layout { size: 0, align: 0 }
}
}
#[deriving(Clone, Eq)]
pub enum IKind {
IBool,
ISChar,
IUChar,
IShort,
IUShort,
IInt,
IUInt,
ILong,
IULong,
ILongLong,
IULongLong
}
#[deriving(Clone, Eq)]
pub enum FKind {
FFloat,
FDouble
}
#[deriving(Clone, Eq)]
pub struct CompInfo {
cstruct: bool,
name: ~str,
fields: ~[FieldInfo],
layout: Layout,
}
impl CompInfo {
pub fn new(name: ~str, cstruct: bool, fields: ~[FieldInfo], layout: Layout) -> CompInfo {
CompInfo {
cstruct: cstruct,
name: name,
fields: fields,
layout: layout,
}
}
}
impl ToStr for CompInfo {
fn to_str(&self) -> ~str {
self.name.clone()
}
}
#[deriving(Clone, Eq)]
pub struct FieldInfo {
name: ~str,
ty: Type,
bit: Option<uint>,
}
impl FieldInfo {
pub fn new(name: ~str, ty: Type, bit: Option<uint>) -> FieldInfo {
FieldInfo {
name: name,
ty: ty,
bit: bit,
}
}
}
#[deriving(Clone, Eq)]
pub struct EnumInfo {
name: ~str,
items: ~[EnumItem],
kind: IKind,
layout: Layout,
}
impl EnumInfo {
pub fn new(name: ~str, kind: IKind, items: ~[EnumItem], layout: Layout) -> EnumInfo {
EnumInfo {
name: name,
items: items,
kind: kind,
layout: layout,
}
}
}
impl ToStr for EnumInfo {
fn to_str(&self) -> ~str {
self.name.clone()
}
}
#[deriving(Clone, Eq)]
pub struct EnumItem {
name: ~str,
val: int
}
impl EnumItem {
pub fn new(name: ~str, val: int) -> EnumItem {
EnumItem {
name: name,
val: val
}
}
}
#[deriving(Clone, Eq)]
pub struct TypeInfo {
name: ~str,
ty: Type
}
impl TypeInfo {
pub fn new(name: ~str, ty: Type) -> TypeInfo {
TypeInfo {
name: name,
ty: ty
}
}
}
impl ToStr for TypeInfo {
fn to_str(&self) -> ~str {
self.name.clone()
}
}
#[deriving(Clone)]
pub struct VarInfo {
name: ~str,
ty: Type,
is_const: bool
}
impl VarInfo {
pub fn new(name: ~str, ty: Type) -> VarInfo {
VarInfo {
name: name,
ty: ty,
is_const: false
}
}
}
impl ToStr for VarInfo {
fn to_str(&self) -> ~str {
self.name.clone()
}
}