Skip to content

Commit b97fe98

Browse files
committed
Generate buffer type for bounded protocols
1 parent c28af26 commit b97fe98

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,22 @@ trait ext_ctxt_ast_builder {
9191
+params: ~[ast::ty_param]) -> @ast::item;
9292
fn item_ty(name: ident, ty: @ast::ty) -> @ast::item;
9393
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::ty];
94+
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field;
95+
fn ty_rec(+~[ast::ty_field]) -> @ast::ty;
9496
}
9597

9698
impl ast_builder of ext_ctxt_ast_builder for ext_ctxt {
99+
fn ty_field_imm(name: ident, ty: @ast::ty) -> ast::ty_field {
100+
{node: {ident: name, mt: { ty: ty, mutbl: ast::m_imm } },
101+
span: empty_span()}
102+
}
103+
104+
fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::ty {
105+
@{id: self.next_id(),
106+
node: ast::ty_rec(fields),
107+
span: empty_span()}
108+
}
109+
97110
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
98111
-> ast::ty_param
99112
{

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ impl compile of to_type_decls for state {
204204

205205
impl compile of gen_init for protocol {
206206
fn gen_init(cx: ext_ctxt) -> @ast::item {
207+
#debug("gen_init");
207208
let start_state = self.states[0];
208209

209210
let body = alt start_state.dir {
@@ -237,6 +238,23 @@ impl compile of gen_init for protocol {
237238
server_states += s.to_endpoint_decls(cx, recv);
238239
}
239240

241+
if self.is_bounded() {
242+
vec::push(
243+
items,
244+
cx.item_ty(
245+
@~"buffer",
246+
cx.ty_rec(
247+
(copy self.states).map_to_vec(
248+
|s| cx.ty_field_imm(
249+
s.name,
250+
cx.ty_path_ast_builder(
251+
(path(@~"pipes")
252+
+ @~"packet")
253+
.add_ty(
254+
cx.ty_path_ast_builder(
255+
path(s.name)))))))))
256+
}
257+
240258
vec::push(items,
241259
cx.item_mod(@~"client",
242260
client_states));

0 commit comments

Comments
 (0)