mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
Rename macros crate to plugins
This commit is contained in:
parent
6177a3bdcc
commit
fcb25a35ec
13 changed files with 113 additions and 74 deletions
12
Cargo.lock
generated
12
Cargo.lock
generated
|
@ -182,9 +182,9 @@ dependencies = [
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
||||||
"harfbuzz 0.1.0 (git+https://github.com/servo/rust-harfbuzz#ad520942cc17232e1a40cdd8a99c2905623d35f6)",
|
"harfbuzz 0.1.0 (git+https://github.com/servo/rust-harfbuzz#ad520942cc17232e1a40cdd8a99c2905623d35f6)",
|
||||||
"layers 0.1.0 (git+https://github.com/servo/rust-layers#ef89918471815dfced7aaf2f1594d5469f03eab7)",
|
"layers 0.1.0 (git+https://github.com/servo/rust-layers#ef89918471815dfced7aaf2f1594d5469f03eab7)",
|
||||||
"macros 0.0.1",
|
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net 0.0.1",
|
"net 0.0.1",
|
||||||
|
"plugins 0.0.1",
|
||||||
"png 0.1.0 (git+https://github.com/servo/rust-png#74418ffbf20e94b0d3bed4a9d004062a13342c79)",
|
"png 0.1.0 (git+https://github.com/servo/rust-png#74418ffbf20e94b0d3bed4a9d004062a13342c79)",
|
||||||
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image#f5022de4ad6bb474a03493d1f274dde9b0f1af0c)",
|
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image#f5022de4ad6bb474a03493d1f274dde9b0f1af0c)",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
|
@ -283,8 +283,8 @@ dependencies = [
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
||||||
"gfx 0.0.1",
|
"gfx 0.0.1",
|
||||||
"layout_traits 0.0.1",
|
"layout_traits 0.0.1",
|
||||||
"macros 0.0.1",
|
|
||||||
"net 0.0.1",
|
"net 0.0.1",
|
||||||
|
"plugins 0.0.1",
|
||||||
"script 0.0.1",
|
"script 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
|
@ -308,10 +308,6 @@ name = "lazy_static"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360"
|
source = "git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "macros"
|
|
||||||
version = "0.0.1"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mozjs-sys"
|
name = "mozjs-sys"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
|
@ -393,9 +389,9 @@ dependencies = [
|
||||||
"http 0.1.0-pre (git+https://github.com/servo/rust-http?ref=servo#4fdedeea8fc77149adf51bb24a37372af21c25b7)",
|
"http 0.1.0-pre (git+https://github.com/servo/rust-http?ref=servo#4fdedeea8fc77149adf51bb24a37372af21c25b7)",
|
||||||
"hubbub 0.1.0 (git+https://github.com/servo/rust-hubbub#c7f868e688de6e9cbdc26aa09292ed072bc2648b)",
|
"hubbub 0.1.0 (git+https://github.com/servo/rust-hubbub#c7f868e688de6e9cbdc26aa09292ed072bc2648b)",
|
||||||
"js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)",
|
"js 0.1.0 (git+https://github.com/servo/rust-mozjs#41fb0d80a5ed5614ca13a120cdb3281e599d4e04)",
|
||||||
"macros 0.0.1",
|
|
||||||
"msg 0.0.1",
|
"msg 0.0.1",
|
||||||
"net 0.0.1",
|
"net 0.0.1",
|
||||||
|
"plugins 0.0.1",
|
||||||
"script_traits 0.0.1",
|
"script_traits 0.0.1",
|
||||||
"style 0.0.1",
|
"style 0.0.1",
|
||||||
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
||||||
|
@ -458,7 +454,7 @@ dependencies = [
|
||||||
"encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#35f0d70f65f73ba16f296f9ec675eddee661ba79)",
|
"encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#35f0d70f65f73ba16f296f9ec675eddee661ba79)",
|
||||||
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
"geom 0.1.0 (git+https://github.com/servo/rust-geom#50a294fd997f0c6eb43e9a58ad6e227fdc2a4692)",
|
||||||
"lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)",
|
"lazy_static 0.1.0 (git+https://github.com/Kimundi/lazy-static.rs#e62a65372f1dd9019e37eb9381d819edff80e360)",
|
||||||
"macros 0.0.1",
|
"plugins 0.0.1",
|
||||||
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
"url 0.1.0 (git+https://github.com/servo/rust-url#bfdf809365600a7941a77524f9bb065886de3379)",
|
||||||
"util 0.0.1",
|
"util 0.0.1",
|
||||||
]
|
]
|
||||||
|
|
|
@ -8,8 +8,8 @@ authors = ["The Servo Project Developers"]
|
||||||
name = "gfx"
|
name = "gfx"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[dependencies.macros]
|
[dependencies.plugins]
|
||||||
path = "../macros"
|
path = "../plugins"
|
||||||
|
|
||||||
[dependencies.net]
|
[dependencies.net]
|
||||||
path = "../net"
|
path = "../net"
|
||||||
|
|
|
@ -22,7 +22,7 @@ extern crate stb_image;
|
||||||
extern crate png;
|
extern crate png;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
#[phase(plugin)]
|
#[phase(plugin)]
|
||||||
extern crate "macros" as servo_macros;
|
extern crate "plugins" as servo_plugins;
|
||||||
extern crate "net" as servo_net;
|
extern crate "net" as servo_net;
|
||||||
#[phase(plugin, link)]
|
#[phase(plugin, link)]
|
||||||
extern crate "util" as servo_util;
|
extern crate "util" as servo_util;
|
||||||
|
|
|
@ -22,8 +22,8 @@ path = "../script_traits"
|
||||||
[dependencies.style]
|
[dependencies.style]
|
||||||
path = "../style"
|
path = "../style"
|
||||||
|
|
||||||
[dependencies.macros]
|
[dependencies.plugins]
|
||||||
path = "../macros"
|
path = "../plugins"
|
||||||
|
|
||||||
[dependencies.net]
|
[dependencies.net]
|
||||||
path = "../net"
|
path = "../net"
|
||||||
|
|
|
@ -23,7 +23,7 @@ extern crate script_traits;
|
||||||
extern crate serialize;
|
extern crate serialize;
|
||||||
extern crate style;
|
extern crate style;
|
||||||
#[phase(plugin)]
|
#[phase(plugin)]
|
||||||
extern crate "macros" as servo_macros;
|
extern crate "plugins" as servo_plugins;
|
||||||
extern crate "net" as servo_net;
|
extern crate "net" as servo_net;
|
||||||
extern crate "msg" as servo_msg;
|
extern crate "msg" as servo_msg;
|
||||||
#[phase(plugin, link)]
|
#[phase(plugin, link)]
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
[package]
|
[package]
|
||||||
name = "macros"
|
name = "plugins"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
authors = ["The Servo Project Developers"]
|
authors = ["The Servo Project Developers"]
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "macros"
|
name = "plugins"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
plugin = true
|
plugin = true
|
32
components/plugins/lib.rs
Normal file
32
components/plugins/lib.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#![feature(macro_rules, plugin_registrar, quote, phase)]
|
||||||
|
|
||||||
|
#![deny(unused_imports, unused_variable)]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[phase(plugin,link)]
|
||||||
|
extern crate syntax;
|
||||||
|
#[phase(plugin, link)]
|
||||||
|
extern crate rustc;
|
||||||
|
#[cfg(test)]
|
||||||
|
extern crate sync;
|
||||||
|
|
||||||
|
use rustc::lint::LintPassObject;
|
||||||
|
use rustc::plugin::Registry;
|
||||||
|
|
||||||
|
mod lints;
|
||||||
|
mod macros;
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests;
|
||||||
|
|
||||||
|
|
||||||
|
#[plugin_registrar]
|
||||||
|
pub fn plugin_registrar(reg: &mut Registry) {
|
||||||
|
reg.register_lint_pass(box lints::TransmutePass as LintPassObject);
|
||||||
|
reg.register_lint_pass(box lints::UnrootedPass as LintPassObject);
|
||||||
|
}
|
||||||
|
|
|
@ -1,24 +1,6 @@
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
use syntax::{ast, codemap, visit};
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
||||||
|
|
||||||
#![feature(macro_rules, plugin_registrar, quote, phase)]
|
|
||||||
|
|
||||||
#![deny(unused_imports, unused_variable)]
|
|
||||||
|
|
||||||
//! Exports macros for use in other Servo crates.
|
|
||||||
|
|
||||||
extern crate syntax;
|
|
||||||
|
|
||||||
#[phase(plugin, link)]
|
|
||||||
extern crate rustc;
|
|
||||||
#[cfg(test)]
|
|
||||||
extern crate sync;
|
|
||||||
|
|
||||||
use syntax::ast;
|
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
use rustc::lint::{Context, LintPass, LintPassObject, LintArray};
|
use rustc::lint::{Context, LintPass, LintArray};
|
||||||
use rustc::plugin::Registry;
|
|
||||||
use rustc::middle::ty::expr_ty;
|
use rustc::middle::ty::expr_ty;
|
||||||
use rustc::middle::{ty, def};
|
use rustc::middle::{ty, def};
|
||||||
use rustc::middle::typeck::astconv::AstConv;
|
use rustc::middle::typeck::astconv::AstConv;
|
||||||
|
@ -29,8 +11,8 @@ declare_lint!(TRANSMUTE_TYPE_LINT, Allow,
|
||||||
declare_lint!(UNROOTED_MUST_ROOT, Deny,
|
declare_lint!(UNROOTED_MUST_ROOT, Deny,
|
||||||
"Warn and report usage of unrooted jsmanaged objects")
|
"Warn and report usage of unrooted jsmanaged objects")
|
||||||
|
|
||||||
struct TransmutePass;
|
pub struct TransmutePass;
|
||||||
struct UnrootedPass;
|
pub struct UnrootedPass;
|
||||||
|
|
||||||
impl LintPass for TransmutePass {
|
impl LintPass for TransmutePass {
|
||||||
fn get_lints(&self) -> LintArray {
|
fn get_lints(&self) -> LintArray {
|
||||||
|
@ -109,11 +91,11 @@ impl LintPass for UnrootedPass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_fn(&mut self, cx: &Context, kind: syntax::visit::FnKind, decl: &ast::FnDecl,
|
fn check_fn(&mut self, cx: &Context, kind: &visit::FnKind, decl: &ast::FnDecl,
|
||||||
block: &ast::Block, _span: syntax::codemap::Span, _id: ast::NodeId) {
|
block: &ast::Block, _span: codemap::Span, _id: ast::NodeId) {
|
||||||
match kind {
|
match *kind {
|
||||||
syntax::visit::FkItemFn(i, _, _, _) |
|
visit::FkItemFn(i, _, _, _) |
|
||||||
syntax::visit::FkMethod(i, _, _) if i.as_str() == "new" || i.as_str() == "new_inherited" => {
|
visit::FkMethod(i, _, _) if i.as_str() == "new" || i.as_str() == "new_inherited" => {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
@ -158,29 +140,4 @@ impl LintPass for UnrootedPass {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[plugin_registrar]
|
|
||||||
pub fn plugin_registrar(reg: &mut Registry) {
|
|
||||||
reg.register_lint_pass(box TransmutePass as LintPassObject);
|
|
||||||
reg.register_lint_pass(box UnrootedPass as LintPassObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[macro_export]
|
|
||||||
macro_rules! bitfield(
|
|
||||||
($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
|
|
||||||
impl $bitfieldname {
|
|
||||||
#[inline]
|
|
||||||
pub fn $getter(self) -> bool {
|
|
||||||
let $bitfieldname(this) = self;
|
|
||||||
(this & $value) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn $setter(&mut self, value: bool) {
|
|
||||||
let $bitfieldname(this) = *self;
|
|
||||||
*self = $bitfieldname((this & !$value) | (if value { $value } else { 0 }))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
20
components/plugins/macros.rs
Normal file
20
components/plugins/macros.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//! Exports macros for use in other Servo crates.
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! bitfield(
|
||||||
|
($bitfieldname:ident, $getter:ident, $setter:ident, $value:expr) => (
|
||||||
|
impl $bitfieldname {
|
||||||
|
#[inline]
|
||||||
|
pub fn $getter(self) -> bool {
|
||||||
|
let $bitfieldname(this) = self;
|
||||||
|
(this & $value) != 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn $setter(&mut self, value: bool) {
|
||||||
|
let $bitfieldname(this) = *self;
|
||||||
|
*self = $bitfieldname((this & !$value) | (if value { $value } else { 0 }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
34
components/plugins/tests.rs
Normal file
34
components/plugins/tests.rs
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
use std::collections::hashmap::HashMap;
|
||||||
|
|
||||||
|
lazy_init! {
|
||||||
|
static ref NUMBER: uint = times_two(3);
|
||||||
|
static ref VEC: [Box<uint>, ..3] = [box 1, box 2, box 3];
|
||||||
|
static ref OWNED_STRING: String = "hello".to_string();
|
||||||
|
static ref HASHMAP: HashMap<uint, &'static str> = {
|
||||||
|
let mut m = HashMap::new();
|
||||||
|
m.insert(0u, "abc");
|
||||||
|
m.insert(1, "def");
|
||||||
|
m.insert(2, "ghi");
|
||||||
|
m
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn times_two(n: uint) -> uint {
|
||||||
|
n * 2
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_basic() {
|
||||||
|
assert_eq!(*OWNED_STRING, "hello".to_string());
|
||||||
|
assert_eq!(*NUMBER, 6);
|
||||||
|
assert!(HASHMAP.find(&1).is_some());
|
||||||
|
assert!(HASHMAP.find(&3).is_none());
|
||||||
|
assert_eq!(VEC.as_slice(), &[box 1, box 2, box 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_repeat() {
|
||||||
|
assert_eq!(*NUMBER, 6);
|
||||||
|
assert_eq!(*NUMBER, 6);
|
||||||
|
assert_eq!(*NUMBER, 6);
|
||||||
|
}
|
|
@ -9,8 +9,8 @@ build = "make -f makefile.cargo"
|
||||||
name = "script"
|
name = "script"
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[dependencies.macros]
|
[dependencies.plugins]
|
||||||
path = "../macros"
|
path = "../plugins"
|
||||||
|
|
||||||
[dependencies.util]
|
[dependencies.util]
|
||||||
path = "../util"
|
path = "../util"
|
||||||
|
|
|
@ -33,7 +33,7 @@ extern crate time;
|
||||||
extern crate canvas;
|
extern crate canvas;
|
||||||
extern crate script_traits;
|
extern crate script_traits;
|
||||||
#[phase(plugin)]
|
#[phase(plugin)]
|
||||||
extern crate "macros" as servo_macros;
|
extern crate "plugins" as servo_plugins;
|
||||||
extern crate "net" as servo_net;
|
extern crate "net" as servo_net;
|
||||||
extern crate "util" as servo_util;
|
extern crate "util" as servo_util;
|
||||||
extern crate style;
|
extern crate style;
|
||||||
|
|
|
@ -11,8 +11,8 @@ path = "lib.rs"
|
||||||
|
|
||||||
doc = false
|
doc = false
|
||||||
|
|
||||||
[dependencies.macros]
|
[dependencies.plugins]
|
||||||
path = "../macros"
|
path = "../plugins"
|
||||||
|
|
||||||
[dependencies.util]
|
[dependencies.util]
|
||||||
path = "../util"
|
path = "../util"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue