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 "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | 1288 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
1289 | 1289 |
1290 int literal_index() { return literal_index_; } | 1290 int literal_index() { return literal_index_; } |
1291 | 1291 |
1292 int depth() const { | 1292 int depth() const { |
1293 // only callable after initialization. | 1293 // only callable after initialization. |
1294 DCHECK(depth_ >= 1); | 1294 DCHECK(depth_ >= 1); |
1295 return depth_; | 1295 return depth_; |
1296 } | 1296 } |
1297 | 1297 |
| 1298 bool is_strong() const { return is_strong_; } |
| 1299 |
1298 protected: | 1300 protected: |
1299 MaterializedLiteral(Zone* zone, int literal_index, int pos) | 1301 MaterializedLiteral(Zone* zone, int literal_index, bool is_strong, int pos) |
1300 : Expression(zone, pos), | 1302 : Expression(zone, pos), |
1301 literal_index_(literal_index), | 1303 literal_index_(literal_index), |
1302 is_simple_(false), | 1304 is_simple_(false), |
| 1305 is_strong_(is_strong), |
1303 depth_(0) {} | 1306 depth_(0) {} |
1304 | 1307 |
1305 // A materialized literal is simple if the values consist of only | 1308 // A materialized literal is simple if the values consist of only |
1306 // constants and simple object and array literals. | 1309 // constants and simple object and array literals. |
1307 bool is_simple() const { return is_simple_; } | 1310 bool is_simple() const { return is_simple_; } |
1308 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } | 1311 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } |
1309 friend class CompileTimeValue; | 1312 friend class CompileTimeValue; |
1310 | 1313 |
1311 void set_depth(int depth) { | 1314 void set_depth(int depth) { |
1312 DCHECK(depth >= 1); | 1315 DCHECK(depth >= 1); |
1313 depth_ = depth; | 1316 depth_ = depth; |
1314 } | 1317 } |
1315 | 1318 |
1316 // Populate the constant properties/elements fixed array. | 1319 // Populate the constant properties/elements fixed array. |
1317 void BuildConstants(Isolate* isolate); | 1320 void BuildConstants(Isolate* isolate); |
1318 friend class ArrayLiteral; | 1321 friend class ArrayLiteral; |
1319 friend class ObjectLiteral; | 1322 friend class ObjectLiteral; |
1320 | 1323 |
1321 // If the expression is a literal, return the literal value; | 1324 // If the expression is a literal, return the literal value; |
1322 // if the expression is a materialized literal and is simple return a | 1325 // if the expression is a materialized literal and is simple return a |
1323 // compile time value as encoded by CompileTimeValue::GetValue(). | 1326 // compile time value as encoded by CompileTimeValue::GetValue(). |
1324 // Otherwise, return undefined literal as the placeholder | 1327 // Otherwise, return undefined literal as the placeholder |
1325 // in the object literal boilerplate. | 1328 // in the object literal boilerplate. |
1326 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); | 1329 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); |
1327 | 1330 |
1328 private: | 1331 private: |
1329 int literal_index_; | 1332 int literal_index_; |
1330 bool is_simple_; | 1333 bool is_simple_; |
| 1334 bool is_strong_; |
1331 int depth_; | 1335 int depth_; |
1332 }; | 1336 }; |
1333 | 1337 |
1334 | 1338 |
1335 // Property is used for passing information | 1339 // Property is used for passing information |
1336 // about an object literal's properties from the parser | 1340 // about an object literal's properties from the parser |
1337 // to the code generator. | 1341 // to the code generator. |
1338 class ObjectLiteralProperty final : public ZoneObject { | 1342 class ObjectLiteralProperty final : public ZoneObject { |
1339 public: | 1343 public: |
1340 enum Kind { | 1344 enum Kind { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 // Assemble bitfield of flags for the CreateObjectLiteral helper. | 1419 // Assemble bitfield of flags for the CreateObjectLiteral helper. |
1416 int ComputeFlags(bool disable_mementos = false) const { | 1420 int ComputeFlags(bool disable_mementos = false) const { |
1417 int flags = fast_elements() ? kFastElements : kNoFlags; | 1421 int flags = fast_elements() ? kFastElements : kNoFlags; |
1418 flags |= has_function() ? kHasFunction : kNoFlags; | 1422 flags |= has_function() ? kHasFunction : kNoFlags; |
1419 if (depth() == 1 && !has_elements() && !may_store_doubles()) { | 1423 if (depth() == 1 && !has_elements() && !may_store_doubles()) { |
1420 flags |= kShallowProperties; | 1424 flags |= kShallowProperties; |
1421 } | 1425 } |
1422 if (disable_mementos) { | 1426 if (disable_mementos) { |
1423 flags |= kDisableMementos; | 1427 flags |= kDisableMementos; |
1424 } | 1428 } |
| 1429 if (is_strong()) { |
| 1430 flags |= kIsStrong; |
| 1431 } |
1425 return flags; | 1432 return flags; |
1426 } | 1433 } |
1427 | 1434 |
1428 enum Flags { | 1435 enum Flags { |
1429 kNoFlags = 0, | 1436 kNoFlags = 0, |
1430 kFastElements = 1, | 1437 kFastElements = 1, |
1431 kHasFunction = 1 << 1, | 1438 kHasFunction = 1 << 1, |
1432 kShallowProperties = 1 << 2, | 1439 kShallowProperties = 1 << 2, |
1433 kDisableMementos = 1 << 3 | 1440 kDisableMementos = 1 << 3, |
| 1441 kIsStrong = 1 << 4 |
1434 }; | 1442 }; |
1435 | 1443 |
1436 struct Accessors: public ZoneObject { | 1444 struct Accessors: public ZoneObject { |
1437 Accessors() : getter(NULL), setter(NULL) {} | 1445 Accessors() : getter(NULL), setter(NULL) {} |
1438 Expression* getter; | 1446 Expression* getter; |
1439 Expression* setter; | 1447 Expression* setter; |
1440 }; | 1448 }; |
1441 | 1449 |
1442 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1450 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
1443 | 1451 |
1444 // Return an AST id for a property that is used in simulate instructions. | 1452 // Return an AST id for a property that is used in simulate instructions. |
1445 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } | 1453 BailoutId GetIdForProperty(int i) { return BailoutId(local_id(i + 1)); } |
1446 | 1454 |
1447 // Unlike other AST nodes, this number of bailout IDs allocated for an | 1455 // Unlike other AST nodes, this number of bailout IDs allocated for an |
1448 // ObjectLiteral can vary, so num_ids() is not a static method. | 1456 // ObjectLiteral can vary, so num_ids() is not a static method. |
1449 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } | 1457 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } |
1450 | 1458 |
1451 protected: | 1459 protected: |
1452 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, | 1460 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, |
1453 int boilerplate_properties, bool has_function, int pos) | 1461 int boilerplate_properties, bool has_function, |
1454 : MaterializedLiteral(zone, literal_index, pos), | 1462 bool is_strong, int pos) |
| 1463 : MaterializedLiteral(zone, literal_index, is_strong, pos), |
1455 properties_(properties), | 1464 properties_(properties), |
1456 boilerplate_properties_(boilerplate_properties), | 1465 boilerplate_properties_(boilerplate_properties), |
1457 fast_elements_(false), | 1466 fast_elements_(false), |
1458 has_elements_(false), | 1467 has_elements_(false), |
1459 may_store_doubles_(false), | 1468 may_store_doubles_(false), |
1460 has_function_(has_function) {} | 1469 has_function_(has_function) {} |
1461 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1470 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
1462 | 1471 |
1463 private: | 1472 private: |
1464 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1473 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
(...skipping 10 matching lines...) Expand all Loading... |
1475 // Node for capturing a regexp literal. | 1484 // Node for capturing a regexp literal. |
1476 class RegExpLiteral final : public MaterializedLiteral { | 1485 class RegExpLiteral final : public MaterializedLiteral { |
1477 public: | 1486 public: |
1478 DECLARE_NODE_TYPE(RegExpLiteral) | 1487 DECLARE_NODE_TYPE(RegExpLiteral) |
1479 | 1488 |
1480 Handle<String> pattern() const { return pattern_->string(); } | 1489 Handle<String> pattern() const { return pattern_->string(); } |
1481 Handle<String> flags() const { return flags_->string(); } | 1490 Handle<String> flags() const { return flags_->string(); } |
1482 | 1491 |
1483 protected: | 1492 protected: |
1484 RegExpLiteral(Zone* zone, const AstRawString* pattern, | 1493 RegExpLiteral(Zone* zone, const AstRawString* pattern, |
1485 const AstRawString* flags, int literal_index, int pos) | 1494 const AstRawString* flags, int literal_index, bool is_strong, |
1486 : MaterializedLiteral(zone, literal_index, pos), | 1495 int pos) |
| 1496 : MaterializedLiteral(zone, literal_index, is_strong, pos), |
1487 pattern_(pattern), | 1497 pattern_(pattern), |
1488 flags_(flags) { | 1498 flags_(flags) { |
1489 set_depth(1); | 1499 set_depth(1); |
1490 } | 1500 } |
1491 | 1501 |
1492 private: | 1502 private: |
1493 const AstRawString* pattern_; | 1503 const AstRawString* pattern_; |
1494 const AstRawString* flags_; | 1504 const AstRawString* flags_; |
1495 }; | 1505 }; |
1496 | 1506 |
(...skipping 24 matching lines...) Expand all Loading... |
1521 | 1531 |
1522 // Populate the constant elements fixed array. | 1532 // Populate the constant elements fixed array. |
1523 void BuildConstantElements(Isolate* isolate); | 1533 void BuildConstantElements(Isolate* isolate); |
1524 | 1534 |
1525 // Assemble bitfield of flags for the CreateArrayLiteral helper. | 1535 // Assemble bitfield of flags for the CreateArrayLiteral helper. |
1526 int ComputeFlags(bool disable_mementos = false) const { | 1536 int ComputeFlags(bool disable_mementos = false) const { |
1527 int flags = depth() == 1 ? kShallowElements : kNoFlags; | 1537 int flags = depth() == 1 ? kShallowElements : kNoFlags; |
1528 if (disable_mementos) { | 1538 if (disable_mementos) { |
1529 flags |= kDisableMementos; | 1539 flags |= kDisableMementos; |
1530 } | 1540 } |
| 1541 if (is_strong()) { |
| 1542 flags |= kIsStrong; |
| 1543 } |
1531 return flags; | 1544 return flags; |
1532 } | 1545 } |
1533 | 1546 |
1534 enum Flags { | 1547 enum Flags { |
1535 kNoFlags = 0, | 1548 kNoFlags = 0, |
1536 kShallowElements = 1, | 1549 kShallowElements = 1, |
1537 kDisableMementos = 1 << 1 | 1550 kDisableMementos = 1 << 1, |
| 1551 kIsStrong = 1 << 2 |
1538 }; | 1552 }; |
1539 | 1553 |
1540 protected: | 1554 protected: |
1541 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index, | 1555 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, int literal_index, |
1542 int pos) | 1556 bool is_strong, int pos) |
1543 : MaterializedLiteral(zone, literal_index, pos), values_(values) {} | 1557 : MaterializedLiteral(zone, literal_index, is_strong, pos), |
| 1558 values_(values) {} |
1544 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1559 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
1545 | 1560 |
1546 private: | 1561 private: |
1547 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1562 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
1548 | 1563 |
1549 Handle<FixedArray> constant_elements_; | 1564 Handle<FixedArray> constant_elements_; |
1550 ZoneList<Expression*>* values_; | 1565 ZoneList<Expression*>* values_; |
1551 }; | 1566 }; |
1552 | 1567 |
1553 | 1568 |
(...skipping 1748 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3302 | 3317 |
3303 Literal* NewTheHoleLiteral(int pos) { | 3318 Literal* NewTheHoleLiteral(int pos) { |
3304 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); | 3319 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); |
3305 } | 3320 } |
3306 | 3321 |
3307 ObjectLiteral* NewObjectLiteral( | 3322 ObjectLiteral* NewObjectLiteral( |
3308 ZoneList<ObjectLiteral::Property*>* properties, | 3323 ZoneList<ObjectLiteral::Property*>* properties, |
3309 int literal_index, | 3324 int literal_index, |
3310 int boilerplate_properties, | 3325 int boilerplate_properties, |
3311 bool has_function, | 3326 bool has_function, |
| 3327 bool is_strong, |
3312 int pos) { | 3328 int pos) { |
3313 return new (zone_) ObjectLiteral(zone_, properties, literal_index, | 3329 return new (zone_) ObjectLiteral(zone_, properties, literal_index, |
3314 boilerplate_properties, has_function, pos); | 3330 boilerplate_properties, has_function, |
| 3331 is_strong, pos); |
3315 } | 3332 } |
3316 | 3333 |
3317 ObjectLiteral::Property* NewObjectLiteralProperty( | 3334 ObjectLiteral::Property* NewObjectLiteralProperty( |
3318 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3335 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
3319 bool is_static, bool is_computed_name) { | 3336 bool is_static, bool is_computed_name) { |
3320 return new (zone_) | 3337 return new (zone_) |
3321 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3338 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); |
3322 } | 3339 } |
3323 | 3340 |
3324 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3341 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
3325 Expression* value, | 3342 Expression* value, |
3326 bool is_static, | 3343 bool is_static, |
3327 bool is_computed_name) { | 3344 bool is_computed_name) { |
3328 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, | 3345 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, |
3329 is_static, is_computed_name); | 3346 is_static, is_computed_name); |
3330 } | 3347 } |
3331 | 3348 |
3332 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, | 3349 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, |
3333 const AstRawString* flags, | 3350 const AstRawString* flags, |
3334 int literal_index, | 3351 int literal_index, |
| 3352 bool is_strong, |
3335 int pos) { | 3353 int pos) { |
3336 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); | 3354 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, |
| 3355 is_strong, pos); |
3337 } | 3356 } |
3338 | 3357 |
3339 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3358 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3340 int literal_index, | 3359 int literal_index, |
| 3360 bool is_strong, |
3341 int pos) { | 3361 int pos) { |
3342 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos); | 3362 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong, |
| 3363 pos); |
3343 } | 3364 } |
3344 | 3365 |
3345 VariableProxy* NewVariableProxy(Variable* var, | 3366 VariableProxy* NewVariableProxy(Variable* var, |
3346 int start_position = RelocInfo::kNoPosition, | 3367 int start_position = RelocInfo::kNoPosition, |
3347 int end_position = RelocInfo::kNoPosition) { | 3368 int end_position = RelocInfo::kNoPosition) { |
3348 return new (zone_) VariableProxy(zone_, var, start_position, end_position); | 3369 return new (zone_) VariableProxy(zone_, var, start_position, end_position); |
3349 } | 3370 } |
3350 | 3371 |
3351 VariableProxy* NewVariableProxy(const AstRawString* name, | 3372 VariableProxy* NewVariableProxy(const AstRawString* name, |
3352 Variable::Kind variable_kind, | 3373 Variable::Kind variable_kind, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3487 | 3508 |
3488 private: | 3509 private: |
3489 Zone* zone_; | 3510 Zone* zone_; |
3490 AstValueFactory* ast_value_factory_; | 3511 AstValueFactory* ast_value_factory_; |
3491 }; | 3512 }; |
3492 | 3513 |
3493 | 3514 |
3494 } } // namespace v8::internal | 3515 } } // namespace v8::internal |
3495 | 3516 |
3496 #endif // V8_AST_H_ | 3517 #endif // V8_AST_H_ |
OLD | NEW |