Skip to content

Commit a59bec4

Browse files
committed
syntax/ext: convert all AstBuilder methods to a uniform syntax.
1 parent 6e50515 commit a59bec4

21 files changed

+998
-1686
lines changed

src/libsyntax/ext/build.rs

+520-1,042
Large diffs are not rendered by default.

src/libsyntax/ext/bytes.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -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(cx.mk_u8(sp, byte));
31+
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
40+
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
51+
bytes.push(cx.expr_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(cx.mk_u8(sp, v as u8));
58+
bytes.push(cx.expr_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 = cx.mk_slice_vec_e(sp, bytes);
71+
let e = cx.expr_vec_slice(sp, bytes);
7272
MRExpr(e)
7373
}

src/libsyntax/ext/deriving/clone.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use ast::{meta_item, item, expr};
1212
use codemap::span;
1313
use ext::base::ExtCtxt;
14-
use ext::build;
1514
use ext::build::AstBuilder;
1615
use ext::deriving::generic::*;
1716

@@ -80,15 +79,15 @@ fn cs_clone(
8079
let ctor_ident;
8180
let all_fields;
8281
let subcall = |field|
83-
cx.mk_method_call(span, field, clone_ident, ~[]);
82+
cx.expr_method_call(span, field, clone_ident, ~[]);
8483

8584
match *substr.fields {
8685
Struct(ref af) => {
87-
ctor_ident = ~[ substr.type_ident ];
86+
ctor_ident = substr.type_ident;
8887
all_fields = af;
8988
}
9089
EnumMatching(_, variant, ref af) => {
91-
ctor_ident = ~[ variant.node.name ];
90+
ctor_ident = variant.node.name;
9291
all_fields = af;
9392
},
9493
EnumNonMatching(*) => cx.span_bug(span,
@@ -103,7 +102,7 @@ fn cs_clone(
103102
[(None, _, _), .. _] => {
104103
// enum-like
105104
let subcalls = all_fields.map(|&(_, self_f, _)| subcall(self_f));
106-
cx.mk_call(span, ctor_ident, subcalls)
105+
cx.expr_call_ident(span, ctor_ident, subcalls)
107106
},
108107
_ => {
109108
// struct-like
@@ -114,16 +113,14 @@ fn cs_clone(
114113
fmt!("unnamed field in normal struct in `deriving(%s)`",
115114
name))
116115
};
117-
build::Field { ident: ident, ex: subcall(self_f) }
116+
cx.field_imm(span, ident, subcall(self_f))
118117
};
119118

120119
if fields.is_empty() {
121120
// no fields, so construct like `None`
122-
cx.mk_path(span, ctor_ident)
121+
cx.expr_ident(span, ctor_ident)
123122
} else {
124-
cx.mk_struct_e(span,
125-
ctor_ident,
126-
fields)
123+
cx.expr_struct_ident(span, ctor_ident, fields)
127124
}
128125
}
129126
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -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, _, _| cx.mk_bool(span, false),
24+
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
2525
cx, span, substr)
2626
}
2727
fn cs_ne(cx: @ExtCtxt, span: span, substr: &Substructure) -> @expr {
28-
cs_or(|cx, span, _, _| cx.mk_bool(span, true),
28+
cs_or(|cx, span, _, _| cx.expr_bool(span, true),
2929
cx, span, substr)
3030
}
3131

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

+11-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use ast::{meta_item, item, expr_if, expr};
12+
use ast::{meta_item, item, expr};
1313
use codemap::span;
1414
use ext::base::ExtCtxt;
1515
use ext::build::AstBuilder;
@@ -62,10 +62,7 @@ fn cs_ord(less: bool, equal: bool,
6262
} else {
6363
cx.ident_of("gt")
6464
};
65-
let false_blk_expr = cx.mk_block(span,
66-
~[], ~[],
67-
Some(cx.mk_bool(span, false)));
68-
let base = cx.mk_bool(span, equal);
65+
let base = cx.expr_bool(span, equal);
6966

7067
cs_fold(
7168
false, // need foldr,
@@ -98,19 +95,15 @@ fn cs_ord(less: bool, equal: bool,
9895
cx.span_bug(span, "Not exactly 2 arguments in `deriving(Ord)`");
9996
}
10097

101-
let cmp = cx.mk_method_call(span,
102-
self_f, cx.ident_of("eq"), other_fs.to_owned());
103-
let subexpr = cx.mk_simple_block(span, subexpr);
104-
let elseif = expr_if(cmp, subexpr, Some(false_blk_expr));
105-
let elseif = cx.mk_expr(span, elseif);
98+
let cmp = cx.expr_method_call(span,
99+
self_f, cx.ident_of("eq"), other_fs.to_owned());
100+
let elseif = cx.expr_if(span, cmp,
101+
subexpr, Some(cx.expr_bool(span, false)));
106102

107-
let cmp = cx.mk_method_call(span,
108-
self_f, binop, other_fs.to_owned());
109-
let true_blk = cx.mk_simple_block(span,
110-
cx.mk_bool(span, true));
111-
let if_ = expr_if(cmp, true_blk, Some(elseif));
112-
113-
cx.mk_expr(span, if_)
103+
let cmp = cx.expr_method_call(span,
104+
self_f, binop, other_fs.to_owned());
105+
cx.expr_if(span, cmp,
106+
cx.expr_bool(span, true), Some(elseif))
114107
},
115108
base,
116109
|cx, span, args, _| {
@@ -119,7 +112,7 @@ fn cs_ord(less: bool, equal: bool,
119112
match args {
120113
[(self_var, _, _),
121114
(other_var, _, _)] =>
122-
cx.mk_bool(span,
115+
cx.expr_bool(span,
123116
if less {
124117
self_var < other_var
125118
} else {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -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, _, _| cx.mk_bool(span, false),
24+
cs_and(|cx, span, _, _| cx.expr_bool(span, false),
2525
cx, span, substr)
2626
}
2727

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

+10-9
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ pub fn ordering_const(cx: @ExtCtxt, span: span, cnst: Ordering) -> @expr {
4747
Equal => "Equal",
4848
Greater => "Greater"
4949
};
50-
cx.mk_path_global(span,
51-
~[cx.ident_of("core"),
52-
cx.ident_of("cmp"),
53-
cx.ident_of(cnst)])
50+
cx.expr_path(
51+
cx.path_global(span,
52+
~[cx.ident_of("core"),
53+
cx.ident_of("cmp"),
54+
cx.ident_of(cnst)]))
5455
}
5556

5657
pub fn cs_cmp(cx: @ExtCtxt, span: span,
@@ -60,11 +61,11 @@ pub fn cs_cmp(cx: @ExtCtxt, span: span,
6061
// foldr (possibly) nests the matches in lexical_ordering better
6162
false,
6263
|cx, span, old, new| {
63-
cx.mk_call_global(span,
64-
~[cx.ident_of("core"),
65-
cx.ident_of("cmp"),
66-
cx.ident_of("lexical_ordering")],
67-
~[old, new])
64+
cx.expr_call_global(span,
65+
~[cx.ident_of("core"),
66+
cx.ident_of("cmp"),
67+
cx.ident_of("lexical_ordering")],
68+
~[old, new])
6869
},
6970
ordering_const(cx, span, Equal),
7071
|cx, span, list, _| {

0 commit comments

Comments
 (0)