Skip to content

Commit

Permalink
Use path helper macros in deriving
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan McAllister committed Feb 7, 2015
1 parent ce5aad2 commit 74eef05
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn expand_deriving_clone<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "clone", "Clone")),
path: path!(std::clone::Clone),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/cmp/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
ret_ty: Literal(path!(bool)),
attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| {
$f(a, b, c)
Expand All @@ -82,7 +82,7 @@ pub fn expand_deriving_eq<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "cmp", "PartialEq")),
path: path!(std::cmp::PartialEq),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/ext/deriving/cmp/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("bool"))),
ret_ty: Literal(path!(bool)),
attributes: attrs,
combine_substructure: combine_substructure(box |cx, span, substr| {
cs_op($op, $equal, cx, span, substr)
Expand All @@ -45,8 +45,8 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
} }
}

let ordering_ty = Literal(Path::new(vec!["std", "cmp", "Ordering"]));
let ret_ty = Literal(Path::new_(vec!["std", "option", "Option"],
let ordering_ty = Literal(path!(std::cmp::Ordering));
let ret_ty = Literal(Path::new_(pathvec!(std::option::Option),
None,
vec![box ordering_ty],
true));
Expand All @@ -69,7 +69,7 @@ pub fn expand_deriving_ord<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: vec![],
path: Path::new(vec!["std", "cmp", "PartialOrd"]),
path: path!(std::cmp::PartialOrd),
additional_bounds: vec![],
generics: LifetimeBounds::empty(),
methods: vec![
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/cmp/totaleq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn expand_deriving_totaleq<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "cmp", "Eq")),
path: path!(std::cmp::Eq),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/cmp/totalord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "cmp", "Ord")),
path: path!(std::cmp::Ord),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand All @@ -39,7 +39,7 @@ pub fn expand_deriving_totalord<F>(cx: &mut ExtCtxt,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(borrowed_self()),
ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))),
ret_ty: Literal(path!(std::cmp::Ordering)),
attributes: attrs,
combine_substructure: combine_substructure(box |a, b, c| {
cs_cmp(a, b, c)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/decodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn expand_deriving_decodable_imp<F>(cx: &mut ExtCtxt,
args: vec!(Ptr(box Literal(Path::new_local("__D")),
Borrowed(None, MutMutable))),
ret_ty: Literal(Path::new_(
vec!("std", "result", "Result"),
pathvec!(std::result::Result),
None,
vec!(box Self, box Literal(Path::new_(
vec!["__D", "Error"], None, vec![], false
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn expand_deriving_default<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "default", "Default")),
path: path!(std::default::Default),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/deriving/encodable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn expand_deriving_encodable_imp<F>(cx: &mut ExtCtxt,
args: vec!(Ptr(box Literal(Path::new_local("__S")),
Borrowed(None, MutMutable))),
ret_ty: Literal(Path::new_(
vec!("std", "result", "Result"),
pathvec!(std::result::Result),
None,
vec!(box Tuple(Vec::new()), box Literal(Path::new_(
vec!["__S", "Error"], None, vec![], false
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/deriving/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ pub fn expand_deriving_hash<F>(cx: &mut ExtCtxt,
F: FnOnce(P<Item>),
{

let path = Path::new_(vec!("std", "hash", "Hash"), None,
let path = Path::new_(pathvec!(std::hash::Hash), None,
vec!(box Literal(Path::new_local("__S"))), true);
let generics = LifetimeBounds {
lifetimes: Vec::new(),
bounds: vec!(("__S",
vec!(Path::new(vec!("std", "hash", "Writer")),
Path::new(vec!("std", "hash", "Hasher"))))),
vec!(path!(std::hash::Writer),
path!(std::hash::Hasher)))),
};
let args = Path::new_local("__S");
let inline = cx.meta_word(span, InternedString::new("inline"));
Expand Down
12 changes: 12 additions & 0 deletions src/libsyntax/ext/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ use ext::base::ExtCtxt;
use codemap::Span;
use ptr::P;

macro_rules! pathvec {
($($x:ident)::+) => (
vec![ $( stringify!($x) ),+ ]
)
}

macro_rules! path {
($($x:tt)*) => (
::ext::deriving::generic::ty::Path::new( pathvec!( $($x)* ) )
)
}

pub mod bounds;
pub mod clone;
pub mod encodable;
Expand Down
12 changes: 5 additions & 7 deletions src/libsyntax/ext/deriving/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,16 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "num", "FromPrimitive")),
path: path!(std::num::FromPrimitive),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
MethodDef {
name: "from_i64",
generics: LifetimeBounds::empty(),
explicit_self: None,
args: vec!(
Literal(Path::new(vec!("i64")))),
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
args: vec!(Literal(path!(i64))),
ret_ty: Literal(Path::new_(pathvec!(std::option::Option),
None,
vec!(box Self),
true)),
Expand All @@ -54,9 +53,8 @@ pub fn expand_deriving_from_primitive<F>(cx: &mut ExtCtxt,
name: "from_u64",
generics: LifetimeBounds::empty(),
explicit_self: None,
args: vec!(
Literal(Path::new(vec!("u64")))),
ret_ty: Literal(Path::new_(vec!("std", "option", "Option"),
args: vec!(Literal(path!(u64))),
ret_ty: Literal(Path::new_(pathvec!(std::option::Option),
None,
vec!(box Self),
true)),
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/deriving/rand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!("std", "rand", "Rand")),
path: path!(std::rand::Rand),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec!(
Expand All @@ -40,7 +40,7 @@ pub fn expand_deriving_rand<F>(cx: &mut ExtCtxt,
generics: LifetimeBounds {
lifetimes: Vec::new(),
bounds: vec!(("R",
vec!( Path::new(vec!("std", "rand", "Rng")) )))
vec!( path!(std::rand::Rng) ))),
},
explicit_self: None,
args: vec!(
Expand Down
6 changes: 3 additions & 3 deletions src/libsyntax/ext/deriving/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
F: FnOnce(P<Item>),
{
// &mut ::std::fmt::Formatter
let fmtr = Ptr(box Literal(Path::new(vec!("std", "fmt", "Formatter"))),
let fmtr = Ptr(box Literal(path!(std::fmt::Formatter)),
Borrowed(None, ast::MutMutable));

let trait_def = TraitDef {
span: span,
attributes: Vec::new(),
path: Path::new(vec!["std", "fmt", "Debug"]),
path: path!(std::fmt::Debug),
additional_bounds: Vec::new(),
generics: LifetimeBounds::empty(),
methods: vec![
Expand All @@ -44,7 +44,7 @@ pub fn expand_deriving_show<F>(cx: &mut ExtCtxt,
generics: LifetimeBounds::empty(),
explicit_self: borrowed_explicit_self(),
args: vec!(fmtr),
ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))),
ret_ty: Literal(path!(std::fmt::Result)),
attributes: Vec::new(),
combine_substructure: combine_substructure(box |a, b, c| {
show_substructure(a, b, c)
Expand Down

0 comments on commit 74eef05

Please sign in to comment.