• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2022-2024 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Siddharth Nayyar
19 
20 #ifndef STG_STABLE_HASH_H_
21 #define STG_STABLE_HASH_H_
22 
23 #include <cstdint>
24 #include <iostream>
25 #include <unordered_map>
26 #include <vector>
27 
28 #include "graph.h"
29 #include "hashing.h"
30 
31 namespace stg {
32 
33 class StableHash {
34  public:
StableHash(const Graph & graph)35   explicit StableHash(const Graph& graph) : graph_(graph) {}
36 
37   HashValue operator()(Id);
38   HashValue operator()(const Special&);
39   HashValue operator()(const PointerReference&);
40   HashValue operator()(const PointerToMember&);
41   HashValue operator()(const Typedef&);
42   HashValue operator()(const Qualified&);
43   HashValue operator()(const Primitive&);
44   HashValue operator()(const Array&);
45   HashValue operator()(const BaseClass&);
46   HashValue operator()(const Method&);
47   HashValue operator()(const Member&);
48   HashValue operator()(const VariantMember&);
49   HashValue operator()(const StructUnion&);
50   HashValue operator()(const Enumeration&);
51   HashValue operator()(const Variant&);
52   HashValue operator()(const Function&);
53   HashValue operator()(const ElfSymbol&);
54   HashValue operator()(const Interface&);
55 
56  private:
57   const Graph& graph_;
58   std::unordered_map<Id, HashValue> cache_;
59 
60   // Function object: (Args...) -> HashValue
61   Hash hash_;
62 };
63 
64 }  // namespace stg
65 
66 #endif  // STG_STABLE_HASH_H_
67