Skip to content

Commit 17dcaee

Browse files
committed
libsyntax: De-mut the pipe compiler
1 parent 1a132b3 commit 17dcaee

File tree

5 files changed

+39
-37
lines changed

5 files changed

+39
-37
lines changed

src/libsyntax/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn mk_handler(emitter: Option<Emitter>) -> @handler {
158158
}
159159
};
160160

161-
@mut HandlerT { mut err_count: 0, emit: emit } as @handler
161+
@mut HandlerT { err_count: 0, emit: emit } as @handler
162162
}
163163

164164
#[deriving_eq]

src/libsyntax/ext/pipes/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn expand_proto(cx: ext_ctxt, _sp: span, id: ast::ident,
7373
let rdr = tt_rdr as reader;
7474
let rust_parser = Parser(sess, cfg, rdr.dup());
7575

76-
let proto = rust_parser.parse_proto(cx.str_of(id));
76+
let mut proto = rust_parser.parse_proto(cx.str_of(id));
7777

7878
// check for errors
7979
visit(proto, cx);

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use core::to_str::ToStr;
2727
use core::vec;
2828

2929
pub trait gen_send {
30-
fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item;
31-
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty;
30+
fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item;
31+
fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty;
3232
}
3333

3434
pub trait to_type_decls {
@@ -47,7 +47,7 @@ pub trait gen_init {
4747
}
4848

4949
pub impl gen_send for message {
50-
fn gen_send(&self, cx: ext_ctxt, try: bool) -> @ast::item {
50+
fn gen_send(&mut self, cx: ext_ctxt, try: bool) -> @ast::item {
5151
debug!("pipec: gen_send");
5252
match *self {
5353
message(ref _id, span, ref tys, this, Some(ref next_state)) => {
@@ -193,7 +193,7 @@ pub impl gen_send for message {
193193
}
194194
}
195195
196-
fn to_ty(&self, cx: ext_ctxt) -> @ast::Ty {
196+
fn to_ty(&mut self, cx: ext_ctxt) -> @ast::Ty {
197197
cx.ty_path_ast_builder(path(~[cx.ident_of(self.name())], self.span())
198198
.add_tys(cx.ty_vars_global(self.get_params())))
199199
}
@@ -259,10 +259,14 @@ pub impl to_type_decls for state {
259259
recv => (*self).dir.reverse()
260260
};
261261
let mut items = ~[];
262-
for self.messages.each |m| {
263-
if dir == send {
264-
items.push(m.gen_send(cx, true));
265-
items.push(m.gen_send(cx, false));
262+
263+
{
264+
let messages = &mut *self.messages;
265+
for vec::each_mut(*messages) |m| {
266+
if dir == send {
267+
items.push(m.gen_send(cx, true));
268+
items.push(m.gen_send(cx, false));
269+
}
266270
}
267271
}
268272
@@ -395,7 +399,8 @@ pub impl gen_init for protocol {
395399
}
396400
397401
cx.ty_path_ast_builder(path(~[cx.ident_of(~"super"),
398-
cx.ident_of(~"__Buffer")], self.span)
402+
cx.ident_of(~"__Buffer")],
403+
copy self.span)
399404
.add_tys(cx.ty_vars_global(params)))
400405
}
401406
@@ -453,12 +458,12 @@ pub impl gen_init for protocol {
453458
}
454459
455460
items.push(cx.item_mod(cx.ident_of(~"client"),
456-
self.span,
461+
copy self.span,
457462
client_states));
458463
items.push(cx.item_mod(cx.ident_of(~"server"),
459-
self.span,
464+
copy self.span,
460465
server_states));
461466

462-
cx.item_mod(cx.ident_of(self.name), self.span, items)
467+
cx.item_mod(cx.ident_of(self.name), copy self.span, items)
463468
}
464469
}

src/libsyntax/ext/pipes/proto.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use ext::base::ext_ctxt;
1616
use ext::pipes::ast_builder::{append_types, ext_ctxt_ast_builder, path};
1717

1818
use core::cmp;
19-
use core::dvec::DVec;
2019
use core::to_str::ToStr;
2120

2221
#[deriving_eq]
@@ -45,26 +44,24 @@ pub struct next_state {
4544
tys: ~[@ast::Ty],
4645
}
4746

48-
pub enum message {
49-
// name, span, data, current state, next state
50-
message(~str, span, ~[@ast::Ty], state, Option<next_state>)
51-
}
47+
// name, span, data, current state, next state
48+
pub struct message(~str, span, ~[@ast::Ty], state, Option<next_state>);
5249

5350
pub impl message {
54-
fn name(&self) -> ~str {
51+
fn name(&mut self) -> ~str {
5552
match *self {
5653
message(ref id, _, _, _, _) => (*id)
5754
}
5855
}
5956

60-
fn span(&self) -> span {
57+
fn span(&mut self) -> span {
6158
match *self {
6259
message(_, span, _, _, _) => span
6360
}
6461
}
6562

6663
/// Return the type parameters actually used by this message
67-
fn get_params(&self) -> ~[ast::ty_param] {
64+
fn get_params(&mut self) -> ~[ast::ty_param] {
6865
match *self {
6966
message(_, _, _, this, _) => this.ty_params
7067
}
@@ -80,7 +77,7 @@ pub struct state_ {
8077
span: span,
8178
dir: direction,
8279
ty_params: ~[ast::ty_param],
83-
messages: DVec<message>,
80+
messages: @mut ~[message],
8481
proto: protocol
8582
}
8683

@@ -121,56 +118,56 @@ pub impl state_ {
121118
}
122119
}
123120

124-
pub type protocol = @protocol_;
121+
pub type protocol = @mut protocol_;
125122

126123
pub fn protocol(name: ~str, +span: span) -> protocol {
127-
@protocol_(name, span)
124+
@mut protocol_(name, span)
128125
}
129126

130127
pub fn protocol_(name: ~str, span: span) -> protocol_ {
131128
protocol_ {
132129
name: name,
133130
span: span,
134-
states: DVec(),
131+
states: @mut ~[],
135132
bounded: None
136133
}
137134
}
138135

139136
pub struct protocol_ {
140137
name: ~str,
141138
span: span,
142-
states: DVec<state>,
139+
states: @mut ~[state],
143140

144-
mut bounded: Option<bool>,
141+
bounded: Option<bool>,
145142
}
146143

147144
pub impl protocol_ {
148145
/// Get a state.
149-
fn get_state(&self, name: ~str) -> state {
146+
fn get_state(&mut self, name: ~str) -> state {
150147
self.states.find(|i| i.name == name).get()
151148
}
152149

153-
fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
150+
fn get_state_by_id(&mut self, id: uint) -> state { self.states[id] }
154151

155-
fn has_state(&self, name: ~str) -> bool {
152+
fn has_state(&mut self, name: ~str) -> bool {
156153
self.states.find(|i| i.name == name).is_some()
157154
}
158155

159-
fn filename(&self) -> ~str {
156+
fn filename(&mut self) -> ~str {
160157
~"proto://" + self.name
161158
}
162159

163-
fn num_states(&self) -> uint { self.states.len() }
160+
fn num_states(&mut self) -> uint { self.states.len() }
164161

165-
fn has_ty_params(&self) -> bool {
162+
fn has_ty_params(&mut self) -> bool {
166163
for self.states.each |s| {
167164
if s.ty_params.len() > 0 {
168165
return true;
169166
}
170167
}
171168
false
172169
}
173-
fn is_bounded(&self) -> bool {
170+
fn is_bounded(&mut self) -> bool {
174171
let bounded = self.bounded.get();
175172
bounded
176173
}
@@ -179,7 +176,7 @@ pub impl protocol_ {
179176
pub impl protocol {
180177
fn add_state_poly(&self, name: ~str, ident: ast::ident, dir: direction,
181178
+ty_params: ~[ast::ty_param]) -> state {
182-
let messages = DVec();
179+
let messages = @mut ~[];
183180

184181
let state = @state_ {
185182
id: self.states.len(),

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn new_tt_reader(sp_diag: span_handler,
5959
let r = @mut TtReader {
6060
sp_diag: sp_diag,
6161
interner: itr,
62-
mut cur: @mut TtFrame {
62+
cur: @mut TtFrame {
6363
readme: @mut src,
6464
idx: 0u,
6565
dotdotdoted: false,

0 commit comments

Comments
 (0)