Skip to content

Commit 8fc624b

Browse files
graydonkevina
authored andcommitted
Fix various drift issues in the qq branch.
1 parent dbb1388 commit 8fc624b

File tree

9 files changed

+34
-33
lines changed

9 files changed

+34
-33
lines changed

src/comp/syntax/codemap.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ type codemap = @{mutable files: [filemap]};
2222

2323
type loc = {file: filemap, line: uint, col: uint};
2424

25-
fn new_codemap() -> codemap {
26-
@{mutable files: [new_filemap("-", @"", 0u, 0u)]}
27-
}
25+
fn new_codemap() -> codemap { @{mutable files: [] } }
2826

2927
fn new_filemap_w_substr(filename: filename, substr: file_substr,
3028
src: @str,
@@ -50,16 +48,14 @@ fn get_substr_info(cm: codemap, lo: uint, hi: uint)
5048
ret (name, {lo: lo, hi: hi, col: pos.col, line: pos.line});
5149
}
5250

53-
fn empty_filemap(cm: codemap) -> filemap {cm.files[0]}
54-
5551
fn next_line(file: filemap, chpos: uint, byte_pos: uint) {
5652
file.lines += [{ch: chpos, byte: byte_pos}];
5753
}
5854

5955
type lookup_fn = fn@(file_pos) -> uint;
6056

6157
fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
62-
-> option::t<{fm: filemap, line: uint}>
58+
-> {fm: filemap, line: uint}
6359
{
6460
let len = vec::len(map.files);
6561
let a = 0u;
@@ -69,7 +65,7 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
6965
if lookup(map.files[m].start_pos) > pos { b = m; } else { a = m; }
7066
}
7167
if (a >= len) {
72-
ret none;
68+
fail #fmt("position %u does not resolve to a source location", pos)
7369
}
7470
let f = map.files[a];
7571
a = 0u;
@@ -78,18 +74,12 @@ fn lookup_line(map: codemap, pos: uint, lookup: lookup_fn)
7874
let m = (a + b) / 2u;
7975
if lookup(f.lines[m]) > pos { b = m; } else { a = m; }
8076
}
81-
ret some({fm: f, line: a});
77+
ret {fm: f, line: a};
8278
}
8379

8480
fn lookup_pos(map: codemap, pos: uint, lookup: lookup_fn) -> loc {
85-
alt lookup_line(map, pos, lookup) {
86-
some({fm: f, line: a}) {
87-
{file: f, line: a + 1u, col: pos - lookup(f.lines[a])}
88-
}
89-
none {
90-
{ file: empty_filemap(map), line: 0u, col: 0u }
91-
}
92-
}
81+
let {fm: f, line: a} = lookup_line(map, pos, lookup);
82+
ret {file: f, line: a + 1u, col: pos - lookup(f.lines[a])};
9383
}
9484

9585
fn lookup_char_pos(map: codemap, pos: uint) -> loc {
@@ -168,7 +158,7 @@ fn lookup_byte_offset(cm: codemap::codemap, chpos: uint)
168158
-> {fm: filemap, pos: uint}
169159
{
170160
fn lookup(pos: file_pos) -> uint { ret pos.ch; }
171-
let {fm,line} = option::get(lookup_line(cm,chpos,lookup));
161+
let {fm,line} = lookup_line(cm,chpos,lookup);
172162
let line_offset = fm.lines[line].byte - fm.start_pos.byte;
173163
let col = chpos - fm.lines[line].ch;
174164
let col_offset = str::byte_len_range(*fm.src, line_offset, col);

src/comp/syntax/ext/expand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ fn expand_crate(sess: session::session, c: @crate) -> @crate {
8383
{fold_expr: bind expand_expr(exts, cx, _, _, _, afp.fold_expr)
8484
with *afp};
8585
let f = make_fold(f_pre);
86-
let cm = parse_expr_from_source_str("<anon>", @core_macros(),
86+
let cm = parse_expr_from_source_str("<core-macros>",
87+
@core_macros(),
8788
sess.opts.cfg,
8889
sess.parse_sess);
8990

src/comp/syntax/ext/qquote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn expand_qquote<N: qq_helper>
248248
rcall = mk_call(cx,sp,
249249
["syntax", "ext", "qquote", "replace"],
250250
[pcall,
251-
mk_vec_e(cx,sp, vec::map(qcx.gather) {|g|
251+
mk_vec_e(cx,sp, vec::map(copy qcx.gather) {|g|
252252
mk_call(cx,sp,
253253
["syntax", "ext", "qquote", g.constr],
254254
[g.e])}),

src/comp/syntax/fold.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,10 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
432432
ty_uniq(mt) {ty_uniq(fold_mt(mt, fld))}
433433
ty_vec(mt) {ty_vec(fold_mt(mt, fld))}
434434
ty_ptr(mt) {ty_ptr(fold_mt(mt, fld))}
435-
ty_task {t}
436-
ty_port(ty) {ty_port(fld.fold_ty(ty))}
437-
ty_chan(ty) {ty_chan(fld.fold_ty(ty))}
438435
ty_rec(fields) {ty_rec(vec::map(fields) {|f| fold_field(f, fld)})}
439436
ty_fn(proto, decl) {ty_fn(proto, fold_fn_decl(decl, fld))}
440437
ty_tup(tys) {ty_tup(vec::map(tys) {|ty| fld.fold_ty(ty)})}
441438
ty_path(path, id) {ty_path(fld.fold_path(path), fld.new_id(id))}
442-
ty_type {t}
443439
// FIXME: constrs likely needs to be folded...
444440
ty_constr(ty, constrs) {ty_constr(fld.fold_ty(ty), constrs)}
445441
ty_mac(mac) {ty_mac(fold_mac(mac))}

src/comp/syntax/parse/lexer.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,12 @@ fn gather_comments_and_literals(cm: codemap::codemap,
711711
}
712712
let tok = next_token(rdr);
713713
if is_lit(tok.tok) {
714-
literals += [{lit: rdr.get_str_from(tok.bpos), pos: tok.chpos}];
714+
let s = rdr.get_str_from(tok.bpos);
715+
literals += [{lit: s, pos: tok.chpos}];
716+
log(debug, "tok lit: " + s);
717+
} else {
718+
log(debug, "tok: " + token::to_str(rdr, tok.tok));
715719
}
716-
log(debug, "tok: " + token::to_str(rdr, tok.tok));
717720
first_read = false;
718721
}
719722
ret {cmnts: comments, lits: literals};

src/comp/syntax/print/pprust.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10101010
}
10111011
ast::expr_assert(expr) {
10121012
word_nbsp(s, "assert");
1013-
popen(s);
10141013
print_expr(s, expr);
1015-
pclose(s);
10161014
}
10171015
ast::expr_mac(m) { print_mac(s, m); }
10181016
}
@@ -1494,10 +1492,20 @@ fn print_literal(s: ps, &&lit: @ast::lit) {
14941492
word(s.s, "'" + escape_str(str::from_char(ch as char), '\'') + "'");
14951493
}
14961494
ast::lit_int(i, t) {
1497-
word(s.s, int::str(i as int) + ast_util::int_ty_to_str(t));
1495+
if i < 0_i64 {
1496+
word(s.s,
1497+
"-" + u64::to_str(-i as u64, 10u)
1498+
+ ast_util::int_ty_to_str(t));
1499+
} else {
1500+
word(s.s,
1501+
u64::to_str(i as u64, 10u)
1502+
+ ast_util::int_ty_to_str(t));
1503+
}
14981504
}
14991505
ast::lit_uint(u, t) {
1500-
word(s.s, uint::str(u as uint) + ast_util::uint_ty_to_str(t));
1506+
word(s.s,
1507+
u64::to_str(u, 10u)
1508+
+ ast_util::uint_ty_to_str(t));
15011509
}
15021510
ast::lit_float(f, t) {
15031511
word(s.s, f + ast_util::float_ty_to_str(t));

src/test/pretty/record-trailing-comma.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ type thing = {x: int, y: int,};
44
fn main() {
55
let sth = {x: 0, y: 1,};
66
let sth2 = {y: 9 with sth};
7-
assert (sth.x + sth2.y == 9);
7+
assert sth.x + sth2.y == 9;
88
}

src/test/run-pass/enum-disr-val-pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
}
1111

1212
fn test_color(color: color, val: int, name: str) {
13-
assert (color as int == val);
14-
assert (color as float == val as float);
13+
assert color as int == val;
14+
assert color as float == val as float;
1515
}
1616

src/test/run-pass/qquote.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
8585
pp::eof(pp.s);
8686
let str = mem_buffer_str(buf);
8787
stdout().write_line(str);
88-
if expect != "" {assert str == expect;}
88+
if expect != "" {
89+
#error("expect: '%s', got: '%s'", expect, str);
90+
assert str == expect;
91+
}
8992
}
9093

0 commit comments

Comments
 (0)