Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
syntax: remove ast::Sigil.
  • Loading branch information
eddyb committed Apr 11, 2014
1 parent 65abf96 commit 0ac5326
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 78 deletions.
22 changes: 2 additions & 20 deletions src/libsyntax/ast.rs
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions src/libsyntax/fold.rs
Expand Up @@ -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),
Expand Down
32 changes: 6 additions & 26 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
48 changes: 21 additions & 27 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand All @@ -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"));
Expand All @@ -2062,15 +2070,15 @@ 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());
}

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 {
Expand Down Expand Up @@ -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, "")));

Expand All @@ -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<()> {
Expand Down
15 changes: 13 additions & 2 deletions src/libsyntax/visit.rs
Expand Up @@ -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())
}
Expand All @@ -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())
Expand Down

0 comments on commit 0ac5326

Please sign in to comment.