diff options
| author | Florian Hahn <flo@fhahn.com> | 2014-09-13 12:55:00 +0200 |
|---|---|---|
| committer | Florian Hahn <flo@fhahn.com> | 2014-09-19 11:10:54 +0200 |
| commit | 89b09440d87a8346c2e6206855ab4f0b90febe25 (patch) | |
| tree | 409f4efc49ca0d40a8e58abaf1483765a4dbd19a /src/libsyntax | |
| parent | af3889f6979647b9bd2dc5f5132d80e3e5b405a5 (diff) | |
| download | rust-89b09440d87a8346c2e6206855ab4f0b90febe25.tar.gz rust-89b09440d87a8346c2e6206855ab4f0b90febe25.zip | |
Allow syntax extensions to return multiple items, closes #16723.
This patch replaces `MacItem` with `MacItems`.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/diagnostics/plugin.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 27 |
2 files changed, 15 insertions, 20 deletions
diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 132b59c89b2..d3c39284f55 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; use ast; use ast::{Ident, Name, TokenTree}; use codemap::Span; -use ext::base::{ExtCtxt, MacExpr, MacItem, MacResult}; +use ext::base::{ExtCtxt, MacExpr, MacResult, MacItems}; use ext::build::AstBuilder; use parse::token; use ptr::P; @@ -102,7 +102,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, let sym = Ident::new(token::gensym(( "__register_diagnostic_".to_string() + token::get_ident(*code).get() ).as_slice())); - MacItem::new(quote_item!(ecx, mod $sym {}).unwrap()) + MacItems::new(vec![quote_item!(ecx, mod $sym {}).unwrap()].into_iter()) } pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, @@ -133,7 +133,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, (descriptions.len(), ecx.expr_vec(span, descriptions)) }) }); - MacItem::new(quote_item!(ecx, + MacItems::new(vec![quote_item!(ecx, pub static $name: [(&'static str, &'static str), ..$count] = $expr; - ).unwrap()) + ).unwrap()].into_iter()) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 773daa4a4c5..fbbbea541a6 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -203,25 +203,20 @@ impl MacResult for MacPat { Some(self.p) } } -/// A convenience type for macros that return a single item. -pub struct MacItem { - i: P<ast::Item> +/// A type for macros that return multiple items. +pub struct MacItems { + items: SmallVector<P<ast::Item>> } -impl MacItem { - pub fn new(i: P<ast::Item>) -> Box<MacResult+'static> { - box MacItem { i: i } as Box<MacResult+'static> + +impl MacItems { + pub fn new<I: Iterator<P<ast::Item>>>(mut it: I) -> Box<MacResult+'static> { + box MacItems { items: it.collect() } as Box<MacResult+'static> } } -impl MacResult for MacItem { - fn make_items(self: Box<MacItem>) -> Option<SmallVector<P<ast::Item>>> { - Some(SmallVector::one(self.i)) - } - fn make_stmt(self: Box<MacItem>) -> Option<P<ast::Stmt>> { - Some(P(codemap::respan( - self.i.span, - ast::StmtDecl( - P(codemap::respan(self.i.span, ast::DeclItem(self.i))), - ast::DUMMY_NODE_ID)))) + +impl MacResult for MacItems { + fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> { + Some(self.items) } } |
