Add a --stat option to bidiff

* include/abg-comparison.h (diff_context::show_stats_only):
	Declare new accessors.
	* src/abg-comparison.cc
	(diff_context::priv::show_stats_only_): New member.
	(diff_context::show_stats_only): Define new accessors.
	(corpus_diff::report): If showing stats only, quit right after
	showing the summary.
	* tools/bidiff.cc (options::show_stats_only): New data member.
	(options::options): Initialize the new data member.
	(display_usage): Add help string for --stat.
	(parse_command_line): Parse the --stat option.
	(set_diff_context_from_opts): Update to set the show_stats_only
	onto the context.  Cleanup the logic to make it more compact.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
This commit is contained in:
Dodji Seketeli 2014-02-28 13:03:53 +01:00
parent d24c3d6341
commit fde5a31a2a
3 changed files with 56 additions and 44 deletions

View File

@ -169,6 +169,12 @@ public:
const decl_base_sptr second,
diff_sptr d);
void
show_stats_only(bool f);
bool
show_stats_only() const;
void
show_deleted_fns(bool f);

View File

@ -77,23 +77,25 @@ decls_diff_map_type;
/// The private member (pimpl) for @ref diff_context.
struct diff_context::priv
{
decls_diff_map_type decls_diff_map;
bool show_deleted_fns_;
bool show_changed_fns_;
bool show_added_fns_;
bool show_deleted_vars_;
bool show_changed_vars_;
bool show_added_vars_;
decls_diff_map_type decls_diff_map;
bool show_stats_only_;
bool show_deleted_fns_;
bool show_changed_fns_;
bool show_added_fns_;
bool show_deleted_vars_;
bool show_changed_vars_;
bool show_added_vars_;
priv()
: show_deleted_fns_(true),
: show_stats_only_(false),
show_deleted_fns_(true),
show_changed_fns_(true),
show_added_fns_(true),
show_deleted_vars_(true),
show_changed_vars_(true),
show_added_vars_(true)
{}
};// end struct diff_context::priv
{}
};// end struct diff_context::priv
diff_context::diff_context()
: priv_(new diff_context::priv)
@ -129,10 +131,10 @@ diff_context::has_diff_for(const decl_base_sptr first,
/// null otherwise.
diff_sptr
diff_context::has_diff_for_types(const type_base_sptr first,
const type_base_sptr second) const
const type_base_sptr second) const
{
return has_diff_for(get_type_declaration(first),
get_type_declaration(second));
get_type_declaration(second));
}
/// Tests if the current diff context already has a given diff.
@ -153,10 +155,26 @@ diff_context::has_diff_for(const diff_sptr d) const
/// @param the diff to add.
void
diff_context::add_diff(decl_base_sptr first,
decl_base_sptr second,
diff_sptr d)
decl_base_sptr second,
diff_sptr d)
{priv_->decls_diff_map[std::make_pair(first, second)] = d;}
/// Set a flag saying if the comparison module should only show the
/// diff stats.
///
/// @param f the flag to set.
void
diff_context::show_stats_only(bool f)
{priv_->show_stats_only_ = f;}
/// Test if the comparison module should only show the diff stats.
///
/// @return true if the comparison module should only show the diff
/// stats, false otherwise.
bool
diff_context::show_stats_only() const
{return priv_->show_stats_only_;}
/// Set a flag saying to show the deleted functions.
///
/// @param f true to show deleted functions.
@ -4511,6 +4529,10 @@ corpus_diff::report(ostream& out, const string& indent) const
const unsigned large_num = 100;
priv_->emit_corpus_diff_stats(out, indent);
if (context()->show_stats_only())
return;
out << "\n";
if (context()->show_deleted_fns())
{

View File

@ -47,6 +47,7 @@ struct options
{
string file1;
string file2;
bool show_stats_only;
bool show_symtabs;
bool show_deleted_fns;
bool show_changed_fns;
@ -58,7 +59,8 @@ struct options
bool show_all_vars;
options()
: show_symtabs(false),
: show_stats_only(false),
show_symtabs(false),
show_deleted_fns(false),
show_changed_fns(false),
show_added_fns(false),
@ -75,6 +77,7 @@ display_usage(const string prog_name, ostream& out)
{
out << "usage: " << prog_name << "[options] [<bi-file1> <bi-file2>]\n"
<< " where options can be:\n"
<< " --stat only display the diff stats\n"
<< " --symtabs only display the symbol tables of the corpora\n"
<< " --deleted-fns display deleted public functions\n"
<< " --changed-fns display changed public functions\n"
@ -113,6 +116,8 @@ parse_command_line(int argc, char* argv[], options& opts)
else
return false;
}
else if (!strcmp(argv[i], "--stat"))
opts.show_stats_only = true;
else if (!strcmp(argv[i], "--symtabs"))
opts.show_symtabs = true;
else if (!strcmp(argv[i], "--help"))
@ -208,36 +213,15 @@ static void
set_diff_context_from_opts(diff_context_sptr ctxt,
options& opts)
{
ctxt->show_stats_only(opts.show_stats_only);
ctxt->show_deleted_fns(opts.show_all_fns || opts.show_deleted_fns);
ctxt->show_changed_fns(opts.show_all_fns || opts.show_changed_fns);
ctxt->show_added_fns(opts.show_all_fns || opts.show_added_fns);
ctxt->show_deleted_vars(opts.show_all_vars || opts.show_deleted_vars);
ctxt->show_changed_vars(opts.show_all_vars || opts.show_changed_vars);
ctxt->show_added_vars(opts.show_all_vars || opts.show_added_vars);
}
if (opts.show_all_fns || opts.show_deleted_fns)
ctxt->show_deleted_fns(true);
else
ctxt->show_deleted_fns(false);
if (opts.show_all_fns || opts.show_changed_fns)
ctxt->show_changed_fns(true);
else
ctxt->show_changed_fns(false);
if (opts.show_all_fns || opts.show_added_fns)
ctxt->show_added_fns(true);
else
ctxt->show_added_fns(false);
if (opts.show_all_vars || opts.show_deleted_vars)
ctxt->show_deleted_vars(true);
else
ctxt->show_deleted_vars(false);
if (opts.show_all_vars || opts.show_changed_vars)
ctxt->show_changed_vars(true);
else
ctxt->show_changed_vars(false);
if (opts.show_all_vars || opts.show_added_vars)
ctxt->show_added_vars(true);
else
ctxt->show_added_vars(false);
}
int