diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-25 17:00:12 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-27 15:54:44 -0700 |
| commit | 03119fe269de56e737562a9ee8d1bc47a9013eb4 (patch) | |
| tree | 043711359bd61d152c33a01a720b1982d5ccb69e /src/comp/syntax/ext | |
| parent | 652332f9d44d0c3eb36c220a88ef37f7f875206f (diff) | |
| download | rust-03119fe269de56e737562a9ee8d1bc47a9013eb4.tar.gz rust-03119fe269de56e737562a9ee8d1bc47a9013eb4.zip | |
Convert ast::ident to istr. Issue #855
Diffstat (limited to 'src/comp/syntax/ext')
| -rw-r--r-- | src/comp/syntax/ext/concat_idents.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/ext/fmt.rs | 20 | ||||
| -rw-r--r-- | src/comp/syntax/ext/ident_to_str.rs | 5 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 39 |
5 files changed, 36 insertions, 35 deletions
diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 466f55e60e6..0b88d09ec4d 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -11,7 +11,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, cx.span_fatal(sp, "#concat_idents requires a vector argument .") } }; - let res: ast::ident = ""; + let res: ast::ident = ~""; for e: @ast::expr in args { res += expr_to_ident(cx, e, "expected an ident"); } diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index 542b2805402..6a80b0b6cb2 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -24,10 +24,11 @@ fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt, mac_invoc(pth, args, body) { assert (vec::len(pth.node.idents) > 0u); let extname = pth.node.idents[0]; - alt exts.find(istr::from_estr(extname)) { + alt exts.find(extname) { none. { cx.span_fatal(pth.span, - #fmt["macro undefined: '%s'", extname]) + #fmt["macro undefined: '%s'", + istr::to_estr(extname)]) } some(normal(ext)) { let expanded = ext(cx, pth.span, args, body); diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index c70ea3234c4..093799714a7 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -100,16 +100,16 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], let recexpr = ast::expr_rec(astfields, option::none::<@ast::expr>); ret @{id: cx.next_id(), node: recexpr, span: sp}; } - fn make_path_vec(cx: &ext_ctxt, ident: str) -> [str] { + fn make_path_vec(cx: &ext_ctxt, ident: &ast::ident) -> [ast::ident] { fn compiling_std(cx: &ext_ctxt) -> bool { ret str::find(cx.crate_file_name(), "std.rc") >= 0; } if compiling_std(cx) { - ret ["extfmt", "rt", ident]; - } else { ret ["std", "extfmt", "rt", ident]; } + ret [~"extfmt", ~"rt", ident]; + } else { ret [~"std", ~"extfmt", ~"rt", ident]; } } fn make_rt_path_expr(cx: &ext_ctxt, sp: span, ident: str) -> @ast::expr { - let path = make_path_vec(cx, ident); + let path = make_path_vec(cx, istr::from_estr(ident)); ret make_path_expr(cx, sp, path); } // Produces an AST expression that represents a RT::conv record, @@ -145,7 +145,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } count_is(c) { let count_lit = make_new_int(cx, sp, c); - let count_is_path = make_path_vec(cx, "count_is"); + let count_is_path = make_path_vec(cx, ~"count_is"); let count_is_args = [count_lit]; ret make_call(cx, sp, count_is_path, count_is_args); } @@ -171,10 +171,10 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], width_expr: @ast::expr, precision_expr: @ast::expr, ty_expr: @ast::expr) -> @ast::expr { ret make_rec_expr(cx, sp, - [{ident: "flags", ex: flags_expr}, - {ident: "width", ex: width_expr}, - {ident: "precision", ex: precision_expr}, - {ident: "ty", ex: ty_expr}]); + [{ident: ~"flags", ex: flags_expr}, + {ident: ~"width", ex: width_expr}, + {ident: ~"precision", ex: precision_expr}, + {ident: ~"ty", ex: ty_expr}]); } let rt_conv_flags = make_flags(cx, sp, cnv.flags); let rt_conv_width = make_count(cx, sp, cnv.width); @@ -185,7 +185,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], } fn make_conv_call(cx: &ext_ctxt, sp: span, conv_type: str, cnv: &conv, arg: @ast::expr) -> @ast::expr { - let fname = "conv_" + conv_type; + let fname = ~"conv_" + istr::from_estr(conv_type); let path = make_path_vec(cx, fname); let cnv_expr = make_rt_conv_expr(cx, sp, cnv); let args = [cnv_expr, arg]; diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index 4eb381762fe..0664987e530 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -1,4 +1,5 @@ import std::vec; +import std::istr; import std::option; import base::*; import syntax::ast; @@ -17,8 +18,8 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, } ret make_new_lit(cx, sp, - ast::lit_str(expr_to_ident(cx, args[0u], - "expected an ident"), + ast::lit_str(istr::to_estr(expr_to_ident(cx, args[0u], + "expected an ident")), ast::sk_rc)); } diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index b0d7cd26020..94d814ae9c8 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -268,8 +268,8 @@ iter free_vars(b: &bindings, e: @expr) -> ident { let idents: hashmap<identistr, ()> = new_str_hash::<()>(); fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings, idents: &hashmap<identistr, ()>) -> ident { - if b.contains_key(istr::from_estr(i)) { - idents.insert(istr::from_estr(i), ()); + if b.contains_key(i) { + idents.insert(i, ()); } ret i; } @@ -281,7 +281,7 @@ iter free_vars(b: &bindings, e: @expr) -> ident { let f = make_fold(f_pre); f.fold_expr(e); // ignore result dummy_out(f); - for each id: identistr in idents.keys() { put istr::to_estr(id); } + for each id: identistr in idents.keys() { put id; } } @@ -298,7 +298,7 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], /* we need to walk over all the free vars in lockstep, except for the leaves, which are just duplicated */ for each fv: ident in free_vars(b, repeat_me) { - let cur_pos = follow(b.get(istr::from_estr(fv)), idx_path); + let cur_pos = follow(b.get(fv), idx_path); alt cur_pos { leaf(_) { } seq(ms, _) { @@ -310,8 +310,10 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], let len = vec::len(*ms); if old_len != len { let msg = - #fmt["'%s' occurs %u times, but ", fv, len] + - #fmt["'%s' occurs %u times", old_name, + #fmt["'%s' occurs %u times, but ", + istr::to_estr(fv), len] + + #fmt["'%s' occurs %u times", + istr::to_estr(old_name), old_len]; cx.span_fatal(repeat_me.span, msg); } @@ -350,7 +352,7 @@ fn transcribe_exprs(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], // substitute, in a position that's required to be an ident fn transcribe_ident(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], i: &ident, _fld: ast_fold) -> ident { - ret alt follow_for_trans(cx, b.find(istr::from_estr(i)), idx_path) { + ret alt follow_for_trans(cx, b.find(i), idx_path) { some(match_ident(a_id)) { a_id.node } some(m) { match_error(cx, m, "an identifier") } none. { i } @@ -362,8 +364,7 @@ fn transcribe_path(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], p: &path_, _fld: ast_fold) -> path_ { // Don't substitute into qualified names. if vec::len(p.types) > 0u || vec::len(p.idents) != 1u { ret p; } - ret alt follow_for_trans(cx, b.find( - istr::from_estr(p.idents[0])), idx_path) { + ret alt follow_for_trans(cx, b.find(p.idents[0]), idx_path) { some(match_ident(id)) { {global: false, idents: [id.node], types: []} } @@ -384,8 +385,7 @@ fn transcribe_expr(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], if vec::len(p.node.types) > 0u || vec::len(p.node.idents) != 1u { e } - alt follow_for_trans(cx, b.find( - istr::from_estr(p.node.idents[0])), idx_path) { + alt follow_for_trans(cx, b.find(p.node.idents[0]), idx_path) { some(match_ident(id)) { expr_path(respan(id.span, {global: false, @@ -409,8 +409,7 @@ fn transcribe_type(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], ast::ty_path(pth, _) { alt path_to_ident(pth) { some(id) { - alt follow_for_trans(cx, b.find( - istr::from_estr(id)), idx_path) { + alt follow_for_trans(cx, b.find(id), idx_path) { some(match_ty(ty)) { ty.node } some(m) { match_error(cx, m, "a type") } none. { orig(t, fld) } @@ -433,7 +432,7 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], ret alt block_to_ident(blk) { some(id) { alt follow_for_trans(cx, b.find( - istr::from_estr(id)), idx_path) { + id), idx_path) { some(match_block(new_blk)) { new_blk.node } @@ -534,10 +533,10 @@ fn p_t_s_r_path(cx: &ext_ctxt, p: &path, s: &selector, b: &binders) { _ { cx.bug("broken traversal in p_t_s_r") } } } - if b.real_binders.contains_key(istr::from_estr(p_id)) { + if b.real_binders.contains_key(p_id) { cx.span_fatal(p.span, "duplicate binding identifier"); } - b.real_binders.insert(istr::from_estr(p_id), + b.real_binders.insert(p_id, compose_sels(s, bind select(cx, _))); } none. { } @@ -584,7 +583,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } let final_step = bind select_pt_1(cx, _, select_pt_2); b.real_binders.insert( - istr::from_estr(id), compose_sels(s, final_step)); + id, compose_sels(s, final_step)); } none. { no_des(cx, pth.span, "under `#<>`"); } } @@ -604,7 +603,7 @@ fn p_t_s_r_mac(cx: &ext_ctxt, mac: &ast::mac, s: &selector, b: &binders) { } } let final_step = bind select_pt_1(cx, _, select_pt_2); - b.real_binders.insert(istr::from_estr(id), + b.real_binders.insert(id, compose_sels(s, final_step)); } none. { no_des(cx, blk.span, "under `#{}`"); } @@ -700,7 +699,7 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, } }; - let macro_name: option::t<str> = none; + let macro_name: option::t<istr> = none; let clauses: [@clause] = []; for arg: @expr in args { alt arg.node { @@ -760,7 +759,7 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, ret {ident: alt macro_name { - some(id) { id } + some(id) { istr::to_estr(id) } none. { cx.span_fatal(sp, "macro definition must have " + |
