Skip to content

Commit 628d3e9

Browse files
committed
Change (hopefully) all of the code that generates strs asts to produce ~strs.
1 parent f5e69d6 commit 628d3e9

File tree

8 files changed

+52
-36
lines changed

8 files changed

+52
-36
lines changed

src/libsyntax/ext/auto_serialize.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,13 @@ impl helpers for ext_ctxt {
222222
fn lit_str(span: span, s: @str/~) -> @ast::expr {
223223
self.expr(
224224
span,
225-
ast::expr_lit(
226-
@{node: ast::lit_str(s),
227-
span: span}))
225+
ast::expr_vstore(
226+
self.expr(
227+
span,
228+
ast::expr_lit(
229+
@{node: ast::lit_str(s),
230+
span: span})),
231+
ast::vstore_uniq))
228232
}
229233

230234
fn lit_uint(span: span, i: uint) -> @ast::expr {

src/libsyntax/ext/build.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
1111
let sp_lit = @{node: lit, span: sp};
1212
mk_expr(cx, sp, ast::expr_lit(sp_lit))
1313
}
14-
fn mk_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
15-
let lit = ast::lit_str(@s);
16-
ret mk_lit(cx, sp, lit);
17-
}
1814
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
1915
let lit = ast::lit_int(i as i64, ast::ty_i);
2016
ret mk_lit(cx, sp, lit);
@@ -23,6 +19,10 @@ fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
2319
let lit = ast::lit_uint(u as u64, ast::ty_u);
2420
ret mk_lit(cx, sp, lit);
2521
}
22+
fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr {
23+
let lit = ast::lit_uint(u as u64, ast::ty_u8);
24+
ret mk_lit(cx, sp, lit);
25+
}
2626
fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
2727
lhs: @ast::expr, rhs: @ast::expr)
2828
-> @ast::expr {
@@ -77,6 +77,13 @@ fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
7777
@ast::expr {
7878
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
7979
}
80+
fn mk_base_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
81+
let lit = ast::lit_str(@s);
82+
ret mk_lit(cx, sp, lit);
83+
}
84+
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
85+
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq)
86+
}
8087

8188
fn mk_rec_e(cx: ext_ctxt, sp: span,
8289
fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->

src/libsyntax/ext/env.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* interface.
66
*/
77
import base::*;
8-
import build::mk_lit;
8+
import build::mk_uniq_str;
99
export expand_syntax_ext;
1010

1111
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
@@ -17,14 +17,11 @@ fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
1717

1818
let var = expr_to_str(cx, args[0], "#env requires a string");
1919
alt os::getenv(var) {
20-
option::none { ret make_new_str(cx, sp, ""); }
21-
option::some(s) { ret make_new_str(cx, sp, s); }
20+
option::none { ret mk_uniq_str(cx, sp, ""); }
21+
option::some(s) { ret mk_uniq_str(cx, sp, s); }
2222
}
2323
}
2424

25-
fn make_new_str(cx: ext_ctxt, sp: codemap::span, +s: str) -> @ast::expr {
26-
ret mk_lit(cx, sp, ast::lit_str(@s));
27-
}
2825
//
2926
// Local Variables:
3027
// mode: rust

src/libsyntax/ext/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
249249
for pieces.each |pc| {
250250
alt pc {
251251
piece_string(s) {
252-
vec::push(piece_exprs, mk_str(cx, fmt_sp, s));
252+
vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s));
253253
}
254254
piece_conv(conv) {
255255
n += 1u;

src/libsyntax/ext/ident_to_str.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import base::*;
2-
import build::mk_lit;
2+
import build::mk_uniq_str;
33
import option;
44

55
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
66
_body: ast::mac_body) -> @ast::expr {
77
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),"ident_to_str");
88

9-
ret mk_lit(cx, sp,
10-
ast::lit_str(expr_to_ident(cx, args[0u],
11-
"expected an ident")));
9+
ret mk_uniq_str(cx, sp, *expr_to_ident(cx, args[0u],
10+
"expected an ident"));
1211
}

src/libsyntax/ext/qquote.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,15 @@ fn finish<T: qq_helper>
242242
~[@"syntax"/~, @"parse"/~, @"parser"/~,
243243
@"parse_from_source_str"/~],
244244
~[node.mk_parse_fn(cx,sp),
245-
mk_str(cx,sp, fname),
245+
mk_uniq_str(cx,sp, fname),
246246
mk_call(cx,sp,
247247
~[@"syntax"/~,@"ext"/~,
248248
@"qquote"/~, @"mk_file_substr"/~],
249-
~[mk_str(cx,sp, loc.file.name),
249+
~[mk_uniq_str(cx,sp, loc.file.name),
250250
mk_uint(cx,sp, loc.line),
251251
mk_uint(cx,sp, loc.col)]),
252252
mk_unary(cx,sp, ast::box(ast::m_imm),
253-
mk_str(cx,sp, str2)),
253+
mk_uniq_str(cx,sp, str2)),
254254
cfg_call(),
255255
parse_sess_call()]
256256
);

src/libsyntax/ext/source_util.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import base::*;
22
import ast;
33
import codemap::span;
44
import print::pprust;
5-
import build::{mk_lit,mk_uniq_vec_e};
5+
import build::{mk_uint,mk_u8,mk_uniq_str,mk_uniq_vec_e};
66

77
export expand_line;
88
export expand_col;
@@ -18,15 +18,15 @@ fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
1818
_body: ast::mac_body) -> @ast::expr {
1919
get_mac_args(cx, sp, arg, 0u, option::some(0u), "line");
2020
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
21-
ret mk_lit(cx, sp, ast::lit_uint(loc.line as u64, ast::ty_u));
21+
ret mk_uint(cx, sp, loc.line);
2222
}
2323

2424
/* #col(): expands to the current column number */
2525
fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
2626
_body: ast::mac_body) -> @ast::expr {
2727
get_mac_args(cx, sp, arg, 0u, option::some(0u), "col");
2828
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
29-
ret mk_lit(cx, sp, ast::lit_uint(loc.col as u64, ast::ty_u));
29+
ret mk_uint(cx, sp, loc.col);
3030
}
3131

3232
/* #file(): expands to the current filename */
@@ -37,20 +37,20 @@ fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
3737
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
3838
let { file: @{ name: filename, _ }, _ } =
3939
codemap::lookup_char_pos(cx.codemap(), sp.lo);
40-
ret mk_lit(cx, sp, ast::lit_str(@filename));
40+
ret mk_uniq_str(cx, sp, filename);
4141
}
4242

4343
fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
4444
_body: ast::mac_body) -> @ast::expr {
4545
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), "stringify");
46-
ret mk_lit(cx, sp, ast::lit_str(@pprust::expr_to_str(args[0])));
46+
ret mk_uniq_str(cx, sp, pprust::expr_to_str(args[0]));
4747
}
4848

4949
fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
5050
-> @ast::expr {
5151
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
52-
ret mk_lit(cx, sp, ast::lit_str(
53-
@str::connect(cx.mod_path().map(|x|*x), "::")));
52+
ret mk_uniq_str(cx, sp,
53+
str::connect(cx.mod_path().map(|x|*x), "::"));
5454
}
5555

5656
fn expand_include(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
@@ -77,7 +77,7 @@ fn expand_include_str(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
7777
}
7878
}
7979

80-
ret mk_lit(cx, sp, ast::lit_str(@result::unwrap(res)));
80+
ret mk_uniq_str(cx, sp, result::unwrap(res));
8181
}
8282

8383
fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
@@ -89,7 +89,7 @@ fn expand_include_bin(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
8989
alt io::read_whole_file(res_rel_file(cx, sp, file)) {
9090
result::ok(src) {
9191
let u8_exprs = vec::map(src, |char: u8| {
92-
mk_lit(cx, sp, ast::lit_uint(char as u64, ast::ty_u8))
92+
mk_u8(cx, sp, char)
9393
});
9494
ret mk_uniq_vec_e(cx, sp, u8_exprs);
9595
}

src/rustc/front/test.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,17 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
301301

302302
let name_lit: ast::lit =
303303
nospan(ast::lit_str(@ast_util::path_name_i(path)));
304-
let name_expr: ast::expr =
305-
{id: cx.sess.next_node_id(),
306-
callee_id: cx.sess.next_node_id(),
307-
node: ast::expr_lit(@name_lit),
308-
span: span};
304+
let name_expr_inner: @ast::expr =
305+
@{id: cx.sess.next_node_id(),
306+
callee_id: cx.sess.next_node_id(),
307+
node: ast::expr_lit(@name_lit),
308+
span: span};
309+
let name_expr = {id: cx.sess.next_node_id(),
310+
callee_id: cx.sess.next_node_id(),
311+
node: ast::expr_vstore(name_expr_inner,
312+
ast::vstore_uniq),
313+
span: dummy_sp()};
314+
309315

310316
let name_field: ast::field =
311317
nospan({mutbl: ast::m_imm, ident: @"name"/~, expr: @name_expr});
@@ -401,8 +407,11 @@ fn mk_test_wrapper(cx: test_ctxt,
401407

402408
fn mk_main(cx: test_ctxt) -> @ast::item {
403409
let str_pt = path_node(~[@"str"/~]);
410+
let str_ty_inner = @{id: cx.sess.next_node_id(),
411+
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
412+
span: dummy_sp()};
404413
let str_ty = @{id: cx.sess.next_node_id(),
405-
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
414+
node: ast::ty_vstore(str_ty_inner, ast::vstore_uniq),
406415
span: dummy_sp()};
407416
let args_mt = {ty: str_ty, mutbl: ast::m_imm};
408417
let args_ty_inner = @{id: cx.sess.next_node_id(),

0 commit comments

Comments
 (0)