Skip to content

Commit 58cc75f

Browse files
committed
---
yaml --- r: 4015 b: refs/heads/master c: 4121279 h: refs/heads/master i: 4013: 2709b1a 4011: 9381676 4007: 4510fdc 3999: 63cf1dc v: v3
1 parent 8f7706b commit 58cc75f

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1a2a8b6b1746241c8781b89c5974d6fcb0148774
2+
refs/heads/master: 41212792c605ee4dcc50031cb187b39f9f0f56fc

trunk/src/comp/metadata/tydecode.rs

+37
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,23 @@ fn parse_constrs(@pstate st, str_def sd) -> (@ty::constr)[] {
8282
ret rslt;
8383
}
8484

85+
// FIXME less copy-and-paste
86+
fn parse_ty_constrs(@pstate st, str_def sd) -> (@ty::type_constr)[] {
87+
let (@ty::type_constr)[] rslt = ~[];
88+
alt (peek(st) as char) {
89+
case (':') {
90+
do {
91+
next(st);
92+
let @ty::type_constr one = parse_constr[path](st, sd,
93+
parse_ty_constr_arg);
94+
rslt += ~[one];
95+
} while (peek(st) as char == ';')
96+
}
97+
case (_) { }
98+
}
99+
ret rslt;
100+
}
101+
85102
fn parse_path(@pstate st, str_def sd) -> ast::path {
86103
let ast::ident[] idents = ~[];
87104
fn is_last(char c) -> bool {
@@ -136,6 +153,19 @@ fn parse_constr_arg(@pstate st, str_def sd) -> ast::fn_constr_arg {
136153
}
137154
}
138155

156+
fn parse_ty_constr_arg(@pstate st, str_def sd)
157+
-> ast::constr_arg_general_[path] {
158+
alt (peek(st) as char) {
159+
case ('*') {
160+
st.pos += 1u;
161+
ret ast::carg_base;
162+
}
163+
case (?c) {
164+
ret ast::carg_ident(parse_path(st, sd));
165+
}
166+
}
167+
}
168+
139169
fn parse_constr[T](@pstate st, str_def sd, arg_parser[T] pser)
140170
-> @ty::constr_general[T] {
141171
auto sp = rec(lo=0u,hi=0u); // FIXME: use a real span
@@ -294,6 +324,13 @@ fn parse_ty(@pstate st, str_def sd) -> ty::t {
294324
}
295325
}
296326
}
327+
case ('A') {
328+
assert (next(st) as char == '[');
329+
auto tt = parse_ty(st, sd);
330+
auto tcs = parse_ty_constrs(st, sd);
331+
assert (next(st) as char == ']');
332+
ret ty::mk_constr(st.tcx, tt, tcs);
333+
}
297334
case (?c) {
298335
log_err "unexpected char in type string: ";
299336
log_err c;

trunk/src/comp/metadata/tyencode.rs

+28
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ fn enc_sty(&ioivec::writer w, &@ctxt cx, &ty::sty st) {
191191
}
192192
case (ty::ty_type) { w.write_char('Y'); }
193193
case (ty::ty_task) { w.write_char('a'); }
194+
case (ty::ty_constr(?ty, ?cs)) {
195+
w.write_str("A[");
196+
enc_ty(w, cx, ty);
197+
for (@ty::type_constr tc in cs) {
198+
enc_ty_constr(w, cx, tc);
199+
}
200+
w.write_char(']');
201+
}
194202
}
195203
}
196204
fn enc_proto(&ioivec::writer w, proto proto) {
@@ -229,6 +237,7 @@ fn enc_ty_fn(&ioivec::writer w, &@ctxt cx, &ty::arg[] args, &ty::t out,
229237

230238
}
231239

240+
// FIXME less copy-and-paste
232241
fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr c) {
233242
w.write_str(path_to_str(c.node.path));
234243
w.write_char('(');
@@ -248,6 +257,25 @@ fn enc_constr(&ioivec::writer w, &@ctxt cx, &@ty::constr c) {
248257
w.write_char(')');
249258
}
250259

260+
fn enc_ty_constr(&ioivec::writer w, &@ctxt cx, &@ty::type_constr c) {
261+
w.write_str(path_to_str(c.node.path));
262+
w.write_char('(');
263+
w.write_str(cx.ds(c.node.id));
264+
w.write_char('|');
265+
auto semi = false;
266+
for (@ty::ty_constr_arg a in c.node.args) {
267+
if (semi) { w.write_char(';'); } else { semi = true; }
268+
alt (a.node) {
269+
case (carg_base) { w.write_char('*'); }
270+
case (carg_ident(?p)) {
271+
w.write_str(path_to_str(p));
272+
}
273+
case (carg_lit(?l)) { w.write_str(lit_to_str(l)); }
274+
}
275+
}
276+
w.write_char(')');
277+
}
278+
251279

252280
//
253281
// Local Variables:

trunk/src/comp/middle/ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export ty_box;
122122
export ty_chan;
123123
export ty_char;
124124
export ty_constr;
125+
export ty_constr_arg;
125126
export ty_float;
126127
export ty_fn;
127128
export ty_fn_abi;

0 commit comments

Comments
 (0)