Commit Graph

58 Commits

Author SHA1 Message Date
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
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
6d4015ec75 Support reading member functions and member types from DWARF
* include/abg-ir.h (method_type_sptr): New convenience typedef.
	* src/abg-dwarf-reader.cc (read_context::{dwarf_version,
	die_wip_classes_map}): New accessors.
	(die_is_virtual): Rename is_virtual into this.
	(is_type_tag, is_type_die, die_virtual_function_index): Define new
	static functions.
	(die_member_offset): Fix comment.
	(get_scope_for_die): Take the read context as argument.
	(canonicalize_and_add_type_to_ir): Likewise.  On NULL scope, get
	the current translation unit from the read context.
	(canonicalize_and_insert_type_into_ir_under_scope): Handle NULL
	context.
	(build_function_decl): Support creating method_decls from here
	when necessary.
	(build_class_type_and_add_to_ir): Rename build_class_type into
	this.  Handle adding the class to the IR and to the relevant maps.
	During the creation of the class, arrange for
	build_ir_node_from_die on the current DIE to return a
	declaration-only class, representing the declaration for the class
	that is being constructed.  This breaks circular dependencies
	induced by decls/types that refer to the class being built, before
	the class is fully built and has a (logical) type ID.  Once the
	class is created, make it refer to the class declaration that was
	previously handed for the requests to the class DIE.  Now requests
	to the class DIE will just yield the newly built class.  Add
	support for member functions and member types.
	(build_corpus): Support reading the dwarf version and stick it
	into the context.
	(build_ir_node_from_die): Adjust for change in
	canonicalize_and_add_type_to_ir and build_class_type signature
	change.
	* src/abg-ir.cc (class_decl::method_decl::get_type): Support
	returning NULL type.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:19:58 +01:00
Dodji Seketeli
f47b1ffd6d Make decl_base::set_scope virtual, to work on class_decl::member_type
* include/abg-ir.h (decl_base::set_scope): Make this virtual.
	(class_decl::member_type::set_scope): Declare an overload here.
	* src/abg-ir.cc (class_decl::member_type::set_scope): Define new
	overload.  Make this set the scope of the underlying type of the
	member type as well.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:14:21 +01:00
Dodji Seketeli
118a5df30d Support artificial parameters
* include/abg-ir.h (function_decl::parameter::{get,
	set}_artificial): Add new accessors for an "artificial" flag.
	* src/abg-reader.cc (build_function_parameter): Support reading
	the artificial parameter flag.
	* src/abg-writer.cc (write_function_decl): Support writing the
	artificial parameter flag.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-20 16:08:32 +01:00
Dodji Seketeli
5be46a9615 Build & use a DIE -> parent map to avoid emitting useless types
* include/abg-ir.h (translation_unit::{mark_type_as_used,
	prune_unused_types}): Remove these declarations.
	* src/abg-ir.cc (translation_unit::priv::used_types_): Remove.
	(class subtype_marking_visitor): Likewise.
	(translation_unit::{mark_type_as_used, prune_unused_types):
	Likewise.
	(get_top_most_scope_under): Fix logic and add comment.
	* src/abg-dwarf-reader.cc (die_tu_map_type, offset_offset_map):
	New convenience typedefs.
	(read_context::{die_tu_map_, die_parent_map_}): New context
	members.
	(read_context::{die_tu_map, die_parent_map}): New accessors.
	(build_ir_node_from_die): New overload that takes the scope of the
	ir node in parameter.
	(die_signed_constant_attribute): Un-comment this.
	(build_die_parent_relations_under, build_die_parent_map)
	(get_parent_die, get_scope_for_die): New static functions.
	(build_translation_unit_and_add_to_ir): Renamed
	build_translation_unit into this. Populate the new
	read_context::die_tu_map() here.
	(canonicalize_and_add_type_to_ir)
	(canonicalize_and_insert_type_into_ir)
	(canonicalize_and_insert_type_into_ir_under_scope): Move these
	overloads over the top of the file.
	(build_namespace_decl_and_add_to_ir): Fix this by adding the
	namespace to the IR scope of the DIE (using the new
	get_scope_for_die()).  Update the read_context::die_decl_map()
	map.
	(build_function_decl): Support functions that return void.  Also,
	skip parameters that don't have type set.
	(build_corpus): Walk all the DIEs to build a DIE -> parent map.
	Adjust for the rename to build_translation_unit_and_add_to_ir.
	(build_ir_node_from_die): Add a scope parm.  Adjust back to
	building IR nodes only for public decls, unless the
	'called_from_public_decl' flag is set.  Adjust to stick the resulting
	IR node into the scope given in parameter.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 22:15:16 +01:00
Dodji Seketeli
96597e61ab Add missing virtual keywords for traverse() method
* include/abg-ir.h ({translation_unit, decl_base, scope_decl,
	type_decl, namespace_decl, qualified_type_decl, pointer_type_def,
	reference_type_def, enum_type_decl, typedef_decl, var_decl,
	function_tdecl, class_decl, class_decl::data_member,
	class_decl::member_function, class_decl::member_function_template,
	class_decl::member_class_template}::traverse): Add a virtual
	keyword at least to "document" that this method is virtual -- and
	thus remind the user that it overrides the
	traversable_base::traverse().

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-14 11:00:47 +01:00
Dodji Seketeli
02b1b2a786 Prune types that are not ref'ed by public decls
* include/abg-fwd.h (remove_decl_from_scope): Declare new
	function.
	* include/abg-ir.h (type_base_sptr, decl_base_sptr): Move these
	convenience typedef before the translation_unit declaration.
	(translation_unit::{mark_type_as_used, prune_unused_types}):
	Declare new methods.
	(decl_base::remove_member_decl): Likewise.
	(class_decl::{remove_member_decl, remove_member_type): Likewise.
	* src/abg-dwarf-reader.cc (die_decl_map_type): Change this map
	type so that the value is now a DIE offset, rather than a DIE.
	This is because many times the lifetime of DIEs is shorter than
	the one of the reader_context.  Also, the die offset uniquely
	designates a physical DIE even if several different instances of
	logical DIE might point to it.
	(struct die_hash): Remove this as it's useless now that we store
	DIE offsets in the map.
	(build_translation_unit): Call build_ir_node_from_die w/o setting
	the called_from_public_decl flag.  Prune the types that are not
	used by any public decls.
	(build_namespace_decl_and_add_to_ir): all build_ir_node_from_die
	w/o setting the called_from_public_decl flag.
	(build_ir_node_from_die): Change the only_public_decl flag into a
	called_from_public_decl flag.  Mark types used by public decls as
	such.  Adjust for the parm changes of build_qualified_type
	build_pointer_type_def, build_reference_type, and
	build_typedef_type.
	(build_qualified_type, build_pointer_type_def)
	(build_reference_type, build_typedef_type): Take a new
	called_from_public_decl.  Pass it to build_ir_node_from_die.
	(build_var_decl): Call build_ir_node_from_die with the
	called_from_public_decl flag set to true to flag the types
	referenced by this variable as being used.
	(build_function_decl): Take a called_from_public_decl flag as
	well, as this function can now call build_function_decl itself to
	build a function decl out of the value of the DW_AT_specification
	attribute, for DIEs representing function definitions.  Also, flag
	the types referenced by public functions are being used.
	* src/abg-ir.cc (translation_unit::priv::used_types_): New map for
	the used types.
	(translation_unit::{mark_type_as_used, prune_unused_types}):
	Define new methods.
	(scope_decl::remove_member_decl): Likewise.
	(remove_decl_from_scope): Define new function.
	(class_decl::{remove_member_decl, remove_member_type}): Define new
	methods.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-13 18:11:46 +01:00
Dodji Seketeli
643b02fd6a Support reading namespaces
* include/abg-fwd.h (get_global_scope): Return a const
	global_scope.  Add a new overload that takes a naked pointer as
	parm.
	(insert_decl_into_scope, get_top_most_scope_under): Declare new
	entry points.
	* include/abg-ir.h (class decl_base, class scope_decl): Add
	insert_decl_into_scope as a friend of these classes.
	(scope_decl::{insert_decl_into_scope, find_iterator_for_member}):
	Declare new member.
	(scope_decl::get_member_decls): New non-const overload.
	* src/abg-dwarf-reader.cc (build_translation_unit): Remove the
	"recurse" parameter.  Adjust the call to build_ir_node_from_die to
	read just public decls that are at namespace scope.  Anything else
	should be dropped unless it's needed to emitting the public
	namespace-level decls.
	(build_namespace_decl_and_add_to_ir)
	(canonicalize_and_insert_type_into_ir): Define new static
	functions.
	(build_corpus): Adjust ad build_translation_unit doesn't have the
	"recurse" parameter anymore.
	(canonicalize_and_add_type_to_ir): Make this static.  Fix
	comments.
	(build_ir_node_from_die): Take a new "only_public_decl"
	parameter. For DW_TAG_base_type case, use the new
	canonicalize_and_insert_type_into_ir to insert the type at the
	right place in the global scope making sure it is seen before the
	current scope.  For pointer, references and qualified types, use
	canonicalize_and_insert_type_into_ir to add the type at the same
	scope as its underlying type.  Handle DW_TAG_{namespace,module}
	using the new build_namespace_decl_and_add_to_ir function.  Add
	some vertical spaces and some assertions.
	* src/abg-ir.cc (scope_decl::add_member_decl): Use scope_decl_sptr
	typedef.
	(scope_decl::{insert_member_decl,find_iterator_for_member}):
	Define new methods.
	(insert_decl_into_scope, get_top_most_scope_under): Define new
	functions.
	(get_global_scope): Constify the return type.
	(get_translation_unit): Adjust as get_global_scope now returns a
	const.
	* src/abg-reader.cc (get_translation_unit): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:40:52 +01:00
Dodji Seketeli
f918fdb0f9 Fix function_decl::parameter::operator==
* include/abg-ir.h (function_decl::parameter::operator==): Support
	empty type, e.g, in presence of a variadic parameter.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:36:17 +01:00
Dodji Seketeli
faa9ae485c Misc style fixes
* include/abg-ir.h (decl_base::set_visibility): Remove useless
	white space.
	(class scope_decl): Remove useless white space.
	(scope_decl::add_member_decl): Use decl_base_sptr convenience
	typedef.
	(global_scope_sptr, namespace_decl_sptr): New convenience typedef.
	(class global_scope): Remove useless white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-12 15:35:09 +01:00
Dodji Seketeli
d3929eaf23 Support the "address-size" attribute for <abi-instr> elements
* include/abg-ir.h (translation_unit::translation_unit): Take an
	address_size parameter.
	(translation_unit::{get_address_size, set_address_size}): New
	accessors.
	* src/abg-ir.cc (translation_unit::priv::address_size_): New
	private member.
	(translation_unit::translation_unit): Take an address_size
	parameter.
	(translation_unit::{get_address_size, set_address_size}): Define
	these new methods.
	* src/abg-reader.cc (read_input): Read the "address-size"
	attribute from the abi-instr element.
	* src/abg-writer.cc (write_translation_unit): Write the
	"address-size" attribute.
	* tests/data/test-read-write/test23.xml: New test input.
	* tests/test-read-write.cc (in_out_specs): Add the new test above
	to the list of files to read and write back.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 12:30:19 +01:00
Dodji Seketeli
bd1af4cd52 Initial support of reading an ABI Corpus from DWARF
* configure.ac: Check the presence of libdw.so and
	elfutils/libdwfl.h headers from elfutils and define the necessary
	linking flags.
	* include/abg-dwarf-reader.h: New header file
	* include/Makefile.am: Add the new header file to the source
	distribution.
	* src/abg-dwarf-reader.cc:: New file.
	* src/Makefile.am: Add the new file to the source distribution.
	* include/abg-fwd.h (dump): Add declarations for several overloads
	to allow dumping to a given output stream.
	* include/abg-ir.h (class translation_unit): Use a pimpl idiom for
	this now.
	(translation_unit::canonicalize_type): Declare new method.
	* src/abg-ir.cc (struct translation_unit::priv): New private type
	for the pimpl idiom for translation_unit.
	(translation_unit::{translation_unit, get_global_scope, get_path,
	set_path, get_loc_mgr}): Adjust for pimpl idiom.
	(translation_unit::canonicalize_type): Define this new method and
	one overload.
	* src/abg-writer.cc (dump): Define several overloads to dump IR
	nodes to given output streams.
	* tools/bidw.cc: New file for the new bidw tool.
	* tools/Makefile.am: Define rules to build the new bidw tools.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-07 08:07:54 +01:00
Dodji Seketeli
6258b5f824 Prepare serialization API for multiple backends
* include/abg-reader.h: New file with abigail::xml_reader APIs.
	* include/abg-writer.h: New file with abigail::xml_writer APIs.
	* include/Makefile.am: Add the new files above to the source
	distribution.
	* src/abg-reader.cc: Update top-file comments.
	(namespace xml_reader): Rename namespace
	reader into this.
	(read_to_translation_unit, read_corpus_from_archive): New static
	functions.
	(read_translation_unit_from_file)
	(read_translation_unit_from_file, read_corpus_from_file): New
	entry points.
	(struct array_deleter): New functor.
	(translation_unit::read): Remove this.
	* src/abg-writer.cc: Update top file comments.
	(namespace xml_writer): Rename namespace
	writer into this.
	(struct archive_write_ctxt): New internal type.
	(create_archive_write_context, write_translation_unit_to_archive)
	(write_translation_unit, write_corpus_to_archive): New low level
	static functions overloads.
	(write_corpus_to_archive, write_translation_unit): Public higher
	level overloads.
	(translation_unit::write): Remove.
	(dump): Update for new xml_writer namespace.
	* include/abg-ir.h (translation_unit::{read, write}): Remove these
	serialization methods.
	* include/abg-corpus.h (corpus_sptr): New convenience typedef.
	(corpus::{read, write}): Remove these methods.
	* src/abg-corpus.cc (corpus::{read, write})
	(corpus::impl::{serialized_tus, archive}): Remove these members.
	(corpus::impl::{get_archive, close_archive, write_tu_to_archive,
	read_to_translation_unit}): Remove these methods.
	* tests/test-bidiff.cc (main): Update for usage of the new
	xml_reader API.
	* tests/test-read-write.cc (main): Likewise. Update for the usage
	of the new xml_writer API, too.
	* tests/test-walker.cc (main): Update for the usage of the new
	xml_reader API.
	* tests/test-write-read-archive.cc (main): Likewise.  And for the
	xml_writer API, too.
	* tools/biar.cc (add_tus_to_archive, extract_tus_from_archive): Likewise.
	* tools/bidiff.cc (main): Likewise, for xml_reader APIs.
	* tools/bilint.cc (main): Likewise, for xml_writer APIs, too.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-04 20:26:38 +01:00
Dodji Seketeli
0b0dd479d1 Add enum_type_decl::get_pretty_representation()
* include/abg-ir.h (enum_type_decl::get_pretty_representation):
	Declare new virtual method override.
	* src/abg-ir.cc (enum_type_decl::get_pretty_representation):
	Define it.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-28 14:58:11 +01:00
Dodji Seketeli
d186189b43 Support diff for enum_type_decl
* include/abg-ir.h (enum_type_decl_sptr): New typedef.
	(enum_type_decl::enumerator::enumerator): Make default constructor
	public so that enumerators can be stored in vectors.  Maybe I
	should have made stored pointers to enumerators instead ...
	(enum_type_decl::enumerator::get_qualified_name): Define new
	method.
	* include/abg-comparison.h (string_enumerator_map)
	(changed_enumerator, string_changed_enumerator_map)
	(enum_diff_sptr): New convenience typedefs.
	(class enum_diff): Declare new class.
	(compute_diff): New overload for enum_type_decl.
	* src/abg-comparison.cc (enum diff_kind, report_mem_header): Move
	these at the beginning of the file.
	(struct enum_diff::priv): Define this.
	(enum_diff::{clear_lookup_tables, lookup_tables_empty,
	ensure_lookup_tables_populated, enum_diff, first_enum,
	second_enum, underlying_type_diff, deleted_enumerators,
	inserted_enumerators, changed_enumerators, length, report}):
	Define these new methods.
	(compute_diff): New overload for enum_diff.
	(compute_diff_for_types): Add support enum_type_decl here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-27 11:47:19 +01:00
Dodji Seketeli
abfc86ca6a Change enum_type_decl::enumerators from a list to a vector
* include/abg-ir.h (enum_type_decl::enumerators): Change this from
	a list to a vector.
	* src/abg-hash.cc (enum_type_decl:#️⃣:operator()): Use the
	typedef enum_type_decl::enumerators rather than std::list<blah>.
	* src/abg-ir.cc (enum_type_decl::get_enumerators): Use
	the enum_type_decl::enumerators typedef.
	(enum_type_decl::operator==): Likewise.
	* src/abg-reader.cc (build_enum_type_decl): Likewise.
	* src/abg-writer.cc (write_enum_type_decl): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-26 09:30:22 +01:00
Dodji Seketeli
5ac1090324 Support diff between qualified types
* include/abg-ir.h (qualified_type_def_sptr): Declare new typedef.
	(class qualified_type_def): Add comment at the end.
	(operator<<(std::ostream&, qualified_type_def::CV)): Declare new
	streaming operator.
	* src/abg-ir.cc (operator<<(std::ostream&,
	qualified_type_def::CV)): Define this new streaming operator.
	* include/abg-comparison.h (class qualified_type): Declare new
	class.
	(compute_diff): Declare new overload for qualified_type_def_sptr.
	* src/abg-comparison.cc (struct qualified_type_diff::priv): Define
	new type.
	(qualified_type_diff::{qualified_type_diff, first_qualified_type,
	second_qualified_type, underlying_type_diff, length}):
	Define new methods.
	(get_leaf_type): Define new static function.
	(compute_diff): Define overload for qualified_type_def_sptr.
	(compute_diff_for_types): Add support for
	diffing qualified_type_def here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-25 23:25:13 +01:00
Dodji Seketeli
d0de718c14 Misc diff reporting nits
* include/abg-ir.h (type_decl::get_pretty_representation): New
	overload.
	* abg-ir.cc (type_decl::get_pretty_representation): Implement it.
	* src/abg-comparison.cc (represent, class_diff::report): Quote the
	pretty representation of abi artifacts in the report.
	(type_decl_diff::report): Better wording to express type_decl
	change.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-21 15:41:39 +01:00
Dodji Seketeli
663c455521 Support reporting changed data member in class
* include/abg-ir.h (operator<<(std::ostream&, decl_base::binding))
	(operator<<(std::ostream&, class_decl::access_specifier)): Declare
	new streaming operators.
	(class_decl::member_type::get_pretty_representation): New virtual
	overload.
	* src/abg-ir.cc (operator<<(std::ostream&, decl_base::binding)):
	(operator<<(std::ostream&, class_decl::access_specifier)): Define
	new streaming operators.
	(class_decl::member_type::get_pretty_representation): Define new method.
	* src/abg-comparison.cc (represent): Make the existing overloads
	end by a newline. Add a new overload that represents the changes
	that happened a given data member.
	(enum diff_kind): New.
	(report_mem_header): Renamed report_num_dels_or_ins into this.
	Make it support introducing changed members as well as
	deletions/insertions.
	(class_diff::report): Adjust for the report_num_dels_or_ins ->
	report_mem_header change.  Use the new represent() overload to
	report about changed data members.  Adjust logic now that
	represent() emits a newline at its end.  Also adjust logic as far
	as representing base classes and member types changes is
	concerned.
	(type_decl_diff::report): Remove useless white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-20 19:27:36 +01:00
Dodji Seketeli
e78cf50a39 Various doxygen doc additions and fixes
* include/abg-comparison.h: Lots of doc string additions & fixes,
	especially for typedefs.
	* include/abg-ir.h: Likewise.
	* src/abg-comparison.cc: Likewise.
	* src/abg-ir.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-20 10:54:15 +01:00
Dodji Seketeli
1cdc283b1d Add diff support for typedef_decl and type_decl
* include/abg-ir.h (operator<<(std::ostream&,
	decl_base::visibility)): Declare new streaming operator.
	* src/abg-ir.cc (operator<<(std::ostream&,
	decl_base::visibility)): Define it.
	(type_decl::{operator==, get_pretty_representation}): Likewise,
	define these new overloads.
	(decl_base::{operator==, get_pretty_representation}): New overloads.
	* include/abg-comparison.h (type_decl_diff type_decl_diff_sptr,
	typedef_diff, typedef_diff_sptr): Declare new classes and
	typedefs.
	* src/abg-comparison.cc (type_decl_diff::{type_decl_diff,
	first_type_decl, second_type_decl, length, report}): New methods
	definitions.
	(compute_diff): New function definition that takes pointers of
	type_decl.
	(typedef_diff::{typedef_diff, first_typedef_decl,
	second_typedef_decl, underlying_type_diff, length, report}): New
	methods.
	(compute_diff): New function definition that takes pointers of
	typedef_decl.
	(try_to_diff_types): New template function, factorized out of ...
	(compute_diff_for_types): ... this.  Add support diffing type_decl
	and typedef_decl.
	(pointer_diff::report): Fix indentation of emitted report.
	* tools/bidiff.cc (parse_command_line): Fix style.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:28:00 +01:00
Dodji Seketeli
a03d9c0e64 Avoid missing member types while reading bi files
* include/abg-fwd.h (get_type_declaration): Declare function.
	* include/abg-ir.h (class decl_base): Add class_decl as a friend.
	This to be able to call decl_base::set_scope from class_decl.
	(scope_decl::add_member_decl): Make this virtual protected, so
	that it can be called (virtually) from e.g, class_decl.
	(type_decl_sptr, typedef_decl_sptr): New convenience typedefs.
	(class_decl::add_member_decl): New virtual overload for
	scope_decl::add_member_decl.
	(class_decl::{add_member_type, add_data_member,
	add_member_function}): New overloads.
	* src/abg-ir.cc (add_decl_to_scope): Benign style cleanup.
	(get_type_declaration): Define new function.
	(class_decl::add_member_decl): New method.
	(class_decl::add_member_type): Avoid silently added a new member
	type when that member type has already been (perhaps
	inadvertently) added to a scope already.  Rather, put a strict
	assert in place there.  Also add a new overload that constructs
	the member type out of a classic type and adds it to the class.
	(class_decl::{add_data_member, add_member_function}): Likewise.
	(class_decl::{add_member_function_template,
	add_member_class_template}): Avoid silently added a new member
	template when that template has already been (perhaps
	inadvertently) added to a scope already.  Rather, put a strict
	assert in place there.
	* src/abg-reader.cc (push_decl_to_current_scope): Take a an extra
	flag saying if the current decl should be added to the current
	scope as well (in addition to being pushed onto the stack of
	scopes maintained in the reader context).
	(push_and_key_type_decl): Likewise, take that extra flag and pass
	it to push_decl_to_current_scope.
	(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_typedef_decl)
	(build_function_tdecl, build_class_tdecl): Likewise.
	(build_class_decl): Likewise.  When building member data, types,
	and functions, make sure /not/ to add the data, type of function to
	the current scope before adding it to the class_decl.  This was
	making the member not being added to the class because it already
	had a scope.
	(build_type_tparameter, build_type_composition)
	(build_non_type_tparameter, build_template_tparameter)
	(build_type): Adjust to add the template parm to the current scope
	explicitly, like previously.
	(handle_type_decl): Use build_type_decl function. Add the
	type_decl to the current scope, like previously.
	(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): Adjust to add the decl to the current scope,
	like previously.
	* tests/data/test-read-write/test21.xml: New test input with
	member type(def).

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:27:49 +01:00
Dodji Seketeli
e34a610c2e Avoid tabs and add const/virtual/offsets to class member diff reports
* include/abg-ir.h (class_decl::get_num_virtual_functions): New
	declaration.
	* src/abg-ir.cc (class_decl::get_num_virtual_functions): New
	definition.
	(function_decl::get_pretty_representation): Represent
	destructors and const member functions.
	* src/abg-writer.cc (write_cdtor_const_static): Take a new bool
	parm for constness and serialize it.
	(write_class_decl): Serialize member functions & function template
	const-ness.
	* src/abg-reader.cc (read_cdtor_const): Read the "const" xml
	attribute, rather than "is_const".

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:27:44 +01:00
Dodji Seketeli
2095a79319 Serialize vtable offset for virtual functions
* include/abg-ir.h
	(class_decl::member_function::get_vtable_offset): Renamed
	class_decl::member_function::get_vtable_offset_in_bits into this.
	The offset is an index into a table; it's not a value in bits.
	* src/abg-hash.cc (class_decl::member_function::hash): Update wrt
	function name change above.
	* src/abg-ir.cc (class_decl::member_function::operator==):
	Likewise.
	* src/abg-reader.cc (build_class_decl): Rename the attribute
	vtable-offset-in-bits into vtable-offset.
	* src/abg-writer.cc (write_voffset): New function.
	(write_class_decl): Use the new write_voffset.  Cleanup.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:27:32 +01:00
Dodji Seketeli
d506105c68 White space and style fixes
* include/abg-ir.h (class_decl::member_function::member_function):
	Align function parameters.
	* src/abg-ir.cc (type_decl::operator==): Remove useless white spaces

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:27:27 +01:00
Dodji Seketeli
8ac9973a1e Pretty representation for variables and types by default
* include/abg-ir.h (var_decl::get_pretty_representation): New
	method declaration.
	* src/abg-ir.cc (decl_base::get_pretty_representation): Prefix
	types with the "type " string.
	(var_decl::get_pretty_representation): New method definition.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:26:24 +01:00
Dodji Seketeli
259b46d88d Support diff/reporting for functions & better diff/report in general
* include/abg-ir.h ({decl_base, class_decl,
	function_decl}::get_pretty_representation): New virtual member to
	get a pretty string name for decls & types.
	(class_decl::parameter): Add an index to the parameter type.
	(class_decl::parameter::parameter): Update the constructor for the
	change above.
	(class_decl::parameter::{get_index, set_index}): Accessors for the
	new index.
	(class_decl::parameter::operator==): Take in account the index.
	(function_type::append_parameter): Set the index of the parameter
	here.
	* include/abg-fwd.h (get_type_name): New declaration.
	* src/abg-ir.cc (get_type_name): New definition.
	({decl_base, function_decl,
	class_decl}::get_pretty_representation): New implementations.
	(method_type::set_class_type): Update this to set function
	parameter's index by default.
	(function_decl::append_parameters): Use the append_parameter
	method from function_type.
	* include/abg-comparison.h (class function_decl_diff): New type
	declaration.
	* src/abg-comparison.cc (compute_diff_for_decls, compute_diff):
	New definitions.
	({pointer_diff, class_diff, scope_diff}::report): Use the new
	get_pretty_representation.  Output a prettier report.
	(function_decl_diff::priv): New type.
	(function_decl_diff::{deleted_parameter_at, inserted_parameter_at,
	ensure_lookup_tables_populated, function_decl_diff,
	first_function_decl, second_function_decl, changed_parms,
	removed_parms, added_parms, length, report}): New member function
	definitions.
	* src/abg-hash.cc (function_decl::parameter::hash): Update this to
	take the index in account.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:25:39 +01:00
Dodji Seketeli
059bb2fbfd Misc style & white space fixes
* include/abg-fwd.h (is_global_scope, is_at_global_scope)
	(is_at_class_scope, is_at_template_scope, is_template_parameter)
	(is_type, is_var_decl, is_template_parm_composition_type)
	(is_template_decl, is_function_template_pattern)
	(add_decl_to_scope, get_global_scope, get_translation_unit):
	Remove parameter names from declarations.
	* include/abg-ir.h (decl_base::set_location): Remove useless white
	space.
	(struct type_shared_ptr_equal): Fix comment filling.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:25:36 +01:00
Dodji Seketeli
b03f170d91 Add more IR nodes dumping routines
* include/abg-fwd.h (dump): Declare 4 overloads for the dumping
	routines.
	* include/abg-ir.h (var_decl_sptr): New typedef.
	* src/abg-writer.cc (dump(const decl_base_sptr)): Add comments.
	(dump(const type_base_sptr)): New dumping routines.
	(dump(const var_decl_sptr)): Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:25:21 +01:00
Dodji Seketeli
ee2d8c9196 Fix IR node comparison bugs
* include/abg-ir.h (type_shared_ptr_equal::operator()): Fix thinko
	in checking for the boolean value of the pointers to types.
	* src/abg-ir.cc (type_decl::operator==(const decl_base&)): Do not
	forget to compare the decl_base part of the type too.
	(type_decl::operator==(const type_base&)): To ease maintenance,
	re-use the equality operator that takes a decl_base.
	(scope_type_decl::operator==(const type_base&)): Likewise.
	(qualified_type_def::operator==(const type_base&)): Likewise.
	(compare_function_types): New sub-routine to compare function
	types.  It fixes an infinite recursion when comparing two methods
	of the same class.
	(function_type::operator==(const type_base&)): Use the new
	compare_function_types function.
	(class_decl::operator==(const decl_base&)): Fix a thinko in the
	first test of the function.  Use a dedicated scope for each class
	section comparison; that way, there won't be any chance to misuse
	the variables pertaining to a different section.  Fix the member
	function sections; we were mistakenly using the variables for the
	*data* section there.
	(class_decl::operator==(const type_base&)): Re-use the operator
	that takes a decl_base.
	(class_decl::operator==(const class_decl&)): Don't remove
	const-ness during the static cast.
	(class_decl::member_function::operator==(const member_function&)):
	Do not remove the reference from the static cast.
	(class_decl::member_class_template::operator==(const
	member_base&)): Likewise.
	(type_tparameter::operator==(const template_parameter&)):
	Likewise.
	(template_tparameter::operator==(const template_parameter&)):
	Likewise.
	(function_tdecl::operator==(const template_decl&)): Likewise.
	(class_tdecl::operator==(const template_decl&)): Likewise.
	(class_tdecl::operator==(const class_tdecl&)): Likewise.
	* tests/data/test-read-write/test12.xml: Update this because the
	test now correctly considers two type template parameters at the
	same index as being equivalent.
	* tests/data/test-read-write/test13.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:25:09 +01:00
Dodji Seketeli
ad0a293672 On going white space cleanups
* include/abg-ir.h: Remove useless white spaces.
	* src/abg-ir.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:25:03 +01:00
Dodji Seketeli
1a647b4321 White space cleanup in abg-ir.h
* include/abg-ir.h
	(class_decl::member_function_template::member_function_template):
	Remove useless white space.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:24:51 +01:00
Dodji Seketeli
e480399ce0 Fix construction of class_decl::member_type
* include/abg-ir.h (class_decl::member_type::member_type): Remove
	inline body from here.
	* src/abg-ir.cc (class_decl::member_type::member_type): Move
	implementation here.  Also, properly set the name of the the
	member_type at construction time.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:24:25 +01:00
Dodji Seketeli
8b3a227ba6 Few typedef additions to abg-ir.h
* include/abg-ir.h (pointer_type_def_sptr)
	(reference_type_def_sptr): New typedefs.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:24:20 +01:00
Dodji Seketeli
a21e0a3442 Fix inheritance of operator== on decl_base and type_base
* include/abg-ir.h (*lots of descendants of decl_base, type_decl)
	(template_decl, class_decl::member_base): Replace the previous classical
	*::operator==(*&) with an overload of decl_base::operator==(const
	decl_base&), type_base::operator==(const type_base),
	template_decl::operator==(const template_decl&) or
	class_decl::member_base::operator==(const
	class_decl::member_base&).  This makes the descendant operator be
	the one called when a comparison involves references the parent
	class.
	* src/abg-ir.cc: Write the implementation of the above.  Remove
	the useless static_casts from the previous operator== code.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:23:50 +01:00
Dodji Seketeli
5f2b66d22e On going misc white spaces and style fixes
* include/abg-ir.h: Add author.  Remove many useless white
	spaces.  Add missing end-of-class comments.  Move function
	declaration comments from here to their definition point.
	* include/abg-fwd.h: Remove useless indentation.  Also move
	doxygen comments to *definition* points in src/abg-ir.cc.
	* src/abg-ir.cc: Remove many useless white spaces.  Move comments
	from declaration points to here.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:23:12 +01:00
Dodji Seketeli
6e590b2a45 Initial un-debugged implementation of scope diffing
* include/abg-comparison.h (class scope_diff): New type.
	(compute_diff(scope_decl_sptr, scope_decl_sptr, scope_diff)): New
	declaration.
	(report_changes): New declaration.
	* src/abg-comparison.cc (struct scope_diff::priv): Define.
	(scope_diff::{clear_lookup_tables, lookup_tables_empty,
	ensure_lookup_tables_populated, scope_diff, member_changes,
	deleted_member_at, inserted_member_at, changed_types,
	changed_decls}): Define these new member functions.
	(compute_diff): Define.
	* include/abg-ir.h (decl_base_sptr): New typedef.
	(operator==(decl_base_sptr, decl_base_sptr)): Declare new
	operator.
	* src/abg-ir.cc (operator==(decl_base_sptr, decl_base_sptr)):
	Define.
	(scope_decl::{operator==, traverse}): Adjust for using vectors to
	store scope members now, rather than lists.
	(scope_decl::{declarations, scopes}): Make these types be vector.
	This makes the members of a scopes be vector, rather than lists.
	This enables them to be diffed.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:22:45 +01:00
Dodji Seketeli
63587eca30 Misc white space, style and comments cleanup
* include/abg-ir.h (class scope_decl): Add end of class comment.
	(class type_base): Add a _sptr typedef and end of class comment.
	* src/abg-ir.cc (operator==(class_decl_sptr, class_decl_sptr)):
	Fix comment.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:21:53 +01:00
Dodji Seketeli
eb6339835f Un-debugged initial implementation of class diffing.
* include/abg-ir.h (decl_base::get_qualified_name): New
	declaration.
	(class_decl::{base_specs, member_types, data_members,
	member_functions, member_function_templates,
	member_class_templates}): Make all these containers be vectors,
	rather than list.  This makes these containers (like
	class_decl::base_specs, class_decl::member_types, etc) be suitable
	to be used by the core diffing algorithms to diff their content.
	(operator==(class_decl_sptr, class_decl_sptr))
	(operator==(class_decl::member_type_sptr, class_decl::member_type_sptr))
	(operator==(class_decl::base_spec_sptr,
	            class_decl::base_spec_sptr))
	(operator==(class_decl::data_member_sptr,
	            class_decl::data_member_sptr))
	(operator==(class_decl::member_function_sptr,
	            class_decl::member_function_sptr))
	(operator==(class_decl::member_function_template_sptr,
	            class_decl::member_function_template_sptr))
	(operator==(class_decl::member_class_template_sptr,
		    class_decl::member_class_template_sptr)): Declare
	these new equality operators.  These are to be used by the core
	diffing algorithms when comparing two vectors of shared pointers
	of members of class_decls.
	* src/abg-ir.cc (decl_base::get_qualified_name): Define.
	(class_decl::class_decl, class_decl::operator==(class_decl&)): Adjust for the
	containers type change to a vector.
	(operator==(class_decl_sptr, class_decl_sptr))
	(operator==(class_decl::member_type_sptr, class_decl::member_type_sptr))
	(operator==(class_decl::base_spec_sptr,
	            class_decl::base_spec_sptr))
	(operator==(class_decl::data_member_sptr,
	            class_decl::data_member_sptr))
	(operator==(class_decl::member_function_sptr,
	            class_decl::member_function_sptr))
	(operator==(class_decl::member_function_template_sptr,
	            class_decl::member_function_template_sptr))
	(operator==(class_decl::member_class_template_sptr,
		    class_decl::member_class_template_sptr)): Define
	these.
	* include/abg-comparison.h (diff::scope_): Remove
	(diff::{first_scope_, second_scope_}): New members.
	(class_decl_diff::class_decl_diff): Pass the new scopes to this
	constructor.
	(class_decl_diff::{first_class_decl, second_class_decl})
	(report_changes): New declarations.
	* src/abg-comparison.cc (class_decl_diff::class_decl_diff): Update
	as per the declaration.
	(class_decl_diff::{first_class_decl, second_class_decl}): Define
	as per the declaration.
	(compute_diff): Initial implementation for this.
	(report_changes): Define.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:21:37 +01:00
Dodji Seketeli
b92e29a396 Misc white space, style and comment fixes
* include/abg-ir.h: Lots of useless white space removals and
	comments adding.
	(class class_decl::member_base): Fix comment.
	* src/abg-hash.cc: Lots of useless white space removals too.
	* src/abg-ir.cc: Remove useless white space too.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:20:28 +01:00
Dodji Seketeli
628911ee5f Prepare node visitors to be usable on things other than IR nodes
* include/abg-fwd.h (node_visitor_base): Renamed ir_node_visitor
	into this.
	* include/abg-traverse.h (struct node_visitor_base): New base for
	the visitors.
	(struct traversable_base): Update comments.
	(traversable_base::traverse): Change this into non-pure virtual.
	Make it take a reference to node_visitor_base, rather than a
	reference to ir_node_visitor.
	* src/abg-traverse.cc (traversable_base::traverse): New empty
	default implementation.
	* include/abg-ir.h: Make ir_node_visitor inherit from new
	node_visitor_base.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:19:12 +01:00
Dodji Seketeli
23d69b405c Renamed data members from m_something to something_
* src/abg-ir.{cc,h}: Renamed data members from m_something to
	something_ and update their usage.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-11-19 11:18:26 +01:00
Dodji Seketeli
0b8a16ef39 Define translation_unit{_sptr,s} types in abigail::
* include/abg-corpus.h (abigail::corpus::{translation_unit_sptr,
	translation_units):  Do not define these typedefs here.  Rather)
	(define them ...
	* include/abg-ir.h
	(abigail::{translation_units,translation_unit_sptr): ... here.
	This is because a translation unit can be manipulated
	independently from an abi corpus.
	* src/abg-corpus.cc (corpus::get_translation_units): Adjust return
	type to comply with the change above.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-08-29 16:45:55 +02:00
Dodji Seketeli
e90467e69b Misc white space cleanups
* include/abg-corpus.h: Cleanup white spaces.
	* include/abg-fwd.h: Likewise.
	* include/abg-ir.h: Likewise.
	* include/abg-libxml-utils.h: Likewise.
	* src/abg-config.cc: Likewise.
	* src/abg-ir.cc: Likewise.
	* src/abg-reader.cc: Likewise.
	* src/abg-writer.cc: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-08-27 16:20:40 +02:00
Dodji Seketeli
6d5f7c1223 Move location, location_manager & translation_unit back into abg-ir.h
* include/abg-corpus.h: Move location location_manager,
	translation_unit from here ...
	* include/abg-ir.h: ... to here.  The reason being that these are
	really constructs of the Internal Representation of the ABI/API of
	a translation unit.  What is left in abg-corpus is really
	exclusively related to an ABI Corpus, which I see more as a
	"packaging" construct that abstracts the bundling of several
	translation units together.  Also, I fixed some comments about the
	location/location_manger types; now a location is made specific to
	a translation unit; to an abi corpus.  A location of a given
	translation unit has to be decoded by the location manager of that
	same translation unit.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-08-27 13:21:26 +02:00
Benjamin Kosnik
6684ad97ad Separate out bits from the ir header.
* include/abg-irfwd.h: Move to...
	* include/abg-fwd.h: ...this.

	* include/abg-ir.h (traverse_base): Move to...
	* include/abg-traverse.h: ...here. New.

	* include/abg-ir.h (location, location_manager, translation_unit):
	Move to...
	* include/abg-corpus.h: ...here.

	* include/Makefile.am: Adjust.
	* include/Makefile.in: Regenerate.
2013-08-14 15:07:19 +02:00
Benjamin Kosnik
9258b41534 Template naming compression.
* include/abg-ir.h: Template naming compressions.
	(class_template_decl): To class_tdecl.
	(function_template_decl): To function_tdecl.
	(template_type_parameter): To type_tparameter.
	(template_non_type_parameter): To non_type_tparameter.
	(template_template_parameter): To template_tparameter.
	(tmpl_parm_type_composition): To type_composition.
	* include/abg-irfwd.h: Same.
	* src/abg-hash.cc: Same.
	* src/abg-ir.cc: Same.
	* src/abg-reader.cc: Same.
2013-08-14 15:07:19 +02:00
Benjamin Kosnik
c06c007abc Move class_decl nested types out-of-line.
* include/abg-ir.h (class_decl): Move nested types out of line.
2013-08-14 15:07:19 +02:00
Benjamin Kosnik
ea59f3c426 Rename class_decl::method to class_decl::method_base.
* include/abg-ir.h (class_decl::member): To member_base.
	* src/abg-hash.cc: Same.
	* src/abg-ir.cc: Same.
	* src/abg-writer.cc: Same.
2013-08-14 15:07:19 +02:00