Release coccinelle-0.1.2
[bpt/coccinelle.git] / parsing_c / parsing_stat.ml
1 open Common
2
3 (* if do .mli:
4 val print_parsing_stat_list: parsing_stat list -> unit
5 *)
6
7 (*****************************************************************************)
8 (* Stat *)
9 (*****************************************************************************)
10 type parsing_stat = {
11 filename: filename;
12 mutable have_timeout: bool;
13
14 mutable correct: int;
15 mutable bad: int;
16
17 mutable commentized: int; (* by our cpp commentizer *)
18
19 (* if want to know exactly what was passed through, uncomment:
20 *
21 * mutable passing_through_lines: int;
22 *
23 * it differs from bad by starting from the error to
24 * the synchro point instead of starting from start of
25 * function to end of function.
26 *)
27
28 }
29
30 let default_stat file = {
31 filename = file;
32 have_timeout = false;
33 correct = 0; bad = 0;
34 commentized = 0;
35 }
36
37 (* todo: stat per dir ? give in terms of func_or_decl numbers:
38 * nbfunc_or_decl pbs / nbfunc_or_decl total ?/
39 *
40 * note: cela dit si y'a des fichiers avec des #ifdef dont on connait pas les
41 * valeurs alors on parsera correctement tout le fichier et pourtant y'aura
42 * aucune def et donc aucune couverture en fait.
43 * ==> TODO evaluer les parties non parsé ?
44 *)
45
46 let print_parsing_stat_list ?(verbose=false) = fun statxs ->
47 let total = List.length statxs in
48 let perfect =
49 statxs
50 +> List.filter (function
51 {have_timeout = false; bad = 0} -> true | _ -> false)
52 +> List.length
53 in
54
55 if verbose then begin
56 pr "\n\n\n---------------------------------------------------------------";
57 pr "pbs with files:";
58 statxs
59 +> List.filter (function
60 | {have_timeout = true} -> true
61 | {bad = n} when n > 0 -> true
62 | _ -> false)
63 +> List.iter (function
64 {filename = file; have_timeout = timeout; bad = n} ->
65 pr (file ^ " " ^ (if timeout then "TIMEOUT" else i_to_s n));
66 );
67
68 pr "\n\n\n";
69 pr "files with lots of tokens passed/commentized:";
70 let threshold_passed = 100 in
71 statxs
72 +> List.filter (function
73 | {commentized = n} when n > threshold_passed -> true
74 | _ -> false)
75 +> List.iter (function
76 {filename = file; commentized = n} ->
77 pr (file ^ " " ^ (i_to_s n));
78 );
79
80 pr "\n\n\n---------------------------------------------------------------";
81 end;
82
83 pr (
84 (sprintf "NB total files = %d; " total) ^
85 (sprintf "perfect = %d; " perfect) ^
86 (sprintf "pbs = %d; " (statxs +> List.filter (function
87 {have_timeout = b; bad = n} when n > 0 -> true | _ -> false)
88 +> List.length)) ^
89 (sprintf "timeout = %d; " (statxs +> List.filter (function
90 {have_timeout = true; bad = n} -> true | _ -> false)
91 +> List.length)) ^
92 (sprintf "=========> %d" ((100 * perfect) / total)) ^ "%"
93
94 );
95 let good = statxs +> List.fold_left (fun acc {correct = x} -> acc+x) 0 in
96 let bad = statxs +> List.fold_left (fun acc {bad = x} -> acc+x) 0 in
97 let passed = statxs +> List.fold_left (fun acc {commentized = x} -> acc+x) 0
98 in
99 let gf, badf = float_of_int good, float_of_int bad in
100 let passedf = float_of_int passed in
101 pr (
102 (sprintf "nb good = %d, nb passed = %d " good passed) ^
103 (sprintf "=========> %f" (100.0 *. (passedf /. gf)) ^ "%")
104 );
105 pr (
106 (sprintf "nb good = %d, nb bad = %d " good bad) ^
107 (sprintf "=========> %f" (100.0 *. (gf /. (gf +. badf))) ^ "%"
108 )
109 )
110
111 (*****************************************************************************)
112 (* Stat *)
113 (*****************************************************************************)
114
115 (* coupling: if you add a new var, modify also assoc_stat_number below *)
116
117 let nTypedefInfer = ref 0
118
119 let nIncludeGrammar = ref 0
120 let nIncludeHack = ref 0
121
122 let nIteratorGrammar = ref 0
123 let nIteratorHeuristic = ref 0
124
125 let nMacroTopDecl = ref 0
126 let nMacroStructDecl = ref 0
127 let nMacroDecl = ref 0
128 let nMacroStmt = ref 0
129 let nMacroString = ref 0
130 let nMacroHigherOrder = ref 0 (* actions *)
131 let nMacrohigherTypeGrammar = ref 0
132 let nMacroAttribute = ref 0
133
134 let nIfdefTop = ref 0
135 let nIfdefStmt = ref 0
136 let nIfdefStruct = ref 0
137 let nIfdefInitializer = ref 0
138 (* nIfdefExpr, nIfdefType *)
139
140 let nIfdefFunheader = ref 0
141
142 let nIfdefExprPassing = ref 0
143 let nIfdefPassing = ref 0
144
145 let nIncludePassing = ref 0
146 let nDefinePassing = ref 0
147
148 let nIfdefZero = ref 0
149 let nIfdefVersion = ref 0
150
151
152
153 let nGccTypeof = ref 0
154 let nGccLongLong = ref 0
155 let nGccAsm = ref 0
156 let nGccInline = ref 0
157 let nGccAttribute = ref 0
158 let nGccCaseRange = ref 0
159 let nGccMixDecl = ref 0
160 let nGccDesignator = ref 0
161 let nGccStmtExpr = ref 0
162 let nGccConstructor = ref 0
163 let nGccEmptyStruct = ref 0
164 let nGccNestedFunc = ref 0
165
166 let nGccMisc = ref 0
167
168
169
170 let nDefineHack = ref 0
171
172 let nDefineConstant = ref 0
173 let nDefineStmt = ref 0
174 let nDefineExpr = ref 0
175 (* both below require some heuristic support *)
176 let nDefineWhile0 = ref 0
177 let nDefineInit = ref 0
178
179 let nDefineOther = ref 0
180
181 let nUndef = ref 0
182 let nPragmaAndCo = ref 0
183
184 (* let nDirectiveTop = ref 0 *)
185 let nDirectiveStmt = ref 0
186 let nDirectiveStruct = ref 0
187 let nDirectiveInitializer = ref 0
188
189
190 (* from standard.h *)
191 let nMacroHint = ref 0
192 let nMacroExpand = ref 0
193
194 let nNotParsedCorrectly = ref 0
195
196 let assoc_stat_number =
197 [
198 "nTypedefInfer", nTypedefInfer;
199
200 "nIteratorHeuristic", nIteratorHeuristic;
201
202 "nMacroTopDecl", nMacroTopDecl;
203 "nMacroStructDecl", nMacroStructDecl;
204 "nMacroDecl", nMacroDecl;
205 "nMacroStmt", nMacroStmt;
206 "nMacroString", nMacroString;
207 "nMacroHigherOrder", nMacroHigherOrder;
208 "nMacroAttribute", nMacroAttribute;
209
210 "nMacrohigherTypeGrammar", nMacrohigherTypeGrammar;
211
212 "nIfdefTop", nIfdefTop;
213 "nIfdefStmt", nIfdefStmt;
214 "nIfdefStruct", nIfdefStruct;
215 "nIfdefInitializer", nIfdefInitializer;
216
217 "nIfdefFunheader", nIfdefFunheader;
218 "nIfdefZero", nIfdefZero;
219 "nIfdefVersion", nIfdefVersion;
220 "nIfdefExprPassing", nIfdefExprPassing;
221 "nIfdefPassing", nIfdefPassing;
222
223 "nIncludePassing", nIncludePassing;
224 "nDefinePassing", nDefinePassing;
225
226 "nMacroExpand", nMacroExpand;
227 "nMacroHint", nMacroHint;
228
229
230 "nGccTypeof", nGccTypeof;
231 "nGccLongLong", nGccLongLong;
232 "nGccAsm", nGccAsm;
233 "nGccInline", nGccInline;
234 "nGccAttribute", nGccAttribute;
235 "nGccCaseRange", nGccCaseRange;
236 "nGccMixDecl", nGccMixDecl;
237 "nGccDesignator", nGccDesignator;
238 "nGccStmtExpr", nGccStmtExpr;
239 "nGccConstructor", nGccConstructor;
240 "nGccEmptyStruct", nGccEmptyStruct;
241 "nGccNestedFunc", nGccNestedFunc;
242
243 "nGccMisc", nGccMisc;
244
245
246 "nDefineHack", nDefineHack;
247
248 "nDefineConstant", nDefineConstant;
249 "nDefineStmt", nDefineStmt;
250 "nDefineExpr", nDefineExpr;
251 "nDefineInit", nDefineInit;
252 "nDefineOther", nDefineOther;
253
254 "nUndef", nUndef;
255 "nPragmaAndCo", nPragmaAndCo;
256
257 "nDirectiveStmt", nDirectiveStmt;
258 "nDirectiveStruct", nDirectiveStruct;
259 "nDirectiveInitializer", nDirectiveInitializer;
260
261 "nNotParsedCorrectly", nNotParsedCorrectly;
262
263
264 (* less *)
265 "nIncludeGrammar", nIncludeGrammar;
266 "nIncludeHack", nIncludeHack;
267
268 "nIteratorGrammar", nIteratorGrammar;
269 ]
270
271 let print_stat_numbers () =
272 assoc_stat_number +> List.iter (fun (k, vref) ->
273 pr2 (spf "%-30s -> %d" k !vref);
274 )