From e64085b0a2b512822ed7f020659fc6bdb8ed8ef5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 8 Mar 2011 18:11:00 -0800 Subject: rustc: Fold over the paths in tag patterns so that we can resolve type variables in them --- src/comp/middle/fold.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 8a1dc70f..ccf3457b 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -452,11 +452,14 @@ fn fold_pat[ENV](&ENV env, ast_fold[ENV] fld, @ast.pat p) -> @ast.pat { ret fld.fold_pat_bind(env_, p.span, id, did, t); } case (ast.pat_tag(?path, ?pats, ?d, ?t)) { + auto ppath = fold_path(env, fld, path); + let vec[@ast.pat] ppats = vec(); for (@ast.pat pat in pats) { ppats += vec(fold_pat(env_, fld, pat)); } - ret fld.fold_pat_tag(env_, p.span, path, ppats, d, t); + + ret fld.fold_pat_tag(env_, p.span, ppath, ppats, d, t); } } } -- cgit v1.2.3 From bafcbb101c104b136ce781380ce6944c49b77691 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Wed, 9 Mar 2011 17:34:22 -0800 Subject: Fold exports. --- src/comp/middle/fold.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index ccf3457b..d08b979a 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -254,6 +254,8 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ident i, vec[ident] idents, def_id id, option.t[def]) -> @view_item) fold_view_item_import, + (fn(&ENV e, &span sp, ident i) -> @view_item) fold_view_item_export, + // Additional nodes. (fn(&ENV e, &span sp, &ast.block_) -> block) fold_block, @@ -852,6 +854,10 @@ fn fold_view_item[ENV](&ENV env, ast_fold[ENV] fld, @view_item vi) ret fld.fold_view_item_import(env_, vi.span, def_ident, idents, def_id, target_def); } + + case (ast.view_item_export(?def_ident)) { + ret fld.fold_view_item_export(env_, vi.span, def_ident); + } } fail; @@ -1339,6 +1345,11 @@ fn identity_fold_view_item_import[ENV](&ENV e, &span sp, ident i, ret @respan(sp, ast.view_item_import(i, is, id, target_def)); } +fn identity_fold_view_item_export[ENV](&ENV e, &span sp, ident i) + -> @view_item { + ret @respan(sp, ast.view_item_export(i)); +} + // Additional identities. fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block { @@ -1516,6 +1527,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { bind identity_fold_view_item_use[ENV](_,_,_,_,_), fold_view_item_import = bind identity_fold_view_item_import[ENV](_,_,_,_,_,_), + fold_view_item_export = + bind identity_fold_view_item_export[ENV](_,_,_), fold_block = bind identity_fold_block[ENV](_,_,_), fold_fn = bind identity_fold_fn[ENV](_,_,_,_), -- 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/middle/fold.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index d08b979a..37ae2c23 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -734,6 +734,7 @@ fn fold_stmt[ENV](&ENV env, ast_fold[ENV] fld, &@stmt s) -> @stmt { fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { + auto index = new_str_hash[ast.block_index_entry](); let ENV env_ = fld.update_env_for_block(env, blk); if (!fld.keep_going(env_)) { @@ -742,7 +743,9 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { let vec[@ast.stmt] stmts = vec(); for (@ast.stmt s in blk.node.stmts) { - append[@ast.stmt](stmts, fold_stmt[ENV](env_, fld, s)); + auto new_stmt = fold_stmt[ENV](env_, fld, s); + append[@ast.stmt](stmts, new_stmt); + ast.index_stmt(index, new_stmt); } auto expr = none[@ast.expr]; @@ -755,8 +758,7 @@ fn fold_block[ENV](&ENV env, ast_fold[ENV] fld, &block blk) -> block { } } - // FIXME: should we reindex? - ret respan(blk.span, rec(stmts=stmts, expr=expr, index=blk.node.index)); + ret respan(blk.span, rec(stmts=stmts, expr=expr, index=index)); } fn fold_arm[ENV](&ENV env, ast_fold[ENV] fld, &arm a) -> arm { -- 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/middle/fold.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/comp/middle/fold.rs') diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 37ae2c23..17a2a2ca 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -273,6 +273,7 @@ type ast_fold[ENV] = (fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod, (fn(&ENV e, &span sp, + vec[@ast.crate_directive] cdirs, &ast._mod m) -> @ast.crate) fold_crate, (fn(&ENV e, @@ -991,9 +992,12 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, } fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate { + // FIXME: possibly fold the directives so you process any expressions + // within them? Not clear. After front/eval.rs, nothing else should look + // at crate directives. let ENV env_ = fld.update_env_for_crate(env, c); let ast._mod m = fold_mod[ENV](env_, fld, c.node.module); - ret fld.fold_crate(env_, c.span, m); + ret fld.fold_crate(env_, c.span, c.node.directives, m); } //// Identity folds. @@ -1381,8 +1385,10 @@ fn identity_fold_native_mod[ENV](&ENV e, ret m; } -fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate { - ret @respan(sp, rec(module=m)); +fn identity_fold_crate[ENV](&ENV e, &span sp, + vec[@ast.crate_directive] cdirs, + &ast._mod m) -> @ast.crate { + ret @respan(sp, rec(directives=cdirs, module=m)); } fn identity_fold_obj[ENV](&ENV e, @@ -1537,7 +1543,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), fold_native_mod = bind identity_fold_native_mod[ENV](_,_), - fold_crate = bind identity_fold_crate[ENV](_,_,_), + fold_crate = bind identity_fold_crate[ENV](_,_,_,_), fold_obj = bind identity_fold_obj[ENV](_,_,_,_), update_env_for_crate = bind identity_update_env_for_crate[ENV](_,_), -- cgit v1.2.3