From 47bb1185f2ae17e6a8b24da533c4d2f548e1e808 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Mon, 21 May 2012 23:17:28 -0700 Subject: [PATCH] rustc: Move walk_pat to ast_util This will allow ast_map to move to the syntax crate --- src/librustsyntax/ast_util.rs | 12 ++++++++++++ src/rustc/middle/ast_map.rs | 2 +- src/rustc/middle/pat_util.rs | 16 +--------------- src/rustc/middle/resolve.rs | 2 +- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/librustsyntax/ast_util.rs b/src/librustsyntax/ast_util.rs index 2f0e4447352..211414ac7d4 100644 --- a/src/librustsyntax/ast_util.rs +++ b/src/librustsyntax/ast_util.rs @@ -530,6 +530,18 @@ pure fn is_item_impl(item: @ast::item) -> bool { } } +fn walk_pat(pat: @pat, it: fn(@pat)) { + it(pat); + alt pat.node { + pat_ident(pth, some(p)) { walk_pat(p, it); } + pat_rec(fields, _) { for fields.each {|f| walk_pat(f.pat, it); } } + pat_enum(_, some(s)) | pat_tup(s) { for s.each {|p| walk_pat(p, it); } } + pat_box(s) | pat_uniq(s) { walk_pat(s, it); } + pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _) + | pat_enum(_, _) {} + } +} + // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/rustc/middle/ast_map.rs b/src/rustc/middle/ast_map.rs index 20d75e493e5..8ba0ed909c5 100644 --- a/src/rustc/middle/ast_map.rs +++ b/src/rustc/middle/ast_map.rs @@ -154,7 +154,7 @@ fn map_block(b: blk, cx: ctx, v: vt) { } fn number_pat(cx: ctx, pat: @pat) { - pat_util::walk_pat(pat) {|p| + ast_util::walk_pat(pat) {|p| alt p.node { pat_ident(_, _) { cx.map.insert(p.id, node_local(cx.local_id)); diff --git a/src/rustc/middle/pat_util.rs b/src/rustc/middle/pat_util.rs index 72bb2257c54..29cacf37092 100644 --- a/src/rustc/middle/pat_util.rs +++ b/src/rustc/middle/pat_util.rs @@ -1,13 +1,11 @@ import syntax::ast::*; import syntax::ast_util; -import syntax::ast_util::path_to_ident; -import syntax::ast_util::respan; +import syntax::ast_util::{path_to_ident, respan, walk_pat}; import syntax::fold; import syntax::fold::*; import syntax::codemap::span; import std::map::hashmap; -export walk_pat; export pat_binding_ids, pat_bindings, pat_id_map; export pat_is_variant; @@ -51,18 +49,6 @@ fn pat_bindings(dm: resolve::def_map, pat: @pat, } } -fn walk_pat(pat: @pat, it: fn(@pat)) { - it(pat); - alt pat.node { - pat_ident(pth, some(p)) { walk_pat(p, it); } - pat_rec(fields, _) { for fields.each {|f| walk_pat(f.pat, it); } } - pat_enum(_, some(s)) | pat_tup(s) { for s.each {|p| walk_pat(p, it); } } - pat_box(s) | pat_uniq(s) { walk_pat(s, it); } - pat_wild | pat_lit(_) | pat_range(_, _) | pat_ident(_, _) - | pat_enum(_, _) {} - } -} - fn pat_binding_ids(dm: resolve::def_map, pat: @pat) -> [node_id] { let mut found = []; pat_bindings(dm, pat) {|b_id, _sp, _pt| found += [b_id]; }; diff --git a/src/rustc/middle/resolve.rs b/src/rustc/middle/resolve.rs index 6df257d34d6..868bf9d06c4 100644 --- a/src/rustc/middle/resolve.rs +++ b/src/rustc/middle/resolve.rs @@ -688,7 +688,7 @@ fn visit_local_with_scope(e: @env, loc: @local, &&sc: scopes, v:vt) { // scope. We disallow this, in order to make alt patterns consisting of a // single identifier unambiguous (does the pattern "foo" refer to enum // foo, or is it binding a new name foo?) - pat_util::walk_pat(loc.node.pat) { |p| + ast_util::walk_pat(loc.node.pat) { |p| alt p.node { pat_ident(path, _) { alt lookup_in_scope(*e, sc, loc.span, path_to_ident(path),