]> git.lizzy.rs Git - rust.git/commitdiff
rustc: track fields in the HIR map.
authorEduard Burtescu <edy.burt@gmail.com>
Wed, 9 Nov 2016 18:57:48 +0000 (20:57 +0200)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 28 Nov 2016 03:12:41 +0000 (05:12 +0200)
src/librustc/hir/map/collector.rs
src/librustc/hir/map/mod.rs
src/librustc/middle/reachable.rs

index 67e9b24f42d2200d2c54107990bfbb23b8aaa239..26fd2b736a42c29bdcba81874fb4835b0c8c3b65 100644 (file)
@@ -242,4 +242,11 @@ fn visit_vis(&mut self, visibility: &'ast Visibility) {
     fn visit_macro_def(&mut self, macro_def: &'ast MacroDef) {
         self.insert_entry(macro_def.id, NotPresent);
     }
+
+    fn visit_struct_field(&mut self, field: &'ast StructField) {
+        self.insert(field.id, NodeField(field));
+        self.with_parent(field.id, |this| {
+            intravisit::walk_struct_field(this, field);
+        });
+    }
 }
index c4ed98ce6e07004ff245653bf01713e58a042cb7..b9763e6ea0dcb430a77eede0cd9c33acd73ff878 100644 (file)
@@ -46,6 +46,7 @@ pub enum Node<'ast> {
     NodeTraitItem(&'ast TraitItem),
     NodeImplItem(&'ast ImplItem),
     NodeVariant(&'ast Variant),
+    NodeField(&'ast StructField),
     NodeExpr(&'ast Expr),
     NodeStmt(&'ast Stmt),
     NodeTy(&'ast Ty),
@@ -75,6 +76,7 @@ pub enum MapEntry<'ast> {
     EntryTraitItem(NodeId, &'ast TraitItem),
     EntryImplItem(NodeId, &'ast ImplItem),
     EntryVariant(NodeId, &'ast Variant),
+    EntryField(NodeId, &'ast StructField),
     EntryExpr(NodeId, &'ast Expr),
     EntryStmt(NodeId, &'ast Stmt),
     EntryTy(NodeId, &'ast Ty),
@@ -106,6 +108,7 @@ fn from_node(p: NodeId, node: Node<'ast>) -> MapEntry<'ast> {
             NodeTraitItem(n) => EntryTraitItem(p, n),
             NodeImplItem(n) => EntryImplItem(p, n),
             NodeVariant(n) => EntryVariant(p, n),
+            NodeField(n) => EntryField(p, n),
             NodeExpr(n) => EntryExpr(p, n),
             NodeStmt(n) => EntryStmt(p, n),
             NodeTy(n) => EntryTy(p, n),
@@ -127,6 +130,7 @@ fn parent_node(self) -> Option<NodeId> {
             EntryTraitItem(id, _) => id,
             EntryImplItem(id, _) => id,
             EntryVariant(id, _) => id,
+            EntryField(id, _) => id,
             EntryExpr(id, _) => id,
             EntryStmt(id, _) => id,
             EntryTy(id, _) => id,
@@ -152,6 +156,7 @@ fn to_node(self) -> Option<Node<'ast>> {
             EntryTraitItem(_, n) => NodeTraitItem(n),
             EntryImplItem(_, n) => NodeImplItem(n),
             EntryVariant(_, n) => NodeVariant(n),
+            EntryField(_, n) => NodeField(n),
             EntryExpr(_, n) => NodeExpr(n),
             EntryStmt(_, n) => NodeStmt(n),
             EntryTy(_, n) => NodeTy(n),
@@ -265,6 +270,7 @@ fn dep_node(&self, id0: NodeId) -> DepNode<DefId> {
                     EntryForeignItem(p, _) |
                     EntryTraitItem(p, _) |
                     EntryVariant(p, _) |
+                    EntryField(p, _) |
                     EntryExpr(p, _) |
                     EntryStmt(p, _) |
                     EntryTy(p, _) |
@@ -308,6 +314,7 @@ fn dep_node(&self, id0: NodeId) -> DepNode<DefId> {
                     EntryTraitItem(p, _) |
                     EntryImplItem(p, _) |
                     EntryVariant(p, _) |
+                    EntryField(p, _) |
                     EntryExpr(p, _) |
                     EntryStmt(p, _) |
                     EntryTy(p, _) |
@@ -656,6 +663,7 @@ pub fn name(&self, id: NodeId) -> Name {
             NodeImplItem(ii) => ii.name,
             NodeTraitItem(ti) => ti.name,
             NodeVariant(v) => v.node.name,
+            NodeField(f) => f.name,
             NodeLifetime(lt) => lt.name,
             NodeTyParam(tp) => tp.name,
             NodeLocal(&Pat { node: PatKind::Binding(_,_,l,_), .. }) => l.node,
@@ -674,6 +682,7 @@ pub fn attrs(&self, id: NodeId) -> &'ast [ast::Attribute] {
             Some(NodeTraitItem(ref ti)) => Some(&ti.attrs[..]),
             Some(NodeImplItem(ref ii)) => Some(&ii.attrs[..]),
             Some(NodeVariant(ref v)) => Some(&v.node.attrs[..]),
+            Some(NodeField(ref f)) => Some(&f.attrs[..]),
             Some(NodeExpr(ref e)) => Some(&*e.attrs),
             Some(NodeStmt(ref s)) => Some(s.node.attrs()),
             // unit/tuple structs take the attributes straight from
@@ -710,6 +719,7 @@ pub fn opt_span(&self, id: NodeId) -> Option<Span> {
             Some(NodeTraitItem(trait_method)) => trait_method.span,
             Some(NodeImplItem(ref impl_item)) => impl_item.span,
             Some(NodeVariant(variant)) => variant.span,
+            Some(NodeField(field)) => field.span,
             Some(NodeExpr(expr)) => expr.span,
             Some(NodeStmt(stmt)) => stmt.span,
             Some(NodeTy(ty)) => ty.span,
@@ -831,6 +841,7 @@ fn next(&mut self) -> Option<NodeId> {
                 Some(EntryTraitItem(_, n))  => n.name(),
                 Some(EntryImplItem(_, n))   => n.name(),
                 Some(EntryVariant(_, n))    => n.name(),
+                Some(EntryField(_, n))      => n.name(),
                 _ => continue,
             };
             if self.matches_names(self.map.get_parent(idx), name) {
@@ -849,6 +860,7 @@ impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() }
 impl Named for Item { fn name(&self) -> Name { self.name } }
 impl Named for ForeignItem { fn name(&self) -> Name { self.name } }
 impl Named for Variant_ { fn name(&self) -> Name { self.name } }
+impl Named for StructField { fn name(&self) -> Name { self.name } }
 impl Named for TraitItem { fn name(&self) -> Name { self.name } }
 impl Named for ImplItem { fn name(&self) -> Name { self.name } }
 
@@ -940,6 +952,7 @@ fn print_node(&mut self, node: &Node) -> io::Result<()> {
             NodeLifetime(a)    => self.print_lifetime(&a),
             NodeVisibility(a)  => self.print_visibility(&a),
             NodeTyParam(_)     => bug!("cannot print TyParam"),
+            NodeField(_)       => bug!("cannot print StructField"),
             // these cases do not carry enough information in the
             // ast_map to reconstruct their full structure for pretty
             // printing.
@@ -1019,6 +1032,11 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
                     variant.node.name,
                     path_str(), id_str)
         }
+        Some(NodeField(ref field)) => {
+            format!("field {} in {}{}",
+                    field.name,
+                    path_str(), id_str)
+        }
         Some(NodeExpr(ref expr)) => {
             format!("expr {}{}", pprust::expr_to_string(&expr), id_str)
         }
index 767886a23157729a7d3e356284b5ad0aaeb5ba0a..b17d41e0fa544da01b581b5c1748fa73bc401067 100644 (file)
@@ -299,6 +299,7 @@ fn propagate_node(&mut self, node: &ast_map::Node,
             ast_map::NodeForeignItem(_) |
             ast_map::NodeVariant(_) |
             ast_map::NodeStructCtor(_) |
+            ast_map::NodeField(_) |
             ast_map::NodeTy(_) => {}
             _ => {
                 bug!("found unexpected thingy in worklist: {}",