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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return type_ == STRING; | 139 return type_ == STRING; |
140 } | 140 } |
141 | 141 |
142 bool IsNumber() const { | 142 bool IsNumber() const { |
143 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; | 143 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI; |
144 } | 144 } |
145 | 145 |
146 bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } | 146 bool ContainsDot() const { return type_ == NUMBER_WITH_DOT; } |
147 | 147 |
148 const AstRawString* AsString() const { | 148 const AstRawString* AsString() const { |
149 if (type_ == STRING) | 149 CHECK_EQ(STRING, type_); |
150 return string_; | 150 return string_; |
151 UNREACHABLE(); | |
152 return 0; | |
153 } | 151 } |
154 | 152 |
155 double AsNumber() const { | 153 double AsNumber() const { |
156 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) | 154 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) |
157 return number_; | 155 return number_; |
158 if (type_ == SMI) | 156 if (type_ == SMI) |
159 return smi_; | 157 return smi_; |
160 UNREACHABLE(); | 158 UNREACHABLE(); |
161 return 0; | 159 return 0; |
162 } | 160 } |
163 | 161 |
| 162 Smi* AsSmi() const { |
| 163 CHECK_EQ(SMI, type_); |
| 164 return Smi::FromInt(smi_); |
| 165 } |
| 166 |
164 bool EqualsString(const AstRawString* string) const { | 167 bool EqualsString(const AstRawString* string) const { |
165 return type_ == STRING && string_ == string; | 168 return type_ == STRING && string_ == string; |
166 } | 169 } |
167 | 170 |
168 bool IsPropertyName() const; | 171 bool IsPropertyName() const; |
169 | 172 |
170 bool BooleanValue() const; | 173 bool BooleanValue() const; |
171 | 174 |
| 175 bool IsSmi() const { return type_ == SMI; } |
| 176 bool IsFalse() const { return type_ == BOOLEAN && !bool_; } |
| 177 bool IsTrue() const { return type_ == BOOLEAN && bool_; } |
| 178 bool IsUndefined() const { return type_ == UNDEFINED; } |
172 bool IsTheHole() const { return type_ == THE_HOLE; } | 179 bool IsTheHole() const { return type_ == THE_HOLE; } |
| 180 bool IsNull() const { return type_ == NULL_TYPE; } |
173 | 181 |
174 void Internalize(Isolate* isolate); | 182 void Internalize(Isolate* isolate); |
175 | 183 |
176 // Can be called after Internalize has been called. | 184 // Can be called after Internalize has been called. |
177 V8_INLINE Handle<Object> value() const { | 185 V8_INLINE Handle<Object> value() const { |
178 if (type_ == STRING) { | 186 if (type_ == STRING) { |
179 return string_->string(); | 187 return string_->string(); |
180 } | 188 } |
181 DCHECK(!value_.is_null()); | 189 DCHECK(!value_.is_null()); |
182 return value_; | 190 return value_; |
(...skipping 14 matching lines...) Expand all Loading... |
197 THE_HOLE | 205 THE_HOLE |
198 }; | 206 }; |
199 | 207 |
200 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; } | 208 explicit AstValue(const AstRawString* s) : type_(STRING) { string_ = s; } |
201 | 209 |
202 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; } | 210 explicit AstValue(const char* name) : type_(SYMBOL) { symbol_name_ = name; } |
203 | 211 |
204 explicit AstValue(double n, bool with_dot) { | 212 explicit AstValue(double n, bool with_dot) { |
205 if (with_dot) { | 213 if (with_dot) { |
206 type_ = NUMBER_WITH_DOT; | 214 type_ = NUMBER_WITH_DOT; |
| 215 number_ = n; |
207 } else { | 216 } else { |
208 type_ = NUMBER; | 217 int int_value; |
| 218 if (DoubleToSmiInteger(n, &int_value)) { |
| 219 type_ = SMI; |
| 220 smi_ = int_value; |
| 221 } else { |
| 222 type_ = NUMBER; |
| 223 number_ = n; |
| 224 } |
209 } | 225 } |
210 number_ = n; | |
211 } | 226 } |
212 | 227 |
213 AstValue(Type t, int i) : type_(t) { | 228 AstValue(Type t, int i) : type_(t) { |
214 DCHECK(type_ == SMI); | 229 DCHECK(type_ == SMI); |
215 smi_ = i; | 230 smi_ = i; |
216 } | 231 } |
217 | 232 |
218 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; } | 233 explicit AstValue(bool b) : type_(BOOLEAN) { bool_ = b; } |
219 | 234 |
220 explicit AstValue(Type t) : type_(t) { | 235 explicit AstValue(Type t) : type_(t) { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 OTHER_CONSTANTS(F) | 385 OTHER_CONSTANTS(F) |
371 #undef F | 386 #undef F |
372 }; | 387 }; |
373 } // namespace internal | 388 } // namespace internal |
374 } // namespace v8 | 389 } // namespace v8 |
375 | 390 |
376 #undef STRING_CONSTANTS | 391 #undef STRING_CONSTANTS |
377 #undef OTHER_CONSTANTS | 392 #undef OTHER_CONSTANTS |
378 | 393 |
379 #endif // V8_AST_AST_VALUE_FACTORY_H_ | 394 #endif // V8_AST_AST_VALUE_FACTORY_H_ |
OLD | NEW |