Commit Graph

391 Commits

Author SHA1 Message Date
Dodji Seketeli
ef94728513 Small optimization hinted by profiling
* include/abg-diff-utils.h (d_path_vec::max_d): Avoid using member
	functions.  This is relevant only when compiling w/o optimization.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
de342efd76 Fix allocation of diff_utils::d_path_vec
* include/abg-diff-utils.h (d_path_vec::d_path_vec):  Do not
	forget to allocate enough data for reverse vectors as well.  The
	comment of the constructor is accurate.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
cb764d3cdf Misc style fixes
* include/abg-hash.h (combine_hashes): Remove trailing white
	spaces.
	* include/abg-ir.h (class function_decl): Add end-of-class
	comment.
	(struct type_base::cached_hash): Fix comment.
	* src/abg-comparison.cc: Remove useless new line.
	* src/abg-corpus.cc: Likewise.
	* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
9905d847d2 Support looking through decl-only classes and update diff reports
accordingly

	* include/abg-comparison.h (class diff_context): New class.
	(class diff::{ctxt_, reported_once_, currently_reporting_}): New
	data members.
	(diff::diff): Initialize the new data members above.
	(diff::{context, currently_reporting, reported_once}): New
	accessors.
	(compute_diff, var_diff::var_diff, pointer_diff::pointer_diff)
	(reference_diff::reference_diff, qualified_type_diff)
	(enum_diff:enum_diff, class_diff::class_diff)
	(scope_diff::scope_diff, function_decl_diff::function_decl_diff)
	(type_decl_diff::type_decl_diff, typedef_diff::typedef_diff)
	(translation_unit_diff::translation_unit_diff, corpus_diff::corpus_diff):
	Take an additional pointer to diff_context.
	* abg-comparison.cc (diff_context::{has_diff_for,
	has_diff_for_types, add_diff}): New methods.
	(try_to_diff, compute_diff_for_types, compute_diff_for_decls)
	(represent): Take an additional pointer to
	diff_context in argument.  In the later function, do not re-report
	a diff if it has already been reported, or if it's being reported
	already.
	(var_diff::var_diff, pointer_diff::pointer_diff)
	(reference_diff::reference_diff)
	(qualified_type_diff::qualified_type_diff, enum_diff::enum_diff)
	(class_diff::class_diff, scope_diff::scope_diff)
	(function_decl_diff::function_decl_diff, type_decl::type_decl)
	(typedef_diff::typedef_diff)
	(translation_unit_diff::translation_unit_diff)
	(corpus_diff::corpus_diff): Take an additional pointer to
	diff_context in argument.
	({pointer_diff, qualified_type_diff,
	reference_type_diff}::report): do not re-report a diff about the
	underlying type if it has already been reported, or if it's being
	reported already.
	(enum_diff::report): Fix this to properly use the populated lookup
	tables.
	(compute_diff): take an additional pointer to diff_context in
	argument. For the var_decl, pointer_diff reference_type_diff,
	qualified_type_diff enum_diff, scope_diff, function_decl_diff,
	type_decl_diff and typedef_diff overloads, do not re-build a diff
	object, if one exits already.  Otherwise, record the new diff
	object created so that it can be re-used later.
	(enum_diff::ensure_lookup_tables_populated): Fix logic to avoid
	one loop.
	(class_decl::priv::{deleted_member_functions_,
	inserted_member_functions_, changed_member_function_}): New
	members to support reporting about member functions changes.
	(class_decl::{lookup_tables_empty, clear_lookup_tables, length):
	Update for the new additions above.
	(class_decl::ensure_lookup_tables_populated): Likewise.  Fix to
	properly use the lookup tables and also avoid a going through
	several loops to compute the changed members.
	(class_decl::report): Flip a switch to make the beginning and end
	of the reporting, in the context.  Also, do not try to report
	again, if we were already reporting this diff.  Fix quite some
	spots to properly use the lookup tables.
	(scope_diff::ensure_lookup_tables_populated): Skip decl-only
	classes during comparison. Fix some thinkos.  Fix logic to avoid a
	loop.
	(scope_diff::report): Adjust to pass a context to
	compute_diff_for_types.
	(function_decl_diff::ensure_lookup_tables_populated): Fix logic to
	avoid a loop.
	(function_decl_diff::report): Adjust call to
	compute_diff_for_types to pass the context.
	(typedef::report): Avoid re-reporting the diff of the underlying
	types, if we are already reporting it.
	(corpus_diff::priv::ensure_lookup_tables_populated): Use the
	pretty representation of the function rather than its name to key
	the maps of deleted and added functions. Fix logic to avoid going
	through an additional loop for the changed functions.
	(corpus_diff::report): Add a title for removed/added/changed
	functions.  Fix indentation for added/removed/changed functions.
	* include/abg-ir.h (class_decl::comparison_started_): New member
	* src/abg-dwarf-reader.cc (is_public_decl): Style fix.
	(is_declaration_only_): New static function.
	(build_class_type_and_add_to_ir): Create decl-only classes (IR) for
	classes flagged as declaration-only in the DWARF.
	* src/abg-hash.cc (class_decl:#️⃣:operator()): Do not forget to
	include the "is_declaration_only" flag into the hashing.
	* src/abg-ir.cc (class_decl::operator==): Look through decl-only
	classes to get their definitions and compare the definitions
	instead.  Avoid comparing member types and fns if the comparison
	of this type has already started.
	* src/abg-reader.cc (build_class_decl): Set the definition of a
	declaration, when we see it.
	* tests/data/test-bidiff/test-qual-type0-report.txt: Update.
	* tests/data/test-bidiff/test-struct0-report.txt: Likewise.
	* tests/data/test-bidiff/test-struct1-report.txt: Likewise.

signed-off-by: Dodji Seketeli <dodji@redhat.com>
Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:10 +01:00
Dodji Seketeli
a2cd6d7e04 Support reading *.bi input with duplicated qualified type ids.
* src/abg-reader.cc (read_context::map_id_and_node): Support
	qualified types with duplicated ids.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
b123d39e6d Fix comparison of member types
* src/abg-ir.cc (class_decl::member_type::operator==): Compare the
	underlying type of the member type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
f8e9d43e68 Avoid duplicated entries in the symbol tables of the corpus
* include/abg-ir.h ({var_decl, function_decl}::ptr_equal): New
	  equality functor for pointers to var_decl and function_decl.
	  ({function_decl, var_decl}::hash): Make these hashing functors
	public.
	* include/abg-hash.cc (struct var_decl::hash, struct
	function_decl::hash): Remove these from here.  There are now in
	the public abg-ir.h.
	({var_decl, function_decl}:#️⃣:operator()): Define these here.
	* src/abg-corpus.cc (symtab_build_visitor_type::{fns_map,
	fn_is_in_map, add_fn_to_map, vars_map, var_is_in_map,
	add_var_to_map}): New accessors.
	(corpus::priv::build_symbol_table): Avoid duplicated entries in
	variables and functions symbols tables.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
e8dd2cf705 Ease debugging of abigail::diff_utils::compute_diff
* include/abg-diff-utils.h (compute_diff): Add asserts on for the
	length of the shortest edit script during the divide and conquer
	part of the diff algorithm.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
b219598e7b Fix further reaching reverse path calculation in core diff algo
* include/abg-diff-utils.h (end_of_frr_d_path_in_k_plus_delta):
	Favour moving left when the two abscissas at the previous steps
	are equal.
	(compute_diff): Update the length of the shortest edit script when
	the size of one of the inputs is zero.
	* tests/test-core-diff.cc (in_out_spec): Add a new input to diff
	two sequences for regression testing.
	* tests/data/test-core-diff/report13.txt: New reference for
	the comparison of the new regression test above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
7d19840822 Add debugging facilities for core diffing issues
* include/abg-ir.h (fns_to_str): Declare new fn.
	* src/abg-ir.cc (get_next_string, fn_to_str, fns_to_str): New
	static functions.
	(fns_to_str): Define new fn.
	* tools/abg-tools-utils.cc (dump_functions_as_string)
	(dump_function_names, compare_functions): New functions.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-02-10 15:51:09 +01:00
Dodji Seketeli
d8dd83d69c Fix apidoc comment
* src/abg-ir.cc (decl_base::operator==): Fix comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-20 12:18:13 +01:00
Dodji Seketeli
2a078ca1af Fix bilint outputting for translation units & corpus
* tools/bilint.cc (main): Fix logic.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-20 12:16:31 +01:00
Dodji Seketeli
e6e4e8425e Remove debugging assertion when diffing
* include/abg-diff-utils.h (d_path_vec::at): Do not check for
	bounds.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-20 12:15:07 +01:00
Dodji Seketeli
84323f2a84 Do not use exceptions in dynamic_cast
* src/abg-ir.cc (class_decl::member_function::operator==)
	(class_decl::member_function::operator==): Do not use the
	exception path for dynamic casting.  This was near the top of many
	profiles.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-20 10:41:28 +01:00
Dodji Seketeli
b152fa74b4 Just add decls sequentially when reading from DWARF
* src/abg-dwarf-reader.cc (insert_decl_into_ir_under_scope)
	(build_namespace_decl_and_add_to_ir, build_enum_type)
	(build_class_type_and_add_to_ir, build_ir_node_from_die)
	(build_ir_node_from_die): Remove.
	* tests/data/test-read-dwarf/test0.abi: Update because now type
	IDs can be used before they are defined.
	* tests/data/test-read-dwarf/test1.abi: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-20 10:32:37 +01:00
Dodji Seketeli
73814ba4fa Misc Doxygen API doc fixes
* include/abg-comparison.h: Various doxygen api doc string fixes.
	* include/abg-diff-utils.h: Likewise.
	* include/abg-dwarf-reader.h: Likewise.
	* include/abg-ir.h: Likewise.
	* include/abg-reader.h: Likewise.
	* include/abg-writer.h: Likewise.
	* src/abg-comparison.cc: Likewise.
	* src/abg-corpus.cc: Likewise.
	* src/abg-dwarf-reader.cc: Likewise.
	* src/abg-ir.cc: Likewise.
	* src/abg-libxml-utils.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
677a69f8e1 Fix bilint --noout, add --diff option
* tools/bilint.cc (options::options): Initialize ...
	(options::{diff, bidiff}): ... new members.
	(display_usage): Update the display usage string for --diff &
	--bidiff options.
	(parse_command_line): Support the --diff and --bidiff options.
	(main): Require the --diff option to actually diff the emitted
	output with input.  Make --noout really work for when reading
	from dwarf.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
b19558028c Read .abi files with types used before being defined & lots of fixes
* src/abg-reader.cc (read_context::m_decls_stack): Make this is a
	std::deque, rather than a std::stack.
	(read_context::{get_id_xml_node_map,
	clear_id_xml_node_map, get_xml_node_decl_map,
	map_xml_node_to_decl, get_decl_for_xml_node,
	clear_xml_node_decl_map, map_id_and_node, get_xml_node_from_id,
	get_scope_for_node, build_or_get_type_decl}): New member
	functions.
	(read_context::{get_cur_decl, push_decl, pop_decl}): Update this
	now that the decl stack uses a std::deque.
	(read_context::clear_decls_stack): New.
	(read_context::get_translation_unit):  Use the first decl of the
	decl stack, that is most certainly the global scope of the current
	translation unit, to get the translation unit.
	(read_context::key_type_decl): Take a new flag to force the
	re-keying; that is set an id to a new type, even if the id was
	already set to a type.
	(read_context::push_and_key_type_decl): Assert that a type must
	have a declaration.
	(handle_*): Make these return the decl_base_sptr resulting from
	the parsing of the xml node, rather than just a bool.
	(walk_xml_node_to_map_type_ids): New static function.
	(read_translation_unit_from_input): Read the abi-instr xml
	sub-tree once, just to build an id->xml node map.  That way, when a
	declaration needs a type what is not yet defined, it can just get
	its XML node, build the type from it and use it.  Do not forget to
	advance the xml reader cursor when the reading of the 'abi-instr'
	sub-tree is read.  Clear all the new maps we have used for the
	current translation unit.
	(handle_element_node): Cleanup logic.
	(build_namespace_decl): Update the new xml node -> decl map, and
	use it to avoid building the same namespace twice.
	(build_function_parameter): Do not even try to get the type of a
	variadic parameter.
	(build_function_decl, build_var_decl): Support types that are defined later.
	(build_type_decl): Do not build the same type twice.  But there
	can be several 'unnamed-enum-underlying-type' node.  In that case
	just return the previous one.
	(build_qualified_type_decl, build_pointer_type_def)
	(build_reference_type_def, build_enum_type_decl)
	(build_typedef_decl): Support underlying type defined later.
	(build_class_decl): Support declaration-only related cases where
	we can have several xml nodes with the same id.  Update the new
	xml node -> IR node maps.  Fix member type adding.
	(build_type_tparameter, build_non_type_tparameter)
	(build_template_tparameter): Support used types defined later.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
5aec5a983d Fix member class template creation
* src/abg-ir.cc (class_decl::add_member_class_template): Do not
	forget the scope of the member class template itself.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
d5a926ebfb Avoid endless loop in unescape_xml_string
* src/abg-libxml-utils.cc (unescape_xml_string): Avoid and endless
	loop for strings containing an '&' but that are not pre-defined
	entities.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
cedf8e9cec Fix a potential crash
* src/abg-ir.cc (decl_base::get_qualified_name): Do not crash if
	the scope is empty.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
a681992d0f Do not loose the member type information when reading them from DWARF
* include/abg-ir.h (class_decl::declaration_):  Make this be a
	decl_base_sptr so that it can actually be a
	class_decl::member_type which underlying type is a class decl.
	(class_decl::{set, get}_earlier_declaration): Take or return a
	decl_base_sptr rather than a class_decl_sptr.
	* src/abg-ir.cc (class_decl::set_earlier_declaration): Take a
	decl_base_sptr rather than a class_decl_sptr.
	* src/abg-dwarf-reader.cc (die_class_map_type): Make this map take
	decl_base_sptr rather than a class_decl_sptr.
	(build_class_type_and_add_to_ir): If the class being currently
	built is a member class, do not loose that information after it
	has been added to its scope.  Also, base types and types of member
	variables can be member types and should retain that information.
	(build_qualified_type): Likewise, the underlying type of a
	qualified type shouldn't loose the information about its
	potentially being a member type.
	(build_pointer_type_def, build_reference_type, build_typedef_type)
	(build_var_decl, build_function_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
be14ac2ab2 Fix hashing of member types
* include/abg-ir.h (class_decl::{member_function_template,
	member_class_template}):  Make these inherit from decl_base, to
	comply with class_decl::member_type.
	(class_decl_base_spec::{base_spec, member_type, member_function,
	member_function_template, member_class_template}::hash): Declare
	these hashing functors in the header here.
	(class_decl::{member_base, member_type, data_member,
	member_function, member_function_template,
	member_class_template}:#️⃣:operator()): define these out of
	line here.
	(type_base::dynamic_hash::operator()): Update this to hash member
	things.
	* src/abg-writer.cc (write_qualified_type_def)
	(write_pointer_type_def, write_class_decl)
	(write_reference_type_def, write_enum_type_decl): Add an overload
	that takes the type ID to use in the serialization.
	(write_member_type): New implementation.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:25 +01:00
Dodji Seketeli
fbe972012a A Member class can also be a scope for other decls in DWARF
* include/abg-fwd.h (as_non_member_class_decl): Declare ...
	* src/abg-ir.cc (as_non_member_class_decl): ... this new function.
	* include/abg-ir.h (class class_decl::member_type): Add more
	comments about member types.
	* src/abg-dwarf-reader.cc (get_scope_for_die): Use the new
	as_non_member_class_decl here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Dodji Seketeli
31b6660832 Misc style fixes
* include/abg-ir.h (location_manager::_Impl): Rename this type
	into priv.
	* src/abg-ir.cc b/src/abg-ir.cc (location_manager::_Impl):
	Likewise.
	(location_manager::location_manager): Update for the renaming
	above.
	* src/abg-reader.cc (build_type_decl): Remove useless white space.
	(build_enum_type_decl, build_class_decl): Use the _sptr typedef in
	the return type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Dodji Seketeli
cca996aa48 Update namespace comments
* src/abg-dwarf-reader.cc (namespace dwarf_reader): Add apidoc comment.
	* src/abg-reader.cc (namespace xml_reader): Update apidoc comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Dodji Seketeli
2322638246 Expand 'abi-instr' XML element nodes during de-serialization
* src/abg-reader.cc (update_read_context)
	(update_depth_info_of_read_context): Remove.
	(read_context::{pop_scope, pop_scope_or_abort): New.
	(read_context::{push_decl_to_current_scope,
	push_and_key_type_decl}): Remove the overloads that take the
	'update_depth_info' boolean.
	(build_namespace_decl): New static function.
	(build_function_decl, build_var_decl, build_type_decl)
	(build_qualified_type_decl, build_pointer_type_def)
	(build_reference_type_def, build_enum_type_decl, build_type_decl)
	(build_class_decl, build_function_tdecl, build_class_tdecl)
	(build_type_tparameter, build_type_composition)
	(build_non_type_tparameter, build_template_tparameter)
	(build_template_parameter, build_type): Remove the
	'update_depth_info' boolean from parameters.
	(handle_element_node): Renamed handle_element into this.  Take an
	xml node and a boolean to add the resulting IR node to the IR.
	(handle_type_decl, handle_namespace_decl)
	(handle_qualified_type_decl, handle_pointer_type_def)
	(handle_reference_type_def, handle_enum_type_decl)
	(handle_typedef_decl, handle_var_decl, handle_function_decl)
	(handle_class_decl, handle_function_tdecl, handle_class_tdecl):
	Take an xml node and a boolean to add the resulting IR node to the
	IR.
	(advance_cursor): No more need to call update_read_context.
	(read_translation_unit_from_input): Expand the 'abi-instr' node
	into memory so that we walk its XML nodes and build the IR nodes
	from them.
	(read_location): Remove the overload that was using the xml reader.
	():

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Dodji Seketeli
fa48bb97f9 Misc style fixes
* src/abg-reader.cc (read_context::{get_cur_decl, pop_decl}): Return
	decl_base_sptr rather than shared_ptr<decl_base>.
	(read_context::push_decl): Take a decl_base_sptr rather than
	shared_ptr<decl_base>.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Dodji Seketeli
1b0f6b489a Fix apidoc markup
* include/abg-comparison.h (class var_diff): @ref var_decls ->
	@ref var_decl.
	* src/abg-comparison.cc (function_decl_diff::first_function_decl):
	@Return -> @return.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-17 15:44:24 +01:00
Jonathan Wakely
22f6a640e7 Fix checkout & build instructions
* CONTRIBUTING: Fix Git repository url.
	* doc/website/mainpage.txt: Add elfutils into the dependencies
	list and fix the repository directory name.  Also use autoreconf
	-i.
	* include/abg-fwd.h: Fix Git repository URL.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-14 15:39:34 +01:00
Dodji Seketeli
3045c0aef2 Tweak dwarf reading test to detect more namespace linking-fu
* tests/data/test-read-dwarf/test0.cc: Define a member function
	out-of-line, outside of its namespace.
	* tests/data/test-read-dwarf/test0.abi: Update the .abi file.
	* tests/data/test-read-dwarf/test0: Update the resulting binary.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:20 +01:00
Dodji Seketeli
4051922cbf Add asserts to detect type id mis-management in native format
* read_translation_unit_from_input
	(read_translation_unit_from_input): Abort when an element could
	not be handled.
	(build_function_parameter, build_type_decl, qualified_type_def)
	(build_pointer_type_def, build_reference_type_def)
	(build_enum_type_decl, build_typedef_decl, build_class_decl)
	(build_type_tparameter, build_template_tparameter)
	(handle_qualified_type_decl, handle_pointer_type_def)
	(handle_reference_type_def, handle_typedef_decl):
	Abort when a referred-to type is not found or if a type is defined twice.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:20 +01:00
Dodji Seketeli
69380c1aa0 Misc style fixes
* src/abg-hash.cc
	(class_decl::member_function_template:#️⃣:operator()): Remove
	useless vertical space.
	* src/abg-ir.cc (class_decl::class_decl): Properly indent.
	* src/abg-writer.cc (fn_tmpl_shared_ptr_map)
	(class_tmpl_shared_ptr_map): Properly indent these typedefs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:20 +01:00
Dodji Seketeli
1377f9fb48 Optimize comparison & underlying type accessing
* include/abg-ir.h (qualified_type::get_underlying_type)
	(pointer_type_def::get_pointed_to_type)
	(reference_type_def::get_pointed_to_type)
	(typedef_decl::get_underlying_type): Avoid triggering refcount
	counter increasing/decreasing here, by returning a reference to
	the underlying type.  This showed up high on a profile.
	({scope_decl, type_decl, scope_type_decl, namespace_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	enum_type_decl, typedef_decl, var_decl, class_decl}::operator==):
	Avoid taking the exception-using path of dynamic_cast.  This
	showed up very high on a profile.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:20 +01:00
Dodji Seketeli
d3e1c98f83 Fix reading/writing native xml corpus files
* src/abg-reader.cc (read_context::clear_type_map): New member
	function.
	(read_translation_unit_from_input): Read up to the next element
	node if we are not on an element node already.  Clear the type
	map.  Realize that we might be on the next 'abi-instr' node upon
	completion.
	(read_corpus_from_input): Read up to the next element node if we
	are not on an element node already.  It must be an "abi-corpus"
	node.  THen Advance to the next 'abi-instr' element node before
	handing it to read_translation_unit_from_input.
	* src/abg-writer.cc (write_context::clear_type_id_map): New member
	function.
	(write_translation_unit): Call it.
	* tools/abg-tools-utils.cc (guess_file_type): Read enough bytes to
	detect abi-corpus files magic bytes.
	* tools/bilint.cc (main): Do not write the corpus file to the
	output stream if --noout has been provided.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:20 +01:00
Dodji Seketeli
c4991c6444 Escape xml pre-defined entities in native (de-)serialization.
* include/abg-libxml-utils.h (escape_xml_string)
	(unescape_xml_string): Declare new functions.
	* src/abg-libxml-utils.cc (escape_xml_string)
	(unescape_xml_string): Define them.
	* src/abg-reader.cc (build_function_decl, build_var_decl)
	(build_type_decl, build_enum_type_decl, build_class_decl)
	(build_type_tparameter, build_non_type_tparameter)
	(build_template_tparameter, handle_namespace_decl)
	(handle_typedef_decl): Use unescape_xml_string.
	* src/abg-writer.cc (write_type_decl, write_function_decl)
	(write_class_decl, write_type_tparameter)
	(write_non_type_tparameter, write_template_tparameter): Use
	escape_xml_string.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:19 +01:00
Dodji Seketeli
5f97fc781c Implement hash caching
* include/abg-ir.h (decl_base::hash_): New member.
	(decl_base::{g,s}et_hash): New accessors.
	(type_base_::cached_hash): Forward-declare new hasher.
	(struct type_ptr_equal): New equality predicate.
	(type_shared_ptr_equal::operator()): Do not forget to test pointer
	equality.
	(type_base::cached_hash): Declare new hasher.
	* src/abg-hash.cc ({decl_base, type_decl, scope_type_decl,
	qualified_type_def, pointer_type_def, reference_type_def,
	enum_type_decl, typedef_decl, var_decl, function_decl,
	function_decl::parameter, class_decl::data_member,
	class_decl::member_function, class_decl, }:#️⃣:operator()):
	Implement caching.
	(type_base::cached_hash::operator()(const type_base*)): Define.
	(type_base::cached_hash::operator() (const type_base_sptr):
	Define.
	* src/abg-ir.cc (type_ptr_map): Make this map use
	type_base::cached_hash instead of type_base::ptr_hash now.
	(decl_base::decl_base): Initialize the new
	decl_base::hash_. member.
	(decl_base::{s,g}et_hash): Define.
	(decl_base::operator==(const decl_base& other)): Take the hash in
	account to speed up inequality detection.
	* src/abg-writer.cc (type_ptr_map): Renamed type_shared_ptr_map
	into this.  Make it use type_base::cached_hash and type_ptr_equal
	instead of type_base::shared_ptr_hash and type_shared_ptr_equal.
	(get_id_for_type): Add overload for type_base*.  Re-write the
	previous overload in terms of this one.
	(write_context::m_type_id_map): Use type_ptr_map as the type for
	this.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:19 +01:00
Dodji Seketeli
e66393d057 Do not canonicalize types anymore; it's slow and luckily not needed
* src/abg-ir.h (translation_unit::canonicalize_type): Remove.
	* src/abg-dwarf-reader.cc (canonicalize_and_add_type_to_ir)
	(canonicalize_and_insert_type_into_ir)
	(canonicalize_and_insert_type_into_ir_under_scope): Remove.
	(build_enum_type, build_class_type, build_ir_node_from_die):
	Update for removal of type canonicalization.
	* src/abg-ir.cc (translation_unit::canonicalize_type): Remove.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:19 +01:00
Dodji Seketeli
f42a59c3dd Fix class scope setting & member type de-serializing from dwarf
* include/abg-fwd.h (add_decl_to_scope, insert_decl_into_scope):
	return the decl added to the scope.
	(as_non_member_type, get_type_declaration): Declare new entry
	points.
	* include/abg-ir.h (class decl_base::insert_decl_into_scope):
	Update this friend declaration.
	(class scope_decl, class_decl): Update the friend add_decl_to_scope
	declaration.
	(scope_decl::add_member_decl): Return the added decl.
	(class_decl_sptr): Move this typedef befoer the class_decl class
	declaration.
	(class_decl::definition_of_declaration_): New member.
	(class_decl::{set_definition_of_declaration,
	get_definition_of_declaration}): New accessors.
	(class_decl::add_member_decl): Return the added member.
	(class_decl::insert_member_type): New member.
	(class_decl::member_base::access_specifier): Make this protected.
	(class_decl::member_type): Make this inherit from type_vase.
	(class_decl::member_type::type_): Remove this member.
	(class_decl::member_type::as_type): Remove this accessor.
	(class_decl::member_type::operator==(const type_base&)): New.
	(class_decl::member_type::operator shared_ptr<type_base>() const):
	Remove.
	(class_decl::member_type::get_underlying_type): New.
	(class_decl::member_type::operator==(const member_type&) const):
	New.
	* src/abg-comparison.cc
	(class_diff::{ensure_lookup_tables_populated, report}): Adjust for
	the removal of class_decl::member_type::as_type.
	* src/abg-dwarf-reader.cc (scope_stack_type): Change this as a
	typedef to stack<scope_decl*>.
	(current_scope): Change return type from scope_decl_sptr to
	scope_decl*.
	(insert_decl_into_scope): New.
	(build_namespace_decl_and_add_to_ir): Use insert_decl_into_scope
	in lieu of add_decl_to_scope.
	(build_class_type_and_add_to_ir): likewise.  Link a class
	definition to its declaration.  Push the current scope on the
	scope stack.  Use as_non_member_type.  Fix setting member types.
	(get_scope_for_die): Look through declaration-only classe to get
	its definition.
	(build_qualified_type, build_pointer_type_def)
	(build_reference_type, build_typedef_type, build_var_decl)
	(build_function_decl): Use as_non_member_type.
	(build_ir_node_from_die): Fix member variable & function adding.
	* src/abg-ir.cc (scope_decl::{add_member_decl,
	insert_member_decl}): Return the added member.
	(add_decl_to_scope): Likewise.
	(insert_decl_into_scope): Likewise.
	(get_top_most_scope_under): Fix logic.
	(get_type_declaration): New overload that return a decl_base*.
	(as_non_member_type): New definition.
	(class_decl::{get_definition_of_declaration,
	set_definition_of_declaration, insert_member_decl}): Likewise.
	(class_decl::add_member_decl): Re-write in terms of
	class::insert_member_decl.
	(class_decl::insert_member_type): New definition.
	(class_decl::add_member_type): Re-write in terms of
	class_decl::insert_member_type.
	(class_decl::remove_member_type): Update for the
	class_decl::member_type::as_type removal.
	(class_decl::{add_data_member, add_member_function,
	add_member_function_template, add_member_class_template}): Call
	scope_decl::add_member_decl.
	(class_decl::member_type::member_type): Update as the type now
	virtually inherits from type_base.
	(class_decl::member_type::{set,get}_access_specifier): New
	definitions.
	(class_decl::member_type::get_underlying_type): Likewise.
	(class_decl::member_type::set_scope): Update wrt
	class_decl::member_type::as_type -> get_underlying_type rename.
	(class_decl::member_type::operator==(const decl_base& other)):
	There is no more class_decl::member_type::as_type.
	(class_decl::member_type::operator==(const type_base& other)):
	New.
	(class_decl::member_type::get_pretty_representation): Update wrt
	class_decl::member_type::as_type -> get_underlying_type rename.
	* src/abg-reader.cc (build_class_decl): New that add
	add_member_decl adds even member types, no need to add it
	explicitly anymore.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-13 17:36:19 +01:00
Dodji Seketeli
8f9b8e76a0 Add regression tests for dwarf reading
* tests/test-read-dwarf.cc: New dwarf reading regression test.
	* tests/data/test-read-dwarf/test0: New test input.
	* data/test-read-dwarf/test0: Likewise.
	* data/test-read-dwarf/test0.abi: Likewise.
	* data/test-read-dwarf/test0.cc: Likewise.
	* data/test-read-dwarf/test1: Likewise.
	* data/test-read-dwarf/test1.abi: Likewise.
	* data/test-read-dwarf/test1.cc: Likewise.
	* tests/Makefile.am: Build the new tests/test-read-dwarf.cc file.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-07 15:51:52 +01:00
Dodji Seketeli
a2ea8852f8 Remove useless dependencies in tests/Makefile.am
* tests/Makefile.am: Remove useless *_DEPENDENCIES variables.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-07 15:33:42 +01:00
Dodji Seketeli
2c9fb3e70d Support new 'abi-corpus' native XML format (.abi)
* include/abg-reader.h (read_corpus_from_native_xml)
	(read_corpus_from_native_xml_file): Declare new entry points.
	* include/abg-writer.h (write_corpus_to_native_xml)
	(write_corpus_to_native_xml_file): Likewise.
	* src/abg-reader.cc (read_translation_unit_from_input): Renamed
	read_input into this.  Support new 'path' attribute for
	'abi-instr' XML element.
	(read_corpus_from_input): New static function.
	(read_translation_unit_from_file)
	(read_translation_unit_from_buffer)
	(read_translation_unit_from_istream): Update wrt read_input ->
	read_translation_unit_from_input.
	(read_corpus_from_native_xml, read_corpus_from_native_xml)
	(read_corpus_from_native_xml_file): Define new entry points.
	* src/abg-writer.cc (write_translation_unit): Write 'path'
	attribute into the 'abi-instr' xml element.
	(write_corpus_to_native_xml, write_corpus_to_native_xml_file):
	Define new entry points.
	* tools/abg-tools-utils.h (file_type::{FILE_TYPE_XML_CORPUS,
	FILE_TYPE_ZIP_CORPUS}): New enumerators.
	* tools/abg-tools-utils.cc (guess_file_type): Support detection of
	the new xml file format containing a document root 'abi-corpus'
	root element.
	* tools/bidiff.cc (main): Support diffing xml corpus-es and zip
	corpus-es.
	* tools/bidw.cc (main): Recognize elf files before reading them.
	* tools/bilint.cc (main): Support reading xml/zip corpus-es too.
	* tests/data/test-read-write/test[0-23].xml: Update 'path'
	attribute.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-07 14:12:26 +01:00
Dodji Seketeli
4ca76c4658 Misc style fixes
* include/abg-writer.h (write_translation_unit): Re-indent parms.
	* src/abg-writer.cc (write_translation_unit): Likewise.
	* test/test-read-write.cc (main): Fix white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-07 14:07:14 +01:00
Dodji Seketeli
aafb86f595 Fix global variables diff reporting in corpus-es
* src/abg-comparison.cc
	(corpus_diff::priv::ensure_lookup_tables_populated): Fix a wrong
	assert, resulting from a copy paste typo.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 17:38:13 +01:00
Dodji Seketeli
0d66442b8b Add support for global variables in corpus diffing
* include/abg-comparison.h (string_var_ptr_map, changed_var_ptr)
	(string_changed_var_ptr_map): New convenience typedefs.
	* src/abg-comparison.cc
	(corpus_diff::priv::{deleted_vars_,added_vars_,changed_vars_}):
	New members.
	(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables}):
	Update wrt the new variables related lookup tables.
	(corpus_diff::ensure_lookup_tables_populated): Update to populate
	variables related lookup tables.
	(corpus_diff::report): Update to display added/removed/changed
	variables.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 16:01:55 +01:00
Dodji Seketeli
a41b741118 Misc style fixlets
* include/abg-comparison.h (changed_function_ptr): Fix comment.
	* src/abg-comparison.cc (corpus_diff::report): Likewise.
	* src/abg-corpus.cc (corpus::is_empty): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-01-06 15:52:25 +01:00
Dodji Seketeli
fbb6b1bc73 Initial support for diffing ABI corpus files
* include/abg-comparison.h (string_function_ptr_map)
	(changed_function_ptr, string_changed_function_ptr_map)
	(corpus_diff_sptr): New convenience typedefs.
	(translation_unit_diff): Add comments.
	(class corpus_diff): New type.
	(compute_diff): New overload for corpus_diff.
	* include/abg-corpus.h (corpus::{functions, variables}): New
	typedefs.
	(corpus::{operator==, get_functions, get_variables}): New members.
	* include/abg-diff-utils.h (struct deep_ptr_eq_functor): New
	functor.
	* include/abg-ir.h (translation_unit::operator==): New member
	equality operator.
	* src/abg-comparison.cc (struct corpus_diff::priv): New private
	struct holding the private members of corpus_diff.
	(corpus_diff::priv::{lookup_tables_empty, clear_lookup_tables,
	ensure_lookup_tables_populated}): Define new private member functions.
	(corpus_diff::{corpus_diff, first_corpus, second_corpus,
	function_changes, variable_changes, length, report}): New public members.
	(struct noop_deleter): New struct.
	(compute_diff): New implementation for corpus_diff.
	* src/abg-corpus.cc (struct corpus::priv): Renamed corpus::impl
	into this.  Add new fns, vars and is_symbol_table_built data
	members.
	(corpus::priv::build_symbol_table): New member function.
	(class symtab_build_visitor_type): New visitor type to build the
	symbol table.
	(struct func_comp, struct var_comp): New comparison functors.
	(corpus::priv::build_symbol_table): Define new member function.
	(corpus::{corpus, add, get_translation_units, operator==,
	get_functions, get_variables}): Define new members.
	* src/abg-ir.cc (translation_unit::operator==): Define new member
	equality operator.
	(operator==(translation_unit_sptr l, translation_unit_sptr r)):
	Define new equality operator.
	* tools/abg-tools-utils.h (enum file_type): New enum.
	(guess_file_type): Declare new function.
	* tools/abg-tools-utils.cc (guess_file_type): define new function.
	* tools/bidiff.cc (main): Guess the type of the files given in
	input and support elf files reading and diffing.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 14:05:19 +01:00
Dodji Seketeli
dbc0225415 Generalize use of equality operator in core diff algorithms
* include/abg-diff-utils.h (struct default_eq_functor): New
	equality functor.
	(end_of_fr_d_path_in_k, end_of_frr_d_path_in_k_plus_delta): Add a
	new equality functor template parameter and document it.  Use it
	to compare the elements of the sequences given in argument.
	(compute_middle_snake, ses_len, compute_diff): Add a new equality
	functor template parameter and document it.  Adjust call to
	end_of_frr_d_path_in_k_plus_delta, end_of_fr_d_path_in_k and
	compute_middle_snake.
	(ses_len, compute_diff): Add a new overload that uses a
	default_eq_functor as comparison functor, to avoid breaking
	existing client code.
	* src/abg-diff-utils.cc (compute_middle_snake): Adjust the call to
	the compute_middle_snake.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:40:14 +01:00
Dodji Seketeli
165434a9d7 Change ir node visitor interface work on pointer to nodes
* include/abg-ir.h (ir_traversable_base): New type to be the base
	of IR nodes that are to be traversed.  Extends traversable_base.
	Its ir_traversable_base::traversable() method takes an
	ir_node_visitor&.
	(ir_node_visitor::visit): Change these virtual overloads to take
	pointers to IR nodes, rather than references.  This will be useful
	to e.g, store these IR nodes in containers on the side for some
	algorithms to work.  That is going to be useful later to,
	e.g. build symbol tables on the side, using the visitor interface.
	(class decl_base): Make this inherit ir_traversable_base.
	* src/abg-ir.cc (*::traverse): Adjust comments and the call the
	ir_node_visitor::visit call.  Use the ir_traversable_base type
	rather than traversable_base.
	(ir_traversable_base::traverse): Define.
	(ir_node_visitor::visit): Change these overloads to take pointers
	rather than reference to ir nodes.
	* tests/test-walker.cc (name_printing_visitor::visit): Adjust to
	take pointers rather than references.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 13:25:32 +01:00
Dodji Seketeli
f54bf5526b Do not forget to read function parms
* src/abg-dwarf-reader.cc (build_function_decl): Do not forget the
	the function parameters.  Oops.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-23 12:51:08 +01:00