提交 5aee3e01 编写于 作者: M Michael Woerister

De-spanned<T> and renamed ast::field (now ast::Field)

上级 4bd14246
......@@ -374,7 +374,7 @@ fn expr(&mut self, expr: @ast::expr, pred: CFGIndex) -> CFGIndex {
ast::expr_struct(_, ref fields, base) => {
let base_exit = self.opt_expr(base, pred);
let field_exprs: ~[@ast::expr] =
fields.iter().transform(|f| f.node.expr).collect();
fields.iter().transform(|f| f.expr).collect();
self.straightline(expr, base_exit, field_exprs)
}
......
......@@ -117,7 +117,7 @@ pub fn classify(e: &expr,
ast::expr_struct(_, ref fs, None) => {
let cs = do fs.iter().transform |f| {
classify(f.node.expr, tcx)
classify(f.expr, tcx)
};
join_all(cs)
}
......
......@@ -705,7 +705,7 @@ fn walk_expr(&mut self,
ast::expr_struct(_, ref fields, with_expr) => {
for fields.iter().advance |field| {
self.walk_expr(field.node.expr, in_out, loop_scopes);
self.walk_expr(field.expr, in_out, loop_scopes);
}
self.walk_opt_expr(with_expr, in_out, loop_scopes);
}
......
......@@ -1161,7 +1161,7 @@ pub fn propagate_through_expr(&self, expr: @expr, succ: LiveNode)
expr_struct(_, ref fields, with_expr) => {
let succ = self.propagate_through_opt_expr(with_expr, succ);
do fields.rev_iter().fold(succ) |succ, field| {
self.propagate_through_expr(field.node.expr, succ)
self.propagate_through_expr(field.expr, succ)
}
}
......
......@@ -394,7 +394,7 @@ pub fn use_expr(&self,
expr_struct(_, ref fields, opt_with) => {
for fields.iter().advance |field| {
self.consume_expr(field.node.expr, visitor);
self.consume_expr(field.expr, visitor);
}
for opt_with.iter().advance |with_expr| {
......@@ -417,7 +417,7 @@ pub fn use_expr(&self,
// specified and (2) have a type that
// moves-by-default:
let consume_with = with_fields.iter().any(|tf| {
!fields.iter().any(|f| f.node.ident == tf.ident) &&
!fields.iter().any(|f| f.ident == tf.ident) &&
ty::type_moves_by_default(self.tcx, tf.mt.ty)
});
......
......@@ -413,9 +413,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
Some(ref entry) => {
debug!("(privacy checking) checking \
impl method");
check_method(expr.span,
&entry.origin,
ident);
check_method(expr.span, &entry.origin, ident);
}
}
}
......@@ -433,8 +431,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
for (*fields).iter().advance |field| {
debug!("(privacy checking) checking \
field in struct literal");
check_field(expr.span, id,
field.node.ident);
check_field(expr.span, id, field.ident);
}
}
}
......@@ -448,8 +445,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
checking field in \
struct variant \
literal");
check_field(expr.span, variant_id,
field.node.ident);
check_field(expr.span, variant_id, field.ident);
}
}
_ => {
......@@ -499,8 +495,7 @@ struct variant \
for fields.iter().advance |field| {
debug!("(privacy checking) checking \
struct pattern");
check_field(pattern.span, id,
field.ident);
check_field(pattern.span, id, field.ident);
}
}
}
......@@ -513,9 +508,7 @@ struct variant \
debug!("(privacy checking) \
checking field in \
struct variant pattern");
check_field(pattern.span,
variant_id,
field.ident);
check_field(pattern.span, variant_id, field.ident);
}
}
_ => {
......
......@@ -488,8 +488,8 @@ fn const_expr_unadjusted(cx: @mut CrateContext, e: &ast::expr) -> ValueRef {
do expr::with_field_tys(tcx, ety, Some(e.id))
|discr, field_tys| {
let cs = field_tys.map(|field_ty| {
match fs.iter().find_(|f| field_ty.ident == f.node.ident) {
Some(f) => const_expr(cx, (*f).node.expr),
match fs.iter().find_(|f| field_ty.ident == f.ident) {
Some(f) => const_expr(cx, (*f).expr),
None => {
cx.tcx.sess.span_bug(e.span, "missing struct field");
}
......
......@@ -1124,7 +1124,7 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
}
fn trans_rec_or_struct(bcx: block,
fields: &[ast::field],
fields: &[ast::Field],
base: Option<@ast::expr>,
expr_span: codemap::span,
id: ast::node_id,
......@@ -1139,11 +1139,11 @@ fn trans_rec_or_struct(bcx: block,
let mut need_base = vec::from_elem(field_tys.len(), true);
let numbered_fields = do fields.map |field| {
let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.node.ident);
let opt_pos = field_tys.iter().position(|field_ty| field_ty.ident == field.ident);
match opt_pos {
Some(i) => {
need_base[i] = false;
(i, field.node.expr)
(i, field.expr)
}
None => {
tcx.sess.span_bug(field.span,
......
......@@ -1872,7 +1872,7 @@ fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
node_id: ast::node_id,
substitutions: ty::substs,
field_types: &[ty::field_ty],
ast_fields: &[ast::field],
ast_fields: &[ast::Field],
check_completeness: bool) {
let tcx = fcx.ccx.tcx;
......@@ -1888,21 +1888,21 @@ fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
for ast_fields.iter().advance |field| {
let mut expected_field_type = ty::mk_err();
let pair = class_field_map.find(&field.node.ident).
let pair = class_field_map.find(&field.ident).
map_consume(|x| *x);
match pair {
None => {
tcx.sess.span_err(
field.span,
fmt!("structure has no field named `%s`",
tcx.sess.str_of(field.node.ident)));
tcx.sess.str_of(field.ident)));
error_happened = true;
}
Some((_, true)) => {
tcx.sess.span_err(
field.span,
fmt!("field `%s` specified more than once",
tcx.sess.str_of(field.node.ident)));
tcx.sess.str_of(field.ident)));
error_happened = true;
}
Some((field_id, false)) => {
......@@ -1910,7 +1910,7 @@ fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
ty::lookup_field_type(
tcx, class_id, field_id, &substitutions);
class_field_map.insert(
field.node.ident, (field_id, true));
field.ident, (field_id, true));
fields_found += 1;
}
}
......@@ -1918,7 +1918,7 @@ fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
// an error, so we can continue typechecking
check_expr_coercable_to_type(
fcx,
field.node.expr,
field.expr,
expected_field_type);
}
......@@ -1961,7 +1961,7 @@ fn check_struct_constructor(fcx: @mut FnCtxt,
id: ast::node_id,
span: codemap::span,
class_id: ast::def_id,
fields: &[ast::field],
fields: &[ast::Field],
base_expr: Option<@ast::expr>) {
let tcx = fcx.ccx.tcx;
......@@ -2051,7 +2051,7 @@ fn check_struct_enum_variant(fcx: @mut FnCtxt,
span: codemap::span,
enum_id: ast::def_id,
variant_id: ast::def_id,
fields: &[ast::field]) {
fields: &[ast::Field]) {
let tcx = fcx.ccx.tcx;
// Look up the number of type parameters and the raw type, and
......
......@@ -54,10 +54,10 @@ pub fn indenter() -> _indenter {
_indenter(())
}
pub fn field_expr(f: ast::field) -> @ast::expr { return f.node.expr; }
pub fn field_expr(f: ast::Field) -> @ast::expr { return f.expr; }
pub fn field_exprs(fields: ~[ast::field]) -> ~[@ast::expr] {
fields.map(|f| f.node.expr)
pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::expr] {
fields.map(|f| f.expr)
}
// Takes a predicate p, returns true iff p is true for any subexpressions
......
......@@ -409,13 +409,12 @@ pub struct arm {
}
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub struct field_ {
pub struct Field {
ident: ident,
expr: @expr,
span: span,
}
pub type field = spanned<field_>;
#[deriving(Clone, Eq, Encodable, Decodable, IterBytes)]
pub enum blk_check_mode {
default_blk,
......@@ -495,7 +494,7 @@ pub enum expr_ {
expr_mac(mac),
// A struct literal expression.
expr_struct(Path, ~[field], Option<@expr>),
expr_struct(Path, ~[Field], Option<@expr>),
// A vector literal constructed from one repeated element.
expr_repeat(@expr /* element */, @expr /* count */, mutability),
......
......@@ -107,9 +107,9 @@ fn expr_method_call(&self, span: span,
args: ~[@ast::expr]) -> @ast::expr;
fn expr_blk(&self, b: ast::Block) -> @ast::expr;
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field;
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr;
fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::field]) -> @ast::expr;
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field;
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::Field]) -> @ast::expr;
fn expr_struct_ident(&self, span: span, id: ast::ident, fields: ~[ast::Field]) -> @ast::expr;
fn expr_lit(&self, sp: span, lit: ast::lit_) -> @ast::expr;
......@@ -477,14 +477,14 @@ fn expr_method_call(&self, span: span,
fn expr_blk(&self, b: ast::Block) -> @ast::expr {
self.expr(b.span, ast::expr_block(b))
}
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::field {
respan(span, ast::field_ { ident: name, expr: e })
fn field_imm(&self, span: span, name: ident, e: @ast::expr) -> ast::Field {
ast::Field { ident: name, expr: e, span: span }
}
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::field]) -> @ast::expr {
fn expr_struct(&self, span: span, path: ast::Path, fields: ~[ast::Field]) -> @ast::expr {
self.expr(span, ast::expr_struct(path, fields, None))
}
fn expr_struct_ident(&self, span: span,
id: ast::ident, fields: ~[ast::field]) -> @ast::expr {
id: ast::ident, fields: ~[ast::Field]) -> @ast::expr {
self.expr_struct(span, self.path_ident(span, id), fields)
}
......
......@@ -488,12 +488,10 @@ pub fn wrap<T>(f: @fn(&T, @ast_fold) -> T)
}
pub fn noop_fold_expr(e: &expr_, fld: @ast_fold) -> expr_ {
fn fold_field_(field: field, fld: @ast_fold) -> field {
spanned {
node: ast::field_ {
ident: fld.fold_ident(field.node.ident),
expr: fld.fold_expr(field.node.expr),
},
fn fold_field_(field: Field, fld: @ast_fold) -> Field {
ast::Field {
ident: fld.fold_ident(field.ident),
expr: fld.fold_expr(field.expr),
span: fld.new_span(field.span),
}
}
......
......@@ -29,7 +29,7 @@
use ast::{expr_ret, expr_self, expr_struct, expr_tup, expr_unary};
use ast::{expr_vec, expr_vstore, expr_vstore_mut_box};
use ast::{expr_vstore_slice, expr_vstore_box};
use ast::{expr_vstore_mut_slice, expr_while, extern_fn, field, fn_decl};
use ast::{expr_vstore_mut_slice, expr_while, extern_fn, Field, fn_decl};
use ast::{expr_vstore_uniq, Onceness, Once, Many};
use ast::{foreign_item, foreign_item_static, foreign_item_fn, foreign_mod};
use ast::{ident, impure_fn, inherited, item, item_, item_static};
......@@ -1498,15 +1498,16 @@ pub fn parse_mutability(&self) -> mutability {
}
// parse ident COLON expr
pub fn parse_field(&self) -> field {
pub fn parse_field(&self) -> Field {
let lo = self.span.lo;
let i = self.parse_ident();
self.expect(&token::COLON);
let e = self.parse_expr();
spanned(lo, e.span.hi, ast::field_ {
ast::Field {
ident: i,
expr: e
})
expr: e,
span: mk_sp(lo, e.span.hi),
}
}
pub fn mk_expr(&self, lo: BytePos, hi: BytePos, node: expr_) -> @expr {
......
......@@ -1103,14 +1103,14 @@ pub fn print_call_post(s: @ps,
}
pub fn print_expr(s: @ps, expr: &ast::expr) {
fn print_field(s: @ps, field: &ast::field) {
fn print_field(s: @ps, field: &ast::Field) {
ibox(s, indent_unit);
print_ident(s, field.node.ident);
print_ident(s, field.ident);
word_space(s, ":");
print_expr(s, field.node.expr);
print_expr(s, field.expr);
end(s);
}
fn get_span(field: &ast::field) -> codemap::span { return field.span; }
fn get_span(field: &ast::Field) -> codemap::span { return field.span; }
maybe_print_comment(s, expr.span.lo);
ibox(s, indent_unit);
......
......@@ -474,7 +474,7 @@ pub fn visit_expr<E:Clone>(ex: @expr, (e, v): (E, vt<E>)) {
expr_struct(ref p, ref flds, base) => {
visit_path(p, (e.clone(), v));
for flds.iter().advance |f| {
(v.visit_expr)(f.node.expr, (e.clone(), v));
(v.visit_expr)(f.expr, (e.clone(), v));
}
visit_expr_opt(base, (e.clone(), v));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册