libabigail/tests/data/test-diff-dwarf/libtest22-changed-parm-c-v1.so
Dodji Seketeli 817aa5555e Un-share diff nodes in the comparison IR
Until now, the diff nodes of the comparison IR were shared.  That is,
two diffs about the same subjects were represented by the same diff
node that would appear twice in the tree.

This was preventing us from spotting e.g, the first occurrence of a
diff node that would later (in the tree) turn to be redundant because
all redundant diff nodes are represented by the same diff node
pointer.

This patch now makes each diff node be different, as far of pointer
comparison is concerned.  But it introduces the concept of canonical
diff node to ease the comparison between two diff nodes.  Two diff
nodes that are equal have the same canonical diff node.

With this facility, it's now possible to tell the difference between
diff nodes that are (structurally) equal.  It's not possible to say
things like "this is the first or second occurrence of the redundant
diff node foo'.

	* include/abg-ir.h: Prefix the doc string with "///", rather than
	writing it inside a /**/ comment.
	* include/abg-comparison.h (function_decl_diff)
	(function_decl_diff_sptr, fn_parm_diff, fn_parm_diff_sptr)
	(var_diff_sptr, base_diff, class_diff, class_diff_sptr): Move
	these class & typedef decls to the top of the file.
	(string_changed_base_map, string_changed_parm_map)
	(unsigned_changed_parm_map, changed_function_ptr)
	(string_changed_function_ptr_map): Remove these typedefs.
	(string_base_diff_sptr_map, string_fn_parm_diff_sptr_map)
	(unsigned_fn_parm_diff_sptr_map, string_var_diff_sptr_map)
	(unsigned_var_diff_sptr_map, string_function_decl_diff_sptr_map)
	(string_var_diff_ptr_map): New typedefs.
	(diff_context::{has_diff_for,add_diff}): Make these member
	functions private.
	(diff_context::{set_canonical_diff_for,
	set_or_get_canonical_diff_for}): Declare new private member
	functions.
	(diff_context::{get_canonical_diff_for,
	initialize_canonical_diff}): New public member functions.
	(diff_context::maybe_apply_filters): Set the default value of the
	'traverse_nodes_once' parameter to false.
	(compute_diff): Make the overload for class_decl_sptr friend of
	the diff_context class.
	(class diff): Make the diff_context class a friend of this one.
	(diff::set_canonical_diff): Declare new private member function.
	(diff::get_canonical_diff): Declare new public member function.
	(diff::children_nodes): Make this return a vector<diff_sptr>, rather
	than a vector<diff*>.
	(diff::append_child_node): Make this take a diff_sptr rather than
	a diff*.
	(class fn_parm_diff): Declare new type.
	(compute_diff): Declare new overload for the new
	function_decl::parameter_sptr.
	(function_decl_diff::subtype_changed_parms): Return a
	string_fn_parm_diff_sptr_map rather than a string_changed_parm.
	(function_decl_diff::children_nodes): Return a vector<diff_sptr>.
	(function_decl_diff::append_child_node): Take a diff_sptr.
	(function_decl_diff::changed_functions): Return a
	string_function_decl_diff_sptr_map.
	(function_decl_diff::changed_variables): Return a
	string_var_diff_sptr.
	(class function_decl::parameter): Make this a pimpled class.
	Also, make it inherit decl_base.
	(equals): New overload for function_decl::parameter.
	(struct function_decl::parameter::hash): Declare this.
	(ir_node_visitor::visit): Declare new overload for
	function_decl::parameter.
	* src/abg-comparison.cc: Add doc-string about the internal
	representation of the comparison engine and also about the concept
	of canonical diff of the comparison engine.
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER)
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER2)
	(RETURN_IF_BEING_REPORTED_OR_WAS_REPORTED_EARLIER3): Consider the
	canonical diff when trying to know if the current node was
	reported earlier.
	(diff_context::priv::canonical_diffs): New data member.
	(diff_context::{get_canonical_diff_for, set_canonical_diff_for,
	set_or_get_canonical_diff_for, initialize_canonical_diff}): Define
	new member functions.
	(diff_context::{diff_has_been_traversed, mark_diff_as_traversed):
	Consider canonical diff for these tests and actions.
	(diff::priv::children_): Change the type of this to
	vector<diff_sptr>.
	(diff::canonical_diff_): New data member.
	(diff::diff): Initialize the diff::canonical_diff_ data member.
	(diff::begin_traversing): Mark the canonical diff node too.
	(diff::is_traversing): Consider the canonical diff node in this
	test.
	(diff::end_traversing): Make the canonical diff node too.  Also
	mark the current node as having been traversed.
	(diff::children_nodes): Return a vector<diff_sptr> type.
	(diff::{get_canonical_diff, set_canonical_diff}): Define new
	member functions.
	(diff::append_child_node): Take a diff_sptr type parameter.
	(diff::{reported_once, currently_reporting}): Flag the canonical
	diff node too.  And consider the canonical diff node when checking
	the flag.
	(diff::traverse): No need to mark the node as being traversed
	because the diff::end_traversing() function does it now.  Adjust
	the code because diff::children_nodes() now returns
	vector<diff_sptr>.
	({distinct_diff, var_diff, pointer_diff, array_diff,
	reference_diff, qualified_type_diff, enum_diff, class_diff,
	base_diff, scope_diff, function_decl_diff, typedef_diff,
	corpus_diff}::chain_into_hierarchy): Adjust to the new type that
	diff::append_child_node() takes.  Also, take into account that the
	diff nodes are now un-shared.
	(compute_diff_for_distinct_kinds, compute_diff_for_types)
	(compute_diff): Do not share diff nodes anymore.  Initialize the
	canonical diff node for the new created node.
	(represent): Take a var_diff_sptr rather than two var_decl_sptr.
	Adjust.  Also take in account the fact that diff nodes are not
	shared anymore, and that they do have canonical diffs.
	(var_diff::type_diff): Make the computation of the type_diff of
	the var_diff be lazy.  This avoids infinite (recursive) creation
	of diff nodes when a class diff node has a sub-type of data member
	that is a class diff node too.
	(var_diff::report): Detect redundant reporting of this kind of
	diff node.
	(class_diff::priv::changed_bases_): Change the type of this to
	string_base_diff_sptr_map.
	(class_diff::priv::subtype_changed_dm_): Change the type of this
	to string_var_diff_sptr_map.
	(class_diff::priv::changed_dm_): Change the type of this to
	unsigned_var_diff_sptr_map.
	(class_diff::priv::{count_filtered_subtype_changed_dm,
	count_filtered_bases}): Do not take a diff_context_sptr anymore.
	(class_diff::ensure_lookup_tables_populated): changed_bases_
	subtype_changed_dm_ and changed_dm_ are now *NOT* shared diff
	nodes anymore.
	(class_diff::priv::base_has_changed): Adjust.
	(class_diff::priv::subtype_changed_dm): Adjust.
	(class_diff::priv::count_filtered_bases): Adjust as changed_bases_
	is now a map of un-shared diff nodes.
	(class_diff::priv::count_filtered_subtype_changed_dm): Adjust as
	subtype_changed_dm_ is now a map of un-shared diff nodes.
	(class_diff::priv::{count_filtered_changed_mem_fns,
	count_filtered_inserted_mem_fns, count_filtered_deleted_mem_fns,
	}): Adjust for change of the default parameter value of
	diff_context::maybe_apply_filters().
	(class_diff::~class_diff): New destructor.
	(class_diff::changed_bases): Return a string_base_diff_sptr_map&
	type.
	(class_diff::{inserted_data_members, deleted_data_members,
	changed_member_fns}): Add doc strings.
	(struct changed_data_member_comp): Remove.
	(struct var_diff_comp): New comparison functor.
	(sort_changed_data_members): Remove.
	(sort_var_diffs): Define new sorting function.
	(class_diff::report): Adjust.
	(fn_parm_diff::*): Define member types and functions of the new
	fn_parm_diff type.
	(function_decl_diff::priv::{subtype_changed_parms_,
	changed_parms_by_id_}): Make these take a map of fn_parm_diff_sptr
	nodes.
	(function_decl_diff::ensure_lookup_tables_populated): Adjust to
	the fact that priv_->subtype_changed_parms_ and
	priv_->priv_->changed_parms_by_id_ now are maps of un-shared
	fn_parm_diff_sptr nodes.
	(function_decl_diff::subtype_changed_parms): Adjust.
	(struct changed_parm_comp): Remove.
	(struct fn_parm_diff_comp): New comparison functor.
	(sort_changed_parm_map): Remove.
	(sort_string_fn_parm_diff_sptr_map): New sorting function.
	(function_decl_diff::report): Adjust.
	(corpus_diff::priv::children_): Change the type of this to
	vector<diff_sptr>.
	(corpus_diff::priv::changed_fns_): Changed the type of this to
	string_function_decl_diff_sptr_map.
	(corpus_diff::priv::changed_vars_): Changed the type of this to
	string_var_diff_sptr_map.
	(corpus_diff::priv::ensure_lookup_tables_populated): Adjust.
	(corpus_diff::priv::apply_filters_and_compute_diff_stats}):
	Adjust.  Do not need to clear redundancy categorization anymore
	because the diff nodes are not shared anymore.
	(corpus_diff::priv::categorize_redundant_changed_sub_nodes):
	Adjust.
	(corpus_diff::priv::clear_redundancy_categorization): Adjust.
	(corpus_diff::changed_variables): Adjust.
	(struct changed_function_ptr_comp): Remove.
	(struct function_decl_diff_comp): New comparison functor.
	(sort_string_changed_function_ptr_map): Remove.
	(sort_string_function_decl_diff_sptr_map): Define new sorting
	function.
	(struct changed_vars_comp): Remove.
	(struct var_diff_sptr_comp): New comparison functor.
	(sort_changed_vars): Remove.
	(sort_string_var_diff_sptr_map): Define new sorting function.
	(corpus_diff::report): Adjust.
	(corpus_diff::traverse): Adjust.
	({category_propagation_visitor,
	suppression_categorization_visitor}::visit_end): Adjust.
	(clear_redundancy_categorization): Adjust.
	* src/abg-hash.cc (function_decl::parameter:#️⃣:operator):
	Adjust.
	* src/abg-ir.cc (struct function_decl::parameter::priv): Define
	here as part of pimpl-ifying the function_decl::parameter type.
	(function_decl::parameter::*): Define here the member functions as
	part of pimpl-ifying the function_decl::parameter type.
	(equals): Define the overload for function_decl::parameter here
	too.
	(ir_node_visitor::visit(function_decl::parameter*)): Define this.
	* tests/data/test-abicompat/test0-fn-changed-report-0.txt: Adjust.
	* tests/data/test-diff-suppr/test5-fn-suppr-report-0.txt: Adjust.
	* tests/data/test-diff-dwarf/libtest21-redundant-fn-v0.so: New
	test input data.
	* tests/data/test-diff-dwarf/libtest21-redundant-fn-v1.so:
	Likewise.
	* tests/data/test-diff-dwarf/test21-redundant-fn-v0.cc: Source
	code for test input binary above.
	* tests/data/test-diff-dwarf/test21-redundant-fn-v1.cc: Likewise.
	* tests/data/test-diff-dwarf/test21-redundant-fn-report-0.txt: New
	test input data.
	* tests/data/test-diff-dwarf/libtest22-changed-parm-c-v0.so: New
	test input data.
	* tests/data/test-diff-dwarf/libtest22-changed-parm-c-v1.so:
	Likewise.
	* tests/data/test-diff-dwarf/test22-changed-parm-c-v0.c: Source
	code for test input binary above.
	* tests/data/test-diff-dwarf/test22-changed-parm-c-v1.c: Likewise.
	* tests/test-diff-dwarf.cc (in_out_spec): Add the new test input
	data to the vector the test inputs to run this harness over.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-0.txt: New
	test input data.
	* tests/data/test-diff-suppr/test8-redundant-fn-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest8-redundant-fn-v0.so: New test
	input binary.
	* tests/data/test-diff-suppr/libtest8-redundant-fn-v1.so: Likewise.
	* tests/data/test-diff-suppr/test8-redundant-fn-v0.cc: Source code
	code for binary test input above.
	* tests/data/test-diff-suppr/test8-redundant-fn-v1.cc: Likewise.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-0.txt:
	New test input data.
	* tests/data/test-diff-suppr/test9-changed-parm-c-report-1.txt:
	Likewise.
	* tests/data/test-diff-suppr/libtest9-changed-parm-c-v0.so: New
	test input binary.
	* tests/data/test-diff-suppr/libtest9-changed-parm-c-v1.so: New
	test input binary.
	* tests/data/test-diff-suppr/test9-changed-parm-c-v0.c: Source
	code for binary test input above.
	* tests/data/test-diff-suppr/test9-changed-parm-c-v1.c: Likewise.
	* tests/test-diff-suppr.cc (in_out_specs): Add the new test input
	data to the vector the test inputs to run this harness over.
	* tests/data/Makefile.am: Add the new files to the source
	distribution.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-12-26 18:45:06 +01:00

8.7 KiB
Executable File