Skip to content

Commit df222f9

Browse files
committed
---
yaml --- r: 14018 b: refs/heads/try c: 98450d0 h: refs/heads/master v: v3
1 parent cf5dcc9 commit df222f9

File tree

4 files changed

+69
-47
lines changed

4 files changed

+69
-47
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
refs/heads/master: 61b1875c16de39c166b0f4d54bba19f9c6777d1a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
5-
refs/heads/try: 5ef53382aeac2de7e6dcc43c156312d2e68c15e4
5+
refs/heads/try: 98450d0dade3c9a1b91a3384426cc4e824b82052
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/try/src/comp/syntax/ext/build.rs

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,78 @@ import syntax::ext::base::ext_ctxt;
66
// NOTE: Moved from fmt.rs which had this fixme:
77
// FIXME: Cleanup the naming of these functions
88

9-
fn make_new_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
9+
fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
1010
let sp_lit = @{node: lit, span: sp};
1111
ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp};
1212
}
13-
fn make_new_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
13+
fn mk_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
1414
let lit = ast::lit_str(s);
15-
ret make_new_lit(cx, sp, lit);
15+
ret mk_lit(cx, sp, lit);
1616
}
17-
fn make_new_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
17+
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
1818
let lit = ast::lit_int(i as i64, ast::ty_i);
19-
ret make_new_lit(cx, sp, lit);
19+
ret mk_lit(cx, sp, lit);
2020
}
21-
fn make_new_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
21+
fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
2222
let lit = ast::lit_uint(u as u64, ast::ty_u);
23-
ret make_new_lit(cx, sp, lit);
23+
ret mk_lit(cx, sp, lit);
2424
}
25-
fn make_add_expr(cx: ext_ctxt, sp: span, lhs: @ast::expr, rhs: @ast::expr)
25+
fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
26+
lhs: @ast::expr, rhs: @ast::expr)
2627
-> @ast::expr {
27-
let binexpr = ast::expr_binary(ast::add, lhs, rhs);
28+
let binexpr = ast::expr_binary(op, lhs, rhs);
2829
ret @{id: cx.next_id(), node: binexpr, span: sp};
2930
}
30-
fn make_path_expr(cx: ext_ctxt, sp: span, idents: [ast::ident]) ->
31-
@ast::expr {
31+
fn mk_unary(cx: ext_ctxt, sp: span, op: ast::unop, e: @ast::expr)
32+
-> @ast::expr {
33+
let expr = ast::expr_unary(op, e);
34+
ret @{id: cx.next_id(), node: expr, span: sp};
35+
}
36+
fn mk_path(cx: ext_ctxt, sp: span, idents: [ast::ident]) ->
37+
@ast::expr {
3238
let path = {global: false, idents: idents, types: []};
3339
let sp_path = @{node: path, span: sp};
3440
let pathexpr = ast::expr_path(sp_path);
3541
ret @{id: cx.next_id(), node: pathexpr, span: sp};
3642
}
37-
fn make_vec_expr(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) ->
43+
fn mk_access_(cx: ext_ctxt, sp: span, p: @ast::expr, m: ast::ident)
44+
-> @ast::expr {
45+
let expr = ast::expr_field(p, m, []);
46+
ret @{id: cx.next_id(), node: expr, span: sp};
47+
}
48+
fn mk_access(cx: ext_ctxt, sp: span, p: [ast::ident], m: ast::ident)
49+
-> @ast::expr {
50+
let pathexpr = mk_path(cx, sp, p);
51+
ret mk_access_(cx, sp, pathexpr, m);
52+
}
53+
fn mk_call_(cx: ext_ctxt, sp: span, fn_expr: @ast::expr,
54+
args: [@ast::expr]) -> @ast::expr {
55+
let callexpr = ast::expr_call(fn_expr, args, false);
56+
ret @{id: cx.next_id(), node: callexpr, span: sp};
57+
}
58+
fn mk_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident],
59+
args: [@ast::expr]) -> @ast::expr {
60+
let pathexpr = mk_path(cx, sp, fn_path);
61+
ret mk_call_(cx, sp, pathexpr, args);
62+
}
63+
// e = expr, t = type
64+
fn mk_vec_e(cx: ext_ctxt, sp: span, exprs: [@ast::expr]) ->
3865
@ast::expr {
3966
let vecexpr = ast::expr_vec(exprs, ast::imm);
4067
ret @{id: cx.next_id(), node: vecexpr, span: sp};
4168
}
42-
fn make_call(cx: ext_ctxt, sp: span, fn_path: [ast::ident],
43-
args: [@ast::expr]) -> @ast::expr {
44-
let pathexpr = make_path_expr(cx, sp, fn_path);
45-
let callexpr = ast::expr_call(pathexpr, args, false);
46-
ret @{id: cx.next_id(), node: callexpr, span: sp};
69+
fn mk_rec_e(cx: ext_ctxt, sp: span,
70+
fields: [{ident: ast::ident, ex: @ast::expr}]) ->
71+
@ast::expr {
72+
let astfields: [ast::field] = [];
73+
for field: {ident: ast::ident, ex: @ast::expr} in fields {
74+
let ident = field.ident;
75+
let val = field.ex;
76+
let astfield =
77+
{node: {mut: ast::imm, ident: ident, expr: val}, span: sp};
78+
astfields += [astfield];
79+
}
80+
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
81+
ret @{id: cx.next_id(), node: recexpr, span: sp};
4782
}
83+

branches/try/src/comp/syntax/ext/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn expand_expr(exts: hashmap<str, syntax_extension>, cx: ext_ctxt,
5656
fn expand_qquote(cx: ext_ctxt, sp: span, e: @ast::expr) -> ast::expr_ {
5757
import syntax::ext::build::*;
5858
let str = codemap::span_to_snippet(sp, cx.session().parse_sess.cm);
59-
let expr = make_new_str(cx, e.span, str);
59+
let expr = mk_str(cx, e.span, str);
6060
ret expr.node;
6161
}
6262

branches/try/src/comp/syntax/ext/fmt.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,12 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: span, arg: @ast::expr,
4545
// NOTE: Moved many of the common ones to build.rs --kevina
4646
fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
4747
-> @ast::expr {
48-
fn make_rec_expr(cx: ext_ctxt, sp: span,
49-
fields: [{ident: ast::ident, ex: @ast::expr}]) ->
50-
@ast::expr {
51-
let astfields: [ast::field] = [];
52-
for field: {ident: ast::ident, ex: @ast::expr} in fields {
53-
let ident = field.ident;
54-
let val = field.ex;
55-
let astfield =
56-
{node: {mut: ast::imm, ident: ident, expr: val}, span: sp};
57-
astfields += [astfield];
58-
}
59-
let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>);
60-
ret @{id: cx.next_id(), node: recexpr, span: sp};
61-
}
6248
fn make_path_vec(_cx: ext_ctxt, ident: ast::ident) -> [ast::ident] {
6349
ret ["extfmt", "rt", ident];
6450
}
6551
fn make_rt_path_expr(cx: ext_ctxt, sp: span, ident: str) -> @ast::expr {
6652
let path = make_path_vec(cx, ident);
67-
ret make_path_expr(cx, sp, path);
53+
ret mk_path(cx, sp, path);
6854
}
6955
// Produces an AST expression that represents a RT::conv record,
7056
// which tells the RT::conv* functions how to perform the conversion
@@ -90,18 +76,18 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
9076
if vec::len::<@ast::expr>(flagexprs) == 0u {
9177
flagexprs += [make_rt_path_expr(cx, sp, "flag_none")];
9278
}
93-
ret make_vec_expr(cx, sp, flagexprs);
79+
ret mk_vec_e(cx, sp, flagexprs);
9480
}
9581
fn make_count(cx: ext_ctxt, sp: span, cnt: count) -> @ast::expr {
9682
alt cnt {
9783
count_implied {
9884
ret make_rt_path_expr(cx, sp, "count_implied");
9985
}
10086
count_is(c) {
101-
let count_lit = make_new_int(cx, sp, c);
87+
let count_lit = mk_int(cx, sp, c);
10288
let count_is_path = make_path_vec(cx, "count_is");
10389
let count_is_args = [count_lit];
104-
ret make_call(cx, sp, count_is_path, count_is_args);
90+
ret mk_call(cx, sp, count_is_path, count_is_args);
10591
}
10692
_ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); }
10793
}
@@ -124,11 +110,11 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
124110
fn make_conv_rec(cx: ext_ctxt, sp: span, flags_expr: @ast::expr,
125111
width_expr: @ast::expr, precision_expr: @ast::expr,
126112
ty_expr: @ast::expr) -> @ast::expr {
127-
ret make_rec_expr(cx, sp,
128-
[{ident: "flags", ex: flags_expr},
129-
{ident: "width", ex: width_expr},
130-
{ident: "precision", ex: precision_expr},
131-
{ident: "ty", ex: ty_expr}]);
113+
ret mk_rec_e(cx, sp,
114+
[{ident: "flags", ex: flags_expr},
115+
{ident: "width", ex: width_expr},
116+
{ident: "precision", ex: precision_expr},
117+
{ident: "ty", ex: ty_expr}]);
132118
}
133119
let rt_conv_flags = make_flags(cx, sp, cnv.flags);
134120
let rt_conv_width = make_count(cx, sp, cnv.width);
@@ -143,7 +129,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
143129
let path = make_path_vec(cx, fname);
144130
let cnv_expr = make_rt_conv_expr(cx, sp, cnv);
145131
let args = [cnv_expr, arg];
146-
ret make_call(cx, arg.span, path, args);
132+
ret mk_call(cx, arg.span, path, args);
147133
}
148134
fn make_new_conv(cx: ext_ctxt, sp: span, cnv: conv, arg: @ast::expr) ->
149135
@ast::expr {
@@ -272,13 +258,13 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
272258
}
273259
let fmt_sp = args[0].span;
274260
let n = 0u;
275-
let tmp_expr = make_new_str(cx, sp, "");
261+
let tmp_expr = mk_str(cx, sp, "");
276262
let nargs = vec::len::<@ast::expr>(args);
277263
for pc: piece in pieces {
278264
alt pc {
279265
piece_string(s) {
280-
let s_expr = make_new_str(cx, fmt_sp, s);
281-
tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, s_expr);
266+
let s_expr = mk_str(cx, fmt_sp, s);
267+
tmp_expr = mk_binary(cx, fmt_sp, ast::add, tmp_expr, s_expr);
282268
}
283269
piece_conv(conv) {
284270
n += 1u;
@@ -291,7 +277,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span, pieces: [piece], args: [@ast::expr])
291277
log_conv(conv);
292278
let arg_expr = args[n];
293279
let c_expr = make_new_conv(cx, fmt_sp, conv, arg_expr);
294-
tmp_expr = make_add_expr(cx, fmt_sp, tmp_expr, c_expr);
280+
tmp_expr = mk_binary(cx, fmt_sp, ast::add, tmp_expr, c_expr);
295281
}
296282
}
297283
}

0 commit comments

Comments
 (0)