aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
authorBrian Anderson <[email protected]>2011-03-13 19:40:25 -0400
committerBrian Anderson <[email protected]>2011-03-13 19:40:25 -0400
commitbbb6836da003be71744b6e6ea7af1fd4674f8291 (patch)
treefc7780f767666cced8406818806216bee3863c91 /src/comp/front
parentRemove extra blocks from the translation of expr_block (diff)
parentAdd llvmext/include to the list of include directories to hopefully put out t... (diff)
downloadrust-bbb6836da003be71744b6e6ea7af1fd4674f8291.tar.xz
rust-bbb6836da003be71744b6e6ea7af1fd4674f8291.zip
Merge branch 'master' into recursive-elseif
Conflicts: src/comp/middle/typeck.rs
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs53
-rw-r--r--src/comp/front/eval.rs9
-rw-r--r--src/comp/front/parser.rs56
-rw-r--r--src/comp/front/pretty.rs87
4 files changed, 71 insertions, 134 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index f9d609d1..59a928be 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 {
@@ -29,9 +29,11 @@ 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);
+ def_upvar(def_id);
def_variant(def_id /* tag */, def_id /* variant */);
def_ty(def_id);
def_ty_arg(def_id);
@@ -42,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);
@@ -64,9 +67,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 */);
@@ -427,6 +436,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/eval.rs b/src/comp/front/eval.rs
index 881797c9..21a764df 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;
@@ -386,9 +386,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 bb7b8558..653e45a1 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) {
@@ -1465,39 +1470,9 @@ 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);
- }
- case (ast.decl_item(?it)) {
- alt (it.node) {
- case (ast.item_fn(?i, _, _, _, _)) {
- index.insert(i, u);
- }
- case (ast.item_mod(?i, _, _)) {
- index.insert(i, u);
- }
- case (ast.item_ty(?i, _, _, _, _)) {
- index.insert(i, u);
- }
- case (ast.item_tag(?i, _, _, _)) {
- index.insert(i, u);
- }
- case (ast.item_obj(?i, _, _, _, _)) {
- index.insert(i, u);
- }
- }
- }
- }
- }
- case (_) { /* fall through */ }
- }
- u += 1u;
+ ast.index_stmt(index, s);
}
ret rec(stmts=stmts, expr=expr, index=index);
}
@@ -2261,7 +2236,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)
@@ -2276,8 +2253,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);
@@ -2288,8 +2263,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();
@@ -2398,7 +2371,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));
}
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 "<unknown ast node>";
-}
-
-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:
-//