From fa2525a7bdba20fd038e10e3275ce6ba0b1af5b5 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 7 Mar 2011 21:34:18 -0500 Subject: Remove old pretty-printer from rustc --- src/comp/front/pretty.rs | 87 ------------------------------------------------ 1 file changed, 87 deletions(-) delete mode 100644 src/comp/front/pretty.rs (limited to 'src/comp/front') diff --git a/src/comp/front/pretty.rs b/src/comp/front/pretty.rs deleted file mode 100644 index 2fd58126..00000000 --- a/src/comp/front/pretty.rs +++ /dev/null @@ -1,87 +0,0 @@ -import std._int; -import std._str; -import std._uint; -import std._vec; - -export print_expr; - -// FIXME this is superseded by ../pretty/pprust.rs. can it be dropped? - -fn unknown() -> str { - ret ""; -} - -fn print_expr(@ast.expr expr) -> str { - alt (expr.node) { - case (ast.expr_lit(?lit, _)) { - ret print_lit(lit); - } - case (ast.expr_binary(?op, ?lhs, ?rhs, _)) { - ret print_expr_binary(op, lhs, rhs); - } - case (ast.expr_call(?path, ?args, _)) { - ret print_expr_call(path, args); - } - case (ast.expr_path(?path, _, _)) { - ret print_path(path); - } - case (_) { - ret unknown(); - } - } -} - -fn print_lit(@ast.lit lit) -> str { - alt (lit.node) { - case (ast.lit_str(?s)) { - ret "\"" + s + "\""; - } - case (ast.lit_int(?i)) { - ret _int.to_str(i, 10u); - } - case (ast.lit_uint(?u)) { - ret _uint.to_str(u, 10u); - } - case (_) { - ret unknown(); - } - } -} - -fn print_expr_binary(ast.binop op, @ast.expr lhs, @ast.expr rhs) -> str { - alt (op) { - case (ast.add) { - auto l = print_expr(lhs); - auto r = print_expr(rhs); - ret l + " + " + r; - } - } -} - -fn print_expr_call(@ast.expr path_expr, vec[@ast.expr] args) -> str { - auto s = print_expr(path_expr); - - s += "("; - fn print_expr_ref(&@ast.expr e) -> str { ret print_expr(e); } - auto mapfn = print_expr_ref; - auto argstrs = _vec.map[@ast.expr, str](mapfn, args); - s += _str.connect(argstrs, ", "); - s += ")"; - - ret s; -} - -fn print_path(ast.path path) -> str { - ret _str.connect(path.node.idents, "."); -} - -// -// 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 ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'"; -// End: -// -- cgit v1.2.3 From 4654faa67c831728c677027f2beb48fe3592b511 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 8 Mar 2011 12:42:56 -0800 Subject: rustc: Add a slot for explicit type parameter instantations to the typechecker's AST annotation --- src/comp/front/ast.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 52ae66c8..56914800 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -21,7 +21,7 @@ type ty_param = rec(ident ident, def_id id); // Annotations added during successive passes. tag ann { ann_none; - ann_type(@middle.ty.t); + ann_type(@middle.ty.t, option.t[vec[@middle.ty.t]] /* ty param substs */); } tag def { -- cgit v1.2.3 From 0d3cec71a3282a090903a919d418c638a3b1ebe6 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Thu, 10 Mar 2011 10:17:10 -0800 Subject: Fix eval typo (caught by Martin Hock). --- src/comp/front/eval.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/comp/front') diff --git a/src/comp/front/eval.rs b/src/comp/front/eval.rs index cae72b1e..ac4b704b 100644 --- a/src/comp/front/eval.rs +++ b/src/comp/front/eval.rs @@ -42,7 +42,7 @@ fn val_is_bool(val v) -> bool { fn val_is_int(val v) -> bool { alt (v) { - case (val_bool(_)) { ret true; } + case (val_int(_)) { ret true; } case (_) { } } ret false; -- cgit v1.2.3 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/eval.rs | 7 +++++-- src/comp/front/parser.rs | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/eval.rs b/src/comp/front/eval.rs index ac4b704b..efa9aa0d 100644 --- a/src/comp/front/eval.rs +++ b/src/comp/front/eval.rs @@ -393,9 +393,12 @@ impure fn eval_crate_directive(parser p, auto full_path = prefix + std.os.path_sep() + file_path; - auto p0 = new_parser(p.get_session(), e, 0, full_path); + auto start_id = p.next_def_id(); + auto p0 = new_parser(p.get_session(), e, start_id, full_path); auto m0 = parse_mod_items(p0, token.EOF); - auto im = ast.item_mod(id, m0, p.next_def_id()); + auto next_id = p0.next_def_id(); + p.set_def(next_id._1); + auto im = ast.item_mod(id, m0, next_id); auto i = @spanned(cdir.span, cdir.span, im); ast.index_item(index, i); append[@ast.item](items, i); 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 7454b534112e8cb7b0192d28c8b8685db31ed283 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 10 Mar 2011 16:49:00 -0800 Subject: rustc: Build up a list of upvars inside foreach bodies --- src/comp/front/ast.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 56914800..584586f6 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -32,6 +32,7 @@ tag def { def_const(def_id); def_arg(def_id); def_local(def_id); + def_upvar(def_id); def_variant(def_id /* tag */, def_id /* variant */); def_ty(def_id); def_ty_arg(def_id); -- cgit v1.2.3 From 0117cf2fc27354e55bcb1c1f0ede97d9ac92f02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Thu, 10 Mar 2011 21:33:53 -0500 Subject: Handle resolving to native modules. --- src/comp/front/ast.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 584586f6..05daf5ee 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -29,6 +29,7 @@ tag def { def_obj(def_id); def_obj_field(def_id); def_mod(def_id); + def_native_mod(def_id); def_const(def_id); def_arg(def_id); def_local(def_id); -- 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/ast.rs | 8 +++++++- src/comp/front/parser.rs | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 05daf5ee..c17eddee 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -66,9 +66,15 @@ type meta_item = spanned[meta_item_]; type meta_item_ = rec(ident name, str value); type block = spanned[block_]; +type block_index = hashmap[ident, block_index_entry]; +tag block_index_entry { + bie_item(@item); + bie_local(@local); + bie_tag_variant(@item /* tag item */, uint /* variant index */); +} type block_ = rec(vec[@stmt] stmts, option.t[@expr] expr, - hashmap[ident,uint] index); + hashmap[ident,block_index_entry] index); type variant_def = tup(def_id /* tag */, def_id /* variant */); 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/ast.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/comp/front/parser.rs | 36 +----------------------------------- 2 files changed, 39 insertions(+), 35 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index c17eddee..b39f3d4c 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -435,6 +435,44 @@ fn index_native_view_item(native_mod_index index, @view_item it) { } } +fn index_stmt(block_index index, @stmt s) { + 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 */ } + } +} + fn is_call_expr(@expr e) -> bool { alt (e.node) { case (expr_call(_, _, _)) { 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/ast.rs | 3 ++- src/comp/front/parser.rs | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/comp/front') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index b39f3d4c..5999388e 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -44,7 +44,8 @@ tag def { } type crate = spanned[crate_]; -type crate_ = rec(_mod module); +type crate_ = rec(vec[@crate_directive] directives, + _mod module); tag crate_directive_ { cdir_expr(@expr); 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