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 #ifndef V8_FIELD_TYPE_H_
6 #define V8_FIELD_TYPE_H_
7 
8 #include "src/ast/ast-types.h"
9 #include "src/objects.h"
10 #include "src/ostreams.h"
11 
12 namespace v8 {
13 namespace internal {
14 
15 template <typename T>
16 class Handle;
17 
18 class FieldType : public Object {
19  public:
20   static FieldType* None();
21   static FieldType* Any();
22   static Handle<FieldType> None(Isolate* isolate);
23   static Handle<FieldType> Any(Isolate* isolate);
24   static FieldType* Class(i::Map* map);
25   static Handle<FieldType> Class(i::Handle<i::Map> map, Isolate* isolate);
26   static FieldType* cast(Object* object);
27 
28   bool NowContains(Object* value) {
29     if (this == Any()) return true;
30     if (this == None()) return false;
31     if (!value->IsHeapObject()) return false;
32     return HeapObject::cast(value)->map() == Map::cast(this);
33   }
34 
35   bool NowContains(Handle<Object> value) { return NowContains(*value); }
36 
37   bool IsClass();
38   Handle<i::Map> AsClass();
39   bool IsNone() { return this == None(); }
40   bool IsAny() { return this == Any(); }
41   bool NowStable();
42   bool NowIs(FieldType* other);
43   bool NowIs(Handle<FieldType> other);
44   AstType* Convert(Zone* zone);
45 
46   void PrintTo(std::ostream& os);
47 };
48 
49 }  // namespace internal
50 }  // namespace v8
51 
52 #endif  // V8_FIELD_TYPE_H_
53