Fix various drift issues in the qq branch.

This commit is contained in:
Graydon Hoare 2012-02-03 17:39:39 -08:00 committed by Kevin Atkinson
parent dbb13883f7
commit 8fc624bc08
9 changed files with 34 additions and 33 deletions

View File

@ -22,9 +22,7 @@ type codemap = @{mutable files: [filemap]};
type loc = {file: filemap, line: uint, col: uint};
fn new_codemap() -> codemap {
@{mutable files: [new_filemap("-", @"", 0u, 0u)]}
}
fn new_codemap() -> codemap { @{mutable files: [] } }
fn new_filemap_w_substr(filename: filename, substr: file_substr,
src: @str,
@ -50,8 +48,6 @@ fn get_substr_info(cm: codemap, lo: uint, hi: uint)
ret (name, {lo: lo, hi: hi, col: pos.col, line: pos.line});
}
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}];
}
@ -59,7 +55,7 @@ fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
type lookup_fn = fn@(file_pos) -> uint;
fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
-> option::t<{fm: filemap, line: uint}>
-> {fm: filemap, line: uint}
{
let len = vec::len(map.files);
let a = 0u;
@ -69,7 +65,7 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
if lookup(map.files[m].start_pos) > pos { b = m; } else { a = m; }
}
if (a >= len) {
ret none;
fail #fmt("position %u does not resolve to a source location", pos)
}
let f = map.files[a];
a = 0u;
@ -78,18 +74,12 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
let m = (a + b) / 2u;
if lookup(f.lines[m]) > pos { b = m; } else { a = m; }
}
ret some({fm: f, line: a});
ret {fm: f, line: a};
}
fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc {
alt lookup_line(map, pos, lookup) {
some({fm: f, line: a}) {
{file: f, line: a + 1u, col: pos - lookup(f.lines[a])}
}
none {
{ file: empty_filemap(map), line: 0u, col: 0u }
}
}
let {fm: f, line: a} = lookup_line(map, pos, lookup);
ret {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
}
fn lookup_char_pos(map: codemap, pos: uint) -> loc {
@ -168,7 +158,7 @@ fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
-> {fm: filemap, pos: uint}
{
fn lookup(pos: file_pos) -> uint { ret pos.ch; }
let {fm,line} = option::get(lookup_line(cm,chpos,lookup));
let {fm,line} = lookup_line(cm,chpos,lookup);
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
let col = chpos - fm.lines[line].ch;
let col_offset = str::byte_len_range(*fm.src, line_offset, col);

View File

@ -83,7 +83,8 @@ fn expand_crate(sess: session::session, c: @crate) -> @crate {
{fold_expr: bind expand_expr(exts, cx, _, _, _, afp.fold_expr)
with *afp};
let f = make_fold(f_pre);
let cm = parse_expr_from_source_str("<anon>", @core_macros(),
let cm = parse_expr_from_source_str("<core-macros>",
@core_macros(),
sess.opts.cfg,
sess.parse_sess);

View File

@ -248,7 +248,7 @@ fn expand_qquote<N: qq_helper>
rcall = mk_call(cx,sp,
["syntax", "ext", "qquote", "replace"],
[pcall,
mk_vec_e(cx,sp, vec::map(qcx.gather) {|g|
mk_vec_e(cx,sp, vec::map(copy qcx.gather) {|g|
mk_call(cx,sp,
["syntax", "ext", "qquote", g.constr],
[g.e])}),

View File

@ -432,14 +432,10 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))}
ty_task {t}
ty_port(ty) {ty_port(fld.fold_ty(ty))}
ty_chan(ty) {ty_chan(fld.fold_ty(ty))}
ty_rec(fields) {ty_rec(vec::map(fields) {|f| fold_field(f, fld)})}
ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))}
ty_tup(tys) {ty_tup(vec::map(tys) {|ty| fld.fold_ty(ty)})}
ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))}
ty_type {t}
// FIXME: constrs likely needs to be folded...
ty_constr(ty, constrs) {ty_constr(fld.fold_ty(ty), constrs)}
ty_mac(mac) {ty_mac(fold_mac(mac))}

View File

@ -711,9 +711,12 @@ fn gather_comments_and_literals(cm: codemap::codemap,
}
let tok = next_token(rdr);
if is_lit(tok.tok) {
literals += [{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}];
}
let s = rdr.get_str_from(tok.bpos);
literals += [{lit: s, pos: tok.chpos}];
log(debug, "tok lit: " + s);
} else {
log(debug, "tok: " + token::to_str(rdr, tok.tok));
}
first_read = false;
}
ret {cmnts: comments, lits: literals};

View File

@ -1010,9 +1010,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
}
ast::expr_assert(expr) {
word_nbsp(s, "assert");
popen(s);
print_expr(s, expr);
pclose(s);
}
ast::expr_mac(m) { print_mac(s, m); }
}
@ -1494,10 +1492,20 @@ fn print_literal(s: ps, &&lit: @ast::lit) {
word(s.s, "'" + escape_str(str::from_char(ch as char), '\'') + "'");
}
ast::lit_int(i, t) {
word(s.s, int::str(i as int) + ast_util::int_ty_to_str(t));
if i < 0_i64 {
word(s.s,
"-" + u64::to_str(-i as u64, 10u)
+ ast_util::int_ty_to_str(t));
} else {
word(s.s,
u64::to_str(i as u64, 10u)
+ ast_util::int_ty_to_str(t));
}
}
ast::lit_uint(u, t) {
word(s.s, uint::str(u as uint) + ast_util::uint_ty_to_str(t));
word(s.s,
u64::to_str(u, 10u)
+ ast_util::uint_ty_to_str(t));
}
ast::lit_float(f, t) {
word(s.s, f + ast_util::float_ty_to_str(t));

View File

@ -4,5 +4,5 @@ type thing = {x: int, y: int,};
fn main() {
let sth = {x: 0, y: 1,};
let sth2 = {y: 9 with sth};
assert (sth.x + sth2.y == 9);
assert sth.x + sth2.y == 9;
}

View File

@ -10,7 +10,7 @@ fn main() {
}
fn test_color(color: color, val: int, name: str) {
assert (color as int == val);
assert (color as float == val as float);
assert color as int == val;
assert color as float == val as float;
}

View File

@ -85,6 +85,9 @@ fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
pp::eof(pp.s);
let str = mem_buffer_str(buf);
stdout().write_line(str);
if expect != "" {assert str == expect;}
if expect != "" {
#error("expect: '%s', got: '%s'", expect, str);
assert str == expect;
}
}