From 4ca0259b20bfc2f33f23e8b82864908fbb3b8133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Thu, 10 Mar 2011 17:34:58 -0500 Subject: Update the current id when we create sub parsers. --- src/comp/front/parser.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 71e592ff..2836b120 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -35,12 +35,13 @@ state type parser = fn get_session() -> session.session; fn get_span() -> common.span; fn next_def_id() -> ast.def_id; + fn set_def(ast.def_num); fn get_prec_table() -> vec[op_spec]; }; impure fn new_parser(session.session sess, eval.env env, - ast.crate_num crate, + ast.def_id initial_def, str path) -> parser { state obj stdio_parser(session.session sess, eval.env env, @@ -94,6 +95,10 @@ impure fn new_parser(session.session sess, ret tup(crate, def); } + fn set_def(ast.def_num d) { + def = d; + } + fn get_file_type() -> file_type { ret ftype; } @@ -114,8 +119,8 @@ impure fn new_parser(session.session sess, auto rdr = lexer.new_reader(srdr, path); auto npos = rdr.get_curr_pos(); ret stdio_parser(sess, env, ftype, lexer.next_token(rdr), - npos, npos, 0, UNRESTRICTED, crate, rdr, - prec_table()); + npos, npos, initial_def._1, UNRESTRICTED, initial_def._0, + rdr, prec_table()); } impure fn unexpected(parser p, token.token t) { -- cgit v1.2.3 From 28d51e3fd2cccdb9fefab71b476fd868a2363ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 11 Mar 2011 17:10:11 -0500 Subject: Add support for indexing tags in blocks. --- src/comp/front/parser.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 2836b120..58cbac00 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1478,31 +1478,36 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt { } fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { - auto index = new_str_hash[uint](); - auto u = 0u; + auto index = new_str_hash[ast.block_index_entry](); for (@ast.stmt s in stmts) { alt (s.node) { case (ast.stmt_decl(?d)) { alt (d.node) { case (ast.decl_local(?loc)) { - index.insert(loc.ident, u); + index.insert(loc.ident, ast.bie_local(loc)); } case (ast.decl_item(?it)) { alt (it.node) { case (ast.item_fn(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } case (ast.item_mod(?i, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } case (ast.item_ty(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } - case (ast.item_tag(?i, _, _, _)) { - index.insert(i, u); + case (ast.item_tag(?i, ?variants, _, _)) { + index.insert(i, ast.bie_item(it)); + let uint vid = 0u; + for (ast.variant v in variants) { + auto t = ast.bie_tag_variant(it, vid); + index.insert(v.name, t); + vid += 1u; + } } case (ast.item_obj(?i, _, _, _, _)) { - index.insert(i, u); + index.insert(i, ast.bie_item(it)); } } } @@ -1510,7 +1515,6 @@ fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { } case (_) { /* fall through */ } } - u += 1u; } ret rec(stmts=stmts, expr=expr, index=index); } -- cgit v1.2.3 From 74d891517be8f6299b0626c26400dd54dd1aac6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 11 Mar 2011 17:29:53 -0500 Subject: reindex the block index. --- src/comp/front/parser.rs | 36 +----------------------------------- 1 file changed, 1 insertion(+), 35 deletions(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 58cbac00..cdd65539 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1480,41 +1480,7 @@ impure fn parse_source_stmt(parser p) -> @ast.stmt { fn index_block(vec[@ast.stmt] stmts, option.t[@ast.expr] expr) -> ast.block_ { auto index = new_str_hash[ast.block_index_entry](); for (@ast.stmt s in stmts) { - alt (s.node) { - case (ast.stmt_decl(?d)) { - alt (d.node) { - case (ast.decl_local(?loc)) { - index.insert(loc.ident, ast.bie_local(loc)); - } - case (ast.decl_item(?it)) { - alt (it.node) { - case (ast.item_fn(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_mod(?i, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_ty(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - case (ast.item_tag(?i, ?variants, _, _)) { - index.insert(i, ast.bie_item(it)); - let uint vid = 0u; - for (ast.variant v in variants) { - auto t = ast.bie_tag_variant(it, vid); - index.insert(v.name, t); - vid += 1u; - } - } - case (ast.item_obj(?i, _, _, _, _)) { - index.insert(i, ast.bie_item(it)); - } - } - } - } - } - case (_) { /* fall through */ } - } + ast.index_stmt(index, s); } ret rec(stmts=stmts, expr=expr, index=index); } -- cgit v1.2.3 From ec7e84ae0d9d04c52a8456c16dd846efe6390340 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 11 Mar 2011 15:49:48 -0800 Subject: Preserve crate directives in the parsed crate. --- src/comp/front/parser.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/comp/front/parser.rs') diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index cdd65539..45cec0c0 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -2244,7 +2244,9 @@ impure fn parse_crate_from_source_file(parser p) -> @ast.crate { auto lo = p.get_span(); auto hi = lo; auto m = parse_mod_items(p, token.EOF); - ret @spanned(lo, hi, rec(module=m)); + let vec[@ast.crate_directive] cdirs = vec(); + ret @spanned(lo, hi, rec(directives=cdirs, + module=m)); } // Logic for parsing crate files (.rc) @@ -2259,8 +2261,6 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive auto hi = lo; alt (p.peek()) { case (token.AUTH) { - // FIXME: currently dropping auth clauses on the floor, - // as there is no effect-checking pass. p.bump(); auto n = parse_path(p, GREEDY); expect(p, token.EQ); @@ -2271,8 +2271,6 @@ impure fn parse_crate_directive(parser p) -> ast.crate_directive } case (token.META) { - // FIXME: currently dropping meta clauses on the floor, - // as there is no crate metadata system p.bump(); auto mis = parse_meta(p); hi = p.get_span(); @@ -2381,7 +2379,8 @@ impure fn parse_crate_from_crate_file(parser p) -> @ast.crate { cdirs, prefix); hi = p.get_span(); expect(p, token.EOF); - ret @spanned(lo, hi, rec(module=m)); + ret @spanned(lo, hi, rec(directives=cdirs, + module=m)); } -- cgit v1.2.3