|
24 | 24 | #include <cxx/ast.h>
|
25 | 25 | #include <cxx/control.h>
|
26 | 26 | #include <cxx/literals.h>
|
| 27 | +#include <cxx/symbols.h> |
| 28 | +#include <cxx/util.h> |
27 | 29 |
|
28 | 30 | #include <cstring>
|
29 | 31 |
|
30 | 32 | namespace cxx {
|
31 | 33 |
|
32 | 34 | namespace {
|
33 | 35 |
|
| 36 | +struct ConstValueHash { |
| 37 | + auto operator()(bool value) const -> std::size_t { |
| 38 | + return std::hash<bool>{}(value); |
| 39 | + } |
| 40 | + auto operator()(std::int32_t value) const -> std::size_t { |
| 41 | + return std::hash<std::int32_t>{}(value); |
| 42 | + } |
| 43 | + auto operator()(std::uint32_t value) const -> std::size_t { |
| 44 | + return std::hash<std::uint32_t>{}(value); |
| 45 | + } |
| 46 | + auto operator()(std::int64_t value) const -> std::size_t { |
| 47 | + return std::hash<std::int64_t>{}(value); |
| 48 | + } |
| 49 | + auto operator()(std::uint64_t value) const -> std::size_t { |
| 50 | + return std::hash<std::uint64_t>{}(value); |
| 51 | + } |
| 52 | + auto operator()(float value) const -> std::size_t { |
| 53 | + return std::hash<float>{}(value); |
| 54 | + } |
| 55 | + auto operator()(double value) const -> std::size_t { |
| 56 | + return std::hash<double>{}(value); |
| 57 | + } |
| 58 | + auto operator()(long double value) const -> std::size_t { |
| 59 | + return std::hash<long double>{}(value); |
| 60 | + } |
| 61 | + auto operator()(const StringLiteral* value) const -> std::size_t { |
| 62 | + return value->hashCode(); |
| 63 | + } |
| 64 | +}; |
| 65 | + |
| 66 | +struct TemplateArgumentHash { |
| 67 | + auto operator()(const Type* arg) const -> std::size_t { |
| 68 | + return std::hash<const void*>{}(arg); |
| 69 | + } |
| 70 | + |
| 71 | + auto operator()(Symbol* arg) const -> std::size_t { |
| 72 | + return arg->name() ? arg->name()->hashValue() : 0; |
| 73 | + } |
| 74 | + |
| 75 | + auto operator()(ConstValue arg) const -> std::size_t { |
| 76 | + return std::visit(ConstValueHash{}, arg); |
| 77 | + } |
| 78 | + |
| 79 | + auto operator()(ExpressionAST* arg) const -> std::size_t { |
| 80 | + return std::hash<const void*>{}(arg); |
| 81 | + } |
| 82 | +}; |
| 83 | + |
34 | 84 | struct ConvertToName {
|
35 | 85 | Control* control_;
|
36 | 86 |
|
@@ -107,4 +157,14 @@ auto Identifier::builtinTypeTrait() const -> BuiltinTypeTraitKind {
|
107 | 157 | return static_cast<const TypeTraitIdentifierInfo*>(info_)->trait();
|
108 | 158 | }
|
109 | 159 |
|
| 160 | +auto TemplateId::hash(const Name* name, |
| 161 | + const std::vector<TemplateArgument>& args) |
| 162 | + -> std::size_t { |
| 163 | + std::size_t hash = name->hashValue(); |
| 164 | + for (const auto& arg : args) { |
| 165 | + hash_combine(hash, std::visit(TemplateArgumentHash{}, arg)); |
| 166 | + } |
| 167 | + return hash; |
| 168 | +} |
| 169 | + |
110 | 170 | } // namespace cxx
|
0 commit comments