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
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.
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
64bool
65deserialize_hash(const string& input, uint64_t& hash);
66
67bool
68serialize_hash(uint64_t hash, string& output);
69
72
74fnv_hash(const std::string& str);
75
77hash(std::uint64_t v, std::uint64_t seed = 0);
78
80hash(const std::string& str);
81
84
85void
88
89bool
91
92void
94}//end namespace hashing
95
96namespace 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__
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:2574
The abstraction of an array type.
Definition: abg-ir.h:2548
Abstraction of a base specifier in a class declaration.
Definition: abg-ir.h:4362
Abstracts a class declaration.
Definition: abg-ir.h:4175
The base type of class_decl and union_decl.
Definition: abg-ir.h:3977
The base type of all declarations.
Definition: abg-ir.h:1585
Abstracts a declaration for an enum type.
Definition: abg-ir.h:2785
Abstraction of a function type.
Definition: abg-ir.h:3420
The base class for member types, data members and member functions. Its purpose is mainly to carry th...
Definition: abg-ir.h:3839
Abstracts the type of a class member function.
Definition: abg-ir.h:3506
The abstraction of a pointer type.
Definition: abg-ir.h:2350
The abstraction of a pointer-to-member type.
Definition: abg-ir.h:2485
The abstraction of a qualified type.
Definition: abg-ir.h:2236
Abstracts a reference type.
Definition: abg-ir.h:2416
An abstraction helper for type declarations.
Definition: abg-ir.h:2003
A basic type declaration that introduces no scope.
Definition: abg-ir.h:2118
The base class of both types and declarations.
Definition: abg-ir.h:1406
The abstraction of a typedef declaration.
Definition: abg-ir.h:2935
Abstracts a union type declaration.
Definition: abg-ir.h:4420
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:34
@ HASHING_FINISHED_STATE
Hashing of given IR node started and is now done. If an ABI artifact is in this state,...
Definition: abg-hash.h:61
@ HASHING_CYCLED_TYPE_STATE
A cycle has been detected in the graph on the current node node.
Definition: abg-hash.h:46
@ HASHING_SUBTYPE_STATE
Hashing a sub-type while hashing another type.
Definition: abg-hash.h:55
@ 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:187
hash_t operator()(const array_type_def &t) const
Hashing function for a array_type_def IR node.
Definition: abg-hash.cc:697
Hash functor for instances of array_type_def::subrange_type.
Definition: abg-hash.h:177
The hashing functor for class_decl::base_spec.
Definition: abg-hash.h:260
hash_t operator()(const base_spec &t) const
Hashing function for a class_decl::base_spec IR node.
Definition: abg-hash.cc:1012
Hasher for the class_decl type.
Definition: abg-hash.h:270
hash_t operator()(const class_decl &t) const
Compute a hash for a class_decl.
Definition: abg-hash.cc:1111
Hasher for the class_or_union type.
Definition: abg-hash.h:250
hash_t operator()(const class_or_union &t) const
Compute a hash for a class_or_union.
Definition: abg-hash.cc:1055
hash_t operator()(const decl_base &d) const
Hash function for an instance of decl_base.
Definition: abg-hash.cc:422
Hash functor for instances of enum_type_decl.
Definition: abg-hash.h:197
hash_t operator()(const enum_type_decl &t) const
Hashing function for a enum_type_decl IR node.
Definition: abg-hash.cc:814
The hashing functor for function_type.
Definition: abg-hash.h:217
hash_t operator()(const function_type &t) const
Hashing function for function_type.
Definition: abg-hash.cc:878
The hashing functor for member_base.
Definition: abg-hash.h:243
hash_t operator()(const member_base &m) const
Hashing function for a member_base IR node.
Definition: abg-hash.cc:1001
Hashing functor for the method_type type.
Definition: abg-hash.h:230
hash_t operator()(const method_type &t) const
Hashing function for a method_type IR node.
Definition: abg-hash.cc:941
Hash functor for instances of pointer_type_def.
Definition: abg-hash.h:144
hash_t operator()(const pointer_type_def &t) const
Hashing function for a pointer_type_def IR node.
Definition: abg-hash.cc:580
Hash functor for instances of ptr_to_mbr_type.
Definition: abg-hash.h:164
hash_t operator()(const ptr_to_mbr_type &t) const
Hashing function for a ptr_to_mbr_type IR node.
Definition: abg-hash.cc:754
Hash functor for instances of qualified_type_def.
Definition: abg-hash.h:134
hash_t operator()(const qualified_type_def &t) const
Hashing function for a qualified_type_def IR node.
Definition: abg-hash.cc:537
Hash functor for instances of reference_type_def.
Definition: abg-hash.h:154
hash_t operator()(const reference_type_def &t) const
Hashing function for a reference_type_def IR node.
Definition: abg-hash.cc:622
Hash functor for instances of type_base.
Definition: abg-hash.h:111
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:391
Hash functor for instances of type_decl.
Definition: abg-hash.h:124
hash_t operator()(const type_decl &t) const
Hashing function for a type_decl IR node.
Definition: abg-hash.cc:460
Hash functor for instances of typedef_decl.
Definition: abg-hash.h:207
hash_t operator()(const typedef_decl &t) const
Hashing function for a typedef_decl IR node.
Definition: abg-hash.cc:498
Hash functor for instances of union_decl type.
Definition: abg-hash.h:280