about summary refs log tree commit diff
path: root/src/librustc_resolve
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-05 00:10:27 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-09-13 09:40:28 +0000
commitc86c8d41a26b2037e80c9fd028a59313a78b3a66 (patch)
treec3b7a4b63c6c276b1eff2d12eea73aa5af69e6a0 /src/librustc_resolve
parent72a636975fc5d0bb4af45af7bdd97987cc722a6a (diff)
downloadrust-c86c8d41a26b2037e80c9fd028a59313a78b3a66.tar.gz
rust-c86c8d41a26b2037e80c9fd028a59313a78b3a66.zip
Perform node id assignment and `macros_at_scope` construction during
the `InvocationCollector` and `PlaceholderExpander` folds.
Diffstat (limited to 'src/librustc_resolve')
-rw-r--r--src/librustc_resolve/assign_ids.rs92
-rw-r--r--src/librustc_resolve/lib.rs1
-rw-r--r--src/librustc_resolve/macros.rs4
3 files changed, 4 insertions, 93 deletions
diff --git a/src/librustc_resolve/assign_ids.rs b/src/librustc_resolve/assign_ids.rs
deleted file mode 100644
index a9e3c6ffe9e..00000000000
--- a/src/librustc_resolve/assign_ids.rs
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use Resolver;
-use rustc::session::Session;
-use rustc::util::nodemap::FnvHashMap;
-use syntax::ast;
-use syntax::ext::hygiene::Mark;
-use syntax::fold::{self, Folder};
-use syntax::ptr::P;
-use syntax::util::move_map::MoveMap;
-use syntax::util::small_vector::SmallVector;
-
-use std::mem;
-
-impl<'a> Resolver<'a> {
-    pub fn assign_node_ids(&mut self, krate: ast::Crate) -> ast::Crate {
-        NodeIdAssigner {
-            sess: self.session,
-            macros_at_scope: &mut self.macros_at_scope,
-        }.fold_crate(krate)
-    }
-}
-
-struct NodeIdAssigner<'a> {
-    sess: &'a Session,
-    macros_at_scope: &'a mut FnvHashMap<ast::NodeId, Vec<Mark>>,
-}
-
-impl<'a> Folder for NodeIdAssigner<'a> {
-    fn new_id(&mut self, old_id: ast::NodeId) -> ast::NodeId {
-        assert_eq!(old_id, ast::DUMMY_NODE_ID);
-        self.sess.next_node_id()
-    }
-
-    fn fold_block(&mut self, block: P<ast::Block>) -> P<ast::Block> {
-        block.map(|mut block| {
-            block.id = self.new_id(block.id);
-
-            let stmt = block.stmts.pop();
-            let mut macros = Vec::new();
-            block.stmts = block.stmts.move_flat_map(|stmt| {
-                if let ast::StmtKind::Item(ref item) = stmt.node {
-                    if let ast::ItemKind::Mac(..) = item.node {
-                        macros.push(item.ident.ctxt.data().outer_mark);
-                        return None;
-                    }
-                }
-
-                let stmt = self.fold_stmt(stmt).pop().unwrap();
-                if !macros.is_empty() {
-                    self.macros_at_scope.insert(stmt.id, mem::replace(&mut macros, Vec::new()));
-                }
-                Some(stmt)
-            });
-
-            stmt.and_then(|mut stmt| {
-                // Avoid wasting a node id on a trailing expression statement,
-                // which shares a HIR node with the expression itself.
-                if let ast::StmtKind::Expr(expr) = stmt.node {
-                    let expr = self.fold_expr(expr);
-                    stmt.id = expr.id;
-                    stmt.node = ast::StmtKind::Expr(expr);
-                    Some(stmt)
-                } else {
-                    self.fold_stmt(stmt).pop()
-                }
-            }).map(|stmt| {
-                if !macros.is_empty() {
-                    self.macros_at_scope.insert(stmt.id, mem::replace(&mut macros, Vec::new()));
-                }
-                block.stmts.push(stmt);
-            });
-
-            block
-        })
-    }
-
-    fn fold_item(&mut self, item: P<ast::Item>) -> SmallVector<P<ast::Item>> {
-        match item.node {
-            ast::ItemKind::Mac(..) => SmallVector::zero(),
-            _ => fold::noop_fold_item(item, self),
-        }
-    }
-}
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 6bf45ab8f6f..ad0507c9fb7 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -84,7 +84,6 @@ mod macros;
 mod check_unused;
 mod build_reduced_graph;
 mod resolve_imports;
-mod assign_ids;
 
 enum SuggestionType {
     Macro(String),
diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs
index 36f501a54d2..67ee4c307d3 100644
--- a/src/librustc_resolve/macros.rs
+++ b/src/librustc_resolve/macros.rs
@@ -41,6 +41,10 @@ impl<'a> base::Resolver for Resolver<'a> {
         self.macro_loader.load_crate(extern_crate, allows_macros)
     }
 
+    fn next_node_id(&mut self) -> ast::NodeId {
+        self.session.next_node_id()
+    }
+
     fn visit_expansion(&mut self, mark: Mark, expansion: &Expansion) {
         expansion.visit_with(&mut ExpansionVisitor {
             current_module: self.expansion_data[mark.as_u32() as usize].module.clone(),