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

Side by Side Diff: src/ast.h

Issue 561913002: Class syntax parsing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/full-codegen.cc » ('J')
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_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 22 matching lines...) Expand all
33 33
34 // Nodes are allocated in a separate zone, which allows faster 34 // Nodes are allocated in a separate zone, which allows faster
35 // allocation and constant-time deallocation of the entire syntax 35 // allocation and constant-time deallocation of the entire syntax
36 // tree. 36 // tree.
37 37
38 38
39 // ---------------------------------------------------------------------------- 39 // ----------------------------------------------------------------------------
40 // Nodes of the abstract syntax tree. Only concrete classes are 40 // Nodes of the abstract syntax tree. Only concrete classes are
41 // enumerated here. 41 // enumerated here.
42 42
43 #define DECLARATION_NODE_LIST(V) \ 43 #define DECLARATION_NODE_LIST(V) \
44 V(VariableDeclaration) \ 44 V(VariableDeclaration) \
45 V(FunctionDeclaration) \ 45 V(FunctionDeclaration) \
46 V(ModuleDeclaration) \ 46 V(ModuleDeclaration) \
47 V(ImportDeclaration) \ 47 V(ImportDeclaration) \
48 V(ExportDeclaration) \ 48 V(ExportDeclaration)
49 49
50 #define MODULE_NODE_LIST(V) \ 50 #define MODULE_NODE_LIST(V) \
51 V(ModuleLiteral) \ 51 V(ModuleLiteral) \
52 V(ModuleVariable) \ 52 V(ModuleVariable) \
53 V(ModulePath) \ 53 V(ModulePath) \
54 V(ModuleUrl) 54 V(ModuleUrl)
55 55
56 #define STATEMENT_NODE_LIST(V) \ 56 #define STATEMENT_NODE_LIST(V) \
57 V(Block) \ 57 V(Block) \
58 V(ModuleStatement) \ 58 V(ModuleStatement) \
59 V(ExpressionStatement) \ 59 V(ExpressionStatement) \
60 V(EmptyStatement) \ 60 V(EmptyStatement) \
61 V(IfStatement) \ 61 V(IfStatement) \
62 V(ContinueStatement) \ 62 V(ContinueStatement) \
63 V(BreakStatement) \ 63 V(BreakStatement) \
64 V(ReturnStatement) \ 64 V(ReturnStatement) \
65 V(WithStatement) \ 65 V(WithStatement) \
66 V(SwitchStatement) \ 66 V(SwitchStatement) \
67 V(DoWhileStatement) \ 67 V(DoWhileStatement) \
68 V(WhileStatement) \ 68 V(WhileStatement) \
69 V(ForStatement) \ 69 V(ForStatement) \
70 V(ForInStatement) \ 70 V(ForInStatement) \
71 V(ForOfStatement) \ 71 V(ForOfStatement) \
72 V(TryCatchStatement) \ 72 V(TryCatchStatement) \
73 V(TryFinallyStatement) \ 73 V(TryFinallyStatement) \
74 V(DebuggerStatement) 74 V(DebuggerStatement)
75 75
76 #define EXPRESSION_NODE_LIST(V) \ 76 #define EXPRESSION_NODE_LIST(V) \
77 V(FunctionLiteral) \ 77 V(FunctionLiteral) \
78 V(NativeFunctionLiteral) \ 78 V(ClassLiteral) \
79 V(Conditional) \ 79 V(NativeFunctionLiteral) \
80 V(VariableProxy) \ 80 V(Conditional) \
81 V(Literal) \ 81 V(VariableProxy) \
82 V(RegExpLiteral) \ 82 V(Literal) \
83 V(ObjectLiteral) \ 83 V(RegExpLiteral) \
84 V(ArrayLiteral) \ 84 V(ObjectLiteral) \
85 V(Assignment) \ 85 V(ArrayLiteral) \
86 V(Yield) \ 86 V(Assignment) \
87 V(Throw) \ 87 V(Yield) \
88 V(Property) \ 88 V(Throw) \
89 V(Call) \ 89 V(Property) \
90 V(CallNew) \ 90 V(Call) \
91 V(CallRuntime) \ 91 V(CallNew) \
92 V(UnaryOperation) \ 92 V(CallRuntime) \
93 V(CountOperation) \ 93 V(UnaryOperation) \
94 V(BinaryOperation) \ 94 V(CountOperation) \
95 V(CompareOperation) \ 95 V(BinaryOperation) \
96 V(ThisFunction) \ 96 V(CompareOperation) \
97 V(SuperReference) \ 97 V(ThisFunction) \
98 V(SuperReference) \
98 V(CaseClause) 99 V(CaseClause)
99 100
100 #define AST_NODE_LIST(V) \ 101 #define AST_NODE_LIST(V) \
101 DECLARATION_NODE_LIST(V) \ 102 DECLARATION_NODE_LIST(V) \
102 MODULE_NODE_LIST(V) \ 103 MODULE_NODE_LIST(V) \
103 STATEMENT_NODE_LIST(V) \ 104 STATEMENT_NODE_LIST(V) \
104 EXPRESSION_NODE_LIST(V) 105 EXPRESSION_NODE_LIST(V)
105 106
106 // Forward declarations 107 // Forward declarations
107 class AstConstructionVisitor; 108 class AstConstructionVisitor;
(...skipping 1344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1452 public: 1453 public:
1453 enum Kind { 1454 enum Kind {
1454 CONSTANT, // Property with constant value (compile time). 1455 CONSTANT, // Property with constant value (compile time).
1455 COMPUTED, // Property with computed value (execution time). 1456 COMPUTED, // Property with computed value (execution time).
1456 MATERIALIZED_LITERAL, // Property value is a materialized literal. 1457 MATERIALIZED_LITERAL, // Property value is a materialized literal.
1457 GETTER, SETTER, // Property is an accessor function. 1458 GETTER, SETTER, // Property is an accessor function.
1458 PROTOTYPE // Property is __proto__. 1459 PROTOTYPE // Property is __proto__.
1459 }; 1460 };
1460 1461
1461 ObjectLiteralProperty(Zone* zone, AstValueFactory* ast_value_factory, 1462 ObjectLiteralProperty(Zone* zone, AstValueFactory* ast_value_factory,
1462 Literal* key, Expression* value); 1463 Literal* key, Expression* value,
1464 bool is_static);
rossberg 2014/09/15 12:32:48 Nit: formatting
arv (Not doing code reviews) 2014/09/15 15:12:32 Done.
1463 1465
1464 Literal* key() { return key_; } 1466 Literal* key() { return key_; }
1465 Expression* value() { return value_; } 1467 Expression* value() { return value_; }
1466 Kind kind() { return kind_; } 1468 Kind kind() { return kind_; }
1467 1469
1468 // Type feedback information. 1470 // Type feedback information.
1469 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1471 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1470 bool IsMonomorphic() { return !receiver_type_.is_null(); } 1472 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1471 Handle<Map> GetReceiverType() { return receiver_type_; } 1473 Handle<Map> GetReceiverType() { return receiver_type_; }
1472 1474
1473 bool IsCompileTimeValue(); 1475 bool IsCompileTimeValue();
1474 1476
1475 void set_emit_store(bool emit_store); 1477 void set_emit_store(bool emit_store);
1476 bool emit_store(); 1478 bool emit_store();
1477 1479
1478 protected: 1480 protected:
1479 template<class> friend class AstNodeFactory; 1481 template<class> friend class AstNodeFactory;
1480 1482
1481 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value); 1483 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value,
1484 bool is_static);
1482 void set_key(Literal* key) { key_ = key; } 1485 void set_key(Literal* key) { key_ = key; }
1483 1486
1484 private: 1487 private:
1485 Literal* key_; 1488 Literal* key_;
1486 Expression* value_; 1489 Expression* value_;
1487 Kind kind_; 1490 Kind kind_;
1488 bool emit_store_; 1491 bool emit_store_;
1492 bool is_static_;
arv (Not doing code reviews) 2014/09/12 21:36:34 What was the conclusion on C++ bit field members?
Sven Panne 2014/09/15 11:13:05 I would leave it as it is, to avoid premature opti
rossberg 2014/09/15 12:32:48 Opinions still differ, better to avoid them for th
arv (Not doing code reviews) 2014/09/15 15:12:32 See later comment.
1489 Handle<Map> receiver_type_; 1493 Handle<Map> receiver_type_;
1490 }; 1494 };
1491 1495
1492 1496
1493 // An object literal has a boilerplate object that is used 1497 // An object literal has a boilerplate object that is used
1494 // for minimizing the work when constructing it at runtime. 1498 // for minimizing the work when constructing it at runtime.
1495 class ObjectLiteral FINAL : public MaterializedLiteral { 1499 class ObjectLiteral FINAL : public MaterializedLiteral {
1496 public: 1500 public:
1497 typedef ObjectLiteralProperty Property; 1501 typedef ObjectLiteralProperty Property;
1498 1502
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
2491 class IsExpression : public BitField<bool, 0, 1> {}; 2495 class IsExpression : public BitField<bool, 0, 1> {};
2492 class IsAnonymous : public BitField<bool, 1, 1> {}; 2496 class IsAnonymous : public BitField<bool, 1, 1> {};
2493 class Pretenure : public BitField<bool, 2, 1> {}; 2497 class Pretenure : public BitField<bool, 2, 1> {};
2494 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; 2498 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2495 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; 2499 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2496 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; 2500 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
2497 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {}; 2501 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {};
2498 }; 2502 };
2499 2503
2500 2504
2505 class ClassLiteral FINAL : public Expression {
2506 public:
2507 typedef ObjectLiteralProperty Property;
2508
2509 DECLARE_NODE_TYPE(ClassLiteral)
2510
2511 Handle<String> name() const { return raw_name_->string(); }
2512 const AstRawString* raw_name() const { return raw_name_; }
2513 Expression* extends() const { return extends_; }
2514 FunctionLiteral* constructor() const { return constructor_; }
2515 ZoneList<Property*>* properties() const { return properties_; }
2516
2517 protected:
2518 ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends,
2519 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2520 AstValueFactory* ast_value_factory, int position, IdGen* id_gen)
2521 : Expression(zone, position, id_gen),
2522 raw_name_(name),
2523 raw_inferred_name_(ast_value_factory->empty_string()),
2524 extends_(extends),
2525 constructor_(constructor),
2526 properties_(properties) {}
2527
2528 private:
2529 const AstRawString* raw_name_;
2530 Handle<String> name_;
2531 const AstString* raw_inferred_name_;
2532 Handle<String> inferred_name_;
2533 Expression* extends_;
2534 FunctionLiteral* constructor_;
2535 ZoneList<Property*>* properties_;
2536 };
2537
2538
2501 class NativeFunctionLiteral FINAL : public Expression { 2539 class NativeFunctionLiteral FINAL : public Expression {
2502 public: 2540 public:
2503 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2541 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2504 2542
2505 Handle<String> name() const { return name_->string(); } 2543 Handle<String> name() const { return name_->string(); }
2506 v8::Extension* extension() const { return extension_; } 2544 v8::Extension* extension() const { return extension_; }
2507 2545
2508 protected: 2546 protected:
2509 NativeFunctionLiteral(Zone* zone, const AstRawString* name, 2547 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2510 v8::Extension* extension, int pos, IdGen* id_gen) 2548 v8::Extension* extension, int pos, IdGen* id_gen)
(...skipping 771 matching lines...) Expand 10 before | Expand all | Expand 10 after
3282 int boilerplate_properties, 3320 int boilerplate_properties,
3283 bool has_function, 3321 bool has_function,
3284 int pos) { 3322 int pos) {
3285 ObjectLiteral* lit = new (zone_) 3323 ObjectLiteral* lit = new (zone_)
3286 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties, 3324 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties,
3287 has_function, pos, id_gen_); 3325 has_function, pos, id_gen_);
3288 VISIT_AND_RETURN(ObjectLiteral, lit) 3326 VISIT_AND_RETURN(ObjectLiteral, lit)
3289 } 3327 }
3290 3328
3291 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, 3329 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
3292 Expression* value) { 3330 Expression* value,
3293 return new (zone_) 3331 bool is_static) {
3294 ObjectLiteral::Property(zone_, ast_value_factory_, key, value); 3332 return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key,
3333 value, is_static);
3295 } 3334 }
3296 3335
3297 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, 3336 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
3298 FunctionLiteral* value, 3337 FunctionLiteral* value,
3299 int pos) { 3338 int pos, bool is_static) {
3300 ObjectLiteral::Property* prop = 3339 ObjectLiteral::Property* prop =
3301 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); 3340 new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static);
3302 prop->set_key(NewStringLiteral(value->raw_name(), pos)); 3341 prop->set_key(NewStringLiteral(value->raw_name(), pos));
3303 return prop; // Not an AST node, will not be visited. 3342 return prop; // Not an AST node, will not be visited.
3304 } 3343 }
3305 3344
3306 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, 3345 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3307 const AstRawString* flags, 3346 const AstRawString* flags,
3308 int literal_index, 3347 int literal_index,
3309 int pos) { 3348 int pos) {
3310 RegExpLiteral* lit = new (zone_) 3349 RegExpLiteral* lit = new (zone_)
3311 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_); 3350 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3447 expected_property_count, handler_count, parameter_count, function_type, 3486 expected_property_count, handler_count, parameter_count, function_type,
3448 has_duplicate_parameters, is_function, is_parenthesized, kind, position, 3487 has_duplicate_parameters, is_function, is_parenthesized, kind, position,
3449 id_gen_); 3488 id_gen_);
3450 // Top-level literal doesn't count for the AST's properties. 3489 // Top-level literal doesn't count for the AST's properties.
3451 if (is_function == FunctionLiteral::kIsFunction) { 3490 if (is_function == FunctionLiteral::kIsFunction) {
3452 visitor_.VisitFunctionLiteral(lit); 3491 visitor_.VisitFunctionLiteral(lit);
3453 } 3492 }
3454 return lit; 3493 return lit;
3455 } 3494 }
3456 3495
3496 ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends,
3497 FunctionLiteral* constructor,
3498 ZoneList<ObjectLiteral::Property*>* properties,
3499 AstValueFactory* ast_value_factory,
3500 int position) {
3501 ClassLiteral* lit =
3502 new (zone_) ClassLiteral(zone_, name, extends, constructor, properties,
3503 ast_value_factory, position, id_gen_);
3504 VISIT_AND_RETURN(ClassLiteral, lit)
3505 }
3506
3457 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3507 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3458 v8::Extension* extension, 3508 v8::Extension* extension,
3459 int pos) { 3509 int pos) {
3460 NativeFunctionLiteral* lit = 3510 NativeFunctionLiteral* lit =
3461 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_); 3511 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_);
3462 VISIT_AND_RETURN(NativeFunctionLiteral, lit) 3512 VISIT_AND_RETURN(NativeFunctionLiteral, lit)
3463 } 3513 }
3464 3514
3465 ThisFunction* NewThisFunction(int pos) { 3515 ThisFunction* NewThisFunction(int pos) {
3466 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_); 3516 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_);
(...skipping 12 matching lines...) Expand all
3479 Zone* zone_; 3529 Zone* zone_;
3480 Visitor visitor_; 3530 Visitor visitor_;
3481 AstValueFactory* ast_value_factory_; 3531 AstValueFactory* ast_value_factory_;
3482 AstNode::IdGen* id_gen_; 3532 AstNode::IdGen* id_gen_;
3483 }; 3533 };
3484 3534
3485 3535
3486 } } // namespace v8::internal 3536 } } // namespace v8::internal
3487 3537
3488 #endif // V8_AST_H_ 3538 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | src/full-codegen.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698