| OLD | NEW | 
|---|
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 147 | 147 | 
| 148 // AstValue is either a string, a number, a string array, a boolean, or a | 148 // AstValue is either a string, a number, a string array, a boolean, or a | 
| 149 // special value (null, undefined, the hole). | 149 // special value (null, undefined, the hole). | 
| 150 class AstValue : public ZoneObject { | 150 class AstValue : public ZoneObject { | 
| 151  public: | 151  public: | 
| 152   bool IsString() const { | 152   bool IsString() const { | 
| 153     return type_ == STRING; | 153     return type_ == STRING; | 
| 154   } | 154   } | 
| 155 | 155 | 
| 156   bool IsNumber() const { | 156   bool IsNumber() const { | 
| 157     return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; | 157     return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI || | 
|  | 158            type_ == SMI_WITH_DOT; | 
| 158   } | 159   } | 
| 159 | 160 | 
| 160   bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } | 161   bool ContainsDot() const { | 
|  | 162     return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT; | 
|  | 163   } | 
| 161 | 164 | 
| 162   const AstRawString* AsString() const { | 165   const AstRawString* AsString() const { | 
| 163     CHECK_EQ(STRING, type_); | 166     CHECK_EQ(STRING, type_); | 
| 164     return string_; | 167     return string_; | 
| 165   } | 168   } | 
| 166 | 169 | 
| 167   double AsNumber() const { | 170   double AsNumber() const { | 
| 168     if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) | 171     if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) | 
| 169       return number_; | 172       return number_; | 
| 170     if (type_ == SMI) | 173     if (type_ == SMI || type_ == SMI_WITH_DOT) | 
| 171       return smi_; | 174       return smi_; | 
| 172     UNREACHABLE(); | 175     UNREACHABLE(); | 
| 173     return 0; | 176     return 0; | 
| 174   } | 177   } | 
| 175 | 178 | 
| 176   Smi* AsSmi() const { | 179   Smi* AsSmi() const { | 
| 177     CHECK_EQ(SMI, type_); | 180     CHECK(type_ == SMI || type_ == SMI_WITH_DOT); | 
| 178     return Smi::FromInt(smi_); | 181     return Smi::FromInt(smi_); | 
| 179   } | 182   } | 
| 180 | 183 | 
| 181   bool EqualsString(const AstRawString* string) const { | 184   bool EqualsString(const AstRawString* string) const { | 
| 182     return type_ == STRING && string_ == string; | 185     return type_ == STRING && string_ == string; | 
| 183   } | 186   } | 
| 184 | 187 | 
| 185   bool IsPropertyName() const; | 188   bool IsPropertyName() const; | 
| 186 | 189 | 
| 187   bool BooleanValue() const; | 190   bool BooleanValue() const; | 
| 188 | 191 | 
| 189   bool IsSmi() const { return type_ == SMI; } | 192   bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } | 
| 190   bool IsFalse() const { return type_ == BOOLEAN && !bool_; } | 193   bool IsFalse() const { return type_ == BOOLEAN && !bool_; } | 
| 191   bool IsTrue() const { return type_ == BOOLEAN && bool_; } | 194   bool IsTrue() const { return type_ == BOOLEAN && bool_; } | 
| 192   bool IsUndefined() const { return type_ == UNDEFINED; } | 195   bool IsUndefined() const { return type_ == UNDEFINED; } | 
| 193   bool IsTheHole() const { return type_ == THE_HOLE; } | 196   bool IsTheHole() const { return type_ == THE_HOLE; } | 
| 194   bool IsNull() const { return type_ == NULL_TYPE; } | 197   bool IsNull() const { return type_ == NULL_TYPE; } | 
| 195 | 198 | 
| 196   void Internalize(Isolate* isolate); | 199   void Internalize(Isolate* isolate); | 
| 197 | 200 | 
| 198   // Can be called after Internalize has been called. | 201   // Can be called after Internalize has been called. | 
| 199   V8_INLINE Handle<Object> value() const { | 202   V8_INLINE Handle<Object> value() const { | 
| 200     if (type_ == STRING) { | 203     if (type_ == STRING) { | 
| 201       return string_->string(); | 204       return string_->string(); | 
| 202     } | 205     } | 
| 203     DCHECK(!value_.is_null()); | 206     DCHECK(!value_.is_null()); | 
| 204     return value_; | 207     return value_; | 
| 205   } | 208   } | 
| 206   AstValue* next() const { return next_; } | 209   AstValue* next() const { return next_; } | 
| 207   void set_next(AstValue* next) { next_ = next; } | 210   void set_next(AstValue* next) { next_ = next; } | 
| 208 | 211 | 
| 209  private: | 212  private: | 
| 210   friend class AstValueFactory; | 213   friend class AstValueFactory; | 
| 211 | 214 | 
| 212   enum Type { | 215   enum Type { | 
| 213     STRING, | 216     STRING, | 
| 214     SYMBOL, | 217     SYMBOL, | 
| 215     NUMBER, | 218     NUMBER, | 
| 216     NUMBER_WITH_DOT, | 219     NUMBER_WITH_DOT, | 
| 217     SMI, | 220     SMI, | 
|  | 221     SMI_WITH_DOT, | 
| 218     BOOLEAN, | 222     BOOLEAN, | 
| 219     NULL_TYPE, | 223     NULL_TYPE, | 
| 220     UNDEFINED, | 224     UNDEFINED, | 
| 221     THE_HOLE | 225     THE_HOLE | 
| 222   }; | 226   }; | 
| 223 | 227 | 
| 224   explicit AstValue(const AstRawString* s) : type_(STRING), next_(nullptr) { | 228   explicit AstValue(const AstRawString* s) : type_(STRING), next_(nullptr) { | 
| 225     string_ = s; | 229     string_ = s; | 
| 226   } | 230   } | 
| 227 | 231 | 
| 228   explicit AstValue(const char* name) : type_(SYMBOL), next_(nullptr) { | 232   explicit AstValue(const char* name) : type_(SYMBOL), next_(nullptr) { | 
| 229     symbol_name_ = name; | 233     symbol_name_ = name; | 
| 230   } | 234   } | 
| 231 | 235 | 
| 232   explicit AstValue(double n, bool with_dot) : next_(nullptr) { | 236   explicit AstValue(double n, bool with_dot) : next_(nullptr) { | 
| 233     if (with_dot) { | 237     int int_value; | 
| 234       type_ = NUMBER_WITH_DOT; | 238     if (DoubleToSmiInteger(n, &int_value)) { | 
|  | 239       type_ = with_dot ? SMI_WITH_DOT : SMI; | 
|  | 240       smi_ = int_value; | 
|  | 241     } else { | 
|  | 242       type_ = with_dot ? NUMBER_WITH_DOT : NUMBER; | 
| 235       number_ = n; | 243       number_ = n; | 
| 236     } else { |  | 
| 237       int int_value; |  | 
| 238       if (DoubleToSmiInteger(n, &int_value)) { |  | 
| 239         type_ = SMI; |  | 
| 240         smi_ = int_value; |  | 
| 241       } else { |  | 
| 242         type_ = NUMBER; |  | 
| 243         number_ = n; |  | 
| 244       } |  | 
| 245     } | 244     } | 
| 246   } | 245   } | 
| 247 | 246 | 
| 248   AstValue(Type t, int i) : type_(t), next_(nullptr) { | 247   AstValue(Type t, int i) : type_(t), next_(nullptr) { | 
| 249     DCHECK(type_ == SMI); | 248     DCHECK(type_ == SMI); | 
| 250     smi_ = i; | 249     smi_ = i; | 
| 251   } | 250   } | 
| 252 | 251 | 
| 253   explicit AstValue(bool b) : type_(BOOLEAN), next_(nullptr) { bool_ = b; } | 252   explicit AstValue(bool b) : type_(BOOLEAN), next_(nullptr) { bool_ = b; } | 
| 254 | 253 | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 434   OTHER_CONSTANTS(F) | 433   OTHER_CONSTANTS(F) | 
| 435 #undef F | 434 #undef F | 
| 436 }; | 435 }; | 
| 437 }  // namespace internal | 436 }  // namespace internal | 
| 438 }  // namespace v8 | 437 }  // namespace v8 | 
| 439 | 438 | 
| 440 #undef STRING_CONSTANTS | 439 #undef STRING_CONSTANTS | 
| 441 #undef OTHER_CONSTANTS | 440 #undef OTHER_CONSTANTS | 
| 442 | 441 | 
| 443 #endif  // V8_AST_AST_VALUE_FACTORY_H_ | 442 #endif  // V8_AST_AST_VALUE_FACTORY_H_ | 
| OLD | NEW | 
|---|