Skip to content

Commit de57bac

Browse files
committed
libsyntax: Explicit-self-ify pipes compiler.
1 parent 0126af3 commit de57bac

File tree

5 files changed

+110
-122
lines changed

5 files changed

+110
-122
lines changed

src/libsyntax/ext/pipes/ast_builder.rs

Lines changed: 60 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -67,65 +67,65 @@ pub impl append_types for @ast::path {
6767
}
6868

6969
pub trait ext_ctxt_ast_builder {
70-
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
70+
fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
7171
-> ast::ty_param;
72-
fn arg(name: ident, ty: @ast::Ty) -> ast::arg;
73-
fn expr_block(e: @ast::expr) -> ast::blk;
74-
fn fn_decl(+inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
75-
fn item(name: ident, span: span, +node: ast::item_) -> @ast::item;
76-
fn item_fn_poly(name: ident,
72+
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg;
73+
fn expr_block(&self, e: @ast::expr) -> ast::blk;
74+
fn fn_decl(&self, +inputs: ~[ast::arg], output: @ast::Ty) -> ast::fn_decl;
75+
fn item(&self, name: ident, span: span, +node: ast::item_) -> @ast::item;
76+
fn item_fn_poly(&self, name: ident,
7777
+inputs: ~[ast::arg],
7878
output: @ast::Ty,
7979
+ty_params: ~[ast::ty_param],
8080
+body: ast::blk) -> @ast::item;
81-
fn item_fn(name: ident,
81+
fn item_fn(&self, name: ident,
8282
+inputs: ~[ast::arg],
8383
output: @ast::Ty,
8484
+body: ast::blk) -> @ast::item;
85-
fn item_enum_poly(name: ident,
85+
fn item_enum_poly(&self, name: ident,
8686
span: span,
8787
+enum_definition: ast::enum_def,
8888
+ty_params: ~[ast::ty_param]) -> @ast::item;
89-
fn item_enum(name: ident, span: span,
89+
fn item_enum(&self, name: ident, span: span,
9090
+enum_definition: ast::enum_def) -> @ast::item;
91-
fn item_struct_poly(name: ident, span: span,
91+
fn item_struct_poly(&self, name: ident, span: span,
9292
struct_def: ast::struct_def,
9393
ty_params: ~[ast::ty_param]) -> @ast::item;
94-
fn item_struct(name: ident, span: span,
94+
fn item_struct(&self, name: ident, span: span,
9595
struct_def: ast::struct_def) -> @ast::item;
96-
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
97-
fn variant(name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
98-
fn item_mod(name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
99-
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty;
100-
fn item_ty_poly(name: ident,
96+
fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr;
97+
fn variant(&self, name: ident, span: span, +tys: ~[@ast::Ty]) -> ast::variant;
98+
fn item_mod(&self, name: ident, span: span, +items: ~[@ast::item]) -> @ast::item;
99+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty;
100+
fn item_ty_poly(&self, name: ident,
101101
span: span,
102102
ty: @ast::Ty,
103103
+params: ~[ast::ty_param]) -> @ast::item;
104-
fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item;
105-
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
106-
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
107-
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field;
108-
fn field_imm(name: ident, e: @ast::expr) -> ast::field;
109-
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
110-
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt;
111-
fn stmt_expr(e: @ast::expr) -> @ast::stmt;
112-
fn block_expr(b: ast::blk) -> @ast::expr;
113-
fn ty_option(ty: @ast::Ty) -> @ast::Ty;
114-
fn ty_infer() -> @ast::Ty;
115-
fn ty_nil_ast_builder() -> @ast::Ty;
116-
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param];
104+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item;
105+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
106+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty];
107+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field;
108+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field;
109+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk;
110+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt;
111+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt;
112+
fn block_expr(&self, b: ast::blk) -> @ast::expr;
113+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty;
114+
fn ty_infer(&self) -> @ast::Ty;
115+
fn ty_nil_ast_builder(&self) -> @ast::Ty;
116+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param];
117117
}
118118

119119
pub impl ext_ctxt_ast_builder for ext_ctxt {
120-
fn ty_option(ty: @ast::Ty) -> @ast::Ty {
120+
fn ty_option(&self, ty: @ast::Ty) -> @ast::Ty {
121121
self.ty_path_ast_builder(path_global(~[
122122
self.ident_of(~"core"),
123123
self.ident_of(~"option"),
124124
self.ident_of(~"Option")
125125
], dummy_sp()).add_ty(ty))
126126
}
127127

128-
fn block_expr(b: ast::blk) -> @ast::expr {
128+
fn block_expr(&self, b: ast::blk) -> @ast::expr {
129129
@expr {
130130
id: self.next_id(),
131131
callee_id: self.next_id(),
@@ -134,24 +134,24 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
134134
}
135135
}
136136

137-
fn stmt_expr(e: @ast::expr) -> @ast::stmt {
137+
fn stmt_expr(&self, e: @ast::expr) -> @ast::stmt {
138138
@spanned { node: ast::stmt_expr(e, self.next_id()),
139139
span: dummy_sp()}
140140
}
141141

142-
fn stmt_let(ident: ident, e: @ast::expr) -> @ast::stmt {
143-
let ext_cx = self;
142+
fn stmt_let(&self, ident: ident, e: @ast::expr) -> @ast::stmt {
143+
let ext_cx = *self;
144144
quote_stmt!( let $ident = $e; )
145145
}
146146

147-
fn field_imm(name: ident, e: @ast::expr) -> ast::field {
147+
fn field_imm(&self, name: ident, e: @ast::expr) -> ast::field {
148148
spanned {
149149
node: ast::field_ { mutbl: ast::m_imm, ident: name, expr: e },
150150
span: dummy_sp(),
151151
}
152152
}
153153

154-
fn ty_field_imm(name: ident, ty: @ast::Ty) -> ast::ty_field {
154+
fn ty_field_imm(&self, name: ident, ty: @ast::Ty) -> ast::ty_field {
155155
spanned {
156156
node: ast::ty_field_ {
157157
ident: name,
@@ -161,21 +161,21 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
161161
}
162162
}
163163

164-
fn ty_infer() -> @ast::Ty {
164+
fn ty_infer(&self) -> @ast::Ty {
165165
@ast::Ty {
166166
id: self.next_id(),
167167
node: ast::ty_infer,
168168
span: dummy_sp(),
169169
}
170170
}
171171

172-
fn ty_param(id: ast::ident, +bounds: ~[ast::ty_param_bound])
172+
fn ty_param(&self, id: ast::ident, +bounds: ~[ast::ty_param_bound])
173173
-> ast::ty_param
174174
{
175175
ast::ty_param { ident: id, id: self.next_id(), bounds: @bounds }
176176
}
177177

178-
fn arg(name: ident, ty: @ast::Ty) -> ast::arg {
178+
fn arg(&self, name: ident, ty: @ast::Ty) -> ast::arg {
179179
ast::arg {
180180
mode: ast::infer(self.next_id()),
181181
is_mutbl: false,
@@ -192,7 +192,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
192192
}
193193
}
194194

195-
fn block(+stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
195+
fn block(&self, +stmts: ~[@ast::stmt], e: @ast::expr) -> ast::blk {
196196
let blk = ast::blk_ {
197197
view_items: ~[],
198198
stmts: stmts,
@@ -204,11 +204,11 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
204204
spanned { node: blk, span: dummy_sp() }
205205
}
206206

207-
fn expr_block(e: @ast::expr) -> ast::blk {
207+
fn expr_block(&self, e: @ast::expr) -> ast::blk {
208208
self.block(~[], e)
209209
}
210210

211-
fn fn_decl(+inputs: ~[ast::arg],
211+
fn fn_decl(&self, +inputs: ~[ast::arg],
212212
output: @ast::Ty) -> ast::fn_decl {
213213
ast::fn_decl {
214214
inputs: inputs,
@@ -217,8 +217,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
217217
}
218218
}
219219

220-
fn item(name: ident,
221-
span: span,
220+
fn item(&self, name: ident, span: span,
222221
+node: ast::item_) -> @ast::item {
223222

224223
// XXX: Would be nice if our generated code didn't violate
@@ -241,7 +240,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
241240
span: span }
242241
}
243242

244-
fn item_fn_poly(name: ident,
243+
fn item_fn_poly(&self, name: ident,
245244
+inputs: ~[ast::arg],
246245
output: @ast::Ty,
247246
+ty_params: ~[ast::ty_param],
@@ -254,37 +253,36 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
254253
body))
255254
}
256255

257-
fn item_fn(name: ident,
256+
fn item_fn(&self, name: ident,
258257
+inputs: ~[ast::arg],
259258
output: @ast::Ty,
260259
+body: ast::blk) -> @ast::item {
261260
self.item_fn_poly(name, inputs, output, ~[], body)
262261
}
263262

264-
fn item_enum_poly(name: ident,
265-
span: span,
263+
fn item_enum_poly(&self, name: ident, span: span,
266264
+enum_definition: ast::enum_def,
267265
+ty_params: ~[ast::ty_param]) -> @ast::item {
268266
self.item(name, span, ast::item_enum(enum_definition, ty_params))
269267
}
270268

271-
fn item_enum(name: ident, span: span,
269+
fn item_enum(&self, name: ident, span: span,
272270
+enum_definition: ast::enum_def) -> @ast::item {
273271
self.item_enum_poly(name, span, enum_definition, ~[])
274272
}
275273

276-
fn item_struct(name: ident, span: span,
274+
fn item_struct(&self, name: ident, span: span,
277275
struct_def: ast::struct_def) -> @ast::item {
278276
self.item_struct_poly(name, span, struct_def, ~[])
279277
}
280278

281-
fn item_struct_poly(name: ident, span: span,
279+
fn item_struct_poly(&self, name: ident, span: span,
282280
struct_def: ast::struct_def,
283281
ty_params: ~[ast::ty_param]) -> @ast::item {
284282
self.item(name, span, ast::item_struct(@struct_def, ty_params))
285283
}
286284

287-
fn struct_expr(path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
285+
fn struct_expr(&self, path: @ast::path, fields: ~[ast::field]) -> @ast::expr {
288286
@ast::expr {
289287
id: self.next_id(),
290288
callee_id: self.next_id(),
@@ -293,8 +291,7 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
293291
}
294292
}
295293

296-
fn variant(name: ident,
297-
span: span,
294+
fn variant(&self, name: ident, span: span,
298295
+tys: ~[@ast::Ty]) -> ast::variant {
299296
let args = do tys.map |ty| {
300297
ast::variant_arg { ty: *ty, id: self.next_id() }
@@ -313,9 +310,9 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
313310
}
314311
}
315312

316-
fn item_mod(name: ident,
317-
span: span,
313+
fn item_mod(&self, name: ident, span: span,
318314
+items: ~[@ast::item]) -> @ast::item {
315+
319316
// XXX: Total hack: import `core::kinds::Owned` to work around a
320317
// parser bug whereby `fn f<T: ::kinds::Owned>` doesn't parse.
321318
let vi = ast::view_item_import(~[
@@ -353,45 +350,43 @@ pub impl ext_ctxt_ast_builder for ext_ctxt {
353350
)
354351
}
355352

356-
fn ty_path_ast_builder(path: @ast::path) -> @ast::Ty {
353+
fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty {
357354
@ast::Ty {
358355
id: self.next_id(),
359356
node: ast::ty_path(path, self.next_id()),
360357
span: path.span,
361358
}
362359
}
363360

364-
fn ty_nil_ast_builder() -> @ast::Ty {
361+
fn ty_nil_ast_builder(&self) -> @ast::Ty {
365362
@ast::Ty {
366363
id: self.next_id(),
367364
node: ast::ty_nil,
368365
span: dummy_sp(),
369366
}
370367
}
371368

372-
fn strip_bounds(bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
369+
fn strip_bounds(&self, bounds: &[ast::ty_param]) -> ~[ast::ty_param] {
373370
do bounds.map |ty_param| {
374371
ast::ty_param { bounds: @~[], ..copy *ty_param }
375372
}
376373
}
377374

378-
fn item_ty_poly(name: ident,
379-
span: span,
380-
ty: @ast::Ty,
375+
fn item_ty_poly(&self, name: ident, span: span, ty: @ast::Ty,
381376
+params: ~[ast::ty_param]) -> @ast::item {
382377
self.item(name, span, ast::item_ty(ty, params))
383378
}
384379

385-
fn item_ty(name: ident, span: span, ty: @ast::Ty) -> @ast::item {
380+
fn item_ty(&self, name: ident, span: span, ty: @ast::Ty) -> @ast::item {
386381
self.item_ty_poly(name, span, ty, ~[])
387382
}
388383

389-
fn ty_vars(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
384+
fn ty_vars(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
390385
ty_params.map(|p| self.ty_path_ast_builder(
391386
path(~[p.ident], dummy_sp())))
392387
}
393388

394-
fn ty_vars_global(+ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
389+
fn ty_vars_global(&self, +ty_params: ~[ast::ty_param]) -> ~[@ast::Ty] {
395390
ty_params.map(|p| self.ty_path_ast_builder(
396391
path(~[p.ident], dummy_sp())))
397392
}

src/libsyntax/ext/pipes/check.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ use ext::pipes::proto::{state, protocol, next_state};
3838
use ext::pipes::proto;
3939

4040
pub impl proto::visitor<(), (), ()> for ext_ctxt {
41-
fn visit_proto(_proto: protocol,
41+
fn visit_proto(&self, _proto: protocol,
4242
_states: &[()]) { }
4343

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

54-
fn visit_message(name: ~str, _span: span, _tys: &[@ast::Ty],
54+
fn visit_message(&self, name: ~str, _span: span, _tys: &[@ast::Ty],
5555
this: state, next: Option<next_state>) {
5656
match next {
5757
Some(next_state { state: ref next, tys: next_tys }) => {

src/libsyntax/ext/pipes/parse_proto.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ use parse::token;
1717
use core::prelude::*;
1818

1919
pub trait proto_parser {
20-
fn parse_proto(id: ~str) -> protocol;
21-
fn parse_state(proto: protocol);
22-
fn parse_message(state: state);
20+
fn parse_proto(&self, id: ~str) -> protocol;
21+
fn parse_state(&self, proto: protocol);
22+
fn parse_message(&self, state: state);
2323
}
2424

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

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

36-
fn parse_state(proto: protocol) {
36+
fn parse_state(&self, proto: protocol) {
3737
let id = self.parse_ident();
3838
let name = *self.interner.get(id);
3939

@@ -63,7 +63,7 @@ pub impl proto_parser for parser::Parser {
6363
|self| self.parse_message(state));
6464
}
6565

66-
fn parse_message(state: state) {
66+
fn parse_message(&self, state: state) {
6767
let mname = *self.interner.get(self.parse_ident());
6868

6969
let args = if self.token == token::LPAREN {

0 commit comments

Comments
 (0)