Skip to content

Commit 6e50515

Browse files
committed
syntax/ext: migrate build.rs functions to AstBuilder methods.
1 parent 8c15a0e commit 6e50515

File tree

19 files changed

+1126
-925
lines changed

19 files changed

+1126
-925
lines changed

src/libsyntax/ext/build.rs

Lines changed: 783 additions & 547 deletions
Large diffs are not rendered by default.

src/libsyntax/ext/bytes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use ast;
1414
use codemap::span;
1515
use ext::base::*;
1616
use ext::base;
17-
use ext::build::{mk_u8, mk_slice_vec_e};
17+
use ext::build::AstBuilder;
1818

1919
pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> base::MacResult {
2020
// Gather all argument expressions
@@ -28,7 +28,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas
2828
// string literal, push each byte to vector expression
2929
ast::lit_str(s) => {
3030
for s.each |byte| {
31-
bytes.push(mk_u8(cx, sp, byte));
31+
bytes.push(cx.mk_u8(sp, byte));
3232
}
3333
}
3434

@@ -37,7 +37,7 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas
3737
if v > 0xFF {
3838
cx.span_err(sp, "Too large u8 literal in bytes!")
3939
} else {
40-
bytes.push(mk_u8(cx, sp, v as u8));
40+
bytes.push(cx.mk_u8(sp, v as u8));
4141
}
4242
}
4343

@@ -48,14 +48,14 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas
4848
} else if v < 0 {
4949
cx.span_err(sp, "Negative integer literal in bytes!")
5050
} else {
51-
bytes.push(mk_u8(cx, sp, v as u8));
51+
bytes.push(cx.mk_u8(sp, v as u8));
5252
}
5353
}
5454

5555
// char literal, push to vector expression
5656
ast::lit_int(v, ast::ty_char) => {
5757
if (v as char).is_ascii() {
58-
bytes.push(mk_u8(cx, sp, v as u8));
58+
bytes.push(cx.mk_u8(sp, v as u8));
5959
} else {
6060
cx.span_err(sp, "Non-ascii char literal in bytes!")
6161
}
@@ -68,6 +68,6 @@ pub fn expand_syntax_ext(cx: @ExtCtxt, sp: span, tts: &[ast::token_tree]) -> bas
6868
}
6969
}
7070

71-
let e = mk_slice_vec_e(cx, sp, bytes);
71+
let e = cx.mk_slice_vec_e(sp, bytes);
7272
MRExpr(e)
7373
}

src/libsyntax/ext/deriving/clone.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use ast::{meta_item, item, expr};
1212
use codemap::span;
1313
use ext::base::ExtCtxt;
1414
use ext::build;
15+
use ext::build::AstBuilder;
1516
use ext::deriving::generic::*;
1617

1718

@@ -79,7 +80,7 @@ fn cs_clone(
7980
let ctor_ident;
8081
let all_fields;
8182
let subcall = |field|
82-
build::mk_method_call(cx, span, field, clone_ident, ~[]);
83+
cx.mk_method_call(span, field, clone_ident, ~[]);
8384

8485
match *substr.fields {
8586
Struct(ref af) => {
@@ -102,7 +103,7 @@ fn cs_clone(
102103
[(None, _, _), .. _] => {
103104
// enum-like
104105
let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f));
105-
build::mk_call(cx, span, ctor_ident, subcalls)
106+
cx.mk_call(span, ctor_ident, subcalls)
106107
},
107108
_ => {
108109
// struct-like
@@ -118,9 +119,9 @@ fn cs_clone(
118119

119120
if fields.is_empty() {
120121
// no fields, so construct like `None`
121-
build::mk_path(cx, span, ctor_ident)
122+
cx.mk_path(span, ctor_ident)
122123
} else {
123-
build::mk_struct_e(cx, span,
124+
cx.mk_struct_e(span,
124125
ctor_ident,
125126
fields)
126127
}

src/libsyntax/ext/deriving/cmp/eq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use ast::{meta_item, item, expr};
1212
use codemap::span;
1313
use ext::base::ExtCtxt;
14-
use ext::build;
14+
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
1616

1717
pub fn expand_deriving_eq(cx: @ExtCtxt,
@@ -21,11 +21,11 @@ pub fn expand_deriving_eq(cx: @ExtCtxt,
2121
// structures are equal if all fields are equal, and non equal, if
2222
// any fields are not equal or if the enum variants are different
2323
fn cs_eq(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
24-
cs_and(|cx, span, _, _| build::mk_bool(cx, span, false),
24+
cs_and(|cx, span, _, _| cx.mk_bool(span, false),
2525
cx, span, substr)
2626
}
2727
fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
28-
cs_or(|cx, span, _, _| build::mk_bool(cx, span, true),
28+
cs_or(|cx, span, _, _| cx.mk_bool(span, true),
2929
cx, span, substr)
3030
}
3131

src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use ast::{meta_item, item, expr_if, expr};
1313
use codemap::span;
1414
use ext::base::ExtCtxt;
15-
use ext::build;
15+
use ext::build::AstBuilder;
1616
use ext::deriving::generic::*;
1717

1818
pub fn expand_deriving_ord(cx: @ExtCtxt,
@@ -62,10 +62,10 @@ fn cs_ord(less: bool, equal: bool,
6262
} else {
6363
cx.ident_of("gt")
6464
};
65-
let false_blk_expr = build::mk_block(cx, span,
65+
let false_blk_expr = cx.mk_block(span,
6666
~[], ~[],
67-
Some(build::mk_bool(cx, span, false)));
68-
let base = build::mk_bool(cx, span, equal);
67+
Some(cx.mk_bool(span, false)));
68+
let base = cx.mk_bool(span, equal);
6969

7070
cs_fold(
7171
false, // need foldr,
@@ -98,19 +98,19 @@ fn cs_ord(less: bool, equal: bool,
9898
cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`");
9999
}
100100

101-
let cmp = build::mk_method_call(cx, span,
101+
let cmp = cx.mk_method_call(span,
102102
self_f, cx.ident_of("eq"), other_fs.to_owned());
103-
let subexpr = build::mk_simple_block(cx, span, subexpr);
103+
let subexpr = cx.mk_simple_block(span, subexpr);
104104
let elseif = expr_if(cmp, subexpr, Some(false_blk_expr));
105-
let elseif = build::mk_expr(cx, span, elseif);
105+
let elseif = cx.mk_expr(span, elseif);
106106

107-
let cmp = build::mk_method_call(cx, span,
107+
let cmp = cx.mk_method_call(span,
108108
self_f, binop, other_fs.to_owned());
109-
let true_blk = build::mk_simple_block(cx, span,
110-
build::mk_bool(cx, span, true));
109+
let true_blk = cx.mk_simple_block(span,
110+
cx.mk_bool(span, true));
111111
let if_ = expr_if(cmp, true_blk, Some(elseif));
112112

113-
build::mk_expr(cx, span, if_)
113+
cx.mk_expr(span, if_)
114114
},
115115
base,
116116
|cx, span, args, _| {
@@ -119,7 +119,7 @@ fn cs_ord(less: bool, equal: bool,
119119
match args {
120120
[(self_var, _, _),
121121
(other_var, _, _)] =>
122-
build::mk_bool(cx, span,
122+
cx.mk_bool(span,
123123
if less {
124124
self_var < other_var
125125
} else {

src/libsyntax/ext/deriving/cmp/totaleq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use ast::{meta_item, item, expr};
1313
use codemap::span;
1414
use ext::base::ExtCtxt;
15-
use ext::build;
15+
use ext::build::AstBuilder;
1616
use ext::deriving::generic::*;
1717

1818
pub fn expand_deriving_totaleq(cx: @ExtCtxt,
@@ -21,7 +21,7 @@ pub fn expand_deriving_totaleq(cx: @ExtCtxt,
2121
in_items: ~[@item]) -> ~[@item] {
2222

2323
fn cs_equals(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
24-
cs_and(|cx, span, _, _| build::mk_bool(cx, span, false),
24+
cs_and(|cx, span, _, _| cx.mk_bool(span, false),
2525
cx, span, substr)
2626
}
2727

src/libsyntax/ext/deriving/cmp/totalord.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use ast::{meta_item, item, expr};
1212
use codemap::span;
1313
use ext::base::ExtCtxt;
14-
use ext::build;
14+
use ext::build::AstBuilder;
1515
use ext::deriving::generic::*;
1616
use core::cmp::{Ordering, Equal, Less, Greater};
1717

@@ -47,7 +47,7 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr {
4747
Equal => "Equal",
4848
Greater => "Greater"
4949
};
50-
build::mk_path_global(cx, span,
50+
cx.mk_path_global(span,
5151
~[cx.ident_of("core"),
5252
cx.ident_of("cmp"),
5353
cx.ident_of(cnst)])
@@ -60,7 +60,7 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span,
6060
// foldr (possibly) nests the matches in lexical_ordering better
6161
false,
6262
|cx, span, old, new| {
63-
build::mk_call_global(cx, span,
63+
cx.mk_call_global(span,
6464
~[cx.ident_of("core"),
6565
cx.ident_of("cmp"),
6666
cx.ident_of("lexical_ordering")],

0 commit comments

Comments
 (0)