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-2025 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 
16 namespace abigail
17 {
18 /// Namespace for hashing.
19 namespace 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.
30  ///
31  /// Note that when a type_or_decl_base::priv::set_hash_value is
32  /// invoked on an artifact which has this state, then the hash value
33  /// is set/saved onto the artifact.
35 
36  /// A cycle has been detected in the graph on the current node node.
37  ///
38  /// This means the hashing has started on the current IR node and
39  /// while hashing its children nodes, this very same IR node is
40  /// visited again to be hashed. This is a cycle and it needs to be
41  /// broken otherwise the hashing continues forever.
42  ///
43  /// Note that when a type_or_decl_base::priv::set_hash_value is
44  /// invoked on an artifact which has this state, then the hash value
45  /// is set/saved onto the artifact.
47 
48  /// Hashing a sub-type while hashing another type.
49  ///
50  /// When a type_or_decl_base::hash_value() is invoked on an artifact
51  /// which has this state, it means the hash value that is computed
52  /// must NOT be set/saved onto the
53  /// artifact. type_or_decl_base::priv::set_hash_value is where this
54  /// is enforced.
56 
57  /// Hashing of given IR node started and is now done. If an ABI
58  /// artifact is in this state, then it must have an hash value
59  /// available and should be get by peek_hash_value or
60  /// type_or_decl_base::hash_value().
62 };
63 
64 bool
65 deserialize_hash(const string& input, uint64_t& hash);
66 
67 bool
68 serialize_hash(uint64_t hash, string& output);
69 
70 hash_t
72 
73 uint32_t
74 fnv_hash(const std::string& str);
75 
76 hash_t
77 hash(std::uint64_t v, std::uint64_t seed = 0);
78 
79 hash_t
80 hash(const std::string& str);
81 
84 
85 void
88 
89 bool
91 
92 void
94 }//end namespace hashing
95 
96 namespace ir
97 {
98 
100 {
101  hash_t
102  operator()(const decl_base& d) const;
103 
104  hash_t
105  operator()(const decl_base* d) const;
106 }; // end struct decl_base::hash
107 
108 
109 /// Hash functor for instances of @ref type_base.
111 {
112  hash_t
113  operator()(const type_base& t) const;
114 
115  hash_t
116  operator()(const type_base* t) const;
117 
118  hash_t
119  operator()(const type_base_sptr t) const;
120 }; // end struct type_base::hash
121 
122 /// Hash functor for instances of @ref type_decl.
124 {
125  hash_t
126  operator()(const type_decl& t) const;
127 
128  hash_t
129  operator()(const type_decl* t) const;
130 }; // end struct type_decl::hash
131 
132 /// Hash functor for instances of @ref qualified_type_def.
134 {
135  hash_t
136  operator()(const qualified_type_def& t) const;
137 
138  hash_t
139  operator()(const qualified_type_def* t) const;
140 }; // end struct qualified_type_def::hash
141 
142 /// Hash functor for instances of @ref pointer_type_def.
144 {
145  hash_t
146  operator()(const pointer_type_def& t) const;
147 
148  hash_t
149  operator()(const pointer_type_def* t) const;
150 }; // end struct pointer_type_def::hash
151 
152 /// Hash functor for instances of @ref reference_type_def.
154 {
155  hash_t
156  operator()(const reference_type_def& t) const;
157 
158  hash_t
159  operator()(const reference_type_def* t) const;
160 }; // end struct reference_type_def::hash
161 
162 /// Hash functor for instances of @ref ptr_to_mbr_type.
164 {
165  hash_t
166  operator() (const ptr_to_mbr_type& t) const;
167 
168  hash_t
169  operator() (const ptr_to_mbr_type* t) const;
170 
171  hash_t
172  operator() (const ptr_to_mbr_type_sptr& t) const;
173 }; // end reference_type_def::hash
174 
175 /// Hash functor for instances of @ref array_type_def::subrange_type
177 {
178  hash_t
179  operator()(const array_type_def::subrange_type& s) const;
180 
181  hash_t
182  operator()(const array_type_def::subrange_type* s) const;
183 };// end struct array_type_def::subrange_type::hash
184 
185 /// Hash functor for instances of @ref array_type_def::hash
187 {
188  hash_t
189  operator()(const array_type_def& t) const;
190 
191  hash_t
192  operator()(const array_type_def* t) const;
193 }; //end struct array_type_def::hash
194 
195 /// Hash functor for instances of @ref enum_type_decl
197 {
198  hash_t
199  operator()(const enum_type_decl& t) const;
200 
201  hash_t
202  operator()(const enum_type_decl* t) const;
203 };// end struct enum_type_decl::hash
204 
205 /// Hash functor for instances of @ref typedef_decl
207 {
208  hash_t
209  operator()(const typedef_decl& t) const;
210 
211  hash_t
212  operator()(const typedef_decl* t) const;
213 };// end struct typedef_decl::hash
214 
215 /// The hashing functor for @ref function_type.
217 {
218  hash_t
219  operator()(const function_type& t) const;
220 
221  hash_t
222  operator()(const function_type* t) const;
223 
224  hash_t
225  operator()(const function_type_sptr t) const;
226 };// end struct function_type::hash
227 
228 /// Hashing functor for the @ref method_type type.
230 {
231  hash_t
232  operator()(const method_type& t) const;
233 
234  hash_t
235  operator()(const method_type* t) const;
236 
237  hash_t
238  operator()(const method_type_sptr t) const;
239 }; // end struct method_type::hash
240 
241 /// The hashing functor for member_base.
243 {
244  hash_t
245  operator()(const member_base& m) const;
246 };
247 
248 /// Hasher for the @ref class_or_union type
250 {
251  hash_t
252  operator()(const class_or_union& t) const;
253 
254  hash_t
255  operator()(const class_or_union* t) const;
256 }; // end struct class_decl::hash
257 
258 /// The hashing functor for class_decl::base_spec.
260 {
261  hash_t
262  operator()(const base_spec& t) const;
263 
264  hash_t
265  operator()(const base_spec* t) const;
266 };
267 
268 /// Hasher for the @ref class_decl type
270 {
271  hash_t
272  operator()(const class_decl& t) const;
273 
274  hash_t
275  operator()(const class_decl* t) const;
276 }; // end struct class_decl::hash
277 
278 /// Hash functor for instances of @ref union_decl type.
280 {
281  hash_t
282  operator()(const union_decl&) const;
283 
284  hash_t
285  operator()(const union_decl*) const;
286 };//end struct union_decl::hash
287 
288 }// end namespace ir
289 }//end namespace abigail
290 
291 #endif //__ABG_HASH_H__
The abstraction of an array type.
Definition: abg-ir.h:2547
The base type of all declarations.
Definition: abg-ir.h:1584
Hash functor for instances of enum_type_decl.
Definition: abg-hash.h:196
Hashing started but is not yet finished.
Definition: abg-hash.h:34
hash_t operator()(const member_base &m) const
Hashing function for a member_base IR node.
Definition: abg-hash.cc:1001
shared_ptr< function_type > function_type_sptr
Convenience typedef for a shared pointer on a function_type.
Definition: abg-fwd.h:208
An abstraction helper for type declarations.
Definition: abg-ir.h:2002
shared_ptr< method_type > method_type_sptr
Convenience typedef for shared pointer to method_type.
Definition: abg-fwd.h:218
The base class of both types and declarations.
Definition: abg-ir.h:1405
Hasher for the class_or_union type.
Definition: abg-hash.h:249
Abstracts a reference type.
Definition: abg-ir.h:2415
The abstraction of a qualified type.
Definition: abg-ir.h:2235
Abstraction of a base specifier in a class declaration.
Definition: abg-ir.h:4362
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
Abstracts the type of a class member function.
Definition: abg-ir.h:3505
A cycle has been detected in the graph on the current node node.
Definition: abg-hash.h:46
Abstracts a class declaration.
Definition: abg-ir.h:4173
Hash functor for instances of pointer_type_def.
Definition: abg-hash.h:143
Hash functor for instances of union_decl type.
Definition: abg-hash.h:279
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
Hash functor for instances of type_decl.
Definition: abg-hash.h:123
bool is_recursive_artefact(const type_or_decl_base &t)
Test if an artifact is recursive.
Definition: abg-hash.cc:302
Abstracts a declaration for an enum type.
Definition: abg-ir.h:2784
Toplevel namespace for libabigail.
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:237
No hashing has been done/started.
Definition: abg-hash.h:27
Hash functor for instances of reference_type_def.
Definition: abg-hash.h:153
uint32_t fnv_hash(const std::string &str)
Compute a stable string hash.
Definition: abg-hash.cc:241
Abstracts a union type declaration.
Definition: abg-ir.h:4421
The abstraction of a pointer-to-member type.
Definition: abg-ir.h:2483
Hash functor for instances of qualified_type_def.
Definition: abg-hash.h:133
Types of the main internal representation of libabigail.
The base type of class_decl and union_decl.
Definition: abg-ir.h:3976
The hashing functor for function_type.
Definition: abg-hash.h:216
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
Hash functor for instances of type_base.
Definition: abg-hash.h:110
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
The abstraction of a pointer type.
Definition: abg-ir.h:2349
Hash functor for instances of typedef_decl.
Definition: abg-hash.h:206
A basic type declaration that introduces no scope.
Definition: abg-ir.h:2117
Hasher for the class_decl type.
Definition: abg-hash.h:269
Hashing a sub-type while hashing another type.
Definition: abg-hash.h:55
The base class for member types, data members and member functions. Its purpose is mainly to carry th...
Definition: abg-ir.h:3838
Hash functor for instances of array_type_def::hash.
Definition: abg-hash.h:186
Abstraction for an array range type, like in Ada, or just for an array dimension like in C or C++...
Definition: abg-ir.h:2573
Hashing functor for the method_type type.
Definition: abg-hash.h:229
Hashing of given IR node started and is now done. If an ABI artifact is in this state, then it must have an hash value available and should be get by peek_hash_value or type_or_decl_base::hash_value().
Definition: abg-hash.h:61
The hashing functor for class_decl::base_spec.
Definition: abg-hash.h:259
Hash functor for instances of array_type_def::subrange_type.
Definition: abg-hash.h:176
The hashing functor for member_base.
Definition: abg-hash.h:242
The abstraction of a typedef declaration.
Definition: abg-ir.h:2934
Hash functor for instances of ptr_to_mbr_type.
Definition: abg-hash.h:163
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
hashing_state
Enumeration of the different hashing states of an IR node being hashed.
Definition: abg-hash.h:24
Abstraction of a function type.
Definition: abg-ir.h:3419
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