syntax: fix fallout of merging ast::ViewItem into ast::Item.

This commit is contained in:
Eduard Burtescu 2015-01-13 17:30:17 +02:00
parent 38ac9e3984
commit 7cece8725b
15 changed files with 201 additions and 417 deletions

View file

@ -97,7 +97,6 @@ pub trait AstBuilder {
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block>;
fn block_all(&self, span: Span,
view_items: Vec<ast::ViewItem>,
stmts: Vec<P<ast::Stmt>>,
expr: Option<P<ast::Expr>>) -> P<ast::Block>;
@ -242,7 +241,7 @@ pub trait AstBuilder {
fn item_mod(&self, span: Span, inner_span: Span,
name: Ident, attrs: Vec<ast::Attribute>,
vi: Vec<ast::ViewItem> , items: Vec<P<ast::Item>> ) -> P<ast::Item>;
items: Vec<P<ast::Item>>) -> P<ast::Item>;
fn item_static(&self,
span: Span,
@ -280,15 +279,15 @@ pub trait AstBuilder {
value: ast::Lit_)
-> P<ast::MetaItem>;
fn view_use(&self, sp: Span,
vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem;
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem;
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> ast::ViewItem;
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem;
fn view_use_glob(&self, sp: Span,
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem;
fn item_use(&self, sp: Span,
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item>;
fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item>;
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> P<ast::Item>;
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item>;
fn item_use_glob(&self, sp: Span,
vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item>;
}
impl<'a> AstBuilder for ExtCtxt<'a> {
@ -519,7 +518,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn block(&self, span: Span, stmts: Vec<P<ast::Stmt>>,
expr: Option<P<Expr>>) -> P<ast::Block> {
self.block_all(span, Vec::new(), stmts, expr)
self.block_all(span, stmts, expr)
}
fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> P<ast::Stmt> {
@ -528,15 +527,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> {
self.block_all(expr.span, Vec::new(), Vec::new(), Some(expr))
self.block_all(expr.span, Vec::new(), Some(expr))
}
fn block_all(&self,
span: Span,
view_items: Vec<ast::ViewItem>,
stmts: Vec<P<ast::Stmt>>,
expr: Option<P<ast::Expr>>) -> P<ast::Block> {
P(ast::Block {
view_items: view_items,
stmts: stmts,
expr: expr,
id: ast::DUMMY_NODE_ID,
@ -1031,16 +1028,14 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}
fn item_mod(&self, span: Span, inner_span: Span, name: Ident,
attrs: Vec<ast::Attribute> ,
vi: Vec<ast::ViewItem> ,
items: Vec<P<ast::Item>> ) -> P<ast::Item> {
attrs: Vec<ast::Attribute>,
items: Vec<P<ast::Item>>) -> P<ast::Item> {
self.item(
span,
name,
attrs,
ast::ItemMod(ast::Mod {
inner: inner_span,
view_items: vi,
items: items,
})
)
@ -1101,47 +1096,47 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
P(respan(sp, ast::MetaNameValue(name, respan(sp, value))))
}
fn view_use(&self, sp: Span,
vis: ast::Visibility, vp: P<ast::ViewPath>) -> ast::ViewItem {
ast::ViewItem {
node: ast::ViewItemUse(vp),
attrs: Vec::new(),
fn item_use(&self, sp: Span,
vis: ast::Visibility, vp: P<ast::ViewPath>) -> P<ast::Item> {
P(ast::Item {
id: ast::DUMMY_NODE_ID,
ident: special_idents::invalid,
attrs: vec![],
node: ast::ItemUse(vp),
vis: vis,
span: sp
}
})
}
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem {
fn item_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> P<ast::Item> {
let last = path.segments.last().unwrap().identifier;
self.view_use_simple_(sp, vis, last, path)
self.item_use_simple_(sp, vis, last, path)
}
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> ast::ViewItem {
self.view_use(sp, vis,
fn item_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> P<ast::Item> {
self.item_use(sp, vis,
P(respan(sp,
ast::ViewPathSimple(ident,
path,
ast::DUMMY_NODE_ID))))
path))))
}
fn view_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident> , imports: &[ast::Ident]) -> ast::ViewItem {
fn item_use_list(&self, sp: Span, vis: ast::Visibility,
path: Vec<ast::Ident>, imports: &[ast::Ident]) -> P<ast::Item> {
let imports = imports.iter().map(|id| {
respan(sp, ast::PathListIdent { name: *id, id: ast::DUMMY_NODE_ID })
}).collect();
self.view_use(sp, vis,
self.item_use(sp, vis,
P(respan(sp,
ast::ViewPathList(self.path(sp, path),
imports,
ast::DUMMY_NODE_ID))))
imports))))
}
fn view_use_glob(&self, sp: Span,
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem {
self.view_use(sp, vis,
fn item_use_glob(&self, sp: Span,
vis: ast::Visibility, path: Vec<ast::Ident>) -> P<ast::Item> {
self.item_use(sp, vis,
P(respan(sp,
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID))))
ast::ViewPathGlob(self.path(sp, path)))))
}
}

View file

@ -1073,7 +1073,7 @@ impl<'a> MethodDef<'a> {
// <delegated expression referring to __self0_vi, et al.>
// }
let arm_expr = cx.expr_block(
cx.block_all(sp, Vec::new(), index_let_stmts, Some(arm_expr)));
cx.block_all(sp, index_let_stmts, Some(arm_expr)));
// Builds arm:
// _ => { let __self0_vi = ...;

View file

@ -206,7 +206,6 @@ pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
// wrap the if-let expr in a block
let span = els.span;
let blk = P(ast::Block {
view_items: vec![],
stmts: vec![],
expr: Some(P(els)),
id: ast::DUMMY_NODE_ID,
@ -799,8 +798,7 @@ pub fn expand_block(blk: P<Block>, fld: &mut MacroExpander) -> P<Block> {
// expand the elements of a block.
pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
b.map(|Block {id, view_items, stmts, expr, rules, span}| {
let new_view_items = view_items.into_iter().map(|x| fld.fold_view_item(x)).collect();
b.map(|Block {id, stmts, expr, rules, span}| {
let new_stmts = stmts.into_iter().flat_map(|x| {
// perform all pending renames
let renamed_stmt = {
@ -821,7 +819,6 @@ pub fn expand_block_elts(b: P<Block>, fld: &mut MacroExpander) -> P<Block> {
});
Block {
id: fld.new_id(id),
view_items: new_view_items,
stmts: new_stmts,
expr: new_expr,
rules: rules,

View file

@ -352,18 +352,11 @@ pub mod rt {
impl<'a> ExtParseUtils for ExtCtxt<'a> {
fn parse_item(&self, s: String) -> P<ast::Item> {
let res = parse::parse_item_from_source_str(
parse::parse_item_from_source_str(
"<quote expansion>".to_string(),
s,
self.cfg(),
self.parse_sess());
match res {
Some(ast) => ast,
None => {
error!("parse error");
panic!()
}
}
self.parse_sess()).expect("parse error")
}
fn parse_stmt(&self, s: String) -> P<ast::Stmt> {
@ -767,7 +760,6 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree])
vector.extend(mk_tts(cx, &tts[]).into_iter());
let block = cx.expr_block(
cx.block_all(sp,
Vec::new(),
vector,
Some(cx.expr_ident(sp, id_ext("tt")))));
@ -778,18 +770,18 @@ fn expand_wrapper(cx: &ExtCtxt,
sp: Span,
cx_expr: P<ast::Expr>,
expr: P<ast::Expr>) -> P<ast::Expr> {
let uses = [
&["syntax", "ext", "quote", "rt"],
].iter().map(|path| {
let path = path.iter().map(|s| s.to_string()).collect();
cx.view_use_glob(sp, ast::Inherited, ids_ext(path))
}).collect();
// Explicitly borrow to avoid moving from the invoker (#16992)
let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr));
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow);
cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr)))
let stmts = [
&["syntax", "ext", "quote", "rt"],
].iter().map(|path| {
let path = path.iter().map(|s| s.to_string()).collect();
cx.stmt_item(sp, cx.item_use_glob(sp, ast::Inherited, ids_ext(path)))
}).chain(Some(stmt_let_ext_cx).into_iter()).collect();
cx.expr_block(cx.block_all(sp, stmts, Some(expr)))
}
fn expand_parse_call(cx: &ExtCtxt,