Skip to content
← Back

src/syntax/trees/expressions/memberwise_hash.ghul

1
namespace Syntax.Trees.Expressions is
2
3
use Source
4
5
// The whole body of a synthesized `get_hash_code`, and the partner
6
// of MEMBERWISE_EQUALS: it hashes the same members, by whatever
7
// each member's comparison reads, so that two values that compare
8
// equal never hash differently.
9
class MEMBERWISE_HASH(
10
location: LOCATION,
11
members: Collections.LIST[string],
12
// Where each member was declared, so that a report about how
13
// it compares lands on the declaration rather than on a body
14
// nobody wrote.
15
member_locations: Collections.LIST[LOCATION]
16
): Expression is
17
// As for MEMBERWISE_EQUALS: what the hash can do is what the
18
// members' own hashes do.
19
called_functions: Collections.LIST[Semantic.Symbols.Function] => memberwise_state.functions()
20
21
memberwise_state: Syntax.Process.MEMBERWISE_STATE field
22
23
super(location)
24
25
clear() is
26
super.clear()
27
memberwise_state.clear()
28
si
29
30
clear_outputs() is
31
super.clear_outputs()
32
memberwise_state.clear()
33
si
34
35
accept(visitor: Visitor) is
36
visitor.visit(self)
37
si
38
si
39
si