OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 #ifndef VM_TYPE_TABLE_H_ | |
6 #define VM_TYPE_TABLE_H_ | |
7 | |
8 #include "platform/assert.h" | |
9 #include "vm/hash_table.h" | |
10 #include "vm/object.h" | |
11 | |
12 namespace dart { | |
13 | |
14 class CanonicalTypeKey { | |
15 public: | |
16 explicit CanonicalTypeKey(const Type& key) : key_(key) { | |
17 } | |
18 bool Matches(const Type& arg) const { | |
19 return key_.Equals(arg); | |
20 } | |
21 uword Hash() const { | |
22 return key_.Hash(); | |
23 } | |
24 const Type& key_; | |
25 | |
26 private: | |
27 DISALLOW_ALLOCATION(); | |
28 }; | |
29 | |
30 | |
31 // Traits for looking up Canonical Type based on it's hash. | |
32 class CanonicalTypeTraits { | |
33 public: | |
34 static const char* Name() { return "CanonicalTypeTraits"; } | |
35 static bool ReportStats() { return false; } | |
36 | |
37 // Called when growing the table. | |
38 static bool IsMatch(const Object& a, const Object& b) { | |
39 ASSERT(a.IsType() && b.IsType()); | |
40 const Type& arg1 = Type::Cast(a); | |
41 const Type& arg2 = Type::Cast(b); | |
42 return arg1.Equals(arg2); | |
43 } | |
44 static bool IsMatch(const CanonicalTypeKey& a, const Object& b) { | |
45 ASSERT(b.IsType()); | |
46 return a.Matches(Type::Cast(b)); | |
47 } | |
48 static uword Hash(const Object& key) { | |
49 ASSERT(key.IsType()); | |
50 return Type::Cast(key).Hash(); | |
51 } | |
52 static uword Hash(const CanonicalTypeKey& key) { | |
53 return key.Hash(); | |
54 } | |
55 static RawObject* NewKey(const CanonicalTypeKey& obj) { | |
56 return obj.key_.raw(); | |
57 } | |
58 }; | |
59 typedef UnorderedHashSet <CanonicalTypeTraits> CanonicalTypeSet; | |
60 | |
61 | |
62 class CanonicalTypeArgumentsKey { | |
63 public: | |
64 explicit CanonicalTypeArgumentsKey(const TypeArguments& key) : key_(key) { | |
65 } | |
66 bool Matches(const TypeArguments& arg) const { | |
67 return key_.Equals(arg) && (key_.Hash() == arg.Hash()); | |
68 } | |
69 uword Hash() const { | |
70 return key_.Hash(); | |
71 } | |
72 const TypeArguments& key_; | |
73 | |
74 private: | |
75 DISALLOW_ALLOCATION(); | |
76 }; | |
77 | |
78 | |
79 // Traits for looking up Canonical TypeArguments based on it's hash. | |
regis
2016/05/16 20:17:48
its
siva
2016/05/16 23:24:25
Done.
| |
80 class CanonicalTypeArgumentsTraits { | |
81 public: | |
82 static const char* Name() { return "CanonicalTypeArgumentsTraits"; } | |
83 static bool ReportStats() { return false; } | |
84 | |
85 // Called when growing the table. | |
86 static bool IsMatch(const Object& a, const Object& b) { | |
87 ASSERT(a.IsTypeArguments() && b.IsTypeArguments()); | |
88 const TypeArguments& arg1 = TypeArguments::Cast(a); | |
89 const TypeArguments& arg2 = TypeArguments::Cast(b); | |
90 return arg1.Equals(arg2) && (arg1.Hash() == arg2.Hash()); | |
91 } | |
92 static bool IsMatch(const CanonicalTypeArgumentsKey& a, const Object& b) { | |
93 ASSERT(b.IsTypeArguments()); | |
94 return a.Matches(TypeArguments::Cast(b)); | |
95 } | |
96 static uword Hash(const Object& key) { | |
97 ASSERT(key.IsTypeArguments()); | |
98 return TypeArguments::Cast(key).Hash(); | |
99 } | |
100 static uword Hash(const CanonicalTypeArgumentsKey& key) { | |
101 return key.Hash(); | |
102 } | |
103 static RawObject* NewKey(const CanonicalTypeArgumentsKey& obj) { | |
104 return obj.key_.raw(); | |
105 } | |
106 }; | |
107 typedef UnorderedHashSet<CanonicalTypeArgumentsTraits> | |
108 CanonicalTypeArgumentsSet; | |
109 | |
110 } // namespace dart | |
111 | |
112 #endif // VM_TYPE_TABLE_H_ | |
OLD | NEW |