Skip to content

libsyntax: Cleanup pipes syntax extension. #4996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 86 additions & 79 deletions src/libsyntax/ext/pipes/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,61 +67,68 @@ pub impl append_types for @ast::path {
}

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 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 item_struct_poly(&self, name: ident, span: span,
struct_def: ast::struct_def,
ty_params: ~[ast::ty_param]) -> @ast::item;
fn item_struct(&self, name: ident, span: span,
struct_def: ast::struct_def) -> @ast::item;
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 ty_rec(+v: ~[ast::ty_field]) -> @ast::Ty;
fn field_imm(name: ident, e: @ast::expr) -> ast::field;
fn rec(+v: ~[ast::field]) -> @ast::expr;
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"),
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(),
Expand All @@ -130,33 +137,24 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}

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 rec(+fields: ~[ast::field]) -> @ast::expr {
@expr {
id: self.next_id(),
callee_id: self.next_id(),
node: ast::expr_rec(fields, None),
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,
Expand All @@ -166,29 +164,21 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}

fn ty_rec(+fields: ~[ast::ty_field]) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_rec(fields),
span: dummy_sp(),
}
}

fn ty_infer() -> @ast::Ty {
fn ty_infer(&self) -> @ast::Ty {
@ast::Ty {
id: self.next_id(),
node: ast::ty_infer,
span: dummy_sp(),
}
}

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,
Expand All @@ -205,7 +195,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}

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,
Expand All @@ -217,11 +207,11 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
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,
Expand All @@ -230,8 +220,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
}
}

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
Expand All @@ -254,7 +243,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
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],
Expand All @@ -267,27 +256,46 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
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 variant(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(&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(&self, path: @ast::path,
fields: ~[ast::field]) -> @ast::expr {
@ast::expr {
id: self.next_id(),
callee_id: self.next_id(),
node: ast::expr_struct(path, fields, None),
span: dummy_sp()
}
}

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() }
Expand All @@ -300,14 +308,15 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
kind: ast::tuple_variant_kind(args),
id: self.next_id(),
disr_expr: None,
vis: ast::public},
vis: ast::public
},
span: span,
}
}

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(~[
Expand Down Expand Up @@ -345,45 +354,43 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
)
}

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()),
span: path.span,
}
}

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,
span: dummy_sp(),
}
}

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())))
}
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/pipes/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ use ext::pipes::proto::{state, protocol, next_state};
use ext::pipes::proto;

pub impl proto::visitor<(), (), ()> for ext_ctxt {
fn visit_proto(_proto: protocol,
fn visit_proto(&self, _proto: protocol,
_states: &[()]) { }

fn visit_state(state: state, _m: &[()]) {
fn visit_state(&self, state: state, _m: &[()]) {
if state.messages.len() == 0 {
self.span_warn(
state.span, // use a real span!
Expand All @@ -51,7 +51,7 @@ pub impl proto::visitor<(), (), ()> for ext_ctxt {
}
}

fn visit_message(name: ~str, _span: span, _tys: &[@ast::Ty],
fn visit_message(&self, name: ~str, _span: span, _tys: &[@ast::Ty],
this: state, next: Option<next_state>) {
match next {
Some(next_state { state: ref next, tys: next_tys }) => {
Expand Down
12 changes: 6 additions & 6 deletions src/libsyntax/ext/pipes/parse_proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ use parse::token;
use core::prelude::*;

pub trait proto_parser {
fn parse_proto(id: ~str) -> protocol;
fn parse_state(proto: protocol);
fn parse_message(state: state);
fn parse_proto(&self, id: ~str) -> protocol;
fn parse_state(&self, proto: protocol);
fn parse_message(&self, state: state);
}

pub impl proto_parser for parser::Parser {
fn parse_proto(id: ~str) -> protocol {
fn parse_proto(&self, id: ~str) -> protocol {
let proto = protocol(id, self.span);

self.parse_seq_to_before_end(token::EOF,
Expand All @@ -33,7 +33,7 @@ pub impl proto_parser for parser::Parser {
return proto;
}

fn parse_state(proto: protocol) {
fn parse_state(&self, proto: protocol) {
let id = self.parse_ident();
let name = *self.interner.get(id);

Expand Down Expand Up @@ -63,7 +63,7 @@ pub impl proto_parser for parser::Parser {
|self| self.parse_message(state));
}

fn parse_message(state: state) {
fn parse_message(&self, state: state) {
let mname = *self.interner.get(self.parse_ident());

let args = if self.token == token::LPAREN {
Expand Down
Loading