Removed the obsolete ast::CallSugar (previously used by do).

This commit is contained in:
Eduard Burtescu 2014-02-14 10:28:32 +02:00 committed by Alex Crichton
parent 07ea23e15d
commit 6e84023596
23 changed files with 79 additions and 146 deletions

View File

@ -831,10 +831,10 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
ast::ExprAssignOp(_, _, dest, _) => { ast::ExprAssignOp(_, _, dest, _) => {
this.check_assignment(dest); this.check_assignment(dest);
} }
ast::ExprCall(f, ref args, _) => { ast::ExprCall(f, ref args) => {
this.check_call(expr, Some(f), f.id, f.span, *args); this.check_call(expr, Some(f), f.id, f.span, *args);
} }
ast::ExprMethodCall(callee_id, _, _, ref args, _) => { ast::ExprMethodCall(callee_id, _, _, ref args) => {
this.check_call(expr, None, callee_id, expr.span, *args); this.check_call(expr, None, callee_id, expr.span, *args);
} }
ast::ExprIndex(callee_id, _, rval) | ast::ExprIndex(callee_id, _, rval) |

View File

@ -351,11 +351,11 @@ impl CFGBuilder {
self.straightline(expr, pred, *elems) self.straightline(expr, pred, *elems)
} }
ast::ExprCall(func, ref args, _) => { ast::ExprCall(func, ref args) => {
self.call(expr, pred, func, *args) self.call(expr, pred, func, *args)
} }
ast::ExprMethodCall(_, _, _, ref args, _) => { ast::ExprMethodCall(_, _, _, ref args) => {
self.call(expr, pred, args[0], args.slice_from(1)) self.call(expr, pred, args[0], args.slice_from(1))
} }

View File

@ -160,7 +160,7 @@ pub fn check_expr(v: &mut CheckCrateVisitor,
} }
} }
} }
ExprCall(callee, _, NoSugar) => { ExprCall(callee, _) => {
let def_map = def_map.borrow(); let def_map = def_map.borrow();
match def_map.get().find(&callee.id) { match def_map.get().find(&callee.id) {
Some(&DefStruct(..)) => {} // OK. Some(&DefStruct(..)) => {} // OK.

View File

@ -577,12 +577,12 @@ impl<'a, O:DataFlowOperator> PropagationContext<'a, O> {
self.walk_opt_expr(with_expr, in_out, loop_scopes); self.walk_opt_expr(with_expr, in_out, loop_scopes);
} }
ast::ExprCall(f, ref args, _) => { ast::ExprCall(f, ref args) => {
self.walk_expr(f, in_out, loop_scopes); self.walk_expr(f, in_out, loop_scopes);
self.walk_call(f.id, expr.id, *args, in_out, loop_scopes); self.walk_call(f.id, expr.id, *args, in_out, loop_scopes);
} }
ast::ExprMethodCall(callee_id, _, _, ref args, _) => { ast::ExprMethodCall(callee_id, _, _, ref args) => {
self.walk_call(callee_id, expr.id, *args, in_out, loop_scopes); self.walk_call(callee_id, expr.id, *args, in_out, loop_scopes);
} }

View File

@ -120,7 +120,7 @@ impl Visitor<()> for EffectCheckVisitor {
fn visit_expr(&mut self, expr: &ast::Expr, _:()) { fn visit_expr(&mut self, expr: &ast::Expr, _:()) {
match expr.node { match expr.node {
ast::ExprMethodCall(callee_id, _, _, _, _) => { ast::ExprMethodCall(callee_id, _, _, _) => {
let base_type = ty::node_id_to_type(self.tcx, callee_id); let base_type = ty::node_id_to_type(self.tcx, callee_id);
debug!("effect: method call case, base type is {}", debug!("effect: method call case, base type is {}",
ppaux::ty_to_str(self.tcx, base_type)); ppaux::ty_to_str(self.tcx, base_type));
@ -129,7 +129,7 @@ impl Visitor<()> for EffectCheckVisitor {
"invocation of unsafe method") "invocation of unsafe method")
} }
} }
ast::ExprCall(base, _, _) => { ast::ExprCall(base, _) => {
let base_type = ty::node_id_to_type(self.tcx, base.id); let base_type = ty::node_id_to_type(self.tcx, base.id);
debug!("effect: call case, base type is {}", debug!("effect: call case, base type is {}",
ppaux::ty_to_str(self.tcx, base_type)); ppaux::ty_to_str(self.tcx, base_type));

View File

@ -1205,7 +1205,7 @@ impl Liveness {
}) })
} }
ExprCall(f, ref args, _) => { ExprCall(f, ref args) => {
// calling a fn with bot return type means that the fn // calling a fn with bot return type means that the fn
// will fail, and hence the successors can be ignored // will fail, and hence the successors can be ignored
let t_ret = ty::ty_fn_ret(ty::expr_ty(self.tcx, f)); let t_ret = ty::ty_fn_ret(ty::expr_ty(self.tcx, f));
@ -1215,7 +1215,7 @@ impl Liveness {
self.propagate_through_expr(f, succ) self.propagate_through_expr(f, succ)
} }
ExprMethodCall(callee_id, _, _, ref args, _) => { ExprMethodCall(callee_id, _, _, ref args) => {
// calling a method with bot return type means that the method // calling a method with bot return type means that the method
// will fail, and hence the successors can be ignored // will fail, and hence the successors can be ignored
let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.tcx, callee_id)); let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.tcx, callee_id));

View File

@ -382,7 +382,7 @@ impl VisitContext {
} }
} }
ExprCall(callee, ref args, _) => { // callee(args) ExprCall(callee, ref args) => { // callee(args)
// Figure out whether the called function is consumed. // Figure out whether the called function is consumed.
let mode = match ty::get(ty::expr_ty(self.tcx, callee)).sty { let mode = match ty::get(ty::expr_ty(self.tcx, callee)).sty {
ty::ty_closure(ref cty) => { ty::ty_closure(ref cty) => {
@ -412,7 +412,7 @@ impl VisitContext {
self.use_fn_args(callee.id, *args); self.use_fn_args(callee.id, *args);
} }
ExprMethodCall(callee_id, _, _, ref args, _) => { // callee.m(args) ExprMethodCall(callee_id, _, _, ref args) => { // callee.m(args)
self.use_fn_args(callee_id, *args); self.use_fn_args(callee_id, *args);
} }

View File

@ -705,7 +705,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
_ => {} _ => {}
} }
} }
ast::ExprMethodCall(_, ident, _, ref args, _) => { ast::ExprMethodCall(_, ident, _, ref args) => {
// see above // see above
let t = ty::type_autoderef(ty::expr_ty(self.tcx, args[0])); let t = ty::type_autoderef(ty::expr_ty(self.tcx, args[0]));
match ty::get(t).sty { match ty::get(t).sty {

View File

@ -5221,7 +5221,7 @@ impl Resolver {
let traits = self.search_for_traits_containing_method(ident); let traits = self.search_for_traits_containing_method(ident);
self.trait_map.insert(expr.id, @RefCell::new(traits)); self.trait_map.insert(expr.id, @RefCell::new(traits));
} }
ExprMethodCall(_, ident, _, _, _) => { ExprMethodCall(_, ident, _, _) => {
debug!("(recording candidate traits for expr) recording \ debug!("(recording candidate traits for expr) recording \
traits for {}", traits for {}",
expr.id); expr.id);

View File

@ -647,7 +647,7 @@ fn const_expr_unadjusted(cx: @CrateContext, e: &ast::Expr,
} }
} }
} }
ast::ExprCall(callee, ref args, _) => { ast::ExprCall(callee, ref args) => {
let tcx = cx.tcx; let tcx = cx.tcx;
let opt_def = { let opt_def = {
let def_map = tcx.def_map.borrow(); let def_map = tcx.def_map.borrow();

View File

@ -2624,7 +2624,7 @@ fn populate_scope_map(cx: &CrateContext,
}) })
} }
ast::ExprCall(fn_exp, ref args, _) => { ast::ExprCall(fn_exp, ref args) => {
walk_expr(cx, fn_exp, scope_stack, scope_map); walk_expr(cx, fn_exp, scope_stack, scope_map);
for arg_exp in args.iter() { for arg_exp in args.iter() {
@ -2632,7 +2632,7 @@ fn populate_scope_map(cx: &CrateContext,
} }
} }
ast::ExprMethodCall(node_id, _, _, ref args, _) => { ast::ExprMethodCall(node_id, _, _, ref args) => {
scope_map.insert(node_id, scope_stack.last().unwrap().scope_metadata); scope_map.insert(node_id, scope_stack.last().unwrap().scope_metadata);
for arg_exp in args.iter() { for arg_exp in args.iter() {

View File

@ -777,11 +777,11 @@ fn trans_rvalue_dps_unadjusted<'a>(bcx: &'a Block<'a>,
expr_to_str(expr), expr_ty.repr(tcx)); expr_to_str(expr), expr_ty.repr(tcx));
closure::trans_expr_fn(bcx, sigil, decl, body, expr.id, dest) closure::trans_expr_fn(bcx, sigil, decl, body, expr.id, dest)
} }
ast::ExprCall(f, ref args, _) => { ast::ExprCall(f, ref args) => {
callee::trans_call(bcx, expr, f, callee::trans_call(bcx, expr, f,
callee::ArgExprs(*args), expr.id, dest) callee::ArgExprs(*args), expr.id, dest)
} }
ast::ExprMethodCall(callee_id, _, _, ref args, _) => { ast::ExprMethodCall(callee_id, _, _, ref args) => {
callee::trans_method_call(bcx, expr, callee_id, args[0], callee::trans_method_call(bcx, expr, callee_id, args[0],
callee::ArgExprs(*args), dest) callee::ArgExprs(*args), dest)
} }

View File

@ -1592,22 +1592,20 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
method_fn_ty: ty::t, method_fn_ty: ty::t,
callee_expr: &ast::Expr, callee_expr: &ast::Expr,
args: &[@ast::Expr], args: &[@ast::Expr],
sugar: ast::CallSugar, deref_args: DerefArgs) -> ty::t {
deref_args: DerefArgs) -> ty::t
{
// HACK(eddyb) ignore provided self (it has special typeck rules). // HACK(eddyb) ignore provided self (it has special typeck rules).
let args = args.slice_from(1); let args = args.slice_from(1);
if ty::type_is_error(method_fn_ty) { if ty::type_is_error(method_fn_ty) {
let err_inputs = err_args(args.len()); let err_inputs = err_args(args.len());
check_argument_types(fcx, sp, err_inputs, callee_expr, check_argument_types(fcx, sp, err_inputs, callee_expr,
args, sugar, deref_args, false); args, deref_args, false);
method_fn_ty method_fn_ty
} else { } else {
match ty::get(method_fn_ty).sty { match ty::get(method_fn_ty).sty {
ty::ty_bare_fn(ref fty) => { ty::ty_bare_fn(ref fty) => {
// HACK(eddyb) ignore self in the definition (see above). // HACK(eddyb) ignore self in the definition (see above).
check_argument_types(fcx, sp, fty.sig.inputs.slice_from(1), check_argument_types(fcx, sp, fty.sig.inputs.slice_from(1),
callee_expr, args, sugar, deref_args, callee_expr, args, deref_args,
fty.sig.variadic); fty.sig.variadic);
fty.sig.output fty.sig.output
} }
@ -1625,7 +1623,6 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
fn_inputs: &[ty::t], fn_inputs: &[ty::t],
callee_expr: &ast::Expr, callee_expr: &ast::Expr,
args: &[@ast::Expr], args: &[@ast::Expr],
sugar: ast::CallSugar,
deref_args: DerefArgs, deref_args: DerefArgs,
variadic: bool) { variadic: bool) {
/*! /*!
@ -1659,18 +1656,12 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
err_args(supplied_arg_count) err_args(supplied_arg_count)
} }
} else { } else {
let suffix = match sugar {
ast::NoSugar => "",
ast::ForSugar => " (including the closure passed by \
the `for` keyword)"
};
let msg = format!( let msg = format!(
"this function takes {} parameter{} \ "this function takes {} parameter{} \
but {} parameter{} supplied{}", but {} parameter{} supplied",
expected_arg_count, if expected_arg_count == 1 {""} else {"s"}, expected_arg_count, if expected_arg_count == 1 {""} else {"s"},
supplied_arg_count, supplied_arg_count,
if supplied_arg_count == 1 {" was"} else {"s were"}, if supplied_arg_count == 1 {" was"} else {"s were"});
suffix);
tcx.sess.span_err(sp, msg); tcx.sess.span_err(sp, msg);
@ -1783,24 +1774,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// The callee checks for bot / err, we don't need to // The callee checks for bot / err, we don't need to
} }
fn write_call(fcx: @FnCtxt, fn write_call(fcx: @FnCtxt, call_expr: &ast::Expr, output: ty::t) {
call_expr: &ast::Expr, fcx.write_ty(call_expr.id, output);
output: ty::t,
sugar: ast::CallSugar) {
let ret_ty = match sugar {
ast::ForSugar => {
match ty::get(output).sty {
ty::ty_bool => {}
_ => fcx.type_error_message(call_expr.span, |actual| {
format!("expected `for` closure to return `bool`, \
but found `{}`", actual) },
output, None)
}
ty::mk_nil()
}
_ => output
};
fcx.write_ty(call_expr.id, ret_ty);
} }
// A generic function for doing all of the checking for call expressions // A generic function for doing all of the checking for call expressions
@ -1808,8 +1783,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
callee_id: ast::NodeId, callee_id: ast::NodeId,
call_expr: &ast::Expr, call_expr: &ast::Expr,
f: &ast::Expr, f: &ast::Expr,
args: &[@ast::Expr], args: &[@ast::Expr]) {
sugar: ast::CallSugar) {
// Index expressions need to be handled separately, to inform them // Index expressions need to be handled separately, to inform them
// that they appear in call position. // that they appear in call position.
check_expr(fcx, f); check_expr(fcx, f);
@ -1857,9 +1831,9 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// Call the generic checker. // Call the generic checker.
check_argument_types(fcx, call_expr.span, fn_sig.inputs, f, check_argument_types(fcx, call_expr.span, fn_sig.inputs, f,
args, sugar, DontDerefArgs, fn_sig.variadic); args, DontDerefArgs, fn_sig.variadic);
write_call(fcx, call_expr, fn_sig.output, sugar); write_call(fcx, call_expr, fn_sig.output);
} }
// Checks a method call. // Checks a method call.
@ -1868,8 +1842,7 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
expr: &ast::Expr, expr: &ast::Expr,
method_name: ast::Ident, method_name: ast::Ident,
args: &[@ast::Expr], args: &[@ast::Expr],
tps: &[ast::P<ast::Ty>], tps: &[ast::P<ast::Ty>]) {
sugar: ast::CallSugar) {
let rcvr = args[0]; let rcvr = args[0];
check_expr(fcx, rcvr); check_expr(fcx, rcvr);
@ -1915,10 +1888,10 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// Call the generic checker. // Call the generic checker.
let fn_ty = fcx.node_ty(callee_id); let fn_ty = fcx.node_ty(callee_id);
let ret_ty = check_method_argument_types(fcx, expr.span, let ret_ty = check_method_argument_types(fcx, expr.span,
fn_ty, expr, args, sugar, fn_ty, expr, args,
DontDerefArgs); DontDerefArgs);
write_call(fcx, expr, ret_ty, sugar); write_call(fcx, expr, ret_ty);
} }
// A generic function for checking the then and else in an if // A generic function for checking the then and else in an if
@ -1985,8 +1958,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
method_map.get().insert(op_ex.id, *origin); method_map.get().insert(op_ex.id, *origin);
} }
check_method_argument_types(fcx, op_ex.span, check_method_argument_types(fcx, op_ex.span,
method_ty, op_ex, args, method_ty, op_ex,
ast::NoSugar, deref_args) args, deref_args)
} }
_ => { _ => {
unbound_method(); unbound_method();
@ -1994,8 +1967,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
// so we get all the error messages // so we get all the error messages
let expected_ty = ty::mk_err(); let expected_ty = ty::mk_err();
check_method_argument_types(fcx, op_ex.span, check_method_argument_types(fcx, op_ex.span,
expected_ty, op_ex, args, expected_ty, op_ex,
ast::NoSugar, deref_args); args, deref_args);
ty::mk_err() ty::mk_err()
} }
} }
@ -2948,8 +2921,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
check_block_with_expected(fcx, b, expected); check_block_with_expected(fcx, b, expected);
fcx.write_ty(id, fcx.node_ty(b.id)); fcx.write_ty(id, fcx.node_ty(b.id));
} }
ast::ExprCall(f, ref args, sugar) => { ast::ExprCall(f, ref args) => {
check_call(fcx, expr.id, expr, f, *args, sugar); check_call(fcx, expr.id, expr, f, *args);
let f_ty = fcx.expr_ty(f); let f_ty = fcx.expr_ty(f);
let (args_bot, args_err) = args.iter().fold((false, false), let (args_bot, args_err) = args.iter().fold((false, false),
|(rest_bot, rest_err), a| { |(rest_bot, rest_err), a| {
@ -2964,8 +2937,8 @@ pub fn check_expr_with_unifier(fcx: @FnCtxt,
fcx.write_bot(id); fcx.write_bot(id);
} }
} }
ast::ExprMethodCall(callee_id, ident, ref tps, ref args, sugar) => { ast::ExprMethodCall(callee_id, ident, ref tps, ref args) => {
check_method_call(fcx, callee_id, expr, ident, *args, *tps, sugar); check_method_call(fcx, callee_id, expr, ident, *args, *tps);
let arg_tys = args.map(|a| fcx.expr_ty(*a)); let arg_tys = args.map(|a| fcx.expr_ty(*a));
let (args_bot, args_err) = arg_tys.iter().fold((false, false), let (args_bot, args_err) = arg_tys.iter().fold((false, false),
|(rest_bot, rest_err), a| { |(rest_bot, rest_err), a| {

View File

@ -432,14 +432,14 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
} }
match expr.node { match expr.node {
ast::ExprCall(callee, ref args, _) => { ast::ExprCall(callee, ref args) => {
constrain_callee(rcx, callee.id, expr, callee); constrain_callee(rcx, callee.id, expr, callee);
constrain_call(rcx, callee.id, expr, None, *args, false); constrain_call(rcx, callee.id, expr, None, *args, false);
visit::walk_expr(rcx, expr, ()); visit::walk_expr(rcx, expr, ());
} }
ast::ExprMethodCall(callee_id, _, _, ref args, _) => { ast::ExprMethodCall(callee_id, _, _, ref args) => {
constrain_call(rcx, callee_id, expr, Some(args[0]), constrain_call(rcx, callee_id, expr, Some(args[0]),
args.slice_from(1), false); args.slice_from(1), false);

View File

@ -702,7 +702,7 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: @FnCtxt, is_early: bool) {
ast::ExprUnary(callee_id, _, _) | ast::ExprUnary(callee_id, _, _) |
ast::ExprAssignOp(callee_id, _, _, _) | ast::ExprAssignOp(callee_id, _, _, _) |
ast::ExprIndex(callee_id, _, _) | ast::ExprIndex(callee_id, _, _) |
ast::ExprMethodCall(callee_id, _, _, _, _) => { ast::ExprMethodCall(callee_id, _, _, _) => {
match ty::method_call_type_param_defs(cx.tcx, fcx.inh.method_map, ex.id) { match ty::method_call_type_param_defs(cx.tcx, fcx.inh.method_map, ex.id) {
Some(type_param_defs) => { Some(type_param_defs) => {
debug!("vtable resolution on parameter bounds for method call {}", debug!("vtable resolution on parameter bounds for method call {}",

View File

@ -307,7 +307,7 @@ fn visit_expr(e: &ast::Expr, wbcx: &mut WbCtxt) {
maybe_resolve_type_vars_for_node(wbcx, e.span, callee_id); maybe_resolve_type_vars_for_node(wbcx, e.span, callee_id);
} }
ast::ExprMethodCall(callee_id, _, _, _, _) => { ast::ExprMethodCall(callee_id, _, _, _) => {
// We must always have written in a callee ID type for these. // We must always have written in a callee ID type for these.
resolve_type_vars_for_node(wbcx, e.span, callee_id); resolve_type_vars_for_node(wbcx, e.span, callee_id);
} }

View File

@ -519,7 +519,7 @@ pub struct Expr {
impl Expr { impl Expr {
pub fn get_callee_id(&self) -> Option<NodeId> { pub fn get_callee_id(&self) -> Option<NodeId> {
match self.node { match self.node {
ExprMethodCall(callee_id, _, _, _, _) | ExprMethodCall(callee_id, _, _, _) |
ExprIndex(callee_id, _, _) | ExprIndex(callee_id, _, _) |
ExprBinary(callee_id, _, _, _) | ExprBinary(callee_id, _, _, _) |
ExprAssignOp(callee_id, _, _, _) | ExprAssignOp(callee_id, _, _, _) |
@ -529,20 +529,14 @@ impl Expr {
} }
} }
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum CallSugar {
NoSugar,
ForSugar
}
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)] #[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum Expr_ { pub enum Expr_ {
ExprVstore(@Expr, ExprVstore), ExprVstore(@Expr, ExprVstore),
// First expr is the place; second expr is the value. // First expr is the place; second expr is the value.
ExprBox(@Expr, @Expr), ExprBox(@Expr, @Expr),
ExprVec(~[@Expr], Mutability), ExprVec(~[@Expr], Mutability),
ExprCall(@Expr, ~[@Expr], CallSugar), ExprCall(@Expr, ~[@Expr]),
ExprMethodCall(NodeId, Ident, ~[P<Ty>], ~[@Expr], CallSugar), ExprMethodCall(NodeId, Ident, ~[P<Ty>], ~[@Expr]),
ExprTup(~[@Expr]), ExprTup(~[@Expr]),
ExprBinary(NodeId, BinOp, @Expr, @Expr), ExprBinary(NodeId, BinOp, @Expr, @Expr),
ExprUnary(NodeId, UnOp, @Expr), ExprUnary(NodeId, UnOp, @Expr),

View File

@ -525,11 +525,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} }
fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr { fn expr_call(&self, span: Span, expr: @ast::Expr, args: ~[@ast::Expr]) -> @ast::Expr {
self.expr(span, ast::ExprCall(expr, args, ast::NoSugar)) self.expr(span, ast::ExprCall(expr, args))
} }
fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr { fn expr_call_ident(&self, span: Span, id: ast::Ident, args: ~[@ast::Expr]) -> @ast::Expr {
self.expr(span, self.expr(span, ast::ExprCall(self.expr_ident(span, id), args))
ast::ExprCall(self.expr_ident(span, id), args, ast::NoSugar))
} }
fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident], fn expr_call_global(&self, sp: Span, fn_path: ~[ast::Ident],
args: ~[@ast::Expr]) -> @ast::Expr { args: ~[@ast::Expr]) -> @ast::Expr {
@ -541,7 +540,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
ident: ast::Ident, ident: ast::Ident,
mut args: ~[@ast::Expr]) -> @ast::Expr { mut args: ~[@ast::Expr]) -> @ast::Expr {
args.unshift(expr); args.unshift(expr);
self.expr(span, ast::ExprMethodCall(ast::DUMMY_NODE_ID, ident, ~[], args, ast::NoSugar)) self.expr(span, ast::ExprMethodCall(ast::DUMMY_NODE_ID, ident, ~[], args))
} }
fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr { fn expr_block(&self, b: P<ast::Block>) -> @ast::Expr {
self.expr(b.span, ast::ExprBlock(b)) self.expr(b.span, ast::ExprBlock(b))

View File

@ -727,19 +727,16 @@ pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr {
ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count), mutt) ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count), mutt)
} }
ExprTup(ref elts) => ExprTup(elts.map(|x| folder.fold_expr(*x))), ExprTup(ref elts) => ExprTup(elts.map(|x| folder.fold_expr(*x))),
ExprCall(f, ref args, blk) => { ExprCall(f, ref args) => {
ExprCall(folder.fold_expr(f), ExprCall(folder.fold_expr(f),
args.map(|&x| folder.fold_expr(x)), args.map(|&x| folder.fold_expr(x)))
blk)
} }
ExprMethodCall(callee_id, i, ref tps, ref args, blk) => { ExprMethodCall(callee_id, i, ref tps, ref args) => {
ExprMethodCall( ExprMethodCall(
folder.new_id(callee_id), folder.new_id(callee_id),
folder.fold_ident(i), folder.fold_ident(i),
tps.map(|&x| folder.fold_ty(x)), tps.map(|&x| folder.fold_ty(x)),
args.map(|&x| folder.fold_expr(x)), args.map(|&x| folder.fold_expr(x)))
blk
)
} }
ExprBinary(callee_id, binop, lhs, rhs) => { ExprBinary(callee_id, binop, lhs, rhs) => {
ExprBinary(folder.new_id(callee_id), ExprBinary(folder.new_id(callee_id),

View File

@ -23,15 +23,13 @@ use ast;
// isn't parsed as (if true {...} else {...} | x) | 5 // isn't parsed as (if true {...} else {...} | x) | 5
pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool { pub fn expr_requires_semi_to_be_stmt(e: @ast::Expr) -> bool {
match e.node { match e.node {
ast::ExprIf(..) ast::ExprIf(..)
| ast::ExprMatch(..) | ast::ExprMatch(..)
| ast::ExprBlock(_) | ast::ExprBlock(_)
| ast::ExprWhile(..) | ast::ExprWhile(..)
| ast::ExprLoop(..) | ast::ExprLoop(..)
| ast::ExprForLoop(..) | ast::ExprForLoop(..) => false,
| ast::ExprCall(_, _, ast::ForSugar) _ => true
| ast::ExprMethodCall(_, _, _, _, ast::ForSugar) => false,
_ => true
} }
} }

View File

@ -13,7 +13,6 @@
use abi; use abi;
use abi::AbiSet; use abi::AbiSet;
use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil}; use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil};
use ast::{CallSugar, NoSugar};
use ast::{BareFnTy, ClosureTy}; use ast::{BareFnTy, ClosureTy};
use ast::{RegionTyParamBound, TraitTyParamBound}; use ast::{RegionTyParamBound, TraitTyParamBound};
use ast::{Provided, Public, Purity}; use ast::{Provided, Public, Purity};
@ -1690,13 +1689,12 @@ impl Parser {
ExprBinary(ast::DUMMY_NODE_ID, binop, lhs, rhs) ExprBinary(ast::DUMMY_NODE_ID, binop, lhs, rhs)
} }
pub fn mk_call(&mut self, f: @Expr, args: ~[@Expr], sugar: CallSugar) -> ast::Expr_ { pub fn mk_call(&mut self, f: @Expr, args: ~[@Expr]) -> ast::Expr_ {
ExprCall(f, args, sugar) ExprCall(f, args)
} }
fn mk_method_call(&mut self, ident: Ident, tps: ~[P<Ty>], args: ~[@Expr], fn mk_method_call(&mut self, ident: Ident, tps: ~[P<Ty>], args: ~[@Expr]) -> ast::Expr_ {
sugar: CallSugar) -> ast::Expr_ { ExprMethodCall(ast::DUMMY_NODE_ID, ident, tps, args)
ExprMethodCall(ast::DUMMY_NODE_ID, ident, tps, args, sugar)
} }
pub fn mk_index(&mut self, expr: @Expr, idx: @Expr) -> ast::Expr_ { pub fn mk_index(&mut self, expr: @Expr, idx: @Expr) -> ast::Expr_ {
@ -1997,7 +1995,7 @@ impl Parser {
hi = self.last_span.hi; hi = self.last_span.hi;
es.unshift(e); es.unshift(e);
let nd = self.mk_method_call(i, tys, es, NoSugar); let nd = self.mk_method_call(i, tys, es);
e = self.mk_expr(lo, hi, nd); e = self.mk_expr(lo, hi, nd);
} }
_ => { _ => {
@ -2022,7 +2020,7 @@ impl Parser {
); );
hi = self.last_span.hi; hi = self.last_span.hi;
let nd = self.mk_call(e, es, NoSugar); let nd = self.mk_call(e, es);
e = self.mk_expr(lo, hi, nd); e = self.mk_expr(lo, hi, nd);
} }

View File

@ -1141,33 +1141,10 @@ pub fn print_expr_vstore(s: &mut State, t: ast::ExprVstore) -> io::IoResult<()>
} }
} }
pub fn print_call_pre(s: &mut State, fn print_call_post(s: &mut State, args: &[@ast::Expr]) -> io::IoResult<()> {
sugar: ast::CallSugar, if_ok!(popen(s));
base_args: &mut ~[@ast::Expr]) if_ok!(commasep_exprs(s, Inconsistent, args));
-> io::IoResult<Option<@ast::Expr>> { if_ok!(pclose(s));
match sugar {
ast::ForSugar => {
if_ok!(head(s, "for"));
Ok(Some(base_args.pop().unwrap()))
}
ast::NoSugar => Ok(None)
}
}
pub fn print_call_post(s: &mut State,
sugar: ast::CallSugar,
blk: &Option<@ast::Expr>,
base_args: &mut ~[@ast::Expr]) -> io::IoResult<()> {
if sugar == ast::NoSugar || !base_args.is_empty() {
if_ok!(popen(s));
if_ok!(commasep_exprs(s, Inconsistent, *base_args));
if_ok!(pclose(s));
}
if sugar != ast::NoSugar {
if_ok!(nbsp(s));
// not sure if this can happen
if_ok!(print_expr(s, blk.unwrap()));
}
Ok(()) Ok(())
} }
@ -1254,15 +1231,12 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> {
} }
if_ok!(pclose(s)); if_ok!(pclose(s));
} }
ast::ExprCall(func, ref args, sugar) => { ast::ExprCall(func, ref args) => {
let mut base_args = (*args).clone();
let blk = if_ok!(print_call_pre(s, sugar, &mut base_args));
if_ok!(print_expr(s, func)); if_ok!(print_expr(s, func));
if_ok!(print_call_post(s, sugar, &blk, &mut base_args)); if_ok!(print_call_post(s, *args));
} }
ast::ExprMethodCall(_, ident, ref tys, ref args, sugar) => { ast::ExprMethodCall(_, ident, ref tys, ref args) => {
let mut base_args = args.slice_from(1).to_owned(); let base_args = args.slice_from(1);
let blk = if_ok!(print_call_pre(s, sugar, &mut base_args));
if_ok!(print_expr(s, args[0])); if_ok!(print_expr(s, args[0]));
if_ok!(word(&mut s.s, ".")); if_ok!(word(&mut s.s, "."));
if_ok!(print_ident(s, ident)); if_ok!(print_ident(s, ident));
@ -1271,7 +1245,7 @@ pub fn print_expr(s: &mut State, expr: &ast::Expr) -> io::IoResult<()> {
if_ok!(commasep(s, Inconsistent, *tys, print_type_ref)); if_ok!(commasep(s, Inconsistent, *tys, print_type_ref));
if_ok!(word(&mut s.s, ">")); if_ok!(word(&mut s.s, ">"));
} }
if_ok!(print_call_post(s, sugar, &blk, &mut base_args)); if_ok!(print_call_post(s, base_args));
} }
ast::ExprBinary(_, op, lhs, rhs) => { ast::ExprBinary(_, op, lhs, rhs) => {
if_ok!(print_expr(s, lhs)); if_ok!(print_expr(s, lhs));

View File

@ -652,13 +652,13 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en
visitor.visit_expr(*subexpression, env.clone()) visitor.visit_expr(*subexpression, env.clone())
} }
} }
ExprCall(callee_expression, ref arguments, _) => { ExprCall(callee_expression, ref arguments) => {
for argument in arguments.iter() { for argument in arguments.iter() {
visitor.visit_expr(*argument, env.clone()) visitor.visit_expr(*argument, env.clone())
} }
visitor.visit_expr(callee_expression, env.clone()) visitor.visit_expr(callee_expression, env.clone())
} }
ExprMethodCall(_, _, ref types, ref arguments, _) => { ExprMethodCall(_, _, ref types, ref arguments) => {
walk_exprs(visitor, *arguments, env.clone()); walk_exprs(visitor, *arguments, env.clone());
for &typ in types.iter() { for &typ in types.iter() {
visitor.visit_ty(typ, env.clone()) visitor.visit_ty(typ, env.clone())