libabigail
abg-hash.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2// -*- mode: C++ -*-
3//
4// Copyright (C) 2013-2024 Red Hat, Inc.
5
6/// @file
7
8#ifndef __ABG_HASH_H__
9#define __ABG_HASH_H__
10
11#include <cstdint>
12#include <cstddef>
13#include <string>
14#include "abg-ir.h"
15
16namespace abigail
17{
18/// Namespace for hashing.
19namespace hashing
20{
21
22/// Enumeration of the different hashing states of an IR node being
23/// hashed.
25{
26 /// No hashing has been done/started.
28
29 /// Hashing started but is not yet finished.
31
32 /// A cycle has been detected in the graph on the current node node.
33 ///
34 /// This means the hashing has started on the current IR node and
35 /// while hashing its children nodes, this very same IR node is
36 /// visited again to be hashed. This is a cycle and it needs to be
37 /// broken otherwise the hashing continues forever.
39
40 /// Hashing of given IR node started and is now done.
42};
43
44bool
45deserialize_hash(const string& input, uint64_t& hash);
46
47bool
48serialize_hash(uint64_t hash, string& output);
49
52
54fnv_hash(const std::string& str);
55
57hash(std::uint64_t v, std::uint64_t seed = 0);
58
60hash(const std::string& str);
61
64
65void
68
69bool
71
72void
74}//end namespace hashing
75
76namespace ir
77{
78
80{
81 hash_t
82 operator()(const decl_base& d) const;
83
84 hash_t
85 operator()(const decl_base* d) const;
86}; // end struct decl_base::hash
87
88
89/// Hash functor for instances of @ref type_base.
91{
92 hash_t
93 operator()(const type_base& t) const;
94
95 hash_t
96 operator()(const type_base* t) const;
97
98 hash_t
99 operator()(const type_base_sptr t) const;
100}; // end struct type_base::hash
101
102/// Hash functor for instances of @ref type_decl.
104{
105 hash_t
106 operator()(const type_decl& t) const;
107
108 hash_t
109 operator()(const type_decl* t) const;
110}; // end struct type_decl::hash
111
112/// Hash functor for instances of @ref qualified_type_def.
114{
115 hash_t
116 operator()(const qualified_type_def& t) const;
117
118 hash_t
119 operator()(const qualified_type_def* t) const;
120}; // end struct qualified_type_def::hash
121
122/// Hash functor for instances of @ref pointer_type_def.
124{
125 hash_t
126 operator()(const pointer_type_def& t) const;
127
128 hash_t
129 operator()(const pointer_type_def* t) const;
130}; // end struct pointer_type_def::hash
131
132/// Hash functor for instances of @ref reference_type_def.
134{
135 hash_t
136 operator()(const reference_type_def& t) const;
137
138 hash_t
139 operator()(const reference_type_def* t) const;
140}; // end struct reference_type_def::hash
141
142/// Hash functor for instances of @ref ptr_to_mbr_type.
144{
145 hash_t
146 operator() (const ptr_to_mbr_type& t) const;
147
148 hash_t
149 operator() (const ptr_to_mbr_type* t) const;
150
151 hash_t
152 operator() (const ptr_to_mbr_type_sptr& t) const;
153}; // end reference_type_def::hash
154
155/// Hash functor for instances of @ref array_type_def::subrange_type
157{
158 hash_t
159 operator()(const array_type_def::subrange_type& s) const;
160
161 hash_t
162 operator()(const array_type_def::subrange_type* s) const;
163};// end struct array_type_def::subrange_type::hash
164
165/// Hash functor for instances of @ref array_type_def::hash
167{
168 hash_t
169 operator()(const array_type_def& t) const;
170
171 hash_t
172 operator()(const array_type_def* t) const;
173}; //end struct array_type_def::hash
174
175/// Hash functor for instances of @ref enum_type_decl
177{
178 hash_t
179 operator()(const enum_type_decl& t) const;
180
181 hash_t
182 operator()(const enum_type_decl* t) const;
183};// end struct enum_type_decl::hash
184
185/// Hash functor for instances of @ref typedef_decl
187{
188 hash_t
189 operator()(const typedef_decl& t) const;
190
191 hash_t
192 operator()(const typedef_decl* t) const;
193};// end struct typedef_decl::hash
194
195/// The hashing functor for @ref function_type.
197{
198 hash_t
199 operator()(const function_type& t) const;
200
201 hash_t
202 operator()(const function_type* t) const;
203
204 hash_t
205 operator()(const function_type_sptr t) const;
206};// end struct function_type::hash
207
208/// Hashing functor for the @ref method_type type.
210{
211 hash_t
212 operator()(const method_type& t) const;
213
214 hash_t
215 operator()(const method_type* t) const;
216
217 hash_t
218 operator()(const method_type_sptr t) const;
219}; // end struct method_type::hash
220
221/// The hashing functor for member_base.
223{
224 hash_t
225 operator()(const member_base& m) const;
226};
227
228/// Hasher for the @ref class_or_union type
230{
231 hash_t
232 operator()(const class_or_union& t) const;
233
234 hash_t
235 operator()(const class_or_union* t) const;
236}; // end struct class_decl::hash
237
238/// The hashing functor for class_decl::base_spec.
240{
241 hash_t
242 operator()(const base_spec& t) const;
243
244 hash_t
245 operator()(const base_spec* t) const;
246};
247
248/// Hasher for the @ref class_decl type
250{
251 hash_t
252 operator()(const class_decl& t) const;
253
254 hash_t
255 operator()(const class_decl* t) const;
256}; // end struct class_decl::hash
257
258/// Hash functor for instances of @ref union_decl type.
260{
261 hash_t
262 operator()(const union_decl&) const;
263
264 hash_t
265 operator()(const union_decl*) const;
266};//end struct union_decl::hash
267
268}// end namespace ir
269}//end namespace abigail
270
271#endif //__ABG_HASH_H__
Types of the main internal representation of libabigail.
Abstraction for an array range type, like in Ada, or just for an array dimension like in C or C++.
Definition: abg-ir.h:2545
The abstraction of an array type.
Definition: abg-ir.h:2519
Abstraction of a base specifier in a class declaration.
Definition: abg-ir.h:4314
Abstracts a class declaration.
Definition: abg-ir.h:4127
The base type of class_decl and union_decl.
Definition: abg-ir.h:3929
The base type of all declarations.
Definition: abg-ir.h:1556
Abstracts a declaration for an enum type.
Definition: abg-ir.h:2756
Abstraction of a function type.
Definition: abg-ir.h:3372
The base class for member types, data members and member functions. Its purpose is mainly to carry th...
Definition: abg-ir.h:3791
Abstracts the type of a class member function.
Definition: abg-ir.h:3458
The abstraction of a pointer type.
Definition: abg-ir.h:2321
The abstraction of a pointer-to-member type.
Definition: abg-ir.h:2456
The abstraction of a qualified type.
Definition: abg-ir.h:2207
Abstracts a reference type.
Definition: abg-ir.h:2387
An abstraction helper for type declarations.
Definition: abg-ir.h:1974
A basic type declaration that introduces no scope.
Definition: abg-ir.h:2089
The base class of both types and declarations.
Definition: abg-ir.h:1377
The abstraction of a typedef declaration.
Definition: abg-ir.h:2898
Abstracts a union type declaration.
Definition: abg-ir.h:4372
hash_t combine_hashes(hash_t val1, hash_t val2)
Combine two hash values to produce a third hash value.
Definition: abg-hash.cc:172
hashing::hashing_state get_hashing_state(const type_or_decl_base &tod)
Get the hashing state of an IR node.
Definition: abg-hash.cc:261
void set_hashing_state(const type_or_decl_base &tod, hashing::hashing_state s)
Set the hashing state of an IR node.
Definition: abg-hash.cc:280
hash_t hash(uint64_t v, uint64_t seed)
Hash an integer value and combine it with a hash previously computed.
Definition: abg-hash.cc:196
hashing_state
Enumeration of the different hashing states of an IR node being hashed.
Definition: abg-hash.h:25
@ HASHING_STARTED_STATE
Hashing started but is not yet finished.
Definition: abg-hash.h:30
@ HASHING_FINISHED_STATE
Hashing of given IR node started and is now done.
Definition: abg-hash.h:41
@ HASHING_CYCLED_TYPE_STATE
A cycle has been detected in the graph on the current node node.
Definition: abg-hash.h:38
@ HASHING_NOT_DONE_STATE
No hashing has been done/started.
Definition: abg-hash.h:27
bool deserialize_hash(const string &input, uint64_t &hash)
Read a string of characters representing a string of hexadecimal digits which itself represents a has...
Definition: abg-hash.cc:99
bool serialize_hash(uint64_t hash, string &output)
Serialiaze a hash value computed using the XH64 algorithm (from the xxhash project) into a string of ...
Definition: abg-hash.cc:138
uint32_t fnv_hash(const std::string &str)
Compute a stable string hash.
Definition: abg-hash.cc:241
bool is_recursive_artefact(const type_or_decl_base &t)
Test if an artifact is recursive.
Definition: abg-hash.cc:302
shared_ptr< method_type > method_type_sptr
Convenience typedef for shared pointer to method_type.
Definition: abg-fwd.h:221
shared_ptr< function_type > function_type_sptr
Convenience typedef for a shared pointer on a function_type.
Definition: abg-fwd.h:210
shared_ptr< ptr_to_mbr_type > ptr_to_mbr_type_sptr
Convenience typedef for a shared pointer to a ptr_to_mbr_type.
Definition: abg-fwd.h:239
Toplevel namespace for libabigail.
Hash functor for instances of array_type_def::hash.
Definition: abg-hash.h:167
hash_t operator()(const array_type_def &t) const
Hashing function for a array_type_def IR node.
Definition: abg-hash.cc:684
Hash functor for instances of array_type_def::subrange_type.
Definition: abg-hash.h:157
The hashing functor for class_decl::base_spec.
Definition: abg-hash.h:240
hash_t operator()(const base_spec &t) const
Hashing function for a class_decl::base_spec IR node.
Definition: abg-hash.cc:960
Hasher for the class_decl type.
Definition: abg-hash.h:250
hash_t operator()(const class_decl &t) const
Compute a hash for a class_decl.
Definition: abg-hash.cc:1046
Hasher for the class_or_union type.
Definition: abg-hash.h:230
hash_t operator()(const class_or_union &t) const
Compute a hash for a class_or_union.
Definition: abg-hash.cc:999
hash_t operator()(const decl_base &d) const
Hash function for an instance of decl_base.
Definition: abg-hash.cc:421
Hash functor for instances of enum_type_decl.
Definition: abg-hash.h:177
hash_t operator()(const enum_type_decl &t) const
Hashing function for a enum_type_decl IR node.
Definition: abg-hash.cc:785
The hashing functor for function_type.
Definition: abg-hash.h:197
hash_t operator()(const function_type &t) const
Hashing function for function_type.
Definition: abg-hash.cc:841
The hashing functor for member_base.
Definition: abg-hash.h:223
hash_t operator()(const member_base &m) const
Hashing function for a member_base IR node.
Definition: abg-hash.cc:949
Hashing functor for the method_type type.
Definition: abg-hash.h:210
hash_t operator()(const method_type &t) const
Hashing function for a method_type IR node.
Definition: abg-hash.cc:897
Hash functor for instances of pointer_type_def.
Definition: abg-hash.h:124
hash_t operator()(const pointer_type_def &t) const
Hashing function for a pointer_type_def IR node.
Definition: abg-hash.cc:573
Hash functor for instances of ptr_to_mbr_type.
Definition: abg-hash.h:144
hash_t operator()(const ptr_to_mbr_type &t) const
Hashing function for a ptr_to_mbr_type IR node.
Definition: abg-hash.cc:734
Hash functor for instances of qualified_type_def.
Definition: abg-hash.h:114
hash_t operator()(const qualified_type_def &t) const
Hashing function for a qualified_type_def IR node.
Definition: abg-hash.cc:533
Hash functor for instances of reference_type_def.
Definition: abg-hash.h:134
hash_t operator()(const reference_type_def &t) const
Hashing function for a reference_type_def IR node.
Definition: abg-hash.cc:612
Hash functor for instances of type_base.
Definition: abg-hash.h:91
hash_t operator()(const type_base &t) const
The hashing functor for using instances of type_or_decl_base as values in a hash map or set.
Definition: abg-hash.cc:390
Hash functor for instances of type_decl.
Definition: abg-hash.h:104
hash_t operator()(const type_decl &t) const
Hashing function for a type_decl IR node.
Definition: abg-hash.cc:459
Hash functor for instances of typedef_decl.
Definition: abg-hash.h:187
hash_t operator()(const typedef_decl &t) const
Hashing function for a typedef_decl IR node.
Definition: abg-hash.cc:497
Hash functor for instances of union_decl type.
Definition: abg-hash.h:260