Chromium Code Reviews

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: Remove extra scope for now Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.cc » ('j') | test/cctest/test-parsing.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...)
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...)
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, bool is_static);
1463 1464
1464 Literal* key() { return key_; } 1465 Literal* key() { return key_; }
1465 Expression* value() { return value_; } 1466 Expression* value() { return value_; }
1466 Kind kind() { return kind_; } 1467 Kind kind() { return kind_; }
1467 1468
1468 // Type feedback information. 1469 // Type feedback information.
1469 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1470 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1470 bool IsMonomorphic() { return !receiver_type_.is_null(); } 1471 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1471 Handle<Map> GetReceiverType() { return receiver_type_; } 1472 Handle<Map> GetReceiverType() { return receiver_type_; }
1472 1473
1473 bool IsCompileTimeValue(); 1474 bool IsCompileTimeValue();
1474 1475
1475 void set_emit_store(bool emit_store); 1476 void set_emit_store(bool emit_store);
1476 bool emit_store(); 1477 bool emit_store();
1477 1478
1478 protected: 1479 protected:
1479 template<class> friend class AstNodeFactory; 1480 template<class> friend class AstNodeFactory;
1480 1481
1481 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value); 1482 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value,
1483 bool is_static);
1482 void set_key(Literal* key) { key_ = key; } 1484 void set_key(Literal* key) { key_ = key; }
1483 1485
1484 private: 1486 private:
1485 Literal* key_; 1487 Literal* key_;
1486 Expression* value_; 1488 Expression* value_;
1487 Kind kind_; 1489 Kind kind_;
1488 bool emit_store_; 1490 bool emit_store_;
1491 bool is_static_;
1489 Handle<Map> receiver_type_; 1492 Handle<Map> receiver_type_;
1490 }; 1493 };
1491 1494
1492 1495
1493 // An object literal has a boilerplate object that is used 1496 // An object literal has a boilerplate object that is used
1494 // for minimizing the work when constructing it at runtime. 1497 // for minimizing the work when constructing it at runtime.
1495 class ObjectLiteral FINAL : public MaterializedLiteral { 1498 class ObjectLiteral FINAL : public MaterializedLiteral {
1496 public: 1499 public:
1497 typedef ObjectLiteralProperty Property; 1500 typedef ObjectLiteralProperty Property;
1498 1501
(...skipping 992 matching lines...)
2491 class IsExpression : public BitField<bool, 0, 1> {}; 2494 class IsExpression : public BitField<bool, 0, 1> {};
2492 class IsAnonymous : public BitField<bool, 1, 1> {}; 2495 class IsAnonymous : public BitField<bool, 1, 1> {};
2493 class Pretenure : public BitField<bool, 2, 1> {}; 2496 class Pretenure : public BitField<bool, 2, 1> {};
2494 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; 2497 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {};
2495 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; 2498 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {};
2496 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; 2499 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {};
2497 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {}; 2500 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {};
2498 }; 2501 };
2499 2502
2500 2503
2504 class ClassLiteral FINAL : public Expression {
2505 public:
2506 typedef ObjectLiteralProperty Property;
2507
2508 DECLARE_NODE_TYPE(ClassLiteral)
2509
2510 Handle<String> name() const { return raw_name_->string(); }
2511 const AstRawString* raw_name() const { return raw_name_; }
2512 Expression* extends() const { return extends_; }
2513 FunctionLiteral* constructor() const { return constructor_; }
2514 ZoneList<Property*>* properties() const { return properties_; }
2515
2516 protected:
2517 ClassLiteral(Zone* zone, const AstRawString* name, Expression* extends,
2518 FunctionLiteral* constructor, ZoneList<Property*>* properties,
2519 AstValueFactory* ast_value_factory, int position, IdGen* id_gen)
2520 : Expression(zone, position, id_gen),
2521 raw_name_(name),
2522 raw_inferred_name_(ast_value_factory->empty_string()),
2523 extends_(extends),
2524 constructor_(constructor),
2525 properties_(properties) {}
2526
2527 private:
2528 const AstRawString* raw_name_;
2529 Handle<String> name_;
2530 const AstString* raw_inferred_name_;
2531 Handle<String> inferred_name_;
2532 Expression* extends_;
2533 FunctionLiteral* constructor_;
2534 ZoneList<Property*>* properties_;
2535 };
2536
2537
2501 class NativeFunctionLiteral FINAL : public Expression { 2538 class NativeFunctionLiteral FINAL : public Expression {
2502 public: 2539 public:
2503 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2540 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2504 2541
2505 Handle<String> name() const { return name_->string(); } 2542 Handle<String> name() const { return name_->string(); }
2506 v8::Extension* extension() const { return extension_; } 2543 v8::Extension* extension() const { return extension_; }
2507 2544
2508 protected: 2545 protected:
2509 NativeFunctionLiteral(Zone* zone, const AstRawString* name, 2546 NativeFunctionLiteral(Zone* zone, const AstRawString* name,
2510 v8::Extension* extension, int pos, IdGen* id_gen) 2547 v8::Extension* extension, int pos, IdGen* id_gen)
(...skipping 771 matching lines...)
3282 int boilerplate_properties, 3319 int boilerplate_properties,
3283 bool has_function, 3320 bool has_function,
3284 int pos) { 3321 int pos) {
3285 ObjectLiteral* lit = new (zone_) 3322 ObjectLiteral* lit = new (zone_)
3286 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties, 3323 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties,
3287 has_function, pos, id_gen_); 3324 has_function, pos, id_gen_);
3288 VISIT_AND_RETURN(ObjectLiteral, lit) 3325 VISIT_AND_RETURN(ObjectLiteral, lit)
3289 } 3326 }
3290 3327
3291 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, 3328 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
3292 Expression* value) { 3329 Expression* value,
3293 return new (zone_) 3330 bool is_static) {
3294 ObjectLiteral::Property(zone_, ast_value_factory_, key, value); 3331 return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key,
3332 value, is_static);
3295 } 3333 }
3296 3334
3297 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, 3335 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
3298 FunctionLiteral* value, 3336 FunctionLiteral* value,
3299 int pos) { 3337 int pos, bool is_static) {
3300 ObjectLiteral::Property* prop = 3338 ObjectLiteral::Property* prop =
3301 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); 3339 new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static);
3302 prop->set_key(NewStringLiteral(value->raw_name(), pos)); 3340 prop->set_key(NewStringLiteral(value->raw_name(), pos));
3303 return prop; // Not an AST node, will not be visited. 3341 return prop; // Not an AST node, will not be visited.
3304 } 3342 }
3305 3343
3306 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, 3344 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3307 const AstRawString* flags, 3345 const AstRawString* flags,
3308 int literal_index, 3346 int literal_index,
3309 int pos) { 3347 int pos) {
3310 RegExpLiteral* lit = new (zone_) 3348 RegExpLiteral* lit = new (zone_)
3311 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_); 3349 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_);
(...skipping 135 matching lines...)
3447 expected_property_count, handler_count, parameter_count, function_type, 3485 expected_property_count, handler_count, parameter_count, function_type,
3448 has_duplicate_parameters, is_function, is_parenthesized, kind, position, 3486 has_duplicate_parameters, is_function, is_parenthesized, kind, position,
3449 id_gen_); 3487 id_gen_);
3450 // Top-level literal doesn't count for the AST's properties. 3488 // Top-level literal doesn't count for the AST's properties.
3451 if (is_function == FunctionLiteral::kIsFunction) { 3489 if (is_function == FunctionLiteral::kIsFunction) {
3452 visitor_.VisitFunctionLiteral(lit); 3490 visitor_.VisitFunctionLiteral(lit);
3453 } 3491 }
3454 return lit; 3492 return lit;
3455 } 3493 }
3456 3494
3495 ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends,
3496 FunctionLiteral* constructor,
3497 ZoneList<ObjectLiteral::Property*>* properties,
3498 AstValueFactory* ast_value_factory,
3499 int position) {
3500 ClassLiteral* lit =
3501 new (zone_) ClassLiteral(zone_, name, extends, constructor, properties,
3502 ast_value_factory, position, id_gen_);
3503 VISIT_AND_RETURN(ClassLiteral, lit)
3504 }
3505
3457 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3506 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3458 v8::Extension* extension, 3507 v8::Extension* extension,
3459 int pos) { 3508 int pos) {
3460 NativeFunctionLiteral* lit = 3509 NativeFunctionLiteral* lit =
3461 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_); 3510 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_);
3462 VISIT_AND_RETURN(NativeFunctionLiteral, lit) 3511 VISIT_AND_RETURN(NativeFunctionLiteral, lit)
3463 } 3512 }
3464 3513
3465 ThisFunction* NewThisFunction(int pos) { 3514 ThisFunction* NewThisFunction(int pos) {
3466 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_); 3515 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_);
(...skipping 12 matching lines...)
3479 Zone* zone_; 3528 Zone* zone_;
3480 Visitor visitor_; 3529 Visitor visitor_;
3481 AstValueFactory* ast_value_factory_; 3530 AstValueFactory* ast_value_factory_;
3482 AstNode::IdGen* id_gen_; 3531 AstNode::IdGen* id_gen_;
3483 }; 3532 };
3484 3533
3485 3534
3486 } } // namespace v8::internal 3535 } } // namespace v8::internal
3487 3536
3488 #endif // V8_AST_H_ 3537 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | test/cctest/test-parsing.cc » ('J')

Powered by Google App Engine