Generalize AST and ty::Generics to accept multiple lifetimes.
This commit is contained in:
parent
85c51d3b02
commit
1f4faaee40
52 changed files with 1510 additions and 1454 deletions
|
|
@ -38,7 +38,7 @@ pub trait AstBuilder {
|
|||
fn path_all(&self, sp: Span,
|
||||
global: bool,
|
||||
idents: ~[ast::Ident],
|
||||
rp: Option<ast::Lifetime>,
|
||||
lifetimes: OptVec<ast::Lifetime>,
|
||||
types: ~[ast::Ty])
|
||||
-> ast::Path;
|
||||
|
||||
|
|
@ -237,19 +237,19 @@ pub trait AstBuilder {
|
|||
|
||||
impl AstBuilder for @ExtCtxt {
|
||||
fn path(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
||||
self.path_all(span, false, strs, None, ~[])
|
||||
self.path_all(span, false, strs, opt_vec::Empty, ~[])
|
||||
}
|
||||
fn path_ident(&self, span: Span, id: ast::Ident) -> ast::Path {
|
||||
self.path(span, ~[id])
|
||||
}
|
||||
fn path_global(&self, span: Span, strs: ~[ast::Ident]) -> ast::Path {
|
||||
self.path_all(span, true, strs, None, ~[])
|
||||
self.path_all(span, true, strs, opt_vec::Empty, ~[])
|
||||
}
|
||||
fn path_all(&self,
|
||||
sp: Span,
|
||||
global: bool,
|
||||
mut idents: ~[ast::Ident],
|
||||
rp: Option<ast::Lifetime>,
|
||||
lifetimes: OptVec<ast::Lifetime>,
|
||||
types: ~[ast::Ty])
|
||||
-> ast::Path {
|
||||
let last_identifier = idents.pop();
|
||||
|
|
@ -257,13 +257,13 @@ impl AstBuilder for @ExtCtxt {
|
|||
.map(|ident| {
|
||||
ast::PathSegment {
|
||||
identifier: ident,
|
||||
lifetime: None,
|
||||
lifetimes: opt_vec::Empty,
|
||||
types: opt_vec::Empty,
|
||||
}
|
||||
}).collect();
|
||||
segments.push(ast::PathSegment {
|
||||
identifier: last_identifier,
|
||||
lifetime: rp,
|
||||
lifetimes: lifetimes,
|
||||
types: opt_vec::from(types),
|
||||
});
|
||||
ast::Path {
|
||||
|
|
@ -327,7 +327,7 @@ impl AstBuilder for @ExtCtxt {
|
|||
self.ident_of("option"),
|
||||
self.ident_of("Option")
|
||||
],
|
||||
None,
|
||||
opt_vec::Empty,
|
||||
~[ ty ]), None)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
segments: ~[
|
||||
ast::PathSegment {
|
||||
identifier: res,
|
||||
lifetime: None,
|
||||
lifetimes: opt_vec::Empty,
|
||||
types: opt_vec::Empty,
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -375,14 +375,10 @@ impl<'self> TraitDef<'self> {
|
|||
cx.ty_ident(trait_span, ty_param.ident)
|
||||
};
|
||||
|
||||
let self_lifetime = if generics.lifetimes.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(*generics.lifetimes.get(0))
|
||||
};
|
||||
let self_lifetimes = generics.lifetimes.clone();
|
||||
|
||||
// Create the type of `self`.
|
||||
let self_type = cx.ty_path(cx.path_all(trait_span, false, ~[ type_ident ], self_lifetime,
|
||||
let self_type = cx.ty_path(cx.path_all(trait_span, false, ~[ type_ident ], self_lifetimes,
|
||||
opt_vec::take_vec(self_ty_params)), None);
|
||||
|
||||
let doc_attr = cx.attribute(
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ use codemap::Span;
|
|||
use ext::base::ExtCtxt;
|
||||
use ext::build::{AstBuilder};
|
||||
use ext::deriving::generic::*;
|
||||
use opt_vec;
|
||||
|
||||
pub fn expand_deriving_rand(cx: @ExtCtxt,
|
||||
span: Span,
|
||||
|
|
@ -77,7 +78,7 @@ fn rand_substructure(cx: @ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
|
|||
let rand_name = cx.path_all(span,
|
||||
true,
|
||||
rand_ident.clone(),
|
||||
None,
|
||||
opt_vec::Empty,
|
||||
~[]);
|
||||
let rand_name = cx.expr_path(rand_name);
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use ext::base::ExtCtxt;
|
|||
use ext::build::AstBuilder;
|
||||
use codemap::{Span,respan};
|
||||
use opt_vec;
|
||||
use opt_vec::OptVec;
|
||||
|
||||
/// The types of pointers
|
||||
pub enum PtrTy<'self> {
|
||||
|
|
@ -71,7 +72,7 @@ impl<'self> Path<'self> {
|
|||
self_generics: &Generics)
|
||||
-> ast::Path {
|
||||
let idents = self.path.map(|s| cx.ident_of(*s) );
|
||||
let lt = mk_lifetime(cx, span, &self.lifetime);
|
||||
let lt = mk_lifetimes(cx, span, &self.lifetime);
|
||||
let tys = self.params.map(|t| t.to_ty(cx, span, self_ty, self_generics));
|
||||
|
||||
cx.path_all(span, self.global, idents, lt, tys)
|
||||
|
|
@ -116,6 +117,13 @@ fn mk_lifetime(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> Option<ast::Lifet
|
|||
}
|
||||
}
|
||||
|
||||
fn mk_lifetimes(cx: @ExtCtxt, span: Span, lt: &Option<&str>) -> OptVec<ast::Lifetime> {
|
||||
match *lt {
|
||||
Some(ref s) => opt_vec::with(cx.lifetime(span, cx.ident_of(*s))),
|
||||
None => opt_vec::Empty
|
||||
}
|
||||
}
|
||||
|
||||
impl<'self> Ty<'self> {
|
||||
pub fn to_ty(&self,
|
||||
cx: @ExtCtxt,
|
||||
|
|
@ -166,13 +174,9 @@ impl<'self> Ty<'self> {
|
|||
let self_params = do self_generics.ty_params.map |ty_param| {
|
||||
cx.ty_ident(span, ty_param.ident)
|
||||
};
|
||||
let lifetime = if self_generics.lifetimes.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(*self_generics.lifetimes.get(0))
|
||||
};
|
||||
let lifetimes = self_generics.lifetimes.clone();
|
||||
|
||||
cx.path_all(span, false, ~[self_ty], lifetime,
|
||||
cx.path_all(span, false, ~[self_ty], lifetimes,
|
||||
opt_vec::take_vec(self_params))
|
||||
}
|
||||
Literal(ref p) => {
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
|
|||
segments: ~[
|
||||
ast::PathSegment {
|
||||
identifier: ident,
|
||||
lifetime: None,
|
||||
lifetimes: opt_vec::Empty,
|
||||
types: opt_vec::Empty,
|
||||
}
|
||||
],
|
||||
|
|
@ -628,7 +628,7 @@ impl Visitor<()> for NewNameFinderContext {
|
|||
segments: [
|
||||
ast::PathSegment {
|
||||
identifier: id,
|
||||
lifetime: _,
|
||||
lifetimes: _,
|
||||
types: _
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use ext::base;
|
|||
use ext::build::AstBuilder;
|
||||
use rsparse = parse;
|
||||
use parse::token;
|
||||
|
||||
use opt_vec;
|
||||
use std::fmt::parse;
|
||||
use std::hashmap::{HashMap, HashSet};
|
||||
use std::vec;
|
||||
|
|
@ -464,7 +464,7 @@ impl Context {
|
|||
sp,
|
||||
true,
|
||||
rtpath("Method"),
|
||||
Some(life),
|
||||
opt_vec::with(life),
|
||||
~[]
|
||||
), None);
|
||||
let st = ast::item_static(ty, ast::MutImmutable, method);
|
||||
|
|
@ -582,7 +582,8 @@ impl Context {
|
|||
self.ecx.ident_of("rt"),
|
||||
self.ecx.ident_of("Piece"),
|
||||
],
|
||||
Some(self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static"))),
|
||||
opt_vec::with(
|
||||
self.ecx.lifetime(self.fmtsp, self.ecx.ident_of("static"))),
|
||||
~[]
|
||||
), None);
|
||||
let ty = ast::ty_fixed_length_vec(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue