Commit Graph

33 Commits

Author SHA1 Message Date
Mark Wielaard
453ed93d01 Handle C99 restrict qualifier and DWARFv3 DW_TAG_restrict_type.
* src/abg-dwarf-reader.cc (build_qualified_type): Handle
	DW_TAG_restrict_type by adding CV_RESTRICT.
	(build_ir_node_from_die): Call build_qualified_type for
	DW_TAG_restrict_type.
	* src/abg-reader.cc (build_qualified_type_decl): Handle
	"restrict" attribute by adding CV_RESTRICT.
	* src/abg-writer.cc (write_qualified_type_def): Output
	"restrict" attribute for CV_RESTRICT.
	* tests/data/test-read-dwarf/test4.c: New test file.
	* tests/data/test-read-dwarf/test4.so: Likewise.
	* tests/data/test-read-dwarf/test4.so.abi: Likewise.
	* tests/data/test-read-write/test24.xml: Likewise.
	* tests/test-read-dwarf.cc (in_out_specs): Add test4.
	* tests/test-read-write.cc (in_out_specs): Add test24.xml.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2014-06-23 15:55:37 +02:00
Dodji Seketeli
ed5cd14a34 Get rid of class_decl::data_member
* include/abg-fwd.h (has_scope): Delete the overloads for
	type_base.
	(get_member_is_static): Add an overload for decl_base*.
	({is,get,set}_data_member,{get_,set}_data_member_is_laid_out)
	({get,set}_data_member_offset): New access declarations.
	* include/abg-ir.h (class context_rel): Move up.
	(decl_base::set_context_rel): New definition.
	(class dm_context_rel): New type.
	(decl_base::hash_as_member): Remove.
	(var_decl::set_scope): Declare new virtual member.
	(class_decl::data_member): Remove.
	(ir_node_visitor::visit): Remove the overload for
	class_decl::data_member.
	(represent_data_member): Remove the represent overload for
	class_decl::data_member into this.  Make it take a var_decl.
	(represent): Change the overload that takes two
	class_decl::data_member take two var_decl.  And adjust it.
	(class_diff::report): Adjust.
	* src/abg-corpus.cc (symtab_build_visitor_type::visit): Remove the
	overload that takes a class_decl::data_member*.  Adjust the
	overload that takes a var_decl to recognize (static) data members.
	* src/abg-dwarf-reader.cc (build_translation_unit_and_add_to_ir)
	(build_class_type_and_add_to_ir, build_ir_node_from_die):
	Adjust.
	* src/abg-hash.cc (var_decl:#️⃣:operator()): Adjust.
	(class_decl::data_member:#️⃣:operator()): Remove.
	(decl_base:#️⃣:operator()): Take the context relationship in
	account here.
	(decl_base::hash_as_member::operator()): Remove.
	({enum_type_decl,typedef_decl}:#️⃣:operator()): Adjust.
	(class_decl::member_function:#️⃣:operator()): Adjust.
	(type_base::dynamic_hash::operator()): Adjust.
	* src/abg-ir.cc (dm_context_rel::~dm_context_rel): New definition.
	(has_scope): Remove overload for type_base.
	(get_member_is_static): New overload for decl_base*.
	(is_data_member): New function definition.
	({get,set}_data_member_{offset,is_laid_out}): Define new
	accessors.
	(var_decl::set_scope): Define new member function.  Make this set
	a dm_context_rel as the context relationship.
	(var_decl::operator==): Adjust to take in account the new data
	member relationship.
	(class_decl::class_decl): Adjust.
	(class_decl::insert_member_decl): Adjust.
	(class_decl::add_data_member): Remove the overload for
	class_decl::data_member.
	(class_decl::add_data_member): Adjust the overload for var_decl.
	(operator==): Remove overload for class_decl::data_member*.
	(class_decl::data_member::operator==): Likewise.
	(ir_node_visitor::visit): Remove overload for
	class_decl::data_member.
	* src/abg-writer.cc (write_layout_offset, write_class_decl):
	Adjust.
	* tests/data/test-read-write/test20.xml: Adjust.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-19 21:18:38 +01:00
Dodji Seketeli
661f76c8f4 Better base class diff reporting
* include/abg-comparison.h (class base_diff): New.
	* include/abg-ir.h (function_decl::get_first_non_implicit_parm):
	New member function.
	(function_type::get_first_non_implicit_parm): Likewise.
	* src/abg-comparison.cc (base_has_changed): Change parm to take
	class_decl::base_spec_sptr.
	(class_diff::ensure_lookup_tables_populated): Compare the base
	specs not just the base classes.
	(class_diff::report): Adjust.  Report sub-type changes in the
	member functions.
	(base_diff::*): Define member functions.
	(compute_diff): Define an overload for base_diff_sptr.
	* src/abg-hash.cc ({function_type,
	method_type}:#️⃣:operator()): Do not hash the implicit parm of
	member functions.
	(class_decl:#️⃣:operator()):  Do not hash member types.
	* src/abg-ir.cc (decl_base::decl_base): Initialize the
	hashing_started_ member that got moved here from class_decl.
	(decl_base::get_hash): Do not set the hash if it's being set b/c
	we are in a class_decl.
	(decl_base::operator==) Do not compare hashes for now.  Two decls
	can have different hashes and compare equal; think about an
	incomplete type foo, that compares equal with a complete foo.
	Their hashes will be different though.  So for now, just avoid
	comparing these.
	(compare_function_types): Avoid comparing the implicit parameter
	for member functions.
	({function, method}_type::get_first_non_implicit_parm): New
	definition.
	* tests/data/test-read-write/test20.xml: Update.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-18 11:27:02 +01:00
Dodji Seketeli
42aaa3124e Do not declare classes before defining them anymore
* src/abg-dwarf-reader.cc (build_class_type_and_add_to_ir): Do not
	declare classes before defining them because both the declaration
	and the definition now compare equal.
	* tests/data/test-read-dwarf/test1.abi: Update test.
	* tests/data/test-read-write/test20.xml: Likewise.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2014-03-11 13:55:35 +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
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
61b13cc9db Support variadic arguments in function decls
* src/abg-reader.cc (build_function_parameter): Support reading
	the "is-variadic" attribute.
	* src/abg-writer.cc (write_function_decl): Support writing the
	"is-variadic" attribute.
	* tests/data/test-read-write/test22.xml: New test input.
	* tests/test-read-write.cc (in_out_specs): Add the new test to the
	list of files to read and write back.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
2013-12-11 12:17:55 +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
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
9b99a77d8a Support offsets and virtual attribute in base class specifiers
* src/abg-ir.h (class_decl::base_spec::base_spec): Take an offset
	and a is_virtual flag.
	(class_decl::base_spec::{get_is_virtual, get_offset_in_bits}): New
	methods.
	(class_decl::has_no_base_nor_member): New method declaration..
	* src/abg-ir.cc (class_decl::base_spec::base_spec): Take an offset
	and a is_virtual flag
	(class_decl::has_no_base_nor_member): Define it.
	* src/abg-reader.cc (read_offset_in_bits): Renamed
	read_var_offset_in_bits into this.
	(read_is_virtual): New static function.
	(build_class_decl): Read the 'layout-offset-in-bits' and the
	'is-virtual' of the base class specifier.  Adjust for the
	read_var_offset_in_bits -> read_offset_in_bits rename.
	* src/abg-writer.cc (write_layout_offset): New overload for the
	base class specifiers.
	(write_class_decl): If the class has no member or base class, make
	it a proper empty xml element.  Write the offset and the
	is-virtual attribute.
	* tests/data/test-read-write/test20.xml: New test input data.
	* tests/test-read-write.cc: De-serialize the test above, serialize
	it back and compare that both versions are the same.
2013-07-23 23:13:53 +02:00
Dodji Seketeli
c94ef0da7a Iron out support for simple base classes.
* src/abg-ir.h (class_decl::base_spec::base_spec): Move this
	out-of-line.  Add a new constructor for clients compiled without
	RTTI.
	* src/abg-ir.cc (class_decl::base_spec::base_spec):  This is now
	here out-of-line.  Define the new constructor for clients compiled
	without RTTI.
	* tests/data/test-read-write/test19.xml: New test case input for
	base classes.
	* tests/test-read-write.cc: De-serialize and serialize the new
	test case input above.
2013-07-23 23:13:53 +02:00
Dodji Seketeli
b04ca87487 Fix handling of forward decl of classes
* abg-ir.h (class_decl::set_earlier_declaration): Move this
	out-of-line and add an overload.
	* src/abg-ir.cc (class_decl::set_earlier_declaration): Moved this
	out-of-line here and add an overload.
	* src/abg-reader.cc (build_class_decl): Really read the
	'decl-of-decl-id' property.  Do not make the definition use the id
	of the declaration.  Both have their id.
	* src/abg-writer.cc (write_class_decl):  Put a space before the
	property "def-of-decl-id".
	* tests/data/test-read-write/test18.xml: New test input.
	* tests/test-read-write.cc: De-serialize this new input, serialize
	it back and make sure both versions are identical.
2013-07-23 23:13:53 +02:00
Dodji Seketeli
c243aac0a4 Support method type/decl, variadic functions, class declarations-only
* src/abg-ir.h (function_decl::parameter::parameter): New
	constructor with variadic parameter marker.
	(function_decl::m_type): Make this protected to let method_decl
	inheriting class to access it.
	(function_decl::get_type): Move this out-of-line.
	(class method_type, method_type_hash): New types.
	(enum class_decl::access_specifier): Add no_access new enumerator.
	(class_decl::data_member::data_member): Move this out-of-line.
	(class_decl::data_member::~data_member): Declare virtual
	destructor.
	(class method_decl): New class.
	(class member_function): Make this inherit method_decl, instead of
	function_decl.
	(class_decl::class_decl): New constructors.
	(class_decl::{hashing_started, is_declaration_only,
	set_earlier_declaration, get_earlier_declaration}): New methods.
	* src/abg-ir.cc (add_decl_to_scope): If a decl is already in a
	scope, don't add it to this scope.
	(get_global_scope): Make this work when passed an instance of
	global_scope.
	(dynamic_type_hash::operator()): Add support for method_type.
	(method_type::{method_type, set_class_type, ~method_type, })
	(method_type_hash::operator()): New defintions.
	(function_decl::get_type, class_decl::class_decl): Move these
	out-of-line here.
	(class_decl::method_decl::{method_decl, ~method_decl, get_type}):
	New definitions.
	(class_decl::member_function::member_function): Move this
	out-of-line here.  Support method_decl.
	(class_decl::data_member::data_member): Likewise.
	(class_decl_hash::operator()): Guard this against endless loop.
	* src/abg-reader.cc (write_class_is_declaration_only): New static
	function.
	(write_var_decl): Take a flag to write the mangled name or not.
	(write_function_decl): Take a flag to skip the first parameter.
	(write_cdtor_const_static): Use 'yes' instead of 'true' as value
	of the properties.
	(write_decl, write_function_template_decl): Adjust wrt the new
	signatures of write_var_decl and write_function_decl.
	(write_enum_type_decl): Simplify call to write_location.
	(write_class_decl): Support serializing declaration-only classes.
	* src/abg-writer.cc:
	* tests/data/test-read-write/test17.xml: New test input.
	* tests/test-read-write.cc: De-serialize the above, and serialize it back.
	* tests/data/test-read-write/test10.xml: Update this test.
2013-07-23 23:13:53 +02:00
Dodji Seketeli
0c65215330 Support function_type and adapt a function_decl to use it
* src/abg-ir.h (class function_type): Forward decl prior to class
	function_decl.
	(function_decl::parameter): Pass string by const reference.  Add a
	variadic marker member and initialize it.
	(function_decl::parameter::get_type): Add a non-const overload.
	(function_decl::parameter::get_variadic_marker): New getter.
	(function_decl::function_decl) Take a const reference to a vector
	for parameters, type size/alignment.  Add two overloads that takes a
	pointer to function_type.
	(function_decl::get_parameters): Move this out-of-line.
	(function_decl::append_parameter(s)): Renamed
	function_decl::add_parameter(s) into these.  Move it out-of-line.
	Add an overload.
	(function_decl::{get_type, set_type}): New declaration.
	(function_decl::get_return_type): Move this out-of-line.
	(function_decl::is_variadic): New in-line function.
	(function_decl::m_type): New data member.
	(function_decl::{m_parms, m_return_type}): Remove.  This are now
	carried by function_decl::m_type.
	(class function_type, struct function_type_hash): New
	declarations.
	(member_function::member_function): Take a vector of pointers to
	parameters.  Take size/align of the type of the member function.
	Adjust initialization.
	* src/abg-ir.cc (dynamic_type_hash): Hash instance of
	function_type accessed through a pointer.
	(function_type::{operator==, ~function_type})
	(function_type_hash::operaror(), function_decl::{get_return_type,
	}, function_decl::parameter:#️⃣:operator()): New definitions.
	(function_decl::function_decl): The out-of-line definitions of the
	declarations above.
	(function_decl::append_parameter): Moved this out-of-line from
	inline function_decl::add_parameter.  Make this rely on the
	underlying m_type.
	(function_decl::operator==): Adjust for use of vector for the
	parameters.  Also, there is no need anymore to compare the
	parameters or the return types as they are compared by the
	comparison of the function types.
	* src/abg-reader.cc (build_function_decl): Read the new size/alignment
	attributes on the function-decl element.  Build a function_type
	and use it to build the function_decl.  Parameters and return type
	are now hung off of the function_type.
	(handle_function_decl): use build_function_decl.
	* src/abg-writer.cc (write_function_decl): Write the new
	size/alignment properties of the function-decl element.  Adjust
	for the use of vectors for function parameters now.
	* tests/data/test-read-write/test10.xml: Adjust for the presence
	of size/alignment properties in the function-decl element now.
	* tests/data/test-read-write/test11.xml: Likewise.
	* tests/data/test-read-write/test12.xml: Likewise.
	* tests/data/test-read-write/test13.xml: Likewise.
	* tests/data/test-read-write/test14.xml: Likewise.
	* tests/data/test-read-write/test9.xml: Likewise.
2013-07-23 23:13:53 +02:00
Dodji Seketeli
a7e6fbbd7d Initial support for member class templates
* src/abg-ir.cc (class_decl::add_member_function_template): Fix
	comment.
	(class_decl::add_member_class_template)
	(class_decl::member_class_template::operator==)
	(class_decl::member_class_template_hash::operator()): New
	definitions.
	(class_decl::operator==): Compare member templates.  Fix logic.
	(class_decl::data_member_hash::operator())
	(class_decl::member_function_hash::operator())
	(class_decl::member_function_template_hash::operator()): Don't
	hash the is_static boolean as it's hashed as part of the 'member'
	sub-object hashing.
	(class_decl::member_function_template::operator==): Move this out
	of line here, from the header file.
	(class_decl_hash::operator()): Hash member class templates.
	* src/abg-ir.h (class_decl::member::{m_is_static,is_static}): Add the is_static
	boolean here, so that it's factorized out of the inherited classes
	of this class.
	(class_decl::data_member::{is_static, m_is_static})
	(class_decl::member_function::{is_static, m_is_static})
	(class_decl::member_function_template::{is_static, m_is_static}): Remove this
	as it's now part of the base 'member' class.
	(class_decl::data_member::operator==)
	(class_decl::member_function::operator==): Don't compare the
	is_static boolean as it's now compared as part of the 'member'
	sub-object comparison.
	(class_decl::member_function_template::operator==): Move this
	out-of-line into src/abg-ir.cc.
	(class class_decl::member_class_template, struct
	class_decl::member_class_template_hash)
	(class_decl::{add_member_class_template,
	get_member_class_templates}): New declarations.
	(class_decl::member_class_templates_type): New typedef.
	* src/abg-reader.cc (build_class_decl): Support de-serializing
	member class templates.
	* src/abg-writer.cc (write_class_decl): Likewise, support
	serializing member class templates.
	* tests/data/test-read-write/test16.xml: New test input.
	* tests/test-read-write.cc (int_out_specs[]): Add the new test
	input to the list of inputs that are de-serialized and serialized
	back.
	* tests/Makefile.am: Add the new test input to the distribution.
2013-07-23 23:13:51 +02:00
Dodji Seketeli
c50b9dbb55 Initial support of class templates
* src/abg-ir.cc (class_template_decl::class_template_decl)
	(class_template_decl::set_pattern)
	(class_template_decl::operator==)
	(class_template_decl::~class_template_decl)
	(class_template_decl_hash::operator())
	(class_tmpl_shared_ptr_hash::operator()): New definitions.
	* src/abg-ir.h (class class_template_decl, struct
	class_tmpl_shared_ptr_hash, struct class_tmpl_shared_ptr_hash):
	New declarations.
	* src/abg-reader.cc (read_context::const_class_tmpl_map_it): New
	typedef.
	(read_context::get_fn_tmpl_decl): Fix comment.
	(read_context::{get_class_tmpl_decl,key_class_tmpl_decl})
	(build_class_template_decl, handle_class_template_decl): New
	definitions.
	(read_context::m_class_tmpl_map): New member.
	(handle_element): Support "class-template-decl" xml elements
	nodes.
	(build_class_decl): Add missing bits to comment.
	(build_function_template_decl): Fix spacing.
	* src/abg-writer.cc (class_tmpl_shared_ptr_map): New typedef.
	(write_context::m_class_tmpl_map): New member.
	(write_context::get_id_for_class_tmpl, write_class_template_decl):
	New definitions.
	(write_template_parameters): Factorize this this out from ...
	(write_function_template_decl): ... here.
	(write_decl): Support writing instances of class_template_decl.
	Fix spacing.
	* tests/data/test-read-write/test15.xml: New test input.
	* tests/Makefile.am: Add the new test15.xml input to the
	distribution.
	* tests/test-read-write.cc (in_out_specs): Add the new test15.xml
	test to the list of serialized output to be de-serialized and
	serialized back.
2013-07-23 23:13:51 +02:00
Dodji Seketeli
97ef8941b3 Support member function templates
* src:abg-ir.h: Move template declarations before class
	class_decl, so that class_decl can have member templates.
	(class class_decl::member_function_template)
	(class_decl::add_member_function_template)
	(class_decl::{base_specs_type, member_types_type,
	data_members_types, member_functions_type,
	member_function_templates_type}): New declarations.
	* src/abg-ir.cc (class_decl::add_member_function_template)
	(class_decl::member_function_template_hash::operator()): New
	definitions.
	(class_decl_hash::operator()):  Support hashing for member
	function templates.
	* src/abg-reader.cc (build_class_decl): Use the new
	class_decl::{member_types_type, data_members_type,
	member_functions_type, base_specs_type} types.  Support member
	function templates.
	* src/abg-writer.cc (write_cdtor_const_static): New definition.
	(write_class_decl): Support member function templates.
	* tests/data/test-read-write/test14.xml: New input data.
	* tests/Makefile.am: Add it to the distribution.
	* tests/test-read-write.cc (InOutSpec int_out_specs): De-serialize
	the new test input file, serialize it back and diff both results.
2013-07-23 23:13:51 +02:00
Dodji Seketeli
6831ba7c21 Support composing template type parameters
* src/abg-ir.h (class tmpl_parm_type_composition): New
	declaration.
	* src/abg-ir.cc
	(tmpl_parm_type_composition::tmpl_parm_type_composition)
	(tmpl_parm_type_composition::~tmpl_parm_type_composition): New
	definitions.
	* src/abg-reader.cc (build_tmpl_parm_type_composition): New
	function.
	(build_template_parameter): Support template parameter type
	composition.
	* src/abg-writer.cc (write_tmpl_parm_type_composition): New
	function.
	(write_template_non_type_parameter): Fix type-id attribute.
	(write_template_parameter): Support template parameter type
	composition.
	* tests/data/test-read-write/test13.xml: New test input.
	* tests/Makefile.am: Add it to the distribution.
	* tests/test-read-write.cc (InOutSpec in_out_spec): Add test13.xml
	to the list of xml file that are de-serialized and serialized back.
2013-07-23 23:13:50 +02:00
Dodji Seketeli
ace9af4568 Fix depth management during the parsing
* src/abg-ir.cc (decl_base_hash::operator()):  Don't hash the
	context for decls in general.
	* src/abg-reader.cc (read_context::push_decl_to_current_scope)
	(read_context::push_and_key_type_decl): Add an overload that takes
	a node and update_depth_info boolean.
	(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_template_type_parameter, build_template_non_type_parameter)
	(build_template_template_parameter, build_template_parameter)
	(build_type): Make these functions take an update_depth_info
	parameter.  Pass it do read_context::push_and_key_type_decl or
	read_context::push_decl_to_current_scope rather than call
	update_read_context.
	(build_function_decl, build_class_decl)
	(build_function_template_decl): Change the seen_by_reader
	parameter into update_depth_info.  Pass the update_depth_info bool
	to read_context::push_decl_to_current_scope rather than call
	update_depth_info here.
	(handle_class, handle_function_template_decl): Adjust.
	* tests/data/test-read-write/test12.xml: Add new test input.
	* tests/test-read-write.cc (InOutSpec in_out_specs): Add it to the
	list of input to de-serialize, serialize back and compare the two.
	* tests/Makefile.am: Add the new test input to the distribution.
2013-07-23 23:13:50 +02:00
Dodji Seketeli
6a03c86a28 Initial support for function templates
* src/abg-ir.h (function_decl::set_return_type): New inline
	definition.
	(class template_decl, struct template_decl_hash, class
	template_parameter, struct template_parameter_hash, struct
	dynamic_template_parameter_hash, struct
	template_parameter_shared_ptr_hash, class template_type_parameter)
	(struct template_type_parameter_hash, class
	template_non_type_parameter, struct
	template_non_type_parameter_hash, class
	template_template_parameter, struct
	template_template_parameter_hash, class function_template_decl)
	(struct function_template_decl_hash, struct
	fn_tmpl_shared_ptr_hash): New declarations.
	* src/abg-ir.cc (dynamic_type_hash::operator()): Add hashing for
	template template, and template type parameters.
	(template_decl_hash::operator, template_decl::~template_decl)
	(template_decl::operator==, template_parameter::operator==)
	(template_parameter_hash::operator())
	(dynamic_template_parameter_hash::operator())
	(template_type_parameter::operator==)
	(template_type_parameter::~template_type_parameter)
	(template_type_parameter_hash::operator())
	(template_non_type_parameter::operator==)
	(template_non_type_parameter::~template_non_type_parameter)
	(template_non_type_parameter_hash::operator())
	(template_template_parameter::operator==)
	(template_template_parameter::~template_template_parameter)
	(template_template_parameter_hash::operator())
	(function_template_decl::operator==)
	(function_template_decl_hash::operator())
	(fn_tmpl_shared_ptr_hash::operator())
	(function_template_decl::~function_template_decl()): New
	definitions.
	* src/abg-reader.cc (read_context::get_fn_tmpl_decl)
	(read_context::key_fn_tmpl_decl): New functions.
	(read_context::m_fn_tmpl_map): New data member.
	(read_context::key_type_decl): Renamed read_context::add_type_decl
	into this.
	(read_context::push_decl_to_current_scope): Renamed
	read_context::finish_decl_creation into this.  Add an assert.
	(read_context::push_and_key_type_decl): Renamed
	read_context::finish_type_decl_creation into this.  Adjust to the
	use of push_decl_to_current_scope and key_type_decl.
	(build_function_template_decl, build_template_type_parameter)
	(build_template_non_type_parameter)
	(build_template_template_parameter, build_template_parameter)
	(handle_function_template_decl): New functions.
	(handle_element): Call handle_function_template_decl.
	(build_function_decl): Take a bool parameter to update depth
	information in parsing context.  Move instantiation of
	function_decl before parsing its xml sub-nodes.  Update the depth
	info in the parsing context if necessary.  Push the newly
	intantiated decl to scope.  And then parse the sub nodes.  Do not
	forget to add the fn parameters and return type using
	function_decl::add_parameter and function_decl::set_return_type.
	(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, handled_type_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): Adjust.
	(build_class_decl): Take a bool parameter to update depth
	information in parsing context. Add comment.  Wait for the class
	members to be built, before keying (and thus hashing it) the
	class.
	(build_type): Fix logic, and adjust.
	* src/abg-writer.cc (write_context::type_has_existing_id)
	(write_context::get_id_for_fn_tmpl, write_template_type_parameter)
	(write_template_non_type_parameter)
	(write_template_template_parameter, write_template_parameter)
	(write_function_template_decl): New functions.
	(write_context::get_id_for_type): Simplify logic.
	(write_decl): Support writing function template.
	* tests/data/test-read-write/test11.xml: New test input.
	* tests/test-read-write.cc (InoutSpec in_out_specs[]):
	De-serialize the new test11.xml test, serialize it back and diff
	output and input.
	* tests/Makefile.am: Add test11.xml to the distribution.
2013-07-23 23:13:50 +02:00
Dodji Seketeli
ee19845a94 Initial Support for class declarations
* src/abg-ir.h (scope_decl::scope_decl)
	(scope_type_decl::scope_type_decl): Don't set mangled name for
	scope_decl instances as it doesn't make sense.
	(var_decl::var_decl): Pass the type shared pointer by value.
	(struct var_decl_hash, function_decl::parameter::operator==)
	(struct function_decl::parameter_hash, function_decl::operator==)
	(struct function_decl_hash, class class_decl, struct
	class_decl_hash): New declarations.
	* src/abg-ir.cc (scope_type_decl::scope_type_decl): Don't set the
	mangled name.  It doesn't make sense for scope_decls.
	(dynamic_type_hash::operator): Fix comment.  Run the hashing for
	scope_type_decl instances *after* running it for class_decl
	instance, otherwise, the class_decl instances case will never get
	hit.
	(var_decl::var_decl): Pass the type shared pointer by value.
	(function_decl::operator==, class_decl::operator==)
	(class_decl_hash::operator()): New fns.
	* src/abg-libxml-utils.h (get_xml_node_depth): Declare new fn.
	(XML_READER_GET_ATTRIBUTE): Fix comment.
	(XML_NODE_GET_ATTRIBUTE): New getter macro.
	* src/abg-libxml-utils.cc (get_xml_node_depth): New definition.
	* src/abg-reader.cc (update_read_context)
	(update_depth_info_of_read_context, read_visibility, read_binding)
	(read_access, read_size_and_alignment, read_static)
	(read_var_offset_in_bits, read_cdtor_const, 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_class_decl)
	(build_type, handle_class_decl): New functions or overloads.
	(handle_element): Update to handle "class-decl" xml elements.
	* src/abg-writer.cc (write_size_and_alignment, write_access)
	(write_class, do_indent_to_level, get_indent_to_level): New fns.
	(write_decl): Update to serialize instances of class_decl.
	(write_type_decl, write_pointer_type_def)
	(write_reference_type_def): Use the new write_size_and_alignment instead of
	writing the attributes directly.
	* tests/data/test-read-write/test10.xml: New test file.
	* tests/Makefile.am: Add tests/data/test-read-write/test10.xml to
	the build system.
	* tests/test-read-write.cc (in_out_spec): De-serialize
	data/test-read-write/test10.xml, serialize it back into
	output/test-read-write/test10.xml, and compare the two output that
	should be identical.
2013-07-23 23:13:49 +02:00
Dodji Seketeli
827f0fe6af Update enum decl representation as per the schema
* src/abg-reader.cc (handle_enum_type_decl): The name of the
	element holding the underlying type is now "underlying-type", no
	more "base".
	* src/abg-writer.cc (write_enum_type_decl): Likewise.
	* tests/data/test-read-write/test6.xml: Likewise.
2013-07-23 23:13:49 +02:00
Dodji Seketeli
43ce2becb1 Add tests/data/test-read-write/test9.xml
* tests/data/test-read-write/test9.xml: (Forgot to) Add this new
	test file.
2013-07-23 23:13:49 +02:00
Dodji Seketeli
760248d26b Support var decl & mangled_name attributes
* src/abg-ir.h (decl_base::binding, decl_base::get_mangled_name)
	(decl_base::set_mangled_name, decl_base::m_mangled_name): New
	declarations.
	(scope_decl::scope_decl: type_decl::type_decl)
	(scope_type_decl::scope_type_decl, typedef_decl::typedef_decl):
	Initialize mangled_name.
	(namespace_decl::namespace_decl): Initialize visibility.
	(class var_decl): New declaration.
	* src/abg-ir.cc (decl_base::decl_base, scope_decl::scope_decl)
	(type_decl::type_decl, scope_type_decl::scope_type_decl):
	Initialize mangled name.
	(namespace_decl::namespace_decl): Initialize visibility.
	(qualified_type_def::qualified_type_def)
	(pointer_type_def::pointer_type_def)
	(reference_type_def::reference_type_def): By default, set the
	visibility to the same as for the underlying type.
	(enum_type_decl::enum_type_decl, typedef_decl::typedef_decl):
	Initialize mangled name.
	(var_decl::var_decl, var_decl::operator==, var_decl::~var_decl):
	New definitions.
	* src/abg-reader.cc (read_visibility, read_binding, handle_var_decl): New
	definitions.
	(read_file): Handle var-decl elements.
	* src/abg-writer.cc (write_location): Rename write_decl_location
	into this.
	(write_var_decl, write_visibility, write_binding): New definitions.
	(write_decl, write_type_decl, write_qualified_type_def)
	(write_pointer_type_def, write_reference_type_def)
	(write_enum_type_decl, write_typedef_decl): Adjust to use
	write_location.
	* tests/data/test-read-write/test8.xml: New test input.
	* tests/test-read-write.cc: De-serialize the above and serialize
	it back and ensure both are equal.
	* tests/Makefile.am: add tests/data/test-read-write/test8.xml to
	the distribution.
2013-04-02 16:51:59 +02:00
Dodji Seketeli
a5a6fd8fce Support typedef declarations
* src/abg-ir.cc (dynamic_type_hash::operator()): Handle hashing of
	a pointer to an instance of typedef_decl.
	(typedef_decl::typedef_decl, typedef_decl::operator==)
	(typedef_decl::operator==, typedef_decl::get_underlying_type)
	(typedef_decl::~typedef_decl): New definitions.
	* src/abg-ir.h (class typedef_decl, struct typedef_decl_hash): New
	declarations.
	* src/abg-reader.cc (handle_typedef_decl): New definition.
	(handle_element): Handle de-serialization of typedef-decl element.
	* src/abg-writer.cc (write_typedef_decl): New definition.
	(write_decl): Handle serialization of an instance of typedef_decl.
	* tests/data/test-read-write/test7.xml: New test.
	* tests/Makefile.am: Add it to the distribution.
	* tests/test-read-write.cc: De-serialize the content of the new
	test, serialize it back and diff both.
2013-03-30 21:59:19 +01:00
Dodji Seketeli
170885cfcc Support enum type declarations
* src/abg-ir.h (class enum_type_decl, struct enum_type_decl_hash):
	New declarations.
	* src/abg-ir.cc (dynamic_type_hash::operator()): Add hashing
	support for enum_type_decl.
	(enum_type_decl::enum_type_decl)
	(enum_type_decl::get_underlying_type)
	(enum_type_decl::get_enumerators, enum_type_decl::~enum_type_decl)
	(enum_type_decl::operator==): New definitions.
	* src/abg-reader.cc (handle_enum_type_decl): New definition.
	(handle_element): Handle "enum-decl" element.
	* src/abg-writer.cc (write_enum_type_decl): New.
	(write_decl): Add support to serialize enum_type_decl.
	* tests/test-read-write.cc: De-serialize and serialize
	data/test-read-write/test6.xml back.
	* tests/data/test-read-write/test6.xml: New test input.
	* tests/Makefile.am: Add it to the distribution.
2013-03-30 19:33:05 +01:00
Dodji Seketeli
0951049924 Support reference types
* src/abg-ir.h (class reference_type_def, struct pointer_type_def)
	(struct reference_type_def): New declaration.
	(type_base_hash::operator(), type_decl_hash::operator())
	(scope_type_decl_hash::operator())
	(qualified_type_def_hash::operator()): Include the typeid name in
	the hash.
	* src/abg-ir.cc (reference_type_def::reference_type_def)
	(reference_type_def::operator==)
	(reference_type_def::get_pointed_to_type)
	(reference_type_def::is_lvalue)
	(reference_type_def::~reference_type_def): New definitions.
	(dynamic_type_hash::operator): Hash pointer_type_def and
	reference_type_def instances.
	* src/abg-reader.cc (read_context::finish_decl_creation)
	(read_context::finish_type_decl_creation)
	(handle_reference_type_def): New definitions.
	(read_file): Handle "reference-type-def" elements.
	(handle_type_decl, handle_namespace_decl)
	(handle_qualified_type_decl, handle_pointer_type_def): Use the new
	read_context::finish_type_decl_creation or
	read_context::finish_decl_creation.
	* src/abg-writer.cc (write_reference_type_def): New definition.
	(write_decl): Supporting writing a pointer to an instance of
	reference_type_def.
	* tests/data/test-read-write/test5.xml: New test file.
	* tests/test-read-write.cc: (De)Serialize it.
	* tests/Makefile.am: Add it to the build system.
2013-03-29 16:44:08 +01:00
Dodji Seketeli
d418d5198f Support pointer types & Fix IR types equality
* src/abg-ir.h (location::{operator==, operator<})
	(decl_base::operator==, scope_decl::operator==)
	(type_base::operator==, struct type_shared_ptr_equal)
	(type_decl::operator==, scope_type::operator==)
	(qualified_type_def::operator==, class pointer_type_def): New
	declarations..
	* src/abg-ir.cc (decl_base::operator==, scope_decl::operator==)
	(type_base::operator==, type_decl::operator==)
	(scope_type_decl::operator==, namespace_decl::operator==)
	(qualified_type_def::operator==)
	(pointer_type_def::pointer_type_def, pointer_type_def::operator==)
	(pointer_type_def::get_pointed_to_type)
	(pointer_type_def::~pointer_type_def): New definitions.
	* src/abg-reader.cc (handle_pointer_type_def): New definition.
	(read_input): Handle pointer-type-def
	elements.
	* src/abg-writer.cc (type_shared_ptr_map):  Make this map use the
	use type_shared_ptr_equal predicate.
	(write_pointer_type_def): New definition.
	(write_decl): Improve logic.  Support serializing a pointer to
	pointer_type_def.
	* tests/data/test-read-write/test4.xml: New test input file.
	* tests/Makefile.am: Add tests/data/test-read-write/test4.xml to
	the build system.
	* tests/test-read-write.cc: (De)serialize the new test file.
2013-03-28 15:42:12 +01:00
Dodji Seketeli
57d8b7da41 Support qualified types & Misc ancillary fixes
* src/abg-ir.h (struct type_base_hash, struct dynamic_type_hash)
	(struct type_shared_ptr_hash, struct scope_type_decl_hash, class
	qualified_type_def, struct qualified_type_def_hash): New.
	(decl_base_hash::operator()): Constify. Don't crash if the scope
	of the decl we are hashing is null.
	(class type_decl): Add comment at the end.
	(type_decl_hash::operator()): Constify.  Reuse the new
	type_base_hash hasher.
	(class namespace_decl): Add comment.
	* src/abg-ir.cc (qualified_type_def::qualified_type_def)
	(qualified_type_def::~qualified_type_def)
	(qualified_type_def::get_cv_quals)
	(qualified_type_def::set_cv_quals)
	(qualified_type_def::get_underlying_type)
	(dynamic_type_hash::operator()): New function definitions.
	* src/abg-reader.cc (handle_qualified_type_decl): New.
	(read_file): Handle elements named "qualified-type-def".
	(read::context::add_type_decl): Assert that
	the type being associated to the unique ID is non-null.
	(handle_type_decl): Fix this in the process; don't crash if some
	attributes are not present.  Associate the unique id present in
	the xml document with the type we just parsed.
	(handle_namespace_decl): Add some comments.  Don't crash if the
	name attribute is not present.
	* src/abg-writer.cc (write_context::get_id_for_type)
	(write_context::m_type_id_map, write_decl_location)
	(write_qualified_type_def): New.
	(write_decl): Handle instances of qualified_type_def.
	(write_type_decl): Use the new write_decl_location and
	write_context::get_id_for_type.
	* tests/data/test-read-write/test0.xml: Update id format since we
	are now using the new write_context::get_id_for_type to generate
	it.
	* tests/data/test-read-write/test1.xml: Likewise.
	* tests/data/test-read-write/test2.xml: Likewise.
	* tests/data/test-read-write/test3.xml: New test.
	* tests/test-read-write.cc: Test De-serializing
	tests/data/test-read-write/test3.xml and serializing it back.
	Also don't bail out if we fail on one input.
	* tests/Makefile.am: Add tests/data/test-read-write/test3.xml to the
	distribution.
2013-03-27 23:59:16 +01:00
Dodji Seketeli
1c1532d60d Fix depth handling during the parsing
* src/abg-reader.cc (read_context::get_cur_scope): Remove useless
	const overload.  Don't make this rely on m_cur_scope.  Rather, use
	the path to the current decl (from the root element) to compute
	the cur scope.
	(read_context::m_cur_scope, read_context::set_cur_scope): Remove
	these.
	(update_read_context): Re-think logic.
	* tests/data/test-read-write/test2.xml: Add new test input.
	* tests/Makefile.am: Add data/test-read-write/test2.xml to the
	distribution.
	* tests/test-read-write.cc: Add data/test-read-write/test2.xml to
	the harness.
2013-03-26 11:43:59 +01:00
Dodji Seketeli
4ef7b34387 Debug read-write of a type-decl in a namespace-decl
* abg-ir.{h,cc} (decl_base::decl_base, scope_decl::scope_decl)
	(type_decl::type_decl, namespace_decl::namespace_decl): Do not
	append a decl to its context from within its constructor.  It's
	better doing that in a function that takes shared_ptrs to decl and
	context.  That way we avoid memory management havoc.
	(decl_base::set_scope): New private function.
	(scope_decl::add_member_decl): Make this private.
	(add_decl_to_scope): New function, friend of decl_base and
	scope_decl.
	* abg-reader.cc (read_context::get_cur_scope): Add a non-const
	overload.
	(handle_type_decl, handle_namespace_decl): Use add_decl_to_scope.
	Adjust to new type_decl and namespace_decl constructor signature.
	* src/abg-writer.cc (write_type): Emit 'id', not 'xml:id'.
	(write_namespace_decl): Emit "namespace-decl", not
	"namespace-decl-name", as the name of namespace element.
	* tests/Makefile.am (test0.xml): Rename input0.xml into this.
	(test1.xml): New test input.
	* tests/data/test-read-write/test0.xml: Update to use 'id' as id
	attribute, rather than xml:id.
	* tests/data/test-read-write/test1.xml: New test.
	* test-read-write.cc (struct InOutSpec): New
	(main): Reorganize to give a list of input files to read and to
	write to an output file, have the test read the input files, write
	them, and diff the two.
2013-03-25 16:56:00 +01:00
Dodji Seketeli
298f19389d Update tests/data/test-read-write/input0.xml
* tests/data/test-read-write/input0.xml: Make this identical to
	how it would look like when serialized.
2013-03-22 17:17:57 +01:00
Dodji Seketeli
fc27d10cee Debugged type-decl de-serialization
* src/abg-ir.cc (namespace_decl::~namespace_decl): Add this
	missing virtual constructor definition.
	* src/abg-reader.cc (read_context::{get_cur_decl,pop_decl}):
	Return a null pointer when the decls stack is empty.
	(update_read_context): Don't try to de-reference a NULL cur_decl.
	(read_input): Don't try to poke at file validity here.  What was I
	thinking.  Really test for advance_cursor to return 1, expressing
	success.
	* src/abg-reader.h (read_file):  Fix style.
	* Makefile.am: Add tests sub-directory.
	* configure.ac: Build with debugging-friendly options if the
	ABIGAIL_DEBUG env variable is set.  Generate tests/Makefile.
	* tests/Makefile.am: New file.
	* tests/test-read-write.cc: Likewise.
	* tests/test-utils.{h,cc}: Likewise.
	* tests/data/test-read-write/input0.xml: Likewise.
2013-03-21 23:57:22 +01:00