1 // Simply gives a rough count of the number of nodes in an AST.
3 use rustc_ast::visit::*;
5 use rustc_span::symbol::Ident;
8 pub struct NodeCounter {
13 pub fn new() -> NodeCounter {
14 NodeCounter { count: 0 }
18 impl<'ast> Visitor<'ast> for NodeCounter {
19 fn visit_ident(&mut self, _ident: Ident) {
22 fn visit_foreign_item(&mut self, i: &ForeignItem) {
24 walk_foreign_item(self, i)
26 fn visit_item(&mut self, i: &Item) {
30 fn visit_local(&mut self, l: &Local) {
34 fn visit_block(&mut self, b: &Block) {
38 fn visit_stmt(&mut self, s: &Stmt) {
42 fn visit_arm(&mut self, a: &Arm) {
46 fn visit_pat(&mut self, p: &Pat) {
50 fn visit_expr(&mut self, ex: &Expr) {
54 fn visit_ty(&mut self, t: &Ty) {
58 fn visit_generic_param(&mut self, param: &GenericParam) {
60 walk_generic_param(self, param)
62 fn visit_generics(&mut self, g: &Generics) {
64 walk_generics(self, g)
66 fn visit_fn(&mut self, fk: visit::FnKind<'_>, s: Span, _: NodeId) {
70 fn visit_assoc_item(&mut self, ti: &AssocItem, ctxt: AssocCtxt) {
72 walk_assoc_item(self, ti, ctxt);
74 fn visit_trait_ref(&mut self, t: &TraitRef) {
76 walk_trait_ref(self, t)
78 fn visit_param_bound(&mut self, bounds: &GenericBound, _ctxt: BoundKind) {
80 walk_param_bound(self, bounds)
82 fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef) {
84 walk_poly_trait_ref(self, t)
86 fn visit_variant_data(&mut self, s: &VariantData) {
88 walk_struct_def(self, s)
90 fn visit_field_def(&mut self, s: &FieldDef) {
92 walk_field_def(self, s)
94 fn visit_enum_def(&mut self, enum_definition: &EnumDef) {
96 walk_enum_def(self, enum_definition)
98 fn visit_variant(&mut self, v: &Variant) {
100 walk_variant(self, v)
102 fn visit_lifetime(&mut self, lifetime: &Lifetime, _: visit::LifetimeCtxt) {
104 walk_lifetime(self, lifetime)
106 fn visit_mac_call(&mut self, mac: &MacCall) {
110 fn visit_path(&mut self, path: &Path, _id: NodeId) {
112 walk_path(self, path)
114 fn visit_use_tree(&mut self, use_tree: &UseTree, id: NodeId, _nested: bool) {
116 walk_use_tree(self, use_tree, id)
118 fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
120 walk_generic_args(self, path_span, generic_args)
122 fn visit_assoc_constraint(&mut self, constraint: &AssocConstraint) {
124 walk_assoc_constraint(self, constraint)
126 fn visit_attribute(&mut self, _attr: &Attribute) {