OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1402 }; | 1402 }; |
1403 | 1403 |
1404 | 1404 |
1405 // Base class for literals that needs space in the corresponding JSFunction. | 1405 // Base class for literals that needs space in the corresponding JSFunction. |
1406 class MaterializedLiteral : public Expression { | 1406 class MaterializedLiteral : public Expression { |
1407 public: | 1407 public: |
1408 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } | 1408 virtual MaterializedLiteral* AsMaterializedLiteral() { return this; } |
1409 | 1409 |
1410 int literal_index() { return literal_index_; } | 1410 int literal_index() { return literal_index_; } |
1411 | 1411 |
| 1412 int depth() const { |
| 1413 // only callable after initialization. |
| 1414 ASSERT(depth_ >= 1); |
| 1415 return depth_; |
| 1416 } |
| 1417 |
1412 protected: | 1418 protected: |
1413 MaterializedLiteral(Isolate* isolate, | 1419 MaterializedLiteral(Isolate* isolate, |
1414 int literal_index, | 1420 int literal_index, |
1415 int pos) | 1421 int pos) |
1416 : Expression(isolate, pos), | 1422 : Expression(isolate, pos), |
1417 literal_index_(literal_index), | 1423 literal_index_(literal_index), |
1418 is_simple_(false) {} | 1424 is_simple_(false), |
| 1425 depth_(0) {} |
1419 | 1426 |
1420 // A materialized literal is simple if the values consist of only | 1427 // A materialized literal is simple if the values consist of only |
1421 // constants and simple object and array literals. | 1428 // constants and simple object and array literals. |
1422 bool is_simple() const { return is_simple_; } | 1429 bool is_simple() const { return is_simple_; } |
1423 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } | 1430 void set_is_simple(bool is_simple) { is_simple_ = is_simple; } |
1424 friend class CompileTimeValue; | 1431 friend class CompileTimeValue; |
1425 | 1432 |
| 1433 void set_depth(int depth) { |
| 1434 ASSERT(depth >= 1); |
| 1435 depth_ = depth; |
| 1436 } |
| 1437 |
1426 // Populate the constant properties/elements fixed array. | 1438 // Populate the constant properties/elements fixed array. |
1427 void BuildConstants(Isolate* isolate, int* depth); | 1439 void BuildConstants(Isolate* isolate); |
1428 friend class ArrayLiteral; | 1440 friend class ArrayLiteral; |
1429 friend class ObjectLiteral; | 1441 friend class ObjectLiteral; |
1430 | 1442 |
1431 // If the expression is a literal, return the literal value; | 1443 // If the expression is a literal, return the literal value; |
1432 // if the expression is a materialized literal and is simple return a | 1444 // if the expression is a materialized literal and is simple return a |
1433 // compile time value as encoded by CompileTimeValue::GetValue(). | 1445 // compile time value as encoded by CompileTimeValue::GetValue(). |
1434 // Otherwise, return undefined literal as the placeholder | 1446 // Otherwise, return undefined literal as the placeholder |
1435 // in the object literal boilerplate. | 1447 // in the object literal boilerplate. |
1436 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); | 1448 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); |
1437 | 1449 |
1438 private: | 1450 private: |
1439 int literal_index_; | 1451 int literal_index_; |
1440 bool is_simple_; | 1452 bool is_simple_; |
| 1453 int depth_; |
1441 }; | 1454 }; |
1442 | 1455 |
1443 | 1456 |
1444 // Property is used for passing information | 1457 // Property is used for passing information |
1445 // about an object literal's properties from the parser | 1458 // about an object literal's properties from the parser |
1446 // to the code generator. | 1459 // to the code generator. |
1447 class ObjectLiteralProperty V8_FINAL : public ZoneObject { | 1460 class ObjectLiteralProperty V8_FINAL : public ZoneObject { |
1448 public: | 1461 public: |
1449 enum Kind { | 1462 enum Kind { |
1450 CONSTANT, // Property with constant value (compile time). | 1463 CONSTANT, // Property with constant value (compile time). |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1498 } | 1511 } |
1499 ZoneList<Property*>* properties() const { return properties_; } | 1512 ZoneList<Property*>* properties() const { return properties_; } |
1500 bool fast_elements() const { return fast_elements_; } | 1513 bool fast_elements() const { return fast_elements_; } |
1501 bool may_store_doubles() const { return may_store_doubles_; } | 1514 bool may_store_doubles() const { return may_store_doubles_; } |
1502 bool has_function() const { return has_function_; } | 1515 bool has_function() const { return has_function_; } |
1503 | 1516 |
1504 // Decide if a property should be in the object boilerplate. | 1517 // Decide if a property should be in the object boilerplate. |
1505 static bool IsBoilerplateProperty(Property* property); | 1518 static bool IsBoilerplateProperty(Property* property); |
1506 | 1519 |
1507 // Populate the constant properties fixed array. | 1520 // Populate the constant properties fixed array. |
1508 void BuildConstantProperties(Isolate* isolate, int* depth = NULL); | 1521 void BuildConstantProperties(Isolate* isolate); |
1509 | 1522 |
1510 // Mark all computed expressions that are bound to a key that | 1523 // Mark all computed expressions that are bound to a key that |
1511 // is shadowed by a later occurrence of the same key. For the | 1524 // is shadowed by a later occurrence of the same key. For the |
1512 // marked expressions, no store code is emitted. | 1525 // marked expressions, no store code is emitted. |
1513 void CalculateEmitStore(Zone* zone); | 1526 void CalculateEmitStore(Zone* zone); |
1514 | 1527 |
1515 enum Flags { | 1528 enum Flags { |
1516 kNoFlags = 0, | 1529 kNoFlags = 0, |
1517 kFastElements = 1, | 1530 kFastElements = 1, |
1518 kHasFunction = 1 << 1 | 1531 kHasFunction = 1 << 1 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 Handle<String> flags() const { return flags_; } | 1570 Handle<String> flags() const { return flags_; } |
1558 | 1571 |
1559 protected: | 1572 protected: |
1560 RegExpLiteral(Isolate* isolate, | 1573 RegExpLiteral(Isolate* isolate, |
1561 Handle<String> pattern, | 1574 Handle<String> pattern, |
1562 Handle<String> flags, | 1575 Handle<String> flags, |
1563 int literal_index, | 1576 int literal_index, |
1564 int pos) | 1577 int pos) |
1565 : MaterializedLiteral(isolate, literal_index, pos), | 1578 : MaterializedLiteral(isolate, literal_index, pos), |
1566 pattern_(pattern), | 1579 pattern_(pattern), |
1567 flags_(flags) {} | 1580 flags_(flags) { |
| 1581 set_depth(1); |
| 1582 } |
1568 | 1583 |
1569 private: | 1584 private: |
1570 Handle<String> pattern_; | 1585 Handle<String> pattern_; |
1571 Handle<String> flags_; | 1586 Handle<String> flags_; |
1572 }; | 1587 }; |
1573 | 1588 |
1574 | 1589 |
1575 // An array literal has a literals object that is used | 1590 // An array literal has a literals object that is used |
1576 // for minimizing the work when constructing it at runtime. | 1591 // for minimizing the work when constructing it at runtime. |
1577 class ArrayLiteral V8_FINAL : public MaterializedLiteral { | 1592 class ArrayLiteral V8_FINAL : public MaterializedLiteral { |
1578 public: | 1593 public: |
1579 DECLARE_NODE_TYPE(ArrayLiteral) | 1594 DECLARE_NODE_TYPE(ArrayLiteral) |
1580 | 1595 |
1581 Handle<FixedArray> constant_elements() const { return constant_elements_; } | 1596 Handle<FixedArray> constant_elements() const { return constant_elements_; } |
1582 ZoneList<Expression*>* values() const { return values_; } | 1597 ZoneList<Expression*>* values() const { return values_; } |
1583 | 1598 |
1584 // Return an AST id for an element that is used in simulate instructions. | 1599 // Return an AST id for an element that is used in simulate instructions. |
1585 BailoutId GetIdForElement(int i) { | 1600 BailoutId GetIdForElement(int i) { |
1586 return BailoutId(first_element_id_.ToInt() + i); | 1601 return BailoutId(first_element_id_.ToInt() + i); |
1587 } | 1602 } |
1588 | 1603 |
1589 // Populate the constant elements fixed array. | 1604 // Populate the constant elements fixed array. |
1590 void BuildConstantElements(Isolate* isolate, int* depth = NULL); | 1605 void BuildConstantElements(Isolate* isolate); |
1591 | 1606 |
1592 protected: | 1607 protected: |
1593 ArrayLiteral(Isolate* isolate, | 1608 ArrayLiteral(Isolate* isolate, |
1594 ZoneList<Expression*>* values, | 1609 ZoneList<Expression*>* values, |
1595 int literal_index, | 1610 int literal_index, |
1596 int pos) | 1611 int pos) |
1597 : MaterializedLiteral(isolate, literal_index, pos), | 1612 : MaterializedLiteral(isolate, literal_index, pos), |
1598 values_(values), | 1613 values_(values), |
1599 first_element_id_(ReserveIdRange(isolate, values->length())) {} | 1614 first_element_id_(ReserveIdRange(isolate, values->length())) {} |
1600 | 1615 |
(...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3270 private: | 3285 private: |
3271 Isolate* isolate_; | 3286 Isolate* isolate_; |
3272 Zone* zone_; | 3287 Zone* zone_; |
3273 Visitor visitor_; | 3288 Visitor visitor_; |
3274 }; | 3289 }; |
3275 | 3290 |
3276 | 3291 |
3277 } } // namespace v8::internal | 3292 } } // namespace v8::internal |
3278 | 3293 |
3279 #endif // V8_AST_H_ | 3294 #endif // V8_AST_H_ |
OLD | NEW |