Skip to content

Commit 7f2c399

Browse files
ericktcatamorphism
authored andcommitted
Convert many libsyntax records into structs
Specifically: ast_map::ctx ast_util::id_range diagnostic::{handler_t,codemap_t} auto_encode::field ext::base::{macro_def,syntax_expander_tt,syntax_expander_tt_item} ext::pipes::proto::next_state
1 parent 28da4ec commit 7f2c399

File tree

12 files changed

+83
-53
lines changed

12 files changed

+83
-53
lines changed

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn reserve_id_range(sess: Session,
164164
let to_id_min = sess.parse_sess.next_id;
165165
let to_id_max = sess.parse_sess.next_id + cnt;
166166
sess.parse_sess.next_id = to_id_max;
167-
return {min: to_id_min, max: to_id_min};
167+
ast_util::id_range { min: to_id_min, max: to_id_min }
168168
}
169169

170170
impl extended_decode_ctxt {

src/libsyntax/ast_map.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,12 @@ enum ast_node {
108108
}
109109

110110
type map = std::map::HashMap<node_id, ast_node>;
111-
type ctx = {map: map, mut path: path,
112-
mut local_id: uint, diag: span_handler};
111+
struct ctx {
112+
map: map,
113+
mut path: path,
114+
mut local_id: uint,
115+
diag: span_handler,
116+
}
113117
type vt = visit::vt<ctx>;
114118

115119
fn extend(cx: ctx, +elt: ident) -> @path {
@@ -131,12 +135,14 @@ fn mk_ast_map_visitor() -> vt {
131135
}
132136

133137
fn map_crate(diag: span_handler, c: crate) -> map {
134-
let cx = {map: std::map::HashMap(),
135-
mut path: ~[],
136-
mut local_id: 0u,
137-
diag: diag};
138+
let cx = ctx {
139+
map: std::map::HashMap(),
140+
mut path: ~[],
141+
mut local_id: 0u,
142+
diag: diag,
143+
};
138144
visit::visit_crate(c, cx, mk_ast_map_visitor());
139-
return cx.map;
145+
cx.map
140146
}
141147

142148
// Used for items loaded from external crate that are being inlined into this
@@ -150,10 +156,12 @@ fn map_decoded_item(diag: span_handler,
150156
// alias analysis, which we will not be running on the inlined items, and
151157
// even if we did I think it only needs an ordering between local
152158
// variables that are simultaneously in scope).
153-
let cx = {map: map,
154-
mut path: /* FIXME (#2543) */ copy path,
155-
mut local_id: 0u,
156-
diag: diag};
159+
let cx = ctx {
160+
map: map,
161+
mut path: /* FIXME (#2543) */ copy path,
162+
mut local_id: 0u,
163+
diag: diag,
164+
};
157165
let v = mk_ast_map_visitor();
158166

159167
// methods get added to the AST map when their impl is visited. Since we

src/libsyntax/ast_util.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ fn dtor_dec() -> fn_decl {
455455

456456
#[auto_encode]
457457
#[auto_decode]
458-
type id_range = {min: node_id, max: node_id};
458+
struct id_range {
459+
min: node_id,
460+
max: node_id,
461+
}
459462

460463
fn empty(range: id_range) -> bool {
461464
range.min >= range.max
@@ -596,7 +599,7 @@ fn compute_id_range(visit_ids_fn: fn(fn@(node_id))) -> id_range {
596599
*min = int::min(*min, id);
597600
*max = int::max(*max, id + 1);
598601
}
599-
return {min:*min, max:*max};
602+
id_range { min: *min, max: *max }
600603
}
601604

602605
fn compute_id_range_for_inlined_item(item: inlined_item) -> id_range {

src/libsyntax/diagnostic.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ trait handler {
5757
fn emit(cmsp: Option<(@codemap::CodeMap, span)>, msg: &str, lvl: level);
5858
}
5959

60-
type handler_t = @{
60+
struct handler_t {
6161
mut err_count: uint,
62-
emit: emitter
63-
};
62+
emit: emitter,
63+
}
6464

65-
type codemap_t = @{
65+
struct codemap_t {
6666
handler: handler,
67-
cm: @codemap::CodeMap
68-
};
67+
cm: @codemap::CodeMap,
68+
}
6969

7070
impl codemap_t: span_handler {
7171
fn span_fatal(sp: span, msg: &str) -> ! {
@@ -138,7 +138,7 @@ fn ice_msg(msg: &str) -> ~str {
138138
}
139139

140140
fn mk_span_handler(handler: handler, cm: @codemap::CodeMap) -> span_handler {
141-
@{ handler: handler, cm: cm } as span_handler
141+
@codemap_t { handler: handler, cm: cm } as span_handler
142142
}
143143

144144
fn mk_handler(emitter: Option<emitter>) -> handler {
@@ -154,12 +154,7 @@ fn mk_handler(emitter: Option<emitter>) -> handler {
154154
}
155155
};
156156

157-
let x: handler_t = @{
158-
mut err_count: 0,
159-
emit: emit
160-
};
161-
162-
x as handler
157+
@handler_t { mut err_count: 0, emit: emit } as handler
163158
}
164159

165160
enum level {

src/libsyntax/ext/auto_encode.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ references other non-built-in types. A type definition like:
4646
4747
#[auto_encode]
4848
#[auto_decode]
49-
type spanned<T> = {node: T, span: span};
49+
struct spanned<T> {node: T, span: span}
5050
5151
would yield functions like:
5252
@@ -810,11 +810,15 @@ fn mk_struct_deser_impl(
810810
// Records and structs don't have the same fields types, but they share enough
811811
// that if we extract the right subfields out we can share the code
812812
// generator code.
813-
type field = { span: span, ident: ast::ident, mutbl: ast::mutability };
813+
struct field {
814+
span: span,
815+
ident: ast::ident,
816+
mutbl: ast::mutability,
817+
}
814818

815819
fn mk_rec_fields(fields: ~[ast::ty_field]) -> ~[field] {
816820
do fields.map |field| {
817-
{
821+
field {
818822
span: field.span,
819823
ident: field.node.ident,
820824
mutbl: field.node.mt.mutbl,
@@ -830,7 +834,7 @@ fn mk_struct_fields(fields: ~[@ast::struct_field]) -> ~[field] {
830834
unnamed fields",
831835
};
832836

833-
{
837+
field {
834838
span: field.span,
835839
ident: ident,
836840
mutbl: match mutbl {
@@ -886,7 +890,7 @@ fn mk_ser_fields(
886890
fn mk_deser_fields(
887891
cx: ext_ctxt,
888892
span: span,
889-
fields: ~[{ span: span, ident: ast::ident, mutbl: ast::mutability }]
893+
fields: ~[field]
890894
) -> ~[ast::field] {
891895
do fields.mapi |idx, field| {
892896
// ast for `|| std::serialize::decode(__d)`

src/libsyntax/ext/base.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,27 @@ use std::map::HashMap;
3232
// is now probably a redundant AST node, can be merged with
3333
// ast::mac_invoc_tt.
3434

35-
type macro_def = {name: ~str, ext: syntax_extension};
35+
struct macro_def {
36+
name: ~str,
37+
ext: syntax_extension,
38+
}
3639

3740
type item_decorator =
3841
fn@(ext_ctxt, span, ast::meta_item, ~[@ast::item]) -> ~[@ast::item];
3942

40-
type syntax_expander_tt = {expander: syntax_expander_tt_, span: Option<span>};
43+
struct syntax_expander_tt {
44+
expander: syntax_expander_tt_,
45+
span: Option<span>,
46+
}
47+
4148
type syntax_expander_tt_ = fn@(ext_ctxt, span, ~[ast::token_tree])
4249
-> mac_result;
4350

44-
type syntax_expander_tt_item
45-
= {expander: syntax_expander_tt_item_, span: Option<span>};
51+
struct syntax_expander_tt_item {
52+
expander: syntax_expander_tt_item_,
53+
span: Option<span>,
54+
}
55+
4656
type syntax_expander_tt_item_
4757
= fn@(ext_ctxt, span, ast::ident, ~[ast::token_tree]) -> mac_result;
4858

@@ -70,10 +80,10 @@ enum syntax_extension {
7080
// AST nodes into full ASTs
7181
fn syntax_expander_table() -> HashMap<~str, syntax_extension> {
7282
fn builtin_normal_tt(f: syntax_expander_tt_) -> syntax_extension {
73-
normal_tt({expander: f, span: None})
83+
normal_tt(syntax_expander_tt {expander: f, span: None})
7484
}
7585
fn builtin_item_tt(f: syntax_expander_tt_item_) -> syntax_extension {
76-
item_tt({expander: f, span: None})
86+
item_tt(syntax_expander_tt_item {expander: f, span: None})
7787
}
7888
let syntax_expanders = HashMap();
7989
syntax_expanders.insert(~"macro_rules",

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ fn expand_expr(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
4646
cx.span_fatal(pth.span,
4747
fmt!("macro undefined: '%s'", *extname))
4848
}
49-
Some(normal_tt({expander: exp, span: exp_sp})) => {
49+
Some(normal_tt(
50+
syntax_expander_tt { expander: exp, span: exp_sp }
51+
)) => {
5052
cx.bt_push(ExpandedFrom({call_site: s,
5153
callie: {name: *extname, span: exp_sp}}));
5254

@@ -231,7 +233,9 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
231233
None =>
232234
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)),
233235

234-
Some(normal_tt({expander: exp, span: exp_sp})) => {
236+
Some(normal_tt(
237+
syntax_expander_tt { expander: exp, span: exp_sp }
238+
)) => {
235239
cx.bt_push(ExpandedFrom(
236240
{call_site: sp, callie: {name: *extname, span: exp_sp}}));
237241
let expanded = match exp(cx, mac.span, tts) {

src/libsyntax/ext/pipes/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ impl ext_ctxt: proto::visitor<(), (), ()> {
5252
}
5353

5454
fn visit_message(name: ~str, _span: span, _tys: &[@ast::Ty],
55-
this: state, next: next_state) {
55+
this: state, next: Option<next_state>) {
5656
match next {
57-
Some({state: ref next, tys: next_tys}) => {
57+
Some(next_state { state: ref next, tys: next_tys }) => {
5858
let proto = this.proto;
5959
if !proto.has_state((*next)) {
6060
// This should be a span fatal, but then we need to

src/libsyntax/ext/pipes/parse_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl parser::Parser: proto_parser {
8888
|p| p.parse_ty(false))
8989
}
9090
else { ~[] };
91-
Some({state: name, tys: ntys})
91+
Some(next_state {state: name, tys: ntys})
9292
}
9393
token::NOT => {
9494
// -> !

src/libsyntax/ext/pipes/pipec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl message: gen_send {
4949
debug!("pipec: gen_send");
5050
match self {
5151
message(ref _id, span, tys, this,
52-
Some({state: ref next, tys: next_tys})) => {
52+
Some(next_state {state: ref next, tys: next_tys})) => {
5353
debug!("pipec: next state exists");
5454
let next = this.proto.get_state((*next));
5555
assert next_tys.len() == next.ty_params.len();
@@ -217,7 +217,7 @@ impl state: to_type_decls {
217217
let message(name, span, tys, this, next) = *m;
218218
219219
let tys = match next {
220-
Some({state: ref next, tys: next_tys}) => {
220+
Some(next_state { state: ref next, tys: next_tys }) => {
221221
let next = this.proto.get_state((*next));
222222
let next_name = cx.str_of(next.data_name());
223223

src/libsyntax/ext/pipes/proto.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,14 @@ impl direction {
5151
}
5252
}
5353

54-
type next_state = Option<{state: ~str, tys: ~[@ast::Ty]}>;
54+
struct next_state {
55+
state: ~str,
56+
tys: ~[@ast::Ty],
57+
}
5558

5659
enum message {
5760
// name, span, data, current state, next state
58-
message(~str, span, ~[@ast::Ty], state, next_state)
61+
message(~str, span, ~[@ast::Ty], state, Option<next_state>)
5962
}
6063

6164
impl message {
@@ -94,7 +97,7 @@ enum state {
9497

9598
impl state {
9699
fn add_message(name: ~str, span: span,
97-
+data: ~[@ast::Ty], next: next_state) {
100+
+data: ~[@ast::Ty], next: Option<next_state>) {
98101
self.messages.push(message(name, span, data, self,
99102
next));
100103
}
@@ -119,7 +122,7 @@ impl state {
119122
fn reachable(f: fn(state) -> bool) {
120123
for self.messages.each |m| {
121124
match *m {
122-
message(_, _, _, _, Some({state: ref id, _})) => {
125+
message(_, _, _, _, Some(next_state { state: ref id, _ })) => {
123126
let state = self.proto.get_state((*id));
124127
if !f(state) { break }
125128
}
@@ -217,7 +220,7 @@ trait visitor<Tproto, Tstate, Tmessage> {
217220
fn visit_proto(proto: protocol, st: &[Tstate]) -> Tproto;
218221
fn visit_state(state: state, m: &[Tmessage]) -> Tstate;
219222
fn visit_message(name: ~str, spane: span, tys: &[@ast::Ty],
220-
this: state, next: next_state) -> Tmessage;
223+
this: state, next: Option<next_state>) -> Tmessage;
221224
}
222225

223226
fn visit<Tproto, Tstate, Tmessage, V: visitor<Tproto, Tstate, Tmessage>>(

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,11 @@ fn add_new_extension(cx: ext_ctxt, sp: span, name: ident,
139139
let exp: @fn(ext_ctxt, span, ~[ast::token_tree]) -> mac_result =
140140
|cx, sp, arg| generic_extension(cx, sp, name, arg, lhses, rhses);
141141

142-
return mr_def({
142+
mr_def(base::macro_def {
143143
name: *cx.parse_sess().interner.get(name),
144-
ext: normal_tt({expander: exp, span: Some(sp)})
145-
});
144+
ext: normal_tt(base::syntax_expander_tt {
145+
expander: exp,
146+
span: Some(sp),
147+
})
148+
})
146149
}

0 commit comments

Comments
 (0)