提交 91fe4ae0 编写于 作者: P Patrick Walton

rustc: Joseph and the Amazing Technicolor Error Messages

上级 616ae95f
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
import util.common.span; import util.common.span;
import util.common.ty_mach; import util.common.ty_mach;
import std._uint; import std._uint;
import std.Term;
import std.io;
import std.map; import std.map;
tag os { tag os {
...@@ -26,6 +28,17 @@ ...@@ -26,6 +28,17 @@
type crate_metadata = rec(str name, type crate_metadata = rec(str name,
vec[u8] data); vec[u8] data);
fn emit_diagnostic(span sp, str msg, str kind, u8 color, codemap.codemap cm) {
auto lo = codemap.lookup_pos(cm, sp.lo);
auto hi = codemap.lookup_pos(cm, sp.hi);
io.stdout().write_str(#fmt("%s:%u:%u:%u:%u: ", lo.filename, lo.line,
lo.col, hi.line, hi.col));
Term.fg(io.stdout().get_buf_writer(), color);
io.stdout().write_str(#fmt("%s:", kind));
Term.reset(io.stdout().get_buf_writer());
io.stdout().write_str(#fmt(" %s\n", msg));
}
state obj session(ast.crate_num cnum, cfg targ, state obj session(ast.crate_num cnum, cfg targ,
map.hashmap[int, crate_metadata] crates, map.hashmap[int, crate_metadata] crates,
mutable vec[@ast.meta_item] metadata, mutable vec[@ast.meta_item] metadata,
...@@ -40,13 +53,8 @@ fn get_targ_crate_num() -> ast.crate_num { ...@@ -40,13 +53,8 @@ fn get_targ_crate_num() -> ast.crate_num {
} }
fn span_err(span sp, str msg) { fn span_err(span sp, str msg) {
auto lo = codemap.lookup_pos(cm, sp.lo); // FIXME: Use constants, but rustboot doesn't know how to export them.
auto hi = codemap.lookup_pos(cm, sp.hi); emit_diagnostic(sp, msg, "error", 9u8, cm);
log_err #fmt("%s:%u:%u:%u:%u: error: %s",
lo.filename,
lo.line, lo.col,
hi.line, hi.col,
msg);
fail; fail;
} }
...@@ -63,13 +71,8 @@ fn get_metadata() -> vec[@ast.meta_item] { ...@@ -63,13 +71,8 @@ fn get_metadata() -> vec[@ast.meta_item] {
} }
fn span_warn(span sp, str msg) { fn span_warn(span sp, str msg) {
auto lo = codemap.lookup_pos(cm, sp.lo); // FIXME: Use constants, but rustboot doesn't know how to export them.
auto hi = codemap.lookup_pos(cm, sp.hi); emit_diagnostic(sp, msg, "warning", 11u8, cm);
log_err #fmt("%s:%u:%u:%u:%u: warning: %s",
lo.filename,
lo.line, lo.col,
hi.line, hi.col,
msg);
} }
fn bug(str msg) { fn bug(str msg) {
...@@ -78,13 +81,9 @@ fn bug(str msg) { ...@@ -78,13 +81,9 @@ fn bug(str msg) {
} }
fn span_unimpl(span sp, str msg) { fn span_unimpl(span sp, str msg) {
auto lo = codemap.lookup_pos(cm, sp.lo); // FIXME: Use constants, but rustboot doesn't know how to export them.
auto hi = codemap.lookup_pos(cm, sp.hi); emit_diagnostic(sp, "internal compiler error: unimplemented " + msg,
log_err #fmt("%s:%u:%u:%u:%u: error: unimplemented %s", "error", 9u8, cm);
lo.filename,
lo.line, lo.col,
hi.line, hi.col,
msg);
fail; fail;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册