Remove filemap box typedef from codemap

This commit is contained in:
Brian Anderson 2012-11-12 16:41:20 -08:00
parent 4c68084963
commit 5f881b48cb
5 changed files with 19 additions and 21 deletions

View File

@ -58,21 +58,19 @@ enum file_substr {
fss_external({filename: ~str, line: uint, col: uint})
}
struct filemap_ {
struct filemap {
name: filename, substr: file_substr, src: @~str,
start_pos: file_pos, mut lines: ~[file_pos]
}
type filemap = @filemap_;
struct CodeMap_ {
files: DVec<filemap>
files: DVec<@filemap>
}
type CodeMap = @CodeMap_;
struct loc {
file: filemap, line: uint, col: uint
file: @filemap, line: uint, col: uint
}
fn new_codemap() -> CodeMap { @CodeMap_ {files: DVec()} }
@ -81,7 +79,7 @@ fn new_filemap_w_substr(+filename: filename, +substr: file_substr,
src: @~str,
start_pos_ch: uint, start_pos_byte: uint)
-> filemap {
return @filemap_ {
return filemap {
name: filename, substr: substr, src: src,
start_pos: file_pos {ch: start_pos_ch, byte: start_pos_byte},
mut lines: ~[file_pos {ch: start_pos_ch, byte: start_pos_byte}]
@ -101,14 +99,14 @@ fn mk_substr_filename(cm: CodeMap, sp: span) -> ~str
return fmt!("<%s:%u:%u>", pos.file.name, pos.line, pos.col);
}
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
fn next_line(file: @filemap, chpos: uint, byte_pos: uint) {
file.lines.push(file_pos {ch: chpos, byte: byte_pos + file.start_pos.byte});
}
type lookup_fn = pure fn(file_pos) -> uint;
fn lookup_line(map: CodeMap, pos: uint, lookup: lookup_fn)
-> {fm: filemap, line: uint}
-> {fm: @filemap, line: uint}
{
let len = map.files.len();
let mut a = 0u;
@ -146,7 +144,7 @@ fn lookup_byte_pos(map: CodeMap, pos: uint) -> loc {
}
fn lookup_char_pos_adj(map: CodeMap, pos: uint)
-> {filename: ~str, line: uint, col: uint, file: Option<filemap>}
-> {filename: ~str, line: uint, col: uint, file: Option<@filemap>}
{
let loc = lookup_char_pos(map, pos);
match (loc.file.substr) {
@ -222,7 +220,7 @@ fn span_to_str(sp: span, cm: CodeMap) -> ~str {
}
struct file_lines {
file: filemap,
file: @filemap,
lines: ~[uint]
}
@ -241,7 +239,7 @@ fn span_to_lines(sp: span, cm: codemap::CodeMap) -> @file_lines {
return @file_lines {file: lo.file, lines: lines};
}
fn get_line(fm: filemap, line: int) -> ~str unsafe {
fn get_line(fm: @filemap, line: int) -> ~str unsafe {
let begin: uint = fm.lines[line].byte - fm.start_pos.byte;
let end = match str::find_char_from(*fm.src, '\n', begin) {
Some(e) => e,
@ -251,7 +249,7 @@ fn get_line(fm: filemap, line: int) -> ~str unsafe {
}
fn lookup_byte_offset(cm: codemap::CodeMap, chpos: uint)
-> {fm: filemap, pos: uint} {
-> {fm: @filemap, pos: uint} {
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
let {fm, line} = lookup_line(cm, chpos, lookup);
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
@ -273,7 +271,7 @@ fn get_snippet(cm: codemap::CodeMap, fidx: uint, lo: uint, hi: uint) -> ~str
return str::slice(*fm.src, lo, hi)
}
fn get_filemap(cm: CodeMap, filename: ~str) -> filemap {
fn get_filemap(cm: CodeMap, filename: ~str) -> @filemap {
for cm.files.each |fm| { if fm.name == filename { return *fm; } }
//XXjdm the following triggers a mismatched type bug
// (or expected function, found _|_)

View File

@ -1,5 +1,5 @@
use base::*;
use codemap::{span, loc, filemap_};
use codemap::{span, loc, filemap};
use print::pprust;
use build::{mk_base_vec_e,mk_uint,mk_u8,mk_uniq_str};
@ -34,7 +34,7 @@ fn expand_col(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
fn expand_file(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
_body: ast::mac_body) -> @ast::expr {
get_mac_args(cx, sp, arg, 0u, option::Some(0u), ~"file");
let loc { file: @filemap_ { name: filename, _ }, _ } =
let loc { file: @filemap { name: filename, _ }, _ } =
codemap::lookup_char_pos(cx.codemap(), sp.lo);
return mk_uniq_str(cx, sp, filename);
}

View File

@ -172,7 +172,7 @@ fn new_parser_etc_from_source_str(sess: parse_sess, cfg: ast::crate_cfg,
+name: ~str, +ss: codemap::file_substr,
source: @~str) -> (Parser, string_reader) {
let ftype = parser::SOURCE_FILE;
let filemap = codemap::new_filemap_w_substr
let filemap = @codemap::new_filemap_w_substr
(name, ss, source, sess.chpos, sess.byte_pos);
sess.cm.files.push(filemap);
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap,
@ -197,7 +197,7 @@ fn new_parser_etc_from_file(sess: parse_sess, cfg: ast::crate_cfg,
result::Err(e) => sess.span_diagnostic.handler().fatal(e)
}
let src = @result::unwrap(res);
let filemap = codemap::new_filemap(path.to_str(), src,
let filemap = @codemap::new_filemap(path.to_str(), src,
sess.chpos, sess.byte_pos);
sess.cm.files.push(filemap);
let srdr = lexer::new_string_reader(sess.span_diagnostic, filemap,

View File

@ -288,7 +288,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
let src = @str::from_bytes(srdr.read_whole_stream());
let itr = parse::token::mk_fake_ident_interner();
let rdr = lexer::new_low_level_string_reader
(span_diagnostic, codemap::new_filemap(path, src, 0u, 0u), itr);
(span_diagnostic, @codemap::new_filemap(path, src, 0u, 0u), itr);
let mut comments: ~[cmnt] = ~[];
let mut literals: ~[lit] = ~[];

View File

@ -25,7 +25,7 @@ type string_reader = @{
mut pos: uint,
mut curr: char,
mut chpos: uint,
filemap: codemap::filemap,
filemap: @codemap::filemap,
interner: @token::ident_interner,
/* cached: */
mut peek_tok: token::Token,
@ -33,7 +33,7 @@ type string_reader = @{
};
fn new_string_reader(span_diagnostic: span_handler,
filemap: codemap::filemap,
filemap: @codemap::filemap,
itr: @token::ident_interner) -> string_reader {
let r = new_low_level_string_reader(span_diagnostic, filemap, itr);
string_advance_token(r); /* fill in peek_* */
@ -42,7 +42,7 @@ fn new_string_reader(span_diagnostic: span_handler,
/* For comments.rs, which hackily pokes into 'pos' and 'curr' */
fn new_low_level_string_reader(span_diagnostic: span_handler,
filemap: codemap::filemap,
filemap: @codemap::filemap,
itr: @token::ident_interner)
-> string_reader {
let r = @{span_diagnostic: span_diagnostic, src: filemap.src,