提交 ddeaea22 编写于 作者: P Patrick Walton

rustc: Change the address-of operator to an explicit production so that we can parse the mutability

上级 07227866
......@@ -1393,7 +1393,6 @@ fn serialize_81<S: std::serialization::serializer>(s: S,
/*syntax::ast::mutability*/
{||
alt v {
syntax::ast::box(v0) {
......@@ -1430,10 +1429,6 @@ fn serialize_81<S: std::serialization::serializer>(s: S,
syntax::ast::neg {
s.emit_enum_variant("syntax::ast::neg", 4u, 0u, {|| })
}
syntax::ast::addr_of {
s.emit_enum_variant("syntax::ast::addr_of", 5u, 0u,
{|| })
}
}
});
}
......@@ -2426,6 +2421,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
/*[@syntax::ast::ty]*/
/*@syntax::ast::expr*//*@syntax::ast::expr*/
/*@syntax::ast::path*/
/*syntax::ast::mutability*//*@syntax::ast::expr*/
/*core::option::t<@syntax::ast::expr>*/
......@@ -2893,8 +2889,26 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
}
})
}
syntax::ast::expr_addr_of(v0, v1) {
s.emit_enum_variant("syntax::ast::expr_addr_of", 25u,
2u,
{||
{
s.emit_enum_variant_arg(0u,
{||
serialize_33(s,
v0)
});
s.emit_enum_variant_arg(1u,
{||
serialize_71(s,
v1)
})
}
})
}
syntax::ast::expr_fail(v0) {
s.emit_enum_variant("syntax::ast::expr_fail", 25u, 1u,
s.emit_enum_variant("syntax::ast::expr_fail", 26u, 1u,
{||
{
s.emit_enum_variant_arg(0u,
......@@ -2906,15 +2920,15 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_break {
s.emit_enum_variant("syntax::ast::expr_break", 26u,
s.emit_enum_variant("syntax::ast::expr_break", 27u,
0u, {|| })
}
syntax::ast::expr_cont {
s.emit_enum_variant("syntax::ast::expr_cont", 27u, 0u,
s.emit_enum_variant("syntax::ast::expr_cont", 28u, 0u,
{|| })
}
syntax::ast::expr_ret(v0) {
s.emit_enum_variant("syntax::ast::expr_ret", 28u, 1u,
s.emit_enum_variant("syntax::ast::expr_ret", 29u, 1u,
{||
{
s.emit_enum_variant_arg(0u,
......@@ -2926,7 +2940,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_be(v0) {
s.emit_enum_variant("syntax::ast::expr_be", 29u, 1u,
s.emit_enum_variant("syntax::ast::expr_be", 30u, 1u,
{||
{
s.emit_enum_variant_arg(0u,
......@@ -2938,7 +2952,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_log(v0, v1, v2) {
s.emit_enum_variant("syntax::ast::expr_log", 30u, 3u,
s.emit_enum_variant("syntax::ast::expr_log", 31u, 3u,
{||
{
s.emit_enum_variant_arg(0u,
......@@ -2960,7 +2974,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_assert(v0) {
s.emit_enum_variant("syntax::ast::expr_assert", 31u,
s.emit_enum_variant("syntax::ast::expr_assert", 32u,
1u,
{||
{
......@@ -2973,7 +2987,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_check(v0, v1) {
s.emit_enum_variant("syntax::ast::expr_check", 32u,
s.emit_enum_variant("syntax::ast::expr_check", 33u,
2u,
{||
{
......@@ -2991,7 +3005,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_if_check(v0, v1, v2) {
s.emit_enum_variant("syntax::ast::expr_if_check", 33u,
s.emit_enum_variant("syntax::ast::expr_if_check", 34u,
3u,
{||
{
......@@ -3014,7 +3028,7 @@ fn serialize_73<S: std::serialization::serializer>(s: S,
})
}
syntax::ast::expr_mac(v0) {
s.emit_enum_variant("syntax::ast::expr_mac", 34u, 1u,
s.emit_enum_variant("syntax::ast::expr_mac", 35u, 1u,
{||
{
s.emit_enum_variant_arg(0u,
......@@ -5550,8 +5564,6 @@ fn deserialize_81<S: std::serialization::deserializer>(s: S) ->
{||
s.read_enum_variant({|v_id|
alt check v_id {
......@@ -5570,7 +5582,6 @@ fn deserialize_81<S: std::serialization::deserializer>(s: S) ->
2u { syntax::ast::deref }
3u { syntax::ast::not }
4u { syntax::ast::neg }
5u { syntax::ast::addr_of }
}
})
})
......@@ -6580,6 +6591,8 @@ fn deserialize_73<S: std::serialization::deserializer>(s: S) ->
/*@syntax::ast::path*/
/*syntax::ast::mutability*//*@syntax::ast::expr*/
/*core::option::t<@syntax::ast::expr>*/
......@@ -6870,26 +6883,36 @@ fn deserialize_73<S: std::serialization::deserializer>(s: S) ->
}))
}
25u {
syntax::ast::expr_addr_of(s.read_enum_variant_arg(0u,
{||
deserialize_33(s)
}),
s.read_enum_variant_arg(1u,
{||
deserialize_71(s)
}))
}
26u {
syntax::ast::expr_fail(s.read_enum_variant_arg(0u,
{||
deserialize_78(s)
}))
}
26u { syntax::ast::expr_break }
27u { syntax::ast::expr_cont }
28u {
27u { syntax::ast::expr_break }
28u { syntax::ast::expr_cont }
29u {
syntax::ast::expr_ret(s.read_enum_variant_arg(0u,
{||
deserialize_78(s)
}))
}
29u {
30u {
syntax::ast::expr_be(s.read_enum_variant_arg(0u,
{||
deserialize_71(s)
}))
}
30u {
31u {
syntax::ast::expr_log(s.read_enum_variant_arg(0u,
{||
deserialize_128(s)
......@@ -6903,13 +6926,13 @@ fn deserialize_73<S: std::serialization::deserializer>(s: S) ->
deserialize_71(s)
}))
}
31u {
32u {
syntax::ast::expr_assert(s.read_enum_variant_arg(0u,
{||
deserialize_71(s)
}))
}
32u {
33u {
syntax::ast::expr_check(s.read_enum_variant_arg(0u,
{||
deserialize_129(s)
......@@ -6919,7 +6942,7 @@ fn deserialize_73<S: std::serialization::deserializer>(s: S) ->
deserialize_71(s)
}))
}
33u {
34u {
syntax::ast::expr_if_check(s.read_enum_variant_arg(0u,
{||
deserialize_71(s)
......@@ -6933,7 +6956,7 @@ fn deserialize_73<S: std::serialization::deserializer>(s: S) ->
deserialize_78(s)
}))
}
34u {
35u {
syntax::ast::expr_mac(s.read_enum_variant_arg(0u,
{||
deserialize_68(s)
......@@ -8171,7 +8194,7 @@ fn serialize_164<S: std::serialization::serializer>(s: S,
s.emit_enum("syntax::ast::def",
/*syntax::ast::def_id*//*syntax::ast::purity*/
/*syntax::ast::def_id*/
/*syntax::ast::node_id*/
/*syntax::ast::def_id*/
/*syntax::ast::def_id*/
/*syntax::ast::def_id*/
......@@ -8534,7 +8557,7 @@ fn deserialize_164<S: std::serialization::deserializer>(s: S) ->
s.read_enum("syntax::ast::def",
/*syntax::ast::def_id*//*syntax::ast::purity*/
/*syntax::ast::def_id*/
/*syntax::ast::node_id*/
/*syntax::ast::def_id*/
......@@ -8985,7 +9008,7 @@ fn deserialize_syntax_ast_inlined_item<S: std::serialization::deserializer>(s:
deserialize_171(s)
}
/*[syntax::ast::node_id]*/
fn serialize_172<S: std::serialization::serializer>(s: S,
fn serialize_173<S: std::serialization::serializer>(s: S,
v:
[syntax::ast::node_id]) {
s.emit_vec(vec::len(v), /*syntax::ast::node_id*/
......@@ -8997,7 +9020,7 @@ fn serialize_172<S: std::serialization::serializer>(s: S,
});
}
/*middle::last_use::is_last_use*/
fn serialize_173<S: std::serialization::serializer>(s: S,
fn serialize_172<S: std::serialization::serializer>(s: S,
v:
middle::last_use::is_last_use) {
s.emit_enum("middle::last_use::is_last_use",
......@@ -9021,7 +9044,7 @@ fn serialize_173<S: std::serialization::serializer>(s: S,
{
s.emit_enum_variant_arg(0u,
{||
serialize_172(s,
serialize_173(s,
v0)
})
}
......@@ -9034,10 +9057,10 @@ fn serialize_middle_last_use_is_last_use<S: std::serialization::serializer>(s:
S,
v:
middle::last_use::is_last_use) {
serialize_173(s, v);
serialize_172(s, v);
}
/*[syntax::ast::node_id]*/
fn deserialize_172<S: std::serialization::deserializer>(s: S) ->
fn deserialize_173<S: std::serialization::deserializer>(s: S) ->
[syntax::ast::node_id] {
s.read_vec(
......@@ -9050,7 +9073,7 @@ fn deserialize_172<S: std::serialization::deserializer>(s: S) ->
})
}
/*middle::last_use::is_last_use*/
fn deserialize_173<S: std::serialization::deserializer>(s: S) ->
fn deserialize_172<S: std::serialization::deserializer>(s: S) ->
middle::last_use::is_last_use {
s.read_enum("middle::last_use::is_last_use",
......@@ -9070,7 +9093,7 @@ fn deserialize_173<S: std::serialization::deserializer>(s: S) ->
2u {
middle::last_use::closes_over(s.read_enum_variant_arg(0u,
{||
deserialize_172(s)
deserialize_173(s)
}))
}
}
......@@ -9080,5 +9103,5 @@ fn deserialize_173<S: std::serialization::deserializer>(s: S) ->
fn deserialize_middle_last_use_is_last_use<S: std::serialization::deserializer>(s:
S)
-> middle::last_use::is_last_use {
deserialize_173(s)
deserialize_172(s)
}
......@@ -1645,18 +1645,19 @@ fn trans_unary(bcx: block, op: ast::unop, e: @ast::expr,
translated using trans_lval(), not \
trans_unary()");
}
ast::addr_of {
// FIXME: This is wrong.
let {bcx, val, kind} = trans_temp_lval(bcx, e);
if kind != owned {
bcx.sess().span_bug(e.span,
"can't take the address of an rvalue");
}
ret store_in_dest(bcx, val, dest);
}
}
}
fn trans_addr_of(cx: block, e: @ast::expr, dest: dest) -> block {
// FIXME: This is wrong.
let {bcx, val, kind} = trans_temp_lval(cx, e);
if kind != owned {
bcx.sess().span_bug(e.span,
"can't take the address of an rvalue");
}
ret store_in_dest(bcx, val, dest);
}
fn trans_compare(cx: block, op: ast::binop, lhs: ValueRef,
_lhs_t: ty::t, rhs: ValueRef, rhs_t: ty::t) -> result {
if ty::type_is_scalar(rhs_t) {
......@@ -3151,6 +3152,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
assert op != ast::deref; // lvals are handled above
ret trans_unary(bcx, op, x, e, dest);
}
ast::expr_addr_of(_, x) { ret trans_addr_of(bcx, x, dest); }
ast::expr_fn(proto, decl, body, cap_clause) {
ret closure::trans_expr_fn(
bcx, proto, decl, body, e.span, e.id, *cap_clause, dest);
......@@ -4307,8 +4309,7 @@ fn trans_const_expr(cx: crate_ctxt, e: @ast::expr) -> ValueRef {
ret alt u {
ast::box(_) |
ast::uniq(_) |
ast::deref |
ast::addr_of { cx.sess.span_bug(e.span,
ast::deref { cx.sess.span_bug(e.span,
"bad unop type in trans_const_expr"); }
ast::not { llvm::LLVMConstNot(te) }
ast::neg {
......
......@@ -409,6 +409,10 @@ fn find_pre_post_expr(fcx: fn_ctxt, e: @expr) {
find_pre_post_expr(fcx, operand);
copy_pre_post(fcx.ccx, e.id, operand);
}
expr_addr_of(_, operand) {
find_pre_post_expr(fcx, operand);
copy_pre_post(fcx.ccx, e.id, operand);
}
expr_cast(operand, _) {
find_pre_post_expr(fcx, operand);
copy_pre_post(fcx.ccx, e.id, operand);
......
......@@ -587,6 +587,9 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
expr_unary(_, operand) {
ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
}
expr_addr_of(_, operand) {
ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
}
expr_cast(operand, _) {
ret find_pre_post_state_sub(fcx, pres, operand, e.id, none);
}
......
......@@ -2198,14 +2198,17 @@ fn check_user_unop(fcx: @fn_ctxt, op_str: str, mname: str,
oper_t = check_user_unop(fcx, "-", "unary-", expr, oper_t);
}
}
ast::addr_of {
// FIXME: This is incorrect. Infer the proper region.
let tm = { ty: oper_t, mutbl: ast::m_imm };
oper_t = ty::mk_rptr(tcx, ty::re_block(0), tm);
}
}
write_ty(tcx, id, oper_t);
}
ast::expr_addr_of(mutbl, oper) {
bot = check_expr(fcx, oper);
let oper_t = expr_ty(tcx, oper);
// FIXME: This is incorrect. Infer the proper region.
let tm = { ty: oper_t, mutbl: mutbl };
oper_t = ty::mk_rptr(tcx, ty::re_block(0), tm);
}
ast::expr_path(pth) {
let defn = lookup_def(fcx, pth.span, id);
......
......@@ -159,7 +159,7 @@ enum binop {
enum unop {
box(mutability),
uniq(mutability),
deref, not, neg, addr_of
deref, not, neg
}
// Generally, after typeck you can get the inferred value
......@@ -245,6 +245,7 @@ enum expr_ {
expr_field(@expr, ident, [@ty]),
expr_index(@expr, @expr),
expr_path(@path),
expr_addr_of(mutability, @expr),
expr_fail(option<@expr>),
expr_break,
expr_cont,
......
......@@ -402,6 +402,7 @@ fn fold_field_(field: field, fld: ast_fold) -> field {
expr_unary(binop, ohs) { expr_unary(binop, fld.fold_expr(ohs)) }
expr_lit(_) { e }
expr_cast(expr, ty) { expr_cast(fld.fold_expr(expr), ty) }
expr_addr_of(m, ohs) { expr_addr_of(m, fld.fold_expr(ohs)) }
expr_if(cond, tr, fl) {
expr_if(fld.fold_expr(cond), fld.fold_block(tr),
option::map(fl, fld.fold_expr))
......
......@@ -1129,9 +1129,10 @@ fn parse_prefix_expr(p: parser) -> pexpr {
}
token::AND {
p.bump();
let m = parse_mutability(p);
let e = to_expr(parse_prefix_expr(p));
hi = e.span.hi;
ex = ast::expr_unary(ast::addr_of, e);
ex = ast::expr_addr_of(m, e);
}
_ { ret parse_dot_or_call_expr(p); }
}
......
......@@ -877,6 +877,10 @@ fn print_opt(s: ps, expr: option<@ast::expr>) {
word(s.s, ast_util::unop_to_str(op));
print_op_maybe_parens(s, expr, parse::parser::unop_prec);
}
ast::expr_addr_of(m, expr) {
print_mutability(s, m);
print_expr(s, expr);
}
ast::expr_lit(lit) { print_literal(s, lit); }
ast::expr_cast(expr, ty) {
print_op_maybe_parens(s, expr, parse::parser::as_prec);
......
......@@ -331,6 +331,7 @@ fn visit_expr<E>(ex: @expr, e: E, v: vt<E>) {
expr_unary(_, a) { v.visit_expr(a, e, v); }
expr_lit(_) { }
expr_cast(x, t) { v.visit_expr(x, e, v); v.visit_ty(t, e, v); }
expr_addr_of(_, x) { v.visit_expr(x, e, v); }
expr_if(x, b, eo) {
v.visit_expr(x, e, v);
v.visit_block(b, e, v);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册