| 265 | } |
| 266 | |
| 267 | void |
| 268 | Bookkeeper::output_pointer_statistics(std::ostream &out) |
| 269 | { |
| 270 | size_t i; |
| 271 | int total_alias_cnt = 0; |
| 272 | int total_has_null_ptr = 0; |
| 273 | int point_to_scalar = 0; |
| 274 | int point_to_struct = 0; |
| 275 | int point_to_pointer = 0; |
| 276 | const vector<const Variable*>& ptrs = FactPointTo::all_ptrs; |
| 277 | const vector<vector<const Variable*> >& aliases = FactPointTo::all_aliases; |
| 278 | for (i=0; i<ptrs.size(); i++) { |
| 279 | total_alias_cnt += aliases[i].size(); |
| 280 | if (find_variable_in_set(aliases[i], FactPointTo::null_ptr) >= 0) { |
| 281 | total_has_null_ptr++; |
| 282 | } |
| 283 | const Variable* var = ptrs[i]; |
| 284 | const Type* t = var->type; |
| 285 | assert(t->eType == ePointer); |
| 286 | if (t->get_indirect_level() > 1) { |
| 287 | point_to_pointer++; |
| 288 | } |
| 289 | else if (t->ptr_type->eType == eSimple) { |
| 290 | point_to_scalar++; |
| 291 | } |
| 292 | else if (t->ptr_type->eType == eStruct) { |
| 293 | point_to_struct++; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | formated_output(out, "total number of pointers: ", ptrs.size()); |
| 298 | if (ptrs.size() > 0) { |
| 299 | out << endl; |
| 300 | formated_output(out, "times a variable address is taken: ", address_taken_cnt); |
| 301 | formated_output(out, "times a pointer is dereferenced on RHS: ", calc_total(read_dereference_cnts)); |
| 302 | out << "breakdown:" << endl; |
| 303 | for (i=1; i<read_dereference_cnts.size(); i++) { |
| 304 | out << " depth: " << i << ", occurrence: " << read_dereference_cnts[i] << endl; |
| 305 | } |
| 306 | formated_output(out, "times a pointer is dereferenced on LHS: ", calc_total(write_dereference_cnts)); |
| 307 | out << "breakdown:" << endl; |
| 308 | for (i=1; i<write_dereference_cnts.size(); i++) { |
| 309 | out << " depth: " << i << ", occurrence: " << write_dereference_cnts[i] << endl; |
| 310 | } |
| 311 | formated_output(out, "times a pointer is compared with null: ", cmp_ptr_to_null); |
| 312 | formated_output(out, "times a pointer is compared with address of another variable: ", cmp_ptr_to_addr); |
| 313 | formated_output(out, "times a pointer is compared with another pointer: ", cmp_ptr_to_ptr); |
| 314 | formated_output(out, "times a pointer is qualified to be dereferenced: ", pointer_avail_for_dereference); |
| 315 | |
| 316 | // if there are dereferenced pointers |
| 317 | if (dereference_level_cnts.size()) { |
| 318 | out << endl; |
| 319 | formated_output(out, "max dereference level: ", dereference_level_cnts.size()-1); |
| 320 | out << "breakdown:" << endl; |
| 321 | for (i=0; i<dereference_level_cnts.size(); i++) { |
| 322 | out << " level: " << i << ", occurrence: " << dereference_level_cnts[i] << endl; |
| 323 | } |
| 324 | } |
nothing calls this directly
no test coverage detected