Generalize AST and ty::Generics to accept multiple lifetimes.

This commit is contained in:
Niko Matsakis
2013-10-29 06:03:32 -04:00
parent 85c51d3b02
commit 1f4faaee40
52 changed files with 1510 additions and 1454 deletions

View File

@@ -144,7 +144,7 @@ pub trait ast_fold {
ident: self.fold_ident(m.ident),
attrs: m.attrs.map(|a| fold_attribute_(*a, self)),
generics: fold_generics(&m.generics, self),
explicit_self: m.explicit_self,
explicit_self: self.fold_explicit_self(&m.explicit_self),
purity: m.purity,
decl: fold_fn_decl(&m.decl, self),
body: self.fold_block(&m.body),
@@ -245,12 +245,14 @@ pub trait ast_fold {
ty_uniq(ref mt) => ty_uniq(fold_mt(mt, self)),
ty_vec(ref mt) => ty_vec(fold_mt(mt, self)),
ty_ptr(ref mt) => ty_ptr(fold_mt(mt, self)),
ty_rptr(region, ref mt) => ty_rptr(region, fold_mt(mt, self)),
ty_rptr(ref region, ref mt) => {
ty_rptr(fold_opt_lifetime(region, self), fold_mt(mt, self))
}
ty_closure(ref f) => {
ty_closure(@TyClosure {
sigil: f.sigil,
purity: f.purity,
region: f.region,
region: fold_opt_lifetime(&f.region, self),
onceness: f.onceness,
bounds: fold_opt_bounds(&f.bounds, self),
decl: fold_fn_decl(&f.decl, self),
@@ -349,7 +351,7 @@ pub trait ast_fold {
global: p.global,
segments: p.segments.map(|segment| ast::PathSegment {
identifier: self.fold_ident(segment.identifier),
lifetime: segment.lifetime,
lifetimes: segment.lifetimes.map(|l| fold_lifetime(l, self)),
types: segment.types.map(|typ| self.fold_ty(typ)),
})
}
@@ -389,6 +391,24 @@ pub trait ast_fold {
fn new_span(&self, sp: Span) -> Span {
sp
}
fn fold_explicit_self(&self, es: &explicit_self) -> explicit_self {
Spanned {
span: self.new_span(es.span),
node: self.fold_explicit_self_(&es.node)
}
}
fn fold_explicit_self_(&self, es: &explicit_self_) -> explicit_self_ {
match *es {
sty_static | sty_value(_) | sty_uniq(_) | sty_box(_) => {
*es
}
sty_region(ref lifetime, m) => {
sty_region(fold_opt_lifetime(lifetime, self), m)
}
}
}
}
/* some little folds that probably aren't useful to have in ast_fold itself*/
@@ -505,6 +525,11 @@ pub fn fold_lifetimes<T:ast_fold>(lts: &OptVec<Lifetime>, fld: &T)
lts.map(|l| fold_lifetime(l, fld))
}
pub fn fold_opt_lifetime<T:ast_fold>(o_lt: &Option<Lifetime>, fld: &T)
-> Option<Lifetime> {
o_lt.as_ref().map(|lt| fold_lifetime(lt, fld))
}
pub fn fold_generics<T:ast_fold>(generics: &Generics, fld: &T) -> Generics {
Generics {ty_params: fold_ty_params(&generics.ty_params, fld),
lifetimes: fold_lifetimes(&generics.lifetimes, fld)}
@@ -675,7 +700,7 @@ pub fn noop_fold_type_method<T:ast_fold>(m: &TypeMethod, fld: &T)
purity: m.purity,
decl: fold_fn_decl(&m.decl, fld),
generics: fold_generics(&m.generics, fld),
explicit_self: m.explicit_self,
explicit_self: fld.fold_explicit_self(&m.explicit_self),
id: fld.new_id(m.id),
span: fld.new_span(m.span),
}