Convert libraries to use #[plugin_registrar]

This commit is contained in:
Keegan McAllister 2014-05-24 21:31:50 -07:00
parent ed41b71fbe
commit aca0bac29f
4 changed files with 24 additions and 34 deletions

View File

@ -1819,9 +1819,8 @@ type int8_t = i8;
### Function-only attributes ### Function-only attributes
- `macro_registrar` - when using loadable syntax extensions, mark this - `plugin_registrar` - mark this function as the registration point for
function as the registration point for the current crate's syntax compiler plugins, such as loadable syntax extensions.
extensions.
- `main` - indicates that this function should be passed to the entry point, - `main` - indicates that this function should be passed to the entry point,
rather than the function in the crate root named `main`. rather than the function in the crate root named `main`.
- `start` - indicates that this function should be used as the entry point, - `start` - indicates that this function should be used as the entry point,

View File

@ -48,29 +48,25 @@ fn main() {
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![deny(deprecated_owned_vector)] #![deny(deprecated_owned_vector)]
#![feature(macro_registrar, managed_boxes)] #![feature(plugin_registrar, managed_boxes)]
extern crate syntax; extern crate syntax;
extern crate rustc;
use syntax::ast; use syntax::ast;
use syntax::ast::Name;
use syntax::attr::contains; use syntax::attr::contains;
use syntax::codemap::{Span, mk_sp}; use syntax::codemap::{Span, mk_sp};
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr}; use syntax::ext::base::{ExtCtxt, MacExpr};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse; use syntax::parse;
use syntax::parse::token; use syntax::parse::token;
use syntax::parse::token::InternedString; use syntax::parse::token::InternedString;
use rustc::plugin::Registry;
#[macro_registrar] #[plugin_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) { pub fn plugin_registrar(reg: &mut Registry) {
register(token::intern("fourcc"), reg.register_macro("fourcc", expand_syntax_ext);
NormalTT(box BasicMacroExpander {
expander: expand_syntax_ext,
span: None,
},
None));
} }
pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])

View File

@ -45,27 +45,23 @@ fn main() {
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![deny(deprecated_owned_vector)] #![deny(deprecated_owned_vector)]
#![feature(macro_registrar, managed_boxes)] #![feature(plugin_registrar, managed_boxes)]
extern crate syntax; extern crate syntax;
extern crate rustc;
use syntax::ast; use syntax::ast;
use syntax::ast::Name;
use syntax::codemap::{Span, mk_sp}; use syntax::codemap::{Span, mk_sp};
use syntax::ext::base; use syntax::ext::base;
use syntax::ext::base::{SyntaxExtension, BasicMacroExpander, NormalTT, ExtCtxt, MacExpr}; use syntax::ext::base::{ExtCtxt, MacExpr};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::parse; use syntax::parse;
use syntax::parse::token; use syntax::parse::token;
use rustc::plugin::Registry;
#[macro_registrar] #[plugin_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) { pub fn plugin_registrar(reg: &mut Registry) {
register(token::intern("hexfloat"), reg.register_macro("hexfloat", expand_syntax_ext);
NormalTT(box BasicMacroExpander {
expander: expand_syntax_ext,
span: None,
},
None));
} }
//Check if the literal is valid (as LLVM expects), //Check if the literal is valid (as LLVM expects),

View File

@ -19,24 +19,24 @@
html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_favicon_url = "http://www.rust-lang.org/favicon.ico",
html_root_url = "http://doc.rust-lang.org/")] html_root_url = "http://doc.rust-lang.org/")]
#![feature(macro_registrar, managed_boxes, quote)] #![feature(plugin_registrar, managed_boxes, quote)]
extern crate regex; extern crate regex;
extern crate syntax; extern crate syntax;
extern crate rustc;
use std::rc::Rc; use std::rc::Rc;
use syntax::ast; use syntax::ast;
use syntax::codemap; use syntax::codemap;
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::ext::base::{ use syntax::ext::base::{ExtCtxt, MacResult, MacExpr, DummyResult};
SyntaxExtension, ExtCtxt, MacResult, MacExpr, DummyResult,
NormalTT, BasicMacroExpander,
};
use syntax::parse; use syntax::parse;
use syntax::parse::token; use syntax::parse::token;
use syntax::print::pprust; use syntax::print::pprust;
use rustc::plugin::Registry;
use regex::Regex; use regex::Regex;
use regex::native::{ use regex::native::{
OneChar, CharClass, Any, Save, Jump, Split, OneChar, CharClass, Any, Save, Jump, Split,
@ -46,11 +46,10 @@ use regex::native::{
}; };
/// For the `regex!` syntax extension. Do not use. /// For the `regex!` syntax extension. Do not use.
#[macro_registrar] #[plugin_registrar]
#[doc(hidden)] #[doc(hidden)]
pub fn macro_registrar(register: |ast::Name, SyntaxExtension|) { pub fn plugin_registrar(reg: &mut Registry) {
let expander = box BasicMacroExpander { expander: native, span: None }; reg.register_macro("regex", native);
register(token::intern("regex"), NormalTT(expander, None))
} }
/// Generates specialized code for the Pike VM for a particular regular /// Generates specialized code for the Pike VM for a particular regular