Home | History | Annotate | Download | only in src
      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 
     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   kAny
     37 };
     38 
     39 inline size_t hash_value(CompareOperationHint hint) {
     40   return static_cast<unsigned>(hint);
     41 }
     42 
     43 std::ostream& operator<<(std::ostream&, CompareOperationHint);
     44 
     45 // Type hints for the ToBoolean type conversion.
     46 enum class ToBooleanHint : uint16_t {
     47   kNone = 0u,
     48   kUndefined = 1u << 0,
     49   kBoolean = 1u << 1,
     50   kNull = 1u << 2,
     51   kSmallInteger = 1u << 3,
     52   kReceiver = 1u << 4,
     53   kString = 1u << 5,
     54   kSymbol = 1u << 6,
     55   kHeapNumber = 1u << 7,
     56   kSimdValue = 1u << 8,
     57   kAny = kUndefined | kBoolean | kNull | kSmallInteger | kReceiver | kString |
     58          kSymbol | kHeapNumber | kSimdValue,
     59   kNeedsMap = kReceiver | kString | kSymbol | kHeapNumber | kSimdValue,
     60   kCanBeUndetectable = kReceiver,
     61 };
     62 
     63 std::ostream& operator<<(std::ostream&, ToBooleanHint);
     64 
     65 typedef base::Flags<ToBooleanHint, uint16_t> ToBooleanHints;
     66 
     67 std::ostream& operator<<(std::ostream&, ToBooleanHints);
     68 
     69 DEFINE_OPERATORS_FOR_FLAGS(ToBooleanHints)
     70 
     71 enum StringAddFlags {
     72   // Omit both parameter checks.
     73   STRING_ADD_CHECK_NONE = 0,
     74   // Check left parameter.
     75   STRING_ADD_CHECK_LEFT = 1 << 0,
     76   // Check right parameter.
     77   STRING_ADD_CHECK_RIGHT = 1 << 1,
     78   // Check both parameters.
     79   STRING_ADD_CHECK_BOTH = STRING_ADD_CHECK_LEFT | STRING_ADD_CHECK_RIGHT,
     80   // Convert parameters when check fails (instead of throwing an exception).
     81   STRING_ADD_CONVERT = 1 << 2,
     82   STRING_ADD_CONVERT_LEFT = STRING_ADD_CHECK_LEFT | STRING_ADD_CONVERT,
     83   STRING_ADD_CONVERT_RIGHT = STRING_ADD_CHECK_RIGHT | STRING_ADD_CONVERT
     84 };
     85 
     86 std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags);
     87 
     88 }  // namespace internal
     89 }  // namespace v8
     90 
     91 #endif  // V8_TYPE_HINTS_H_
     92