}
pub trait ext_ctxt_ast_builder {
- fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
+ fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
-> ast::ty_param;
- fn arg(name: ident, ty: @ast::Ty) -> ast::arg;
- fn expr_block(e: @ast::expr) -> ast::blk;
- fn fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
- fn item(name: ident, span: span, +node: ast::item_) -> @ast::item;
- fn item_fn_poly(name: ident,
+ fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg;
+ fn expr_block(&self, e: @ast::expr) -> ast::blk;
+ fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
+ fn item(&self, name: ident, span: span, +node: ast::item_) -> @ast::item;
+ fn item_fn_poly(&self, name: ident,
+inputs: ~[ast::arg],
output: @ast::Ty,
+ty_params: ~[ast::ty_param],
+body: ast::blk) -> @ast::item;
- fn item_fn(name: ident,
+ fn item_fn(&self, name: ident,
+inputs: ~[ast::arg],
output: @ast::Ty,
+body: ast::blk) -> @ast::item;
- fn item_enum_poly(name: ident,
+ fn item_enum_poly(&self, name: ident,
span: span,
+enum_definition: ast::enum_def,
+ty_params: ~[ast::ty_param]) -> @ast::item;
- fn item_enum(name: ident, span: span,
+ fn item_enum(&self, name: ident, span: span,
+enum_definition: ast::enum_def) -> @ast::item;
- fn item_struct_poly(name: ident, span: span,
+ fn item_struct_poly(&self, name: ident, span: span,
struct_def: ast::struct_def,
ty_params: ~[ast::ty_param]) -> @ast::item;
- fn item_struct(name: ident, span: span,
+ fn item_struct(&self, name: ident, span: span,
struct_def: ast::struct_def) -> @ast::item;
- fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
- fn variant(name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
- fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
- fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty;
- fn item_ty_poly(name: ident,
+ fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
+ fn variant(&self, name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
+ fn item_mod(&self, name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
+ fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
+ fn item_ty_poly(&self, name: ident,
span: span,
ty: @ast::Ty,
+params: ~[ast::ty_param]) -> @ast::item;
- fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item;
- fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
- fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
- fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field;
- fn field_imm(name: ident, e: @ast::expr) -> ast::field;
- fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
- fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
- fn stmt_expr(e: @ast::expr) -> @ast::stmt;
- fn block_expr(b: ast::blk) -> @ast::expr;
- fn ty_option(ty: @ast::Ty) -> @ast::Ty;
- fn ty_infer() -> @ast::Ty;
- fn ty_nil_ast_builder() -> @ast::Ty;
- fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param];
+ fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
+ fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
+ fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
+ fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field;
+ fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field;
+ fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
+ fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt;
+ fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt;
+ fn block_expr(&self, b: ast::blk) -> @ast::expr;
+ fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
+ fn ty_infer(&self) -> @ast::Ty;
+ fn ty_nil_ast_builder(&self) -> @ast::Ty;
+ fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param];
}
pub impl ext_ctxt_ast_builder for ext_ctxt {
- fn ty_option(ty: @ast::Ty) -> @ast::Ty {
+ fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
self.ty_path_ast_builder(path_global(~[
self.ident_of(~"core"),
self.ident_of(~"option"),
], dummy_sp()).add_ty(ty))
}
- fn block_expr(b: ast::blk) -> @ast::expr {
+ fn block_expr(&self, b: ast::blk) -> @ast::expr {
@expr {
id: self.next_id(),
callee_id: self.next_id(),
}
}
- fn stmt_expr(e: @ast::expr) -> @ast::stmt {
+ fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
@spanned { node: ast::stmt_expr(e, self.next_id()),
span: dummy_sp()}
}
- fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
- let ext_cx = self;
+ fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
+ let ext_cx = *self;
quote_stmt!( let $ident = $e; )
}
- fn field_imm(name: ident, e: @ast::expr) -> ast::field {
+ fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
spanned {
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
span: dummy_sp(),
}
}
- fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
+ fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
spanned {
node: ast::ty_field_ {
ident: name,
}
}
- fn ty_infer() -> @ast::Ty {
+ fn ty_infer(&self) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_infer,
}
}
- fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
+ fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
-> ast::ty_param
{
ast::ty_param { ident: id, id: self.next_id(), bounds: @bounds }
}
- fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
+ fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
ast::arg {
mode: ast::infer(self.next_id()),
is_mutbl: false,
}
}
- fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
+ fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
let blk = ast::blk_ {
view_items: ~[],
stmts: stmts,
spanned { node: blk, span: dummy_sp() }
}
- fn expr_block(e: @ast::expr) -> ast::blk {
+ fn expr_block(&self, e: @ast::expr) -> ast::blk {
self.block(~[], e)
}
- fn fn_decl(+inputs: ~[ast::arg],
+ fn fn_decl(&self, +inputs: ~[ast::arg],
output: @ast::Ty) -> ast::fn_decl {
ast::fn_decl {
inputs: inputs,
}
}
- fn item(name: ident,
- span: span,
+ fn item(&self, name: ident, span: span,
+node: ast::item_) -> @ast::item {
// XXX: Would be nice if our generated code didn't violate
span: span }
}
- fn item_fn_poly(name: ident,
+ fn item_fn_poly(&self, name: ident,
+inputs: ~[ast::arg],
output: @ast::Ty,
+ty_params: ~[ast::ty_param],
body))
}
- fn item_fn(name: ident,
+ fn item_fn(&self, name: ident,
+inputs: ~[ast::arg],
output: @ast::Ty,
+body: ast::blk) -> @ast::item {
self.item_fn_poly(name, inputs, output, ~[], body)
}
- fn item_enum_poly(name: ident,
- span: span,
+ fn item_enum_poly(&self, name: ident, span: span,
+enum_definition: ast::enum_def,
+ty_params: ~[ast::ty_param]) -> @ast::item {
self.item(name, span, ast::item_enum(enum_definition, ty_params))
}
- fn item_enum(name: ident, span: span,
+ fn item_enum(&self, name: ident, span: span,
+enum_definition: ast::enum_def) -> @ast::item {
self.item_enum_poly(name, span, enum_definition, ~[])
}
- fn item_struct(name: ident, span: span,
+ fn item_struct(&self, name: ident, span: span,
struct_def: ast::struct_def) -> @ast::item {
self.item_struct_poly(name, span, struct_def, ~[])
}
- fn item_struct_poly(name: ident, span: span,
+ fn item_struct_poly(&self, name: ident, span: span,
struct_def: ast::struct_def,
ty_params: ~[ast::ty_param]) -> @ast::item {
self.item(name, span, ast::item_struct(@struct_def, ty_params))
}
- fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
+ fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
@ast::expr {
id: self.next_id(),
callee_id: self.next_id(),
}
}
- fn variant(name: ident,
- span: span,
+ fn variant(&self, name: ident, span: span,
+tys: ~[@ast::Ty]) -> ast::variant {
let args = do tys.map |ty| {
ast::variant_arg { ty: *ty, id: self.next_id() }
}
}
- fn item_mod(name: ident,
- span: span,
+ fn item_mod(&self, name: ident, span: span,
+items: ~[@ast::item]) -> @ast::item {
+
// XXX: Total hack: import `core::kinds::Owned` to work around a
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
let vi = ast::view_item_import(~[
)
}
- fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
+ fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_path(path, self.next_id()),
}
}
- fn ty_nil_ast_builder() -> @ast::Ty {
+ fn ty_nil_ast_builder(&self) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_nil,
}
}
- fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
+ fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
do bounds.map |ty_param| {
ast::ty_param { bounds: @~[], ..copy *ty_param }
}
}
- fn item_ty_poly(name: ident,
- span: span,
- ty: @ast::Ty,
+ fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
+params: ~[ast::ty_param]) -> @ast::item {
self.item(name, span, ast::item_ty(ty, params))
}
- fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item {
+ fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
self.item_ty_poly(name, span, ty, ~[])
}
- fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
+ fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
ty_params.map(|p| self.ty_path_ast_builder(
path(~[p.ident], dummy_sp())))
}
- fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
+ fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
ty_params.map(|p| self.ty_path_ast_builder(
path(~[p.ident], dummy_sp())))
}
use core::vec;
pub trait gen_send {
- fn gen_send(cx: ext_ctxt, try: bool) -> @ast::item;
- fn to_ty(cx: ext_ctxt) -> @ast::Ty;
+ fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item;
+ fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty;
}
pub trait to_type_decls {
- fn to_type_decls(cx: ext_ctxt) -> ~[@ast::item];
- fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item];
+ fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item];
+ fn to_endpoint_decls(&self, cx: ext_ctxt, dir: direction) -> ~[@ast::item];
}
pub trait gen_init {
- fn gen_init(cx: ext_ctxt) -> @ast::item;
- fn compile(cx: ext_ctxt) -> @ast::item;
- fn buffer_ty_path(cx: ext_ctxt) -> @ast::Ty;
- fn gen_buffer_type(cx: ext_ctxt) -> @ast::item;
- fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr;
- fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr;
+ fn gen_init(&self, cx: ext_ctxt) -> @ast::item;
+ fn compile(&self, cx: ext_ctxt) -> @ast::item;
+ fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty;
+ fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item;
+ fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr;
+ fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr;
}
pub impl gen_send for message {
- fn gen_send(cx: ext_ctxt, try: bool) -> @ast::item {
+ fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item {
debug!("pipec: gen_send");
- match self {
+ match *self {
message(ref _id, span, tys, this,
Some(next_state {state: ref next, tys: next_tys})) => {
debug!("pipec: next state exists");
}
}
- fn to_ty(cx: ext_ctxt) -> @ast::Ty {
+ fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty {
cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span())
.add_tys(cx.ty_vars_global(self.get_params())))
}
}
pub impl to_type_decls for state {
- fn to_type_decls(cx: ext_ctxt) -> ~[@ast::item] {
+ fn to_type_decls(&self, cx: ext_ctxt) -> ~[@ast::item] {
debug!("pipec: to_type_decls");
// This compiles into two different type declarations. Say the
// state is called ping. This will generate both `ping` and
]
}
- fn to_endpoint_decls(cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
+ fn to_endpoint_decls(&self, cx: ext_ctxt, dir: direction) -> ~[@ast::item] {
debug!("pipec: to_endpoint_decls");
let dir = match dir {
send => (*self).dir,
}
pub impl gen_init for protocol {
- fn gen_init(cx: ext_ctxt) -> @ast::item {
+ fn gen_init(&self, cx: ext_ctxt) -> @ast::item {
let ext_cx = cx;
debug!("gen_init");
body.to_source(cx)))
}
- fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
+ fn gen_buffer_init(&self, ext_cx: ext_ctxt) -> @ast::expr {
ext_cx.struct_expr(path(~[ext_cx.ident_of(~"__Buffer")],
dummy_sp()),
self.states.map_to_vec(|s| {
}))
}
- fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr {
+ fn gen_init_bounded(&self, ext_cx: ext_ctxt) -> @ast::expr {
debug!("gen_init_bounded");
let buffer_fields = self.gen_buffer_init(ext_cx);
let buffer = quote_expr!(~::pipes::Buffer {
})
}
- fn buffer_ty_path(cx: ext_ctxt) -> @ast::Ty {
+ fn buffer_ty_path(&self, cx: ext_ctxt) -> @ast::Ty {
let mut params: ~[ast::ty_param] = ~[];
for (copy self.states).each |s| {
for s.ty_params.each |tp| {
.add_tys(cx.ty_vars_global(params)))
}
- fn gen_buffer_type(cx: ext_ctxt) -> @ast::item {
+ fn gen_buffer_type(&self, cx: ext_ctxt) -> @ast::item {
let ext_cx = cx;
let mut params: ~[ast::ty_param] = ~[];
let fields = do (copy self.states).map_to_vec |s| {
cx.strip_bounds(params))
}
- fn compile(cx: ext_ctxt) -> @ast::item {
+ fn compile(&self, cx: ext_ctxt) -> @ast::item {
let mut items = ~[self.gen_init(cx)];
let mut client_states = ~[];
let mut server_states = ~[];
}
pub impl direction {
- fn reverse() -> direction {
- match self {
+ fn reverse(&self) -> direction {
+ match *self {
send => recv,
recv => send
}
}
pub impl message {
- fn name() -> ~str {
- match self {
+ fn name(&self) -> ~str {
+ match *self {
message(ref id, _, _, _, _) => (*id)
}
}
- fn span() -> span {
- match self {
+ fn span(&self) -> span {
+ match *self {
message(_, span, _, _, _) => span
}
}
/// Return the type parameters actually used by this message
- fn get_params() -> ~[ast::ty_param] {
- match self {
+ fn get_params(&self) -> ~[ast::ty_param] {
+ match *self {
message(_, _, _, this, _) => this.ty_params
}
}
pub impl protocol_ {
/// Get a state.
- fn get_state(name: ~str) -> state {
+ fn get_state(&self, name: ~str) -> state {
self.states.find(|i| i.name == name).get()
}
- fn get_state_by_id(id: uint) -> state { self.states[id] }
+ fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
- fn has_state(name: ~str) -> bool {
+ fn has_state(&self, name: ~str) -> bool {
self.states.find(|i| i.name == name).is_some()
}
- fn filename() -> ~str {
+ fn filename(&self) -> ~str {
~"proto://" + self.name
}
- fn num_states() -> uint { self.states.len() }
+ fn num_states(&self) -> uint { self.states.len() }
- fn has_ty_params() -> bool {
+ fn has_ty_params(&self) -> bool {
for self.states.each |s| {
if s.ty_params.len() > 0 {
return true;
}
false
}
- fn is_bounded() -> bool {
+ fn is_bounded(&self) -> bool {
let bounded = self.bounded.get();
bounded
- //if bounded && self.has_ty_params() {
- // debug!("protocol %s has is bounded, but type parameters\
- // are not yet supported.",
- // *self.name);
- // false
- //}
- //else { bounded }
}
}
pub impl protocol {
- fn add_state_poly(name: ~str, ident: ast::ident, dir: direction,
+ fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction,
+ty_params: ~[ast::ty_param]) -> state {
let messages = DVec();
dir: dir,
ty_params: ty_params,
messages: messages,
- proto: self
+ proto: *self
};
self.states.push(state);
}
pub trait visitor<Tproto, Tstate, Tmessage> {
- fn visit_proto(proto: protocol, st: &[Tstate]) -> Tproto;
- fn visit_state(state: state, m: &[Tmessage]) -> Tstate;
- fn visit_message(name: ~str, spane: span, tys: &[@ast::Ty],
+ fn visit_proto(&self, proto: protocol, st: &[Tstate]) -> Tproto;
+ fn visit_state(&self, state: state, m: &[Tmessage]) -> Tstate;
+ fn visit_message(&self, name: ~str, spane: span, tys: &[@ast::Ty],
this: state, next: Option<next_state>) -> Tmessage;
}