2015-11-11 05:26:14 +00:00
|
|
|
// Simply gives a rought count of the number of nodes in an AST.
|
|
|
|
|
2019-02-06 17:33:01 +00:00
|
|
|
use crate::visit::*;
|
|
|
|
use crate::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 {
|
2018-03-19 00:54:56 +00:00
|
|
|
fn visit_ident(&mut self, ident: Ident) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
2018-03-19 00:54:56 +00:00
|
|
|
walk_ident(self, ident);
|
2015-11-11 05:26:14 +00:00
|
|
|
}
|
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)
|
|
|
|
}
|
2018-05-27 19:07:09 +00:00
|
|
|
fn visit_generic_param(&mut self, param: &GenericParam) {
|
2017-10-16 19:07:26 +00:00
|
|
|
self.count += 1;
|
|
|
|
walk_generic_param(self, param)
|
|
|
|
}
|
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)
|
|
|
|
}
|
2019-02-06 17:33:01 +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)
|
|
|
|
}
|
2018-06-14 11:08:58 +00:00
|
|
|
fn visit_param_bound(&mut self, bounds: &GenericBound) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
2018-05-28 14:23:16 +00:00
|
|
|
walk_param_bound(self, bounds)
|
2015-11-11 05:26:14 +00:00
|
|
|
}
|
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_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)
|
|
|
|
}
|
2017-09-26 21:04:00 +00:00
|
|
|
fn visit_use_tree(&mut self, use_tree: &UseTree, id: NodeId, _nested: bool) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
2017-09-26 21:04:00 +00:00
|
|
|
walk_use_tree(self, use_tree, id)
|
2015-11-11 05:26:14 +00:00
|
|
|
}
|
2018-02-13 11:32:37 +00:00
|
|
|
fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
|
2015-11-11 05:26:14 +00:00
|
|
|
self.count += 1;
|
2018-02-13 11:32:37 +00:00
|
|
|
walk_generic_args(self, path_span, generic_args)
|
2015-11-11 05:26:14 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
}
|