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_AST_H_ | 5 #ifndef V8_AST_AST_H_ |
6 #define V8_AST_AST_H_ | 6 #define V8_AST_AST_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/ast/ast-value-factory.h" | 9 #include "src/ast/ast-value-factory.h" |
10 #include "src/ast/modules.h" | 10 #include "src/ast/modules.h" |
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 MaterializedLiteral* AsMaterializedLiteral() final { return this; } | 1330 MaterializedLiteral* AsMaterializedLiteral() final { return this; } |
1331 | 1331 |
1332 int literal_index() { return literal_index_; } | 1332 int literal_index() { return literal_index_; } |
1333 | 1333 |
1334 int depth() const { | 1334 int depth() const { |
1335 // only callable after initialization. | 1335 // only callable after initialization. |
1336 DCHECK(depth_ >= 1); | 1336 DCHECK(depth_ >= 1); |
1337 return depth_; | 1337 return depth_; |
1338 } | 1338 } |
1339 | 1339 |
1340 bool is_strong() const { return is_strong_; } | |
1341 | |
1342 protected: | 1340 protected: |
1343 MaterializedLiteral(Zone* zone, int literal_index, bool is_strong, int pos) | 1341 MaterializedLiteral(Zone* zone, int literal_index, int pos) |
1344 : Expression(zone, pos), | 1342 : Expression(zone, pos), |
1345 literal_index_(literal_index), | 1343 literal_index_(literal_index), |
1346 is_simple_(false), | 1344 is_simple_(false), |
1347 is_strong_(is_strong), | |
1348 depth_(0) {} | 1345 depth_(0) {} |
1349 | 1346 |
1350 // A materialized literal is simple if the values consist of only | 1347 // A materialized literal is simple if the values consist of only |
1351 // constants and simple object and array literals. | 1348 // constants and simple object and array literals. |
1352 bool is_simple() const { return is_simple_; } | 1349 bool is_simple() const { return is_simple_; } |
1353 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } | 1350 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } |
1354 friend class CompileTimeValue; | 1351 friend class CompileTimeValue; |
1355 | 1352 |
1356 void set_depth(int depth) { | 1353 void set_depth(int depth) { |
1357 DCHECK(depth >= 1); | 1354 DCHECK(depth >= 1); |
1358 depth_ = depth; | 1355 depth_ = depth; |
1359 } | 1356 } |
1360 | 1357 |
1361 // Populate the constant properties/elements fixed array. | 1358 // Populate the constant properties/elements fixed array. |
1362 void BuildConstants(Isolate* isolate); | 1359 void BuildConstants(Isolate* isolate); |
1363 friend class ArrayLiteral; | 1360 friend class ArrayLiteral; |
1364 friend class ObjectLiteral; | 1361 friend class ObjectLiteral; |
1365 | 1362 |
1366 // If the expression is a literal, return the literal value; | 1363 // If the expression is a literal, return the literal value; |
1367 // if the expression is a materialized literal and is simple return a | 1364 // if the expression is a materialized literal and is simple return a |
1368 // compile time value as encoded by CompileTimeValue::GetValue(). | 1365 // compile time value as encoded by CompileTimeValue::GetValue(). |
1369 // Otherwise, return undefined literal as the placeholder | 1366 // Otherwise, return undefined literal as the placeholder |
1370 // in the object literal boilerplate. | 1367 // in the object literal boilerplate. |
1371 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); | 1368 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); |
1372 | 1369 |
1373 private: | 1370 private: |
1374 int literal_index_; | 1371 int literal_index_; |
1375 bool is_simple_; | 1372 bool is_simple_; |
1376 bool is_strong_; | |
1377 int depth_; | 1373 int depth_; |
1378 | 1374 |
1379 friend class AstLiteralReindexer; | 1375 friend class AstLiteralReindexer; |
1380 }; | 1376 }; |
1381 | 1377 |
1382 | 1378 |
1383 // Property is used for passing information | 1379 // Property is used for passing information |
1384 // about an object literal's properties from the parser | 1380 // about an object literal's properties from the parser |
1385 // to the code generator. | 1381 // to the code generator. |
1386 class ObjectLiteralProperty final : public ZoneObject { | 1382 class ObjectLiteralProperty final : public ZoneObject { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 // Assemble bitfield of flags for the CreateObjectLiteral helper. | 1477 // Assemble bitfield of flags for the CreateObjectLiteral helper. |
1482 int ComputeFlags(bool disable_mementos = false) const { | 1478 int ComputeFlags(bool disable_mementos = false) const { |
1483 int flags = fast_elements() ? kFastElements : kNoFlags; | 1479 int flags = fast_elements() ? kFastElements : kNoFlags; |
1484 flags |= has_function() ? kHasFunction : kNoFlags; | 1480 flags |= has_function() ? kHasFunction : kNoFlags; |
1485 if (has_shallow_properties()) { | 1481 if (has_shallow_properties()) { |
1486 flags |= kShallowProperties; | 1482 flags |= kShallowProperties; |
1487 } | 1483 } |
1488 if (disable_mementos) { | 1484 if (disable_mementos) { |
1489 flags |= kDisableMementos; | 1485 flags |= kDisableMementos; |
1490 } | 1486 } |
1491 if (is_strong()) { | |
1492 flags |= kIsStrong; | |
1493 } | |
1494 return flags; | 1487 return flags; |
1495 } | 1488 } |
1496 | 1489 |
1497 enum Flags { | 1490 enum Flags { |
1498 kNoFlags = 0, | 1491 kNoFlags = 0, |
1499 kFastElements = 1, | 1492 kFastElements = 1, |
1500 kHasFunction = 1 << 1, | 1493 kHasFunction = 1 << 1, |
1501 kShallowProperties = 1 << 2, | 1494 kShallowProperties = 1 << 2, |
1502 kDisableMementos = 1 << 3, | 1495 kDisableMementos = 1 << 3 |
1503 kIsStrong = 1 << 4 | |
1504 }; | 1496 }; |
1505 | 1497 |
1506 struct Accessors: public ZoneObject { | 1498 struct Accessors: public ZoneObject { |
1507 Accessors() : getter(NULL), setter(NULL) {} | 1499 Accessors() : getter(NULL), setter(NULL) {} |
1508 ObjectLiteralProperty* getter; | 1500 ObjectLiteralProperty* getter; |
1509 ObjectLiteralProperty* setter; | 1501 ObjectLiteralProperty* setter; |
1510 }; | 1502 }; |
1511 | 1503 |
1512 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } | 1504 BailoutId CreateLiteralId() const { return BailoutId(local_id(0)); } |
1513 | 1505 |
(...skipping 11 matching lines...) Expand all Loading... |
1525 return parent_num_ids() + 1 + 2 * properties()->length(); | 1517 return parent_num_ids() + 1 + 2 * properties()->length(); |
1526 } | 1518 } |
1527 | 1519 |
1528 // Object literals need one feedback slot for each non-trivial value, as well | 1520 // Object literals need one feedback slot for each non-trivial value, as well |
1529 // as some slots for home objects. | 1521 // as some slots for home objects. |
1530 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 1522 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
1531 FeedbackVectorSlotCache* cache) override; | 1523 FeedbackVectorSlotCache* cache) override; |
1532 | 1524 |
1533 protected: | 1525 protected: |
1534 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, | 1526 ObjectLiteral(Zone* zone, ZoneList<Property*>* properties, int literal_index, |
1535 int boilerplate_properties, bool has_function, bool is_strong, | 1527 int boilerplate_properties, bool has_function, int pos) |
1536 int pos) | 1528 : MaterializedLiteral(zone, literal_index, pos), |
1537 : MaterializedLiteral(zone, literal_index, is_strong, pos), | |
1538 properties_(properties), | 1529 properties_(properties), |
1539 boilerplate_properties_(boilerplate_properties), | 1530 boilerplate_properties_(boilerplate_properties), |
1540 fast_elements_(false), | 1531 fast_elements_(false), |
1541 has_elements_(false), | 1532 has_elements_(false), |
1542 may_store_doubles_(false), | 1533 may_store_doubles_(false), |
1543 has_function_(has_function) {} | 1534 has_function_(has_function) {} |
1544 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1535 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
1545 | 1536 |
1546 private: | 1537 private: |
1547 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1538 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 // Node for capturing a regexp literal. | 1571 // Node for capturing a regexp literal. |
1581 class RegExpLiteral final : public MaterializedLiteral { | 1572 class RegExpLiteral final : public MaterializedLiteral { |
1582 public: | 1573 public: |
1583 DECLARE_NODE_TYPE(RegExpLiteral) | 1574 DECLARE_NODE_TYPE(RegExpLiteral) |
1584 | 1575 |
1585 Handle<String> pattern() const { return pattern_->string(); } | 1576 Handle<String> pattern() const { return pattern_->string(); } |
1586 int flags() const { return flags_; } | 1577 int flags() const { return flags_; } |
1587 | 1578 |
1588 protected: | 1579 protected: |
1589 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags, | 1580 RegExpLiteral(Zone* zone, const AstRawString* pattern, int flags, |
1590 int literal_index, bool is_strong, int pos) | 1581 int literal_index, int pos) |
1591 : MaterializedLiteral(zone, literal_index, is_strong, pos), | 1582 : MaterializedLiteral(zone, literal_index, pos), |
1592 pattern_(pattern), | 1583 pattern_(pattern), |
1593 flags_(flags) { | 1584 flags_(flags) { |
1594 set_depth(1); | 1585 set_depth(1); |
1595 } | 1586 } |
1596 | 1587 |
1597 private: | 1588 private: |
1598 const AstRawString* const pattern_; | 1589 const AstRawString* const pattern_; |
1599 int const flags_; | 1590 int const flags_; |
1600 }; | 1591 }; |
1601 | 1592 |
(...skipping 24 matching lines...) Expand all Loading... |
1626 | 1617 |
1627 // Populate the constant elements fixed array. | 1618 // Populate the constant elements fixed array. |
1628 void BuildConstantElements(Isolate* isolate); | 1619 void BuildConstantElements(Isolate* isolate); |
1629 | 1620 |
1630 // Assemble bitfield of flags for the CreateArrayLiteral helper. | 1621 // Assemble bitfield of flags for the CreateArrayLiteral helper. |
1631 int ComputeFlags(bool disable_mementos = false) const { | 1622 int ComputeFlags(bool disable_mementos = false) const { |
1632 int flags = depth() == 1 ? kShallowElements : kNoFlags; | 1623 int flags = depth() == 1 ? kShallowElements : kNoFlags; |
1633 if (disable_mementos) { | 1624 if (disable_mementos) { |
1634 flags |= kDisableMementos; | 1625 flags |= kDisableMementos; |
1635 } | 1626 } |
1636 if (is_strong()) { | |
1637 flags |= kIsStrong; | |
1638 } | |
1639 return flags; | 1627 return flags; |
1640 } | 1628 } |
1641 | 1629 |
1642 // Provide a mechanism for iterating through values to rewrite spreads. | 1630 // Provide a mechanism for iterating through values to rewrite spreads. |
1643 ZoneList<Expression*>::iterator FirstSpread() const { | 1631 ZoneList<Expression*>::iterator FirstSpread() const { |
1644 return (first_spread_index_ >= 0) ? values_->begin() + first_spread_index_ | 1632 return (first_spread_index_ >= 0) ? values_->begin() + first_spread_index_ |
1645 : values_->end(); | 1633 : values_->end(); |
1646 } | 1634 } |
1647 ZoneList<Expression*>::iterator EndValue() const { return values_->end(); } | 1635 ZoneList<Expression*>::iterator EndValue() const { return values_->end(); } |
1648 | 1636 |
1649 // Rewind an array literal omitting everything from the first spread on. | 1637 // Rewind an array literal omitting everything from the first spread on. |
1650 void RewindSpreads() { | 1638 void RewindSpreads() { |
1651 values_->Rewind(first_spread_index_); | 1639 values_->Rewind(first_spread_index_); |
1652 first_spread_index_ = -1; | 1640 first_spread_index_ = -1; |
1653 } | 1641 } |
1654 | 1642 |
1655 enum Flags { | 1643 enum Flags { |
1656 kNoFlags = 0, | 1644 kNoFlags = 0, |
1657 kShallowElements = 1, | 1645 kShallowElements = 1, |
1658 kDisableMementos = 1 << 1, | 1646 kDisableMementos = 1 << 1 |
1659 kIsStrong = 1 << 2 | |
1660 }; | 1647 }; |
1661 | 1648 |
1662 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, | 1649 void AssignFeedbackVectorSlots(Isolate* isolate, FeedbackVectorSpec* spec, |
1663 FeedbackVectorSlotCache* cache) override; | 1650 FeedbackVectorSlotCache* cache) override; |
1664 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } | 1651 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } |
1665 | 1652 |
1666 protected: | 1653 protected: |
1667 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, | 1654 ArrayLiteral(Zone* zone, ZoneList<Expression*>* values, |
1668 int first_spread_index, int literal_index, bool is_strong, | 1655 int first_spread_index, int literal_index, int pos) |
1669 int pos) | 1656 : MaterializedLiteral(zone, literal_index, pos), |
1670 : MaterializedLiteral(zone, literal_index, is_strong, pos), | |
1671 values_(values), | 1657 values_(values), |
1672 first_spread_index_(first_spread_index) {} | 1658 first_spread_index_(first_spread_index) {} |
1673 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1659 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
1674 | 1660 |
1675 private: | 1661 private: |
1676 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1662 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
1677 | 1663 |
1678 Handle<FixedArray> constant_elements_; | 1664 Handle<FixedArray> constant_elements_; |
1679 ZoneList<Expression*>* values_; | 1665 ZoneList<Expression*>* values_; |
1680 int first_spread_index_; | 1666 int first_spread_index_; |
(...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3235 Literal* NewTheHoleLiteral(int pos) { | 3221 Literal* NewTheHoleLiteral(int pos) { |
3236 return new (local_zone_) | 3222 return new (local_zone_) |
3237 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos); | 3223 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos); |
3238 } | 3224 } |
3239 | 3225 |
3240 ObjectLiteral* NewObjectLiteral( | 3226 ObjectLiteral* NewObjectLiteral( |
3241 ZoneList<ObjectLiteral::Property*>* properties, | 3227 ZoneList<ObjectLiteral::Property*>* properties, |
3242 int literal_index, | 3228 int literal_index, |
3243 int boilerplate_properties, | 3229 int boilerplate_properties, |
3244 bool has_function, | 3230 bool has_function, |
3245 bool is_strong, | |
3246 int pos) { | 3231 int pos) { |
3247 return new (local_zone_) | 3232 return new (local_zone_) |
3248 ObjectLiteral(local_zone_, properties, literal_index, | 3233 ObjectLiteral(local_zone_, properties, literal_index, |
3249 boilerplate_properties, has_function, is_strong, pos); | 3234 boilerplate_properties, has_function, pos); |
3250 } | 3235 } |
3251 | 3236 |
3252 ObjectLiteral::Property* NewObjectLiteralProperty( | 3237 ObjectLiteral::Property* NewObjectLiteralProperty( |
3253 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3238 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
3254 bool is_static, bool is_computed_name) { | 3239 bool is_static, bool is_computed_name) { |
3255 return new (local_zone_) | 3240 return new (local_zone_) |
3256 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3241 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); |
3257 } | 3242 } |
3258 | 3243 |
3259 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3244 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
3260 Expression* value, | 3245 Expression* value, |
3261 bool is_static, | 3246 bool is_static, |
3262 bool is_computed_name) { | 3247 bool is_computed_name) { |
3263 return new (local_zone_) ObjectLiteral::Property( | 3248 return new (local_zone_) ObjectLiteral::Property( |
3264 ast_value_factory_, key, value, is_static, is_computed_name); | 3249 ast_value_factory_, key, value, is_static, is_computed_name); |
3265 } | 3250 } |
3266 | 3251 |
3267 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, | 3252 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, |
3268 int literal_index, bool is_strong, int pos) { | 3253 int literal_index, int pos) { |
3269 return new (local_zone_) RegExpLiteral(local_zone_, pattern, flags, | 3254 return new (local_zone_) |
3270 literal_index, is_strong, pos); | 3255 RegExpLiteral(local_zone_, pattern, flags, literal_index, pos); |
3271 } | 3256 } |
3272 | 3257 |
3273 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3258 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3274 int literal_index, | 3259 int literal_index, |
3275 bool is_strong, | |
3276 int pos) { | 3260 int pos) { |
3277 return new (local_zone_) | 3261 return new (local_zone_) |
3278 ArrayLiteral(local_zone_, values, -1, literal_index, is_strong, pos); | 3262 ArrayLiteral(local_zone_, values, -1, literal_index, pos); |
3279 } | 3263 } |
3280 | 3264 |
3281 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3265 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3282 int first_spread_index, int literal_index, | 3266 int first_spread_index, int literal_index, |
3283 bool is_strong, int pos) { | 3267 int pos) { |
3284 return new (local_zone_) ArrayLiteral( | 3268 return new (local_zone_) ArrayLiteral( |
3285 local_zone_, values, first_spread_index, literal_index, is_strong, pos); | 3269 local_zone_, values, first_spread_index, literal_index, pos); |
3286 } | 3270 } |
3287 | 3271 |
3288 VariableProxy* NewVariableProxy(Variable* var, | 3272 VariableProxy* NewVariableProxy(Variable* var, |
3289 int start_position = RelocInfo::kNoPosition, | 3273 int start_position = RelocInfo::kNoPosition, |
3290 int end_position = RelocInfo::kNoPosition) { | 3274 int end_position = RelocInfo::kNoPosition) { |
3291 return new (parser_zone_) | 3275 return new (parser_zone_) |
3292 VariableProxy(parser_zone_, var, start_position, end_position); | 3276 VariableProxy(parser_zone_, var, start_position, end_position); |
3293 } | 3277 } |
3294 | 3278 |
3295 VariableProxy* NewVariableProxy(const AstRawString* name, | 3279 VariableProxy* NewVariableProxy(const AstRawString* name, |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 : NULL; \ | 3536 : NULL; \ |
3553 } | 3537 } |
3554 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3538 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
3555 #undef DECLARE_NODE_FUNCTIONS | 3539 #undef DECLARE_NODE_FUNCTIONS |
3556 | 3540 |
3557 | 3541 |
3558 } // namespace internal | 3542 } // namespace internal |
3559 } // namespace v8 | 3543 } // namespace v8 |
3560 | 3544 |
3561 #endif // V8_AST_AST_H_ | 3545 #endif // V8_AST_AST_H_ |
OLD | NEW |