diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-25 15:12:54 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-27 15:54:44 -0700 |
| commit | 652332f9d44d0c3eb36c220a88ef37f7f875206f (patch) | |
| tree | 61e00059bd5e16cc90b4f103cad5dff72f11fffb /src/comp/syntax/ext | |
| parent | faef9490ae724bce4802405f826d65988b2b7b05 (diff) | |
Convert std::map::new_str_hash to istrs. Issue #855
Diffstat (limited to 'src/comp/syntax/ext')
| -rw-r--r-- | src/comp/syntax/ext/base.rs | 15 | ||||
| -rw-r--r-- | src/comp/syntax/ext/expand.rs | 9 | ||||
| -rw-r--r-- | src/comp/syntax/ext/simplext.rs | 46 |
3 files changed, 43 insertions, 27 deletions
diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index 6d1bd6626c2..a354aa67090 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -1,3 +1,4 @@ +import std::istr; import std::vec; import std::option; import std::map::hashmap; @@ -19,17 +20,17 @@ tag syntax_extension { // A temporary hard-coded map of methods for expanding syntax extension // AST nodes into full ASTs -fn syntax_expander_table() -> hashmap<str, syntax_extension> { +fn syntax_expander_table() -> hashmap<istr, syntax_extension> { let syntax_expanders = new_str_hash::<syntax_extension>(); - syntax_expanders.insert("fmt", normal(ext::fmt::expand_syntax_ext)); - syntax_expanders.insert("env", normal(ext::env::expand_syntax_ext)); - syntax_expanders.insert("macro", + syntax_expanders.insert(~"fmt", normal(ext::fmt::expand_syntax_ext)); + syntax_expanders.insert(~"env", normal(ext::env::expand_syntax_ext)); + syntax_expanders.insert(~"macro", macro_defining(ext::simplext::add_new_extension)); - syntax_expanders.insert("concat_idents", + syntax_expanders.insert(~"concat_idents", normal(ext::concat_idents::expand_syntax_ext)); - syntax_expanders.insert("ident_to_str", + syntax_expanders.insert(~"ident_to_str", normal(ext::ident_to_str::expand_syntax_ext)); - syntax_expanders.insert("log_syntax", + syntax_expanders.insert(~"log_syntax", normal(ext::log_syntax::expand_syntax_ext)); ret syntax_expanders; } diff --git a/src/comp/syntax/ext/expand.rs b/src/comp/syntax/ext/expand.rs index 149216aa6cd..542b2805402 100644 --- a/src/comp/syntax/ext/expand.rs +++ b/src/comp/syntax/ext/expand.rs @@ -5,6 +5,7 @@ import std::option::some; import std::map::hashmap; import std::vec; +import std::istr; import syntax::ast::crate; import syntax::ast::expr_; @@ -14,7 +15,7 @@ import syntax::fold::*; import syntax::ext::base::*; -fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, +fn expand_expr(exts: &hashmap<istr, syntax_extension>, cx: &ext_ctxt, e: &expr_, fld: ast_fold, orig: &fn(&expr_, ast_fold) -> expr_) -> expr_ { ret alt e { @@ -23,7 +24,7 @@ fn expand_expr(exts: &hashmap<str, 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(extname) { + alt exts.find(istr::from_estr(extname)) { none. { cx.span_fatal(pth.span, #fmt["macro undefined: '%s'", extname]) @@ -40,7 +41,9 @@ fn expand_expr(exts: &hashmap<str, syntax_extension>, cx: &ext_ctxt, } some(macro_defining(ext)) { let named_extension = ext(cx, pth.span, args, body); - exts.insert(named_extension.ident, named_extension.ext); + exts.insert( + istr::from_estr(named_extension.ident), + named_extension.ext); ast::expr_rec([], none) } } diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index fb4402732ae..b0d7cd26020 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -2,6 +2,7 @@ use std; import codemap::span; import std::vec; +import std::istr; import std::option; import std::map::hashmap; import std::map::new_str_hash; @@ -18,6 +19,7 @@ import fold::*; import ast::node_id; import ast_util::respan; import ast::ident; +import ast::identistr; import ast::path; import ast::ty; import ast::blk; @@ -155,9 +157,9 @@ fn compose_sels(s1: selector, s2: selector) -> selector { type binders = - {real_binders: hashmap<ident, selector>, + {real_binders: hashmap<identistr, selector>, mutable literal_ast_matchers: [selector]}; -type bindings = hashmap<ident, arb_depth<matchable>>; +type bindings = hashmap<identistr, arb_depth<matchable>>; fn acumm_bindings(_cx: &ext_ctxt, _b_dest: &bindings, _b_src: &bindings) { } @@ -189,7 +191,8 @@ fn use_selectors_to_bind(b: &binders, e: @expr) -> option::t<bindings> { alt sel(match_expr(e)) { none. { ret none; } _ { } } } let never_mind: bool = false; - for each pair: @{key: ident, val: selector} in b.real_binders.items() { + for each pair: @{key: identistr, + val: selector} in b.real_binders.items() { alt pair.val(match_expr(e)) { none. { never_mind = true; } some(mtc) { res.insert(pair.key, mtc); } @@ -262,10 +265,12 @@ fn follow_for_trans(cx: &ext_ctxt, mmaybe: &option::t<arb_depth<matchable>>, /* helper for transcribe_exprs: what vars from `b` occur in `e`? */ iter free_vars(b: &bindings, e: @expr) -> ident { - let idents: hashmap<ident, ()> = new_str_hash::<()>(); + let idents: hashmap<identistr, ()> = new_str_hash::<()>(); fn mark_ident(i: &ident, _fld: ast_fold, b: &bindings, - idents: &hashmap<ident, ()>) -> ident { - if b.contains_key(i) { idents.insert(i, ()); } + idents: &hashmap<identistr, ()>) -> ident { + if b.contains_key(istr::from_estr(i)) { + idents.insert(istr::from_estr(i), ()); + } ret i; } // using fold is a hack: we want visit, but it doesn't hit idents ) : @@ -276,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: ident in idents.keys() { put id; } + for each id: identistr in idents.keys() { put istr::to_estr(id); } } @@ -293,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(fv), idx_path); + let cur_pos = follow(b.get(istr::from_estr(fv)), idx_path); alt cur_pos { leaf(_) { } seq(ms, _) { @@ -345,7 +350,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(i), idx_path) { + ret alt follow_for_trans(cx, b.find(istr::from_estr(i)), idx_path) { some(match_ident(a_id)) { a_id.node } some(m) { match_error(cx, m, "an identifier") } none. { i } @@ -357,7 +362,8 @@ 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(p.idents[0]), idx_path) { + ret alt follow_for_trans(cx, b.find( + istr::from_estr(p.idents[0])), idx_path) { some(match_ident(id)) { {global: false, idents: [id.node], types: []} } @@ -378,7 +384,8 @@ 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(p.node.idents[0]), idx_path) { + alt follow_for_trans(cx, b.find( + istr::from_estr(p.node.idents[0])), idx_path) { some(match_ident(id)) { expr_path(respan(id.span, {global: false, @@ -402,7 +409,8 @@ 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(id), idx_path) { + alt follow_for_trans(cx, b.find( + istr::from_estr(id)), idx_path) { some(match_ty(ty)) { ty.node } some(m) { match_error(cx, m, "a type") } none. { orig(t, fld) } @@ -424,7 +432,8 @@ fn transcribe_block(cx: &ext_ctxt, b: &bindings, idx_path: @mutable [uint], orig: fn(&blk_, ast_fold) -> blk_) -> blk_ { ret alt block_to_ident(blk) { some(id) { - alt follow_for_trans(cx, b.find(id), idx_path) { + alt follow_for_trans(cx, b.find( + istr::from_estr(id)), idx_path) { some(match_block(new_blk)) { new_blk.node } @@ -525,10 +534,11 @@ 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(p_id) { + if b.real_binders.contains_key(istr::from_estr(p_id)) { cx.span_fatal(p.span, "duplicate binding identifier"); } - b.real_binders.insert(p_id, compose_sels(s, bind select(cx, _))); + b.real_binders.insert(istr::from_estr(p_id), + compose_sels(s, bind select(cx, _))); } none. { } } @@ -573,7 +583,8 @@ 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(id, compose_sels(s, final_step)); + b.real_binders.insert( + istr::from_estr(id), compose_sels(s, final_step)); } none. { no_des(cx, pth.span, "under `#<>`"); } } @@ -593,7 +604,8 @@ 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(id, compose_sels(s, final_step)); + b.real_binders.insert(istr::from_estr(id), + compose_sels(s, final_step)); } none. { no_des(cx, blk.span, "under `#{}`"); } } |
