Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: src/ast/ast.h

Issue 2302643002: Split the AST representation of class properties from object properties (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() const { return key_; }
1298 Expression* value() const { return value_; }
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
1320 Expression* key_;
1321 Expression* value_;
1322 FeedbackVectorSlot slots_[2];
1323 bool is_computed_name_;
1324 };
1294 1325
1295 // Property is used for passing information 1326 // Property is used for passing information
1296 // about an object literal's properties from the parser 1327 // about an object literal's properties from the parser
1297 // to the code generator. 1328 // to the code generator.
1298 class ObjectLiteralProperty final : public ZoneObject { 1329 class ObjectLiteralProperty final : public LiteralProperty {
1299 public: 1330 public:
1300 enum Kind : uint8_t { 1331 enum Kind : uint8_t {
1301 CONSTANT, // Property with constant value (compile time). 1332 CONSTANT, // Property with constant value (compile time).
1302 COMPUTED, // Property with computed value (execution time). 1333 COMPUTED, // Property with computed value (execution time).
1303 MATERIALIZED_LITERAL, // Property value is a materialized literal. 1334 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1304 GETTER, 1335 GETTER,
1305 SETTER, // Property is an accessor function. 1336 SETTER, // Property is an accessor function.
1306 PROTOTYPE // Property is __proto__. 1337 PROTOTYPE // Property is __proto__.
1307 }; 1338 };
1308 1339
1309 Expression* key() { return key_; } 1340 Kind kind() const { return kind_; }
1310 Expression* value() { return value_; }
1311 Kind kind() { return kind_; }
1312
1313 void set_key(Expression* e) { key_ = e; }
1314 void set_value(Expression* e) { value_ = e; }
1315 1341
1316 // Type feedback information. 1342 // Type feedback information.
1317 bool IsMonomorphic() { return !receiver_type_.is_null(); } 1343 bool IsMonomorphic() const { return !receiver_type_.is_null(); }
1318 Handle<Map> GetReceiverType() { return receiver_type_; } 1344 Handle<Map> GetReceiverType() const { return receiver_type_; }
1319 1345
1320 bool IsCompileTimeValue(); 1346 bool IsCompileTimeValue() const;
1321 1347
1322 void set_emit_store(bool emit_store); 1348 void set_emit_store(bool emit_store);
1323 bool emit_store(); 1349 bool emit_store() const;
1324
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 1350
1337 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; } 1351 void set_receiver_type(Handle<Map> map) { receiver_type_ = map; }
1338 1352
1339 bool NeedsSetFunctionName() const;
1340
1341 private: 1353 private:
1342 friend class AstNodeFactory; 1354 friend class AstNodeFactory;
1343 1355
1344 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind, 1356 ObjectLiteralProperty(Expression* key, Expression* value, Kind kind,
1345 bool is_static, bool is_computed_name); 1357 bool is_computed_name);
1346 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key, 1358 ObjectLiteralProperty(AstValueFactory* ast_value_factory, Expression* key,
1347 Expression* value, bool is_static, 1359 Expression* value, bool is_computed_name);
1348 bool is_computed_name);
1349 1360
1350 Expression* key_;
1351 Expression* value_;
1352 FeedbackVectorSlot slots_[2];
1353 Kind kind_; 1361 Kind kind_;
1354 bool emit_store_; 1362 bool emit_store_;
1355 bool is_static_;
1356 bool is_computed_name_;
1357 Handle<Map> receiver_type_; 1363 Handle<Map> receiver_type_;
1358 }; 1364 };
1359 1365
1360 1366
1361 // An object literal has a boilerplate object that is used 1367 // An object literal has a boilerplate object that is used
1362 // for minimizing the work when constructing it at runtime. 1368 // for minimizing the work when constructing it at runtime.
1363 class ObjectLiteral final : public MaterializedLiteral { 1369 class ObjectLiteral final : public MaterializedLiteral {
1364 public: 1370 public:
1365 typedef ObjectLiteralProperty Property; 1371 typedef ObjectLiteralProperty Property;
1366 1372
(...skipping 1304 matching lines...) Expand 10 before | Expand all | Expand 10 after
2671 int yield_count_; 2677 int yield_count_;
2672 2678
2673 const AstString* raw_name_; 2679 const AstString* raw_name_;
2674 DeclarationScope* scope_; 2680 DeclarationScope* scope_;
2675 ZoneList<Statement*>* body_; 2681 ZoneList<Statement*>* body_;
2676 const AstString* raw_inferred_name_; 2682 const AstString* raw_inferred_name_;
2677 Handle<String> inferred_name_; 2683 Handle<String> inferred_name_;
2678 AstProperties ast_properties_; 2684 AstProperties ast_properties_;
2679 }; 2685 };
2680 2686
2687 // Property is used for passing information
2688 // about a class literal's properties from the parser to the code generator.
2689 class ClassLiteralProperty final : public LiteralProperty {
2690 public:
2691 enum Kind : uint8_t { METHOD, GETTER, SETTER };
2692
2693 Kind kind() const { return kind_; }
2694
2695 bool is_static() const { return is_static_; }
2696
2697 private:
2698 friend class AstNodeFactory;
2699
2700 ClassLiteralProperty(Expression* key, Expression* value, Kind kind,
2701 bool is_static, bool is_computed_name);
2702
2703 Kind kind_;
2704 bool is_static_;
2705 };
2681 2706
2682 class ClassLiteral final : public Expression { 2707 class ClassLiteral final : public Expression {
2683 public: 2708 public:
2684 typedef ObjectLiteralProperty Property; 2709 typedef ClassLiteralProperty Property;
2685 2710
2686 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; } 2711 VariableProxy* class_variable_proxy() const { return class_variable_proxy_; }
2687 Expression* extends() const { return extends_; } 2712 Expression* extends() const { return extends_; }
2688 void set_extends(Expression* e) { extends_ = e; } 2713 void set_extends(Expression* e) { extends_ = e; }
2689 FunctionLiteral* constructor() const { return constructor_; } 2714 FunctionLiteral* constructor() const { return constructor_; }
2690 void set_constructor(FunctionLiteral* f) { constructor_ = f; } 2715 void set_constructor(FunctionLiteral* f) { constructor_ = f; }
2691 ZoneList<Property*>* properties() const { return properties_; } 2716 ZoneList<Property*>* properties() const { return properties_; }
2692 int start_position() const { return position(); } 2717 int start_position() const { return position(); }
2693 int end_position() const { return end_position_; } 2718 int end_position() const { return end_position_; }
2694 2719
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
3170 3195
3171 ObjectLiteral* NewObjectLiteral( 3196 ObjectLiteral* NewObjectLiteral(
3172 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, 3197 ZoneList<ObjectLiteral::Property*>* properties, int literal_index,
3173 uint32_t boilerplate_properties, int pos) { 3198 uint32_t boilerplate_properties, int pos) {
3174 return new (zone_) 3199 return new (zone_)
3175 ObjectLiteral(properties, literal_index, boilerplate_properties, pos); 3200 ObjectLiteral(properties, literal_index, boilerplate_properties, pos);
3176 } 3201 }
3177 3202
3178 ObjectLiteral::Property* NewObjectLiteralProperty( 3203 ObjectLiteral::Property* NewObjectLiteralProperty(
3179 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, 3204 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3180 bool is_static, bool is_computed_name) { 3205 bool is_computed_name) {
3181 return new (zone_) 3206 return new (zone_)
3182 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); 3207 ObjectLiteral::Property(key, value, kind, is_computed_name);
3183 } 3208 }
3184 3209
3185 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, 3210 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3186 Expression* value, 3211 Expression* value,
3187 bool is_static,
3188 bool is_computed_name) { 3212 bool is_computed_name) {
3189 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, 3213 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3190 is_static, is_computed_name); 3214 is_computed_name);
3191 } 3215 }
3192 3216
3193 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, 3217 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags,
3194 int literal_index, int pos) { 3218 int literal_index, int pos) {
3195 return new (zone_) RegExpLiteral(pattern, flags, literal_index, pos); 3219 return new (zone_) RegExpLiteral(pattern, flags, literal_index, pos);
3196 } 3220 }
3197 3221
3198 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3222 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3199 int literal_index, 3223 int literal_index,
3200 int pos) { 3224 int pos) {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
3349 int materialized_literal_count, int expected_property_count) { 3373 int materialized_literal_count, int expected_property_count) {
3350 return new (zone_) FunctionLiteral( 3374 return new (zone_) FunctionLiteral(
3351 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope, 3375 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
3352 body, materialized_literal_count, expected_property_count, 0, 3376 body, materialized_literal_count, expected_property_count, 0,
3353 FunctionLiteral::kAnonymousExpression, 3377 FunctionLiteral::kAnonymousExpression,
3354 FunctionLiteral::kNoDuplicateParameters, 3378 FunctionLiteral::kNoDuplicateParameters,
3355 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, 3379 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0,
3356 false); 3380 false);
3357 } 3381 }
3358 3382
3383 ClassLiteral::Property* NewClassLiteralProperty(
3384 Expression* key, Expression* value, ClassLiteralProperty::Kind kind,
3385 bool is_static, bool is_computed_name) {
3386 return new (zone_)
3387 ClassLiteral::Property(key, value, kind, is_static, is_computed_name);
3388 }
3389
3359 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, 3390 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends,
3360 FunctionLiteral* constructor, 3391 FunctionLiteral* constructor,
3361 ZoneList<ObjectLiteral::Property*>* properties, 3392 ZoneList<ClassLiteral::Property*>* properties,
3362 int start_position, int end_position) { 3393 int start_position, int end_position) {
3363 return new (zone_) ClassLiteral(proxy, extends, constructor, properties, 3394 return new (zone_) ClassLiteral(proxy, extends, constructor, properties,
3364 start_position, end_position); 3395 start_position, end_position);
3365 } 3396 }
3366 3397
3367 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3398 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3368 v8::Extension* extension, 3399 v8::Extension* extension,
3369 int pos) { 3400 int pos) {
3370 return new (zone_) NativeFunctionLiteral(name, extension, pos); 3401 return new (zone_) NativeFunctionLiteral(name, extension, pos);
3371 } 3402 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 : NULL; \ 3495 : NULL; \
3465 } 3496 }
3466 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3497 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3467 #undef DECLARE_NODE_FUNCTIONS 3498 #undef DECLARE_NODE_FUNCTIONS
3468 3499
3469 3500
3470 } // namespace internal 3501 } // namespace internal
3471 } // namespace v8 3502 } // namespace v8
3472 3503
3473 #endif // V8_AST_AST_H_ 3504 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698