about summary refs log tree commit diff
path: root/src/libsyntax/fold.rs
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-10-29 06:03:32 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-11-08 19:42:46 -0500
commit1f4faaee401f8681e25afbcf3b6296b6cd2ca55a (patch)
treef0dac4e7f58ebab635c4bba59a04fca2833db4a8 /src/libsyntax/fold.rs
parent85c51d3b02e421e2ab99c330e0d8212293f64f04 (diff)
downloadrust-1f4faaee401f8681e25afbcf3b6296b6cd2ca55a.tar.gz
rust-1f4faaee401f8681e25afbcf3b6296b6cd2ca55a.zip
Generalize AST and ty::Generics to accept multiple lifetimes.
Diffstat (limited to 'src/libsyntax/fold.rs')
-rw-r--r--src/libsyntax/fold.rs35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 388de29b456..ea0ab95a451 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -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),
     }