9 #include "abg-internal.h"
11 ABG_BEGIN_EXPORT_DECLARATIONS
26 #define abigail_hash_mix(a, b, c) \
28 a -= b; a -= c; a ^= (c>>13); \
29 b -= c; b -= a; b ^= (a<< 8); \
30 c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
31 a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
32 b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
33 c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
34 a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
35 b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
36 c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
40 combine_hashes(
size_t val1,
size_t val2)
43 size_t a = 0x9e3779b9;
44 abigail_hash_mix(a, val1, val2);
66 const uint32_t prime = 0x01000193;
67 const uint32_t offset_basis = 0x811c9dc5;
68 uint32_t hash = offset_basis;
69 for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
95 type_base::hash::operator()(
const type_base& t)
const
97 std::hash<size_t> size_t_hash;
98 std::hash<string> str_hash;
100 size_t v = str_hash(
typeid(t).name());
113 type_base::hash::operator()(
const type_base* t)
const
114 {
return operator()(*t);}
122 type_base::hash::operator()(
const type_base_sptr t)
const
123 {
return operator()(*t);}
125 struct decl_base::hash
130 std::hash<string> str_hash;
132 size_t v = str_hash(
typeid(d).name());
146 struct type_decl::hash
151 decl_base::hash decl_hash;
153 std::hash<string> str_hash;
155 size_t v = str_hash(
typeid(t).name());
156 v = hashing::combine_hashes(v, decl_hash(t));
157 v = hashing::combine_hashes(v, type_hash(t));
169 scope_decl::hash::operator()(
const scope_decl& d)
const
171 std::hash<string> hash_string;
172 size_t v = hash_string(
typeid(d).name());
173 for (scope_decl::declarations::const_iterator i =
177 v = hashing::combine_hashes(v, (*i)->get_hash());
188 scope_decl::hash::operator()(
const scope_decl* d)
const
189 {
return d? operator()(*d) : 0;}
191 struct scope_type_decl::hash
196 decl_base::hash decl_hash;
198 std::hash<string> str_hash;
200 size_t v = str_hash(
typeid(t).name());
201 v = hashing::combine_hashes(v, decl_hash(t));
202 v = hashing::combine_hashes(v, type_hash(t));
208 struct qualified_type_def::hash
214 decl_base::hash decl_hash;
215 std::hash<string> str_hash;
217 size_t v = str_hash(
typeid(t).name());
218 v = hashing::combine_hashes(v, type_hash(t));
219 v = hashing::combine_hashes(v, decl_hash(t));
225 struct pointer_type_def::hash
230 std::hash<string> str_hash;
232 decl_base::hash decl_hash;
235 size_t v = str_hash(
typeid(t).name());
236 v = hashing::combine_hashes(v, decl_hash(t));
237 v = hashing::combine_hashes(v, type_base_hash(t));
243 struct reference_type_def::hash
248 std::hash<string> hash_str;
250 decl_base::hash hash_decl;
253 size_t v = hash_str(
typeid(t).name());
254 v = hashing::combine_hashes(v, hash_str(t.is_lvalue()
257 v = hashing::combine_hashes(v, hash_type_base(t));
258 v = hashing::combine_hashes(v, hash_decl(t));
259 v = hashing::combine_hashes(v, hash_type_ptr(t.get_pointed_to_type()));
264 struct array_type_def::subrange_type::hash
269 std::hash<int> hash_size_t;
276 struct array_type_def::hash
281 std::hash<string> hash_str;
283 decl_base::hash hash_decl;
285 array_type_def::subrange_type::hash hash_subrange;
287 size_t v = hash_str(
typeid(t).name());
289 v = hashing::combine_hashes(v, hash_type_base(t));
290 v = hashing::combine_hashes(v, hash_decl(t));
293 for (vector<array_type_def::subrange_sptr >::const_iterator i =
297 v = hashing::combine_hashes(v, hash_subrange(**i));
303 struct enum_type_decl::hash
308 std::hash<string> str_hash;
309 decl_base::hash decl_hash;
311 std::hash<size_t> size_t_hash;
313 size_t v = str_hash(
typeid(t).name());
314 v = hashing::combine_hashes(v, decl_hash(t));
316 for (enum_type_decl::enumerators::const_iterator i =
321 v = hashing::combine_hashes(v, str_hash(i->get_name()));
322 v = hashing::combine_hashes(v, size_t_hash(i->get_value()));
328 struct typedef_decl::hash
333 std::hash<string> str_hash;
335 decl_base::hash decl_hash;
338 size_t v = str_hash(
typeid(t).name());
339 v = hashing::combine_hashes(v,
hash_type(t));
340 v = hashing::combine_hashes(v, decl_hash(t));
357 var_decl::hash::operator()(
const var_decl& t)
const
359 std::hash<string> hash_string;
360 decl_base::hash hash_decl;
362 std::hash<size_t> hash_size_t;
364 size_t v = hash_string(
typeid(t).name());
365 v = hashing::combine_hashes(v, hash_decl(t));
366 v = hashing::combine_hashes(v, hash_type_ptr(t.
get_type()));
370 v = hashing::combine_hashes(v, hash_decl(*t.
get_scope()));
383 var_decl::hash::operator()(
const var_decl* t)
const
384 {
return operator()(*t);}
398 std::hash<int> hash_int;
399 std::hash<size_t> hash_size_t;
400 std::hash<bool> hash_bool;
401 std::hash<string> hash_string;
402 decl_base::hash hash_decl_base;
405 size_t v = hash_string(
typeid(t).name());
406 v = hashing::combine_hashes(v, hash_decl_base(t));
407 v = hashing::combine_hashes(v, hash_type_ptr(t.
get_type()));
408 v = hashing::combine_hashes(v, hash_bool(t.is_declared_inline()));
409 v = hashing::combine_hashes(v, hash_int(t.get_binding()));
418 v = hashing::combine_hashes(v, hash_bool(is_ctor));
419 v = hashing::combine_hashes(v, hash_bool(is_dtor));
420 v = hashing::combine_hashes(v, hash_bool(is_static));
421 v = hashing::combine_hashes(v, hash_bool(is_const));
422 if (!is_static && !is_ctor)
423 v = hashing::combine_hashes(v, hash_size_t(voffset));
436 {
return operator()(*t);}
439 function_decl::parameter::hash::operator()
443 std::hash<bool> hash_bool;
444 std::hash<unsigned> hash_unsigned;
445 size_t v = hash_type_ptr(p.get_type());
446 v = hashing::combine_hashes(v, hash_unsigned(p.get_index()));
447 v = hashing::combine_hashes(v, hash_bool(p.get_variadic_marker()));
452 function_decl::parameter::hash::operator()
454 {
return operator()(*p);}
457 function_decl::parameter::hash::operator()
459 {
return operator()(p.get());}
462 struct method_type::hash
467 std::hash<string> hash_string;
471 size_t v = hash_string(
typeid(t).name());
473 v = hashing::combine_hashes(v, hash_string(class_name));
475 vector<shared_ptr<function_decl::parameter> >::const_iterator i =
479 v = hashing::combine_hashes(v, hash_parameter(**i));
486 {
return operator()(*t);}
490 {
return operator()(t.get());}
501 function_type::hash::operator()(
const function_type& t)
const
503 std::hash<string> hash_string;
507 size_t v = hash_string(
typeid(t).name());
509 for (vector<shared_ptr<function_decl::parameter> >::const_iterator i =
513 v = hashing::combine_hashes(v, hash_parameter(**i));
523 function_type::hash::operator()(
const function_type* t)
const
525 if (
const method_type* m = dynamic_cast<const method_type*>(t))
530 return operator()(*t);
540 {
return operator()(t.get());}
545 member_base::hash::operator()(
const member_base& m)
const
547 std::hash<int> hash_int;
552 class_decl::base_spec::hash::operator()(
const base_spec& t)
const
556 std::hash<size_t> hash_size;
557 std::hash<bool> hash_bool;
558 std::hash<string> hash_string;
560 size_t v = hash_string(
typeid(t).name());
561 v = hashing::combine_hashes(v, hash_member(t));
562 v = hashing::combine_hashes(v, hash_size(t.get_offset_in_bits()));
563 v = hashing::combine_hashes(v, hash_bool(t.get_is_virtual()));
564 v = hashing::combine_hashes(v, hash_type_ptr(t.get_base_class()));
569 member_function_template::hash::operator()
572 std::hash<bool> hash_bool;
575 std::hash<string> hash_string;
577 size_t v = hash_member(t);
578 string n = t.get_qualified_name();
579 v = hashing::combine_hashes(v, hash_string(n));
580 v = hashing::combine_hashes(v, hash_function_tdecl(t));
581 v = hashing::combine_hashes(v, hash_bool(t.is_constructor()));
582 v = hashing::combine_hashes(v, hash_bool(t.is_const()));
587 member_class_template::hash::operator()
592 std::hash<string> hash_string;
594 size_t v = hash_member(t);
595 string n = t.get_qualified_name();
596 v = hashing::combine_hashes(v, hash_string(n));
597 v = hashing::combine_hashes(v, hash_class_tdecl(t));
623 size_t v = operator()
630 std::hash<string> hash_string;
631 scope_type_decl::hash hash_scope_type;
636 size_t v = hash_string(
typeid(t).name());
637 v = hashing::combine_hashes(v, hash_scope_type(t));
642 for (class_decl::data_members::const_iterator d =
646 v = hashing::combine_hashes(v, hash_data_member(**d));
653 for (member_function_templates::const_iterator f =
657 v = hashing::combine_hashes(v, hash_member_fn_tmpl(**f));
660 for (member_class_templates::const_iterator c =
664 v = hashing::combine_hashes(v, hash_member_class_tmpl(**c));
678 {
return t ? operator()(*t) : 0;}
686 class_decl::hash::operator()(
const class_decl& t)
const
709 std::hash<string> hash_string;
713 size_t v = hash_string(
typeid(t).name());
718 for (class_decl::base_specs::const_iterator b =
724 v = hashing::combine_hashes(v, hash_base(**b));
727 v = hashing::combine_hashes(v, hash_class_or_union(t));
740 class_decl::hash::operator()(
const class_decl* t)
const
741 {
return t ? operator()(*t) : 0;}
743 struct template_parameter::hash
753 if (t.get_hashing_has_started())
756 t.set_hashing_has_started(
true);
758 std::hash<unsigned> hash_unsigned;
759 std::hash<std::string> hash_string;
762 size_t v = hash_string(
typeid(t).name());
763 v = hashing::combine_hashes(v, hash_unsigned(t.get_index()));
764 v = hashing::combine_hashes(v, hash_template_decl
765 (*t.get_enclosing_template_decl()));
767 t.set_hashing_has_started(
false);
773 struct template_parameter::dynamic_hash
779 struct template_parameter::shared_ptr_hash
782 operator()(
const shared_ptr<template_parameter> t)
const
783 {
return template_parameter::dynamic_hash()(t.get());}
787 template_decl::hash::operator()(
const template_decl& t)
const
789 std::hash<string> hash_string;
790 template_parameter::shared_ptr_hash hash_template_parameter;
792 size_t v = hash_string(
typeid(t).name());
795 for (list<template_parameter_sptr>::const_iterator p =
799 if (!(*p)->get_hashing_has_started())
800 v = hashing::combine_hashes(v, hash_template_parameter(*p));
805 struct type_tparameter::hash
810 std::hash<string> hash_string;
811 template_parameter::hash hash_template_parameter;
814 size_t v = hash_string(
typeid(t).name());
815 v = hashing::combine_hashes(v, hash_template_parameter(t));
816 v = hashing::combine_hashes(v,
hash_type(t));
830 template_parameter::hash hash_template_parameter;
831 std::hash<string> hash_string;
834 size_t v = hash_string(
typeid(t).name());
835 v = hashing::combine_hashes(v, hash_template_parameter(t));
836 v = hashing::combine_hashes(v, hash_string(t.
get_name()));
849 {
return t ? operator()(*t) : 0;}
851 struct template_tparameter::hash
856 std::hash<string> hash_string;
857 type_tparameter::hash hash_template_type_parm;
860 size_t v = hash_string(
typeid(t).name());
861 v = hashing::combine_hashes(v, hash_template_type_parm(t));
862 v = hashing::combine_hashes(v, hash_template_decl(t));
869 template_parameter::dynamic_hash::
873 dynamic_cast<const template_tparameter*>(t))
874 return template_tparameter::hash()(*p);
876 dynamic_cast<const type_tparameter*>(t))
877 return type_tparameter::hash()(*p);
879 dynamic_cast<const non_type_tparameter*>(t))
883 return template_parameter::hash()(*t);
894 std::hash<string> hash_string;
897 size_t v = hash_string(
typeid(t).name());
909 {
return t ? operator()(*t): 0;}
912 function_tdecl::hash::
915 std::hash<string> hash_string;
916 decl_base::hash hash_decl_base;
920 size_t v = hash_string(
typeid(t).name());
922 v = hashing::combine_hashes(v, hash_decl_base(t));
923 v = hashing::combine_hashes(v, hash_template_decl(t));
925 v = hashing::combine_hashes(v, hash_function_decl(*t.
get_pattern()));
931 function_tdecl::shared_ptr_hash::
932 operator()(
const shared_ptr<function_tdecl> f)
const
936 return hash_fn_tmpl_decl(*f);
944 std::hash<string> hash_string;
945 decl_base::hash hash_decl_base;
949 size_t v = hash_string(
typeid(t).name());
950 v = hashing::combine_hashes(v, hash_decl_base(t));
951 v = hashing::combine_hashes(v, hash_template_decl(t));
953 v = hashing::combine_hashes(v, hash_class_decl(*t.
get_pattern()));
959 class_tdecl::shared_ptr_hash::
960 operator()(
const shared_ptr<class_tdecl> t)
const
965 return hash_class_tmpl_decl(*t);
994 dynamic_cast<const member_function_template*>(t))
997 dynamic_cast<const member_class_template*>(t))
1000 dynamic_cast<const template_tparameter*>(t))
1003 dynamic_cast<const type_tparameter*>(t))
1005 if (
const type_decl* d = dynamic_cast<const type_decl*> (t))
1013 if (
const array_type_def* d = dynamic_cast<const array_type_def*>(t))
1015 if (
const enum_type_decl* d = dynamic_cast<const enum_type_decl*>(t))
1017 if (
const typedef_decl* d = dynamic_cast<const typedef_decl*>(t))
1019 if (
const class_decl* d = dynamic_cast<const class_decl*>(t))
1021 if (
const union_decl* d = dynamic_cast<const union_decl*>(t))
1023 if (
const scope_type_decl* d = dynamic_cast<const scope_type_decl*>(t))
1025 if (
const method_type* d = dynamic_cast<const method_type*>(t))
1027 if (
const function_type* d = dynamic_cast<const function_type*>(t))
1035 type_base::shared_ptr_hash::operator()(
const shared_ptr<type_base> t)
const
size_t operator()(const type_base *t) const
A hashing function for type declarations.
const member_class_templates & get_member_class_templates() const
Get the member class templates of this class.
The abstraction of an array type.
The base type of all declarations.
const member_function_templates & get_member_function_templates() const
Get the member function templates of this class.
size_t operator()(const function_decl &t) const
Compute a hash value for an instance of function_decl.
Abstracts a member class template template.
A type that introduces a scope.
bool is_data_member(const var_decl &v)
Test if a var_decl is a data member.
shared_ptr< function_type > function_type_sptr
Convenience typedef for a shared pointer on a function_type.
bool is_member_function(const function_decl &f)
Test whether a function_decl is a member function.
An abstraction helper for type declarations.
shared_ptr< method_type > method_type_sptr
Convenience typedef for shared pointer to method_type.
const function_type_sptr get_type() const
Return the type of the current instance of function_decl.
A declaration that introduces a scope.
The hashing functor for member_function_template.
Hasher for the class_or_union type.
Abstracts a reference type.
The abstraction of a qualified type.
A hashing functor for a function_decl::parameter.
access_specifier get_member_access_specifier(const decl_base &d)
Gets the access specifier for a class member.
The base class of templates.
shared_ptr< function_decl > get_pattern() const
Get the pattern of the function template.
ssize_t get_member_function_vtable_offset(const function_decl &f)
Get the vtable offset of a member function.
const type_base_sptr get_composed_type() const
Getter for the resulting composed type.
parameters::const_iterator get_first_non_implicit_parm() const
Get the first parameter of the function.
bool empty() const
Test if the current instance of interned_string is empty.
Abstracts the type of a class member function.
bool is_member_decl(const decl_base_sptr d)
Tests if a declaration is a class member.
const type_base_sptr get_type() const
Getter for the type of the template parameter.
class_or_union * is_class_or_union_type(const type_or_decl_base *t)
Test if a type is a class_or_union.
const declarations & get_member_decls() const
Getter for the member declarations carried by the current scope_decl.
Abstracts a class declaration.
const interned_string & get_name() const
Getter for the name of the current decl.
CV get_cv_quals() const
Getter of the const/volatile qualifier bit field.
size_t hash_type(const type_base *t)
Hash an ABI artifact that is either a type.
bool hashing_started() const
Getter for the 'hashing_started' property.
class_or_union_sptr get_class_type() const
Get the class type this method belongs to.
Abstracts a variable declaration.
Abstract a class template.
bool get_member_function_is_dtor(const function_decl &f)
Test whether a member function is a destructor.
Abstraction of a function parameter.
Abstract a member function template.
access_specifier get_access_specifier() const
Getter for the access specifier of this member.
Abstracts a type template parameter.
shared_ptr< class_decl > get_pattern() const
Getter of the pattern of the template.
const data_members & get_non_static_data_members() const
Get the non-static data memebers of this class_or_union.
Abstracts a declaration for an enum type.
uint64_t get_data_member_offset(const var_decl &m)
Get the offset of a data member.
bool get_is_declaration_only() const
Test if a decl_base is a declaration-only decl.
Toplevel namespace for libabigail.
Hasher for the scope_decl type.
uint32_t fnv_hash(const std::string &str)
Compute a stable string hash.
Abstracts a union type declaration.
shared_ptr< parameter > parameter_sptr
Convenience typedef for a shared pointer on a function_decl::parameter.
virtual size_t get_size_in_bits() const
Getter for the size of the type.
scope_decl * get_scope() const
Return the type containing the current decl, if any.
type_base_sptr get_return_type() const
Getter for the return type of the current instance of function_type.
const parameters & get_parameters() const
Getter for the set of parameters of the current intance of function_type.
Abstraction for a function declaration.
Types of the main internal representation of libabigail.
const interned_string & get_linkage_name() const
Getter for the mangled name.
The base type of class_decl and union_decl.
A hashing functor fo instances and pointers of function_decl.
The hashing functor for function_type.
Abstracts non type template parameters.
type_base_sptr get_underlying_type() const
Getter of the underlying type of the typedef.
Abstract a function template declaration.
#define ABG_ASSERT(cond)
This is a wrapper around the 'assert' glibc call. It allows for its argument to have side effects...
Hash functor for instances of type_base.
bool get_data_member_is_laid_out(const var_decl &m)
Test whether a data member is laid out.
const std::vector< subrange_sptr > & get_subranges() const
Get the array's subranges.
Hasher for the non_type_tparameter type.
int64_t get_upper_bound() const
Getter of the upper bound of the subrange type.
const type_base_sptr get_type() const
Getter of the type of the variable.
The abstraction of a pointer type.
bool get_member_function_is_ctor(const function_decl &f)
Test whether a member function is a constructor.
A basic type declaration that introduces no scope.
shared_ptr< class_decl > class_decl_sptr
Convenience typedef for a shared pointer on a class_decl.
Hasher for the class_decl type.
virtual void get_qualified_name(interned_string &qualified_name, bool internal=false) const
Compute the qualified name of the decl.
A hashing functor for instances and pointers of var_decl.
const std::list< template_parameter_sptr > & get_template_parameters() const
Get the list of template parameters of the current instance of template_decl.
const type_base_sptr get_element_type() const
Getter of the type of an array element.
The base class for member types, data members and member functions. Its purpose is mainly to carry th...
const enumerators & get_enumerators() const
type_base_sptr get_underlying_type() const
Return the underlying type of the enum.
friend class_decl * is_class_type(const type_or_decl_base *)
Test whether a type is a class.
bool get_member_is_static(const decl_base &d)
Gets a flag saying if a class member is static or not.
Abstraction for an array range type, like in Ada, or just for an array dimension like in C or C++...
bool get_member_function_is_const(const function_decl &f)
Test whether a member function is const.
The hashing functor for class_decl::base_spec.
The hashing functor for member_class_template.
Abstracts a template template parameter.
The hashing functor for member_base.
The abstraction of a typedef declaration.
This abstracts a composition of types based on template type parameters. The result of the compositio...
const type_base_sptr get_pointed_to_type() const
Getter of the pointed-to type.
virtual size_t get_alignment_in_bits() const
Getter for the alignment of the type.
int64_t get_lower_bound() const
Getter of the lower bound of the subrange type.
Base class for a template parameter. Client code should use the more specialized type_template_parame...
The namespace of the internal representation of ABI artifacts like types and decls.
const decl_base_sptr get_definition_of_declaration() const
If this decl_base is declaration-only, get its definition, if any.
Abstraction of a function type.
const base_specs & get_base_specifiers() const
Get the base specifiers for this class.