Chromium Code Reviews| 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-value-factory.h" | 8 #include "src/ast/ast-value-factory.h" |
| 9 #include "src/ast/modules.h" | 9 #include "src/ast/modules.h" |
| 10 #include "src/ast/variables.h" | 10 #include "src/ast/variables.h" |
| (...skipping 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); | 1284 Handle<Object> GetBoilerplateValue(Expression* expression, Isolate* isolate); |
| 1285 | 1285 |
| 1286 private: | 1286 private: |
| 1287 bool is_simple_ : 1; | 1287 bool is_simple_ : 1; |
| 1288 int depth_ : 31; | 1288 int depth_ : 31; |
| 1289 int literal_index_; | 1289 int literal_index_; |
| 1290 | 1290 |
| 1291 friend class AstLiteralReindexer; | 1291 friend class AstLiteralReindexer; |
| 1292 }; | 1292 }; |
| 1293 | 1293 |
| 1294 // Common supertype for ObjectLiteralProperty and ClassLiteralProperty | |
| 1295 class LiteralProperty : public ZoneObject { | |
| 1296 public: | |
| 1297 Expression* key() { return key_; } | |
| 1298 Expression* value() { return value_; } | |
|
adamk
2016/09/01 21:18:22
Might as well make these const methods while you'r
bakkot
2016/09/01 23:24:31
Done.
| |
| 1299 void set_key(Expression* e) { key_ = e; } | |
| 1300 void set_value(Expression* e) { value_ = e; } | |
| 1301 | |
| 1302 bool is_computed_name() const { return is_computed_name_; } | |
| 1303 | |
| 1304 FeedbackVectorSlot GetSlot(int offset = 0) const { | |
| 1305 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | |
| 1306 return slots_[offset]; | |
| 1307 } | |
| 1308 | |
| 1309 void SetSlot(FeedbackVectorSlot slot, int offset = 0) { | |
| 1310 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | |
| 1311 slots_[offset] = slot; | |
| 1312 } | |
| 1313 | |
| 1314 bool NeedsSetFunctionName() const; | |
| 1315 | |
| 1316 protected: | |
| 1317 LiteralProperty(Expression* key, Expression* value, bool is_computed_name) | |
| 1318 : key_(key), value_(value), is_computed_name_(is_computed_name) {} | |
| 1319 Expression* key_; | |
|
adamk
2016/09/01 21:18:23
Please leave a blank line above to separate the co
bakkot
2016/09/01 23:24:31
Done.
| |
| 1320 Expression* value_; | |
| 1321 FeedbackVectorSlot slots_[2]; | |
| 1322 bool is_computed_name_; | |
| 1323 }; | |
| 1294 | 1324 |
| 1295 // Property is used for passing information | 1325 // Property is used for passing information |
| 1296 // about an object literal's properties from the parser | 1326 // about an object literal's properties from the parser |
| 1297 // to the code generator. | 1327 // to the code generator. |
| 1298 class ObjectLiteralProperty final : public ZoneObject { | 1328 class ObjectLiteralProperty final : public LiteralProperty { |
| 1299 public: | 1329 public: |
| 1300 enum Kind : uint8_t { | 1330 enum Kind : uint8_t { |
| 1301 CONSTANT, // Property with constant value (compile time). | 1331 CONSTANT, // Property with constant value (compile time). |
| 1302 COMPUTED, // Property with computed value (execution time). | 1332 COMPUTED, // Property with computed value (execution time). |
| 1303 MATERIALIZED_LITERAL, // Property value is a materialized literal. | 1333 MATERIALIZED_LITERAL, // Property value is a materialized literal. |
| 1304 GETTER, | 1334 GETTER, |
| 1305 SETTER, // Property is an accessor function. | 1335 SETTER, // Property is an accessor function. |
| 1306 PROTOTYPE // Property is __proto__. | 1336 PROTOTYPE // Property is __proto__. |
| 1307 }; | 1337 }; |
| 1308 | 1338 |
| 1309 Expression* key() { return key_; } | |
| 1310 Expression* value() { return value_; } | |
| 1311 Kind kind() { return kind_; } | 1339 Kind kind() { return kind_; } |
|
adamk
2016/09/01 21:18:22
Consider adding const modifiers to the getters in
bakkot
2016/09/01 23:24:31
Done.
| |
| 1312 | 1340 |
| 1313 void set_key(Expression* e) { key_ = e; } | |
| 1314 void set_value(Expression* e) { value_ = e; } | |
| 1315 | |
| 1316 // Type feedback information. | 1341 // Type feedback information. |
| 1317 bool IsMonomorphic() { return !receiver_type_.is_null(); } | 1342 bool IsMonomorphic() { return !receiver_type_.is_null(); } |
| 1318 Handle<Map> GetReceiverType() { return receiver_type_; } | 1343 Handle<Map> GetReceiverType() { return receiver_type_; } |
| 1319 | 1344 |
| 1320 bool IsCompileTimeValue(); | 1345 bool IsCompileTimeValue(); |
| 1321 | 1346 |
| 1322 void set_emit_store(bool emit_store); | 1347 void set_emit_store(bool emit_store); |
| 1323 bool emit_store(); | 1348 bool emit_store(); |
| 1324 | 1349 |
| 1325 bool is_static() const { return is_static_; } | |
| 1326 bool is_computed_name() const { return is_computed_name_; } | |
| 1327 | |
| 1328 FeedbackVectorSlot GetSlot(int offset = 0) const { | |
| 1329 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | |
| 1330 return slots_[offset]; | |
| 1331 } | |
| 1332 void SetSlot(FeedbackVectorSlot slot, int offset = 0) { | |
| 1333 DCHECK_LT(offset, static_cast<int>(arraysize(slots_))); | |
| 1334 slots_[offset] = slot; | |
| 1335 } | |
| 1336 | |
| 1337 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } | 1350 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } |
| 1338 | 1351 |
| 1339 bool NeedsSetFunctionName() const; | |
| 1340 | |
| 1341 private: | 1352 private: |
| 1342 friend class AstNodeFactory; | 1353 friend class AstNodeFactory; |
| 1343 | 1354 |
| 1344 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, | 1355 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, |
| 1345 bool is_static, bool is_computed_name); | 1356 bool is_computed_name); |
| 1346 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, | 1357 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, |
| 1347 Expression* value, bool is_static, | 1358 Expression* value, bool is_computed_name); |
| 1348 bool is_computed_name); | |
| 1349 | 1359 |
| 1350 Expression* key_; | |
| 1351 Expression* value_; | |
| 1352 FeedbackVectorSlot slots_[2]; | |
| 1353 Kind kind_; | 1360 Kind kind_; |
| 1354 bool emit_store_; | 1361 bool emit_store_; |
|
adamk
2016/09/01 21:18:23
Make this a single-bit bitfield to pack with kind_
bakkot
2016/09/01 23:24:31
Sounded like this wasn't worth doing, so I'm leavi
| |
| 1355 bool is_static_; | |
| 1356 bool is_computed_name_; | |
| 1357 Handle<Map> receiver_type_; | 1362 Handle<Map> receiver_type_; |
| 1358 }; | 1363 }; |
| 1359 | 1364 |
| 1360 | 1365 |
| 1361 // An object literal has a boilerplate object that is used | 1366 // An object literal has a boilerplate object that is used |
| 1362 // for minimizing the work when constructing it at runtime. | 1367 // for minimizing the work when constructing it at runtime. |
| 1363 class ObjectLiteral final : public MaterializedLiteral { | 1368 class ObjectLiteral final : public MaterializedLiteral { |
| 1364 public: | 1369 public: |
| 1365 typedef ObjectLiteralProperty Property; | 1370 typedef ObjectLiteralProperty Property; |
| 1366 | 1371 |
| (...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2671 int yield_count_; | 2676 int yield_count_; |
| 2672 | 2677 |
| 2673 const AstString* raw_name_; | 2678 const AstString* raw_name_; |
| 2674 DeclarationScope* scope_; | 2679 DeclarationScope* scope_; |
| 2675 ZoneList<Statement*>* body_; | 2680 ZoneList<Statement*>* body_; |
| 2676 const AstString* raw_inferred_name_; | 2681 const AstString* raw_inferred_name_; |
| 2677 Handle<String> inferred_name_; | 2682 Handle<String> inferred_name_; |
| 2678 AstProperties ast_properties_; | 2683 AstProperties ast_properties_; |
| 2679 }; | 2684 }; |
| 2680 | 2685 |
| 2686 // Property is used for passing information | |
| 2687 // about a class literal's properties from the parser to the code generator. | |
| 2688 class ClassLiteralProperty final : public LiteralProperty { | |
| 2689 public: | |
| 2690 enum Kind : uint8_t { METHOD, GETTER, SETTER }; | |
| 2691 | |
| 2692 Kind kind() { return kind_; } | |
|
adamk
2016/09/01 21:18:22
Make this a const method too.
bakkot
2016/09/01 23:24:31
Done.
| |
| 2693 | |
| 2694 bool is_static() const { return is_static_; } | |
| 2695 | |
| 2696 private: | |
| 2697 friend class AstNodeFactory; | |
| 2698 | |
| 2699 ClassLiteralProperty(Expression* key, Expression* value, Kind kind, | |
| 2700 bool is_static, bool is_computed_name); | |
| 2701 | |
| 2702 Kind kind_; | |
| 2703 bool is_static_; | |
| 2704 }; | |
| 2681 | 2705 |
| 2682 class ClassLiteral final : public Expression { | 2706 class ClassLiteral final : public Expression { |
| 2683 public: | 2707 public: |
| 2684 typedef ObjectLiteralProperty Property; | 2708 typedef ClassLiteralProperty Property; |
| 2685 | 2709 |
| 2686 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } | 2710 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } |
| 2687 Expression* extends() const { return extends_; } | 2711 Expression* extends() const { return extends_; } |
| 2688 void set_extends(Expression* e) { extends_ = e; } | 2712 void set_extends(Expression* e) { extends_ = e; } |
| 2689 FunctionLiteral* constructor() const { return constructor_; } | 2713 FunctionLiteral* constructor() const { return constructor_; } |
| 2690 void set_constructor(FunctionLiteral* f) { constructor_ = f; } | 2714 void set_constructor(FunctionLiteral* f) { constructor_ = f; } |
| 2691 ZoneList<Property*>* properties() const { return properties_; } | 2715 ZoneList<Property*>* properties() const { return properties_; } |
| 2692 int start_position() const { return position(); } | 2716 int start_position() const { return position(); } |
| 2693 int end_position() const { return end_position_; } | 2717 int end_position() const { return end_position_; } |
| 2694 | 2718 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3170 | 3194 |
| 3171 ObjectLiteral* NewObjectLiteral( | 3195 ObjectLiteral* NewObjectLiteral( |
| 3172 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, | 3196 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, |
| 3173 uint32_t boilerplate_properties, int pos) { | 3197 uint32_t boilerplate_properties, int pos) { |
| 3174 return new (zone_) | 3198 return new (zone_) |
| 3175 ObjectLiteral(properties, literal_index, boilerplate_properties, pos); | 3199 ObjectLiteral(properties, literal_index, boilerplate_properties, pos); |
| 3176 } | 3200 } |
| 3177 | 3201 |
| 3178 ObjectLiteral::Property* NewObjectLiteralProperty( | 3202 ObjectLiteral::Property* NewObjectLiteralProperty( |
| 3179 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3203 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
| 3180 bool is_static, bool is_computed_name) { | 3204 bool is_computed_name) { |
| 3181 return new (zone_) | 3205 return new (zone_) |
| 3182 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3206 ObjectLiteral::Property(key, value, kind, is_computed_name); |
| 3183 } | 3207 } |
| 3184 | 3208 |
| 3185 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3209 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
| 3186 Expression* value, | 3210 Expression* value, |
| 3187 bool is_static, | |
| 3188 bool is_computed_name) { | 3211 bool is_computed_name) { |
| 3189 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, | 3212 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, |
| 3190 is_static, is_computed_name); | 3213 is_computed_name); |
| 3191 } | 3214 } |
| 3192 | 3215 |
| 3193 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, | 3216 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, |
| 3194 int literal_index, int pos) { | 3217 int literal_index, int pos) { |
| 3195 return new (zone_) RegExpLiteral(pattern, flags, literal_index, pos); | 3218 return new (zone_) RegExpLiteral(pattern, flags, literal_index, pos); |
| 3196 } | 3219 } |
| 3197 | 3220 |
| 3198 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3221 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
| 3199 int literal_index, | 3222 int literal_index, |
| 3200 int pos) { | 3223 int pos) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3349 int materialized_literal_count, int expected_property_count) { | 3372 int materialized_literal_count, int expected_property_count) { |
| 3350 return new (zone_) FunctionLiteral( | 3373 return new (zone_) FunctionLiteral( |
| 3351 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, | 3374 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, |
| 3352 body, materialized_literal_count, expected_property_count, 0, | 3375 body, materialized_literal_count, expected_property_count, 0, |
| 3353 FunctionLiteral::kAnonymousExpression, | 3376 FunctionLiteral::kAnonymousExpression, |
| 3354 FunctionLiteral::kNoDuplicateParameters, | 3377 FunctionLiteral::kNoDuplicateParameters, |
| 3355 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, | 3378 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, |
| 3356 false); | 3379 false); |
| 3357 } | 3380 } |
| 3358 | 3381 |
| 3382 ClassLiteral::Property* NewClassLiteralProperty( | |
| 3383 Expression* key, Expression* value, ClassLiteralProperty::Kind kind, | |
| 3384 bool is_static, bool is_computed_name) { | |
| 3385 return new (zone_) | |
| 3386 ClassLiteral::Property(key, value, kind, is_static, is_computed_name); | |
| 3387 } | |
| 3388 | |
| 3359 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, | 3389 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, |
| 3360 FunctionLiteral* constructor, | 3390 FunctionLiteral* constructor, |
| 3361 ZoneList<ObjectLiteral::Property*>* properties, | 3391 ZoneList<ClassLiteral::Property*>* properties, |
| 3362 int start_position, int end_position) { | 3392 int start_position, int end_position) { |
| 3363 return new (zone_) ClassLiteral(proxy, extends, constructor, properties, | 3393 return new (zone_) ClassLiteral(proxy, extends, constructor, properties, |
| 3364 start_position, end_position); | 3394 start_position, end_position); |
| 3365 } | 3395 } |
| 3366 | 3396 |
| 3367 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3397 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
| 3368 v8::Extension* extension, | 3398 v8::Extension* extension, |
| 3369 int pos) { | 3399 int pos) { |
| 3370 return new (zone_) NativeFunctionLiteral(name, extension, pos); | 3400 return new (zone_) NativeFunctionLiteral(name, extension, pos); |
| 3371 } | 3401 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3464 : NULL; \ | 3494 : NULL; \ |
| 3465 } | 3495 } |
| 3466 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) | 3496 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) |
| 3467 #undef DECLARE_NODE_FUNCTIONS | 3497 #undef DECLARE_NODE_FUNCTIONS |
| 3468 | 3498 |
| 3469 | 3499 |
| 3470 } // namespace internal | 3500 } // namespace internal |
| 3471 } // namespace v8 | 3501 } // namespace v8 |
| 3472 | 3502 |
| 3473 #endif // V8_AST_AST_H_ | 3503 #endif // V8_AST_AST_H_ |
| OLD | NEW |