Line data Source code
1 : // Copyright 2016 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "src/field-type.h"
6 :
7 : #include "src/ast/ast-types.h"
8 : #include "src/handles-inl.h"
9 : #include "src/objects-inl.h"
10 : #include "src/ostreams.h"
11 :
12 : namespace v8 {
13 : namespace internal {
14 :
15 : // static
16 13971546 : FieldType* FieldType::None() {
17 : // Do not Smi::kZero here or for Any(), as that may translate
18 : // as `nullptr` which is not a valid value for `this`.
19 13971546 : return reinterpret_cast<FieldType*>(Smi::FromInt(2));
20 : }
21 :
22 : // static
23 69916972 : FieldType* FieldType::Any() {
24 69916972 : return reinterpret_cast<FieldType*>(Smi::FromInt(1));
25 : }
26 :
27 : // static
28 465385 : Handle<FieldType> FieldType::None(Isolate* isolate) {
29 465385 : return handle(None(), isolate);
30 : }
31 :
32 : // static
33 11587902 : Handle<FieldType> FieldType::Any(Isolate* isolate) {
34 11587905 : return handle(Any(), isolate);
35 : }
36 :
37 : // static
38 0 : FieldType* FieldType::Class(i::Map* map) { return FieldType::cast(map); }
39 :
40 : // static
41 1604255 : Handle<FieldType> FieldType::Class(i::Handle<i::Map> map, Isolate* isolate) {
42 1604255 : return handle(Class(*map), isolate);
43 : }
44 :
45 : // static
46 67490749 : FieldType* FieldType::cast(Object* object) {
47 : DCHECK(object == None() || object == Any() || object->IsMap());
48 67490749 : return reinterpret_cast<FieldType*>(object);
49 : }
50 :
51 19660018 : bool FieldType::IsClass() { return this->IsMap(); }
52 :
53 1291759 : Handle<i::Map> FieldType::AsClass() {
54 : DCHECK(IsClass());
55 : i::Map* map = Map::cast(this);
56 1291759 : return handle(map, map->GetIsolate());
57 : }
58 :
59 0 : bool FieldType::NowStable() {
60 0 : return !this->IsClass() || this->AsClass()->is_stable();
61 : }
62 :
63 159260 : bool FieldType::NowIs(FieldType* other) {
64 2894563 : if (other->IsAny()) return true;
65 869797 : if (IsNone()) return true;
66 669910 : if (other->IsNone()) return false;
67 644387 : if (IsAny()) return false;
68 : DCHECK(IsClass());
69 : DCHECK(other->IsClass());
70 448703 : return this == other;
71 : }
72 :
73 5470606 : bool FieldType::NowIs(Handle<FieldType> other) { return NowIs(*other); }
74 :
75 11992 : AstType* FieldType::Convert(Zone* zone) {
76 11992 : if (IsAny()) return AstType::NonInternal();
77 11986 : if (IsNone()) return AstType::None();
78 : DCHECK(IsClass());
79 23960 : return AstType::Class(AsClass(), zone);
80 : }
81 :
82 0 : void FieldType::PrintTo(std::ostream& os) {
83 0 : if (IsAny()) {
84 0 : os << "Any";
85 0 : } else if (IsNone()) {
86 0 : os << "None";
87 : } else {
88 : DCHECK(IsClass());
89 0 : os << "Class(" << static_cast<void*>(*AsClass()) << ")";
90 : }
91 0 : }
92 :
93 : } // namespace internal
94 : } // namespace v8
|