Skip to content

Commit 0490c36

Browse files
committed
Unify some data structures in syntax::ast that were doing the same thing
As a preparation to removing some duplication in typeck.
1 parent 3b61064 commit 0490c36

22 files changed

+327
-397
lines changed

src/comp/front/test.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod {
5151
// we want to be main.
5252
fn nomain(&&item: @ast::item) -> option::t<@ast::item> {
5353
alt item.node {
54-
ast::item_fn(f, _) {
54+
ast::item_fn(_, _, _) {
5555
if item.ident == "main" {
5656
option::none
5757
} else { option::some(item) }
@@ -83,7 +83,7 @@ fn fold_item(cx: test_ctxt, &&i: @ast::item, fld: fold::ast_fold) ->
8383

8484
if is_test_fn(i) {
8585
alt i.node {
86-
ast::item_fn(f, _) when f.decl.purity == ast::unsafe_fn {
86+
ast::item_fn(decl, _, _) when decl.purity == ast::unsafe_fn {
8787
cx.sess.span_fatal(
8888
i.span,
8989
"unsafe functions cannot be used for tests");
@@ -110,9 +110,9 @@ fn is_test_fn(i: @ast::item) -> bool {
110110

111111
fn has_test_signature(i: @ast::item) -> bool {
112112
alt i.node {
113-
ast::item_fn(f, tps) {
114-
let input_cnt = vec::len(f.decl.inputs);
115-
let no_output = f.decl.output.node == ast::ty_nil;
113+
ast::item_fn(decl, tps, _) {
114+
let input_cnt = vec::len(decl.inputs);
115+
let no_output = decl.output.node == ast::ty_nil;
116116
let tparm_cnt = vec::len(tps);
117117
input_cnt == 0u && no_output && tparm_cnt == 0u
118118
}
@@ -190,13 +190,12 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
190190
let ret_ty = mk_test_desc_vec_ty(cx);
191191

192192
let decl: ast::fn_decl =
193-
{inputs: [],
193+
{proto: ast::proto_bare,
194+
inputs: [],
194195
output: ret_ty,
195196
purity: ast::impure_fn,
196-
il: ast::il_normal,
197197
cf: ast::return_val,
198198
constraints: []};
199-
let proto = ast::proto_bare;
200199

201200
// The vector of test_descs for this crate
202201
let test_descs = mk_test_desc_vec(cx);
@@ -205,9 +204,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
205204
default_block([], option::some(test_descs), cx.sess.next_node_id());
206205
let body = nospan(body_);
207206

208-
let fn_ = {decl: decl, proto: proto, body: body};
209-
210-
let item_ = ast::item_fn(fn_, []);
207+
let item_ = ast::item_fn(decl, [], body);
211208
let item: ast::item =
212209
{ident: "tests",
213210
attrs: [],
@@ -325,10 +322,10 @@ fn mk_test_wrapper(cx: test_ctxt,
325322
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
326323

327324
let wrapper_decl: ast::fn_decl = {
325+
proto: ast::proto_bare,
328326
inputs: [],
329327
output: @nospan(ast::ty_nil),
330328
purity: ast::impure_fn,
331-
il: ast::il_normal,
332329
cf: ast::return_val,
333330
constraints: []
334331
};
@@ -341,20 +338,14 @@ fn mk_test_wrapper(cx: test_ctxt,
341338
rules: ast::default_blk
342339
});
343340

344-
let wrapper_fn: ast::_fn = {
345-
decl: wrapper_decl,
346-
proto: ast::proto_bare,
347-
body: wrapper_body
348-
};
349-
350341
let wrapper_capture: @ast::capture_clause = @{
351342
copies: [],
352343
moves: []
353344
};
354345

355346
let wrapper_expr: ast::expr = {
356347
id: cx.sess.next_node_id(),
357-
node: ast::expr_fn(wrapper_fn, wrapper_capture),
348+
node: ast::expr_fn(wrapper_decl, wrapper_body, wrapper_capture),
358349
span: span
359350
};
360351

@@ -375,13 +366,12 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
375366
let ret_ty = nospan(ast::ty_nil);
376367

377368
let decl: ast::fn_decl =
378-
{inputs: [args_arg],
369+
{proto: ast::proto_bare,
370+
inputs: [args_arg],
379371
output: @ret_ty,
380372
purity: ast::impure_fn,
381-
il: ast::il_normal,
382373
cf: ast::return_val,
383374
constraints: []};
384-
let proto = ast::proto_bare;
385375

386376
let test_main_call_expr = mk_test_main_call(cx);
387377

@@ -390,9 +380,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
390380
cx.sess.next_node_id());
391381
let body = {node: body_, span: dummy_sp()};
392382

393-
let fn_ = {decl: decl, proto: proto, body: body};
394-
395-
let item_ = ast::item_fn(fn_, []);
383+
let item_ = ast::item_fn(decl, [], body);
396384
let item: ast::item =
397385
{ident: "main",
398386
attrs: [],

src/comp/metadata/common.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ const tag_crate_deps: uint = 0x25u;
6262
// A single crate dependency
6363
const tag_crate_dep: uint = 0x26u;
6464

65-
const tag_items_data_item_inlineness: uint = 0x27u;
66-
6765
const tag_crate_hash: uint = 0x28u;
6866

6967
const tag_mod_impl: uint = 0x30u;

src/comp/metadata/encoder.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
7474
encode_def_id(ebml_w, local_def(it.id));
7575
ebml::end_tag(ebml_w);
7676
}
77-
item_fn(_, tps) {
77+
item_fn(_, tps, _) {
7878
add_to_index(ebml_w, path, index, it.ident);
7979
ebml::start_tag(ebml_w, tag_paths_data_item);
8080
encode_name(ebml_w, it.ident);
@@ -105,7 +105,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
105105
encode_def_id(ebml_w, local_def(it.id));
106106
ebml::end_tag(ebml_w);
107107
}
108-
item_res(_, _, tps, ctor_id) {
108+
item_res(_, tps, _, _, ctor_id) {
109109
add_to_index(ebml_w, path, index, it.ident);
110110
ebml::start_tag(ebml_w, tag_paths_data_item);
111111
encode_name(ebml_w, it.ident);
@@ -173,12 +173,6 @@ fn encode_family(ebml_w: ebml::writer, c: u8) {
173173
ebml::end_tag(ebml_w);
174174
}
175175

176-
fn encode_inlineness(ebml_w: ebml::writer, c: u8) {
177-
ebml::start_tag(ebml_w, tag_items_data_item_inlineness);
178-
ebml_w.writer.write([c]);
179-
ebml::end_tag(ebml_w);
180-
}
181-
182176
fn def_to_str(did: def_id) -> str { ret #fmt["%d:%d", did.crate, did.node]; }
183177

184178
fn encode_type_param_kinds(ebml_w: ebml::writer, tps: [ty_param]) {
@@ -282,20 +276,15 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
282276
encode_symbol(ecx, ebml_w, item.id);
283277
ebml::end_tag(ebml_w);
284278
}
285-
item_fn(fd, tps) {
279+
item_fn(decl, tps, _) {
286280
ebml::start_tag(ebml_w, tag_items_data_item);
287281
encode_def_id(ebml_w, local_def(item.id));
288282
encode_family(ebml_w,
289-
alt fd.decl.purity {
283+
alt decl.purity {
290284
unsafe_fn. { 'u' }
291285
pure_fn. { 'p' }
292286
impure_fn. { 'f' }
293287
} as u8);
294-
encode_inlineness(ebml_w,
295-
alt fd.decl.il {
296-
il_normal. { 'n' }
297-
il_inline. { 'i' }
298-
} as u8);
299288
encode_type_param_kinds(ebml_w, tps);
300289
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
301290
encode_symbol(ecx, ebml_w, item.id);
@@ -333,7 +322,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
333322
ebml::end_tag(ebml_w);
334323
encode_tag_variant_info(ecx, ebml_w, item.id, variants, index, tps);
335324
}
336-
item_res(_, _, tps, ctor_id) {
325+
item_res(_, tps, _, _, ctor_id) {
337326
let fn_ty = node_id_to_monotype(ecx.ccx.tcx, ctor_id);
338327

339328
ebml::start_tag(ebml_w, tag_items_data_item);
@@ -383,22 +372,21 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
383372
encode_name(ebml_w, item.ident);
384373
for m in methods {
385374
ebml::start_tag(ebml_w, tag_impl_method);
386-
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.node.id))));
375+
ebml_w.writer.write(str::bytes(def_to_str(local_def(m.id))));
387376
ebml::end_tag(ebml_w);
388377
}
389378
ebml::end_tag(ebml_w);
390379

391380
for m in methods {
392-
index += [{val: m.node.id, pos: ebml_w.writer.tell()}];
381+
index += [{val: m.id, pos: ebml_w.writer.tell()}];
393382
ebml::start_tag(ebml_w, tag_items_data_item);
394-
encode_def_id(ebml_w, local_def(m.node.id));
383+
encode_def_id(ebml_w, local_def(m.id));
395384
encode_family(ebml_w, 'f' as u8);
396-
encode_inlineness(ebml_w, 'n' as u8);
397-
encode_type_param_kinds(ebml_w, tps + m.node.tps);
385+
encode_type_param_kinds(ebml_w, tps + m.tps);
398386
encode_type(ecx, ebml_w,
399-
node_id_to_monotype(ecx.ccx.tcx, m.node.id));
400-
encode_name(ebml_w, m.node.ident);
401-
encode_symbol(ecx, ebml_w, m.node.id);
387+
node_id_to_monotype(ecx.ccx.tcx, m.id));
388+
encode_name(ebml_w, m.ident);
389+
encode_symbol(ecx, ebml_w, m.id);
402390
ebml::end_tag(ebml_w);
403391
}
404392
}

src/comp/middle/ast_map.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ fn map_item(cx: ctx, i: @item) {
6868
item_obj(ob, _, ctor_id) {
6969
cx.map.insert(ctor_id, node_obj_ctor(i));
7070
for m in ob.methods {
71-
cx.map.insert(m.node.id, node_obj_method(m));
71+
cx.map.insert(m.id, node_obj_method(m));
7272
}
7373
}
7474
item_impl(_, _, ms) {
75-
for m in ms { cx.map.insert(m.node.id, node_method(m)); }
75+
for m in ms { cx.map.insert(m.id, node_method(m)); }
7676
}
77-
item_res(_, dtor_id, _, ctor_id) {
77+
item_res(_, _, _, dtor_id, ctor_id) {
7878
cx.map.insert(ctor_id, node_res_ctor(i));
7979
cx.map.insert(dtor_id, node_item(i));
8080
}

src/comp/middle/debuginfo.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -721,23 +721,23 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
721721
let (ident, ret_ty, id) = alt cx.ast_map.get(fcx.id) {
722722
ast_map::node_item(item) {
723723
alt item.node {
724-
ast::item_fn(f, _) | ast::item_res(f, _, _, _) {
725-
(item.ident, f.decl.output, item.id)
724+
ast::item_fn(decl, _, _) | ast::item_res(decl, _, _, _, _) {
725+
(item.ident, decl.output, item.id)
726726
}
727727
}
728728
}
729729
ast_map::node_obj_method(method) {
730-
(method.node.ident, method.node.meth.decl.output, method.node.id)
730+
(method.ident, method.decl.output, method.id)
731731
}
732732
ast_map::node_res_ctor(item) {
733-
alt item.node { ast::item_res(f, _, _, ctor_id) {
734-
(item.ident, f.decl.output, ctor_id)
733+
alt item.node { ast::item_res(decl, _, _, _, ctor_id) {
734+
(item.ident, decl.output, ctor_id)
735735
}}
736736
}
737737
ast_map::node_expr(expr) {
738738
alt expr.node {
739-
ast::expr_fn(f, _) {
740-
(dbg_cx.names.next("fn"), f.decl.output, expr.id)
739+
ast::expr_fn(decl, _, _) {
740+
(dbg_cx.names.next("fn"), decl.output, expr.id)
741741
}
742742
ast::expr_fn_block(decl, _) {
743743
(dbg_cx.names.next("fn"), decl.output, expr.id)

src/comp/middle/freevars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ fn collect_freevars(def_map: resolve::def_map, blk: ast::blk)
3838
let walk_expr =
3939
lambda (expr: @ast::expr, &&depth: int, v: visit::vt<int>) {
4040
alt expr.node {
41-
ast::expr_fn(f, captures) {
42-
if f.proto != ast::proto_bare {
41+
ast::expr_fn(decl, _, captures) {
42+
if decl.proto != ast::proto_bare {
4343
visit::visit_expr(expr, depth + 1, v);
4444
}
4545
}

src/comp/middle/kind.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ fn check_expr(e: @expr, cx: ctx, v: visit::vt<ctx>) {
178178
}
179179
}
180180
expr_ternary(_, a, b) { maybe_copy(cx, a); maybe_copy(cx, b); }
181-
expr_fn(_, cap_clause) { check_fn_cap_clause(cx, e.id, *cap_clause); }
182-
181+
expr_fn(_, _, cap_clause) {
182+
check_fn_cap_clause(cx, e.id, *cap_clause);
183+
}
183184
_ { }
184185
}
185186
visit::visit_expr(e, cx, v);

src/comp/middle/last_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ fn visit_expr(ex: @expr, cx: ctx, v: visit::vt<ctx>) {
136136
for arg in args {
137137
alt arg.node {
138138
//NDM--register captured as uses
139-
expr_fn(_, captured) { fns += [arg]; }
139+
expr_fn(_, _, captured) { fns += [arg]; }
140140
expr_fn_block(_, _) { fns += [arg]; }
141141
_ {
142142
alt arg_ts[i].mode {

0 commit comments

Comments
 (0)