• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 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_TYPE_HINTS_H_
6 #define V8_TYPE_HINTS_H_
7 
8 #include "src/base/flags.h"
9 #include "src/utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 // Type hints for an binary operation.
15 enum class BinaryOperationHint : uint8_t {
16   kNone,
17   kSignedSmall,
18   kSigned32,
19   kNumberOrOddball,
20   kString,
21   kAny
22 };
23 
hash_value(BinaryOperationHint hint)24 inline size_t hash_value(BinaryOperationHint hint) {
25   return static_cast<unsigned>(hint);
26 }
27 
28 std::ostream& operator<<(std::ostream&, BinaryOperationHint);
29 
30 // Type hints for an compare operation.
31 enum class CompareOperationHint : uint8_t {
32   kNone,
33   kSignedSmall,
34   kNumber,
35   kNumberOrOddball,
36   kInternalizedString,
37   kString,
38   kReceiver,
39   kAny
40 };
41 
hash_value(CompareOperationHint hint)42 inline size_t hash_value(CompareOperationHint hint) {
43   return static_cast<unsigned>(hint);
44 }
45 
46 std::ostream& operator<<(std::ostream&, CompareOperationHint);
47 
48 // Type hints for the ToBoolean type conversion.
49 enum class ToBooleanHint : uint16_t {
50   kNone = 0u,
51   kUndefined = 1u << 0,
52   kBoolean = 1u << 1,
53   kNull = 1u << 2,
54   kSmallInteger = 1u << 3,
55   kReceiver = 1u << 4,
56   kString = 1u << 5,
57   kSymbol = 1u << 6,
58   kHeapNumber = 1u << 7,
59   kAny = kUndefined | kBoolean | kNull | kSmallInteger | kReceiver | kString |
60          kSymbol | kHeapNumber,
61   kNeedsMap = kReceiver | kString | kSymbol | kHeapNumber,
62   kCanBeUndetectable = kReceiver,
63 };
64 
65 std::ostream& operator<<(std::ostream&, ToBooleanHint);
66 std::string ToString(ToBooleanHint);
67 
68 typedef base::Flags<ToBooleanHint, uint16_t> ToBooleanHints;
69 
70 std::ostream& operator<<(std::ostream&, ToBooleanHints);
71 std::string ToString(ToBooleanHints);
72 
73 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints)
74 
75 enum StringAddFlags {
76   // Omit both parameter checks.
77   STRING_ADD_CHECK_NONE = 0,
78   // Check left parameter.
79   STRING_ADD_CHECK_LEFT = 1 << 0,
80   // Check right parameter.
81   STRING_ADD_CHECK_RIGHT = 1 << 1,
82   // Check both parameters.
83   STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
84   // Convert parameters when check fails (instead of throwing an exception).
85   STRING_ADD_CONVERT = 1 << 2,
86   STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT,
87   STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT
88 };
89 
90 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
91 
92 }  // namespace internal
93 }  // namespace v8
94 
95 #endif  // V8_TYPE_HINTS_H_
96