]> git.proxmox.com Git - rustc.git/blob - src/librustc_ast_passes/node_count.rs
New upstream version 1.44.1+dfsg1
[rustc.git] / src / librustc_ast_passes / node_count.rs
1 // Simply gives a rought count of the number of nodes in an AST.
2
3 use rustc_ast::ast::*;
4 use rustc_ast::visit::*;
5 use rustc_span::Span;
6
7 pub struct NodeCounter {
8 pub count: usize,
9 }
10
11 impl NodeCounter {
12 pub fn new() -> NodeCounter {
13 NodeCounter { count: 0 }
14 }
15 }
16
17 impl<'ast> Visitor<'ast> for NodeCounter {
18 fn visit_ident(&mut self, ident: Ident) {
19 self.count += 1;
20 walk_ident(self, ident);
21 }
22 fn visit_mod(&mut self, m: &Mod, _s: Span, _a: &[Attribute], _n: NodeId) {
23 self.count += 1;
24 walk_mod(self, m)
25 }
26 fn visit_foreign_item(&mut self, i: &ForeignItem) {
27 self.count += 1;
28 walk_foreign_item(self, i)
29 }
30 fn visit_item(&mut self, i: &Item) {
31 self.count += 1;
32 walk_item(self, i)
33 }
34 fn visit_local(&mut self, l: &Local) {
35 self.count += 1;
36 walk_local(self, l)
37 }
38 fn visit_block(&mut self, b: &Block) {
39 self.count += 1;
40 walk_block(self, b)
41 }
42 fn visit_stmt(&mut self, s: &Stmt) {
43 self.count += 1;
44 walk_stmt(self, s)
45 }
46 fn visit_arm(&mut self, a: &Arm) {
47 self.count += 1;
48 walk_arm(self, a)
49 }
50 fn visit_pat(&mut self, p: &Pat) {
51 self.count += 1;
52 walk_pat(self, p)
53 }
54 fn visit_expr(&mut self, ex: &Expr) {
55 self.count += 1;
56 walk_expr(self, ex)
57 }
58 fn visit_ty(&mut self, t: &Ty) {
59 self.count += 1;
60 walk_ty(self, t)
61 }
62 fn visit_generic_param(&mut self, param: &GenericParam) {
63 self.count += 1;
64 walk_generic_param(self, param)
65 }
66 fn visit_generics(&mut self, g: &Generics) {
67 self.count += 1;
68 walk_generics(self, g)
69 }
70 fn visit_fn(&mut self, fk: FnKind<'_>, s: Span, _: NodeId) {
71 self.count += 1;
72 walk_fn(self, fk, s)
73 }
74 fn visit_assoc_item(&mut self, ti: &AssocItem, ctxt: AssocCtxt) {
75 self.count += 1;
76 walk_assoc_item(self, ti, ctxt);
77 }
78 fn visit_trait_ref(&mut self, t: &TraitRef) {
79 self.count += 1;
80 walk_trait_ref(self, t)
81 }
82 fn visit_param_bound(&mut self, bounds: &GenericBound) {
83 self.count += 1;
84 walk_param_bound(self, bounds)
85 }
86 fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) {
87 self.count += 1;
88 walk_poly_trait_ref(self, t, m)
89 }
90 fn visit_variant_data(&mut self, s: &VariantData) {
91 self.count += 1;
92 walk_struct_def(self, s)
93 }
94 fn visit_struct_field(&mut self, s: &StructField) {
95 self.count += 1;
96 walk_struct_field(self, s)
97 }
98 fn visit_enum_def(
99 &mut self,
100 enum_definition: &EnumDef,
101 generics: &Generics,
102 item_id: NodeId,
103 _: Span,
104 ) {
105 self.count += 1;
106 walk_enum_def(self, enum_definition, generics, item_id)
107 }
108 fn visit_variant(&mut self, v: &Variant) {
109 self.count += 1;
110 walk_variant(self, v)
111 }
112 fn visit_lifetime(&mut self, lifetime: &Lifetime) {
113 self.count += 1;
114 walk_lifetime(self, lifetime)
115 }
116 fn visit_mac(&mut self, _mac: &MacCall) {
117 self.count += 1;
118 walk_mac(self, _mac)
119 }
120 fn visit_path(&mut self, path: &Path, _id: NodeId) {
121 self.count += 1;
122 walk_path(self, path)
123 }
124 fn visit_use_tree(&mut self, use_tree: &UseTree, id: NodeId, _nested: bool) {
125 self.count += 1;
126 walk_use_tree(self, use_tree, id)
127 }
128 fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
129 self.count += 1;
130 walk_generic_args(self, path_span, generic_args)
131 }
132 fn visit_assoc_ty_constraint(&mut self, constraint: &AssocTyConstraint) {
133 self.count += 1;
134 walk_assoc_ty_constraint(self, constraint)
135 }
136 fn visit_attribute(&mut self, _attr: &Attribute) {
137 self.count += 1;
138 }
139 }