Remove Node* prefix from AnnNode

This commit is contained in:
varkor 2018-08-22 22:05:19 +01:00
parent befc4b1100
commit 4b12f700db
4 changed files with 65 additions and 69 deletions

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::AnnNode::*;
use rustc_target::spec::abi::Abi;
use syntax::ast;
use syntax::source_map::{SourceMap, Spanned};
@ -33,12 +31,12 @@ use std::iter::Peekable;
use std::vec;
pub enum AnnNode<'a> {
NodeName(&'a ast::Name),
NodeBlock(&'a hir::Block),
NodeItem(&'a hir::Item),
NodeSubItem(ast::NodeId),
NodeExpr(&'a hir::Expr),
NodePat(&'a hir::Pat),
Name(&'a ast::Name),
Block(&'a hir::Block),
Item(&'a hir::Item),
SubItem(ast::NodeId),
Expr(&'a hir::Expr),
Pat(&'a hir::Pat),
}
pub enum Nested {
@ -529,7 +527,7 @@ impl<'a> State<'a> {
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(item.span.lo())?;
self.print_outer_attributes(&item.attrs)?;
self.ann.pre(self, NodeItem(item))?;
self.ann.pre(self, AnnNode::Item(item))?;
match item.node {
hir::ItemKind::ExternCrate(orig_name) => {
self.head(&visibility_qualified(&item.vis, "extern crate"))?;
@ -768,7 +766,7 @@ impl<'a> State<'a> {
self.s.word(";")?;
}
}
self.ann.post(self, NodeItem(item))
self.ann.post(self, AnnNode::Item(item))
}
pub fn print_trait_ref(&mut self, t: &hir::TraitRef) -> io::Result<()> {
@ -933,7 +931,7 @@ impl<'a> State<'a> {
}
pub fn print_trait_item(&mut self, ti: &hir::TraitItem) -> io::Result<()> {
self.ann.pre(self, NodeSubItem(ti.id))?;
self.ann.pre(self, AnnNode::SubItem(ti.id))?;
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(ti.span.lo())?;
self.print_outer_attributes(&ti.attrs)?;
@ -965,11 +963,11 @@ impl<'a> State<'a> {
default.as_ref().map(|ty| &**ty))?;
}
}
self.ann.post(self, NodeSubItem(ti.id))
self.ann.post(self, AnnNode::SubItem(ti.id))
}
pub fn print_impl_item(&mut self, ii: &hir::ImplItem) -> io::Result<()> {
self.ann.pre(self, NodeSubItem(ii.id))?;
self.ann.pre(self, AnnNode::SubItem(ii.id))?;
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(ii.span.lo())?;
self.print_outer_attributes(&ii.attrs)?;
@ -995,7 +993,7 @@ impl<'a> State<'a> {
self.print_associated_type(ii.ident, Some(bounds), None)?;
}
}
self.ann.post(self, NodeSubItem(ii.id))
self.ann.post(self, AnnNode::SubItem(ii.id))
}
pub fn print_stmt(&mut self, st: &hir::Stmt) -> io::Result<()> {
@ -1055,7 +1053,7 @@ impl<'a> State<'a> {
hir::DefaultBlock => (),
}
self.maybe_print_comment(blk.span.lo())?;
self.ann.pre(self, NodeBlock(blk))?;
self.ann.pre(self, AnnNode::Block(blk))?;
self.bopen()?;
self.print_inner_attributes(attrs)?;
@ -1072,7 +1070,7 @@ impl<'a> State<'a> {
_ => (),
}
self.bclose_maybe_open(blk.span, indented, close_box)?;
self.ann.post(self, NodeBlock(blk))
self.ann.post(self, AnnNode::Block(blk))
}
fn print_else(&mut self, els: Option<&hir::Expr>) -> io::Result<()> {
@ -1321,7 +1319,7 @@ impl<'a> State<'a> {
self.maybe_print_comment(expr.span.lo())?;
self.print_outer_attributes(&expr.attrs)?;
self.ibox(indent_unit)?;
self.ann.pre(self, NodeExpr(expr))?;
self.ann.pre(self, AnnNode::Expr(expr))?;
match expr.node {
hir::ExprKind::Box(ref expr) => {
self.word_space("box")?;
@ -1559,7 +1557,7 @@ impl<'a> State<'a> {
self.print_expr_maybe_paren(&expr, parser::PREC_JUMP)?;
}
}
self.ann.post(self, NodeExpr(expr))?;
self.ann.post(self, AnnNode::Expr(expr))?;
self.end()
}
@ -1606,7 +1604,7 @@ impl<'a> State<'a> {
} else {
self.s.word(&ident.as_str())?;
}
self.ann.post(self, NodeName(&ident.name))
self.ann.post(self, AnnNode::Name(&ident.name))
}
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
@ -1774,7 +1772,7 @@ impl<'a> State<'a> {
pub fn print_pat(&mut self, pat: &hir::Pat) -> io::Result<()> {
self.maybe_print_comment(pat.span.lo())?;
self.ann.pre(self, NodePat(pat))?;
self.ann.pre(self, AnnNode::Pat(pat))?;
// Pat isn't normalized, but the beauty of it
// is that it doesn't matter
match pat.node {
@ -1928,7 +1926,7 @@ impl<'a> State<'a> {
self.s.word("]")?;
}
}
self.ann.post(self, NodePat(pat))
self.ann.post(self, AnnNode::Pat(pat))
}
fn print_arm(&mut self, arm: &hir::Arm) -> io::Result<()> {

View File

@ -117,12 +117,12 @@ impl<'a, 'tcx, O:DataFlowOperator> pprust::PpAnn for DataFlowContext<'a, 'tcx, O
ps: &mut pprust::State,
node: pprust::AnnNode) -> io::Result<()> {
let id = match node {
pprust::NodeName(_) => return Ok(()),
pprust::NodeExpr(expr) => expr.hir_id.local_id,
pprust::NodeBlock(blk) => blk.hir_id.local_id,
pprust::NodeItem(_) |
pprust::NodeSubItem(_) => return Ok(()),
pprust::NodePat(pat) => pat.hir_id.local_id
pprust::AnnNode::Name(_) => return Ok(()),
pprust::AnnNode::Expr(expr) => expr.hir_id.local_id,
pprust::AnnNode::Block(blk) => blk.hir_id.local_id,
pprust::AnnNode::Item(_) |
pprust::AnnNode::SubItem(_) => return Ok(()),
pprust::AnnNode::Pat(pat) => pat.hir_id.local_id
};
if !self.has_bitset_for_local_id(id) {

View File

@ -355,33 +355,33 @@ impl<'hir> PrinterSupport for IdentifiedAnnotation<'hir> {
impl<'hir> pprust::PpAnn for IdentifiedAnnotation<'hir> {
fn pre(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node {
pprust::NodeExpr(_) => s.popen(),
pprust::AnnNode::Expr(_) => s.popen(),
_ => Ok(()),
}
}
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node {
pprust::NodeIdent(_) |
pprust::NodeName(_) => Ok(()),
pprust::AnnNode::Ident(_) |
pprust::AnnNode::Name(_) => Ok(()),
pprust::NodeItem(item) => {
pprust::AnnNode::Item(item) => {
s.s.space()?;
s.synth_comment(item.id.to_string())
}
pprust::NodeSubItem(id) => {
pprust::AnnNode::SubItem(id) => {
s.s.space()?;
s.synth_comment(id.to_string())
}
pprust::NodeBlock(blk) => {
pprust::AnnNode::Block(blk) => {
s.s.space()?;
s.synth_comment(format!("block {}", blk.id))
}
pprust::NodeExpr(expr) => {
pprust::AnnNode::Expr(expr) => {
s.s.space()?;
s.synth_comment(expr.id.to_string())?;
s.pclose()
}
pprust::NodePat(pat) => {
pprust::AnnNode::Pat(pat) => {
s.s.space()?;
s.synth_comment(format!("pat {}", pat.id))
}
@ -414,34 +414,34 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> {
}
fn pre(&self, s: &mut pprust_hir::State, node: pprust_hir::AnnNode) -> io::Result<()> {
match node {
pprust_hir::NodeExpr(_) => s.popen(),
pprust_hir::AnnNode::Expr(_) => s.popen(),
_ => Ok(()),
}
}
fn post(&self, s: &mut pprust_hir::State, node: pprust_hir::AnnNode) -> io::Result<()> {
match node {
pprust_hir::NodeName(_) => Ok(()),
pprust_hir::NodeItem(item) => {
pprust_hir::AnnNode::Name(_) => Ok(()),
pprust_hir::AnnNode::Item(item) => {
s.s.space()?;
s.synth_comment(format!("node_id: {} hir local_id: {}",
item.id, item.hir_id.local_id.0))
}
pprust_hir::NodeSubItem(id) => {
pprust_hir::AnnNode::SubItem(id) => {
s.s.space()?;
s.synth_comment(id.to_string())
}
pprust_hir::NodeBlock(blk) => {
pprust_hir::AnnNode::Block(blk) => {
s.s.space()?;
s.synth_comment(format!("block node_id: {} hir local_id: {}",
blk.id, blk.hir_id.local_id.0))
}
pprust_hir::NodeExpr(expr) => {
pprust_hir::AnnNode::Expr(expr) => {
s.s.space()?;
s.synth_comment(format!("node_id: {} hir local_id: {}",
expr.id, expr.hir_id.local_id.0))?;
s.pclose()
}
pprust_hir::NodePat(pat) => {
pprust_hir::AnnNode::Pat(pat) => {
s.s.space()?;
s.synth_comment(format!("pat node_id: {} hir local_id: {}",
pat.id, pat.hir_id.local_id.0))
@ -467,13 +467,13 @@ impl<'a> PrinterSupport for HygieneAnnotation<'a> {
impl<'a> pprust::PpAnn for HygieneAnnotation<'a> {
fn post(&self, s: &mut pprust::State, node: pprust::AnnNode) -> io::Result<()> {
match node {
pprust::NodeIdent(&ast::Ident { name, span }) => {
pprust::AnnNode::Ident(&ast::Ident { name, span }) => {
s.s.space()?;
// FIXME #16420: this doesn't display the connections
// between syntax contexts
s.synth_comment(format!("{}{:?}", name.as_u32(), span.ctxt()))
}
pprust::NodeName(&name) => {
pprust::AnnNode::Name(&name) => {
s.s.space()?;
s.synth_comment(name.as_u32().to_string())
}
@ -519,13 +519,13 @@ impl<'a, 'tcx> pprust_hir::PpAnn for TypedAnnotation<'a, 'tcx> {
}
fn pre(&self, s: &mut pprust_hir::State, node: pprust_hir::AnnNode) -> io::Result<()> {
match node {
pprust_hir::NodeExpr(_) => s.popen(),
pprust_hir::AnnNode::Expr(_) => s.popen(),
_ => Ok(()),
}
}
fn post(&self, s: &mut pprust_hir::State, node: pprust_hir::AnnNode) -> io::Result<()> {
match node {
pprust_hir::NodeExpr(expr) => {
pprust_hir::AnnNode::Expr(expr) => {
s.s.space()?;
s.s.word("as")?;
s.s.space()?;

View File

@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
pub use self::AnnNode::*;
use rustc_target::spec::abi::{self, Abi};
use ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use ast::{SelfKind, GenericBound, TraitBoundModifier};
@ -36,13 +34,13 @@ use std::iter::Peekable;
use std::vec;
pub enum AnnNode<'a> {
NodeIdent(&'a ast::Ident),
NodeName(&'a ast::Name),
NodeBlock(&'a ast::Block),
NodeItem(&'a ast::Item),
NodeSubItem(ast::NodeId),
NodeExpr(&'a ast::Expr),
NodePat(&'a ast::Pat),
Ident(&'a ast::Ident),
Name(&'a ast::Name),
Block(&'a ast::Block),
Item(&'a ast::Item),
SubItem(ast::NodeId),
Expr(&'a ast::Expr),
Pat(&'a ast::Pat),
}
pub trait PpAnn {
@ -1196,7 +1194,7 @@ impl<'a> State<'a> {
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(item.span.lo())?;
self.print_outer_attributes(&item.attrs)?;
self.ann.pre(self, NodeItem(item))?;
self.ann.pre(self, AnnNode::Item(item))?;
match item.node {
ast::ItemKind::ExternCrate(orig_name) => {
self.head(&visibility_qualified(&item.vis, "extern crate"))?;
@ -1439,7 +1437,7 @@ impl<'a> State<'a> {
self.end()?;
}
}
self.ann.post(self, NodeItem(item))
self.ann.post(self, AnnNode::Item(item))
}
fn print_trait_ref(&mut self, t: &ast::TraitRef) -> io::Result<()> {
@ -1596,7 +1594,7 @@ impl<'a> State<'a> {
pub fn print_trait_item(&mut self, ti: &ast::TraitItem)
-> io::Result<()> {
self.ann.pre(self, NodeSubItem(ti.id))?;
self.ann.pre(self, AnnNode::SubItem(ti.id))?;
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(ti.span.lo())?;
self.print_outer_attributes(&ti.attrs)?;
@ -1638,11 +1636,11 @@ impl<'a> State<'a> {
}
}
}
self.ann.post(self, NodeSubItem(ti.id))
self.ann.post(self, AnnNode::SubItem(ti.id))
}
pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> io::Result<()> {
self.ann.pre(self, NodeSubItem(ii.id))?;
self.ann.pre(self, AnnNode::SubItem(ii.id))?;
self.hardbreak_if_not_bol()?;
self.maybe_print_comment(ii.span.lo())?;
self.print_outer_attributes(&ii.attrs)?;
@ -1672,7 +1670,7 @@ impl<'a> State<'a> {
}
}
}
self.ann.post(self, NodeSubItem(ii.id))
self.ann.post(self, AnnNode::SubItem(ii.id))
}
pub fn print_stmt(&mut self, st: &ast::Stmt) -> io::Result<()> {
@ -1756,7 +1754,7 @@ impl<'a> State<'a> {
BlockCheckMode::Default => ()
}
self.maybe_print_comment(blk.span.lo())?;
self.ann.pre(self, NodeBlock(blk))?;
self.ann.pre(self, AnnNode::Block(blk))?;
self.bopen()?;
self.print_inner_attributes(attrs)?;
@ -1774,7 +1772,7 @@ impl<'a> State<'a> {
}
self.bclose_maybe_open(blk.span, indented, close_box)?;
self.ann.post(self, NodeBlock(blk))
self.ann.post(self, AnnNode::Block(blk))
}
fn print_else(&mut self, els: Option<&ast::Expr>) -> io::Result<()> {
@ -2065,7 +2063,7 @@ impl<'a> State<'a> {
}
self.ibox(INDENT_UNIT)?;
self.ann.pre(self, NodeExpr(expr))?;
self.ann.pre(self, AnnNode::Expr(expr))?;
match expr.node {
ast::ExprKind::Box(ref expr) => {
self.word_space("box")?;
@ -2385,7 +2383,7 @@ impl<'a> State<'a> {
self.print_block_with_attrs(blk, attrs)?
}
}
self.ann.post(self, NodeExpr(expr))?;
self.ann.post(self, AnnNode::Expr(expr))?;
self.end()
}
@ -2404,7 +2402,7 @@ impl<'a> State<'a> {
} else {
self.s.word(&ident.as_str())?;
}
self.ann.post(self, NodeIdent(&ident))
self.ann.post(self, AnnNode::Ident(&ident))
}
pub fn print_usize(&mut self, i: usize) -> io::Result<()> {
@ -2413,7 +2411,7 @@ impl<'a> State<'a> {
pub fn print_name(&mut self, name: ast::Name) -> io::Result<()> {
self.s.word(&name.as_str())?;
self.ann.post(self, NodeName(&name))
self.ann.post(self, AnnNode::Name(&name))
}
pub fn print_for_decl(&mut self, loc: &ast::Local,
@ -2537,7 +2535,7 @@ impl<'a> State<'a> {
pub fn print_pat(&mut self, pat: &ast::Pat) -> io::Result<()> {
self.maybe_print_comment(pat.span.lo())?;
self.ann.pre(self, NodePat(pat))?;
self.ann.pre(self, AnnNode::Pat(pat))?;
/* Pat isn't normalized, but the beauty of it
is that it doesn't matter */
match pat.node {
@ -2675,7 +2673,7 @@ impl<'a> State<'a> {
}
PatKind::Mac(ref m) => self.print_mac(m)?,
}
self.ann.post(self, NodePat(pat))
self.ann.post(self, AnnNode::Pat(pat))
}
fn print_pats(&mut self, pats: &[P<ast::Pat>]) -> io::Result<()> {