Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: src/field-type.cc

Issue 1700923002: Move FieldType to separate h/cc files. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/field-type.h ('k') | src/json-parser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/handles-inl.h"
8 #include "src/ostreams.h"
9 #include "src/types.h"
10
11 namespace v8 {
12 namespace internal {
13
14 // static
15 FieldType* FieldType::None() {
16 return reinterpret_cast<FieldType*>(Smi::FromInt(0));
17 }
18
19 // static
20 FieldType* FieldType::Any() {
21 return reinterpret_cast<FieldType*>(Smi::FromInt(1));
22 }
23
24 // static
25 Handle<FieldType> FieldType::None(Isolate* isolate) {
26 return handle(None(), isolate);
27 }
28
29 // static
30 Handle<FieldType> FieldType::Any(Isolate* isolate) {
31 return handle(Any(), isolate);
32 }
33
34 // static
35 FieldType* FieldType::Class(i::Map* map) { return FieldType::cast(map); }
36
37 // static
38 Handle<FieldType> FieldType::Class(i::Handle<i::Map> map, Isolate* isolate) {
39 return handle(Class(*map), isolate);
40 }
41
42 // static
43 FieldType* FieldType::cast(Object* object) {
44 DCHECK(object == None() || object == Any() || object->IsMap());
45 return reinterpret_cast<FieldType*>(object);
46 }
47
48 bool FieldType::NowContains(Object* value) {
49 if (this == Any()) return true;
50 if (this == None()) return false;
51 if (!value->IsHeapObject()) return false;
52 return HeapObject::cast(value)->map() == Map::cast(this);
53 }
54
55 bool FieldType::NowContains(Handle<Object> value) {
56 return NowContains(*value);
57 }
58
59 bool FieldType::IsClass() { return this->IsMap(); }
60
61 Handle<i::Map> FieldType::AsClass() {
62 DCHECK(IsClass());
63 i::Map* map = Map::cast(this);
64 return handle(map, map->GetIsolate());
65 }
66
67 bool FieldType::NowStable() {
68 return !this->IsClass() || this->AsClass()->is_stable();
69 }
70
71 bool FieldType::NowIs(FieldType* other) {
72 if (other->IsAny()) return true;
73 if (IsNone()) return true;
74 if (other->IsNone()) return false;
75 if (IsAny()) return false;
76 DCHECK(IsClass());
77 DCHECK(other->IsClass());
78 return this == other;
79 }
80
81 bool FieldType::NowIs(Handle<FieldType> other) { return NowIs(*other); }
82
83 Type* FieldType::Convert(Zone* zone) {
84 if (IsAny()) return Type::Any();
85 if (IsNone()) return Type::None();
86 DCHECK(IsClass());
87 return Type::Class(AsClass(), zone);
88 }
89
90 void FieldType::PrintTo(std::ostream& os) {
91 if (IsAny()) {
92 os << "Any";
93 } else if (IsNone()) {
94 os << "None";
95 } else {
96 DCHECK(IsClass());
97 os << "Class(" << static_cast<void*>(*AsClass()) << ")";
98 }
99 }
100
101 } // namespace internal
102 } // namespace v8
OLDNEW
« no previous file with comments | « src/field-type.h ('k') | src/json-parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698