Skip to content

Commit

Permalink
auto merge of #14554 : kmcallister/rust/plugin_registrar, r=cmr
Browse files Browse the repository at this point in the history
This implements the design in rust-lang/rfcs#86.  It shouldn't be merged until that RFC is accepted, but it would be great if somebody has time to review the code before then.
  • Loading branch information
bors committed Jun 9, 2014
2 parents b6146e6 + deecda6 commit 0ea7aa3
Show file tree
Hide file tree
Showing 92 changed files with 669 additions and 403 deletions.
6 changes: 3 additions & 3 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ DEPS_uuid := std serialize
DEPS_sync := std alloc
DEPS_getopts := std
DEPS_collections := core alloc
DEPS_fourcc := syntax std
DEPS_hexfloat := syntax std
DEPS_fourcc := rustc syntax std
DEPS_hexfloat := rustc syntax std
DEPS_num := std
DEPS_test := std getopts serialize term time regex native:rust_test_helpers
DEPS_time := std serialize sync
DEPS_rand := core
DEPS_url := std
DEPS_log := std sync
DEPS_regex := std
DEPS_regex_macros = syntax std regex
DEPS_regex_macros = rustc syntax std regex
DEPS_fmt_macros = std

TOOL_DEPS_compiletest := test green rustuv getopts
Expand Down
10 changes: 8 additions & 2 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

extern crate test;
extern crate getopts;
#[phase(link, syntax)]
extern crate log;
extern crate green;
extern crate rustuv;

#[cfg(stage0)]
#[phase(syntax, link)]
extern crate log;

#[cfg(not(stage0))]
#[phase(plugin, link)]
extern crate log;

extern crate regex;

use std::os;
Expand Down
7 changes: 3 additions & 4 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1819,9 +1819,8 @@ type int8_t = i8;

### Function-only attributes

- `macro_registrar` - when using loadable syntax extensions, mark this
function as the registration point for the current crate's syntax
extensions.
- `plugin_registrar` - mark this function as the registration point for
compiler plugins, such as loadable syntax extensions.
- `main` - indicates that this function should be passed to the entry point,
rather than the function in the crate root named `main`.
- `start` - indicates that this function should be used as the entry point,
Expand Down Expand Up @@ -4098,7 +4097,7 @@ that demonstrates all four of them:

~~~~
#![feature(phase)]
#[phase(syntax, link)] extern crate log;
#[phase(plugin, link)] extern crate log;
fn main() {
error!("This is an error log")
Expand Down
12 changes: 10 additions & 2 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,14 @@
#![no_std]
#![feature(phase)]

#[cfg(stage0)]
#[phase(syntax, link)]
extern crate core;

#[cfg(not(stage0))]
#[phase(plugin, link)]
extern crate core;

extern crate libc;


Expand All @@ -80,8 +86,10 @@ extern crate libc;
#[cfg(test)] extern crate debug;
#[cfg(test)] extern crate sync;
#[cfg(test)] extern crate native;
#[cfg(test)] #[phase(syntax, link)] extern crate std;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;

// Heaps provided for low-level allocation strategies

Expand Down
16 changes: 13 additions & 3 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@
#![feature(macro_rules, managed_boxes, default_type_params, phase, globs)]
#![no_std]

#[phase(syntax, link)] extern crate core;
extern crate alloc;

#[cfg(stage0)]
#[phase(syntax, link)]
extern crate core;

#[cfg(not(stage0))]
#[phase(plugin, link)]
extern crate core;

#[cfg(test)] extern crate native;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate std;
#[cfg(test)] #[phase(syntax, link)] extern crate log;

#[cfg(test, stage0)] #[phase(syntax, link)] extern crate std;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate std;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;

use core::prelude::*;

Expand Down
3 changes: 2 additions & 1 deletion src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Simple [DEFLATE][def]-based compression. This is a wrapper around the
#![feature(phase)]
#![deny(deprecated_owned_vector)]

#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;

extern crate libc;

Expand Down
20 changes: 8 additions & 12 deletions src/libfourcc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ to be `big`, i.e. left-to-right order. It returns a u32.
To load the extension and use it:
```rust,ignore
#[phase(syntax)]
#[phase(plugin)]
extern crate fourcc;
fn main() {
Expand All @@ -48,29 +48,25 @@ fn main() {
html_root_url = "http://doc.rust-lang.org/")]

#![deny(deprecated_owned_vector)]
#![feature(macro_registrar, managed_boxes)]
#![feature(plugin_registrar, managed_boxes)]

extern crate syntax;
extern crate rustc;

use syntax::ast;
use syntax::ast::Name;
use syntax::attr::contains;
use syntax::codemap::{Span, mk_sp};
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::parse;
use syntax::parse::token;
use syntax::parse::token::InternedString;
use rustc::plugin::Registry;

#[macro_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
register(token::intern("fourcc"),
NormalTT(box BasicMacroExpander {
expander: expand_syntax_ext,
span: None,
},
None));
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("fourcc", expand_syntax_ext);
}

pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
Expand Down
3 changes: 2 additions & 1 deletion src/libgetopts/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
#![deny(deprecated_owned_vector)]

#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test, stage0)] #[phase(syntax, link)] extern crate log;
#[cfg(test, not(stage0))] #[phase(plugin, link)] extern crate log;

use std::cmp::PartialEq;
use std::result::{Err, Ok};
Expand Down
6 changes: 3 additions & 3 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
//!
//! ```
//! #![feature(phase)]
//! #[phase(syntax)] extern crate green;
//! #[phase(plugin)] extern crate green;
//!
//! green_start!(main)
//!
Expand Down Expand Up @@ -211,7 +211,7 @@
#![allow(visible_private_types)]
#![deny(deprecated_owned_vector)]

#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test)] #[phase(plugin, link)] extern crate log;
#[cfg(test)] extern crate rustuv;
extern crate libc;
extern crate alloc;
Expand Down Expand Up @@ -249,7 +249,7 @@ pub mod task;
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax)] extern crate green;
/// #[phase(plugin)] extern crate green;
///
/// green_start!(main)
///
Expand Down
20 changes: 8 additions & 12 deletions src/libhexfloat/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ literal.
To load the extension and use it:
```rust,ignore
#[phase(syntax)]
#[phase(plugin)]
extern crate hexfloat;
fn main() {
Expand All @@ -45,27 +45,23 @@ fn main() {
html_root_url = "http://doc.rust-lang.org/")]

#![deny(deprecated_owned_vector)]
#![feature(macro_registrar, managed_boxes)]
#![feature(plugin_registrar, managed_boxes)]

extern crate syntax;
extern crate rustc;

use syntax::ast;
use syntax::ast::Name;
use syntax::codemap::{Span, mk_sp};
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::parse;
use syntax::parse::token;
use rustc::plugin::Registry;

#[macro_registrar]
pub fn macro_registrar(register: |Name, SyntaxExtension|) {
register(token::intern("hexfloat"),
NormalTT(box BasicMacroExpander {
expander: expand_syntax_ext,
span: None,
},
None));
#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("hexfloat", expand_syntax_ext);
}

//Check if the literal is valid (as LLVM expects),
Expand Down
2 changes: 1 addition & 1 deletion src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Utilities for program-wide and customizable logging
```
#![feature(phase)]
#[phase(syntax, link)] extern crate log;
#[phase(plugin, link)] extern crate log;
fn main() {
debug!("this is a debug {}", "message");
Expand Down
12 changes: 6 additions & 6 deletions src/liblog/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// log!(log::DEBUG, "this is a debug message");
Expand Down Expand Up @@ -51,7 +51,7 @@ macro_rules! log(
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// # let error = 3;
Expand All @@ -69,7 +69,7 @@ macro_rules! error(
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// # let code = 3;
Expand All @@ -87,7 +87,7 @@ macro_rules! warn(
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// # let ret = 3;
Expand All @@ -107,7 +107,7 @@ macro_rules! info(
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// debug!("x = {x}, y = {y}", x=10, y=20);
Expand All @@ -124,7 +124,7 @@ macro_rules! debug(
///
/// ```
/// #![feature(phase)]
/// #[phase(syntax, link)] extern crate log;
/// #[phase(plugin, link)] extern crate log;
///
/// # fn main() {
/// # struct Point { x: int, y: int }
Expand Down
19 changes: 17 additions & 2 deletions src/librand/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,28 @@
#![no_std]
#![experimental]

#[cfg(stage0)]
#[phase(syntax, link)]
extern crate core;

#[cfg(not(stage0))]
#[phase(plugin, link)]
extern crate core;

#[cfg(test, stage0)]
#[phase(syntax, link)] extern crate std;

#[cfg(test, stage0)]
#[phase(syntax, link)] extern crate log;

#[cfg(test, not(stage0))]
#[phase(plugin, link)] extern crate std;

#[cfg(test, not(stage0))]
#[phase(plugin, link)] extern crate log;

#[cfg(test)] extern crate native;
#[cfg(test)] extern crate debug;
#[cfg(test)] #[phase(syntax, link)] extern crate std;
#[cfg(test)] #[phase(syntax, link)] extern crate log;

use core::prelude::*;

Expand Down
Loading

0 comments on commit 0ea7aa3

Please sign in to comment.