libabigail
Loading...
Searching...
No Matches
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-2026 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. This is a bitfield.
25{
26 /// No hashing has been done/started.
27 ///
28 /// Or if any hashing has started, it's been completed.
29 ///
30 /// Note that when type_or_decl_base::set_hash_value is invoked on
31 /// an IR node in this state, the hash value is saved onto the IR
32 /// node.
34
35 /// Hashing started but is not yet finished.
37
38 /// A cycle has been detected in the graph on the current node.
39 ///
40 /// This means the hashing has started on the current IR node and
41 /// while hashing its children nodes, this very same IR node is
42 /// visited again to be hashed. This is a cycle and it needs to be
43 /// broken otherwise the hashing continues forever.
45
46 /// Hashing of the given IR node started, is done and a hash value
47 /// has been stored onto the node. IOW, If an ABI artifact is in
48 /// this state, then it must have an hash value available and should
49 /// be get by peek_hash_value or type_or_decl_base::hash_value().
51};
52
53bool
54deserialize_hash(const string& input, uint64_t& hash);
55
56bool
57serialize_hash(uint64_t hash, string& output);
58
61
63fnv_hash(const std::string& str);
64
66hash(std::uint64_t v, std::uint64_t seed = 0);
67
69hash(const std::string& str);
70
73
74void
77
78void
81
82bool
83is_recursive_artefact(const type_or_decl_base& t);
84
85void
86is_recursive_artefact(const type_or_decl_base& t, bool f);
87}//end namespace hashing
88
89namespace ir
90{
91
93{
94 hash_t
95 operator()(const decl_base& d) const;
96
97 hash_t
98 operator()(const decl_base* d) const;
99}; // end struct decl_base::hash
100
101
102/// Hash functor for instances of @ref type_base.
104{
105 hash_t
106 operator()(const type_base& t) const;
107
108 hash_t
109 operator()(const type_base* t) const;
110
111 hash_t
112 operator()(const type_base_sptr t) const;
113}; // end struct type_base::hash
114
115/// Hash functor for instances of @ref type_decl.
117{
118 hash_t
119 operator()(const type_decl& t) const;
120
121 hash_t
122 operator()(const type_decl* t) const;
123}; // end struct type_decl::hash
124
125/// Hash functor for instances of @ref qualified_type_def.
127{
128 hash_t
129 operator()(const qualified_type_def& t) const;
130
131 hash_t
132 operator()(const qualified_type_def* t) const;
133}; // end struct qualified_type_def::hash
134
135/// Hash functor for instances of @ref pointer_type_def.
137{
138 hash_t
139 operator()(const pointer_type_def& t) const;
140
141 hash_t
142 operator()(const pointer_type_def* t) const;
143}; // end struct pointer_type_def::hash
144
145/// Hash functor for instances of @ref reference_type_def.
147{
148 hash_t
149 operator()(const reference_type_def& t) const;
150
151 hash_t
152 operator()(const reference_type_def* t) const;
153}; // end struct reference_type_def::hash
154
155/// Hash functor for instances of @ref ptr_to_mbr_type.
157{
158 hash_t
159 operator() (const ptr_to_mbr_type& t) const;
160
161 hash_t
162 operator() (const ptr_to_mbr_type* t) const;
163
164 hash_t
165 operator() (const ptr_to_mbr_type_sptr& t) const;
166}; // end reference_type_def::hash
167
168/// Hash functor for instances of @ref array_type_def::subrange_type
170{
171 hash_t
172 operator()(const array_type_def::subrange_type& s) const;
173
174 hash_t
175 operator()(const array_type_def::subrange_type* s) const;
176};// end struct array_type_def::subrange_type::hash
177
178/// Hash functor for instances of @ref array_type_def::hash
180{
181 hash_t
182 operator()(const array_type_def& t) const;
183
184 hash_t
185 operator()(const array_type_def* t) const;
186}; //end struct array_type_def::hash
187
188/// Hash functor for instances of @ref enum_type_decl
190{
191 hash_t
192 operator()(const enum_type_decl& t) const;
193
194 hash_t
195 operator()(const enum_type_decl* t) const;
196};// end struct enum_type_decl::hash
197
198/// Hash functor for instances of @ref typedef_decl
200{
201 hash_t
202 operator()(const typedef_decl& t) const;
203
204 hash_t
205 operator()(const typedef_decl* t) const;
206};// end struct typedef_decl::hash
207
208/// The hashing functor for @ref function_type.
210{
211 hash_t
212 operator()(const function_type& t) const;
213
214 hash_t
215 operator()(const function_type* t) const;
216
217 hash_t
218 operator()(const function_type_sptr t) const;
219};// end struct function_type::hash
220
221/// Hashing functor for the @ref method_type type.
223{
224 hash_t
225 operator()(const method_type& t) const;
226
227 hash_t
228 operator()(const method_type* t) const;
229
230 hash_t
231 operator()(const method_type_sptr t) const;
232}; // end struct method_type::hash
233
234/// The hashing functor for member_base.
236{
237 hash_t
238 operator()(const member_base& m) const;
239};
240
241/// Hasher for the @ref class_or_union type
243{
244 hash_t
245 operator()(const class_or_union& t) const;
246
247 hash_t
248 operator()(const class_or_union* t) const;
249}; // end struct class_decl::hash
250
251/// The hashing functor for class_decl::base_spec.
253{
254 hash_t
255 operator()(const base_spec& t) const;
256
257 hash_t
258 operator()(const base_spec* t) const;
259};
260
261/// Hasher for the @ref class_decl type
263{
264 hash_t
265 operator()(const class_decl& t) const;
266
267 hash_t
268 operator()(const class_decl* t) const;
269}; // end struct class_decl::hash
270
271/// Hash functor for instances of @ref union_decl type.
273{
274 hash_t
275 operator()(const union_decl&) const;
276
277 hash_t
278 operator()(const union_decl*) const;
279};//end struct union_decl::hash
280
281}// end namespace ir
282}//end namespace abigail
283
284#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:2578
The abstraction of an array type.
Definition abg-ir.h:2552
Abstraction of a base specifier in a class declaration.
Definition abg-ir.h:4391
Abstracts a class declaration.
Definition abg-ir.h:4214
The base type of class_decl and union_decl.
Definition abg-ir.h:4005
The base type of all declarations.
Definition abg-ir.h:1584
Abstracts a declaration for an enum type.
Definition abg-ir.h:2796
Abstraction of a function type.
Definition abg-ir.h:3429
The base class for member types, data members and member functions. Its purpose is mainly to carry th...
Definition abg-ir.h:3867
Abstracts the type of a class member function.
Definition abg-ir.h:3527
The abstraction of a pointer type.
Definition abg-ir.h:2354
The abstraction of a pointer-to-member type.
Definition abg-ir.h:2489
The abstraction of a qualified type.
Definition abg-ir.h:2240
Abstracts a reference type.
Definition abg-ir.h:2420
An abstraction helper for type declarations.
Definition abg-ir.h:2014
A basic type declaration that introduces no scope.
Definition abg-ir.h:2122
The base class of both types and declarations.
Definition abg-ir.h:1378
The abstraction of a typedef declaration.
Definition abg-ir.h:2936
Abstracts a union type declaration.
Definition abg-ir.h:4449
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
void add_to_hashing_state(const ir::type_or_decl_base &tod, hashing::hashing_state s)
Add a state to the hashing state of a given IR node.
Definition abg-hash.cc:299
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. This is a bitfield.
Definition abg-hash.h:25
@ HASHING_STARTED_STATE
Hashing started but is not yet finished.
Definition abg-hash.h:36
@ HASHING_FINISHED_STATE
Hashing of the given IR node started, is done and a hash value has been stored onto the node....
Definition abg-hash.h:50
@ HASHING_CYCLED_TYPE_STATE
A cycle has been detected in the graph on the current node.
Definition abg-hash.h:44
@ HASHING_NOT_DONE_STATE
No hashing has been done/started.
Definition abg-hash.h:33
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
shared_ptr< method_type > method_type_sptr
Convenience typedef for shared pointer to method_type.
Definition abg-fwd.h:222
shared_ptr< function_type > function_type_sptr
Convenience typedef for a shared pointer on a function_type.
Definition abg-fwd.h:211
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:240
Toplevel namespace for libabigail.
Hash functor for instances of array_type_def::hash.
Definition abg-hash.h:180
hash_t operator()(const array_type_def &t) const
Hashing function for a array_type_def IR node.
Definition abg-hash.cc:836
Hash functor for instances of array_type_def::subrange_type.
Definition abg-hash.h:170
The hashing functor for class_decl::base_spec.
Definition abg-hash.h:253
hash_t operator()(const base_spec &t) const
Hashing function for a class_decl::base_spec IR node.
Definition abg-hash.cc:1122
Hasher for the class_decl type.
Definition abg-hash.h:263
hash_t operator()(const class_decl &t) const
Compute a hash for a class_decl.
Definition abg-hash.cc:1210
Hasher for the class_or_union type.
Definition abg-hash.h:243
hash_t operator()(const class_or_union &t) const
Compute a hash for a class_or_union.
Definition abg-hash.cc:1162
hash_t operator()(const decl_base &d) const
Hash function for an instance of decl_base.
Definition abg-hash.cc:579
Hash functor for instances of enum_type_decl.
Definition abg-hash.h:190
hash_t operator()(const enum_type_decl &t) const
Hashing function for a enum_type_decl IR node.
Definition abg-hash.cc:945
The hashing functor for function_type.
Definition abg-hash.h:210
hash_t operator()(const function_type &t) const
Hashing function for function_type.
Definition abg-hash.cc:1003
The hashing functor for member_base.
Definition abg-hash.h:236
hash_t operator()(const member_base &m) const
Hashing function for a member_base IR node.
Definition abg-hash.cc:1111
Hashing functor for the method_type type.
Definition abg-hash.h:223
hash_t operator()(const method_type &t) const
Hashing function for a method_type IR node.
Definition abg-hash.cc:1054
Hash functor for instances of pointer_type_def.
Definition abg-hash.h:137
hash_t operator()(const pointer_type_def &t) const
Hashing function for a pointer_type_def IR node.
Definition abg-hash.cc:729
Hash functor for instances of ptr_to_mbr_type.
Definition abg-hash.h:157
hash_t operator()(const ptr_to_mbr_type &t) const
Hashing function for a ptr_to_mbr_type IR node.
Definition abg-hash.cc:891
Hash functor for instances of qualified_type_def.
Definition abg-hash.h:127
hash_t operator()(const qualified_type_def &t) const
Hashing function for a qualified_type_def IR node.
Definition abg-hash.cc:688
Hash functor for instances of reference_type_def.
Definition abg-hash.h:147
hash_t operator()(const reference_type_def &t) const
Hashing function for a reference_type_def IR node.
Definition abg-hash.cc:769
Hash functor for instances of type_base.
Definition abg-hash.h:104
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:548
Hash functor for instances of type_decl.
Definition abg-hash.h:117
hash_t operator()(const type_decl &t) const
Hashing function for a type_decl IR node.
Definition abg-hash.cc:616
Hash functor for instances of typedef_decl.
Definition abg-hash.h:200
hash_t operator()(const typedef_decl &t) const
Hashing function for a typedef_decl IR node.
Definition abg-hash.cc:654
Hash functor for instances of union_decl type.
Definition abg-hash.h:273