mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
Change (hopefully) all of the code that generates strs asts to produce ~strs.
This commit is contained in:
parent
f5e69d611e
commit
628d3e9d38
@ -222,9 +222,13 @@ impl helpers for ext_ctxt {
|
||||
fn lit_str(span: span, s: @str/~) -> @ast::expr {
|
||||
self.expr(
|
||||
span,
|
||||
ast::expr_lit(
|
||||
@{node: ast::lit_str(s),
|
||||
span: span}))
|
||||
ast::expr_vstore(
|
||||
self.expr(
|
||||
span,
|
||||
ast::expr_lit(
|
||||
@{node: ast::lit_str(s),
|
||||
span: span})),
|
||||
ast::vstore_uniq))
|
||||
}
|
||||
|
||||
fn lit_uint(span: span, i: uint) -> @ast::expr {
|
||||
|
@ -11,10 +11,6 @@ fn mk_lit(cx: ext_ctxt, sp: span, lit: ast::lit_) -> @ast::expr {
|
||||
let sp_lit = @{node: lit, span: sp};
|
||||
mk_expr(cx, sp, ast::expr_lit(sp_lit))
|
||||
}
|
||||
fn mk_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
let lit = ast::lit_str(@s);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
}
|
||||
fn mk_int(cx: ext_ctxt, sp: span, i: int) -> @ast::expr {
|
||||
let lit = ast::lit_int(i as i64, ast::ty_i);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
@ -23,6 +19,10 @@ fn mk_uint(cx: ext_ctxt, sp: span, u: uint) -> @ast::expr {
|
||||
let lit = ast::lit_uint(u as u64, ast::ty_u);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
}
|
||||
fn mk_u8(cx: ext_ctxt, sp: span, u: u8) -> @ast::expr {
|
||||
let lit = ast::lit_uint(u as u64, ast::ty_u8);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
}
|
||||
fn mk_binary(cx: ext_ctxt, sp: span, op: ast::binop,
|
||||
lhs: @ast::expr, rhs: @ast::expr)
|
||||
-> @ast::expr {
|
||||
@ -77,6 +77,13 @@ fn mk_fixed_vec_e(cx: ext_ctxt, sp: span, exprs: ~[@ast::expr]) ->
|
||||
@ast::expr {
|
||||
mk_vstore_e(cx, sp, mk_base_vec_e(cx, sp, exprs), ast::vstore_fixed(none))
|
||||
}
|
||||
fn mk_base_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
let lit = ast::lit_str(@s);
|
||||
ret mk_lit(cx, sp, lit);
|
||||
}
|
||||
fn mk_uniq_str(cx: ext_ctxt, sp: span, s: str) -> @ast::expr {
|
||||
mk_vstore_e(cx, sp, mk_base_str(cx, sp, s), ast::vstore_uniq)
|
||||
}
|
||||
|
||||
fn mk_rec_e(cx: ext_ctxt, sp: span,
|
||||
fields: ~[{ident: ast::ident, ex: @ast::expr}]) ->
|
||||
|
@ -5,7 +5,7 @@
|
||||
* interface.
|
||||
*/
|
||||
import base::*;
|
||||
import build::mk_lit;
|
||||
import build::mk_uniq_str;
|
||||
export expand_syntax_ext;
|
||||
|
||||
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,
|
||||
|
||||
let var = expr_to_str(cx, args[0], "#env requires a string");
|
||||
alt os::getenv(var) {
|
||||
option::none { ret make_new_str(cx, sp, ""); }
|
||||
option::some(s) { ret make_new_str(cx, sp, s); }
|
||||
option::none { ret mk_uniq_str(cx, sp, ""); }
|
||||
option::some(s) { ret mk_uniq_str(cx, sp, s); }
|
||||
}
|
||||
}
|
||||
|
||||
fn make_new_str(cx: ext_ctxt, sp: codemap::span, +s: str) -> @ast::expr {
|
||||
ret mk_lit(cx, sp, ast::lit_str(@s));
|
||||
}
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
@ -249,7 +249,7 @@ fn pieces_to_expr(cx: ext_ctxt, sp: span,
|
||||
for pieces.each |pc| {
|
||||
alt pc {
|
||||
piece_string(s) {
|
||||
vec::push(piece_exprs, mk_str(cx, fmt_sp, s));
|
||||
vec::push(piece_exprs, mk_uniq_str(cx, fmt_sp, s));
|
||||
}
|
||||
piece_conv(conv) {
|
||||
n += 1u;
|
||||
|
@ -1,12 +1,11 @@
|
||||
import base::*;
|
||||
import build::mk_lit;
|
||||
import build::mk_uniq_str;
|
||||
import option;
|
||||
|
||||
fn expand_syntax_ext(cx: ext_ctxt, sp: codemap::span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx,sp,arg,1u,option::some(1u),"ident_to_str");
|
||||
|
||||
ret mk_lit(cx, sp,
|
||||
ast::lit_str(expr_to_ident(cx, args[0u],
|
||||
"expected an ident")));
|
||||
ret mk_uniq_str(cx, sp, *expr_to_ident(cx, args[0u],
|
||||
"expected an ident"));
|
||||
}
|
||||
|
@ -242,15 +242,15 @@ fn finish<T: qq_helper>
|
||||
~[@"syntax"/~, @"parse"/~, @"parser"/~,
|
||||
@"parse_from_source_str"/~],
|
||||
~[node.mk_parse_fn(cx,sp),
|
||||
mk_str(cx,sp, fname),
|
||||
mk_uniq_str(cx,sp, fname),
|
||||
mk_call(cx,sp,
|
||||
~[@"syntax"/~,@"ext"/~,
|
||||
@"qquote"/~, @"mk_file_substr"/~],
|
||||
~[mk_str(cx,sp, loc.file.name),
|
||||
~[mk_uniq_str(cx,sp, loc.file.name),
|
||||
mk_uint(cx,sp, loc.line),
|
||||
mk_uint(cx,sp, loc.col)]),
|
||||
mk_unary(cx,sp, ast::box(ast::m_imm),
|
||||
mk_str(cx,sp, str2)),
|
||||
mk_uniq_str(cx,sp, str2)),
|
||||
cfg_call(),
|
||||
parse_sess_call()]
|
||||
);
|
||||
|
@ -2,7 +2,7 @@ import base::*;
|
||||
import ast;
|
||||
import codemap::span;
|
||||
import print::pprust;
|
||||
import build::{mk_lit,mk_uniq_vec_e};
|
||||
import build::{mk_uint,mk_u8,mk_uniq_str,mk_uniq_vec_e};
|
||||
|
||||
export expand_line;
|
||||
export expand_col;
|
||||
@ -18,7 +18,7 @@ fn expand_line(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "line");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_lit(cx, sp, ast::lit_uint(loc.line as u64, ast::ty_u));
|
||||
ret mk_uint(cx, sp, loc.line);
|
||||
}
|
||||
|
||||
/* #col(): expands to the current column number */
|
||||
@ -26,7 +26,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "col");
|
||||
let loc = codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_lit(cx, sp, ast::lit_uint(loc.col as u64, ast::ty_u));
|
||||
ret mk_uint(cx, sp, loc.col);
|
||||
}
|
||||
|
||||
/* #file(): expands to the current filename */
|
||||
@ -37,20 +37,20 @@ fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
|
||||
let { file: @{ name: filename, _ }, _ } =
|
||||
codemap::lookup_char_pos(cx.codemap(), sp.lo);
|
||||
ret mk_lit(cx, sp, ast::lit_str(@filename));
|
||||
ret mk_uniq_str(cx, sp, filename);
|
||||
}
|
||||
|
||||
fn expand_stringify(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
|
||||
_body: ast::mac_body) -> @ast::expr {
|
||||
let args = get_mac_args(cx, sp, arg, 1u, option::some(1u), "stringify");
|
||||
ret mk_lit(cx, sp, ast::lit_str(@pprust::expr_to_str(args[0])));
|
||||
ret mk_uniq_str(cx, sp, pprust::expr_to_str(args[0]));
|
||||
}
|
||||
|
||||
fn expand_mod(cx: ext_ctxt, sp: span, arg: ast::mac_arg, _body: ast::mac_body)
|
||||
-> @ast::expr {
|
||||
get_mac_args(cx, sp, arg, 0u, option::some(0u), "file");
|
||||
ret mk_lit(cx, sp, ast::lit_str(
|
||||
@str::connect(cx.mod_path().map(|x|*x), "::")));
|
||||
ret mk_uniq_str(cx, sp,
|
||||
str::connect(cx.mod_path().map(|x|*x), "::"));
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
ret mk_lit(cx, sp, ast::lit_str(@result::unwrap(res)));
|
||||
ret mk_uniq_str(cx, sp, result::unwrap(res));
|
||||
}
|
||||
|
||||
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,
|
||||
alt io::read_whole_file(res_rel_file(cx, sp, file)) {
|
||||
result::ok(src) {
|
||||
let u8_exprs = vec::map(src, |char: u8| {
|
||||
mk_lit(cx, sp, ast::lit_uint(char as u64, ast::ty_u8))
|
||||
mk_u8(cx, sp, char)
|
||||
});
|
||||
ret mk_uniq_vec_e(cx, sp, u8_exprs);
|
||||
}
|
||||
|
@ -301,11 +301,17 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
|
||||
|
||||
let name_lit: ast::lit =
|
||||
nospan(ast::lit_str(@ast_util::path_name_i(path)));
|
||||
let name_expr: ast::expr =
|
||||
{id: cx.sess.next_node_id(),
|
||||
callee_id: cx.sess.next_node_id(),
|
||||
node: ast::expr_lit(@name_lit),
|
||||
span: span};
|
||||
let name_expr_inner: @ast::expr =
|
||||
@{id: cx.sess.next_node_id(),
|
||||
callee_id: cx.sess.next_node_id(),
|
||||
node: ast::expr_lit(@name_lit),
|
||||
span: span};
|
||||
let name_expr = {id: cx.sess.next_node_id(),
|
||||
callee_id: cx.sess.next_node_id(),
|
||||
node: ast::expr_vstore(name_expr_inner,
|
||||
ast::vstore_uniq),
|
||||
span: dummy_sp()};
|
||||
|
||||
|
||||
let name_field: ast::field =
|
||||
nospan({mutbl: ast::m_imm, ident: @"name"/~, expr: @name_expr});
|
||||
@ -401,8 +407,11 @@ fn mk_test_wrapper(cx: test_ctxt,
|
||||
|
||||
fn mk_main(cx: test_ctxt) -> @ast::item {
|
||||
let str_pt = path_node(~[@"str"/~]);
|
||||
let str_ty_inner = @{id: cx.sess.next_node_id(),
|
||||
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
|
||||
span: dummy_sp()};
|
||||
let str_ty = @{id: cx.sess.next_node_id(),
|
||||
node: ast::ty_path(str_pt, cx.sess.next_node_id()),
|
||||
node: ast::ty_vstore(str_ty_inner, ast::vstore_uniq),
|
||||
span: dummy_sp()};
|
||||
let args_mt = {ty: str_ty, mutbl: ast::m_imm};
|
||||
let args_ty_inner = @{id: cx.sess.next_node_id(),
|
||||
|
Loading…
Reference in New Issue
Block a user