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_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 Loading... |
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 Loading... |
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...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3293 int boilerplate_properties, | 3330 int boilerplate_properties, |
3294 bool has_function, | 3331 bool has_function, |
3295 int pos) { | 3332 int pos) { |
3296 ObjectLiteral* lit = new (zone_) | 3333 ObjectLiteral* lit = new (zone_) |
3297 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties, | 3334 ObjectLiteral(zone_, properties, literal_index, boilerplate_properties, |
3298 has_function, pos, id_gen_); | 3335 has_function, pos, id_gen_); |
3299 VISIT_AND_RETURN(ObjectLiteral, lit) | 3336 VISIT_AND_RETURN(ObjectLiteral, lit) |
3300 } | 3337 } |
3301 | 3338 |
3302 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, | 3339 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, |
3303 Expression* value) { | 3340 Expression* value, |
3304 return new (zone_) | 3341 bool is_static) { |
3305 ObjectLiteral::Property(zone_, ast_value_factory_, key, value); | 3342 return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key, |
| 3343 value, is_static); |
3306 } | 3344 } |
3307 | 3345 |
3308 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, | 3346 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, |
3309 FunctionLiteral* value, | 3347 FunctionLiteral* value, |
3310 int pos) { | 3348 int pos, bool is_static) { |
3311 ObjectLiteral::Property* prop = | 3349 ObjectLiteral::Property* prop = |
3312 new(zone_) ObjectLiteral::Property(zone_, is_getter, value); | 3350 new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static); |
3313 prop->set_key(NewStringLiteral(value->raw_name(), pos)); | 3351 prop->set_key(NewStringLiteral(value->raw_name(), pos)); |
3314 return prop; // Not an AST node, will not be visited. | 3352 return prop; // Not an AST node, will not be visited. |
3315 } | 3353 } |
3316 | 3354 |
3317 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, | 3355 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, |
3318 const AstRawString* flags, | 3356 const AstRawString* flags, |
3319 int literal_index, | 3357 int literal_index, |
3320 int pos) { | 3358 int pos) { |
3321 RegExpLiteral* lit = new (zone_) | 3359 RegExpLiteral* lit = new (zone_) |
3322 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_); | 3360 RegExpLiteral(zone_, pattern, flags, literal_index, pos, id_gen_); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3458 expected_property_count, handler_count, parameter_count, function_type, | 3496 expected_property_count, handler_count, parameter_count, function_type, |
3459 has_duplicate_parameters, is_function, is_parenthesized, kind, position, | 3497 has_duplicate_parameters, is_function, is_parenthesized, kind, position, |
3460 id_gen_); | 3498 id_gen_); |
3461 // Top-level literal doesn't count for the AST's properties. | 3499 // Top-level literal doesn't count for the AST's properties. |
3462 if (is_function == FunctionLiteral::kIsFunction) { | 3500 if (is_function == FunctionLiteral::kIsFunction) { |
3463 visitor_.VisitFunctionLiteral(lit); | 3501 visitor_.VisitFunctionLiteral(lit); |
3464 } | 3502 } |
3465 return lit; | 3503 return lit; |
3466 } | 3504 } |
3467 | 3505 |
| 3506 ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends, |
| 3507 FunctionLiteral* constructor, |
| 3508 ZoneList<ObjectLiteral::Property*>* properties, |
| 3509 AstValueFactory* ast_value_factory, |
| 3510 int position) { |
| 3511 ClassLiteral* lit = |
| 3512 new (zone_) ClassLiteral(zone_, name, extends, constructor, properties, |
| 3513 ast_value_factory, position, id_gen_); |
| 3514 VISIT_AND_RETURN(ClassLiteral, lit) |
| 3515 } |
| 3516 |
3468 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3517 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
3469 v8::Extension* extension, | 3518 v8::Extension* extension, |
3470 int pos) { | 3519 int pos) { |
3471 NativeFunctionLiteral* lit = | 3520 NativeFunctionLiteral* lit = |
3472 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_); | 3521 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos, id_gen_); |
3473 VISIT_AND_RETURN(NativeFunctionLiteral, lit) | 3522 VISIT_AND_RETURN(NativeFunctionLiteral, lit) |
3474 } | 3523 } |
3475 | 3524 |
3476 ThisFunction* NewThisFunction(int pos) { | 3525 ThisFunction* NewThisFunction(int pos) { |
3477 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_); | 3526 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos, id_gen_); |
(...skipping 12 matching lines...) Expand all Loading... |
3490 Zone* zone_; | 3539 Zone* zone_; |
3491 Visitor visitor_; | 3540 Visitor visitor_; |
3492 AstValueFactory* ast_value_factory_; | 3541 AstValueFactory* ast_value_factory_; |
3493 AstNode::IdGen* id_gen_; | 3542 AstNode::IdGen* id_gen_; |
3494 }; | 3543 }; |
3495 | 3544 |
3496 | 3545 |
3497 } } // namespace v8::internal | 3546 } } // namespace v8::internal |
3498 | 3547 |
3499 #endif // V8_AST_H_ | 3548 #endif // V8_AST_H_ |
OLD | NEW |