rustc: Move much of metadata reading over to interior vectors

This commit is contained in:
Patrick Walton 2011-07-12 10:59:18 -07:00
parent 4664b67ea2
commit be489ee9e2
16 changed files with 337 additions and 336 deletions

View file

@ -1,8 +1,8 @@
import std::uint;
import std::str;
import std::vec;
import std::term;
import std::io;
import std::termivec;
import std::ioivec;
import std::option;
import std::option::some;
import std::option::none;
@ -70,21 +70,21 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
}
case (none) { }
}
io::stdout().write_str(ss + ": ");
if (term::color_supported()) {
term::fg(io::stdout().get_buf_writer(), color);
ioivec::stdout().write_str(ss + ": ");
if (termivec::color_supported()) {
termivec::fg(ioivec::stdout().get_buf_writer(), color);
}
io::stdout().write_str(#fmt("%s:", kind));
if (term::color_supported()) {
term::reset(io::stdout().get_buf_writer());
ioivec::stdout().write_str(#fmt("%s:", kind));
if (termivec::color_supported()) {
termivec::reset(ioivec::stdout().get_buf_writer());
}
io::stdout().write_str(#fmt(" %s\n", msg));
ioivec::stdout().write_str(#fmt(" %s\n", msg));
alt (maybe_lines) {
case (some(?lines)) {
// FIXME: reading in the entire file is the worst possible way to
// get access to the necessary lines.
auto rdr = io::file_reader(lines.name);
auto file = str::unsafe_from_bytes(rdr.read_whole_stream());
auto rdr = ioivec::file_reader(lines.name);
auto file = str::unsafe_from_bytes_ivec(rdr.read_whole_stream());
auto fm = codemap::get_filemap(cm, lines.name);
// arbitrarily only print up to six lines of the error
@ -97,12 +97,13 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
}
// Print the offending lines
for (uint line in display_lines) {
io::stdout().write_str(#fmt("%s:%u ", fm.name, line + 1u));
ioivec::stdout().write_str(#fmt("%s:%u ", fm.name,
line + 1u));
auto s = codemap::get_line(fm, line as int, file);
if (!str::ends_with(s, "\n")) {
s += "\n";
}
io::stdout().write_str(s);
ioivec::stdout().write_str(s);
}
if (elided) {
auto last_line = display_lines.(vec::len(display_lines) - 1u);
@ -111,7 +112,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
auto out = "";
while (indent > 0u) { out += " "; indent -= 1u; }
out += "...\n";
io::stdout().write_str(out);
ioivec::stdout().write_str(out);
}
// If there's one line at fault we can easily point to the problem
@ -138,7 +139,7 @@ fn emit_diagnostic(&option::t[span] sp, &str msg, &str kind, u8 color,
width -= 1u;
}
}
io::stdout().write_str(s + "\n");
ioivec::stdout().write_str(s + "\n");
}
}
case (_) {}

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::str;
import std::vec;
import std::int;
@ -734,8 +734,8 @@ type lit = rec(str lit, uint pos);
fn gather_comments_and_literals(&codemap::codemap cm, str path)
-> rec(cmnt[] cmnts, lit[] lits) {
auto srdr = io::file_reader(path);
auto src = str::unsafe_from_bytes(srdr.read_whole_stream());
auto srdr = ioivec::file_reader(path);
auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
auto itr = @interner::mk[str](str::hash, str::eq);
auto rdr = new_reader(cm, src, codemap::new_filemap(path, 0u), itr);
let cmnt[] comments = ~[];

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::ivec;
import std::vec;
import std::str;
@ -59,8 +59,8 @@ fn new_parser_from_file(parse_sess sess, ast::crate_cfg cfg,
str path, uint pos) -> parser {
auto ftype = SOURCE_FILE;
if (str::ends_with(path, ".rc")) { ftype = CRATE_FILE; }
auto srdr = io::file_reader(path);
auto src = str::unsafe_from_bytes(srdr.read_whole_stream());
auto srdr = ioivec::file_reader(path);
auto src = str::unsafe_from_bytes_ivec(srdr.read_whole_stream());
auto filemap = codemap::new_filemap(path, pos);
vec::push(sess.cm.files, filemap);
auto itr = @interner::mk(str::hash, str::eq);

View file

@ -1,5 +1,5 @@
import std::io;
import std::ioivec;
import std::vec;
import std::str;
@ -98,7 +98,7 @@ type print_stack_elt = rec(int offset, print_stack_break pbreak);
const int size_infinity = 0xffff;
fn mk_printer(io::writer out, uint linewidth) -> printer {
fn mk_printer(ioivec::writer out, uint linewidth) -> printer {
// Yes 3, it makes the ring buffers big enough to never
// fall behind.
@ -198,7 +198,7 @@ fn mk_printer(io::writer out, uint linewidth) -> printer {
* the method called 'pretty_print', and the 'PRINT' process is the method
* called 'print'.
*/
obj printer(io::writer out,
obj printer(ioivec::writer out,
uint buf_len,
mutable int margin, // width of lines we're constrained to

View file

@ -1,7 +1,7 @@
import std::ivec;
import std::int;
import std::io;
import std::ioivec;
import std::str;
import std::uint;
import std::vec;
@ -57,7 +57,7 @@ fn ibox(&ps s, uint u) {
fn end(&ps s) { ivec::pop(s.boxes); pp::end(s.s); }
fn rust_printer(io::writer writer) -> ps {
fn rust_printer(ioivec::writer writer) -> ps {
let pp::breaks[] boxes = ~[];
ret @rec(s=pp::mk_printer(writer, default_columns),
cm=none[codemap],
@ -74,7 +74,7 @@ const uint indent_unit = 4u;
const uint default_columns = 78u;
fn print_crate(&codemap cm, @ast::crate crate, str filename,
io::writer out, &pp_ann ann) {
ioivec::writer out, &pp_ann ann) {
let pp::breaks[] boxes = ~[];
auto r = lexer::gather_comments_and_literals(cm, filename);
auto s =
@ -104,7 +104,7 @@ fn item_to_str(&@ast::item i) -> str { be to_str(i, print_item); }
fn path_to_str(&ast::path p) -> str { be to_str(p, print_path); }
fn fun_to_str(&ast::_fn f, str name, &ast::ty_param[] params) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
print_fn(s, f.decl, f.proto, name, params);
eof(s.s);
@ -112,7 +112,7 @@ fn fun_to_str(&ast::_fn f, str name, &ast::ty_param[] params) -> str {
}
fn block_to_str(&ast::block blk) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
// containing cbox, will be closed by print-block at }
@ -1505,7 +1505,7 @@ fn escape_str(str st, char to_escape) -> str {
}
fn to_str[T](&T t, fn(&ps, &T) f) -> str {
auto writer = io::string_writer();
auto writer = ioivec::string_writer();
auto s = rust_printer(writer.get_writer());
f(s, t);
eof(s.s);