diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-08-24 21:26:19 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-08-27 15:54:43 -0700 |
| commit | fcc031c5b4dc8f64c497b8dd1e066068e862bd72 (patch) | |
| tree | d31401261cbe92f9d5039c193dfcb66b3767e018 /src/comp/metadata | |
| parent | 20178b9312675f4889bd656916a1f32cbacc94d6 (diff) | |
| download | rust-fcc031c5b4dc8f64c497b8dd1e066068e862bd72.tar.gz rust-fcc031c5b4dc8f64c497b8dd1e066068e862bd72.zip | |
Convert std::io to istrs. Issue #855
Diffstat (limited to 'src/comp/metadata')
| -rw-r--r-- | src/comp/metadata/creader.rs | 3 | ||||
| -rw-r--r-- | src/comp/metadata/decoder.rs | 27 | ||||
| -rw-r--r-- | src/comp/metadata/encoder.rs | 9 | ||||
| -rw-r--r-- | src/comp/metadata/tyencode.rs | 76 |
4 files changed, 64 insertions, 51 deletions
diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index c13de2d6f9d..e06f0ca455f 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -86,7 +86,8 @@ fn list_file_metadata(path: str, out: io::writer) { alt get_metadata_section(path) { option::some(bytes) { decoder::list_crate_metadata(bytes, out); } option::none. { - out.write_str("Could not find metadata in " + path + ".\n"); + out.write_str( + istr::from_estr("Could not find metadata in " + path + ".\n")); } } } diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index 0476fd88605..522aba23b6f 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -4,6 +4,7 @@ import std::ebml; import std::vec; import std::option; import std::str; +import std::istr; import std::io; import std::map::hashmap; import syntax::ast; @@ -346,18 +347,20 @@ fn get_attributes(md: &ebml::doc) -> [ast::attribute] { fn list_meta_items(meta_items: &ebml::doc, out: io::writer) { for mi: @ast::meta_item in get_meta_items(meta_items) { - out.write_str(#fmt["%s\n", pprust::meta_item_to_str(*mi)]); + out.write_str( + istr::from_estr(#fmt["%s\n", pprust::meta_item_to_str(*mi)])); } } fn list_crate_attributes(md: &ebml::doc, out: io::writer) { - out.write_str("=Crate Attributes=\n"); + out.write_str(~"=Crate Attributes=\n"); for attr: ast::attribute in get_attributes(md) { - out.write_str(#fmt["%s\n", pprust::attribute_to_str(attr)]); + out.write_str( + istr::from_estr(#fmt["%s\n", pprust::attribute_to_str(attr)])); } - out.write_str("\n\n"); + out.write_str(~"\n\n"); } fn get_crate_attributes(data: @[u8]) -> [ast::attribute] { @@ -380,17 +383,18 @@ fn get_crate_deps(data: @[u8]) -> [crate_dep] { } fn list_crate_deps(data: @[u8], out: io::writer) { - out.write_str("=External Dependencies=\n"); + out.write_str(~"=External Dependencies=\n"); for dep: crate_dep in get_crate_deps(data) { - out.write_str(#fmt["%d %s\n", dep.cnum, dep.ident]); + out.write_str( + istr::from_estr(#fmt["%d %s\n", dep.cnum, dep.ident])); } - out.write_str("\n"); + out.write_str(~"\n"); } fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) { - out.write_str("=Items=\n"); + out.write_str(~"=Items=\n"); let paths = ebml::get_doc(md, tag_paths); let items = ebml::get_doc(md, tag_items); let index = ebml::get_doc(paths, tag_index); @@ -403,11 +407,12 @@ fn list_crate_items(bytes: &@[u8], md: &ebml::doc, out: io::writer) { let def = ebml::doc_at(bytes, data.pos); let did_doc = ebml::get_doc(def, tag_def_id); let did = parse_def_id(ebml::doc_data(did_doc)); - out.write_str(#fmt["%s (%s)\n", data.path, - describe_def(items, did)]); + out.write_str( + istr::from_estr(#fmt["%s (%s)\n", data.path, + describe_def(items, did)])); } } - out.write_str("\n"); + out.write_str(~"\n"); } fn list_crate_metadata(bytes: &@[u8], out: io::writer) { diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index b2d76729361..12db17936dd 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -2,6 +2,7 @@ import std::vec; import std::str; +import std::istr; import std::uint; import std::io; import std::option; @@ -435,7 +436,9 @@ fn encode_index<T>(ebml_w: &ebml::writer, buckets: &[@[entry<T>]], ebml::end_tag(ebml_w); } -fn write_str(writer: &io::writer, s: &str) { writer.write_str(s); } +fn write_str(writer: &io::writer, s: &str) { + writer.write_str(istr::from_estr(s)); +} fn write_int(writer: &io::writer, n: &int) { writer.write_be_uint(n as uint, 4u); @@ -616,7 +619,7 @@ fn encode_metadata(cx: &@crate_ctxt, crate: &@crate) -> str { // remaining % 4 bytes. buf_w.write([0u8, 0u8, 0u8, 0u8]); - ret string_w.get_str(); + ret istr::to_estr(string_w.get_str()); } // Get the encoded string for a type @@ -624,7 +627,7 @@ fn encoded_ty(tcx: &ty::ctxt, t: ty::t) -> str { let cx = @{ds: def_to_str, tcx: tcx, abbrevs: tyencode::ac_no_abbrevs}; let sw = io::string_writer(); tyencode::enc_ty(sw.get_writer(), cx, t); - ret sw.get_str(); + ret istr::to_estr(sw.get_str()); } diff --git a/src/comp/metadata/tyencode.rs b/src/comp/metadata/tyencode.rs index 34a810adb3b..399ab85fd30 100644 --- a/src/comp/metadata/tyencode.rs +++ b/src/comp/metadata/tyencode.rs @@ -46,15 +46,15 @@ fn enc_ty(w: &io::writer, cx: &@ctxt, t: ty::t) { none. { let sw = io::string_writer(); enc_sty(sw.get_writer(), cx, ty::struct(cx.tcx, t)); - result_str = sw.get_str(); + result_str = istr::to_estr(sw.get_str()); cx.tcx.short_names_cache.insert(t, result_str); } } - w.write_str(result_str); + w.write_str(istr::from_estr(result_str)); } ac_use_abbrevs(abbrevs) { alt abbrevs.find(t) { - some(a) { w.write_str(a.s); ret; } + some(a) { w.write_str(istr::from_estr(a.s)); ret; } none. { let pos = w.get_buf_writer().tell(); enc_sty(w, cx, ty::struct(cx.tcx, t)); @@ -100,30 +100,30 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { ty::ty_float. { w.write_char('l'); } ty::ty_machine(mach) { alt mach { - ty_u8. { w.write_str("Mb"); } - ty_u16. { w.write_str("Mw"); } - ty_u32. { w.write_str("Ml"); } - ty_u64. { w.write_str("Md"); } - ty_i8. { w.write_str("MB"); } - ty_i16. { w.write_str("MW"); } - ty_i32. { w.write_str("ML"); } - ty_i64. { w.write_str("MD"); } - ty_f32. { w.write_str("Mf"); } - ty_f64. { w.write_str("MF"); } + ty_u8. { w.write_str(~"Mb"); } + ty_u16. { w.write_str(~"Mw"); } + ty_u32. { w.write_str(~"Ml"); } + ty_u64. { w.write_str(~"Md"); } + ty_i8. { w.write_str(~"MB"); } + ty_i16. { w.write_str(~"MW"); } + ty_i32. { w.write_str(~"ML"); } + ty_i64. { w.write_str(~"MD"); } + ty_f32. { w.write_str(~"Mf"); } + ty_f64. { w.write_str(~"MF"); } } } ty::ty_char. { w.write_char('c'); } ty::ty_str. { w.write_char('s'); } ty::ty_istr. { w.write_char('S'); } ty::ty_tag(def, tys) { - w.write_str("t["); - w.write_str(cx.ds(def)); + w.write_str(~"t["); + w.write_str(istr::from_estr(cx.ds(def))); w.write_char('|'); for t: ty::t in tys { enc_ty(w, cx, t); } w.write_char(']'); } ty::ty_tup(ts) { - w.write_str("T["); + w.write_str(~"T["); for t in ts { enc_ty(w, cx, t); } w.write_char(']'); } @@ -132,9 +132,9 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { ty::ty_ptr(mt) { w.write_char('*'); enc_mt(w, cx, mt); } ty::ty_vec(mt) { w.write_char('I'); enc_mt(w, cx, mt); } ty::ty_rec(fields) { - w.write_str("R["); + w.write_str(~"R["); for field: ty::field in fields { - w.write_str(field.ident); + w.write_str(istr::from_estr(field.ident)); w.write_char('='); enc_mt(w, cx, field.mt); } @@ -156,17 +156,17 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { enc_ty_fn(w, cx, args, out, return, []); } ty::ty_obj(methods) { - w.write_str("O["); + w.write_str(~"O["); for m: ty::method in methods { enc_proto(w, m.proto); - w.write_str(m.ident); + w.write_str(istr::from_estr(m.ident)); enc_ty_fn(w, cx, m.inputs, m.output, m.cf, m.constrs); } w.write_char(']'); } ty::ty_res(def, ty, tps) { - w.write_str("r["); - w.write_str(cx.ds(def)); + w.write_str(~"r["); + w.write_str(istr::from_estr(cx.ds(def))); w.write_char('|'); enc_ty(w, cx, ty); for t: ty::t in tps { enc_ty(w, cx, t); } @@ -174,24 +174,24 @@ fn enc_sty(w: &io::writer, cx: &@ctxt, st: &ty::sty) { } ty::ty_var(id) { w.write_char('X'); - w.write_str(istr::to_estr(int::str(id))); + w.write_str(int::str(id)); } ty::ty_native(def) { w.write_char('E'); - w.write_str(cx.ds(def)); + w.write_str(istr::from_estr(cx.ds(def))); w.write_char('|'); } ty::ty_param(id, k) { alt k { - kind_unique. { w.write_str("pu"); } - kind_shared. { w.write_str("ps"); } - kind_pinned. { w.write_str("pp"); } + kind_unique. { w.write_str(~"pu"); } + kind_shared. { w.write_str(~"ps"); } + kind_pinned. { w.write_str(~"pp"); } } - w.write_str(istr::to_estr(uint::str(id))); + w.write_str(uint::str(id)); } ty::ty_type. { w.write_char('Y'); } ty::ty_constr(ty, cs) { - w.write_str("A["); + w.write_str(~"A["); enc_ty(w, cx, ty); for tc: @ty::type_constr in cs { enc_ty_constr(w, cx, tc); } w.write_char(']'); @@ -235,9 +235,9 @@ fn enc_ty_fn(w: &io::writer, cx: &@ctxt, args: &[ty::arg], out: ty::t, // FIXME less copy-and-paste fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { - w.write_str(path_to_str(c.node.path)); + w.write_str(istr::from_estr(path_to_str(c.node.path))); w.write_char('('); - w.write_str(cx.ds(c.node.id)); + w.write_str(istr::from_estr(cx.ds(c.node.id))); w.write_char('|'); let semi = false; for a: @constr_arg in c.node.args { @@ -245,24 +245,28 @@ fn enc_constr(w: &io::writer, cx: &@ctxt, c: &@ty::constr) { alt a.node { carg_base. { w.write_char('*'); } carg_ident(i) { w.write_uint(i); } - carg_lit(l) { w.write_str(lit_to_str(l)); } + carg_lit(l) { + w.write_str(istr::from_estr(lit_to_str(l))); + } } } w.write_char(')'); } fn enc_ty_constr(w: &io::writer, cx: &@ctxt, c: &@ty::type_constr) { - w.write_str(path_to_str(c.node.path)); + w.write_str(istr::from_estr(path_to_str(c.node.path))); w.write_char('('); - w.write_str(cx.ds(c.node.id)); + w.write_str(istr::from_estr(cx.ds(c.node.id))); w.write_char('|'); let semi = false; for a: @ty::ty_constr_arg in c.node.args { if semi { w.write_char(';'); } else { semi = true; } alt a.node { carg_base. { w.write_char('*'); } - carg_ident(p) { w.write_str(path_to_str(p)); } - carg_lit(l) { w.write_str(lit_to_str(l)); } + carg_ident(p) { + w.write_str(istr::from_estr(path_to_str(p))); } + carg_lit(l) { + w.write_str(istr::from_estr(lit_to_str(l))); } } } w.write_char(')'); |
