type-hints.cc 4.49 KB
Newer Older
1 2 3 4
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
#include "src/type-hints.h"
6 7 8 9

namespace v8 {
namespace internal {

10
std::ostream& operator<<(std::ostream& os, BinaryOperationHint hint) {
11
  switch (hint) {
12
    case BinaryOperationHint::kNone:
13
      return os << "None";
14
    case BinaryOperationHint::kSignedSmall:
15
      return os << "SignedSmall";
16
    case BinaryOperationHint::kSigned32:
17
      return os << "Signed32";
18
    case BinaryOperationHint::kNumberOrOddball:
19
      return os << "NumberOrOddball";
20 21
    case BinaryOperationHint::kString:
      return os << "String";
22
    case BinaryOperationHint::kAny:
23 24 25 26 27 28
      return os << "Any";
  }
  UNREACHABLE();
  return os;
}

29
std::ostream& operator<<(std::ostream& os, CompareOperationHint hint) {
30
  switch (hint) {
31
    case CompareOperationHint::kNone:
32
      return os << "None";
33
    case CompareOperationHint::kSignedSmall:
34
      return os << "SignedSmall";
35
    case CompareOperationHint::kNumber:
36
      return os << "Number";
37
    case CompareOperationHint::kNumberOrOddball:
38
      return os << "NumberOrOddball";
39 40
    case CompareOperationHint::kInternalizedString:
      return os << "InternalizedString";
41 42
    case CompareOperationHint::kString:
      return os << "String";
43 44
    case CompareOperationHint::kReceiver:
      return os << "Receiver";
45
    case CompareOperationHint::kAny:
46 47 48 49 50 51
      return os << "Any";
  }
  UNREACHABLE();
  return os;
}

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
std::ostream& operator<<(std::ostream& os, ToBooleanHint hint) {
  switch (hint) {
    case ToBooleanHint::kNone:
      return os << "None";
    case ToBooleanHint::kUndefined:
      return os << "Undefined";
    case ToBooleanHint::kBoolean:
      return os << "Boolean";
    case ToBooleanHint::kNull:
      return os << "Null";
    case ToBooleanHint::kSmallInteger:
      return os << "SmallInteger";
    case ToBooleanHint::kReceiver:
      return os << "Receiver";
    case ToBooleanHint::kString:
      return os << "String";
    case ToBooleanHint::kSymbol:
      return os << "Symbol";
    case ToBooleanHint::kHeapNumber:
      return os << "HeapNumber";
    case ToBooleanHint::kAny:
      return os << "Any";
74 75
    case ToBooleanHint::kNeedsMap:
      return os << "NeedsMap";
76 77 78 79 80
  }
  UNREACHABLE();
  return os;
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
std::string ToString(ToBooleanHint hint) {
  switch (hint) {
    case ToBooleanHint::kNone:
      return "None";
    case ToBooleanHint::kUndefined:
      return "Undefined";
    case ToBooleanHint::kBoolean:
      return "Boolean";
    case ToBooleanHint::kNull:
      return "Null";
    case ToBooleanHint::kSmallInteger:
      return "SmallInteger";
    case ToBooleanHint::kReceiver:
      return "Receiver";
    case ToBooleanHint::kString:
      return "String";
    case ToBooleanHint::kSymbol:
      return "Symbol";
    case ToBooleanHint::kHeapNumber:
      return "HeapNumber";
    case ToBooleanHint::kAny:
      return "Any";
    case ToBooleanHint::kNeedsMap:
      return "NeedsMap";
  }
  UNREACHABLE();
  return "";
}

110 111 112 113
std::ostream& operator<<(std::ostream& os, ToBooleanHints hints) {
  if (hints == ToBooleanHint::kAny) return os << "Any";
  if (hints == ToBooleanHint::kNone) return os << "None";
  bool first = true;
114
  for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * 8; ++i) {
115 116 117 118 119 120 121 122 123 124
    ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i);
    if (hints & hint) {
      if (!first) os << "|";
      first = false;
      os << hint;
    }
  }
  return os;
}

125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
std::string ToString(ToBooleanHints hints) {
  if (hints == ToBooleanHint::kAny) return "Any";
  if (hints == ToBooleanHint::kNone) return "None";
  std::string ret;
  bool first = true;
  for (ToBooleanHints::mask_type i = 0; i < sizeof(i) * 8; ++i) {
    ToBooleanHint const hint = static_cast<ToBooleanHint>(1u << i);
    if (hints & hint) {
      if (!first) ret += "|";
      first = false;
      ret += ToString(hint);
    }
  }
  return ret;
}

141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
std::ostream& operator<<(std::ostream& os, const StringAddFlags& flags) {
  switch (flags) {
    case STRING_ADD_CHECK_NONE:
      return os << "CheckNone";
    case STRING_ADD_CHECK_LEFT:
      return os << "CheckLeft";
    case STRING_ADD_CHECK_RIGHT:
      return os << "CheckRight";
    case STRING_ADD_CHECK_BOTH:
      return os << "CheckBoth";
    case STRING_ADD_CONVERT_LEFT:
      return os << "ConvertLeft";
    case STRING_ADD_CONVERT_RIGHT:
      return os << "ConvertRight";
    case STRING_ADD_CONVERT:
      break;
  }
  UNREACHABLE();
  return os;
}

162 163
}  // namespace internal
}  // namespace v8