Flutter Engine
The Flutter Engine
canonical_tables.cc
Go to the documentation of this file.
1// Copyright (c) 2020, 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
6
7#include "vm/regexp.h"
8
9namespace dart {
10
12 // In the absence of hot reload, this can just be an identity check. With
13 // reload, some old program elements may be retained by the stack, closures
14 // or mirrors, which are absent from the new version of the library's
15 // metadata table. This name-based matching fuzzy maps the old program
16 // elements to corresponding new elements, preserving the behavior of the old
17 // metaname+fields scheme.
18 if (a.IsLibrary() && b.IsLibrary()) {
19 const String& url_a = String::Handle(Library::Cast(a).url());
20 const String& url_b = String::Handle(Library::Cast(b).url());
21 return url_a.Equals(url_b);
22 } else if (a.IsClass() && b.IsClass()) {
23 const String& name_a = String::Handle(Class::Cast(a).Name());
24 const String& name_b = String::Handle(Class::Cast(b).Name());
25 return name_a.Equals(name_b);
26 } else if (a.IsFunction() && b.IsFunction()) {
27 const auto& func_a = Function::Cast(a);
28 const auto& func_b = Function::Cast(b);
29 if (func_a.IsNonImplicitClosureFunction() ||
30 func_b.IsNonImplicitClosureFunction()) {
31 return a.ptr() == b.ptr();
32 }
33 const String& name_a = String::Handle(func_a.name());
34 const String& name_b = String::Handle(func_b.name());
35 if (!name_a.Equals(name_b)) {
36 return false;
37 }
38 const Object& owner_a = Object::Handle(Function::Cast(a).Owner());
39 const Object& owner_b = Object::Handle(Function::Cast(b).Owner());
40 return IsMatch(owner_a, owner_b);
41 } else if (a.IsField() && b.IsField()) {
42 const String& name_a = String::Handle(Field::Cast(a).name());
43 const String& name_b = String::Handle(Field::Cast(b).name());
44 if (!name_a.Equals(name_b)) {
45 return false;
46 }
47 const Object& owner_a = Object::Handle(Field::Cast(a).Owner());
48 const Object& owner_b = Object::Handle(Field::Cast(b).Owner());
49 return IsMatch(owner_a, owner_b);
50 } else if (a.IsTypeParameter() && b.IsTypeParameter()) {
51 if (TypeParameter::Cast(a).index() != TypeParameter::Cast(b).index() ||
52 TypeParameter::Cast(a).base() != TypeParameter::Cast(b).base()) {
53 return false;
54 }
55 return TypeParameter::Cast(a).parameterized_class_id() ==
56 TypeParameter::Cast(b).parameterized_class_id();
57 }
58 return a.ptr() == b.ptr();
59}
60
62 if (key.IsLibrary()) {
63 return String::Hash(Library::Cast(key).url());
64 } else if (key.IsClass()) {
65 return String::Hash(Class::Cast(key).Name());
66 } else if (key.IsFunction()) {
67 return CombineHashes(String::Hash(Function::Cast(key).name()),
68 Hash(Object::Handle(Function::Cast(key).Owner())));
69 } else if (key.IsField()) {
70 return CombineHashes(String::Hash(Field::Cast(key).name()),
71 Hash(Object::Handle(Field::Cast(key).Owner())));
72 } else if (key.IsTypeParameter()) {
73 return TypeParameter::Cast(key).Hash();
74 } else if (key.IsNamespace()) {
75 return Hash(Library::Handle(Namespace::Cast(key).target()));
76 }
78}
79
81 ASSERT(!(key.IsString() || key.IsAbstractType()));
82}
83
85 ASSERT(!(obj.IsString() || obj.IsAbstractType()));
86 if (key_.CanonicalizeEquals(obj)) {
87 ASSERT(obj.IsCanonical());
88 return true;
89 }
90 return false;
91}
92
94 return key_.CanonicalizeHash();
95}
96
98 ASSERT(!(a.IsString() || a.IsAbstractType()));
99 ASSERT(!(b.IsString() || b.IsAbstractType()));
100 return a.ptr() == b.ptr();
101}
102
104 const Object& b) {
105 return a.Matches(Instance::Cast(b));
106}
107
109 ASSERT(!(key.IsString() || key.IsAbstractType()));
110 ASSERT(key.IsInstance());
111 return Instance::Cast(key).CanonicalizeHash();
112}
113
115 return key.Hash();
116}
117
119 return obj.key_.ptr();
120}
121
124 key.flags_);
125}
126
127} // namespace dart
#define UNREACHABLE()
Definition: assert.h:248
CanonicalInstanceKey(const Instance &key)
bool Matches(const Instance &obj) const
static bool IsMatch(const Object &a, const Object &b)
static ObjectPtr NewKey(const CanonicalInstanceKey &obj)
static uword Hash(const Object &key)
static ObjectPtr NewKey(const RegExpKey &key)
virtual bool CanonicalizeEquals(const Instance &other) const
Definition: object.cc:20259
virtual uint32_t CanonicalizeHash() const
Definition: object.cc:20316
static uword Hash(const Object &key)
static bool IsMatch(const Object &a, const Object &b)
static const char * Name()
ObjectPtr ptr() const
Definition: object.h:332
bool IsCanonical() const
Definition: object.h:335
static Object & Handle()
Definition: object.h:407
static RegExpPtr CreateRegExp(Thread *thread, const String &pattern, RegExpFlags flags)
Definition: regexp.cc:5573
bool Equals(const String &str) const
Definition: object.h:13337
uword Hash() const
Definition: object.h:10216
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
static bool b
struct MyStruct a[10]
uint32_t * target
Definition: dart_vm.cc:33
const char *const name
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
Definition: hash.h:12
uintptr_t uword
Definition: globals.h:501