aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-04-08 18:44:20 +0200
committerMarijn Haverbeke <[email protected]>2011-04-09 01:05:18 +0200
commit1af3174fe3b565371a5978381f604ea9c01e86d3 (patch)
tree1690b133b0690fdf6a2c005528355c2d00313129 /src
parentMake lexer buffer the whole file (diff)
downloadrust-1af3174fe3b565371a5978381f604ea9c01e86d3.tar.xz
rust-1af3174fe3b565371a5978381f604ea9c01e86d3.zip
Move to single-uint file-position representation.
This makes passing them around cheaper. There is now a table (see front/codemap.rs) that is needed to transform such an uint into an actual filename/line/col location. Also cleans up the span building in the parser a bit.
Diffstat (limited to 'src')
-rw-r--r--src/comp/driver/rustc.rs7
-rw-r--r--src/comp/driver/session.rs36
-rw-r--r--src/comp/front/codemap.rs65
-rw-r--r--src/comp/front/eval.rs122
-rw-r--r--src/comp/front/extfmt.rs12
-rw-r--r--src/comp/front/lexer.rs81
-rw-r--r--src/comp/front/parser.rs413
-rw-r--r--src/comp/middle/trans.rs5
-rw-r--r--src/comp/pretty/pprust.rs19
-rw-r--r--src/comp/rustc.rc1
-rw-r--r--src/comp/util/common.rs3
11 files changed, 413 insertions, 351 deletions
diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs
index 28953696..c2f63368 100644
--- a/src/comp/driver/rustc.rs
+++ b/src/comp/driver/rustc.rs
@@ -62,7 +62,7 @@ impure fn compile_input(session.session sess,
bool parse_only,
vec[str] library_search_paths) {
auto def = tup(0, 0);
- auto p = parser.new_parser(sess, env, def, input);
+ auto p = parser.new_parser(sess, env, def, input, 0u);
auto crate = parse_input(sess, p, input);
if (parse_only) {ret;}
crate = creader.read_crates(sess, crate, library_search_paths);
@@ -79,7 +79,7 @@ impure fn pretty_print_input(session.session sess,
eval.env env,
str input) {
auto def = tup(0, 0);
- auto p = front.parser.new_parser(sess, env, def, input);
+ auto p = front.parser.new_parser(sess, env, def, input, 0u);
auto crate = front.parser.parse_crate_from_source_file(p);
pretty.pprust.print_file(crate.node.module, input, std.io.stdout());
}
@@ -125,7 +125,8 @@ impure fn main(vec[str] args) {
auto crate_cache = common.new_int_hash[session.crate_metadata]();
auto target_crate_num = 0;
- auto sess = session.session(target_crate_num, target_cfg, crate_cache);
+ auto sess = session.session(target_crate_num, target_cfg, crate_cache,
+ front.codemap.new_codemap());
let option.t[str] input_file = none[str];
let option.t[str] output_file = none[str];
diff --git a/src/comp/driver/session.rs b/src/comp/driver/session.rs
index 797fb7e2..dab02fbd 100644
--- a/src/comp/driver/session.rs
+++ b/src/comp/driver/session.rs
@@ -1,4 +1,5 @@
import front.ast;
+import front.codemap;
import util.common.span;
import util.common.ty_mach;
import std._uint;
@@ -25,7 +26,8 @@ type cfg = rec(os os,
type crate_metadata = vec[u8];
obj session(ast.crate_num cnum, cfg targ,
- map.hashmap[int, crate_metadata] crates) {
+ map.hashmap[int, crate_metadata] crates,
+ codemap.codemap cm) {
fn get_targ_cfg() -> cfg {
ret targ;
@@ -36,10 +38,12 @@ obj session(ast.crate_num cnum, cfg targ,
}
fn span_err(span sp, str msg) {
+ auto lo = codemap.lookup_pos(cm, sp.lo);
+ auto hi = codemap.lookup_pos(cm, sp.hi);
log #fmt("%s:%u:%u:%u:%u: error: %s",
- sp.filename,
- sp.lo.line, sp.lo.col,
- sp.hi.line, sp.hi.col,
+ lo.filename,
+ lo.line, lo.col,
+ hi.line, hi.col,
msg);
fail;
}
@@ -50,10 +54,12 @@ obj session(ast.crate_num cnum, cfg targ,
}
fn span_warn(span sp, str msg) {
+ auto lo = codemap.lookup_pos(cm, sp.lo);
+ auto hi = codemap.lookup_pos(cm, sp.hi);
log #fmt("%s:%u:%u:%u:%u: warning: %s",
- sp.filename,
- sp.lo.line, sp.lo.col,
- sp.hi.line, sp.hi.col,
+ lo.filename,
+ lo.line, lo.col,
+ hi.line, hi.col,
msg);
}
@@ -63,10 +69,12 @@ obj session(ast.crate_num cnum, cfg targ,
}
fn span_unimpl(span sp, str msg) {
+ auto lo = codemap.lookup_pos(cm, sp.lo);
+ auto hi = codemap.lookup_pos(cm, sp.hi);
log #fmt("%s:%u:%u:%u:%u: error: unimplemented %s",
- sp.filename,
- sp.lo.line, sp.lo.col,
- sp.hi.line, sp.hi.col,
+ lo.filename,
+ lo.line, lo.col,
+ hi.line, hi.col,
msg);
fail;
}
@@ -87,6 +95,14 @@ obj session(ast.crate_num cnum, cfg targ,
fn has_external_crate(int num) -> bool {
ret crates.contains_key(num);
}
+
+ fn get_codemap() -> codemap.codemap {
+ ret cm;
+ }
+
+ fn lookup_pos(uint pos) -> codemap.loc {
+ ret codemap.lookup_pos(cm, pos);
+ }
}
diff --git a/src/comp/front/codemap.rs b/src/comp/front/codemap.rs
new file mode 100644
index 00000000..20b4e2ee
--- /dev/null
+++ b/src/comp/front/codemap.rs
@@ -0,0 +1,65 @@
+import std._vec;
+
+/* A codemap is a thing that maps uints to file/line/column positions
+ * in a crate. This to make it possible to represent the positions
+ * with single-word things, rather than passing records all over the
+ * compiler.
+ */
+
+type filemap = @rec(str name,
+ uint start_pos,
+ mutable vec[uint] lines);
+type codemap = @rec(mutable vec[filemap] files);
+type loc = rec(str filename, uint line, uint col);
+
+fn new_codemap() -> codemap {
+ let vec[filemap] files = vec();
+ ret @rec(mutable files=files);
+}
+
+fn new_filemap(str filename, uint start_pos) -> filemap {
+ let vec[uint] lines = vec();
+ ret @rec(name=filename,
+ start_pos=start_pos,
+ mutable lines=lines);
+}
+
+fn next_line(filemap file, uint pos) {
+ _vec.push[uint](file.lines, pos);
+}
+
+fn lookup_pos(codemap map, uint pos) -> loc {
+ for (filemap f in map.files) {
+ if (f.start_pos < pos) {
+ auto line_num = 1u;
+ auto line_start = 0u;
+ // FIXME this can be a binary search if we need to be faster
+ for (uint line_start_ in f.lines) {
+ // FIXME duplicate code due to lack of working break
+ if (line_start_ > pos) {
+ ret rec(filename=f.name,
+ line=line_num,
+ col=pos-line_start);
+ }
+ line_start = line_start_;
+ line_num += 1u;
+ }
+ ret rec(filename=f.name,
+ line=line_num,
+ col=pos-line_start);
+ }
+ }
+ log #fmt("Failed to find a location for character %u", pos);
+ fail;
+}
+
+//
+// Local Variables:
+// mode: rust
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C $RBUILD 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End:
+//
diff --git a/src/comp/front/eval.rs b/src/comp/front/eval.rs
index 1cd4dd49..ca350c36 100644
--- a/src/comp/front/eval.rs
+++ b/src/comp/front/eval.rs
@@ -25,6 +25,9 @@ tag val {
}
type env = vec[tup(ident, val)];
+type ctx = @rec(parser p,
+ session.session sess,
+ mutable uint chpos);
fn mk_env() -> env {
let env e = vec();
@@ -89,50 +92,50 @@ fn lookup(session.session sess, env e, span sp, ident i) -> val {
fail;
}
-fn eval_lit(session.session sess, env e, span sp, @ast.lit lit) -> val {
+fn eval_lit(ctx cx, span sp, @ast.lit lit) -> val {
alt (lit.node) {
case (ast.lit_bool(?b)) { ret val_bool(b); }
case (ast.lit_int(?i)) { ret val_int(i); }
case (ast.lit_str(?s)) { ret val_str(s); }
case (_) {
- sess.span_err(sp, "evaluating unsupported literal");
+ cx.sess.span_err(sp, "evaluating unsupported literal");
}
}
fail;
}
-fn eval_expr(session.session sess, env e, @ast.expr x) -> val {
+fn eval_expr(ctx cx, env e, @ast.expr x) -> val {
alt (x.node) {
case (ast.expr_path(?pth, _, _)) {
if (_vec.len[ident](pth.node.idents) == 1u &&
_vec.len[@ast.ty](pth.node.types) == 0u) {
- ret lookup(sess, e, x.span, pth.node.idents.(0));
+ ret lookup(cx.sess, e, x.span, pth.node.idents.(0));
}
- sess.span_err(x.span, "evaluating structured path-name");
+ cx.sess.span_err(x.span, "evaluating structured path-name");
}
case (ast.expr_lit(?lit, _)) {
- ret eval_lit(sess, e, x.span, lit);
+ ret eval_lit(cx, x.span, lit);
}
case (ast.expr_unary(?op, ?a, _)) {
- auto av = eval_expr(sess, e, a);
+ auto av = eval_expr(cx, e, a);
alt (op) {
case (ast.not) {
if (val_is_bool(av)) {
ret val_bool(!val_as_bool(av));
}
- sess.span_err(x.span, "bad types in '!' expression");
+ cx.sess.span_err(x.span, "bad types in '!' expression");
}
case (_) {
- sess.span_err(x.span, "evaluating unsupported unop");
+ cx.sess.span_err(x.span, "evaluating unsupported unop");
}
}
}
case (ast.expr_binary(?op, ?a, ?b, _)) {
- auto av = eval_expr(sess, e, a);
- auto bv = eval_expr(sess, e, b);
+ auto av = eval_expr(cx, e, a);
+ auto bv = eval_expr(cx, e, b);
alt (op) {
case (ast.add) {
if (val_is_int(av) && val_is_int(bv)) {
@@ -141,66 +144,66 @@ fn eval_expr(session.session sess, env e, @ast.expr x) -> val {
if (val_is_str(av) && val_is_str(bv)) {
ret val_str(val_as_str(av) + val_as_str(bv));
}
- sess.span_err(x.span, "bad types in '+' expression");
+ cx.sess.span_err(x.span, "bad types in '+' expression");
}
case (ast.sub) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) - val_as_int(bv));
}
- sess.span_err(x.span, "bad types in '-' expression");
+ cx.sess.span_err(x.span, "bad types in '-' expression");
}
case (ast.mul) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) * val_as_int(bv));
}
- sess.span_err(x.span, "bad types in '*' expression");
+ cx.sess.span_err(x.span, "bad types in '*' expression");
}
case (ast.div) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) / val_as_int(bv));
}
- sess.span_err(x.span, "bad types in '/' expression");
+ cx.sess.span_err(x.span, "bad types in '/' expression");
}
case (ast.rem) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) % val_as_int(bv));
}
- sess.span_err(x.span, "bad types in '%' expression");
+ cx.sess.span_err(x.span, "bad types in '%' expression");
}
case (ast.and) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) && val_as_bool(bv));
}
- sess.span_err(x.span, "bad types in '&&' expression");
+ cx.sess.span_err(x.span, "bad types in '&&' expression");
}
case (ast.or) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) || val_as_bool(bv));
}
- sess.span_err(x.span, "bad types in '||' expression");
+ cx.sess.span_err(x.span, "bad types in '||' expression");
}
case (ast.eq) {
- ret val_bool(val_eq(sess, x.span, av, bv));
+ ret val_bool(val_eq(cx.sess, x.span, av, bv));
}
case (ast.ne) {
- ret val_bool(! val_eq(sess, x.span, av, bv));
+ ret val_bool(! val_eq(cx.sess, x.span, av, bv));
}
case (_) {
- sess.span_err(x.span, "evaluating unsupported binop");
+ cx.sess.span_err(x.span, "evaluating unsupported binop");
}
}
}
case (_) {
- sess.span_err(x.span, "evaluating unsupported expression");
+ cx.sess.span_err(x.span, "evaluating unsupported expression");
}
}
fail;
@@ -221,7 +224,7 @@ fn val_eq(session.session sess, span sp, val av, val bv) -> bool {
fail;
}
-impure fn eval_crate_directives(parser p,
+impure fn eval_crate_directives(ctx cx,
env e,
vec[@ast.crate_directive] cdirs,
str prefix,
@@ -231,28 +234,27 @@ impure fn eval_crate_directives(parser p,
ast.mod_index_entry] index) {
for (@ast.crate_directive sub_cdir in cdirs) {
- eval_crate_directive(p, e, sub_cdir, prefix,
+ eval_crate_directive(cx, e, sub_cdir, prefix,
view_items, items, index);
}
}
-impure fn eval_crate_directives_to_mod(parser p,
- env e,
+impure fn eval_crate_directives_to_mod(ctx cx, env e,
vec[@ast.crate_directive] cdirs,
str prefix) -> ast._mod {
let vec[@ast.view_item] view_items = vec();
let vec[@ast.item] items = vec();
auto index = new_str_hash[ast.mod_index_entry]();
- eval_crate_directives(p, e, cdirs, prefix,
+ eval_crate_directives(cx, e, cdirs, prefix,
view_items, items, index);
ret rec(view_items=view_items, items=items, index=index);
}
-impure fn eval_crate_directive_block(parser p,
+impure fn eval_crate_directive_block(ctx cx,
env e,
&ast.block blk,
str prefix,
@@ -264,19 +266,18 @@ impure fn eval_crate_directive_block(parser p,
for (@ast.stmt s in blk.node.stmts) {
alt (s.node) {
case (ast.stmt_crate_directive(?cdir)) {
- eval_crate_directive(p, e, cdir, prefix,
+ eval_crate_directive(cx, e, cdir, prefix,
view_items, items, index);
}
case (_) {
- auto sess = p.get_session();
- sess.span_err(s.span,
- "unsupported stmt in crate-directive block");
+ cx.sess.span_err(s.span,
+ "unsupported stmt in crate-directive block");
}
}
}
}
-impure fn eval_crate_directive_expr(parser p,
+impure fn eval_crate_directive_expr(ctx cx,
env e,
@ast.expr x,
str prefix,
@@ -284,25 +285,23 @@ impure fn eval_crate_directive_expr(parser p,
&mutable vec[@ast.item] items,
hashmap[ast.ident,
ast.mod_index_entry] index) {
- auto sess = p.get_session();
-
alt (x.node) {
case (ast.expr_if(?cond, ?thn, ?elopt, _)) {
- auto cv = eval_expr(sess, e, cond);
+ auto cv = eval_expr(cx, e, cond);
if (!val_is_bool(cv)) {
- sess.span_err(x.span, "bad cond type in 'if'");
+ cx.sess.span_err(x.span, "bad cond type in 'if'");
}
if (val_as_bool(cv)) {
- ret eval_crate_directive_block(p, e, thn, prefix,
+ ret eval_crate_directive_block(cx, e, thn, prefix,
view_items, items,
index);
}
alt (elopt) {
case (some[@ast.expr](?els)) {
- ret eval_crate_directive_expr(p, e, els, prefix,
+ ret eval_crate_directive_expr(cx, e, els, prefix,
view_items, items,
index);
}
@@ -313,45 +312,44 @@ impure fn eval_crate_directive_expr(parser p,
}
case (ast.expr_alt(?v, ?arms, _)) {
- auto vv = eval_expr(sess, e, v);
+ auto vv = eval_expr(cx, e, v);
for (ast.arm arm in arms) {
alt (arm.pat.node) {
case (ast.pat_lit(?lit, _)) {
- auto pv = eval_lit(sess, e,
- arm.pat.span, lit);
- if (val_eq(sess, arm.pat.span, vv, pv)) {
+ auto pv = eval_lit(cx, arm.pat.span, lit);
+ if (val_eq(cx.sess, arm.pat.span, vv, pv)) {
ret eval_crate_directive_block
- (p, e, arm.block, prefix,
+ (cx, e, arm.block, prefix,
view_items, items, index);
}
}
case (ast.pat_wild(_)) {
ret eval_crate_directive_block
- (p, e, arm.block, prefix,
+ (cx, e, arm.block, prefix,
view_items, items, index);
}
case (_) {
- sess.span_err(arm.pat.span,
- "bad pattern type in 'alt'");
+ cx.sess.span_err(arm.pat.span,
+ "bad pattern type in 'alt'");
}
}
}
- sess.span_err(x.span, "no cases matched in 'alt'");
+ cx.sess.span_err(x.span, "no cases matched in 'alt'");
}
case (ast.expr_block(?block, _)) {
- ret eval_crate_directive_block(p, e, block, prefix,
+ ret eval_crate_directive_block(cx, e, block, prefix,
view_items, items,
index);
}
case (_) {
- sess.span_err(x.span, "unsupported expr type");
+ cx.sess.span_err(x.span, "unsupported expr type");
}
}
}
-impure fn eval_crate_directive(parser p,
+impure fn eval_crate_directive(ctx cx,
env e,
@ast.crate_directive cdir,
str prefix,
@@ -362,14 +360,14 @@ impure fn eval_crate_directive(parser p,
alt (cdir.node) {
case (ast.cdir_let(?id, ?x, ?cdirs)) {
- auto v = eval_expr(p.get_session(), e, x);
+ auto v = eval_expr(cx, e, x);
auto e0 = vec(tup(id, v)) + e;
- eval_crate_directives(p, e0, cdirs, prefix,
+ eval_crate_directives(cx, e0, cdirs, prefix,
view_items, items, index);
}
case (ast.cdir_expr(?x)) {
- eval_crate_directive_expr(p, e, x, prefix,
+ eval_crate_directive_expr(cx, e, x, prefix,
view_items, items, index);
}
@@ -385,13 +383,15 @@ impure fn eval_crate_directive(parser p,
auto full_path = prefix + std.fs.path_sep() + file_path;
- auto start_id = p.next_def_id();
- auto p0 = new_parser(p.get_session(), e, start_id, full_path);
+ auto start_id = cx.p.next_def_id();
+ auto p0 = new_parser(cx.sess, e, start_id, full_path, cx.chpos);
auto m0 = parse_mod_items(p0, token.EOF);
auto next_id = p0.next_def_id();
- p.set_def(next_id._1);
+ // Thread defids and chpos through the parsers
+ cx.p.set_def(next_id._1);
+ cx.chpos = p0.get_chpos();
auto im = ast.item_mod(id, m0, next_id);
- auto i = @spanned(cdir.span, cdir.span, im);
+ auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
ast.index_item(index, i);
_vec.push[@ast.item](items, i);
}
@@ -407,9 +407,9 @@ impure fn eval_crate_directive(parser p,
}
auto full_path = prefix + std.fs.path_sep() + path;
- auto m0 = eval_crate_directives_to_mod(p, e, cdirs, full_path);
- auto im = ast.item_mod(id, m0, p.next_def_id());
- auto i = @spanned(cdir.span, cdir.span, im);
+ auto m0 = eval_crate_directives_to_mod(cx, e, cdirs, full_path);
+ auto im = ast.item_mod(id, m0, cx.p.next_def_id());
+ auto i = @spanned(cdir.span.lo, cdir.span.hi, im);
ast.index_item(index, i);
_vec.push[@ast.item](items, i);
}
diff --git a/src/comp/front/extfmt.rs b/src/comp/front/extfmt.rs
index 5028e0c8..5e4f86af 100644
--- a/src/comp/front/extfmt.rs
+++ b/src/comp/front/extfmt.rs
@@ -318,9 +318,9 @@ fn parse_type(str s, uint i, uint lim) -> tup(ty, uint) {
fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
fn make_new_lit(common.span sp, ast.lit_ lit) -> @ast.expr {
- auto sp_lit = @parser.spanned[ast.lit_](sp, sp, lit);
+ auto sp_lit = @rec(node=lit, span=sp);
auto expr = ast.expr_lit(sp_lit, ast.ann_none);
- ret @parser.spanned[ast.expr_](sp, sp, expr);
+ ret @rec(node=expr, span=sp);
}
fn make_new_str(common.span sp, str s) -> @ast.expr {
@@ -336,7 +336,7 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
fn make_add_expr(common.span sp,
@ast.expr lhs, @ast.expr rhs) -> @ast.expr {
auto binexpr = ast.expr_binary(ast.add, lhs, rhs, ast.ann_none);
- ret @parser.spanned[ast.expr_](sp, sp, binexpr);
+ ret @rec(node=binexpr, span=sp);
}
fn make_call(common.span sp, vec[ast.ident] fn_path,
@@ -344,11 +344,11 @@ fn pieces_to_expr(vec[piece] pieces, vec[@ast.expr] args) -> @ast.expr {
let vec[ast.ident] path_idents = fn_path;
let vec[@ast.ty] path_types = vec();
auto path = rec(idents = path_idents, types = path_types);
- auto sp_path = parser.spanned[ast.path_](sp, sp, path);
+ auto sp_path = rec(node=path, span=sp);
auto pathexpr = ast.expr_path(sp_path, none[ast.def], ast.ann_none);
- auto sp_pathexpr = @parser.spanned[ast.expr_](sp, sp, pathexpr);
+ auto sp_pathexpr = @rec(node=pathexpr, span=sp);
auto callexpr = ast.expr_call(sp_pathexpr, args, ast.ann_none);
- auto sp_callexpr = @parser.spanned[ast.expr_](sp, sp, callexpr);
+ auto sp_callexpr = @rec(node=callexpr, span=sp);
ret sp_callexpr;
}
diff --git a/src/comp/front/lexer.rs b/src/comp/front/lexer.rs
index fb3a7e27..65091ff7 100644
--- a/src/comp/front/lexer.rs
+++ b/src/comp/front/lexer.rs
@@ -17,42 +17,32 @@ state type reader = state obj {
impure fn init();
impure fn bump();
fn mark();
- fn get_filename() -> str;
- fn get_mark_pos() -> common.pos;
- fn get_curr_pos() -> common.pos;
+ fn get_mark_chpos() -> uint;
+ fn get_chpos() -> uint;
fn get_keywords() -> hashmap[str,token.token];
fn get_reserved() -> hashmap[str,()];
+ fn get_filemap() -> codemap.filemap;
};
-impure fn new_reader(io.reader rdr, str filename) -> reader
-{
+impure fn new_reader(io.reader rdr, str filename, codemap.filemap filemap)
+ -> reader {
state obj reader(str file,
- str filename,
uint len,
mutable uint pos,
mutable char ch,
- mutable uint mark_line,
- mutable uint mark_col,
- mutable uint line,
- mutable uint col,
+ mutable uint mark_chpos,
+ mutable uint chpos,
hashmap[str,token.token] keywords,
- hashmap[str,()] reserved) {
+ hashmap[str,()] reserved,
+ codemap.filemap fm) {
fn is_eof() -> bool {
ret ch == -1 as char;
}
- fn get_curr_pos() -> common.pos {
- ret rec(line=line, col=col);
- }
-
- fn get_mark_pos() -> common.pos {
- ret rec(line=mark_line, col=mark_col);
- }
-
- fn get_filename() -> str {
- ret filename;
- }
+ fn mark() { mark_chpos = chpos; }
+ fn get_mark_chpos() -> uint { ret mark_chpos; }
+ fn get_chpos() -> uint { ret chpos; }
fn curr() -> char {
ret ch;
@@ -73,11 +63,9 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
impure fn bump() {
if (pos < len) {
+ chpos += 1u;
if (ch == '\n') {
- line += 1u;
- col = 0u;
- } else {
- col += 1u;
+ codemap.next_line(fm, chpos);
}
auto next = _str.char_range_at(file, pos);
pos = next._1;
@@ -87,11 +75,6 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
}
}
- fn mark() {
- mark_line = line;
- mark_col = col;
- }
-
fn get_keywords() -> hashmap[str,token.token] {
ret keywords;
}
@@ -99,8 +82,22 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
fn get_reserved() -> hashmap[str,()] {
ret reserved;
}
+
+ fn get_filemap() -> codemap.filemap {
+ ret fm;
+ }
}
+ auto file = _str.unsafe_from_bytes(rdr.read_whole_stream());
+ auto rd = reader(file, _str.byte_len(file), 0u, -1 as char,
+ filemap.start_pos, filemap.start_pos,
+ keyword_table(),
+ reserved_word_table(),
+ filemap);
+ rd.init();
+ ret rd;
+}
+fn keyword_table() -> std.map.hashmap[str, token.token] {
auto keywords = new_str_hash[token.token]();
keywords.insert("mod", token.MOD);
@@ -205,8 +202,11 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
keywords.insert("f32", token.MACH(common.ty_f32));
keywords.insert("f64", token.MACH(common.ty_f64));
- auto reserved = new_str_hash[()]();
+ ret keywords;
+}
+fn reserved_word_table() -> std.map.hashmap[str, ()] {
+ auto reserved = new_str_hash[()]();
reserved.insert("f16", ()); // IEEE 754-2008 'binary16' interchange fmt
reserved.insert("f80", ()); // IEEE 754-1985 'extended'
reserved.insert("f128", ()); // IEEE 754-2008 'binary128'
@@ -214,15 +214,9 @@ impure fn new_reader(io.reader rdr, str filename) -> reader
reserved.insert("m64", ()); // IEEE 754-2008 'decimal64'
reserved.insert("m128", ()); // IEEE 754-2008 'decimal128'
reserved.insert("dec", ()); // One of m32, m64, m128
-
- auto file = _str.unsafe_from_bytes(rdr.read_whole_stream());
- auto rd = reader(file, filename, _str.byte_len(file), 0u, -1 as char,
- 1u, 0u, 1u, 0u, keywords, reserved);
- rd.init();
- ret rd;
+ ret reserved;
}
-
fn in_range(char c, char lo, char hi) -> bool {
ret lo <= c && c <= hi;
}
@@ -797,7 +791,8 @@ tag cmnt_ {
cmnt_line(str);
cmnt_block(vec[str]);
}
-type cmnt = rec(cmnt_ val, common.pos pos, bool space_after);
+
+type cmnt = rec(cmnt_ val, uint pos, bool space_after);
impure fn consume_whitespace(reader rdr) -> uint {
auto lines = 0u;
@@ -809,7 +804,7 @@ impure fn consume_whitespace(reader rdr) -> uint {
}
impure fn read_line_comment(reader rdr) -> cmnt {
- auto p = rdr.get_curr_pos();
+ auto p = rdr.get_chpos();
rdr.bump(); rdr.bump();
while (rdr.curr() == ' ') {rdr.bump();}
auto val = "";
@@ -823,7 +818,7 @@ impure fn read_line_comment(reader rdr) -> cmnt {
}
impure fn read_block_comment(reader rdr) -> cmnt {
- auto p = rdr.get_curr_pos();
+ auto p = rdr.get_chpos();
rdr.bump(); rdr.bump();
while (rdr.curr() == ' ') {rdr.bump();}
let vec[str] lines = vec();
@@ -857,7 +852,7 @@ impure fn read_block_comment(reader rdr) -> cmnt {
impure fn gather_comments(str path) -> vec[cmnt] {
auto srdr = io.file_reader(path);
- auto rdr = new_reader(srdr, path);
+ auto rdr = new_reader(srdr, path, codemap.new_filemap(path, 0u));
let vec[cmnt] comments = vec();
while (!rdr.is_eof()) {
while (true) {
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 5ed7dd27..617f1813 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -34,21 +34,25 @@ state type parser =
fn get_env() -> eval.env;
fn get_session() -> session.session;
fn get_span() -> common.span;
+ fn get_lo_pos() -> uint;
+ fn get_hi_pos() -> uint;
fn next_def_id() -> ast.def_id;
fn set_def(ast.def_num);
fn get_prec_table() -> vec[op_spec];
+ fn get_filemap() -> codemap.filemap;
+ fn get_chpos() -> uint;
};
impure fn new_parser(session.session sess,
eval.env env,
ast.def_id initial_def,
- str path) -> parser {
+ str path, uint pos) -> parser {
state obj stdio_parser(session.session sess,
eval.env env,
file_type ftype,
mutable token.token tok,
- mutable common.pos lo,
- mutable common.pos hi,
+ mutable uint lo,
+ mutable uint hi,
mutable ast.def_num def,
mutable restriction res,
ast.crate_num crate,
@@ -63,14 +67,12 @@ impure fn new_parser(session.session sess,
// log rdr.get_filename()
// + ":" + common.istr(lo.line as int);
tok = lexer.next_token(rdr);
- lo = rdr.get_mark_pos();
- hi = rdr.get_curr_pos();
+ lo = rdr.get_mark_chpos();
+ hi = rdr.get_chpos();
}
impure fn err(str m) {
- auto span = rec(filename = rdr.get_filename(),
- lo = lo, hi = hi);
- sess.span_err(span, m);
+ sess.span_err(rec(lo=lo, hi=hi), m);
}
impure fn restrict(restriction r) {
@@ -85,10 +87,9 @@ impure fn new_parser(session.session sess,
ret sess;
}
- fn get_span() -> common.span {
- ret rec(filename = rdr.get_filename(),
- lo = lo, hi = hi);
- }
+ fn get_span() -> common.span { ret rec(lo=lo, hi=hi); }
+ fn get_lo_pos() -> uint { ret lo; }
+ fn get_hi_pos() -> uint { ret hi; }
fn next_def_id() -> ast.def_id {
def += 1;
@@ -110,16 +111,24 @@ impure fn new_parser(session.session sess,
fn get_prec_table() -> vec[op_spec] {
ret precs;
}
+
+ fn get_filemap() -> codemap.filemap {
+ ret rdr.get_filemap();
+ }
+
+ fn get_chpos() -> uint {ret rdr.get_chpos();}
}
auto ftype = SOURCE_FILE;
if (_str.ends_with(path, ".rc")) {
ftype = CRATE_FILE;
}
auto srdr = io.file_reader(path);
- auto rdr = lexer.new_reader(srdr, path);
+ auto filemap = codemap.new_filemap(path, pos);
+ _vec.push[codemap.filemap](sess.get_codemap().files, filemap);
+ auto rdr = lexer.new_reader(srdr, path, filemap);
// Make sure npos points at first actual token.
lexer.consume_any_whitespace(rdr);
- auto npos = rdr.get_curr_pos();
+ auto npos = rdr.get_chpos();
ret stdio_parser(sess, env, ftype, lexer.next_token(rdr),
npos, npos, initial_def._1, UNRESTRICTED, initial_def._0,
rdr, prec_table());
@@ -143,10 +152,8 @@ impure fn expect(parser p, token.token t) {
}
}
-fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
- ret rec(node=node, span=rec(filename=lo.filename,
- lo=lo.lo,
- hi=hi.hi));
+fn spanned[T](uint lo, uint hi, &T node) -> ast.spanned[T] {
+ ret rec(node=node, span=rec(lo=lo, hi=hi));
}
impure fn parse_ident(parser p) -> ast.ident {
@@ -185,8 +192,8 @@ impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
}
-impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
- ast.span lo) -> ast.ty_ {
+impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p, uint lo)
+ -> ast.ty_ {
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
auto mode;
if (p.peek() == token.BINOP(token.AND)) {
@@ -211,7 +218,7 @@ impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
ret rec(mode=mode, ty=t);
}
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto f = parse_fn_input_ty; // FIXME: trans_const_lval bug
auto inputs = parse_seq[rec(ast.mode mode, @ast.ty ty)](token.LPAREN,
@@ -226,7 +233,7 @@ impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
p.bump();
output = parse_ty(p);
} else {
- output = @spanned(lo, inputs.span, ast.ty_nil);
+ output = @spanned(lo, inputs.span.hi, ast.ty_nil);
}
ret ast.ty_fn(eff, proto, inputs.node, output);
@@ -241,10 +248,10 @@ impure fn parse_proto(parser p) -> ast.proto {
fail;
}
-impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
+impure fn parse_ty_obj(parser p, &mutable uint hi) -> ast.ty_ {
expect(p, token.OBJ);
impure fn parse_method_sig(parser p) -> ast.ty_method {
- auto flo = p.get_span();
+ auto flo = p.get_lo_pos();
let ast.effect eff = parse_effect(p);
let ast.proto proto = parse_proto(p);
@@ -265,7 +272,7 @@ impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
token.RBRACE,
none[token.token],
f, p);
- hi = meths.span;
+ hi = meths.span.hi;
ret ast.ty_obj(meths.node);
}
@@ -282,30 +289,29 @@ impure fn parse_ty_field(parser p) -> ast.ty_field {
}
impure fn parse_constr_arg(parser p) -> @ast.constr_arg {
- auto lo = p.get_span();
+ auto sp = p.get_span();
auto carg = ast.carg_base;
if (p.peek() == token.BINOP(token.STAR)) {
p.bump();
} else {
carg = ast.carg_ident(parse_ident(p));
}
- ret @spanned(lo, lo, carg);
+ ret @rec(node=carg, span=sp);
}
impure fn parse_ty_constr(parser p) -> @ast.constr {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto path = parse_path(p, GREEDY);
auto pf = parse_constr_arg;
auto args = parse_seq[@ast.constr_arg](token.LPAREN,
token.RPAREN,
some(token.COMMA), pf, p);
- auto hi = args.span;
- ret @spanned(lo, hi, rec(path=path, args=args.node));
+ ret @spanned(lo, args.span.hi, rec(path=path, args=args.node));
}
impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
+ auto hi = p.get_hi_pos();
let vec[@ast.constr] constrs = vec();
if (p.peek() == token.COLON) {
p.bump();
@@ -314,7 +320,7 @@ impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
alt (p.peek()) {
case (token.IDENT(_)) {
auto constr = parse_ty_constr(p);
- hi = constr.span;
+ hi = constr.span.hi;
_vec.push[@ast.constr](constrs, constr);
if (p.peek() == token.COMMA) {
p.bump();
@@ -331,14 +337,14 @@ impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
impure fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
if (p.peek() == token.COLON) {
auto constrs = parse_constrs(p);
- ret @spanned(t.span, constrs.span,
+ ret @spanned(t.span.lo, constrs.span.hi,
ast.ty_constr(t, constrs.node));
}
ret t;
}
impure fn parse_ty(parser p) -> @ast.ty {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto hi = lo;
let ast.ty_ t;
@@ -360,13 +366,13 @@ impure fn parse_ty(parser p) -> @ast.ty {
p.bump();
alt (p.peek()) {
case (token.RPAREN) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
p.bump();
t = ast.ty_nil;
}
case (_) {
t = parse_ty(p).node;
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RPAREN);
}
}
@@ -375,7 +381,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
case (token.AT) {
p.bump();
auto mt = parse_mt(p);
- hi = mt.ty.span;
+ hi = mt.ty.span.hi;
t = ast.ty_box(mt);
}
@@ -383,7 +389,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
p.bump();
expect(p, token.LBRACKET);
t = ast.ty_vec(parse_mt(p));
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RBRACKET);
}
@@ -393,7 +399,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
auto elems = parse_seq[ast.mt] (token.LPAREN,
token.RPAREN,
some(token.COMMA), f, p);
- hi = elems.span;
+ hi = elems.span.hi;
t = ast.ty_tup(elems.node);
}
@@ -405,28 +411,28 @@ impure fn parse_ty(parser p) -> @ast.ty {
token.RPAREN,
some(token.COMMA),
f, p);
- hi = elems.span;
+ hi = elems.span.hi;
t = ast.ty_rec(elems.node);
}
case (token.FN) {
- auto flo = p.get_span();
+ auto flo = p.get_lo_pos();
p.bump();
t = parse_ty_fn(eff, ast.proto_fn, p, flo);
alt (t) {
case (ast.ty_fn(_, _, _, ?out)) {
- hi = out.span;
+ hi = out.span.hi;
}
}
}
case (token.ITER) {
- auto flo = p.get_span();
+ auto flo = p.get_lo_pos();
p.bump();
t = parse_ty_fn(eff, ast.proto_iter, p, flo);
alt (t) {
case (ast.ty_fn(_, _, _, ?out)) {
- hi = out.span;
+ hi = out.span.hi;
}
}
}
@@ -439,7 +445,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
p.bump();
expect(p, token.LBRACKET);
t = ast.ty_port(parse_ty(p));
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RBRACKET);
}
@@ -447,14 +453,14 @@ impure fn parse_ty(parser p) -> @ast.ty {
p.bump();
expect(p, token.LBRACKET);
t = ast.ty_chan(parse_ty(p));
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RBRACKET);
}
case (token.IDENT(_)) {
auto path = parse_path(p, GREEDY);
t = ast.ty_path(path, none[ast.def]);
- hi = path.span;
+ hi = path.span.hi;
}
case (token.MUTABLE) {
@@ -463,7 +469,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
"ignoring deprecated 'mutable' type constructor");
auto typ = parse_ty(p);
t = typ.node;
- hi = typ.span;
+ hi = typ.span.hi;
}
case (_) {
@@ -495,6 +501,7 @@ impure fn parse_arg(parser p) -> ast.arg {
impure fn parse_seq_to_end[T](token.token ket,
option.t[token.token] sep,
(impure fn(parser) -> T) f,
+ mutable uint hi,
parser p) -> vec[T] {
let bool first = true;
let vec[T] v = vec();
@@ -514,24 +521,25 @@ impure fn parse_seq_to_end[T](token.token ket,
let T t = f(p);
v += vec(t);
}
+ hi = p.get_hi_pos();
expect(p, ket);
ret v;
}
impure fn parse_seq[T](token.token bra,
- token.token ket,
- option.t[token.token] sep,
- (impure fn(parser) -> T) f,
- parser p) -> util.common.spanned[vec[T]] {
- auto lo = p.get_span();
+ token.token ket,
+ option.t[token.token] sep,
+ (impure fn(parser) -> T) f,
+ parser p) -> util.common.spanned[vec[T]] {
+ auto lo = p.get_lo_pos();
+ auto hi = p.get_hi_pos();
expect(p, bra);
- auto result = parse_seq_to_end[T](ket, sep, f, p);
- auto hi = p.get_span();
+ auto result = parse_seq_to_end[T](ket, sep, f, hi, p);
ret spanned(lo, hi, result);
}
impure fn parse_lit(parser p) -> ast.lit {
- auto lo = p.get_span();
+ auto sp = p.get_span();
let ast.lit_ lit = ast.lit_nil;
alt (p.peek()) {
case (token.LIT_INT(?i)) {
@@ -570,7 +578,7 @@ impure fn parse_lit(parser p) -> ast.lit {
unexpected(p, t);
}
}
- ret spanned(lo, lo, lit);
+ ret rec(node=lit, span=sp);
}
fn is_ident(token.token t) -> bool {
@@ -586,7 +594,7 @@ tag greed {
MINIMAL;
}
-impure fn parse_ty_args(parser p, span hi) ->
+impure fn parse_ty_args(parser p, uint hi) ->
util.common.spanned[vec[@ast.ty]] {
if (p.peek() == token.LBRACKET) {
@@ -597,12 +605,13 @@ impure fn parse_ty_args(parser p, span hi) ->
pf, p);
}
let vec[@ast.ty] v = vec();
+ auto pos = p.get_lo_pos();
ret spanned(hi, hi, v);
}
impure fn parse_path(parser p, greed g) -> ast.path {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto hi = lo;
let vec[ast.ident] ids = vec();
@@ -610,7 +619,7 @@ impure fn parse_path(parser p, greed g) -> ast.path {
while (more) {
alt (p.peek()) {
case (token.IDENT(?i)) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
ids += vec(i);
p.bump();
if (p.peek() == token.DOT) {
@@ -631,7 +640,7 @@ impure fn parse_path(parser p, greed g) -> ast.path {
}
auto tys = parse_ty_args(p, hi);
- ret spanned(lo, tys.span, rec(idents=ids, types=tys.node));
+ ret spanned(lo, tys.span.hi, rec(idents=ids, types=tys.node));
}
impure fn parse_mutability(parser p) -> ast.mutability {
@@ -656,19 +665,19 @@ impure fn parse_field(parser p) -> ast.field {
impure fn parse_bottom_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
+ auto hi = p.get_hi_pos();
// FIXME: can only remove this sort of thing when both typestate and
// alt-exhaustive-match checking are co-operating.
- auto lit = @spanned(lo, lo, ast.lit_nil);
+ auto lit = @spanned(lo, hi, ast.lit_nil);
let ast.expr_ ex = ast.expr_lit(lit, ast.ann_none);
alt (p.peek()) {
case (token.IDENT(_)) {
auto pth = parse_path(p, MINIMAL);
- hi = pth.span;
+ hi = pth.span.hi;
ex = ast.expr_path(pth, none[ast.def], ast.ann_none);
}
@@ -676,7 +685,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
p.bump();
alt (p.peek()) {
case (token.RPAREN) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
p.bump();
auto lit = @spanned(lo, hi, ast.lit_nil);
ret @spanned(lo, hi,
@@ -685,7 +694,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
case (_) { /* fall through */ }
}
auto e = parse_expr(p);
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RPAREN);
ret @spanned(lo, hi, e.node);
}
@@ -703,7 +712,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- hi = es.span;
+ hi = es.span.hi;
ex = ast.expr_tup(es.node, ast.ann_none);
}
@@ -716,8 +725,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
auto es = parse_seq_to_end[@ast.expr](token.RPAREN,
some(token.COMMA),
- pf, p);
- hi = p.get_span();
+ pf, hi, p);
ex = ast.expr_vec(es, mut, ast.ann_none);
}
@@ -731,14 +739,14 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
while (more) {
alt (p.peek()) {
case (token.RPAREN) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
p.bump();
more = false;
}
case (token.WITH) {
p.bump();
base = some[@ast.expr](parse_expr(p));
- hi = p.get_span();
+ hi = p.get_hi_pos();
expect(p, token.RPAREN);
more = false;
}
@@ -776,7 +784,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- hi = es.span;
+ hi = es.span.hi;
ex = ast.expr_bind(e, es.node, ast.ann_none);
}
@@ -788,7 +796,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- hi = es.span;
+ hi = es.span.hi;
ex = expand_syntax_ext(p, es.span, pth, es.node,
none[@ast.expr]);
}
@@ -801,7 +809,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
case (token.LOG) {
p.bump();
auto e = parse_expr(p);
- auto hi = e.span;
+ auto hi = e.span.hi;
ex = ast.expr_log(e, ast.ann_none);
}
@@ -810,7 +818,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
alt (p.peek()) {
case (token.LPAREN) {
auto e = parse_expr(p);
- auto hi = e.span;
+ auto hi = e.span.hi;
ex = ast.expr_check_expr(e, ast.ann_none);
}
case (_) {
@@ -827,7 +835,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
}
case (_) {
auto e = parse_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_ret(some[@ast.expr](e), ast.ann_none);
}
}
@@ -851,7 +859,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
}
case (_) {
auto e = parse_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_put(some[@ast.expr](e), ast.ann_none);
}
}
@@ -862,7 +870,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
auto e = parse_expr(p);
// FIXME: Is this the right place for this check?
if /*check*/ (ast.is_call_expr(e)) {
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_be(e, ast.ann_none);
}
else {
@@ -874,7 +882,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
p.bump();
expect(p, token.LPAREN);
expect(p, token.RPAREN);
- hi = p.get_span();
+ hi = p.get_hi_pos();
ex = ast.expr_port(ast.ann_none);
}
@@ -882,7 +890,7 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
p.bump();
expect(p, token.LPAREN);
auto e = parse_expr(p);
- hi = e.span;
+ hi = e.span.hi;
expect(p, token.RPAREN);
ex = ast.expr_chan(e, ast.ann_none);
}
@@ -899,13 +907,13 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- hi = es.span;
+ hi = es.span.hi;
ex = ast.expr_call(f, es.node, ast.ann_none);
}
case (_) {
auto lit = parse_lit(p);
- hi = lit.span;
+ hi = lit.span.hi;
ex = ast.expr_lit(@lit, ast.ann_none);
}
}
@@ -941,7 +949,7 @@ impure fn expand_syntax_ext(parser p, ast.span sp,
}
}
-impure fn extend_expr_by_ident(parser p, span lo, span hi,
+impure fn extend_expr_by_ident(parser p, uint lo, uint hi,
@ast.expr e, ast.ident i) -> @ast.expr {
auto e_ = e.node;
alt (e.node) {
@@ -950,11 +958,11 @@ impure fn extend_expr_by_ident(parser p, span lo, span hi,
auto idents_ = pth.node.idents;
idents_ += vec(i);
auto tys = parse_ty_args(p, hi);
- auto pth_ = spanned(pth.span, tys.span,
+ auto pth_ = spanned(pth.span.lo, tys.span.hi,
rec(idents=idents_,
types=tys.node));
e_ = ast.expr_path(pth_, def, ann);
- ret @spanned(pth_.span, pth_.span, e_);
+ ret @spanned(pth_.span.lo, pth_.span.hi, e_);
} else {
e_ = ast.expr_field(e, i, ann);
}
@@ -967,16 +975,16 @@ impure fn extend_expr_by_ident(parser p, span lo, span hi,
}
impure fn parse_self_method(parser p) -> @ast.expr {
- auto lo = p.get_span();
+ auto sp = p.get_span();
let ast.ident f_name = parse_ident(p);
auto hi = p.get_span();
- ret @spanned(lo, hi, ast.expr_self_method(f_name, ast.ann_none));
+ ret @rec(node=ast.expr_self_method(f_name, ast.ann_none), span=sp);
}
impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto e = parse_bottom_expr(p);
- auto hi = e.span;
+ auto hi = e.span.hi;
while (true) {
alt (p.peek()) {
@@ -990,7 +998,7 @@ impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- hi = es.span;
+ hi = es.span.hi;
auto e_ = ast.expr_call(e, es.node, ast.ann_none);
e = @spanned(lo, hi, e_);
}
@@ -1001,7 +1009,7 @@ impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
alt (p.peek()) {
case (token.IDENT(?i)) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
p.bump();
e = extend_expr_by_ident(p, lo, hi, e, i);
}
@@ -1009,7 +1017,7 @@ impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
case (token.LPAREN) {
p.bump();
auto ix = parse_expr(p);
- hi = ix.span;
+ hi = ix.span.hi;
expect(p, token.RPAREN);
auto e_ = ast.expr_index(e, ix, ast.ann_none);
e = @spanned(lo, hi, e_);
@@ -1036,8 +1044,8 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
"ignoring deprecated 'mutable' prefix operator");
}
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
+ auto hi = p.get_hi_pos();
// FIXME: can only remove this sort of thing when both typestate and
// alt-exhaustive-match checking are co-operating.
@@ -1049,14 +1057,14 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
case (token.NOT) {
p.bump();
auto e = parse_prefix_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_unary(ast.not, e, ast.ann_none);
}
case (token.TILDE) {
p.bump();
auto e = parse_prefix_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_unary(ast.bitnot, e, ast.ann_none);
}
@@ -1065,14 +1073,14 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
case (token.MINUS) {
p.bump();
auto e = parse_prefix_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_unary(ast.neg, e, ast.ann_none);
}
case (token.STAR) {
p.bump();
auto e = parse_prefix_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_unary(ast.deref, e, ast.ann_none);
}
@@ -1086,7 +1094,7 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
p.bump();
auto m = parse_mutability(p);
auto e = parse_prefix_expr(p);
- hi = e.span;
+ hi = e.span.hi;
ex = ast.expr_unary(ast.box(m), e, ast.ann_none);
}
@@ -1144,7 +1152,7 @@ impure fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
case (token.AS) {
auto rhs = parse_ty(p);
auto _as = ast.expr_cast(lhs, rhs, ast.ann_none);
- auto span = @spanned(lhs.span, rhs.span, _as);
+ auto span = @spanned(lhs.span.lo, rhs.span.hi, _as);
ret parse_more_binops(p, span, min_prec);
}
case (_) {
@@ -1152,7 +1160,7 @@ impure fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
cur.prec);
auto bin = ast.expr_binary(cur.op, lhs, rhs,
ast.ann_none);
- auto span = @spanned(lhs.span, rhs.span, bin);
+ auto span = @spanned(lhs.span.lo, rhs.span.hi, bin);
ret parse_more_binops(p, span, min_prec);
}
}
@@ -1162,13 +1170,13 @@ impure fn parse_more_binops(parser p, @ast.expr lhs, int min_prec)
}
impure fn parse_assign_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto lhs = parse_binops(p);
alt (p.peek()) {
case (token.EQ) {
p.bump();
auto rhs = parse_expr(p);
- ret @spanned(lo, rhs.span,
+ ret @spanned(lo, rhs.span.hi,
ast.expr_assign(lhs, rhs, ast.ann_none));
}
case (token.BINOPEQ(?op)) {
@@ -1188,19 +1196,19 @@ impure fn parse_assign_expr(parser p) -> @ast.expr {
case (token.LSR) { aop = ast.lsr; }
case (token.ASR) { aop = ast.asr; }
}
- ret @spanned(lo, rhs.span,
+ ret @spanned(lo, rhs.span.hi,
ast.expr_assign_op(aop, lhs, rhs, ast.ann_none));
}
case (token.SEND) {
p.bump();
auto rhs = parse_expr(p);
- ret @spanned(lo, rhs.span,
+ ret @spanned(lo, rhs.span.hi,
ast.expr_send(lhs, rhs, ast.ann_none));
}
case (token.LARROW) {
p.bump();
auto rhs = parse_expr(p);
- ret @spanned(lo, rhs.span,
+ ret @spanned(lo, rhs.span.hi,
ast.expr_recv(lhs, rhs, ast.ann_none));
}
case (_) { /* fall through */ }
@@ -1209,8 +1217,7 @@ impure fn parse_assign_expr(parser p) -> @ast.expr {
}
impure fn parse_if_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
expect(p, token.IF);
expect(p, token.LPAREN);
@@ -1218,12 +1225,12 @@ impure fn parse_if_expr(parser p) -> @ast.expr {
expect(p, token.RPAREN);
auto thn = parse_block(p);
let option.t[@ast.expr] els = none[@ast.expr];
- hi = thn.span;
+ auto hi = thn.span.hi;
alt (p.peek()) {
case (token.ELSE) {
auto elexpr = parse_else_expr(p);
els = some(elexpr);
- hi = elexpr.span;
+ hi = elexpr.span.hi;
}
case (_) { /* fall through */ }
}
@@ -1239,29 +1246,27 @@ impure fn parse_else_expr(parser p) -> @ast.expr {
}
case (_) {
auto blk = parse_block(p);
- ret @spanned(blk.span, blk.span,
+ ret @spanned(blk.span.lo, blk.span.hi,
ast.expr_block(blk, ast.ann_none));
}
}
}
impure fn parse_head_local(parser p) -> @ast.decl {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
let @ast.local local;
if (p.peek() == token.AUTO) {
local = parse_auto_local(p);
} else {
local = parse_typed_local(p);
}
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
}
impure fn parse_for_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
auto is_each = false;
expect(p, token.FOR);
@@ -1278,10 +1283,10 @@ impure fn parse_for_expr(parser p) -> @ast.expr {
auto seq = parse_expr(p);
expect(p, token.RPAREN);
auto body = parse_block(p);
- hi = body.span;
+ auto hi = body.span.hi;
if (is_each) {
ret @spanned(lo, hi, ast.expr_for_each(decl, seq, body,
- ast.ann_none));
+ ast.ann_none));
} else {
ret @spanned(lo, hi, ast.expr_for(decl, seq, body,
ast.ann_none));
@@ -1290,21 +1295,19 @@ impure fn parse_for_expr(parser p) -> @ast.expr {
impure fn parse_while_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
expect(p, token.WHILE);
expect (p, token.LPAREN);
auto cond = parse_expr(p);
expect(p, token.RPAREN);
auto body = parse_block(p);
- hi = body.span;
+ auto hi = body.span.hi;
ret @spanned(lo, hi, ast.expr_while(cond, body, ast.ann_none));
}
impure fn parse_do_while_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
expect(p, token.DO);
auto body = parse_block(p);
@@ -1312,12 +1315,12 @@ impure fn parse_do_while_expr(parser p) -> @ast.expr {
expect (p, token.LPAREN);
auto cond = parse_expr(p);
expect(p, token.RPAREN);
- hi = cond.span;
+ auto hi = cond.span.hi;
ret @spanned(lo, hi, ast.expr_do_while(body, cond, ast.ann_none));
}
impure fn parse_alt_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.ALT);
expect(p, token.LPAREN);
auto discriminant = parse_expr(p);
@@ -1347,7 +1350,7 @@ impure fn parse_alt_expr(parser p) -> @ast.expr {
case (token.ELSE) {
p.bump();
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
auto pat = @spanned(lo, hi, ast.pat_wild(ast.ann_none));
auto index = index_arm(pat);
auto block = parse_block(p);
@@ -1360,15 +1363,15 @@ impure fn parse_alt_expr(parser p) -> @ast.expr {
}
}
}
+ auto hi = p.get_hi_pos();
p.bump();
auto expr = ast.expr_alt(discriminant, arms, ast.ann_none);
- auto hi = p.get_span();
ret @spanned(lo, hi, expr);
}
impure fn parse_spawn_expr(parser p) -> @ast.expr {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.SPAWN);
// FIXME: Parse domain and name
@@ -1379,7 +1382,7 @@ impure fn parse_spawn_expr(parser p) -> @ast.expr {
token.RPAREN,
some(token.COMMA),
pf, p);
- auto hi = es.span;
+ auto hi = es.span.hi;
auto spawn_expr = ast.expr_spawn(ast.dom_implicit,
option.none[str],
fn_expr,
@@ -1404,7 +1407,7 @@ impure fn parse_expr_inner(parser p) -> @ast.expr {
alt (p.peek()) {
case (token.LBRACE) {
auto blk = parse_block(p);
- ret @spanned(blk.span, blk.span,
+ ret @spanned(blk.span.lo, blk.span.hi,
ast.expr_block(blk, ast.ann_none));
}
case (token.IF) {
@@ -1451,13 +1454,12 @@ impure fn parse_initializer(parser p) -> option.t[ast.initializer] {
}
impure fn parse_pat(parser p) -> @ast.pat {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
+ auto hi = p.get_hi_pos();
auto pat;
alt (p.peek()) {
case (token.UNDERSCORE) {
- hi = p.get_span();
p.bump();
pat = ast.pat_wild(ast.ann_none);
}
@@ -1465,7 +1467,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
p.bump();
alt (p.peek()) {
case (token.IDENT(?id)) {
- hi = p.get_span();
+ hi = p.get_hi_pos();
p.bump();
pat = ast.pat_bind(id, p.next_def_id(), ast.ann_none);
}
@@ -1478,7 +1480,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
}
case (token.IDENT(?id)) {
auto tag_path = parse_path(p, GREEDY);
- hi = tag_path.span;
+ hi = tag_path.span.hi;
let vec[@ast.pat] args;
alt (p.peek()) {
@@ -1487,7 +1489,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
auto a = parse_seq[@ast.pat](token.LPAREN, token.RPAREN,
some(token.COMMA), f, p);
args = a.node;
- hi = a.span;
+ hi = a.span.hi;
}
case (_) { args = vec(); }
}
@@ -1497,7 +1499,7 @@ impure fn parse_pat(parser p) -> @ast.pat {
}
case (_) {
auto lit = parse_lit(p);
- hi = lit.span;
+ hi = lit.span.hi;
pat = ast.pat_lit(@lit, ast.ann_none);
}
}
@@ -1527,19 +1529,17 @@ impure fn parse_auto_local(parser p) -> @ast.local {
}
impure fn parse_let(parser p) -> @ast.decl {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.LET);
auto local = parse_typed_local(p);
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
}
impure fn parse_auto(parser p) -> @ast.decl {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.AUTO);
auto local = parse_auto_local(p);
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.decl_local(local));
+ ret @spanned(lo, p.get_hi_pos(), ast.decl_local(local));
}
impure fn parse_stmt(parser p) -> @ast.stmt {
@@ -1552,39 +1552,38 @@ impure fn parse_stmt(parser p) -> @ast.stmt {
impure fn parse_crate_stmt(parser p) -> @ast.stmt {
auto cdir = parse_crate_directive(p);
- ret @spanned(cdir.span, cdir.span,
+ ret @spanned(cdir.span.lo, cdir.span.hi,
ast.stmt_crate_directive(@cdir));
}
impure fn parse_source_stmt(parser p) -> @ast.stmt {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
alt (p.peek()) {
case (token.LET) {
auto decl = parse_let(p);
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
+ ret @spanned(lo, decl.span.hi,
+ ast.stmt_decl(decl, none[@ts_ann]));
}
case (token.AUTO) {
auto decl = parse_auto(p);
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
+ ret @spanned(lo, decl.span.hi,
+ ast.stmt_decl(decl, none[@ts_ann]));
}
case (_) {
if (peeking_at_item(p)) {
// Might be a local item decl.
auto i = parse_item(p);
- auto hi = i.span;
+ auto hi = i.span.hi;
auto decl = @spanned(lo, hi, ast.decl_item(i));
ret @spanned(lo, hi, ast.stmt_decl(decl, none[@ts_ann]));
} else {
// Remainder are line-expr stmts.
auto e = parse_expr(p);
- auto hi = p.get_span();
- ret @spanned(lo, hi, ast.stmt_expr(e, none[@ts_ann]));
+ ret @spanned(lo, e.span.hi, ast.stmt_expr(e, none[@ts_ann]));
}
}
}
@@ -1678,7 +1677,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
}
impure fn parse_block(parser p) -> ast.block {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
let vec[@ast.stmt] stmts = vec();
let option.t[@ast.expr] expr = none[@ast.expr];
@@ -1731,7 +1730,7 @@ impure fn parse_block(parser p) -> ast.block {
}
}
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
p.bump();
auto bloc = index_block(stmts, expr);
@@ -1774,7 +1773,7 @@ impure fn parse_fn_decl(parser p, ast.effect eff) -> ast.fn_decl {
p.bump();
output = parse_ty(p);
} else {
- output = @spanned(inputs.span, inputs.span, ast.ty_nil);
+ output = @spanned(inputs.span.lo, inputs.span.hi, ast.ty_nil);
}
ret rec(effect=eff, inputs=inputs.node, output=output);
}
@@ -1795,13 +1794,13 @@ impure fn parse_fn_header(parser p)
}
impure fn parse_item_fn_or_iter(parser p, ast.effect eff) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto proto = parse_proto(p);
auto t = parse_fn_header(p);
auto f = parse_fn(p, eff, proto);
auto item = ast.item_fn(t._0, f, t._1,
p.next_def_id(), ast.ann_none);
- ret @spanned(lo, f.body.span, item);
+ ret @spanned(lo, f.body.span.hi, item);
}
@@ -1813,18 +1812,18 @@ impure fn parse_obj_field(parser p) -> ast.obj_field {
}
impure fn parse_method(parser p) -> @ast.method {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
auto eff = parse_effect(p);
auto proto = parse_proto(p);
auto ident = parse_ident(p);
auto f = parse_fn(p, eff, proto);
auto meth = rec(ident=ident, meth=f,
id=p.next_def_id(), ann=ast.ann_none);
- ret @spanned(lo, f.body.span, meth);
+ ret @spanned(lo, f.body.span.hi, meth);
}
impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.OBJ);
auto ident = parse_ident(p);
auto ty_params = parse_ty_params(p);
@@ -1852,7 +1851,7 @@ impure fn parse_item_obj(parser p, ast.layer lyr) -> @ast.item {
}
}
}
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.RBRACE);
let ast._obj ob = rec(fields=fields.node,
@@ -1880,25 +1879,25 @@ impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
}
impure fn parse_item_const(parser p) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.CONST);
auto ty = parse_ty(p);
auto id = parse_ident(p);
expect(p, token.EQ);
auto e = parse_expr(p);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
auto item = ast.item_const(id, ty, e, p.next_def_id(), ast.ann_none);
ret @spanned(lo, hi, item);
}
impure fn parse_item_mod(parser p) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.MOD);
auto id = parse_ident(p);
expect(p, token.LBRACE);
auto m = parse_mod_items(p, token.RBRACE);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.RBRACE);
auto item = ast.item_mod(id, m, p.next_def_id());
ret @spanned(lo, hi, item);
@@ -1906,14 +1905,14 @@ impure fn parse_item_mod(parser p) -> @ast.item {
impure fn parse_item_native_type(parser p) -> @ast.native_item {
auto t = parse_type_decl(p);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
auto item = ast.native_item_ty(t._1, p.next_def_id());
ret @spanned(t._0, hi, item);
}
impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.FN);
auto t = parse_fn_header(p);
auto decl = parse_fn_decl(p, eff);
@@ -1922,7 +1921,7 @@ impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
p.bump();
link_name = some[str](parse_str_lit_or_env_ident(p));
}
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
auto item = ast.native_item_fn(t._0, link_name, decl,
t._1, p.next_def_id(),
@@ -1984,7 +1983,7 @@ fn default_native_name(session.session sess, str id) -> str {
}
impure fn parse_item_native_mod(parser p) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.NATIVE);
auto abi = ast.native_abi_cdecl;
if (p.peek() != token.MOD) {
@@ -2010,14 +2009,14 @@ impure fn parse_item_native_mod(parser p) -> @ast.item {
}
expect(p, token.LBRACE);
auto m = parse_native_mod_items(p, native_name, abi);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.RBRACE);
auto item = ast.item_native_mod(id, m, p.next_def_id());
ret @spanned(lo, hi, item);
}
-impure fn parse_type_decl(parser p) -> tup(span, ast.ident) {
- auto lo = p.get_span();
+impure fn parse_type_decl(parser p) -> tup(uint, ast.ident) {
+ auto lo = p.get_lo_pos();
expect(p, token.TYPE);
auto id = parse_ident(p);
ret tup(lo, id);
@@ -2029,14 +2028,14 @@ impure fn parse_item_type(parser p) -> @ast.item {
expect(p, token.EQ);
auto ty = parse_ty(p);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
auto item = ast.item_ty(t._1, ty, tps, p.next_def_id(), ast.ann_none);
ret @spanned(t._0, hi, item);
}
impure fn parse_item_tag(parser p) -> @ast.item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.TAG);
auto id = parse_ident(p);
auto ty_params = parse_ty_params(p);
@@ -2047,7 +2046,7 @@ impure fn parse_item_tag(parser p) -> @ast.item {
auto tok = p.peek();
alt (tok) {
case (token.IDENT(?name)) {
- auto vlo = p.get_span();
+ auto vlo = p.get_lo_pos();
p.bump();
let vec[ast.variant_arg] args = vec();
@@ -2065,7 +2064,7 @@ impure fn parse_item_tag(parser p) -> @ast.item {
case (_) { /* empty */ }
}
- auto vhi = p.get_span();
+ auto vhi = p.get_hi_pos();
expect(p, token.SEMI);
auto id = p.next_def_id();
@@ -2079,9 +2078,9 @@ impure fn parse_item_tag(parser p) -> @ast.item {
}
}
}
+ auto hi = p.get_hi_pos();
p.bump();
- auto hi = p.get_span();
auto item = ast.item_tag(id, variants, ty_params, p.next_def_id(),
ast.ann_none);
ret @spanned(lo, hi, item);
@@ -2203,12 +2202,12 @@ impure fn parse_item(parser p) -> @ast.item {
}
impure fn parse_meta_item(parser p) -> @ast.meta_item {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
auto ident = parse_ident(p);
expect(p, token.EQ);
alt (p.peek()) {
case (token.LIT_STR(?s)) {
+ auto hi = p.get_hi_pos();
p.bump();
ret @spanned(lo, hi, rec(name = ident, value = s));
}
@@ -2226,8 +2225,6 @@ impure fn parse_meta(parser p) -> vec[@ast.meta_item] {
}
impure fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
- auto lo = p.get_span();
- auto hi = lo;
alt (p.peek()) {
case (token.LPAREN) {
ret parse_meta(p);
@@ -2240,11 +2237,11 @@ impure fn parse_optional_meta(parser p) -> vec[@ast.meta_item] {
}
impure fn parse_use(parser p) -> @ast.view_item {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
expect(p, token.USE);
auto ident = parse_ident(p);
auto metadata = parse_optional_meta(p);
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
auto use_decl = ast.view_item_use(ident, metadata, p.next_def_id(),
none[int]);
@@ -2254,14 +2251,14 @@ impure fn parse_use(parser p) -> @ast.view_item {
impure fn parse_rest_import_name(parser p, ast.ident first,
option.t[ast.ident] def_ident)
-> @ast.view_item {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
let vec[ast.ident] identifiers = vec(first);
while (p.peek() != token.SEMI) {
expect(p, token.DOT);
auto i = parse_ident(p);
identifiers += vec(i);
}
+ auto hi = p.get_hi_pos();
p.bump();
auto defined_id;
alt (def_ident) {
@@ -2316,10 +2313,10 @@ impure fn parse_import(parser p) -> @ast.view_item {
}
impure fn parse_export(parser p) -> @ast.view_item {
- auto lo = p.get_span();
+ auto lo = p.get_lo_pos();
expect(p, token.EXPORT);
auto id = parse_ident(p);
- auto hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
ret @spanned(lo, hi, ast.view_item_export(id));
}
@@ -2373,12 +2370,11 @@ impure fn parse_native_view(parser p, ast.native_mod_index index)
impure fn parse_crate_from_source_file(parser p) -> @ast.crate {
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
auto m = parse_mod_items(p, token.EOF);
let vec[@ast.crate_directive] cdirs = vec();
- ret @spanned(lo, hi, rec(directives=cdirs,
- module=m));
+ ret @spanned(lo, p.get_lo_pos(), rec(directives=cdirs,
+ module=m));
}
// Logic for parsing crate files (.rc)
@@ -2389,15 +2385,14 @@ impure fn parse_crate_from_source_file(parser p) -> @ast.crate {
impure fn parse_crate_directive(parser p) -> ast.crate_directive
{
- auto lo = p.get_span();
- auto hi = lo;
+ auto lo = p.get_lo_pos();
alt (p.peek()) {
case (token.AUTH) {
p.bump();
auto n = parse_path(p, GREEDY);
expect(p, token.EQ);
auto e = parse_effect(p);
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
ret spanned(lo, hi, ast.cdir_auth(n, e));
}
@@ -2405,7 +2400,7 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
case (token.META) {
p.bump();
auto mis = parse_meta(p);
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.SEMI);
ret spanned(lo, hi, ast.cdir_meta(mis));
}
@@ -2429,7 +2424,7 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
// mod x = "foo.rs";
case (token.SEMI) {
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
p.bump();
ret spanned(lo, hi, ast.cdir_src_mod(id, file_opt));
}
@@ -2439,7 +2434,7 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
case (token.LBRACE) {
p.bump();
auto cdirs = parse_crate_directives(p, token.RBRACE);
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.RBRACE);
ret spanned(lo, hi,
ast.cdir_dir_mod(id, file_opt, cdirs));
@@ -2460,29 +2455,29 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive
expect(p, token.RPAREN);
expect(p, token.LBRACE);
auto v = parse_crate_directives(p, token.RBRACE);
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.RBRACE);
ret spanned(lo, hi, ast.cdir_let(id, x, v));
}
case (token.USE) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
}
case (token.IMPORT) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
}
case (token.EXPORT) {
auto vi = parse_view_item(p);
- ret spanned(lo, vi.span, ast.cdir_view_item(vi));
+ ret spanned(lo, vi.span.hi, ast.cdir_view_item(vi));
}
case (_) {
auto x = parse_expr(p);
- ret spanned(lo, x.span, ast.cdir_expr(x));
+ ret spanned(lo, x.span.hi, ast.cdir_expr(x));
}
}
fail;
@@ -2503,13 +2498,13 @@ impure fn parse_crate_directives(parser p, token.token term)
}
impure fn parse_crate_from_crate_file(parser p) -> @ast.crate {
- auto lo = p.get_span();
- auto hi = lo;
- auto prefix = std.fs.dirname(lo.filename);
+ auto lo = p.get_lo_pos();
+ auto prefix = std.fs.dirname(p.get_filemap().name);
auto cdirs = parse_crate_directives(p, token.EOF);
- auto m = eval.eval_crate_directives_to_mod(p, p.get_env(),
+ auto cx = @rec(p=p, sess=p.get_session(), mutable chpos=p.get_chpos());
+ auto m = eval.eval_crate_directives_to_mod(cx, p.get_env(),
cdirs, prefix);
- hi = p.get_span();
+ auto hi = p.get_hi_pos();
expect(p, token.EOF);
ret @spanned(lo, hi, rec(directives=cdirs,
module=m));
diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs
index 09dad4bc..3c03d0fc 100644
--- a/src/comp/middle/trans.rs
+++ b/src/comp/middle/trans.rs
@@ -4939,8 +4939,9 @@ fn trans_check_expr(@block_ctxt cx, @ast.expr e) -> result {
fn trans_fail(@block_ctxt cx, common.span sp, str fail_str) -> result {
auto V_fail_str = p2i(C_cstr(cx.fcx.ccx, fail_str));
- auto V_filename = p2i(C_cstr(cx.fcx.ccx, sp.filename));
- auto V_line = sp.lo.line as int;
+ auto loc = cx.fcx.ccx.sess.lookup_pos(sp.lo);
+ auto V_filename = p2i(C_cstr(cx.fcx.ccx, loc.filename));
+ auto V_line = loc.line as int;
auto args = vec(V_fail_str, V_filename, C_int(V_line));
auto sub = trans_upcall(cx, "upcall_fail", args);
diff --git a/src/comp/pretty/pprust.rs b/src/comp/pretty/pprust.rs
index d560fe5b..8c09393a 100644
--- a/src/comp/pretty/pprust.rs
+++ b/src/comp/pretty/pprust.rs
@@ -159,8 +159,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
fn get_span(&ast.ty_field f) -> common.span {
// Try to reconstruct the span for this field
auto sp = f.mt.ty.span;
- auto hi = rec(line=sp.hi.line,
- col=sp.hi.col + _str.char_len(f.ident) + 1u);
+ auto hi = sp.hi + _str.char_len(f.ident) + 1u;
ret rec(hi=hi with sp);
}
auto f = print_field;
@@ -329,14 +328,9 @@ impure fn print_item(ps s, @ast.item item) {
}
impure fn print_block(ps s, ast.block blk) {
- auto cur_line = 0u;
maybe_print_comment(s, blk.span.lo);
bopen(s);
for (@ast.stmt st in blk.node.stmts) {
- if (cur_line != 0u && st.span.lo.line > cur_line + 1u) {
- line(s.s);
- }
- cur_line = st.span.hi.line;
maybe_print_comment(s, st.span.lo);
alt (st.node) {
case (ast.stmt_decl(?decl,_)) {print_decl(s, decl);}
@@ -347,9 +341,6 @@ impure fn print_block(ps s, ast.block blk) {
}
alt (blk.node.expr) {
case (option.some[@ast.expr](?expr)) {
- if (cur_line != 0u && expr.span.lo.line > cur_line + 1u) {
- line(s.s);
- }
print_expr(s, expr);
if (!maybe_print_line_comment(s, expr.span)) {line(s.s);}
}
@@ -958,12 +949,11 @@ fn next_comment(ps s) -> option.t[lexer.cmnt] {
}
}
-impure fn maybe_print_comment(ps s, common.pos pos) {
+impure fn maybe_print_comment(ps s, uint pos) {
while (true) {
alt (next_comment(s)) {
case (option.some[lexer.cmnt](?cmnt)) {
- if (cmnt.pos.line < pos.line ||
- (cmnt.pos.line == pos.line && cmnt.pos.col < pos.col)) {
+ if (cmnt.pos < pos) {
print_comment(s, cmnt.val);
if (cmnt.space_after) {line(s.s);}
s.cur_cmnt += 1u;
@@ -977,8 +967,7 @@ impure fn maybe_print_comment(ps s, common.pos pos) {
impure fn maybe_print_line_comment(ps s, common.span span) -> bool {
alt (next_comment(s)) {
case (option.some[lexer.cmnt](?cmnt)) {
- if (span.hi.line == cmnt.pos.line &&
- span.hi.col + 4u >= cmnt.pos.col) {
+ if (span.hi + 4u >= cmnt.pos) {
wrd(s.s, " ");
print_comment(s, cmnt.val);
s.cur_cmnt += 1u;
diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc
index 14efb667..981577ab 100644
--- a/src/comp/rustc.rc
+++ b/src/comp/rustc.rc
@@ -7,6 +7,7 @@ mod front {
mod ast;
mod creader;
mod extfmt;
+ mod codemap;
mod lexer;
mod parser;
mod token;
diff --git a/src/comp/util/common.rs b/src/comp/util/common.rs
index 6dec6c00..b33a7db2 100644
--- a/src/comp/util/common.rs
+++ b/src/comp/util/common.rs
@@ -5,8 +5,7 @@ import front.ast;
type filename = str;
-type pos = rec(uint line, uint col);
-type span = rec(filename filename, pos lo, pos hi);
+type span = rec(uint lo, uint hi);
type spanned[T] = rec(T node, span span);
tag ty_mach {