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 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3298 | 3313 |
3299 Literal* NewTheHoleLiteral(int pos) { | 3314 Literal* NewTheHoleLiteral(int pos) { |
3300 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); | 3315 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); |
3301 } | 3316 } |
3302 | 3317 |
3303 ObjectLiteral* NewObjectLiteral( | 3318 ObjectLiteral* NewObjectLiteral( |
3304 ZoneList<ObjectLiteral::Property*>* properties, | 3319 ZoneList<ObjectLiteral::Property*>* properties, |
3305 int literal_index, | 3320 int literal_index, |
3306 int boilerplate_properties, | 3321 int boilerplate_properties, |
3307 bool has_function, | 3322 bool has_function, |
| 3323 bool is_strong, |
3308 int pos) { | 3324 int pos) { |
3309 return new (zone_) ObjectLiteral(zone_, properties, literal_index, | 3325 return new (zone_) ObjectLiteral(zone_, properties, literal_index, |
3310 boilerplate_properties, has_function, pos); | 3326 boilerplate_properties, has_function, |
| 3327 is_strong, pos); |
3311 } | 3328 } |
3312 | 3329 |
3313 ObjectLiteral::Property* NewObjectLiteralProperty( | 3330 ObjectLiteral::Property* NewObjectLiteralProperty( |
3314 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3331 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
3315 bool is_static, bool is_computed_name) { | 3332 bool is_static, bool is_computed_name) { |
3316 return new (zone_) | 3333 return new (zone_) |
3317 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3334 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); |
3318 } | 3335 } |
3319 | 3336 |
3320 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3337 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
3321 Expression* value, | 3338 Expression* value, |
3322 bool is_static, | 3339 bool is_static, |
3323 bool is_computed_name) { | 3340 bool is_computed_name) { |
3324 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, | 3341 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, |
3325 is_static, is_computed_name); | 3342 is_static, is_computed_name); |
3326 } | 3343 } |
3327 | 3344 |
3328 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, | 3345 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, |
3329 const AstRawString* flags, | 3346 const AstRawString* flags, |
3330 int literal_index, | 3347 int literal_index, |
| 3348 bool is_strong, |
3331 int pos) { | 3349 int pos) { |
3332 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos); | 3350 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, |
| 3351 is_strong, pos); |
3333 } | 3352 } |
3334 | 3353 |
3335 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3354 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3336 int literal_index, | 3355 int literal_index, |
| 3356 bool is_strong, |
3337 int pos) { | 3357 int pos) { |
3338 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos); | 3358 return new (zone_) ArrayLiteral(zone_, values, literal_index, is_strong, |
| 3359 pos); |
3339 } | 3360 } |
3340 | 3361 |
3341 VariableProxy* NewVariableProxy(Variable* var, | 3362 VariableProxy* NewVariableProxy(Variable* var, |
3342 int start_position = RelocInfo::kNoPosition, | 3363 int start_position = RelocInfo::kNoPosition, |
3343 int end_position = RelocInfo::kNoPosition) { | 3364 int end_position = RelocInfo::kNoPosition) { |
3344 return new (zone_) VariableProxy(zone_, var, start_position, end_position); | 3365 return new (zone_) VariableProxy(zone_, var, start_position, end_position); |
3345 } | 3366 } |
3346 | 3367 |
3347 VariableProxy* NewVariableProxy(const AstRawString* name, | 3368 VariableProxy* NewVariableProxy(const AstRawString* name, |
3348 Variable::Kind variable_kind, | 3369 Variable::Kind variable_kind, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3484 | 3505 |
3485 private: | 3506 private: |
3486 Zone* zone_; | 3507 Zone* zone_; |
3487 AstValueFactory* ast_value_factory_; | 3508 AstValueFactory* ast_value_factory_; |
3488 }; | 3509 }; |
3489 | 3510 |
3490 | 3511 |
3491 } } // namespace v8::internal | 3512 } } // namespace v8::internal |
3492 | 3513 |
3493 #endif // V8_AST_H_ | 3514 #endif // V8_AST_H_ |
OLD | NEW |