2015-11-11 05:26:14 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
|
|
|
// Simply gives a rought count of the number of nodes in an AST.
|
|
|
|
|
|
|
|
use visit::*;
|
|
|
|
use ast::*;
|
2016-06-21 22:08:13 +00:00
|
|
|
use syntax_pos::Span;
|
2015-11-11 05:26:14 +00:00
|
|
|
|
|
|
|
pub struct NodeCounter {
|
|
|
|
pub count: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NodeCounter {
|
|
|
|
pub fn new() -> NodeCounter {
|
|
|
|
NodeCounter {
|
|
|
|
count: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-06 10:26:52 +00:00
|
|
|
impl<'ast> Visitor<'ast> for NodeCounter {
|
2015-11-11 05:26:14 +00:00
|
|
|
fn visit_ident(&mut self, span: Span, ident: Ident) {
|
|
|
|
self.count += 1;
|
|
|
|
walk_ident(self, span, ident);
|
|
|
|
}
|
2017-05-11 19:15:29 +00:00
|
|
|
fn visit_mod(&mut self, m: &Mod, _s: Span, _a: &[Attribute], _n: NodeId) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_mod(self, m)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_foreign_item(&mut self, i: &ForeignItem) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_foreign_item(self, i)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_item(&mut self, i: &Item) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_item(self, i)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_local(&mut self, l: &Local) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_local(self, l)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_block(&mut self, b: &Block) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_block(self, b)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_stmt(&mut self, s: &Stmt) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_stmt(self, s)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_arm(&mut self, a: &Arm) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_arm(self, a)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_pat(&mut self, p: &Pat) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_pat(self, p)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_expr(&mut self, ex: &Expr) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_expr(self, ex)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_ty(&mut self, t: &Ty) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_ty(self, t)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_generics(&mut self, g: &Generics) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_generics(self, g)
|
|
|
|
}
|
2016-10-25 23:17:29 +00:00
|
|
|
fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, s: Span, _: NodeId) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
2016-10-25 23:17:29 +00:00
|
|
|
walk_fn(self, fk, fd, s)
|
2015-11-11 05:26:14 +00:00
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_trait_item(&mut self, ti: &TraitItem) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_trait_item(self, ti)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_impl_item(&mut self, ii: &ImplItem) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_impl_item(self, ii)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_trait_ref(&mut self, t: &TraitRef) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_trait_ref(self, t)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_ty_param_bound(self, bounds)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_poly_trait_ref(self, t, m)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_variant_data(&mut self, s: &VariantData, _: Ident,
|
|
|
|
_: &Generics, _: NodeId, _: Span) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_struct_def(self, s)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_struct_field(&mut self, s: &StructField) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_struct_field(self, s)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_enum_def(&mut self, enum_definition: &EnumDef,
|
|
|
|
generics: &Generics, item_id: NodeId, _: Span) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_enum_def(self, enum_definition, generics, item_id)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_variant(&mut self, v: &Variant, g: &Generics, item_id: NodeId) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_variant(self, v, g, item_id)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_lifetime(&mut self, lifetime: &Lifetime) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_lifetime(self, lifetime)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_lifetime_def(self, lifetime)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_mac(&mut self, _mac: &Mac) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_mac(self, _mac)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_path(&mut self, path: &Path, _id: NodeId) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_path(self, path)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_path_list_item(self, prefix, item)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_path_parameters(self, path_span, path_parameters)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_assoc_type_binding(self, type_binding)
|
|
|
|
}
|
2016-06-12 07:51:31 +00:00
|
|
|
fn visit_attribute(&mut self, _attr: &Attribute) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
|
|
|
}
|
|
|
|
}
|