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