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 | |
| parent | faef9490ae724bce4802405f826d65988b2b7b05 (diff) | |
| download | rust-652332f9d44d0c3eb36c220a88ef37f7f875206f.tar.gz rust-652332f9d44d0c3eb36c220a88ef37f7f875206f.zip | |
Convert std::map::new_str_hash to istrs. Issue #855
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 5 | ||||
| -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 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 87 |
6 files changed, 92 insertions, 72 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index d44baebb6f3..d380fbecdb4 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -8,6 +8,8 @@ import codemap::filename; type spanned<T> = {node: T, span: span}; type ident = str; +type identistr = istr; + // Functions may or may not have names. type fn_ident = option::t<ident>; diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 15f41af5cac..687070da24f 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -1,4 +1,5 @@ import std::str; +import std::istr; import std::option; import codemap::span; import ast::*; @@ -43,7 +44,7 @@ fn def_id_of_def(d: def) -> def_id { } } -type pat_id_map = std::map::hashmap<str, ast::node_id>; +type pat_id_map = std::map::hashmap<istr, ast::node_id>; // This is used because same-named variables in alternative patterns need to // use the node_id of their namesake in the first pattern. @@ -51,7 +52,7 @@ fn pat_id_map(pat: &@pat) -> pat_id_map { let map = std::map::new_str_hash::<node_id>(); for each bound in pat_bindings(pat) { let name = alt bound.node { pat_bind(n) { n } }; - map.insert(name, bound.id); + map.insert(istr::from_estr(name), bound.id); } ret map; } 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 `#{}`"); } } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index b5d71a6ee9c..c0beb8a32c3 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -53,7 +53,7 @@ type parser = fn get_str(token::str_num) -> str; fn get_reader() -> lexer::reader; fn get_filemap() -> codemap::filemap; - fn get_bad_expr_words() -> hashmap<str, ()>; + fn get_bad_expr_words() -> hashmap<istr, ()>; fn get_chpos() -> uint; fn get_byte_pos() -> uint; fn get_id() -> node_id; @@ -84,7 +84,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, mutable restr: restriction, rdr: lexer::reader, precs: @[op_spec], - bad_words: hashmap<str, ()>) { + bad_words: hashmap<istr, ()>) { fn peek() -> token::token { ret tok; } fn bump() { last_tok_span = tok_span; @@ -132,7 +132,7 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, } fn get_reader() -> lexer::reader { ret rdr; } fn get_filemap() -> codemap::filemap { ret rdr.get_filemap(); } - fn get_bad_expr_words() -> hashmap<str, ()> { ret bad_words; } + fn get_bad_expr_words() -> hashmap<istr, ()> { ret bad_words; } fn get_chpos() -> uint { ret rdr.get_chpos(); } fn get_byte_pos() -> uint { ret rdr.get_byte_pos(); } fn get_id() -> node_id { ret next_node_id(sess); } @@ -148,44 +148,44 @@ fn new_parser(sess: parse_sess, cfg: ast::crate_cfg, rdr: lexer::reader, // These are the words that shouldn't be allowed as value identifiers, // because, if used at the start of a line, they will cause the line to be // interpreted as a specific kind of statement, which would be confusing. -fn bad_expr_word_table() -> hashmap<str, ()> { +fn bad_expr_word_table() -> hashmap<istr, ()> { let words = new_str_hash(); - words.insert("mod", ()); - words.insert("if", ()); - words.insert("else", ()); - words.insert("while", ()); - words.insert("do", ()); - words.insert("alt", ()); - words.insert("for", ()); - words.insert("each", ()); - words.insert("break", ()); - words.insert("cont", ()); - words.insert("put", ()); - words.insert("ret", ()); - words.insert("be", ()); - words.insert("fail", ()); - words.insert("type", ()); - words.insert("resource", ()); - words.insert("check", ()); - words.insert("assert", ()); - words.insert("claim", ()); - words.insert("prove", ()); - words.insert("native", ()); - words.insert("fn", ()); - words.insert("block", ()); - words.insert("lambda", ()); - words.insert("pure", ()); - words.insert("iter", ()); - words.insert("block", ()); - words.insert("import", ()); - words.insert("export", ()); - words.insert("let", ()); - words.insert("const", ()); - words.insert("log", ()); - words.insert("log_err", ()); - words.insert("tag", ()); - words.insert("obj", ()); - words.insert("copy", ()); + words.insert(~"mod", ()); + words.insert(~"if", ()); + words.insert(~"else", ()); + words.insert(~"while", ()); + words.insert(~"do", ()); + words.insert(~"alt", ()); + words.insert(~"for", ()); + words.insert(~"each", ()); + words.insert(~"break", ()); + words.insert(~"cont", ()); + words.insert(~"put", ()); + words.insert(~"ret", ()); + words.insert(~"be", ()); + words.insert(~"fail", ()); + words.insert(~"type", ()); + words.insert(~"resource", ()); + words.insert(~"check", ()); + words.insert(~"assert", ()); + words.insert(~"claim", ()); + words.insert(~"prove", ()); + words.insert(~"native", ()); + words.insert(~"fn", ()); + words.insert(~"block", ()); + words.insert(~"lambda", ()); + words.insert(~"pure", ()); + words.insert(~"iter", ()); + words.insert(~"block", ()); + words.insert(~"import", ()); + words.insert(~"export", ()); + words.insert(~"let", ()); + words.insert(~"const", ()); + words.insert(~"log", ()); + words.insert(~"log_err", ()); + words.insert(~"tag", ()); + words.insert(~"obj", ()); + words.insert(~"copy", ()); ret words; } @@ -273,7 +273,7 @@ fn check_bad_word(p: &parser) { alt p.peek() { token::IDENT(sid, false) { let w = p.get_str(sid); - if p.get_bad_expr_words().contains_key(w) { + if p.get_bad_expr_words().contains_key(istr::from_estr(w)) { p.fatal("found " + w + " in expression position"); } } @@ -1455,7 +1455,8 @@ fn parse_pat(p: &parser) -> @ast::pat { p.bump(); subpat = parse_pat(p); } else { - if p.get_bad_expr_words().contains_key(fieldname) { + if p.get_bad_expr_words() + .contains_key(istr::from_estr(fieldname)) { p.fatal("found " + fieldname + " in binding position"); } subpat = @@ -2061,7 +2062,7 @@ fn parse_item_tag(p: &parser, attrs: &[ast::attribute]) -> @ast::item { let variants: [ast::variant] = []; // Newtype syntax if p.peek() == token::EQ { - if p.get_bad_expr_words().contains_key(id) { + if p.get_bad_expr_words().contains_key(istr::from_estr(id)) { p.fatal("found " + id + " in tag constructor position"); } p.bump(); |
