| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_AST_H_ | 5 #ifndef V8_AST_H_ |
| 6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 | 9 |
| 10 #include "assembler.h" | 10 #include "assembler.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 V(TryCatchStatement) \ | 71 V(TryCatchStatement) \ |
| 72 V(TryFinallyStatement) \ | 72 V(TryFinallyStatement) \ |
| 73 V(DebuggerStatement) | 73 V(DebuggerStatement) |
| 74 | 74 |
| 75 #define EXPRESSION_NODE_LIST(V) \ | 75 #define EXPRESSION_NODE_LIST(V) \ |
| 76 V(FunctionLiteral) \ | 76 V(FunctionLiteral) \ |
| 77 V(NativeFunctionLiteral) \ | 77 V(NativeFunctionLiteral) \ |
| 78 V(Conditional) \ | 78 V(Conditional) \ |
| 79 V(VariableProxy) \ | 79 V(VariableProxy) \ |
| 80 V(Literal) \ | 80 V(Literal) \ |
| 81 V(StringLiteral) \ |
| 82 V(NumberLiteral) \ |
| 81 V(RegExpLiteral) \ | 83 V(RegExpLiteral) \ |
| 82 V(ObjectLiteral) \ | 84 V(ObjectLiteral) \ |
| 83 V(ArrayLiteral) \ | 85 V(ArrayLiteral) \ |
| 84 V(Assignment) \ | 86 V(Assignment) \ |
| 85 V(Yield) \ | 87 V(Yield) \ |
| 86 V(Throw) \ | 88 V(Throw) \ |
| 87 V(Property) \ | 89 V(Property) \ |
| 88 V(Call) \ | 90 V(Call) \ |
| 89 V(CallNew) \ | 91 V(CallNew) \ |
| 90 V(CallRuntime) \ | 92 V(CallRuntime) \ |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // names because [] for string objects is handled only by keyed ICs. | 325 // names because [] for string objects is handled only by keyed ICs. |
| 324 virtual bool IsPropertyName() const { return false; } | 326 virtual bool IsPropertyName() const { return false; } |
| 325 | 327 |
| 326 // True iff the result can be safely overwritten (to avoid allocation). | 328 // True iff the result can be safely overwritten (to avoid allocation). |
| 327 // False for operations that can return one of their operands. | 329 // False for operations that can return one of their operands. |
| 328 virtual bool ResultOverwriteAllowed() const { return false; } | 330 virtual bool ResultOverwriteAllowed() const { return false; } |
| 329 | 331 |
| 330 // True iff the expression is a literal represented as a smi. | 332 // True iff the expression is a literal represented as a smi. |
| 331 bool IsSmiLiteral() const; | 333 bool IsSmiLiteral() const; |
| 332 | 334 |
| 333 // True iff the expression is a string literal. | |
| 334 bool IsStringLiteral() const; | |
| 335 | |
| 336 // True iff the expression is the null literal. | 335 // True iff the expression is the null literal. |
| 337 bool IsNullLiteral() const; | 336 bool IsNullLiteral() const; |
| 338 | 337 |
| 339 // True if we can prove that the expression is the undefined literal. | 338 // True if we can prove that the expression is the undefined literal. |
| 340 bool IsUndefinedLiteral(Isolate* isolate) const; | 339 bool IsUndefinedLiteral(Isolate* isolate) const; |
| 341 | 340 |
| 341 Literal* AsAnyLiteral(); |
| 342 |
| 342 // Expression type bounds | 343 // Expression type bounds |
| 343 Bounds bounds() const { return bounds_; } | 344 Bounds bounds() const { return bounds_; } |
| 344 void set_bounds(Bounds bounds) { bounds_ = bounds; } | 345 void set_bounds(Bounds bounds) { bounds_ = bounds; } |
| 345 | 346 |
| 346 // Type feedback information for assignments and properties. | 347 // Type feedback information for assignments and properties. |
| 347 virtual bool IsMonomorphic() { | 348 virtual bool IsMonomorphic() { |
| 348 UNREACHABLE(); | 349 UNREACHABLE(); |
| 349 return false; | 350 return false; |
| 350 } | 351 } |
| 351 virtual SmallMapList* GetReceiverTypes() { | 352 virtual SmallMapList* GetReceiverTypes() { |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1321 | 1322 |
| 1322 class EmptyStatement V8_FINAL : public Statement { | 1323 class EmptyStatement V8_FINAL : public Statement { |
| 1323 public: | 1324 public: |
| 1324 DECLARE_NODE_TYPE(EmptyStatement) | 1325 DECLARE_NODE_TYPE(EmptyStatement) |
| 1325 | 1326 |
| 1326 protected: | 1327 protected: |
| 1327 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} | 1328 explicit EmptyStatement(Zone* zone, int pos): Statement(zone, pos) {} |
| 1328 }; | 1329 }; |
| 1329 | 1330 |
| 1330 | 1331 |
| 1331 class Literal V8_FINAL : public Expression { | 1332 class Literal : public Expression { |
| 1332 public: | 1333 public: |
| 1333 DECLARE_NODE_TYPE(Literal) | 1334 DECLARE_NODE_TYPE(Literal) |
| 1334 | 1335 |
| 1335 virtual bool IsPropertyName() const V8_OVERRIDE { | |
| 1336 if (value_->IsInternalizedString()) { | |
| 1337 uint32_t ignored; | |
| 1338 return !String::cast(*value_)->AsArrayIndex(&ignored); | |
| 1339 } | |
| 1340 return false; | |
| 1341 } | |
| 1342 | |
| 1343 Handle<String> AsPropertyName() { | |
| 1344 ASSERT(IsPropertyName()); | |
| 1345 return Handle<String>::cast(value_); | |
| 1346 } | |
| 1347 | |
| 1348 virtual bool ToBooleanIsTrue() const V8_OVERRIDE { | 1336 virtual bool ToBooleanIsTrue() const V8_OVERRIDE { |
| 1349 return value_->BooleanValue(); | 1337 return value()->BooleanValue(); |
| 1350 } | 1338 } |
| 1351 virtual bool ToBooleanIsFalse() const V8_OVERRIDE { | 1339 virtual bool ToBooleanIsFalse() const V8_OVERRIDE { |
| 1352 return !value_->BooleanValue(); | 1340 return !value()->BooleanValue(); |
| 1353 } | 1341 } |
| 1354 | 1342 |
| 1355 // Identity testers. | 1343 // Identity testers. |
| 1356 bool IsNull() const { | 1344 bool IsNull() const { |
| 1357 ASSERT(!value_.is_null()); | 1345 ASSERT(!value_.is_null()); |
| 1358 return value_->IsNull(); | 1346 return value_->IsNull(); |
| 1359 } | 1347 } |
| 1360 bool IsTrue() const { | 1348 bool IsTrue() const { |
| 1361 ASSERT(!value_.is_null()); | 1349 ASSERT(!value_.is_null()); |
| 1362 return value_->IsTrue(); | 1350 return value_->IsTrue(); |
| 1363 } | 1351 } |
| 1364 bool IsFalse() const { | 1352 bool IsFalse() const { |
| 1365 ASSERT(!value_.is_null()); | 1353 ASSERT(!value_.is_null()); |
| 1366 return value_->IsFalse(); | 1354 return value_->IsFalse(); |
| 1367 } | 1355 } |
| 1368 | 1356 |
| 1369 Handle<Object> value() const { return value_; } | 1357 virtual Handle<Object> value() const { return value_; } |
| 1370 | 1358 |
| 1371 // Support for using Literal as a HashMap key. NOTE: Currently, this works | 1359 // Support for using Literal as a HashMap key. NOTE: Currently, this works |
| 1372 // only for string and number literals! | 1360 // only for string and number literals! |
| 1373 uint32_t Hash() { return ToString()->Hash(); } | 1361 uint32_t Hash() { return ToString()->Hash(); } |
| 1374 | 1362 |
| 1375 static bool Match(void* literal1, void* literal2) { | 1363 static bool Match(void* literal1, void* literal2) { |
| 1376 Handle<String> s1 = static_cast<Literal*>(literal1)->ToString(); | 1364 Handle<String> s1 = static_cast<Literal*>(literal1)->ToString(); |
| 1377 Handle<String> s2 = static_cast<Literal*>(literal2)->ToString(); | 1365 Handle<String> s2 = static_cast<Literal*>(literal2)->ToString(); |
| 1378 return String::Equals(s1, s2); | 1366 return String::Equals(s1, s2); |
| 1379 } | 1367 } |
| 1380 | 1368 |
| 1381 TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); } | 1369 TypeFeedbackId LiteralFeedbackId() const { return reuse(id()); } |
| 1382 | 1370 |
| 1383 protected: | 1371 protected: |
| 1372 Literal(Zone* zone, int position) |
| 1373 : Expression(zone, position), |
| 1374 isolate_(zone->isolate()) {} |
| 1384 Literal(Zone* zone, Handle<Object> value, int position) | 1375 Literal(Zone* zone, Handle<Object> value, int position) |
| 1385 : Expression(zone, position), | 1376 : Expression(zone, position), |
| 1386 value_(value), | 1377 isolate_(zone->isolate()), |
| 1387 isolate_(zone->isolate()) { } | 1378 value_(value) {} |
| 1379 |
| 1380 virtual Handle<String> ToString() const; |
| 1381 |
| 1382 // TODO(dcarney): remove. this is only needed for Match and Hash. |
| 1383 Isolate* isolate_; |
| 1388 | 1384 |
| 1389 private: | 1385 private: |
| 1390 Handle<String> ToString(); | 1386 Handle<Object> value_; |
| 1387 }; |
| 1388 |
| 1389 |
| 1390 class StringLiteral V8_FINAL : public Literal { |
| 1391 public: |
| 1392 DECLARE_NODE_TYPE(StringLiteral) |
| 1393 |
| 1394 virtual bool IsPropertyName() const V8_OVERRIDE { |
| 1395 uint32_t ignored; |
| 1396 return !string_->AsArrayIndex(&ignored); |
| 1397 } |
| 1398 |
| 1399 virtual Handle<String> AsPropertyName() const V8_OVERRIDE { |
| 1400 ASSERT(IsPropertyName()); |
| 1401 return string_; |
| 1402 } |
| 1403 |
| 1404 virtual Handle<Object> value() const V8_OVERRIDE { |
| 1405 return string_; |
| 1406 } |
| 1407 |
| 1408 virtual Handle<String> string() const V8_OVERRIDE { return string_; } |
| 1409 |
| 1410 protected: |
| 1411 virtual Handle<String> ToString() const V8_OVERRIDE { return string_; } |
| 1412 |
| 1413 private: |
| 1414 StringLiteral(Zone* zone, Handle<String> string, |
| 1415 int position) |
| 1416 : Literal(zone, position), string_(string) {} |
| 1417 |
| 1418 Handle<String> string_; |
| 1419 }; |
| 1420 |
| 1421 |
| 1422 class NumberLiteral V8_FINAL : public Literal { |
| 1423 public: |
| 1424 DECLARE_NODE_TYPE(NumberLiteral) |
| 1425 |
| 1426 virtual Handle<Object> value() const V8_OVERRIDE { |
| 1427 return value_; |
| 1428 } |
| 1429 |
| 1430 double number() const { |
| 1431 return value_->Number(); |
| 1432 } |
| 1433 |
| 1434 protected: |
| 1435 virtual Handle<String> ToString() const V8_OVERRIDE; |
| 1436 |
| 1437 private: |
| 1438 NumberLiteral(Zone* zone, Handle<Object> value, |
| 1439 int position) |
| 1440 : Literal(zone, position), value_(value) { |
| 1441 ASSERT(value->IsNumber()); |
| 1442 } |
| 1391 | 1443 |
| 1392 Handle<Object> value_; | 1444 Handle<Object> value_; |
| 1393 // TODO(dcarney): remove. this is only needed for Match and Hash. | |
| 1394 Isolate* isolate_; | |
| 1395 }; | 1445 }; |
| 1396 | 1446 |
| 1397 | 1447 |
| 1448 |
| 1398 // Base class for literals that needs space in the corresponding JSFunction. | 1449 // Base class for literals that needs space in the corresponding JSFunction. |
| 1399 class MaterializedLiteral : public Expression { | 1450 class MaterializedLiteral : public Expression { |
| 1400 public: | 1451 public: |
| 1401 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | 1452 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
| 1402 | 1453 |
| 1403 int literal_index() { return literal_index_; } | 1454 int literal_index() { return literal_index_; } |
| 1404 | 1455 |
| 1405 int depth() const { | 1456 int depth() const { |
| 1406 // only callable after initialization. | 1457 // only callable after initialization. |
| 1407 ASSERT(depth_ >= 1); | 1458 ASSERT(depth_ >= 1); |
| (...skipping 1713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3121 } | 3172 } |
| 3122 | 3173 |
| 3123 CaseClause* NewCaseClause( | 3174 CaseClause* NewCaseClause( |
| 3124 Expression* label, ZoneList<Statement*>* statements, int pos) { | 3175 Expression* label, ZoneList<Statement*>* statements, int pos) { |
| 3125 CaseClause* clause = | 3176 CaseClause* clause = |
| 3126 new(zone_) CaseClause(zone_, label, statements, pos); | 3177 new(zone_) CaseClause(zone_, label, statements, pos); |
| 3127 VISIT_AND_RETURN(CaseClause, clause) | 3178 VISIT_AND_RETURN(CaseClause, clause) |
| 3128 } | 3179 } |
| 3129 | 3180 |
| 3130 Literal* NewLiteral(Handle<Object> handle, int pos) { | 3181 Literal* NewLiteral(Handle<Object> handle, int pos) { |
| 3182 ASSERT(!handle->IsString()); |
| 3131 Literal* lit = new(zone_) Literal(zone_, handle, pos); | 3183 Literal* lit = new(zone_) Literal(zone_, handle, pos); |
| 3132 VISIT_AND_RETURN(Literal, lit) | 3184 VISIT_AND_RETURN(Literal, lit) |
| 3133 } | 3185 } |
| 3134 | 3186 |
| 3135 Literal* NewNumberLiteral(double number, int pos) { | 3187 StringLiteral* NewStringLiteral(Handle<String> handle, int pos) { |
| 3136 return NewLiteral( | 3188 StringLiteral* lit = new(zone_) StringLiteral(zone_, handle, pos); |
| 3189 VISIT_AND_RETURN(StringLiteral, lit) |
| 3190 } |
| 3191 |
| 3192 NumberLiteral* NewNumberLiteral(Handle<Object> handle, int pos) { |
| 3193 ASSERT(handle->IsNumber()); |
| 3194 NumberLiteral* lit = new(zone_) NumberLiteral(zone_, handle, pos); |
| 3195 VISIT_AND_RETURN(NumberLiteral, lit) |
| 3196 } |
| 3197 |
| 3198 NumberLiteral* NewNumberLiteral(double number, int pos) { |
| 3199 return NewNumberLiteral( |
| 3137 zone_->isolate()->factory()->NewNumber(number, TENURED), pos); | 3200 zone_->isolate()->factory()->NewNumber(number, TENURED), pos); |
| 3138 } | 3201 } |
| 3139 | 3202 |
| 3140 ObjectLiteral* NewObjectLiteral( | 3203 ObjectLiteral* NewObjectLiteral( |
| 3141 ZoneList<ObjectLiteral::Property*>* properties, | 3204 ZoneList<ObjectLiteral::Property*>* properties, |
| 3142 int literal_index, | 3205 int literal_index, |
| 3143 int boilerplate_properties, | 3206 int boilerplate_properties, |
| 3144 bool has_function, | 3207 bool has_function, |
| 3145 int pos) { | 3208 int pos) { |
| 3146 ObjectLiteral* lit = new(zone_) ObjectLiteral( | 3209 ObjectLiteral* lit = new(zone_) ObjectLiteral( |
| 3147 zone_, properties, literal_index, boilerplate_properties, | 3210 zone_, properties, literal_index, boilerplate_properties, |
| 3148 has_function, pos); | 3211 has_function, pos); |
| 3149 VISIT_AND_RETURN(ObjectLiteral, lit) | 3212 VISIT_AND_RETURN(ObjectLiteral, lit) |
| 3150 } | 3213 } |
| 3151 | 3214 |
| 3152 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, | 3215 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, |
| 3153 Expression* value) { | 3216 Expression* value) { |
| 3154 return new(zone_) ObjectLiteral::Property(zone_, key, value); | 3217 return new(zone_) ObjectLiteral::Property(zone_, key, value); |
| 3155 } | 3218 } |
| 3156 | 3219 |
| 3157 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, | 3220 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, |
| 3158 FunctionLiteral* value, | 3221 FunctionLiteral* value, |
| 3159 int pos) { | 3222 int pos) { |
| 3160 ObjectLiteral::Property* prop = | 3223 ObjectLiteral::Property* prop = |
| 3161 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); | 3224 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); |
| 3162 prop->set_key(NewLiteral(value->name(), pos)); | 3225 prop->set_key(NewStringLiteral(value->name(), pos)); |
| 3163 return prop; // Not an AST node, will not be visited. | 3226 return prop; // Not an AST node, will not be visited. |
| 3164 } | 3227 } |
| 3165 | 3228 |
| 3166 RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, | 3229 RegExpLiteral* NewRegExpLiteral(Handle<String> pattern, |
| 3167 Handle<String> flags, | 3230 Handle<String> flags, |
| 3168 int literal_index, | 3231 int literal_index, |
| 3169 int pos) { | 3232 int pos) { |
| 3170 RegExpLiteral* lit = | 3233 RegExpLiteral* lit = |
| 3171 new(zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); | 3234 new(zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); |
| 3172 VISIT_AND_RETURN(RegExpLiteral, lit); | 3235 VISIT_AND_RETURN(RegExpLiteral, lit); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3333 | 3396 |
| 3334 private: | 3397 private: |
| 3335 Zone* zone_; | 3398 Zone* zone_; |
| 3336 Visitor visitor_; | 3399 Visitor visitor_; |
| 3337 }; | 3400 }; |
| 3338 | 3401 |
| 3339 | 3402 |
| 3340 } } // namespace v8::internal | 3403 } } // namespace v8::internal |
| 3341 | 3404 |
| 3342 #endif // V8_AST_H_ | 3405 #endif // V8_AST_H_ |
| OLD | NEW |