syntax: remove ast::Sigil.
This commit is contained in:
parent
65abf96fb6
commit
0ac532686f
|
@ -359,23 +359,6 @@ pub enum Mutability {
|
|||
MutImmutable,
|
||||
}
|
||||
|
||||
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
|
||||
pub enum Sigil {
|
||||
BorrowedSigil,
|
||||
OwnedSigil,
|
||||
ManagedSigil
|
||||
}
|
||||
|
||||
impl fmt::Show for Sigil {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
BorrowedSigil => "&".fmt(f),
|
||||
OwnedSigil => "~".fmt(f),
|
||||
ManagedSigil => "@".fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
|
||||
pub enum ExprVstore {
|
||||
ExprVstoreUniq, // ~[1,2,3,4]
|
||||
|
@ -791,8 +774,6 @@ impl fmt::Show for Onceness {
|
|||
|
||||
#[deriving(Eq, TotalEq, Encodable, Decodable, Hash)]
|
||||
pub struct ClosureTy {
|
||||
pub sigil: Sigil,
|
||||
pub region: Option<Lifetime>,
|
||||
pub lifetimes: Vec<Lifetime>,
|
||||
pub fn_style: FnStyle,
|
||||
pub onceness: Onceness,
|
||||
|
@ -822,7 +803,8 @@ pub enum Ty_ {
|
|||
TyFixedLengthVec(P<Ty>, @Expr),
|
||||
TyPtr(MutTy),
|
||||
TyRptr(Option<Lifetime>, MutTy),
|
||||
TyClosure(@ClosureTy),
|
||||
TyClosure(@ClosureTy, Option<Lifetime>),
|
||||
TyProc(@ClosureTy),
|
||||
TyBareFn(@BareFnTy),
|
||||
TyTup(Vec<P<Ty>> ),
|
||||
TyPath(Path, Option<OwnedSlice<TyParamBound>>, NodeId), // for #7264; see above
|
||||
|
|
|
@ -155,11 +155,18 @@ pub trait Folder {
|
|||
TyRptr(ref region, ref mt) => {
|
||||
TyRptr(fold_opt_lifetime(region, self), fold_mt(mt, self))
|
||||
}
|
||||
TyClosure(ref f) => {
|
||||
TyClosure(ref f, ref region) => {
|
||||
TyClosure(@ClosureTy {
|
||||
sigil: f.sigil,
|
||||
fn_style: f.fn_style,
|
||||
region: fold_opt_lifetime(&f.region, self),
|
||||
onceness: f.onceness,
|
||||
bounds: fold_opt_bounds(&f.bounds, self),
|
||||
decl: self.fold_fn_decl(f.decl),
|
||||
lifetimes: f.lifetimes.iter().map(|l| fold_lifetime(l, self)).collect(),
|
||||
}, fold_opt_lifetime(region, self))
|
||||
}
|
||||
TyProc(ref f) => {
|
||||
TyProc(@ClosureTy {
|
||||
fn_style: f.fn_style,
|
||||
onceness: f.onceness,
|
||||
bounds: fold_opt_bounds(&f.bounds, self),
|
||||
decl: self.fold_fn_decl(f.decl),
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#![macro_escape]
|
||||
|
||||
use abi;
|
||||
use ast::{Sigil, BorrowedSigil, ManagedSigil, OwnedSigil};
|
||||
use ast::{BareFnTy, ClosureTy};
|
||||
use ast::{RegionTyParamBound, TraitTyParamBound};
|
||||
use ast::{Provided, Public, FnStyle};
|
||||
|
@ -49,8 +48,8 @@ use ast::StrStyle;
|
|||
use ast::{SelfRegion, SelfStatic, SelfUniq, SelfValue};
|
||||
use ast::{TokenTree, TraitMethod, TraitRef, TTDelim, TTSeq, TTTok};
|
||||
use ast::{TTNonterminal, TupleVariantKind, Ty, Ty_, TyBot, TyBox};
|
||||
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyBareFn, TyTypeof};
|
||||
use ast::{TyInfer, TypeMethod};
|
||||
use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn};
|
||||
use ast::{TyTypeof, TyInfer, TypeMethod};
|
||||
use ast::{TyNil, TyParam, TyParamBound, TyPath, TyPtr, TyRptr};
|
||||
use ast::{TyTup, TyU32, TyUniq, TyVec, UnUniq};
|
||||
use ast::{UnnamedField, UnsafeBlock, UnsafeFn, ViewItem};
|
||||
|
@ -923,9 +922,7 @@ impl<'a> Parser<'a> {
|
|||
cf: ret_style,
|
||||
variadic: variadic
|
||||
});
|
||||
TyClosure(@ClosureTy {
|
||||
sigil: OwnedSigil,
|
||||
region: None,
|
||||
TyProc(@ClosureTy {
|
||||
fn_style: NormalFn,
|
||||
onceness: Once,
|
||||
bounds: bounds,
|
||||
|
@ -984,14 +981,12 @@ impl<'a> Parser<'a> {
|
|||
});
|
||||
|
||||
TyClosure(@ClosureTy {
|
||||
sigil: BorrowedSigil,
|
||||
region: region,
|
||||
fn_style: fn_style,
|
||||
onceness: onceness,
|
||||
bounds: bounds,
|
||||
decl: decl,
|
||||
lifetimes: lifetimes,
|
||||
})
|
||||
}, region)
|
||||
}
|
||||
|
||||
pub fn parse_unsafety(&mut self) -> FnStyle {
|
||||
|
@ -1201,11 +1196,11 @@ impl<'a> Parser<'a> {
|
|||
} else if self.token == token::AT {
|
||||
// MANAGED POINTER
|
||||
self.bump();
|
||||
self.parse_box_or_uniq_pointee(ManagedSigil)
|
||||
TyBox(self.parse_ty(false))
|
||||
} else if self.token == token::TILDE {
|
||||
// OWNED POINTER
|
||||
self.bump();
|
||||
self.parse_box_or_uniq_pointee(OwnedSigil)
|
||||
TyUniq(self.parse_ty(false))
|
||||
} else if self.token == token::BINOP(token::STAR) {
|
||||
// STAR POINTER (bare pointer?)
|
||||
self.bump();
|
||||
|
@ -1271,21 +1266,6 @@ impl<'a> Parser<'a> {
|
|||
P(Ty {id: ast::DUMMY_NODE_ID, node: t, span: sp})
|
||||
}
|
||||
|
||||
// parse the type following a @ or a ~
|
||||
pub fn parse_box_or_uniq_pointee(&mut self,
|
||||
sigil: ast::Sigil)
|
||||
-> Ty_ {
|
||||
// other things are parsed as @/~ + a type. Note that constructs like
|
||||
// ~[] and ~str will be resolved during typeck to slices and so forth,
|
||||
// rather than boxed ptrs. But the special casing of str/vec is not
|
||||
// reflected in the AST type.
|
||||
if sigil == OwnedSigil {
|
||||
TyUniq(self.parse_ty(false))
|
||||
} else {
|
||||
TyBox(self.parse_ty(false))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_borrowed_pointee(&mut self) -> Ty_ {
|
||||
// look for `&'lt` or `&'foo ` and interpret `foo` as the region name:
|
||||
let opt_lifetime = self.parse_opt_lifetime();
|
||||
|
|
|
@ -483,14 +483,23 @@ impl<'a> State<'a> {
|
|||
f.fn_style, ast::Many, f.decl, None, &None,
|
||||
Some(&generics), None));
|
||||
}
|
||||
ast::TyClosure(f) => {
|
||||
ast::TyClosure(f, ref region) => {
|
||||
let generics = ast::Generics {
|
||||
lifetimes: f.lifetimes.clone(),
|
||||
ty_params: OwnedSlice::empty()
|
||||
};
|
||||
try!(self.print_ty_fn(None, Some(f.sigil), &f.region,
|
||||
f.fn_style, f.onceness, f.decl, None, &f.bounds,
|
||||
Some(&generics), None));
|
||||
try!(self.print_ty_fn(None, Some('&'), region, f.fn_style,
|
||||
f.onceness, f.decl, None, &f.bounds,
|
||||
Some(&generics), None));
|
||||
}
|
||||
ast::TyProc(f) => {
|
||||
let generics = ast::Generics {
|
||||
lifetimes: f.lifetimes.clone(),
|
||||
ty_params: OwnedSlice::empty()
|
||||
};
|
||||
try!(self.print_ty_fn(None, Some('~'), &None, f.fn_style,
|
||||
f.onceness, f.decl, None, &f.bounds,
|
||||
Some(&generics), None));
|
||||
}
|
||||
ast::TyPath(ref path, ref bounds, _) => {
|
||||
try!(self.print_bounded_path(path, bounds));
|
||||
|
@ -1716,8 +1725,7 @@ impl<'a> State<'a> {
|
|||
opt_explicit_self: Option<ast::ExplicitSelf_>,
|
||||
vis: ast::Visibility) -> IoResult<()> {
|
||||
try!(self.head(""));
|
||||
try!(self.print_fn_header_info(opt_explicit_self, fn_style, abi,
|
||||
ast::Many, None, vis));
|
||||
try!(self.print_fn_header_info(opt_explicit_self, fn_style, abi, vis));
|
||||
try!(self.nbsp());
|
||||
try!(self.print_ident(name));
|
||||
try!(self.print_generics(generics));
|
||||
|
@ -2023,7 +2031,7 @@ impl<'a> State<'a> {
|
|||
|
||||
pub fn print_ty_fn(&mut self,
|
||||
opt_abi: Option<abi::Abi>,
|
||||
opt_sigil: Option<ast::Sigil>,
|
||||
opt_sigil: Option<char>,
|
||||
opt_region: &Option<ast::Lifetime>,
|
||||
fn_style: ast::FnStyle,
|
||||
onceness: ast::Onceness,
|
||||
|
@ -2037,15 +2045,15 @@ impl<'a> State<'a> {
|
|||
|
||||
// Duplicates the logic in `print_fn_header_info()`. This is because that
|
||||
// function prints the sigil in the wrong place. That should be fixed.
|
||||
if opt_sigil == Some(ast::OwnedSigil) && onceness == ast::Once {
|
||||
if opt_sigil == Some('~') && onceness == ast::Once {
|
||||
try!(word(&mut self.s, "proc"));
|
||||
} else if opt_sigil == Some(ast::BorrowedSigil) {
|
||||
} else if opt_sigil == Some('&') {
|
||||
try!(self.print_extern_opt_abi(opt_abi));
|
||||
try!(self.print_fn_style(fn_style));
|
||||
try!(self.print_onceness(onceness));
|
||||
} else {
|
||||
assert!(opt_sigil.is_none());
|
||||
try!(self.print_opt_abi_and_extern_if_nondefault(opt_abi));
|
||||
try!(self.print_opt_sigil(opt_sigil));
|
||||
try!(self.print_fn_style(fn_style));
|
||||
try!(self.print_onceness(onceness));
|
||||
try!(word(&mut self.s, "fn"));
|
||||
|
@ -2062,7 +2070,7 @@ impl<'a> State<'a> {
|
|||
match generics { Some(g) => try!(self.print_generics(g)), _ => () }
|
||||
try!(zerobreak(&mut self.s));
|
||||
|
||||
if opt_sigil == Some(ast::BorrowedSigil) {
|
||||
if opt_sigil == Some('&') {
|
||||
try!(word(&mut self.s, "|"));
|
||||
} else {
|
||||
try!(self.popen());
|
||||
|
@ -2070,7 +2078,7 @@ impl<'a> State<'a> {
|
|||
|
||||
try!(self.print_fn_args(decl, opt_explicit_self));
|
||||
|
||||
if opt_sigil == Some(ast::BorrowedSigil) {
|
||||
if opt_sigil == Some('&') {
|
||||
try!(word(&mut self.s, "|"));
|
||||
} else {
|
||||
if decl.variadic {
|
||||
|
@ -2327,22 +2335,10 @@ impl<'a> State<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn print_opt_sigil(&mut self,
|
||||
opt_sigil: Option<ast::Sigil>) -> IoResult<()> {
|
||||
match opt_sigil {
|
||||
Some(ast::BorrowedSigil) => word(&mut self.s, "&"),
|
||||
Some(ast::OwnedSigil) => word(&mut self.s, "~"),
|
||||
Some(ast::ManagedSigil) => word(&mut self.s, "@"),
|
||||
None => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_fn_header_info(&mut self,
|
||||
_opt_explicit_self: Option<ast::ExplicitSelf_>,
|
||||
opt_fn_style: Option<ast::FnStyle>,
|
||||
abi: abi::Abi,
|
||||
onceness: ast::Onceness,
|
||||
opt_sigil: Option<ast::Sigil>,
|
||||
vis: ast::Visibility) -> IoResult<()> {
|
||||
try!(word(&mut self.s, visibility_qualified(vis, "")));
|
||||
|
||||
|
@ -2357,9 +2353,7 @@ impl<'a> State<'a> {
|
|||
try!(self.print_opt_fn_style(opt_fn_style));
|
||||
}
|
||||
|
||||
try!(self.print_onceness(onceness));
|
||||
try!(word(&mut self.s, "fn"));
|
||||
self.print_opt_sigil(opt_sigil)
|
||||
word(&mut self.s, "fn")
|
||||
}
|
||||
|
||||
pub fn print_fn_style(&mut self, s: ast::FnStyle) -> IoResult<()> {
|
||||
|
|
|
@ -328,7 +328,7 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
|||
visitor.visit_ty(tuple_element_type, env.clone())
|
||||
}
|
||||
}
|
||||
TyClosure(ref function_declaration) => {
|
||||
TyClosure(ref function_declaration, ref region) => {
|
||||
for argument in function_declaration.decl.inputs.iter() {
|
||||
visitor.visit_ty(argument.ty, env.clone())
|
||||
}
|
||||
|
@ -338,11 +338,22 @@ pub fn walk_ty<E: Clone, V: Visitor<E>>(visitor: &mut V, typ: &Ty, env: E) {
|
|||
}
|
||||
visitor.visit_opt_lifetime_ref(
|
||||
typ.span,
|
||||
&function_declaration.region,
|
||||
region,
|
||||
env.clone());
|
||||
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
|
||||
env.clone());
|
||||
}
|
||||
TyProc(ref function_declaration) => {
|
||||
for argument in function_declaration.decl.inputs.iter() {
|
||||
visitor.visit_ty(argument.ty, env.clone())
|
||||
}
|
||||
visitor.visit_ty(function_declaration.decl.output, env.clone());
|
||||
for bounds in function_declaration.bounds.iter() {
|
||||
walk_ty_param_bounds(visitor, bounds, env.clone())
|
||||
}
|
||||
walk_lifetime_decls(visitor, &function_declaration.lifetimes,
|
||||
env.clone());
|
||||
}
|
||||
TyBareFn(ref function_declaration) => {
|
||||
for argument in function_declaration.decl.inputs.iter() {
|
||||
visitor.visit_ty(argument.ty, env.clone())
|
||||
|
|
Loading…
Reference in New Issue