提交 1c91fb4d 编写于 作者: K Kevin Atkinson

Don't rely on filename to get a file from the filemap

as there may be more than one filemap with the same filename (in the
case of stdin for instance).  This involved storing a pointer to the
filemap rather than the filename in location info such as
codemap::pos.
上级 4616117f
......@@ -189,11 +189,7 @@ fn emit(cmsp: option<(codemap::codemap, span)>,
fn highlight_lines(cm: codemap::codemap, sp: span,
lines: @codemap::file_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; }
let fm = codemap::get_filemap(cm, lines.name);
let fm = lines.file;
// arbitrarily only print up to six lines of the error
let max_lines = 6u;
......
......@@ -238,7 +238,7 @@ fn create_block(cx: @block_ctxt) -> @metadata<block_md> {
let start = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
sp.lo);
let fname = start.filename;
let fname = start.file.name;
let end = codemap::lookup_char_pos(bcx_ccx(cx).sess.codemap,
sp.hi);
let tg = LexicalBlockTag;
......@@ -632,8 +632,8 @@ fn t_to_ty(cx: @crate_ctxt, t: ty::t, span: span) -> @ast::ty {
};
}
fn filename_from_span(cx: @crate_ctxt, sp: span) -> str {
codemap::lookup_char_pos(cx.sess.codemap, sp.lo).filename
fn filename_from_span(cx: @crate_ctxt, sp: codemap::span) -> str {
codemap::lookup_char_pos(cx.sess.codemap, sp.lo).file.name
}
fn create_var(type_tag: int, context: ValueRef, name: str, file: ValueRef,
......@@ -670,7 +670,7 @@ fn create_local_var(bcx: @block_ctxt, local: @ast::local)
local.span.lo);
let ty = node_id_type(bcx, local.node.id);
let tymd = create_ty(cx, ty, local.node.ty);
let filemd = create_file(cx, loc.filename);
let filemd = create_file(cx, loc.file.name);
let context = alt bcx.parent {
parent_none { create_function(bcx.fcx).node }
parent_some(_) { create_block(bcx).node }
......@@ -719,7 +719,7 @@ fn create_arg(bcx: @block_ctxt, arg: ast::arg, sp: span)
sp.lo);
let ty = node_id_type(bcx, arg.id);
let tymd = create_ty(cx, ty, arg.ty);
let filemd = create_file(cx, loc.filename);
let filemd = create_file(cx, loc.file.name);
let context = create_function(bcx.fcx);
let mdnode = create_var(tg, context.node, arg.ident, filemd.node,
loc.line as int, tymd.node);
......@@ -812,7 +812,7 @@ fn create_function(fcx: @fn_ctxt) -> @metadata<subprogram_md> {
let loc = codemap::lookup_char_pos(cx.sess.codemap,
sp.lo);
let file_node = create_file(cx, loc.filename).node;
let file_node = create_file(cx, loc.file.name).node;
let key = if cx.item_symbols.contains_key(fcx.id) { fcx.id } else { id };
let mangled = cx.item_symbols.get(key);
let ty_node = if cx.sess.opts.extra_debuginfo {
......
......@@ -3848,7 +3848,7 @@ fn trans_fail_value(bcx: @block_ctxt, sp_opt: option<span>,
some(sp) {
let sess = bcx_ccx(bcx).sess;
let loc = codemap::lookup_char_pos(sess.parse_sess.cm, sp.lo);
V_filename = C_cstr(bcx_ccx(bcx), loc.filename);
V_filename = C_cstr(bcx_ccx(bcx), loc.file.name);
V_line = loc.line as int;
}
none { V_filename = C_cstr(bcx_ccx(bcx), "<runtime>"); V_line = 0; }
......
......@@ -16,9 +16,11 @@
type codemap = @{mutable files: [filemap]};
type loc = {filename: filename, line: uint, col: uint};
type loc = {file: filemap, line: uint, col: uint};
fn new_codemap() -> codemap { ret @{mutable files: []}; }
fn new_codemap() -> codemap {
@{mutable files: [new_filemap("-", @"", 0u, 0u)]}
}
fn new_filemap(filename: filename, src: @str,
start_pos_ch: uint, start_pos_byte: uint)
......@@ -28,6 +30,8 @@ fn new_filemap(filename: filename, src: @str,
mutable lines: [{ch: start_pos_ch, byte: start_pos_byte}]};
}
fn empty_filemap(cm: codemap) -> filemap {cm.files[0]}
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
file.lines += [{ch: chpos, byte: byte_pos}];
}
......@@ -60,10 +64,10 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc {
alt lookup_line(map, pos, lookup) {
some({fm: f, line: a}) {
{filename: f.name, line: a + 1u, col: pos - lookup(f.lines[a])}
{file: f, line: a + 1u, col: pos - lookup(f.lines[a])}
}
none {
{ filename: "-", line: 0u, col: 0u }
{ file: empty_filemap(map), line: 0u, col: 0u }
}
}
}
......@@ -89,20 +93,21 @@ enum opt_span {
fn span_to_str(sp: span, cm: codemap) -> str {
let cur = sp;
let res = "";
// FIXME: Should probably be doing pointer comparison on filemap
let prev_file = none;
while true {
let lo = lookup_char_pos(cm, cur.lo);
let hi = lookup_char_pos(cm, cur.hi);
res +=
#fmt["%s:%u:%u: %u:%u",
if some(lo.filename) == prev_file {
if some(lo.file.name) == prev_file {
"-"
} else { lo.filename }, lo.line, lo.col, hi.line, hi.col];
} else { lo.file.name }, 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);
prev_file = some(lo.file.name);
res += "<<";
}
}
......@@ -111,14 +116,15 @@ fn span_to_str(sp: span, cm: codemap) -> str {
ret res;
}
type file_lines = {name: str, lines: [uint]};
type file_lines = {file: filemap, lines: [uint]};
fn span_to_lines(sp: span, cm: codemap::codemap) -> @file_lines {
let lo = lookup_char_pos(cm, sp.lo);
let hi = lookup_char_pos(cm, sp.hi);
// FIXME: Check for filemap?
let lines = [];
uint::range(lo.line - 1u, hi.line as uint) {|i| lines += [i]; };
ret @{name: lo.filename, lines: lines};
ret @{file: lo.file, lines: lines};
}
fn get_line(fm: filemap, line: int) -> str unsafe {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册