Remove MacroRulesTT
.
This commit is contained in:
parent
0ddb66c4c7
commit
2abdc8805c
@ -17,7 +17,7 @@ use rustc::mir::transform::MirMapPass;
|
||||
|
||||
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
|
||||
use syntax::ext::base::{IdentTT, MultiModifier, MultiDecorator};
|
||||
use syntax::ext::base::{MacroExpanderFn, MacroRulesTT};
|
||||
use syntax::ext::base::MacroExpanderFn;
|
||||
use syntax::parse::token;
|
||||
use syntax::ast;
|
||||
use syntax::feature_gate::AttributeType;
|
||||
@ -111,10 +111,6 @@ impl<'a> Registry<'a> {
|
||||
}
|
||||
MultiDecorator(ext) => MultiDecorator(ext),
|
||||
MultiModifier(ext) => MultiModifier(ext),
|
||||
MacroRulesTT => {
|
||||
self.sess.err("plugin tried to register a new MacroRulesTT");
|
||||
return;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -457,9 +457,6 @@ pub enum SyntaxExtension {
|
||||
/// the block.
|
||||
///
|
||||
IdentTT(Box<IdentMacroExpander + 'static>, Option<Span>, bool),
|
||||
|
||||
/// Represents `macro_rules!` itself.
|
||||
MacroRulesTT,
|
||||
}
|
||||
|
||||
pub type NamedSyntaxExtension = (Name, SyntaxExtension);
|
||||
|
@ -12,7 +12,7 @@ use ast::{Block, Crate, Ident, Mac_, PatKind};
|
||||
use ast::{MacStmtStyle, StmtKind, ItemKind};
|
||||
use ast;
|
||||
use ext::hygiene::Mark;
|
||||
use ext::placeholders::{self, placeholder, PlaceholderExpander};
|
||||
use ext::placeholders::{placeholder, PlaceholderExpander};
|
||||
use attr::{self, HasAttrs};
|
||||
use codemap::{ExpnInfo, NameAndSpan, MacroBang, MacroAttribute};
|
||||
use syntax_pos::{self, Span, ExpnId};
|
||||
@ -377,46 +377,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
kind.make_from(expander.expand(self.cx, span, ident, marked_tts, attrs))
|
||||
}
|
||||
|
||||
MacroRulesTT => {
|
||||
if ident.name == keywords::Invalid.name() {
|
||||
self.cx.span_err(path.span,
|
||||
&format!("macro {}! expects an ident argument", extname));
|
||||
return kind.dummy(span);
|
||||
};
|
||||
|
||||
self.cx.bt_push(ExpnInfo {
|
||||
call_site: span,
|
||||
callee: NameAndSpan {
|
||||
format: MacroBang(extname),
|
||||
span: None,
|
||||
// `macro_rules!` doesn't directly allow unstable
|
||||
// (this is orthogonal to whether the macro it creates allows it)
|
||||
allow_internal_unstable: false,
|
||||
}
|
||||
});
|
||||
|
||||
let def = ast::MacroDef {
|
||||
ident: ident,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: span,
|
||||
imported_from: None,
|
||||
use_locally: true,
|
||||
body: marked_tts,
|
||||
export: attr::contains_name(&attrs, "macro_export"),
|
||||
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
|
||||
attrs: attrs,
|
||||
};
|
||||
|
||||
self.cx.insert_macro(def.clone());
|
||||
|
||||
// If keep_macs is true, expands to a MacEager::items instead.
|
||||
if self.cx.ecfg.keep_macs {
|
||||
Some(placeholders::reconstructed_macro_rules(&def, &path))
|
||||
} else {
|
||||
Some(placeholders::macro_scope_placeholder())
|
||||
}
|
||||
}
|
||||
|
||||
MultiDecorator(..) | MultiModifier(..) => {
|
||||
self.cx.span_err(path.span,
|
||||
&format!("`{}` can only be used in attributes", extname));
|
||||
|
@ -13,7 +13,7 @@ use codemap::{DUMMY_SP, dummy_spanned};
|
||||
use ext::base::ExtCtxt;
|
||||
use ext::expand::{Expansion, ExpansionKind};
|
||||
use fold::*;
|
||||
use parse::token::keywords;
|
||||
use parse::token::{intern, keywords};
|
||||
use ptr::P;
|
||||
use util::move_map::MoveMap;
|
||||
use util::small_vector::SmallVector;
|
||||
@ -214,7 +214,7 @@ impl<'a, 'b> Folder for PlaceholderExpander<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn reconstructed_macro_rules(def: &ast::MacroDef, path: &ast::Path) -> Expansion {
|
||||
pub fn reconstructed_macro_rules(def: &ast::MacroDef) -> Expansion {
|
||||
Expansion::Items(SmallVector::one(P(ast::Item {
|
||||
ident: def.ident,
|
||||
attrs: def.attrs.clone(),
|
||||
@ -222,7 +222,14 @@ pub fn reconstructed_macro_rules(def: &ast::MacroDef, path: &ast::Path) -> Expan
|
||||
node: ast::ItemKind::Mac(ast::Mac {
|
||||
span: def.span,
|
||||
node: ast::Mac_ {
|
||||
path: path.clone(),
|
||||
path: ast::Path {
|
||||
span: DUMMY_SP,
|
||||
global: false,
|
||||
segments: vec![ast::PathSegment {
|
||||
identifier: ast::Ident::with_empty_ctxt(intern("macro_rules")),
|
||||
parameters: ast::PathParameters::none(),
|
||||
}],
|
||||
},
|
||||
tts: def.body.clone(),
|
||||
}
|
||||
}),
|
||||
|
@ -8,10 +8,11 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use ast;
|
||||
use {ast, attr};
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
|
||||
use ext::base::{NormalTT, TTMacroExpander};
|
||||
use ext::base::{DummyResult, ExtCtxt, MacEager, MacResult, SyntaxExtension};
|
||||
use ext::base::{IdentMacroExpander, NormalTT, TTMacroExpander};
|
||||
use ext::placeholders;
|
||||
use ext::tt::macro_parser::{Success, Error, Failure};
|
||||
use ext::tt::macro_parser::{MatchedSeq, MatchedNonterminal};
|
||||
use ext::tt::macro_parser::parse;
|
||||
@ -242,6 +243,38 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
|
||||
cx.span_fatal(best_fail_spot.substitute_dummy(sp), &best_fail_msg[..]);
|
||||
}
|
||||
|
||||
pub struct MacroRulesExpander;
|
||||
impl IdentMacroExpander for MacroRulesExpander {
|
||||
fn expand(&self,
|
||||
cx: &mut ExtCtxt,
|
||||
span: Span,
|
||||
ident: ast::Ident,
|
||||
tts: Vec<tokenstream::TokenTree>,
|
||||
attrs: Vec<ast::Attribute>)
|
||||
-> Box<MacResult> {
|
||||
let def = ast::MacroDef {
|
||||
ident: ident,
|
||||
id: ast::DUMMY_NODE_ID,
|
||||
span: span,
|
||||
imported_from: None,
|
||||
use_locally: true,
|
||||
body: tts,
|
||||
export: attr::contains_name(&attrs, "macro_export"),
|
||||
allow_internal_unstable: attr::contains_name(&attrs, "allow_internal_unstable"),
|
||||
attrs: attrs,
|
||||
};
|
||||
|
||||
cx.insert_macro(def.clone());
|
||||
|
||||
// If keep_macs is true, expands to a MacEager::items instead.
|
||||
if cx.ecfg.keep_macs {
|
||||
MacEager::items(placeholders::reconstructed_macro_rules(&def).make_items())
|
||||
} else {
|
||||
MacEager::items(placeholders::macro_scope_placeholder().make_items())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Note that macro-by-example's input is also matched against a token tree:
|
||||
// $( $lhs:tt => $rhs:tt );+
|
||||
//
|
||||
|
@ -50,8 +50,9 @@ pub mod deriving;
|
||||
|
||||
use std::rc::Rc;
|
||||
use syntax::ast;
|
||||
use syntax::ext::base::{MacroExpanderFn, MacroRulesTT, NormalTT, MultiModifier};
|
||||
use syntax::ext::base::{MacroExpanderFn, NormalTT, IdentTT, MultiModifier};
|
||||
use syntax::ext::hygiene::Mark;
|
||||
use syntax::ext::tt::macro_rules::MacroRulesExpander;
|
||||
use syntax::parse::token::intern;
|
||||
|
||||
pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver, enable_quotes: bool) {
|
||||
@ -59,7 +60,7 @@ pub fn register_builtins(resolver: &mut syntax::ext::base::Resolver, enable_quot
|
||||
resolver.add_macro(Mark::root(), ast::Ident::with_empty_ctxt(intern(name)), Rc::new(ext));
|
||||
};
|
||||
|
||||
register("macro_rules", MacroRulesTT);
|
||||
register("macro_rules", IdentTT(Box::new(MacroRulesExpander), None, false));
|
||||
|
||||
macro_rules! register {
|
||||
($( $name:ident: $f:expr, )*) => { $(
|
||||
|
Loading…
x
Reference in New Issue
Block a user