Skip to content

Commit 8a3a1fc

Browse files
ericktcatamorphism
authored andcommitted
convert ast::expr into a struct
1 parent 1280a64 commit 8a3a1fc

File tree

15 files changed

+222
-148
lines changed

15 files changed

+222
-148
lines changed

src/libfuzzer/fuzzer.rc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ fn find_rust_files(files: &mut ~[Path], path: &Path) {
7676

7777
fn common_exprs() -> ~[ast::expr] {
7878
fn dse(e: ast::expr_) -> ast::expr {
79-
{ id: 0, callee_id: -1, node: e, span: ast_util::dummy_sp() }
79+
ast::expr {
80+
id: 0,
81+
callee_id: -1,
82+
node: e,
83+
span: ast_util::dummy_sp(),
84+
}
8085
}
8186

8287
fn dsl(l: ast::lit_) -> ast::lit {

src/librustc/front/test.rs

Lines changed: 101 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,19 @@ fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr {
351351
descs.push(mk_test_desc_rec(cx, *test));
352352
}
353353

354-
let inner_expr = @{id: cx.sess.next_node_id(),
355-
callee_id: cx.sess.next_node_id(),
356-
node: ast::expr_vec(descs, ast::m_imm),
357-
span: dummy_sp()};
358-
return @{id: cx.sess.next_node_id(),
359-
callee_id: cx.sess.next_node_id(),
360-
node: ast::expr_vstore(inner_expr, ast::expr_vstore_uniq),
361-
span: dummy_sp()};
354+
let inner_expr = @ast::expr {
355+
id: cx.sess.next_node_id(),
356+
callee_id: cx.sess.next_node_id(),
357+
node: ast::expr_vec(descs, ast::m_imm),
358+
span: dummy_sp(),
359+
};
360+
361+
@ast::expr {
362+
id: cx.sess.next_node_id(),
363+
callee_id: cx.sess.next_node_id(),
364+
node: ast::expr_vstore(inner_expr, ast::expr_vstore_uniq),
365+
span: dummy_sp(),
366+
}
362367
}
363368

364369
fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
@@ -371,17 +376,20 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
371376
let name_lit: ast::lit =
372377
nospan(ast::lit_str(@ast_util::path_name_i(
373378
path, cx.sess.parse_sess.interner)));
374-
let name_expr_inner: @ast::expr =
375-
@{id: cx.sess.next_node_id(),
376-
callee_id: cx.sess.next_node_id(),
377-
node: ast::expr_lit(@name_lit),
378-
span: span};
379-
let name_expr = {id: cx.sess.next_node_id(),
380-
callee_id: cx.sess.next_node_id(),
381-
node: ast::expr_vstore(name_expr_inner,
382-
ast::expr_vstore_uniq),
383-
span: dummy_sp()};
384379

380+
let name_expr_inner = @ast::expr {
381+
id: cx.sess.next_node_id(),
382+
callee_id: cx.sess.next_node_id(),
383+
node: ast::expr_lit(@name_lit),
384+
span: span,
385+
};
386+
387+
let name_expr = ast::expr {
388+
id: cx.sess.next_node_id(),
389+
callee_id: cx.sess.next_node_id(),
390+
node: ast::expr_vstore(name_expr_inner, ast::expr_vstore_uniq),
391+
span: dummy_sp(),
392+
};
385393

386394
let name_field = nospan(ast::field_ {
387395
mutbl: ast::m_imm,
@@ -391,11 +399,12 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
391399

392400
let fn_path = path_node_global(path);
393401

394-
let fn_expr: ast::expr =
395-
{id: cx.sess.next_node_id(),
396-
callee_id: cx.sess.next_node_id(),
397-
node: ast::expr_path(fn_path),
398-
span: span};
402+
let fn_expr = ast::expr {
403+
id: cx.sess.next_node_id(),
404+
callee_id: cx.sess.next_node_id(),
405+
node: ast::expr_path(fn_path),
406+
span: span,
407+
};
399408

400409
let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);
401410

@@ -407,11 +416,12 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
407416

408417
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
409418

410-
let ignore_expr: ast::expr =
411-
{id: cx.sess.next_node_id(),
412-
callee_id: cx.sess.next_node_id(),
413-
node: ast::expr_lit(@ignore_lit),
414-
span: span};
419+
let ignore_expr = ast::expr {
420+
id: cx.sess.next_node_id(),
421+
callee_id: cx.sess.next_node_id(),
422+
node: ast::expr_lit(@ignore_lit),
423+
span: span,
424+
};
415425

416426
let ignore_field = nospan(ast::field_ {
417427
mutbl: ast::m_imm,
@@ -421,11 +431,12 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
421431

422432
let fail_lit: ast::lit = nospan(ast::lit_bool(test.should_fail));
423433

424-
let fail_expr: ast::expr =
425-
{id: cx.sess.next_node_id(),
426-
callee_id: cx.sess.next_node_id(),
427-
node: ast::expr_lit(@fail_lit),
428-
span: span};
434+
let fail_expr = ast::expr {
435+
id: cx.sess.next_node_id(),
436+
callee_id: cx.sess.next_node_id(),
437+
node: ast::expr_lit(@fail_lit),
438+
span: span,
439+
};
429440

430441
let fail_field = nospan(ast::field_ {
431442
mutbl: ast::m_imm,
@@ -437,14 +448,19 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
437448
mk_path(cx, ~[cx.sess.ident_of(~"test"),
438449
cx.sess.ident_of(~"TestDesc")]);
439450

440-
let desc_rec_: ast::expr_ =
441-
ast::expr_struct(
442-
test_desc_path,
443-
~[name_field, fn_field, ignore_field, fail_field],
444-
option::None);
445-
let desc_rec: ast::expr =
446-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
447-
node: desc_rec_, span: span};
451+
let desc_rec_ = ast::expr_struct(
452+
test_desc_path,
453+
~[name_field, fn_field, ignore_field, fail_field],
454+
option::None
455+
);
456+
457+
let desc_rec = ast::expr {
458+
id: cx.sess.next_node_id(),
459+
callee_id: cx.sess.next_node_id(),
460+
node: desc_rec_,
461+
span: span,
462+
};
463+
448464
return @desc_rec;
449465
}
450466

@@ -454,11 +470,11 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
454470
fn mk_test_wrapper(cx: test_ctxt,
455471
+fn_path_expr: ast::expr,
456472
span: span) -> @ast::expr {
457-
let call_expr: ast::expr = {
473+
let call_expr = ast::expr {
458474
id: cx.sess.next_node_id(),
459475
callee_id: cx.sess.next_node_id(),
460476
node: ast::expr_call(@fn_path_expr, ~[], false),
461-
span: span
477+
span: span,
462478
};
463479

464480
let call_stmt: ast::stmt = nospan(
@@ -478,11 +494,10 @@ fn mk_test_wrapper(cx: test_ctxt,
478494
rules: ast::default_blk
479495
});
480496

481-
let wrapper_expr: ast::expr = {
497+
let wrapper_expr = ast::expr {
482498
id: cx.sess.next_node_id(),
483499
callee_id: cx.sess.next_node_id(),
484-
node: ast::expr_fn(ast::ProtoBare, wrapper_decl,
485-
wrapper_body, @~[]),
500+
node: ast::expr_fn(ast::ProtoBare, wrapper_decl, wrapper_body, @~[]),
486501
span: span
487502
};
488503

@@ -525,51 +540,59 @@ fn mk_test_main_call(cx: test_ctxt) -> @ast::expr {
525540
cx.sess.ident_of(~"args")
526541
]);
527542

528-
let args_path_expr_: ast::expr_ = ast::expr_path(args_path);
529-
530-
let args_path_expr: ast::expr =
531-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
532-
node: args_path_expr_, span: dummy_sp()};
533-
534-
let args_call_expr_ = ast::expr_call(@args_path_expr, ~[], false);
543+
let args_path_expr = ast::expr {
544+
id: cx.sess.next_node_id(),
545+
callee_id: cx.sess.next_node_id(),
546+
node: ast::expr_path(args_path),
547+
span: dummy_sp(),
548+
};
535549

536-
let args_call_expr: ast::expr =
537-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
538-
node: args_call_expr_, span: dummy_sp()};
550+
let args_call_expr = ast::expr {
551+
id: cx.sess.next_node_id(),
552+
callee_id: cx.sess.next_node_id(),
553+
node: ast::expr_call(@args_path_expr, ~[], false),
554+
span: dummy_sp(),
555+
};
539556

540557
// Call __test::test to generate the vector of test_descs
541558
let test_path = path_node(~[cx.sess.ident_of(~"tests")]);
542559

543-
let test_path_expr_: ast::expr_ = ast::expr_path(test_path);
544-
545-
let test_path_expr: ast::expr =
546-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
547-
node: test_path_expr_, span: dummy_sp()};
548-
549-
let test_call_expr_ = ast::expr_call(@test_path_expr, ~[], false);
560+
let test_path_expr = ast::expr {
561+
id: cx.sess.next_node_id(),
562+
callee_id: cx.sess.next_node_id(),
563+
node: ast::expr_path(test_path),
564+
span: dummy_sp(),
565+
};
550566

551-
let test_call_expr: ast::expr =
552-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
553-
node: test_call_expr_, span: dummy_sp()};
567+
let test_call_expr = ast::expr {
568+
id: cx.sess.next_node_id(),
569+
callee_id: cx.sess.next_node_id(),
570+
node: ast::expr_call(@test_path_expr, ~[], false),
571+
span: dummy_sp(),
572+
};
554573

555574
// Call std::test::test_main
556575
let test_main_path =
557576
mk_path(cx, ~[cx.sess.ident_of(~"test"),
558577
cx.sess.ident_of(~"test_main")]);
559578

560-
let test_main_path_expr_: ast::expr_ = ast::expr_path(test_main_path);
561-
562-
let test_main_path_expr: ast::expr =
563-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
564-
node: test_main_path_expr_, span: dummy_sp()};
565-
566-
let test_main_call_expr_: ast::expr_ =
567-
ast::expr_call(@test_main_path_expr,
568-
~[@args_call_expr, @test_call_expr], false);
579+
let test_main_path_expr = ast::expr {
580+
id: cx.sess.next_node_id(),
581+
callee_id: cx.sess.next_node_id(),
582+
node: ast::expr_path(test_main_path),
583+
span: dummy_sp(),
584+
};
569585

570-
let test_main_call_expr: ast::expr =
571-
{id: cx.sess.next_node_id(), callee_id: cx.sess.next_node_id(),
572-
node: test_main_call_expr_, span: dummy_sp()};
586+
let test_main_call_expr = ast::expr {
587+
id: cx.sess.next_node_id(),
588+
callee_id: cx.sess.next_node_id(),
589+
node: ast::expr_call(
590+
@test_main_path_expr,
591+
~[@args_call_expr, @test_call_expr],
592+
false
593+
),
594+
span: dummy_sp(),
595+
};
573596

574597
return @test_main_call_expr;
575598
}

src/librustc/middle/check_const.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ fn check_item(sess: Session, ast_map: ast_map::map,
5757
fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
5858
fn is_str(e: @expr) -> bool {
5959
match e.node {
60-
expr_vstore(@{node: expr_lit(@spanned { node: lit_str(_),
61-
_}), _},
62-
expr_vstore_uniq) => true,
63-
_ => false
60+
expr_vstore(
61+
@expr { node: expr_lit(@spanned { node: lit_str(_), _}), _ },
62+
expr_vstore_uniq
63+
) => true,
64+
_ => false
6465
}
6566
}
6667
match p.node {

src/librustc/middle/check_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn check_crate(tcx: ty::ctxt, crate: @crate) {
3838
expr_fn_block(_, ref b, _) => {
3939
(v.visit_block)((*b), {in_loop: false, can_ret: false}, v);
4040
}
41-
expr_loop_body(@{node: expr_fn_block(_, ref b, _), _}) => {
41+
expr_loop_body(@expr {node: expr_fn_block(_, ref b, _), _}) => {
4242
let proto = ty::ty_fn_proto(ty::expr_ty(tcx, e));
4343
let blk = (proto == ProtoBorrowed);
4444
(v.visit_block)((*b), {in_loop: true, can_ret: blk}, v);

src/librustc/middle/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ fn is_refutable(cx: @MatchCheckCtxt, pat: &pat) -> bool {
693693
is_refutable(cx, sub)
694694
}
695695
pat_wild | pat_ident(_, _, None) => { false }
696-
pat_lit(@{node: expr_lit(@spanned { node: lit_nil, _}), _}) => {
696+
pat_lit(@expr {node: expr_lit(@spanned { node: lit_nil, _}), _}) => {
697697
// "()"
698698
false
699699
}

src/librustc/middle/lint.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,10 @@ fn check_item_path_statement(cx: ty::ctxt, it: @ast::item) {
799799
visit::mk_simple_visitor(@visit::SimpleVisitor {
800800
visit_stmt: |s: @ast::stmt| {
801801
match s.node {
802-
ast::stmt_semi(@{id: id,
803-
callee_id: _,
804-
node: ast::expr_path(_),
805-
span: _}, _) => {
802+
ast::stmt_semi(
803+
@ast::expr { id: id, node: ast::expr_path(_), _ },
804+
_
805+
) => {
806806
cx.sess.span_lint(
807807
path_statement, id, it.id,
808808
s.span,

src/librustc/middle/trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn trans_call_inner(
421421
let ret_in_loop = match /*bad*/copy args {
422422
ArgExprs(args) => {
423423
args.len() > 0u && match vec::last(args).node {
424-
ast::expr_loop_body(@{
424+
ast::expr_loop_body(@ast::expr {
425425
node: ast::expr_fn_block(_, ref body, _),
426426
_
427427
}) => body_contains_ret((*body)),
@@ -628,7 +628,7 @@ fn trans_arg_expr(bcx: block,
628628
match arg_expr.node {
629629
ast::expr_loop_body(
630630
// XXX: Bad copy.
631-
blk@@{
631+
blk@@ast::expr {
632632
node: ast::expr_fn_block(copy decl, ref body, cap),
633633
_
634634
}) =>

src/libsyntax/ast.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -696,8 +696,14 @@ impl blk_check_mode : cmp::Eq {
696696

697697
#[auto_encode]
698698
#[auto_decode]
699-
type expr = {id: node_id, callee_id: node_id, node: expr_, span: span};
700-
// Extra node ID is only used for index, assign_op, unary, binary, method call
699+
struct expr {
700+
id: node_id,
701+
// Extra node ID is only used for index, assign_op, unary, binary, method
702+
// call
703+
callee_id: node_id,
704+
node: expr_,
705+
span: span,
706+
}
701707

702708
#[auto_encode]
703709
#[auto_decode]

src/libsyntax/ext/auto_encode.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,12 @@ priv impl ext_ctxt {
263263
}
264264

265265
fn expr(span: span, node: ast::expr_) -> @ast::expr {
266-
@{id: self.next_id(), callee_id: self.next_id(),
267-
node: node, span: span}
266+
@ast::expr {
267+
id: self.next_id(),
268+
callee_id: self.next_id(),
269+
node: node,
270+
span: span,
271+
}
268272
}
269273

270274
fn path(span: span, strs: ~[ast::ident]) -> @ast::path {

src/libsyntax/ext/build.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ use ext::build;
1919
use core::dvec;
2020
use core::option;
2121

22-
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) ->
22+
fn mk_expr(cx: ext_ctxt, sp: codemap::span, expr: ast::expr_) -> @ast::expr {
2323
@ast::expr {
24-
return @{id: cx.next_id(), callee_id: cx.next_id(),
25-
node: expr, span: sp};
24+
id: cx.next_id(),
25+
callee_id: cx.next_id(),
26+
node: expr,
27+
span: sp,
28+
}
2629
}
2730

2831
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {

0 commit comments

Comments
 (0)