| 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/ast/ast-types.h" | 8 #include "src/ast/ast-types.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 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1233 | 1233 |
| 1234 Literal(const AstValue* value, int position) | 1234 Literal(const AstValue* value, int position) |
| 1235 : Expression(position, kLiteral), value_(value) {} | 1235 : Expression(position, kLiteral), value_(value) {} |
| 1236 | 1236 |
| 1237 static int parent_num_ids() { return Expression::num_ids(); } | 1237 static int parent_num_ids() { return Expression::num_ids(); } |
| 1238 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1238 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1239 | 1239 |
| 1240 const AstValue* value_; | 1240 const AstValue* value_; |
| 1241 }; | 1241 }; |
| 1242 | 1242 |
| 1243 | 1243 // Base class for literals that need space in the type feedback vector. |
| 1244 class AstLiteralReindexer; | |
| 1245 | |
| 1246 // Base class for literals that needs space in the corresponding JSFunction. | |
| 1247 class MaterializedLiteral : public Expression { | 1244 class MaterializedLiteral : public Expression { |
| 1248 public: | 1245 public: |
| 1249 int literal_index() { return literal_index_; } | |
| 1250 | |
| 1251 int depth() const { | 1246 int depth() const { |
| 1252 // only callable after initialization. | 1247 // only callable after initialization. |
| 1253 DCHECK(depth_ >= 1); | 1248 DCHECK(depth_ >= 1); |
| 1254 return depth_; | 1249 return depth_; |
| 1255 } | 1250 } |
| 1256 | 1251 |
| 1252 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, |
| 1253 FeedbackVectorSlotCache* cache) { |
| 1254 literal_slot_ = spec->AddLiteralSlot(); |
| 1255 } |
| 1256 |
| 1257 FeedbackVectorSlot literal_slot() const { return literal_slot_; } |
| 1258 |
| 1257 private: | 1259 private: |
| 1258 int depth_ : 31; | 1260 int depth_ : 31; |
| 1259 int literal_index_; | 1261 FeedbackVectorSlot literal_slot_; |
| 1260 | |
| 1261 friend class AstLiteralReindexer; | |
| 1262 | 1262 |
| 1263 class IsSimpleField | 1263 class IsSimpleField |
| 1264 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {}; | 1264 : public BitField<bool, Expression::kNextBitFieldIndex, 1> {}; |
| 1265 | 1265 |
| 1266 protected: | 1266 protected: |
| 1267 MaterializedLiteral(int literal_index, int pos, NodeType type) | 1267 MaterializedLiteral(int pos, NodeType type) |
| 1268 : Expression(pos, type), depth_(0), literal_index_(literal_index) { | 1268 : Expression(pos, type), depth_(0) { |
| 1269 bit_field_ |= IsSimpleField::encode(false); | 1269 bit_field_ |= IsSimpleField::encode(false); |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 // A materialized literal is simple if the values consist of only | 1272 // A materialized literal is simple if the values consist of only |
| 1273 // constants and simple object and array literals. | 1273 // constants and simple object and array literals. |
| 1274 bool is_simple() const { return IsSimpleField::decode(bit_field_); } | 1274 bool is_simple() const { return IsSimpleField::decode(bit_field_); } |
| 1275 void set_is_simple(bool is_simple) { | 1275 void set_is_simple(bool is_simple) { |
| 1276 bit_field_ = IsSimpleField::update(bit_field_, is_simple); | 1276 bit_field_ = IsSimpleField::update(bit_field_, is_simple); |
| 1277 } | 1277 } |
| 1278 friend class CompileTimeValue; | 1278 friend class CompileTimeValue; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } | 1465 int num_ids() const { return parent_num_ids() + 1 + properties()->length(); } |
| 1466 | 1466 |
| 1467 // Object literals need one feedback slot for each non-trivial value, as well | 1467 // Object literals need one feedback slot for each non-trivial value, as well |
| 1468 // as some slots for home objects. | 1468 // as some slots for home objects. |
| 1469 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, | 1469 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, |
| 1470 FeedbackVectorSlotCache* cache); | 1470 FeedbackVectorSlotCache* cache); |
| 1471 | 1471 |
| 1472 private: | 1472 private: |
| 1473 friend class AstNodeFactory; | 1473 friend class AstNodeFactory; |
| 1474 | 1474 |
| 1475 ObjectLiteral(ZoneList<Property*>* properties, int literal_index, | 1475 ObjectLiteral(ZoneList<Property*>* properties, |
| 1476 uint32_t boilerplate_properties, int pos, | 1476 uint32_t boilerplate_properties, int pos, |
| 1477 bool has_rest_property) | 1477 bool has_rest_property) |
| 1478 : MaterializedLiteral(literal_index, pos, kObjectLiteral), | 1478 : MaterializedLiteral(pos, kObjectLiteral), |
| 1479 boilerplate_properties_(boilerplate_properties), | 1479 boilerplate_properties_(boilerplate_properties), |
| 1480 properties_(properties) { | 1480 properties_(properties) { |
| 1481 bit_field_ |= FastElementsField::encode(false) | | 1481 bit_field_ |= FastElementsField::encode(false) | |
| 1482 HasElementsField::encode(false) | | 1482 HasElementsField::encode(false) | |
| 1483 MayStoreDoublesField::encode(false) | | 1483 MayStoreDoublesField::encode(false) | |
| 1484 HasRestPropertyField::encode(has_rest_property); | 1484 HasRestPropertyField::encode(has_rest_property); |
| 1485 } | 1485 } |
| 1486 | 1486 |
| 1487 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1487 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
| 1488 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1488 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 | 1527 |
| 1528 // Node for capturing a regexp literal. | 1528 // Node for capturing a regexp literal. |
| 1529 class RegExpLiteral final : public MaterializedLiteral { | 1529 class RegExpLiteral final : public MaterializedLiteral { |
| 1530 public: | 1530 public: |
| 1531 Handle<String> pattern() const { return pattern_->string(); } | 1531 Handle<String> pattern() const { return pattern_->string(); } |
| 1532 int flags() const { return flags_; } | 1532 int flags() const { return flags_; } |
| 1533 | 1533 |
| 1534 private: | 1534 private: |
| 1535 friend class AstNodeFactory; | 1535 friend class AstNodeFactory; |
| 1536 | 1536 |
| 1537 RegExpLiteral(const AstRawString* pattern, int flags, int literal_index, | 1537 RegExpLiteral(const AstRawString* pattern, int flags, int pos) |
| 1538 int pos) | 1538 : MaterializedLiteral(pos, kRegExpLiteral), |
| 1539 : MaterializedLiteral(literal_index, pos, kRegExpLiteral), | |
| 1540 flags_(flags), | 1539 flags_(flags), |
| 1541 pattern_(pattern) { | 1540 pattern_(pattern) { |
| 1542 set_depth(1); | 1541 set_depth(1); |
| 1543 } | 1542 } |
| 1544 | 1543 |
| 1545 int const flags_; | 1544 int const flags_; |
| 1546 const AstRawString* const pattern_; | 1545 const AstRawString* const pattern_; |
| 1547 }; | 1546 }; |
| 1548 | 1547 |
| 1549 | 1548 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1612 kDisableMementos = 1 << 1 | 1611 kDisableMementos = 1 << 1 |
| 1613 }; | 1612 }; |
| 1614 | 1613 |
| 1615 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, | 1614 void AssignFeedbackVectorSlots(FeedbackVectorSpec* spec, |
| 1616 FeedbackVectorSlotCache* cache); | 1615 FeedbackVectorSlotCache* cache); |
| 1617 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } | 1616 FeedbackVectorSlot LiteralFeedbackSlot() const { return literal_slot_; } |
| 1618 | 1617 |
| 1619 private: | 1618 private: |
| 1620 friend class AstNodeFactory; | 1619 friend class AstNodeFactory; |
| 1621 | 1620 |
| 1622 ArrayLiteral(ZoneList<Expression*>* values, int first_spread_index, | 1621 ArrayLiteral(ZoneList<Expression*>* values, int first_spread_index, int pos) |
| 1623 int literal_index, int pos) | 1622 : MaterializedLiteral(pos, kArrayLiteral), |
| 1624 : MaterializedLiteral(literal_index, pos, kArrayLiteral), | |
| 1625 first_spread_index_(first_spread_index), | 1623 first_spread_index_(first_spread_index), |
| 1626 values_(values) {} | 1624 values_(values) {} |
| 1627 | 1625 |
| 1628 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } | 1626 static int parent_num_ids() { return MaterializedLiteral::num_ids(); } |
| 1629 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1627 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1630 | 1628 |
| 1631 int first_spread_index_; | 1629 int first_spread_index_; |
| 1632 FeedbackVectorSlot literal_slot_; | 1630 FeedbackVectorSlot literal_slot_; |
| 1633 Handle<ConstantElementsPair> constant_elements_; | 1631 Handle<ConstantElementsPair> constant_elements_; |
| 1634 ZoneList<Expression*>* values_; | 1632 ZoneList<Expression*>* values_; |
| (...skipping 1691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3326 | 3324 |
| 3327 Literal* NewUndefinedLiteral(int pos) { | 3325 Literal* NewUndefinedLiteral(int pos) { |
| 3328 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos); | 3326 return new (zone_) Literal(ast_value_factory_->NewUndefined(), pos); |
| 3329 } | 3327 } |
| 3330 | 3328 |
| 3331 Literal* NewTheHoleLiteral(int pos) { | 3329 Literal* NewTheHoleLiteral(int pos) { |
| 3332 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos); | 3330 return new (zone_) Literal(ast_value_factory_->NewTheHole(), pos); |
| 3333 } | 3331 } |
| 3334 | 3332 |
| 3335 ObjectLiteral* NewObjectLiteral( | 3333 ObjectLiteral* NewObjectLiteral( |
| 3336 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, | 3334 ZoneList<ObjectLiteral::Property*>* properties, |
| 3337 uint32_t boilerplate_properties, int pos, bool has_rest_property) { | 3335 uint32_t boilerplate_properties, int pos, bool has_rest_property) { |
| 3338 return new (zone_) | 3336 return new (zone_) ObjectLiteral(properties, boilerplate_properties, pos, |
| 3339 ObjectLiteral(properties, literal_index, boilerplate_properties, pos, | 3337 has_rest_property); |
| 3340 has_rest_property); | |
| 3341 } | 3338 } |
| 3342 | 3339 |
| 3343 ObjectLiteral::Property* NewObjectLiteralProperty( | 3340 ObjectLiteral::Property* NewObjectLiteralProperty( |
| 3344 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3341 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
| 3345 bool is_computed_name) { | 3342 bool is_computed_name) { |
| 3346 return new (zone_) | 3343 return new (zone_) |
| 3347 ObjectLiteral::Property(key, value, kind, is_computed_name); | 3344 ObjectLiteral::Property(key, value, kind, is_computed_name); |
| 3348 } | 3345 } |
| 3349 | 3346 |
| 3350 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3347 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
| 3351 Expression* value, | 3348 Expression* value, |
| 3352 bool is_computed_name) { | 3349 bool is_computed_name) { |
| 3353 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, | 3350 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, |
| 3354 is_computed_name); | 3351 is_computed_name); |
| 3355 } | 3352 } |
| 3356 | 3353 |
| 3357 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, | 3354 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, |
| 3358 int literal_index, int pos) { | 3355 int pos) { |
| 3359 return new (zone_) RegExpLiteral(pattern, flags, literal_index, pos); | 3356 return new (zone_) RegExpLiteral(pattern, flags, pos); |
| 3360 } | 3357 } |
| 3361 | 3358 |
| 3362 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3359 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
| 3363 int literal_index, | |
| 3364 int pos) { | 3360 int pos) { |
| 3365 return new (zone_) ArrayLiteral(values, -1, literal_index, pos); | 3361 return new (zone_) ArrayLiteral(values, -1, pos); |
| 3366 } | 3362 } |
| 3367 | 3363 |
| 3368 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3364 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
| 3369 int first_spread_index, int literal_index, | 3365 int first_spread_index, int pos) { |
| 3370 int pos) { | 3366 return new (zone_) ArrayLiteral(values, first_spread_index, pos); |
| 3371 return new (zone_) | |
| 3372 ArrayLiteral(values, first_spread_index, literal_index, pos); | |
| 3373 } | 3367 } |
| 3374 | 3368 |
| 3375 VariableProxy* NewVariableProxy(Variable* var, | 3369 VariableProxy* NewVariableProxy(Variable* var, |
| 3376 int start_position = kNoSourcePosition) { | 3370 int start_position = kNoSourcePosition) { |
| 3377 return new (zone_) VariableProxy(var, start_position); | 3371 return new (zone_) VariableProxy(var, start_position); |
| 3378 } | 3372 } |
| 3379 | 3373 |
| 3380 VariableProxy* NewVariableProxy(const AstRawString* name, | 3374 VariableProxy* NewVariableProxy(const AstRawString* name, |
| 3381 VariableKind variable_kind, | 3375 VariableKind variable_kind, |
| 3382 int start_position = kNoSourcePosition) { | 3376 int start_position = kNoSourcePosition) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3645 : NULL; \ | 3639 : NULL; \ |
| 3646 } | 3640 } |
| 3647 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3641 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3648 #undef DECLARE_NODE_FUNCTIONS | 3642 #undef DECLARE_NODE_FUNCTIONS |
| 3649 | 3643 |
| 3650 | 3644 |
| 3651 } // namespace internal | 3645 } // namespace internal |
| 3652 } // namespace v8 | 3646 } // namespace v8 |
| 3653 | 3647 |
| 3654 #endif // V8_AST_AST_H_ | 3648 #endif // V8_AST_AST_H_ |
| OLD | NEW |