提交 4a133640 编写于 作者: S Seo Sanghyeon

Remove obsolete mutability from ast::Ty

上级 9eb89a6c
......@@ -282,6 +282,12 @@ pub fn ast_path_to_ty<AC:AstConv,RS:RegionScope>(
pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t {
fn ast_ty_to_mt<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, ty: &ast::Ty) -> ty::mt {
ty::mt {ty: ast_ty_to_ty(this, rscope, ty), mutbl: ast::MutImmutable}
}
fn ast_mt_to_mt<AC:AstConv, RS:RegionScope>(
this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt {
......@@ -303,8 +309,8 @@ fn mk_pointer<AC:AstConv,
debug!("mk_pointer(vst={:?})", vst);
match a_seq_ty.ty.node {
ast::ty_vec(ref mt) => {
let mut mt = ast_mt_to_mt(this, rscope, mt);
ast::ty_vec(ty) => {
let mut mt = ast_ty_to_mt(this, rscope, ty);
if a_seq_ty.mutbl == ast::MutMutable {
mt = ty::mt { ty: mt.ty, mutbl: a_seq_ty.mutbl };
}
......@@ -394,14 +400,15 @@ fn check_path_args(tcx: ty::ctxt,
mk_pointer(this, rscope, mt, ty::vstore_box,
|tmt| ty::mk_box(tcx, tmt))
}
ast::ty_uniq(ref mt) => {
mk_pointer(this, rscope, mt, ty::vstore_uniq,
ast::ty_uniq(ty) => {
let mt = ast::mt { ty: ty, mutbl: ast::MutImmutable };
mk_pointer(this, rscope, &mt, ty::vstore_uniq,
|tmt| ty::mk_uniq(tcx, tmt))
}
ast::ty_vec(ref mt) => {
ast::ty_vec(ty) => {
tcx.sess.span_err(ast_ty.span, "bare `[]` is not a type");
// return /something/ so they can at least get more errors
ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, mt), ty::vstore_uniq)
ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty), ty::vstore_uniq)
}
ast::ty_ptr(ref mt) => {
ty::mk_ptr(tcx, ast_mt_to_mt(this, rscope, mt))
......@@ -532,15 +539,15 @@ fn check_path_args(tcx: ty::ctxt,
}
}
}
ast::ty_fixed_length_vec(ref a_mt, e) => {
ast::ty_fixed_length_vec(ty, e) => {
match const_eval::eval_const_expr_partial(&tcx, e) {
Ok(ref r) => {
match *r {
const_eval::const_int(i) =>
ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, a_mt),
ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty),
ty::vstore_fixed(i as uint)),
const_eval::const_uint(i) =>
ty::mk_evec(tcx, ast_mt_to_mt(this, rscope, a_mt),
ty::mk_evec(tcx, ast_ty_to_mt(this, rscope, ty),
ty::vstore_fixed(i as uint)),
_ => {
tcx.sess.span_fatal(
......
......@@ -621,10 +621,10 @@ fn clean(&self) -> Type {
BorrowedRef {lifetime: l.clean(), mutability: m.mutbl.clean(),
type_: ~m.ty.clean()},
ty_box(ref m) => Managed(m.mutbl.clean(), ~m.ty.clean()),
ty_uniq(ref m) => Unique(~m.ty.clean()),
ty_vec(ref m) => Vector(~m.ty.clean()),
ty_fixed_length_vec(ref m, ref e) => FixedVector(~m.ty.clean(),
e.span.to_src()),
ty_uniq(ty) => Unique(~ty.clean()),
ty_vec(ty) => Vector(~ty.clean()),
ty_fixed_length_vec(ty, ref e) => FixedVector(~ty.clean(),
e.span.to_src()),
ty_tup(ref tys) => Tuple(tys.iter().map(|x| x.clean()).collect()),
ty_path(ref p, ref tpbs, id) =>
resolve_type(p.clean(), tpbs.clean(), id),
......
......@@ -875,9 +875,9 @@ pub enum ty_ {
ty_nil,
ty_bot, /* bottom type */
ty_box(mt),
ty_uniq(mt),
ty_vec(mt),
ty_fixed_length_vec(mt, @Expr),
ty_uniq(P<Ty>),
ty_vec(P<Ty>),
ty_fixed_length_vec(P<Ty>, @Expr),
ty_ptr(mt),
ty_rptr(Option<Lifetime>, mt),
ty_closure(@TyClosure),
......
......@@ -312,7 +312,7 @@ fn ty_rptr(&self,
ast::ty_rptr(lifetime, self.ty_mt(ty, mutbl)))
}
fn ty_uniq(&self, span: Span, ty: P<ast::Ty>) -> P<ast::Ty> {
self.ty(span, ast::ty_uniq(self.ty_mt(ty, ast::MutImmutable)))
self.ty(span, ast::ty_uniq(ty))
}
fn ty_box(&self, span: Span,
ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> {
......
......@@ -593,7 +593,7 @@ fn to_expr(&self, extra: @ast::Expr) -> @ast::Expr {
~[]
), None);
let ty = ast::ty_fixed_length_vec(
self.ecx.ty_mt(piece_ty, ast::MutImmutable),
piece_ty,
self.ecx.expr_uint(self.fmtsp, self.pieces.len())
);
let ty = self.ecx.ty(self.fmtsp, ty);
......
......@@ -241,8 +241,8 @@ fn fold_ty(&self, t: P<Ty>) -> P<Ty> {
let node = match t.node {
ty_nil | ty_bot | ty_infer => t.node.clone(),
ty_box(ref mt) => ty_box(fold_mt(mt, self)),
ty_uniq(ref mt) => ty_uniq(fold_mt(mt, self)),
ty_vec(ref mt) => ty_vec(fold_mt(mt, self)),
ty_uniq(ty) => ty_uniq(self.fold_ty(ty)),
ty_vec(ty) => ty_vec(self.fold_ty(ty)),
ty_ptr(ref mt) => ty_ptr(fold_mt(mt, self)),
ty_rptr(ref region, ref mt) => {
ty_rptr(fold_opt_lifetime(region, self), fold_mt(mt, self))
......@@ -272,8 +272,8 @@ fn fold_ty(&self, t: P<Ty>) -> P<Ty> {
fold_opt_bounds(bounds, self),
self.new_id(id))
}
ty_fixed_length_vec(ref mt, e) => {
ty_fixed_length_vec(fold_mt(mt, self), self.fold_expr(e))
ty_fixed_length_vec(ty, e) => {
ty_fixed_length_vec(self.fold_ty(ty), self.fold_expr(e))
}
ty_typeof(expr) => ty_typeof(self.fold_expr(expr)),
};
......
......@@ -1213,11 +1213,11 @@ pub fn parse_ty(&self, _: bool) -> P<Ty> {
} else if *self.token == token::AT {
// MANAGED POINTER
self.bump();
self.parse_box_or_uniq_pointee(ManagedSigil, ty_box)
self.parse_box_or_uniq_pointee(ManagedSigil)
} else if *self.token == token::TILDE {
// OWNED POINTER
self.bump();
self.parse_box_or_uniq_pointee(OwnedSigil, ty_uniq)
self.parse_box_or_uniq_pointee(OwnedSigil)
} else if *self.token == token::BINOP(token::STAR) {
// STAR POINTER (bare pointer?)
self.bump();
......@@ -1225,13 +1225,13 @@ pub fn parse_ty(&self, _: bool) -> P<Ty> {
} else if *self.token == token::LBRACKET {
// VECTOR
self.expect(&token::LBRACKET);
let mt = mt { ty: self.parse_ty(false), mutbl: MutImmutable };
let t = self.parse_ty(false);
// Parse the `, ..e` in `[ int, ..e ]`
// where `e` is a const expression
let t = match self.maybe_parse_fixed_vstore() {
None => ty_vec(mt),
Some(suffix) => ty_fixed_length_vec(mt, suffix)
None => ty_vec(t),
Some(suffix) => ty_fixed_length_vec(t, suffix)
};
self.expect(&token::RBRACKET);
t
......@@ -1284,8 +1284,7 @@ pub fn parse_ty(&self, _: bool) -> P<Ty> {
// parse the type following a @ or a ~
pub fn parse_box_or_uniq_pointee(&self,
sigil: ast::Sigil,
ctor: |v: mt| -> ty_)
sigil: ast::Sigil)
-> ty_ {
// ~'foo fn() or ~fn() are parsed directly as obsolete fn types:
match *self.token {
......@@ -1309,9 +1308,9 @@ pub fn parse_box_or_uniq_pointee(&self,
// rather than boxed ptrs. But the special casing of str/vec is not
// reflected in the AST type.
if sigil == OwnedSigil {
ctor(mt { ty: self.parse_ty(false), mutbl: MutImmutable })
ty_uniq(self.parse_ty(false))
} else {
ctor(self.parse_mt())
ty_box(self.parse_mt())
}
}
......
......@@ -401,14 +401,10 @@ pub fn print_type(s: @ps, ty: &ast::Ty) {
ast::ty_nil => word(s.s, "()"),
ast::ty_bot => word(s.s, "!"),
ast::ty_box(ref mt) => { word(s.s, "@"); print_mt(s, mt); }
ast::ty_uniq(ref mt) => { word(s.s, "~"); print_mt(s, mt); }
ast::ty_vec(ref mt) => {
ast::ty_uniq(ty) => { word(s.s, "~"); print_type(s, ty); }
ast::ty_vec(ty) => {
word(s.s, "[");
match mt.mutbl {
ast::MutMutable => word_space(s, "mut"),
ast::MutImmutable => ()
}
print_type(s, mt.ty);
print_type(s, ty);
word(s.s, "]");
}
ast::ty_ptr(ref mt) => { word(s.s, "*"); print_mt(s, mt); }
......@@ -444,13 +440,9 @@ pub fn print_type(s: @ps, ty: &ast::Ty) {
Some(&generics), None);
}
ast::ty_path(ref path, ref bounds, _) => print_bounded_path(s, path, bounds),
ast::ty_fixed_length_vec(ref mt, v) => {
ast::ty_fixed_length_vec(ty, v) => {
word(s.s, "[");
match mt.mutbl {
ast::MutMutable => word_space(s, "mut"),
ast::MutImmutable => ()
}
print_type(s, mt.ty);
print_type(s, ty);
word(s.s, ", ..");
print_expr(s, v);
word(s.s, "]");
......
......@@ -298,8 +298,10 @@ pub fn skip_ty<E, V:Visitor<E>>(_: &mut V, _: &Ty, _: E) {
pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
match typ.node {
ty_box(ref mutable_type) | ty_uniq(ref mutable_type) |
ty_vec(ref mutable_type) | ty_ptr(ref mutable_type) => {
ty_uniq(ty) | ty_vec(ty) => {
visitor.visit_ty(ty, env)
}
ty_box(ref mutable_type) | ty_ptr(ref mutable_type) => {
visitor.visit_ty(mutable_type.ty, env)
}
ty_rptr(ref lifetime, ref mutable_type) => {
......@@ -340,8 +342,8 @@ pub fn walk_ty<E:Clone, V:Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
walk_ty_param_bounds(visitor, bounds, env.clone())
}
}
ty_fixed_length_vec(ref mutable_type, expression) => {
visitor.visit_ty(mutable_type.ty, env.clone());
ty_fixed_length_vec(ty, expression) => {
visitor.visit_ty(ty, env.clone());
visitor.visit_expr(expression, env)
}
ty_typeof(expression) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册