Convert rustc::syntax::codemap to istrs. Issue #855
This commit is contained in:
parent
9fb085560d
commit
3dc2419443
@ -10,6 +10,7 @@
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
import std::str;
|
||||
import std::istr;
|
||||
import syntax::parse::parser::parse_sess;
|
||||
|
||||
tag os { os_win32; os_macos; os_linux; }
|
||||
@ -60,19 +61,19 @@
|
||||
fn get_cstore() -> metadata::cstore::cstore { cstore }
|
||||
fn span_fatal(sp: span, msg: str) -> ! {
|
||||
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
||||
codemap::emit_error(some(sp), msg, parse_sess.cm);
|
||||
codemap::emit_error(some(sp), istr::from_estr(msg), parse_sess.cm);
|
||||
fail;
|
||||
}
|
||||
fn fatal(msg: str) -> ! {
|
||||
codemap::emit_error(none, msg, parse_sess.cm);
|
||||
codemap::emit_error(none, istr::from_estr(msg), parse_sess.cm);
|
||||
fail;
|
||||
}
|
||||
fn span_err(sp: span, msg: str) {
|
||||
codemap::emit_error(some(sp), msg, parse_sess.cm);
|
||||
codemap::emit_error(some(sp), istr::from_estr(msg), parse_sess.cm);
|
||||
err_count += 1u;
|
||||
}
|
||||
fn err(msg: str) {
|
||||
codemap::emit_error(none, msg, parse_sess.cm);
|
||||
codemap::emit_error(none, istr::from_estr(msg), parse_sess.cm);
|
||||
err_count += 1u;
|
||||
}
|
||||
fn abort_if_errors() {
|
||||
@ -80,14 +81,18 @@ fn abort_if_errors() {
|
||||
}
|
||||
fn span_warn(sp: span, msg: str) {
|
||||
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
||||
codemap::emit_warning(some(sp), msg, parse_sess.cm);
|
||||
codemap::emit_warning(some(sp), istr::from_estr(msg), parse_sess.cm);
|
||||
}
|
||||
fn warn(msg: str) {
|
||||
codemap::emit_warning(none, istr::from_estr(msg), parse_sess.cm);
|
||||
}
|
||||
fn warn(msg: str) { codemap::emit_warning(none, msg, parse_sess.cm); }
|
||||
fn span_note(sp: span, msg: str) {
|
||||
// FIXME: Use constants, but rustboot doesn't know how to export them.
|
||||
codemap::emit_note(some(sp), msg, parse_sess.cm);
|
||||
codemap::emit_note(some(sp), istr::from_estr(msg), parse_sess.cm);
|
||||
}
|
||||
fn note(msg: str) {
|
||||
codemap::emit_note(none, istr::from_estr(msg), parse_sess.cm);
|
||||
}
|
||||
fn note(msg: str) { codemap::emit_note(none, msg, parse_sess.cm); }
|
||||
fn span_bug(sp: span, msg: str) -> ! {
|
||||
self.span_fatal(sp, #fmt["internal compiler error %s", msg]);
|
||||
}
|
||||
@ -107,7 +112,7 @@ fn next_node_id() -> ast::node_id {
|
||||
ret syntax::parse::parser::next_node_id(parse_sess);
|
||||
}
|
||||
fn span_str(sp: span) -> str {
|
||||
ret codemap::span_to_str(sp, self.get_codemap());
|
||||
ret istr::to_estr(codemap::span_to_str(sp, self.get_codemap()));
|
||||
}
|
||||
fn set_main_id(d: node_id) { main_fn = some(d); }
|
||||
fn get_main_id() -> option::t<node_id> { main_fn }
|
||||
|
@ -73,26 +73,26 @@ fn lookup_byte_pos(map: codemap, pos: uint) -> loc {
|
||||
}
|
||||
type span = {lo: uint, hi: uint, expanded_from: opt_span};
|
||||
|
||||
fn span_to_str(sp: &span, cm: &codemap) -> str {
|
||||
fn span_to_str(sp: &span, cm: &codemap) -> istr {
|
||||
let cur = sp;
|
||||
let res = "";
|
||||
let res = ~"";
|
||||
let prev_file = none;
|
||||
while true {
|
||||
let lo = lookup_char_pos(cm, cur.lo);
|
||||
let hi = lookup_char_pos(cm, cur.hi);
|
||||
res +=
|
||||
res += istr::from_estr(
|
||||
#fmt["%s:%u:%u: %u:%u",
|
||||
if some(lo.filename) == prev_file {
|
||||
"-"
|
||||
} else {
|
||||
istr::to_estr(lo.filename)
|
||||
}, lo.line, lo.col, hi.line, hi.col];
|
||||
}, lo.line, lo.col, hi.line, hi.col]);
|
||||
alt cur.expanded_from {
|
||||
os_none. { break; }
|
||||
os_some(new_sp) {
|
||||
cur = *new_sp;
|
||||
prev_file = some(lo.filename);
|
||||
res += "<<";
|
||||
res += ~"<<";
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,24 +100,25 @@ fn span_to_str(sp: &span, cm: &codemap) -> str {
|
||||
ret res;
|
||||
}
|
||||
|
||||
fn emit_diagnostic(sp: &option::t<span>, msg: &str, kind: &str, color: u8,
|
||||
fn emit_diagnostic(sp: &option::t<span>, msg: &istr, kind: &istr, color: u8,
|
||||
cm: &codemap) {
|
||||
let ss = "";
|
||||
let ss = ~"";
|
||||
let maybe_lines: option::t<@file_lines> = none;
|
||||
alt sp {
|
||||
some(ssp) {
|
||||
ss = span_to_str(ssp, cm) + " ";
|
||||
ss = span_to_str(ssp, cm) + ~" ";
|
||||
maybe_lines = some(span_to_lines(ssp, cm));
|
||||
}
|
||||
none. { }
|
||||
}
|
||||
io::stdout().write_str(istr::from_estr(ss));
|
||||
io::stdout().write_str(ss);
|
||||
if term::color_supported() {
|
||||
term::fg(io::stdout().get_buf_writer(), color);
|
||||
}
|
||||
io::stdout().write_str(istr::from_estr(#fmt["%s:", kind]));
|
||||
io::stdout().write_str(istr::from_estr(#fmt["%s:", istr::to_estr(kind)]));
|
||||
if term::color_supported() { term::reset(io::stdout().get_buf_writer()); }
|
||||
io::stdout().write_str(istr::from_estr(#fmt[" %s\n", msg]));
|
||||
io::stdout().write_str(istr::from_estr(#fmt[" %s\n",
|
||||
istr::to_estr(msg)]));
|
||||
|
||||
maybe_highlight_lines(sp, cm, maybe_lines);
|
||||
}
|
||||
@ -129,12 +130,11 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
||||
some(lines) {
|
||||
// If we're not looking at a real file then we can't re-open it to
|
||||
// pull out the lines
|
||||
if lines.name == "-" { ret; }
|
||||
if lines.name == ~"-" { ret; }
|
||||
|
||||
// FIXME: reading in the entire file is the worst possible way to
|
||||
// get access to the necessary lines.
|
||||
let file = istr::to_estr(
|
||||
io::read_whole_file_str(istr::from_estr(lines.name)));
|
||||
let file = io::read_whole_file_str(lines.name);
|
||||
let fm = get_filemap(cm, lines.name);
|
||||
|
||||
// arbitrarily only print up to six lines of the error
|
||||
@ -151,8 +151,8 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
||||
istr::from_estr(#fmt["%s:%u ",
|
||||
istr::to_estr(fm.name), line + 1u]));
|
||||
let s = get_line(fm, line as int, file);
|
||||
if !str::ends_with(s, "\n") { s += "\n"; }
|
||||
io::stdout().write_str(istr::from_estr(s));
|
||||
if !istr::ends_with(s, ~"\n") { s += ~"\n"; }
|
||||
io::stdout().write_str(s);
|
||||
}
|
||||
if elided {
|
||||
let last_line = display_lines[vec::len(display_lines) - 1u];
|
||||
@ -194,17 +194,17 @@ fn maybe_highlight_lines(sp: &option::t<span>, cm: &codemap,
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_warning(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, "warning", 11u8, cm);
|
||||
fn emit_warning(sp: &option::t<span>, msg: &istr, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, ~"warning", 11u8, cm);
|
||||
}
|
||||
fn emit_error(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, "error", 9u8, cm);
|
||||
fn emit_error(sp: &option::t<span>, msg: &istr, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, ~"error", 9u8, cm);
|
||||
}
|
||||
fn emit_note(sp: &option::t<span>, msg: &str, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, "note", 10u8, cm);
|
||||
fn emit_note(sp: &option::t<span>, msg: &istr, cm: &codemap) {
|
||||
emit_diagnostic(sp, msg, ~"note", 10u8, cm);
|
||||
}
|
||||
|
||||
type file_lines = {name: str, lines: [uint]};
|
||||
type file_lines = {name: istr, lines: [uint]};
|
||||
|
||||
fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
||||
let lo = lookup_char_pos(cm, sp.lo);
|
||||
@ -213,10 +213,10 @@ fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
|
||||
for each i: uint in uint::range(lo.line - 1u, hi.line as uint) {
|
||||
lines += [i];
|
||||
}
|
||||
ret @{name: istr::to_estr(lo.filename), lines: lines};
|
||||
ret @{name: lo.filename, lines: lines};
|
||||
}
|
||||
|
||||
fn get_line(fm: filemap, line: int, file: &str) -> str {
|
||||
fn get_line(fm: filemap, line: int, file: &istr) -> istr {
|
||||
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
|
||||
let end: uint;
|
||||
if line as uint < vec::len(fm.lines) - 1u {
|
||||
@ -225,17 +225,17 @@ fn get_line(fm: filemap, line: int, file: &str) -> str {
|
||||
// If we're not done parsing the file, we're at the limit of what's
|
||||
// parsed. If we just slice the rest of the string, we'll print out
|
||||
// the remainder of the file, which is undesirable.
|
||||
end = str::byte_len(file);
|
||||
let rest = str::slice(file, begin, end);
|
||||
let newline = str::index(rest, '\n' as u8);
|
||||
end = istr::byte_len(file);
|
||||
let rest = istr::slice(file, begin, end);
|
||||
let newline = istr::index(rest, '\n' as u8);
|
||||
if newline != -1 { end = begin + (newline as uint); }
|
||||
}
|
||||
ret str::slice(file, begin, end);
|
||||
ret istr::slice(file, begin, end);
|
||||
}
|
||||
|
||||
fn get_filemap(cm: codemap, filename: str) -> filemap {
|
||||
fn get_filemap(cm: codemap, filename: istr) -> filemap {
|
||||
for fm: filemap in cm.files {
|
||||
if fm.name == istr::from_estr(filename) { ret fm; }
|
||||
if fm.name == filename { ret fm; }
|
||||
}
|
||||
//XXjdm the following triggers a mismatched type bug
|
||||
// (or expected function, found _|_)
|
||||
|
@ -81,7 +81,7 @@ fn bump() {
|
||||
fn err(m: &istr) {
|
||||
codemap::emit_error(
|
||||
some(ast_util::mk_sp(chpos, chpos)),
|
||||
istr::to_estr(m), cm);
|
||||
m, cm);
|
||||
}
|
||||
}
|
||||
let strs: [istr] = [];
|
||||
|
@ -113,12 +113,12 @@ fn look_ahead(distance: uint) -> token::token {
|
||||
}
|
||||
fn fatal(m: &istr) -> ! {
|
||||
codemap::emit_error(some(self.get_span()),
|
||||
istr::to_estr(m), sess.cm);
|
||||
m, sess.cm);
|
||||
fail;
|
||||
}
|
||||
fn warn(m: &istr) {
|
||||
codemap::emit_warning(some(self.get_span()),
|
||||
istr::to_estr(m), sess.cm);
|
||||
m, sess.cm);
|
||||
}
|
||||
fn restrict(r: restriction) { restr = r; }
|
||||
fn get_restriction() -> restriction { ret restr; }
|
||||
@ -2581,8 +2581,8 @@ fn parse_crate_from_file(input: &istr, cfg: &ast::crate_cfg,
|
||||
} else if istr::ends_with(input, ~".rs") {
|
||||
parse_crate_from_source_file(input, cfg, sess)
|
||||
} else {
|
||||
codemap::emit_error(none, "unknown input file type: "
|
||||
+ istr::to_estr(input),
|
||||
codemap::emit_error(none, ~"unknown input file type: "
|
||||
+ input,
|
||||
sess.cm);
|
||||
fail
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user