From f09ef6ec66b0a204c52cc67a6c91a69da65a5407 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 26 Aug 2011 18:48:08 -0700 Subject: [PATCH] Convert rest of the AST to istrs. Issue #855 --- src/comp/back/link.rs | 4 ++-- src/comp/front/attr.rs | 4 ++-- src/comp/front/test.rs | 4 +++- src/comp/metadata/creader.rs | 17 +++++++++++------ src/comp/metadata/encoder.rs | 2 +- src/comp/middle/trans.rs | 10 ++++++---- src/comp/syntax/ast.rs | 12 ++++++------ src/comp/syntax/ext/base.rs | 6 +++--- src/comp/syntax/ext/concat_idents.rs | 2 +- src/comp/syntax/ext/env.rs | 4 ++-- src/comp/syntax/ext/fmt.rs | 4 ++-- src/comp/syntax/ext/ident_to_str.rs | 6 +++--- src/comp/syntax/ext/log_syntax.rs | 2 +- src/comp/syntax/ext/simplext.rs | 5 +++-- src/comp/syntax/parse/parser.rs | 16 ++++++++++------ src/comp/syntax/print/pprust.rs | 16 ++++++++++------ 16 files changed, 66 insertions(+), 48 deletions(-) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 1b12c3181637..77f3cf671cc4 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -324,12 +324,12 @@ fn build_link_meta(sess: &session::session, c: &ast::crate, output: &istr, for meta: @ast::meta_item in linkage_metas { if attr::get_meta_item_name(meta) == ~"name" { alt attr::get_meta_item_value_str(meta) { - some(v) { name = some(istr::from_estr(v)); } + some(v) { name = some(v); } none. { cmh_items += [meta]; } } } else if attr::get_meta_item_name(meta) == ~"vers" { alt attr::get_meta_item_value_str(meta) { - some(v) { vers = some(istr::from_estr(v)); } + some(v) { vers = some(v); } none. { cmh_items += [meta]; } } } else { cmh_items += [meta]; } diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index 711f9f670395..8bc0ce941fb8 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -81,7 +81,7 @@ fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident { // Gets the string value if the meta_item is a meta_name_value variant // containing a string, otherwise none -fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t { +fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t { alt meta.node { ast::meta_name_value(_, v) { alt v.node { @@ -196,7 +196,7 @@ fn span<@T>(item: &T) -> ast::spanned { } fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item { - let value_lit = span(ast::lit_str(value, ast::sk_rc)); + let value_lit = span(ast::lit_str(istr::from_estr(value), ast::sk_rc)); ret mk_name_value_item(name, value_lit); } diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index 425736c2d5c4..4d027c867bbe 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -2,6 +2,7 @@ import std::option; import std::vec; +import std::istr; import syntax::ast; import syntax::ast_util; import syntax::ast_util::*; @@ -249,7 +250,8 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { log #fmt["encoding %s", ast_util::path_name_i(path)]; let name_lit: ast::lit = - nospan(ast::lit_str(ast_util::path_name_i(path), ast::sk_rc)); + nospan(ast::lit_str( + istr::from_estr(ast_util::path_name_i(path)), ast::sk_rc)); let name_expr: ast::expr = {id: cx.next_node_id(), node: ast::expr_lit(@name_lit), diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index 00cdd808179e..f7b9473867b0 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -68,11 +68,14 @@ fn visit_item(e: env, i: &@ast::item) { ret; } let cstore = e.sess.get_cstore(); - if !cstore::add_used_library(cstore, m.native_name) { ret; } + if !cstore::add_used_library(cstore, + istr::to_estr(m.native_name)) { ret; } for a: ast::attribute in attr::find_attrs_by_name(i.attrs, ~"link_args") { alt attr::get_meta_item_value_str(attr::attr_meta(a)) { - some(linkarg) { cstore::add_used_link_args(cstore, linkarg); } + some(linkarg) { + cstore::add_used_link_args(cstore, istr::to_estr(linkarg)); + } none. {/* fallthrough */ } } } @@ -133,19 +136,21 @@ fn find_library_crate(sess: &session::session, ident: &ast::ident, some(i) { alt attr::get_meta_item_value_str(i) { some(n) { n } - _ { istr::to_estr(ident) } + _ { ident } } } - none. { istr::to_estr(ident) } + none. { ident } } }; let nn = default_native_lib_naming(sess, sess.get_opts().static); let x = - find_library_crate_aux(nn, crate_name, metas, library_search_paths); + find_library_crate_aux(nn, istr::to_estr(crate_name), + metas, library_search_paths); if x != none || sess.get_opts().static { ret x; } let nn2 = default_native_lib_naming(sess, true); - ret find_library_crate_aux(nn2, crate_name, metas, library_search_paths); + ret find_library_crate_aux(nn2, istr::to_estr(crate_name), + metas, library_search_paths); } fn find_library_crate_aux(nn: &{prefix: str, suffix: str}, crate_name: str, diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index b842b900e6cc..d0f5f6452839 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -465,7 +465,7 @@ fn encode_meta_item(ebml_w: &ebml::writer, mi: &meta_item) { ebml_w.writer.write(istr::bytes(name)); ebml::end_tag(ebml_w); ebml::start_tag(ebml_w, tag_meta_item_value); - ebml_w.writer.write(str::bytes(value)); + ebml_w.writer.write(istr::bytes(value)); ebml::end_tag(ebml_w); ebml::end_tag(ebml_w); } diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index 3b4764b7aa7e..c0cf7c6b53b7 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -2523,16 +2523,16 @@ fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef { } ret C_integral(t, i as uint, s); } - ast::lit_float(fs) { ret C_float(istr::from_estr(fs)); } + ast::lit_float(fs) { ret C_float(fs); } ast::lit_mach_float(tm, s) { let t = T_float(); alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } } - ret C_floating(istr::from_estr(s), t); + ret C_floating(s, t); } ast::lit_char(c) { ret C_integral(T_char(), c as uint, False); } ast::lit_bool(b) { ret C_bool(b); } ast::lit_nil. { ret C_nil(); } - ast::lit_str(s, ast::sk_rc.) { ret C_str(cx, istr::from_estr(s)); } + ast::lit_str(s, ast::sk_rc.) { ret C_str(cx, s); } ast::lit_str(s, ast::sk_unique.) { cx.sess.span_unimpl(lit.span, "unique string in this context"); } @@ -2541,7 +2541,9 @@ fn trans_crate_lit(cx: &@crate_ctxt, lit: &ast::lit) -> ValueRef { fn trans_lit(cx: &@block_ctxt, lit: &ast::lit) -> result { alt lit.node { - ast::lit_str(s, ast::sk_unique.) { ret trans_lit_istr(cx, s); } + ast::lit_str(s, ast::sk_unique.) { + ret trans_lit_istr(cx, istr::to_estr(s)); + } _ { ret rslt(cx, trans_crate_lit(bcx_ccx(cx), lit)); } } } diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index edbc1f829fc6..44ed863351eb 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -237,7 +237,7 @@ tag blk_sort { type mac = spanned; tag mac_ { - mac_invoc(path, @expr, option::t); + mac_invoc(path, @expr, option::t); mac_embed_type(@ty); mac_embed_block(blk); mac_ellipsis; @@ -246,13 +246,13 @@ tag mac_ { type lit = spanned; tag lit_ { - lit_str(str, seq_kind); + lit_str(istr, seq_kind); lit_char(char); lit_int(int); lit_uint(uint); lit_mach_int(ty_mach, int); - lit_float(str); - lit_mach_float(ty_mach, str); + lit_float(istr); + lit_mach_float(ty_mach, istr); lit_nil; lit_bool(bool); } @@ -421,7 +421,7 @@ tag native_abi { } type native_mod = - {native_name: str, + {native_name: istr, abi: native_abi, view_items: [@view_item], items: [@native_item]}; @@ -494,7 +494,7 @@ type native_item = tag native_item_ { native_item_ty; - native_item_fn(option::t, fn_decl, [ty_param]); + native_item_fn(option::t, fn_decl, [ty_param]); } // diff --git a/src/comp/syntax/ext/base.rs b/src/comp/syntax/ext/base.rs index a354aa67090f..d9cdb54ad304 100644 --- a/src/comp/syntax/ext/base.rs +++ b/src/comp/syntax/ext/base.rs @@ -8,10 +8,10 @@ import std::map::new_str_hash; import codemap; type syntax_expander = - fn(&ext_ctxt, span, @ast::expr, option::t) -> @ast::expr; + fn(&ext_ctxt, span, @ast::expr, &option::t) -> @ast::expr; type macro_def = {ident: str, ext: syntax_extension}; type macro_definer = - fn(&ext_ctxt, span, @ast::expr, option::t) -> macro_def; + fn(&ext_ctxt, span, @ast::expr, &option::t) -> macro_def; tag syntax_extension { normal(syntax_expander); @@ -100,7 +100,7 @@ fn expr_to_str(cx: &ext_ctxt, expr: @ast::expr, error: str) -> str { alt expr.node { ast::expr_lit(l) { alt l.node { - ast::lit_str(s, _) { ret s; } + ast::lit_str(s, _) { ret istr::to_estr(s); } _ { cx.span_fatal(l.span, error); } } } diff --git a/src/comp/syntax/ext/concat_idents.rs b/src/comp/syntax/ext/concat_idents.rs index 0b88d09ec4d8..0ac2ef0debe6 100644 --- a/src/comp/syntax/ext/concat_idents.rs +++ b/src/comp/syntax/ext/concat_idents.rs @@ -3,7 +3,7 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option::t) -> @ast::expr { + _body: &option::t) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } diff --git a/src/comp/syntax/ext/env.rs b/src/comp/syntax/ext/env.rs index 75fca2398ebc..f2cd093edaeb 100644 --- a/src/comp/syntax/ext/env.rs +++ b/src/comp/syntax/ext/env.rs @@ -12,7 +12,7 @@ import base::*; export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option::t) -> @ast::expr { + _body: &option::t) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -36,7 +36,7 @@ fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, } fn make_new_str(cx: &ext_ctxt, sp: codemap::span, s: str) -> @ast::expr { - ret make_new_lit(cx, sp, ast::lit_str(s, ast::sk_rc)); + ret make_new_lit(cx, sp, ast::lit_str(istr::from_estr(s), ast::sk_rc)); } // // Local Variables: diff --git a/src/comp/syntax/ext/fmt.rs b/src/comp/syntax/ext/fmt.rs index 2a441341f499..2173cfba40fb 100644 --- a/src/comp/syntax/ext/fmt.rs +++ b/src/comp/syntax/ext/fmt.rs @@ -17,7 +17,7 @@ import codemap::span; export expand_syntax_ext; fn expand_syntax_ext(cx: &ext_ctxt, sp: span, arg: @ast::expr, - _body: option::t) -> @ast::expr { + _body: &option::t) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -52,7 +52,7 @@ fn pieces_to_expr(cx: &ext_ctxt, sp: span, pieces: &[piece], ret @{id: cx.next_id(), node: ast::expr_lit(sp_lit), span: sp}; } fn make_new_str(cx: &ext_ctxt, sp: span, s: str) -> @ast::expr { - let lit = ast::lit_str(s, ast::sk_rc); + let lit = ast::lit_str(istr::from_estr(s), ast::sk_rc); ret make_new_lit(cx, sp, lit); } fn make_new_int(cx: &ext_ctxt, sp: span, i: int) -> @ast::expr { diff --git a/src/comp/syntax/ext/ident_to_str.rs b/src/comp/syntax/ext/ident_to_str.rs index 0664987e5309..ec176dd2fa33 100644 --- a/src/comp/syntax/ext/ident_to_str.rs +++ b/src/comp/syntax/ext/ident_to_str.rs @@ -5,7 +5,7 @@ import base::*; import syntax::ast; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option::t) -> @ast::expr { + _body: &option::t) -> @ast::expr { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -18,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(istr::to_estr(expr_to_ident(cx, args[0u], - "expected an ident")), + ast::lit_str(expr_to_ident(cx, args[0u], + "expected an ident"), ast::sk_rc)); } diff --git a/src/comp/syntax/ext/log_syntax.rs b/src/comp/syntax/ext/log_syntax.rs index 3cf240097dc9..3cab1dbd915e 100644 --- a/src/comp/syntax/ext/log_syntax.rs +++ b/src/comp/syntax/ext/log_syntax.rs @@ -4,7 +4,7 @@ import syntax::ast; import std::istr; fn expand_syntax_ext(cx: &ext_ctxt, sp: codemap::span, arg: @ast::expr, - _body: option::t) -> @ast::expr { + _body: &option::t) -> @ast::expr { cx.print_backtrace(); std::io::stdout().write_line( diff --git a/src/comp/syntax/ext/simplext.rs b/src/comp/syntax/ext/simplext.rs index 55f54c3057cf..eca20e2225eb 100644 --- a/src/comp/syntax/ext/simplext.rs +++ b/src/comp/syntax/ext/simplext.rs @@ -688,7 +688,7 @@ fn p_t_s_r_actual_vector(cx: &ext_ctxt, elts: [@expr], _repeat_after: bool, } fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: option::t) -> base::macro_def { + _body: &option::t) -> base::macro_def { let args: [@ast::expr] = alt arg.node { ast::expr_vec(elts, _) { elts } @@ -768,7 +768,8 @@ fn add_new_extension(cx: &ext_ctxt, sp: span, arg: @expr, ext: normal(ext)}; fn generic_extension(cx: &ext_ctxt, sp: span, arg: @expr, - _body: option::t, clauses: [@clause]) -> @expr { + _body: &option::t, + clauses: [@clause]) -> @expr { for c: @clause in clauses { alt use_selectors_to_bind(c.params, arg) { some(bindings) { ret transcribe(cx, bindings, c.body) } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 85f809ef9653..ce3b917118ec 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -696,7 +696,7 @@ fn parse_lit(p: &parser) -> ast::lit { token::LIT_UINT(u) { p.bump(); lit = ast::lit_uint(u); } token::LIT_FLOAT(s) { p.bump(); - lit = ast::lit_float(p.get_str(s)); + lit = ast::lit_float(istr::from_estr(p.get_str(s))); } token::LIT_MACH_INT(tm, i) { p.bump(); @@ -704,12 +704,12 @@ fn parse_lit(p: &parser) -> ast::lit { } token::LIT_MACH_FLOAT(tm, s) { p.bump(); - lit = ast::lit_mach_float(tm, p.get_str(s)); + lit = ast::lit_mach_float(tm, istr::from_estr(p.get_str(s))); } token::LIT_CHAR(c) { p.bump(); lit = ast::lit_char(c); } token::LIT_STR(s) { p.bump(); - lit = ast::lit_str(p.get_str(s), ast::sk_rc); + lit = ast::lit_str(istr::from_estr(p.get_str(s)), ast::sk_rc); } token::LPAREN. { p.bump(); @@ -896,7 +896,8 @@ fn parse_bottom_expr(p: &parser) -> @ast::expr { let sp = p.get_span(); p.bump(); let lit = - @{node: ast::lit_str(p.get_str(s), ast::sk_unique), + @{node: ast::lit_str(istr::from_estr(p.get_str(s)), + ast::sk_unique), span: sp}; ex = ast::expr_lit(lit); } @@ -1971,7 +1972,10 @@ fn parse_item_native_fn(p: &parser, attrs: &[ast::attribute]) -> let t = parse_fn_header(p); let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal); let link_name = none; - if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); } + if p.peek() == token::EQ { + p.bump(); + link_name = some(istr::from_estr(parse_str(p))); + } let hi = p.get_hi_pos(); expect(p, token::SEMI); ret @{ident: t.ident, @@ -2006,7 +2010,7 @@ fn parse_native_mod_items(p: &parser, native_name: &str, initial_attrs = []; items += [parse_native_item(p, attrs)]; } - ret {native_name: native_name, + ret {native_name: istr::from_estr(native_name), abi: abi, view_items: view_items, items: items}; diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 530b16a20377..9fff1a8be802 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -371,7 +371,11 @@ fn print_native_item(s: &ps, item: &@ast::native_item) { decl.constraints); alt lname { none. { } - some(ss) { space(s.s); word_space(s, "="); print_string(s, ss); } + some(ss) { + space(s.s); + word_space(s, "="); + print_string(s, istr::to_estr(ss)); + } } end(s); // end head-ibox word(s.s, ";"); @@ -426,9 +430,9 @@ fn print_item(s: &ps, item: &@ast::item) { } word_nbsp(s, "mod"); word_nbsp(s, istr::to_estr(item.ident)); - if !str::eq(nmod.native_name, istr::to_estr(item.ident)) { + if !istr::eq(nmod.native_name, item.ident) { word_space(s, "="); - print_string(s, nmod.native_name); + print_string(s, istr::to_estr(nmod.native_name)); nbsp(s); } bopen(s); @@ -1505,7 +1509,7 @@ fn print_literal(s: &ps, lit: &@ast::lit) { alt lit.node { ast::lit_str(st, kind) { if kind == ast::sk_unique { word(s.s, "~"); } - print_string(s, st); + print_string(s, istr::to_estr(st)); } ast::lit_char(ch) { word(s.s, @@ -1514,14 +1518,14 @@ fn print_literal(s: &ps, lit: &@ast::lit) { } ast::lit_int(val) { word(s.s, istr::to_estr(int::str(val))); } ast::lit_uint(val) { word(s.s, istr::to_estr(uint::str(val)) + "u"); } - ast::lit_float(fstr) { word(s.s, fstr); } + ast::lit_float(fstr) { word(s.s, istr::to_estr(fstr)); } ast::lit_mach_int(mach, val) { word(s.s, istr::to_estr(int::str(val as int))); word(s.s, ast_util::ty_mach_to_str(mach)); } ast::lit_mach_float(mach, val) { // val is already a str - word(s.s, val); + word(s.s, istr::to_estr(val)); word(s.s, ast_util::ty_mach_to_str(mach)); } ast::lit_nil. { word(s.s, "()"); }