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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 V(Yield) \ | 86 V(Yield) \ |
87 V(Throw) \ | 87 V(Throw) \ |
88 V(Property) \ | 88 V(Property) \ |
89 V(Call) \ | 89 V(Call) \ |
90 V(CallNew) \ | 90 V(CallNew) \ |
91 V(CallRuntime) \ | 91 V(CallRuntime) \ |
92 V(UnaryOperation) \ | 92 V(UnaryOperation) \ |
93 V(CountOperation) \ | 93 V(CountOperation) \ |
94 V(BinaryOperation) \ | 94 V(BinaryOperation) \ |
95 V(CompareOperation) \ | 95 V(CompareOperation) \ |
| 96 V(SpreadOperation) \ |
96 V(ThisFunction) \ | 97 V(ThisFunction) \ |
97 V(SuperReference) \ | 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 |
(...skipping 15 matching lines...) Expand all Loading... |
121 class RegExpBackReference; | 122 class RegExpBackReference; |
122 class RegExpCapture; | 123 class RegExpCapture; |
123 class RegExpCharacterClass; | 124 class RegExpCharacterClass; |
124 class RegExpCompiler; | 125 class RegExpCompiler; |
125 class RegExpDisjunction; | 126 class RegExpDisjunction; |
126 class RegExpEmpty; | 127 class RegExpEmpty; |
127 class RegExpLookahead; | 128 class RegExpLookahead; |
128 class RegExpQuantifier; | 129 class RegExpQuantifier; |
129 class RegExpText; | 130 class RegExpText; |
130 | 131 |
| 132 // Other forward declarations |
| 133 class Scope; |
| 134 |
131 #define DEF_FORWARD_DECLARATION(type) class type; | 135 #define DEF_FORWARD_DECLARATION(type) class type; |
132 AST_NODE_LIST(DEF_FORWARD_DECLARATION) | 136 AST_NODE_LIST(DEF_FORWARD_DECLARATION) |
133 #undef DEF_FORWARD_DECLARATION | 137 #undef DEF_FORWARD_DECLARATION |
134 | 138 |
135 | 139 |
136 // Typedef only introduced to avoid unreadable code. | 140 // Typedef only introduced to avoid unreadable code. |
137 // Please do appreciate the required space in "> >". | 141 // Please do appreciate the required space in "> >". |
138 typedef ZoneList<Handle<String> > ZoneStringList; | 142 typedef ZoneList<Handle<String> > ZoneStringList; |
139 typedef ZoneList<Handle<Object> > ZoneObjectList; | 143 typedef ZoneList<Handle<Object> > ZoneObjectList; |
140 | 144 |
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1884 // Helpers to determine how to handle the call. | 1888 // Helpers to determine how to handle the call. |
1885 CallType GetCallType(Isolate* isolate) const; | 1889 CallType GetCallType(Isolate* isolate) const; |
1886 bool IsUsingCallFeedbackSlot(Isolate* isolate) const; | 1890 bool IsUsingCallFeedbackSlot(Isolate* isolate) const; |
1887 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const; | 1891 bool IsUsingCallFeedbackICSlot(Isolate* isolate) const; |
1888 | 1892 |
1889 #ifdef DEBUG | 1893 #ifdef DEBUG |
1890 // Used to assert that the FullCodeGenerator records the return site. | 1894 // Used to assert that the FullCodeGenerator records the return site. |
1891 bool return_is_recorded_; | 1895 bool return_is_recorded_; |
1892 #endif | 1896 #endif |
1893 | 1897 |
| 1898 inline void MarkSpreadCall() { |
| 1899 bit_field_ |= HasSpreadArgumentsField::encode(true); |
| 1900 } |
| 1901 |
| 1902 inline bool HasSpreadArguments() const { |
| 1903 return HasSpreadArgumentsField::decode(bit_field_); |
| 1904 } |
| 1905 |
1894 protected: | 1906 protected: |
1895 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, | 1907 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, |
1896 int pos) | 1908 int pos) |
1897 : Expression(zone, pos), | 1909 : Expression(zone, pos), |
1898 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()), | 1910 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()), |
1899 expression_(expression), | 1911 expression_(expression), |
1900 arguments_(arguments), | 1912 arguments_(arguments), |
1901 bit_field_(IsUninitializedField::encode(false)) { | 1913 bit_field_( |
| 1914 IsUninitializedField::encode(false) | |
| 1915 HasSpreadArgumentsField::encode(false)) { |
1902 if (expression->IsProperty()) { | 1916 if (expression->IsProperty()) { |
1903 expression->AsProperty()->mark_for_call(); | 1917 expression->AsProperty()->mark_for_call(); |
1904 } | 1918 } |
1905 } | 1919 } |
1906 static int parent_num_ids() { return Expression::num_ids(); } | 1920 static int parent_num_ids() { return Expression::num_ids(); } |
1907 | 1921 |
1908 private: | 1922 private: |
1909 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1923 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
1910 | 1924 |
1911 // We store this as an integer because we don't know if we have a slot or | 1925 // We store this as an integer because we don't know if we have a slot or |
1912 // an ic slot until scoping time. | 1926 // an ic slot until scoping time. |
1913 int ic_slot_or_slot_; | 1927 int ic_slot_or_slot_; |
1914 Expression* expression_; | 1928 Expression* expression_; |
1915 ZoneList<Expression*>* arguments_; | 1929 ZoneList<Expression*>* arguments_; |
1916 Handle<JSFunction> target_; | 1930 Handle<JSFunction> target_; |
1917 Handle<Cell> cell_; | 1931 Handle<Cell> cell_; |
1918 Handle<AllocationSite> allocation_site_; | 1932 Handle<AllocationSite> allocation_site_; |
1919 class IsUninitializedField : public BitField8<bool, 0, 1> {}; | 1933 class IsUninitializedField : public BitField8<bool, 0, 1> {}; |
| 1934 class HasSpreadArgumentsField : public BitField8<bool, 1, 1> {}; |
1920 uint8_t bit_field_; | 1935 uint8_t bit_field_; |
1921 }; | 1936 }; |
1922 | 1937 |
1923 | 1938 |
1924 class CallNew FINAL : public Expression { | 1939 class CallNew FINAL : public Expression { |
1925 public: | 1940 public: |
1926 DECLARE_NODE_TYPE(CallNew) | 1941 DECLARE_NODE_TYPE(CallNew) |
1927 | 1942 |
1928 Expression* expression() const { return expression_; } | 1943 Expression* expression() const { return expression_; } |
1929 ZoneList<Expression*>* arguments() const { return arguments_; } | 1944 ZoneList<Expression*>* arguments() const { return arguments_; } |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 2251 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
2237 | 2252 |
2238 Token::Value op_; | 2253 Token::Value op_; |
2239 Expression* left_; | 2254 Expression* left_; |
2240 Expression* right_; | 2255 Expression* right_; |
2241 | 2256 |
2242 Type* combined_type_; | 2257 Type* combined_type_; |
2243 }; | 2258 }; |
2244 | 2259 |
2245 | 2260 |
| 2261 class SpreadOperation FINAL : public Expression { |
| 2262 public: |
| 2263 DECLARE_NODE_TYPE(SpreadOperation) |
| 2264 |
| 2265 Expression* expression() const { return expression_; } |
| 2266 Expression* assign_iterator() const { return assign_iterator_; } |
| 2267 Expression* next_result() const { return next_result_; } |
| 2268 Expression* result_done() const { return result_done_; } |
| 2269 Expression* result_value() const { return result_value_; } |
| 2270 |
| 2271 static int num_ids() { return parent_num_ids(); } |
| 2272 |
| 2273 protected: |
| 2274 SpreadOperation(Zone* zone, AstNodeFactory* factory, |
| 2275 AstValueFactory* value_factory, Scope* scope, |
| 2276 Expression* expression, int pos); |
| 2277 static int parent_num_ids() { return Expression::num_ids(); } |
| 2278 |
| 2279 private: |
| 2280 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2281 |
| 2282 Expression* expression_; |
| 2283 Expression* assign_iterator_; |
| 2284 Expression* next_result_; |
| 2285 Expression* result_done_; |
| 2286 Expression* result_value_; |
| 2287 }; |
| 2288 |
| 2289 |
2246 class Conditional FINAL : public Expression { | 2290 class Conditional FINAL : public Expression { |
2247 public: | 2291 public: |
2248 DECLARE_NODE_TYPE(Conditional) | 2292 DECLARE_NODE_TYPE(Conditional) |
2249 | 2293 |
2250 Expression* condition() const { return condition_; } | 2294 Expression* condition() const { return condition_; } |
2251 Expression* then_expression() const { return then_expression_; } | 2295 Expression* then_expression() const { return then_expression_; } |
2252 Expression* else_expression() const { return else_expression_; } | 2296 Expression* else_expression() const { return else_expression_; } |
2253 | 2297 |
2254 static int num_ids() { return parent_num_ids() + 2; } | 2298 static int num_ids() { return parent_num_ids() + 2; } |
2255 BailoutId ThenId() const { return BailoutId(local_id(0)); } | 2299 BailoutId ThenId() const { return BailoutId(local_id(0)); } |
(...skipping 1200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3456 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); | 3500 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); |
3457 } | 3501 } |
3458 | 3502 |
3459 CompareOperation* NewCompareOperation(Token::Value op, | 3503 CompareOperation* NewCompareOperation(Token::Value op, |
3460 Expression* left, | 3504 Expression* left, |
3461 Expression* right, | 3505 Expression* right, |
3462 int pos) { | 3506 int pos) { |
3463 return new (zone_) CompareOperation(zone_, op, left, right, pos); | 3507 return new (zone_) CompareOperation(zone_, op, left, right, pos); |
3464 } | 3508 } |
3465 | 3509 |
| 3510 SpreadOperation* NewSpreadOperation(Scope* scope, Expression* expression, |
| 3511 int pos) { |
| 3512 return new (zone_) SpreadOperation(zone_, this, ast_value_factory_, scope, |
| 3513 expression, pos); |
| 3514 } |
| 3515 |
3466 Conditional* NewConditional(Expression* condition, | 3516 Conditional* NewConditional(Expression* condition, |
3467 Expression* then_expression, | 3517 Expression* then_expression, |
3468 Expression* else_expression, | 3518 Expression* else_expression, |
3469 int position) { | 3519 int position) { |
3470 return new (zone_) Conditional(zone_, condition, then_expression, | 3520 return new (zone_) Conditional(zone_, condition, then_expression, |
3471 else_expression, position); | 3521 else_expression, position); |
3472 } | 3522 } |
3473 | 3523 |
3474 Assignment* NewAssignment(Token::Value op, | 3524 Assignment* NewAssignment(Token::Value op, |
3475 Expression* target, | 3525 Expression* target, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3531 } | 3581 } |
3532 | 3582 |
3533 ThisFunction* NewThisFunction(int pos) { | 3583 ThisFunction* NewThisFunction(int pos) { |
3534 return new (zone_) ThisFunction(zone_, pos); | 3584 return new (zone_) ThisFunction(zone_, pos); |
3535 } | 3585 } |
3536 | 3586 |
3537 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { | 3587 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { |
3538 return new (zone_) SuperReference(zone_, this_var, pos); | 3588 return new (zone_) SuperReference(zone_, this_var, pos); |
3539 } | 3589 } |
3540 | 3590 |
| 3591 // Utilities |
| 3592 Expression* GetIterator(Expression* iterable) { |
| 3593 Expression* iterator_symbol_literal = |
| 3594 NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); |
| 3595 int pos = iterable->position(); |
| 3596 Expression* prop = NewProperty(iterable, iterator_symbol_literal, pos); |
| 3597 ZoneList<Expression*>* args = new (zone_) ZoneList<Expression*>(0, zone_); |
| 3598 return NewCall(prop, args, pos); |
| 3599 } |
| 3600 |
3541 private: | 3601 private: |
3542 Zone* zone_; | 3602 Zone* zone_; |
3543 AstValueFactory* ast_value_factory_; | 3603 AstValueFactory* ast_value_factory_; |
3544 }; | 3604 }; |
3545 | 3605 |
3546 | 3606 |
3547 } } // namespace v8::internal | 3607 } } // namespace v8::internal |
3548 | 3608 |
3549 #endif // V8_AST_H_ | 3609 #endif // V8_AST_H_ |
OLD | NEW |