Skip to content

Commit 7efbfea

Browse files
committed
Convert rustc::syntax::ext::base to istrs. Issue #855
1 parent 9857048 commit 7efbfea

File tree

7 files changed

+87
-82
lines changed

7 files changed

+87
-82
lines changed

src/comp/syntax/ext/base.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import codemap;
99

1010
type syntax_expander =
1111
fn(&ext_ctxt, span, @ast::expr, &option::t<istr>) -> @ast::expr;
12-
type macro_def = {ident: str, ext: syntax_extension};
12+
type macro_def = {ident: istr, ext: syntax_extension};
1313
type macro_definer =
1414
fn(&ext_ctxt, span, @ast::expr, &option::t<istr>) -> macro_def;
1515

@@ -36,9 +36,9 @@ fn syntax_expander_table() -> hashmap<istr, syntax_extension> {
3636
}
3737

3838
obj ext_ctxt(sess: @session,
39-
crate_file_name_hack: str,
39+
crate_file_name_hack: istr,
4040
mutable backtrace: codemap::opt_span) {
41-
fn crate_file_name() -> str { ret crate_file_name_hack; }
41+
fn crate_file_name() -> istr { ret crate_file_name_hack; }
4242

4343
fn session() -> @session { ret sess; }
4444

@@ -58,29 +58,29 @@ obj ext_ctxt(sess: @session,
5858
let tmp = pre;
5959
backtrace = tmp;
6060
}
61-
_ { self.bug("tried to pop without a push"); }
61+
_ { self.bug(~"tried to pop without a push"); }
6262
}
6363
}
6464

65-
fn span_fatal(sp: span, msg: str) -> ! {
65+
fn span_fatal(sp: span, msg: istr) -> ! {
6666
self.print_backtrace();
67-
sess.span_fatal(sp, istr::from_estr(msg));
67+
sess.span_fatal(sp, msg);
6868
}
69-
fn span_err(sp: span, msg: str) {
69+
fn span_err(sp: span, msg: istr) {
7070
self.print_backtrace();
71-
sess.span_err(sp, istr::from_estr(msg));
71+
sess.span_err(sp, msg);
7272
}
73-
fn span_unimpl(sp: span, msg: str) -> ! {
73+
fn span_unimpl(sp: span, msg: istr) -> ! {
7474
self.print_backtrace();
75-
sess.span_unimpl(sp, istr::from_estr(msg));
75+
sess.span_unimpl(sp, msg);
7676
}
77-
fn span_bug(sp: span, msg: str) -> ! {
77+
fn span_bug(sp: span, msg: istr) -> ! {
7878
self.print_backtrace();
79-
sess.span_bug(sp, istr::from_estr(msg));
79+
sess.span_bug(sp, msg);
8080
}
81-
fn bug(msg: str) -> ! {
81+
fn bug(msg: istr) -> ! {
8282
self.print_backtrace();
83-
sess.bug(istr::from_estr(msg));
83+
sess.bug(msg);
8484
}
8585
fn next_id() -> ast::node_id { ret sess.next_node_id(); }
8686

@@ -96,23 +96,24 @@ fn mk_ctxt(sess: &session) -> ext_ctxt {
9696
// super-ugly and needs a better solution.
9797
let crate_file_name_hack = sess.get_codemap().files[0].name;
9898

99-
ret ext_ctxt(@sess, istr::to_estr(crate_file_name_hack),
99+
ret ext_ctxt(@sess, crate_file_name_hack,
100100
codemap::os_none);
101101
}
102102

103-
fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: str) -> str {
103+
fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: &istr) -> istr {
104104
alt expr.node {
105105
ast::expr_lit(l) {
106106
alt l.node {
107-
ast::lit_str(s, _) { ret istr::to_estr(s); }
107+
ast::lit_str(s, _) { ret s; }
108108
_ { cx.span_fatal(l.span, error); }
109109
}
110110
}
111111
_ { cx.span_fatal(expr.span, error); }
112112
}
113113
}
114114

115-
fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr, error: str) -> ast::ident {
115+
fn expr_to_ident(cx: &ext_ctxt, expr: @ast::expr,
116+
error: &istr) -> ast::ident {
116117
alt expr.node {
117118
ast::expr_path(p) {
118119
if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u {

src/comp/syntax/ext/concat_idents.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
88
alt arg.node {
99
ast::expr_vec(elts, _) { elts }
1010
_ {
11-
cx.span_fatal(sp, "#concat_idents requires a vector argument .")
11+
cx.span_fatal(sp, ~"#concat_idents requires a vector argument .")
1212
}
1313
};
1414
let res: ast::ident = ~"";
1515
for e: @ast::expr in args {
16-
res += expr_to_ident(cx, e, "expected an ident");
16+
res += expr_to_ident(cx, e, ~"expected an ident");
1717
}
1818

1919
ret @{id: cx.next_id(),

src/comp/syntax/ext/env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
1717
alt arg.node {
1818
ast::expr_vec(elts, _) { elts }
1919
_ {
20-
cx.span_fatal(sp, "#env requires arguments of the form `[...]`.")
20+
cx.span_fatal(sp, ~"#env requires arguments of the form `[...]`.")
2121
}
2222
};
2323
if vec::len::<@ast::expr>(args) != 1u {
24-
cx.span_fatal(sp, "malformed #env call");
24+
cx.span_fatal(sp, ~"malformed #env call");
2525
}
2626
// FIXME: if this was more thorough it would manufacture an
2727
// option::t<str> rather than just an maybe-empty string.
2828

29-
let var = expr_to_str(cx, args[0], "#env requires a string");
30-
alt generic_os::getenv(istr::from_estr(var)) {
29+
let var = expr_to_str(cx, args[0], ~"#env requires a string");
30+
alt generic_os::getenv(var) {
3131
option::none. { ret make_new_str(cx, sp, ""); }
3232
option::some(s) {
3333
ret make_new_str(cx, sp, istr::to_estr(s));

src/comp/syntax/ext/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt,
2626
let extname = pth.node.idents[0];
2727
alt exts.find(extname) {
2828
none. {
29-
cx.span_fatal(pth.span,
29+
cx.span_fatal(pth.span, istr::from_estr(
3030
#fmt["macro undefined: '%s'",
31-
istr::to_estr(extname)])
31+
istr::to_estr(extname)]))
3232
}
3333
some(normal(ext)) {
3434
let expanded = ext(cx, pth.span, args, body);
@@ -43,13 +43,13 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt,
4343
some(macro_defining(ext)) {
4444
let named_extension = ext(cx, pth.span, args, body);
4545
exts.insert(
46-
istr::from_estr(named_extension.ident),
46+
named_extension.ident,
4747
named_extension.ext);
4848
ast::expr_rec([], none)
4949
}
5050
}
5151
}
52-
_ { cx.span_bug(mac.span, "naked syntactic bit") }
52+
_ { cx.span_bug(mac.span, ~"naked syntactic bit") }
5353
}
5454
}
5555
_ { orig(e, fld) }

src/comp/syntax/ext/fmt.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,24 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr,
2222
alt arg.node {
2323
ast::expr_vec(elts, _) { elts }
2424
_ {
25-
cx.span_fatal(sp, "#fmt requires arguments of the form `[...]`.")
25+
cx.span_fatal(sp, ~"#fmt requires arguments of the form `[...]`.")
2626
}
2727
};
2828
if vec::len::<@ast::expr>(args) == 0u {
29-
cx.span_fatal(sp, "#fmt requires a format string");
29+
cx.span_fatal(sp, ~"#fmt requires a format string");
3030
}
3131
let fmt =
3232
expr_to_str(cx, args[0],
33-
"first argument to #fmt must be a " + "string literal.");
33+
~"first argument to #fmt must be a "
34+
+ ~"string literal.");
3435
let fmtspan = args[0].span;
3536
log "Format string:";
3637
log fmt;
3738
fn parse_fmt_err_(cx: &ext_ctxt, sp: span, msg: str) -> ! {
38-
cx.span_fatal(sp, msg);
39+
cx.span_fatal(sp, istr::from_estr(msg));
3940
}
4041
let parse_fmt_err = bind parse_fmt_err_(cx, fmtspan, _);
41-
let pieces = parse_fmt_string(fmt, parse_fmt_err);
42+
let pieces = parse_fmt_string(istr::to_estr(fmt), parse_fmt_err);
4243
ret pieces_to_expr(cx, sp, pieces, args);
4344
}
4445

@@ -102,7 +103,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
102103
}
103104
fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] {
104105
fn compiling_std(cx: &ext_ctxt) -> bool {
105-
ret str::find(cx.crate_file_name(), "std.rc") >= 0;
106+
ret istr::find(cx.crate_file_name(), ~"std.rc") >= 0;
106107
}
107108
if compiling_std(cx) {
108109
ret [~"extfmt", ~"rt", ident];
@@ -149,7 +150,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
149150
let count_is_args = [count_lit];
150151
ret make_call(cx, sp, count_is_path, count_is_args);
151152
}
152-
_ { cx.span_unimpl(sp, "unimplemented #fmt conversion"); }
153+
_ { cx.span_unimpl(sp, ~"unimplemented #fmt conversion"); }
153154
}
154155
}
155156
fn make_ty(cx: &ext_ctxt, sp: span, t: &ty) -> @ast::expr {
@@ -203,7 +204,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
203204
_ { ret false; }
204205
}
205206
}
206-
let unsupported = "conversion not supported in #fmt string";
207+
let unsupported = ~"conversion not supported in #fmt string";
207208
alt cnv.param {
208209
option::none. { }
209210
_ { cx.span_unimpl(sp, unsupported); }
@@ -214,15 +215,15 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
214215
flag_sign_always. {
215216
if !is_signed_type(cnv) {
216217
cx.span_fatal(sp,
217-
"+ flag only valid in " +
218-
"signed #fmt conversion");
218+
~"+ flag only valid in " +
219+
~"signed #fmt conversion");
219220
}
220221
}
221222
flag_space_for_sign. {
222223
if !is_signed_type(cnv) {
223224
cx.span_fatal(sp,
224-
"space flag only valid in " +
225-
"signed #fmt conversions");
225+
~"space flag only valid in " +
226+
~"signed #fmt conversions");
226227
}
227228
}
228229
flag_left_zero_pad. { }
@@ -330,8 +331,8 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
330331
n += 1u;
331332
if n >= nargs {
332333
cx.span_fatal(sp,
333-
"not enough arguments to #fmt " +
334-
"for the given format string");
334+
~"not enough arguments to #fmt " +
335+
~"for the given format string");
335336
}
336337
log "Building conversion:";
337338
log_conv(conv);
@@ -345,9 +346,9 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece],
345346

346347
if expected_nargs < nargs {
347348
cx.span_fatal(
348-
sp,
349+
sp, istr::from_estr(
349350
#fmt["too many arguments to #fmt. found %u, expected %u",
350-
nargs, expected_nargs]);
351+
nargs, expected_nargs]));
351352
}
352353
ret tmp_expr;
353354
}

src/comp/syntax/ext/ident_to_str.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr,
1010
alt arg.node {
1111
ast::expr_vec(elts, _) { elts }
1212
_ {
13-
cx.span_fatal(sp, "#ident_to_str requires a vector argument .")
13+
cx.span_fatal(sp, ~"#ident_to_str requires a vector argument .")
1414
}
1515
};
1616
if vec::len::<@ast::expr>(args) != 1u {
17-
cx.span_fatal(sp, "malformed #ident_to_str call");
17+
cx.span_fatal(sp, ~"malformed #ident_to_str call");
1818
}
1919

2020
ret make_new_lit(cx, sp,
2121
ast::lit_str(expr_to_ident(cx, args[0u],
22-
"expected an ident"),
22+
~"expected an ident"),
2323
ast::sk_rc));
2424

2525
}

0 commit comments

Comments
 (0)