Skip to content

Commit a0617ea

Browse files
committed
librustc: Eliminate most expressions of the form a.b() that are not method calls. rs=refactoring
1 parent b38d7f6 commit a0617ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+296
-276
lines changed

src/libcore/task/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ impl TaskBuilder {
414414
mut notify_chan: move notify_chan,
415415
sched: x.opts.sched
416416
};
417-
spawn::spawn_raw(move opts, x.gen_body(move f));
417+
spawn::spawn_raw(move opts, (x.gen_body)(move f));
418418
}
419419
/// Runs a task, while transfering ownership of one argument to the child.
420420
fn spawn_with<A: Send>(arg: A, f: fn~(v: A)) {

src/librustc/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,15 +610,15 @@ fn mangle_internal_name_by_type_only(ccx: @crate_ctxt,
610610
fn mangle_internal_name_by_path_and_seq(ccx: @crate_ctxt, path: path,
611611
flav: ~str) -> ~str {
612612
return mangle(ccx.sess,
613-
vec::append_one(path, path_name(ccx.names(flav))));
613+
vec::append_one(path, path_name((ccx.names)(flav))));
614614
}
615615

616616
fn mangle_internal_name_by_path(ccx: @crate_ctxt, path: path) -> ~str {
617617
return mangle(ccx.sess, path);
618618
}
619619

620620
fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: ~str) -> ~str {
621-
return fmt!("%s_%u", flav, ccx.names(flav).repr);
621+
return fmt!("%s_%u", flav, (ccx.names)(flav).repr);
622622
}
623623

624624
// If the user wants an exe generated we need to invoke

src/librustc/front/config.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,25 @@ fn fold_block(cx: ctxt, b: ast::blk_, fld: fold::ast_fold) ->
126126
}
127127

128128
fn item_in_cfg(cx: ctxt, item: @ast::item) -> bool {
129-
return cx.in_cfg(item.attrs);
129+
return (cx.in_cfg)(item.attrs);
130130
}
131131

132132
fn foreign_item_in_cfg(cx: ctxt, item: @ast::foreign_item) -> bool {
133-
return cx.in_cfg(item.attrs);
133+
return (cx.in_cfg)(item.attrs);
134134
}
135135

136136
fn view_item_in_cfg(cx: ctxt, item: @ast::view_item) -> bool {
137-
return cx.in_cfg(item.attrs);
137+
return (cx.in_cfg)(item.attrs);
138138
}
139139

140140
fn method_in_cfg(cx: ctxt, meth: @ast::method) -> bool {
141-
return cx.in_cfg(meth.attrs);
141+
return (cx.in_cfg)(meth.attrs);
142142
}
143143

144144
fn trait_method_in_cfg(cx: ctxt, meth: &ast::trait_method) -> bool {
145145
match *meth {
146-
ast::required(ref meth) => cx.in_cfg(meth.attrs),
147-
ast::provided(@ref meth) => cx.in_cfg(meth.attrs)
146+
ast::required(ref meth) => (cx.in_cfg)(meth.attrs),
147+
ast::provided(@ref meth) => (cx.in_cfg)(meth.attrs)
148148
}
149149
}
150150

src/librustc/metadata/encoder.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ fn encode_info_for_ctor(ecx: @encode_ctxt, ebml_w: Writer::Serializer,
474474
encode_path(ecx, ebml_w, path, ast_map::path_name(ident));
475475
match item {
476476
Some(it) => {
477-
ecx.encode_inlined_item(ecx, ebml_w, path, it);
477+
(ecx.encode_inlined_item)(ecx, ebml_w, path, it);
478478
}
479479
None => {
480480
encode_symbol(ecx, ebml_w, id);
@@ -503,7 +503,7 @@ fn encode_info_for_method(ecx: @encode_ctxt, ebml_w: Writer::Serializer,
503503
encode_path(ecx, ebml_w, impl_path, ast_map::path_name(m.ident));
504504
encode_self_type(ebml_w, m.self_ty.node);
505505
if all_tps.len() > 0u || should_inline {
506-
ecx.encode_inlined_item(
506+
(ecx.encode_inlined_item)(
507507
ecx, ebml_w, impl_path,
508508
ii_method(local_def(parent_id), m));
509509
} else {
@@ -581,7 +581,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: Writer::Serializer,
581581
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
582582
encode_attributes(ebml_w, item.attrs);
583583
if tps.len() > 0u || should_inline(item.attrs) {
584-
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
584+
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
585585
} else {
586586
encode_symbol(ecx, ebml_w, item.id);
587587
}
@@ -623,7 +623,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: Writer::Serializer,
623623
for enum_definition.variants.each |v| {
624624
encode_variant_id(ebml_w, local_def(v.node.id));
625625
}
626-
ecx.encode_inlined_item(ecx, ebml_w, path, ii_item(item));
626+
(ecx.encode_inlined_item)(ecx, ebml_w, path, ii_item(item));
627627
encode_path(ecx, ebml_w, path, ast_map::path_name(item.ident));
628628
encode_region_param(ecx, ebml_w, item);
629629
}
@@ -851,8 +851,8 @@ fn encode_info_for_foreign_item(ecx: @encode_ctxt, ebml_w: Writer::Serializer,
851851
encode_type_param_bounds(ebml_w, ecx, tps);
852852
encode_type(ecx, ebml_w, node_id_to_type(ecx.tcx, nitem.id));
853853
if abi == foreign_abi_rust_intrinsic {
854-
ecx.encode_inlined_item(ecx, ebml_w, path,
855-
ii_foreign(nitem));
854+
(ecx.encode_inlined_item)(ecx, ebml_w, path,
855+
ii_foreign(nitem));
856856
} else {
857857
encode_symbol(ecx, ebml_w, nitem.id);
858858
}

src/librustc/metadata/tyencode.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
6767
// Do not emit node ids that map to unexported names. Those
6868
// are not helpful.
6969
if def_id.crate != local_crate ||
70-
cx.reachable(def_id.node) {
70+
(cx.reachable)(def_id.node) {
7171
w.write_char('"');
72-
w.write_str(cx.ds(def_id));
72+
w.write_str((cx.ds)(def_id));
7373
w.write_char('|');
7474
}
7575
}
@@ -229,14 +229,14 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
229229
}
230230
ty::ty_enum(def, substs) => {
231231
w.write_str(&"t[");
232-
w.write_str(cx.ds(def));
232+
w.write_str((cx.ds)(def));
233233
w.write_char('|');
234234
enc_substs(w, cx, substs);
235235
w.write_char(']');
236236
}
237237
ty::ty_trait(def, substs, vstore) => {
238238
w.write_str(&"x[");
239-
w.write_str(cx.ds(def));
239+
w.write_str((cx.ds)(def));
240240
w.write_char('|');
241241
enc_substs(w, cx, substs);
242242
enc_vstore(w, cx, vstore);
@@ -293,7 +293,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
293293
}
294294
ty::ty_param({idx: id, def_id: did}) => {
295295
w.write_char('p');
296-
w.write_str(cx.ds(did));
296+
w.write_str((cx.ds)(did));
297297
w.write_char('|');
298298
w.write_str(uint::str(id));
299299
}
@@ -309,7 +309,7 @@ fn enc_sty(w: io::Writer, cx: @ctxt, st: ty::sty) {
309309
ty::ty_class(def, substs) => {
310310
debug!("~~~~ %s", ~"a[");
311311
w.write_str(&"a[");
312-
let s = cx.ds(def);
312+
let s = (cx.ds)(def);
313313
debug!("~~~~ %s", s);
314314
w.write_str(s);
315315
debug!("~~~~ %s", ~"|");

src/librustc/middle/borrowck/gather_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ fn req_loans_in_expr(ex: @ast::expr,
189189
ast::expr_while(cond, body) => {
190190
// during the condition, can only root for the condition
191191
self.root_ub = cond.id;
192-
vt.visit_expr(cond, self, vt);
192+
(vt.visit_expr)(cond, self, vt);
193193

194194
// during body, can only root for the body
195195
self.root_ub = body.node.id;
196-
vt.visit_block(body, self, vt);
196+
(vt.visit_block)(body, self, vt);
197197
}
198198

199199
// see explanation attached to the `root_ub` field:

src/librustc/middle/check_const.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ fn check_item(sess: Session, ast_map: ast_map::map,
2222
it: @item, &&_is_const: bool, v: visit::vt<bool>) {
2323
match it.node {
2424
item_const(_, ex) => {
25-
v.visit_expr(ex, true, v);
25+
(v.visit_expr)(ex, true, v);
2626
check_item_recursion(sess, ast_map, def_map, it);
2727
}
2828
item_enum(enum_definition, _) => {
2929
for enum_definition.variants.each |var| {
3030
do option::iter(&var.node.disr_expr) |ex| {
31-
v.visit_expr(*ex, true, v);
31+
(v.visit_expr)(*ex, true, v);
3232
}
3333
}
3434
}
@@ -46,10 +46,10 @@ fn check_pat(p: @pat, &&_is_const: bool, v: visit::vt<bool>) {
4646
}
4747
match p.node {
4848
// Let through plain ~-string literals here
49-
pat_lit(a) => if !is_str(a) { v.visit_expr(a, true, v); },
49+
pat_lit(a) => if !is_str(a) { (v.visit_expr)(a, true, v); },
5050
pat_range(a, b) => {
51-
if !is_str(a) { v.visit_expr(a, true, v); }
52-
if !is_str(b) { v.visit_expr(b, true, v); }
51+
if !is_str(a) { (v.visit_expr)(a, true, v); }
52+
if !is_str(b) { (v.visit_expr)(b, true, v); }
5353
}
5454
_ => visit::visit_pat(p, false, v)
5555
}
@@ -179,7 +179,7 @@ fn check_item_recursion(sess: Session, ast_map: ast_map::map,
179179
visit_expr: visit_expr,
180180
.. *visit::default_visitor()
181181
});
182-
visitor.visit_item(it, env, visitor);
182+
(visitor.visit_item)(it, env, visitor);
183183

184184
fn visit_item(it: @item, &&env: env, v: visit::vt<env>) {
185185
if (*env.idstack).contains(&(it.id)) {
@@ -197,7 +197,7 @@ fn check_item_recursion(sess: Session, ast_map: ast_map::map,
197197
Some(def_const(def_id)) => {
198198
match env.ast_map.get(def_id.node) {
199199
ast_map::node_item(it, _) => {
200-
v.visit_item(it, env, v);
200+
(v.visit_item)(it, env, v);
201201
}
202202
_ => fail ~"const not bound to an item"
203203
}

src/librustc/middle/check_loop.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@ use syntax::visit;
44
type ctx = {in_loop: bool, can_ret: bool};
55

66
fn check_crate(tcx: ty::ctxt, crate: @crate) {
7-
visit::visit_crate(*crate, {in_loop: false,can_ret: true}, visit::mk_vt(@{
7+
visit::visit_crate(*crate,
8+
{in_loop: false, can_ret: true},
9+
visit::mk_vt(@{
810
visit_item: |i, _cx, v| {
911
visit::visit_item(i, {in_loop: false, can_ret: true}, v);
1012
},
1113
visit_expr: |e: @expr, cx: ctx, v: visit::vt<ctx>| {
1214
match e.node {
1315
expr_while(e, b) => {
14-
v.visit_expr(e, cx, v);
15-
v.visit_block(b, {in_loop: true,.. cx}, v);
16+
(v.visit_expr)(e, cx, v);
17+
(v.visit_block)(b, {in_loop: true,.. cx}, v);
1618
}
1719
expr_loop(b, _) => {
18-
v.visit_block(b, {in_loop: true,.. cx}, v);
20+
(v.visit_block)(b, {in_loop: true,.. cx}, v);
1921
}
2022
expr_fn(_, _, _, _) => {
2123
visit::visit_expr(e, {in_loop: false, can_ret: true}, v);
2224
}
2325
expr_fn_block(_, b, _) => {
24-
v.visit_block(b, {in_loop: false, can_ret: false}, v);
26+
(v.visit_block)(b, {in_loop: false, can_ret: false}, v);
2527
}
2628
expr_loop_body(@{node: expr_fn_block(_, b, _), _}) => {
2729
let proto = ty::ty_fn_proto(ty::expr_ty(tcx, e));
2830
let blk = (proto == ProtoBorrowed);
29-
v.visit_block(b, {in_loop: true, can_ret: blk}, v);
31+
(v.visit_block)(b, {in_loop: true, can_ret: blk}, v);
3032
}
3133
expr_break(_) => {
3234
if !cx.in_loop {

src/librustc/middle/freevars.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fn collect_freevars(def_map: resolve::DefMap, blk: ast::blk)
7676

7777
let v = visit::mk_vt(@{visit_item: ignore_item, visit_expr: walk_expr,
7878
.. *visit::default_visitor()});
79-
v.visit_block(blk, 1, v);
79+
(v.visit_block)(blk, 1, v);
8080
return @*refs;
8181
}
8282

src/librustc/middle/liveness.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ fn visit_fn(fk: visit::fn_kind, decl: fn_decl, body: blk,
449449
visit_arm: check_arm,
450450
.. *visit::default_visitor()
451451
});
452-
check_vt.visit_block(body, lsets, check_vt);
452+
(check_vt.visit_block)(body, lsets, check_vt);
453453
lsets.check_ret(id, sp, fk, entry_ln);
454454
lsets.warn_about_unused_args(decl, entry_ln);
455455
}
@@ -1512,7 +1512,7 @@ fn check_expr(expr: @expr, &&self: @Liveness, vt: vt<@Liveness>) {
15121512

15131513
expr_assign(l, r) => {
15141514
self.check_lvalue(l, vt);
1515-
vt.visit_expr(r, self, vt);
1515+
(vt.visit_expr)(r, self, vt);
15161516

15171517
visit::visit_expr(expr, self, vt);
15181518
}

src/librustc/middle/region.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,13 @@ fn determine_rp_in_fn(fk: visit::fn_kind,
584584
visitor: visit::vt<determine_rp_ctxt>) {
585585
do cx.with(cx.item_id, false) {
586586
do cx.with_ambient_variance(rv_contravariant) {
587-
for decl.inputs.each |a| { visitor.visit_ty(a.ty, cx, visitor); }
587+
for decl.inputs.each |a| {
588+
(visitor.visit_ty)(a.ty, cx, visitor);
589+
}
588590
}
589-
visitor.visit_ty(decl.output, cx, visitor);
590-
visitor.visit_ty_params(visit::tps_of_fn(fk), cx, visitor);
591-
visitor.visit_block(body, cx, visitor);
591+
(visitor.visit_ty)(decl.output, cx, visitor);
592+
(visitor.visit_ty_params)(visit::tps_of_fn(fk), cx, visitor);
593+
(visitor.visit_block)(body, cx, visitor);
592594
}
593595
}
594596

@@ -695,7 +697,7 @@ fn determine_rp_in_ty(ty: @ast::Ty,
695697
// type parameters are---for now, anyway---always invariant
696698
do cx.with_ambient_variance(rv_invariant) {
697699
for path.types.each |tp| {
698-
visitor.visit_ty(*tp, cx, visitor);
700+
(visitor.visit_ty)(*tp, cx, visitor);
699701
}
700702
}
701703
}
@@ -707,11 +709,11 @@ fn determine_rp_in_ty(ty: @ast::Ty,
707709
// parameters are contravariant
708710
do cx.with_ambient_variance(rv_contravariant) {
709711
for f.decl.inputs.each |a| {
710-
visitor.visit_ty(a.ty, cx, visitor);
712+
(visitor.visit_ty)(a.ty, cx, visitor);
711713
}
712714
}
713715
visit::visit_ty_param_bounds(f.bounds, cx, visitor);
714-
visitor.visit_ty(f.decl.output, cx, visitor);
716+
(visitor.visit_ty)(f.decl.output, cx, visitor);
715717
}
716718
}
717719

@@ -725,10 +727,10 @@ fn determine_rp_in_ty(ty: @ast::Ty,
725727
// mutability is invariant
726728
if mt.mutbl == ast::m_mutbl {
727729
do cx.with_ambient_variance(rv_invariant) {
728-
visitor.visit_ty(mt.ty, cx, visitor);
730+
(visitor.visit_ty)(mt.ty, cx, visitor);
729731
}
730732
} else {
731-
visitor.visit_ty(mt.ty, cx, visitor);
733+
(visitor.visit_ty)(mt.ty, cx, visitor);
732734
}
733735
}
734736
}

src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,7 @@ fn new_block(cx: fn_ctxt, parent: Option<block>, +kind: block_kind,
10391039
-> block {
10401040

10411041
let s = if cx.ccx.sess.opts.save_temps || cx.ccx.sess.opts.debuginfo {
1042-
cx.ccx.names(name)
1042+
(cx.ccx.names)(name)
10431043
} else { special_idents::invalid };
10441044
let llbb: BasicBlockRef = str::as_c_str(cx.ccx.sess.str_of(s), |buf| {
10451045
llvm::LLVMAppendBasicBlock(cx.llfn, buf)
@@ -2067,7 +2067,7 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id,
20672067
None if substs.is_none() => {
20682068
let s = mangle_exported_name(
20692069
ccx,
2070-
vec::append(path, ~[path_name(ccx.names(~"dtor"))]),
2070+
vec::append(path, ~[path_name((ccx.names)(~"dtor"))]),
20712071
t);
20722072
ccx.item_symbols.insert(id, s);
20732073
s
@@ -2081,7 +2081,7 @@ fn get_dtor_symbol(ccx: @crate_ctxt, path: path, id: ast::node_id,
20812081
mangle_exported_name(
20822082
ccx,
20832083
vec::append(path,
2084-
~[path_name(ccx.names(~"dtor"))]),
2084+
~[path_name((ccx.names)(~"dtor"))]),
20852085
mono_ty)
20862086
}
20872087
None => {
@@ -2253,7 +2253,7 @@ fn get_item_val(ccx: @crate_ctxt, id: ast::node_id) -> ValueRef {
22532253
fn register_method(ccx: @crate_ctxt, id: ast::node_id, pth: @ast_map::path,
22542254
m: @ast::method) -> ValueRef {
22552255
let mty = ty::node_id_to_type(ccx.tcx, id);
2256-
let pth = vec::append(*pth, ~[path_name(ccx.names(~"meth")),
2256+
let pth = vec::append(*pth, ~[path_name((ccx.names)(~"meth")),
22572257
path_name(m.ident)]);
22582258
let llfn = register_fn_full(ccx, m.span, pth, id, mty);
22592259
set_inline_hint_if_appr(m.attrs, llfn);

src/librustc/middle/trans/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ fn C_cstr(cx: @crate_ctxt, s: ~str) -> ValueRef {
10491049
llvm::LLVMConstString(buf, str::len(s) as c_uint, False)
10501050
};
10511051
let g =
1052-
str::as_c_str(fmt!("str%u", cx.names(~"str").repr),
1052+
str::as_c_str(fmt!("str%u", (cx.names)(~"str").repr),
10531053
|buf| llvm::LLVMAddGlobal(cx.llmod, val_ty(sc), buf));
10541054
llvm::LLVMSetInitializer(g, sc);
10551055
llvm::LLVMSetGlobalConstant(g, True);
@@ -1111,7 +1111,7 @@ fn C_bytes_plus_null(bytes: ~[u8]) -> ValueRef unsafe {
11111111
11121112
fn C_shape(ccx: @crate_ctxt, bytes: ~[u8]) -> ValueRef {
11131113
let llshape = C_bytes_plus_null(bytes);
1114-
let name = fmt!("shape%u", ccx.names(~"shape").repr);
1114+
let name = fmt!("shape%u", (ccx.names)(~"shape").repr);
11151115
let llglobal = str::as_c_str(name, |buf| {
11161116
llvm::LLVMAddGlobal(ccx.llmod, val_ty(llshape), buf)
11171117
});

0 commit comments

Comments
 (0)