Chromium Code Reviews| 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 static bool HasSpreadArguments(ZoneList<Expression*>* arguments) { | |
| 1899 ZoneList<Expression*>::iterator it; | |
| 1900 for (it = arguments->begin(); it != arguments->end(); ++it) { | |
| 1901 if ((*it)->IsSpreadOperation()) { | |
| 1902 return true; | |
| 1903 } | |
| 1904 } | |
| 1905 return false; | |
| 1906 } | |
| 1907 | |
| 1908 inline bool HasSpreadArguments() const { | |
| 1909 return HasSpreadArgumentsField::decode(bit_field_); | |
| 1910 } | |
| 1911 | |
| 1894 protected: | 1912 protected: |
| 1895 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, | 1913 Call(Zone* zone, Expression* expression, ZoneList<Expression*>* arguments, |
| 1896 int pos) | 1914 int pos) |
| 1897 : Expression(zone, pos), | 1915 : Expression(zone, pos), |
| 1898 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()), | 1916 ic_slot_or_slot_(FeedbackVectorICSlot::Invalid().ToInt()), |
| 1899 expression_(expression), | 1917 expression_(expression), |
| 1900 arguments_(arguments), | 1918 arguments_(arguments), |
| 1901 bit_field_(IsUninitializedField::encode(false)) { | 1919 bit_field_( |
| 1920 IsUninitializedField::encode(false) | | |
| 1921 HasSpreadArgumentsField::encode(HasSpreadArguments(arguments))) { | |
|
arv (Not doing code reviews)
2015/02/12 21:41:34
Maybe have the parser keep track of this and set t
| |
| 1902 if (expression->IsProperty()) { | 1922 if (expression->IsProperty()) { |
| 1903 expression->AsProperty()->mark_for_call(); | 1923 expression->AsProperty()->mark_for_call(); |
| 1904 } | 1924 } |
| 1905 } | 1925 } |
| 1906 static int parent_num_ids() { return Expression::num_ids(); } | 1926 static int parent_num_ids() { return Expression::num_ids(); } |
| 1907 | 1927 |
| 1908 private: | 1928 private: |
| 1909 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | 1929 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 1910 | 1930 |
| 1911 // We store this as an integer because we don't know if we have a slot or | 1931 // We store this as an integer because we don't know if we have a slot or |
| 1912 // an ic slot until scoping time. | 1932 // an ic slot until scoping time. |
| 1913 int ic_slot_or_slot_; | 1933 int ic_slot_or_slot_; |
| 1914 Expression* expression_; | 1934 Expression* expression_; |
| 1915 ZoneList<Expression*>* arguments_; | 1935 ZoneList<Expression*>* arguments_; |
| 1916 Handle<JSFunction> target_; | 1936 Handle<JSFunction> target_; |
| 1917 Handle<Cell> cell_; | 1937 Handle<Cell> cell_; |
| 1918 Handle<AllocationSite> allocation_site_; | 1938 Handle<AllocationSite> allocation_site_; |
| 1919 class IsUninitializedField : public BitField8<bool, 0, 1> {}; | 1939 class IsUninitializedField : public BitField8<bool, 0, 1> {}; |
| 1940 class HasSpreadArgumentsField : public BitField8<bool, 1, 1> {}; | |
| 1920 uint8_t bit_field_; | 1941 uint8_t bit_field_; |
| 1921 }; | 1942 }; |
| 1922 | 1943 |
| 1923 | 1944 |
| 1924 class CallNew FINAL : public Expression { | 1945 class CallNew FINAL : public Expression { |
| 1925 public: | 1946 public: |
| 1926 DECLARE_NODE_TYPE(CallNew) | 1947 DECLARE_NODE_TYPE(CallNew) |
| 1927 | 1948 |
| 1928 Expression* expression() const { return expression_; } | 1949 Expression* expression() const { return expression_; } |
| 1929 ZoneList<Expression*>* arguments() const { return arguments_; } | 1950 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; } | 2257 int local_id(int n) const { return base_id() + parent_num_ids() + n; } |
| 2237 | 2258 |
| 2238 Token::Value op_; | 2259 Token::Value op_; |
| 2239 Expression* left_; | 2260 Expression* left_; |
| 2240 Expression* right_; | 2261 Expression* right_; |
| 2241 | 2262 |
| 2242 Type* combined_type_; | 2263 Type* combined_type_; |
| 2243 }; | 2264 }; |
| 2244 | 2265 |
| 2245 | 2266 |
| 2267 class SpreadOperation FINAL : public Expression { | |
| 2268 public: | |
| 2269 DECLARE_NODE_TYPE(SpreadOperation) | |
| 2270 | |
| 2271 Expression* expression() const { return expression_; } | |
| 2272 Expression* assign_iterator() const { return assign_iterator_; } | |
| 2273 Expression* next_result() const { return next_result_; } | |
| 2274 Expression* result_done() const { return result_done_; } | |
| 2275 Expression* result_value() const { return result_value_; } | |
| 2276 | |
| 2277 static int num_ids() { return parent_num_ids(); } | |
| 2278 | |
| 2279 protected: | |
| 2280 SpreadOperation(Zone* zone, AstNodeFactory* factory, | |
| 2281 AstValueFactory* value_factory, Scope* scope, | |
| 2282 Expression* expression, int pos); | |
| 2283 static int parent_num_ids() { return Expression::num_ids(); } | |
| 2284 | |
| 2285 private: | |
| 2286 int local_id(int n) const { return base_id() + parent_num_ids() + n; } | |
| 2287 | |
| 2288 Expression* expression_; | |
| 2289 Expression* assign_iterator_; | |
| 2290 Expression* next_result_; | |
| 2291 Expression* result_done_; | |
| 2292 Expression* result_value_; | |
| 2293 }; | |
| 2294 | |
| 2295 | |
| 2246 class Conditional FINAL : public Expression { | 2296 class Conditional FINAL : public Expression { |
| 2247 public: | 2297 public: |
| 2248 DECLARE_NODE_TYPE(Conditional) | 2298 DECLARE_NODE_TYPE(Conditional) |
| 2249 | 2299 |
| 2250 Expression* condition() const { return condition_; } | 2300 Expression* condition() const { return condition_; } |
| 2251 Expression* then_expression() const { return then_expression_; } | 2301 Expression* then_expression() const { return then_expression_; } |
| 2252 Expression* else_expression() const { return else_expression_; } | 2302 Expression* else_expression() const { return else_expression_; } |
| 2253 | 2303 |
| 2254 static int num_ids() { return parent_num_ids() + 2; } | 2304 static int num_ids() { return parent_num_ids() + 2; } |
| 2255 BailoutId ThenId() const { return BailoutId(local_id(0)); } | 2305 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); | 3506 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); |
| 3457 } | 3507 } |
| 3458 | 3508 |
| 3459 CompareOperation* NewCompareOperation(Token::Value op, | 3509 CompareOperation* NewCompareOperation(Token::Value op, |
| 3460 Expression* left, | 3510 Expression* left, |
| 3461 Expression* right, | 3511 Expression* right, |
| 3462 int pos) { | 3512 int pos) { |
| 3463 return new (zone_) CompareOperation(zone_, op, left, right, pos); | 3513 return new (zone_) CompareOperation(zone_, op, left, right, pos); |
| 3464 } | 3514 } |
| 3465 | 3515 |
| 3516 SpreadOperation* NewSpreadOperation(Scope* scope, Expression* expression, | |
| 3517 int pos) { | |
| 3518 return new (zone_) SpreadOperation(zone_, this, ast_value_factory_, scope, | |
| 3519 expression, pos); | |
| 3520 } | |
| 3521 | |
| 3466 Conditional* NewConditional(Expression* condition, | 3522 Conditional* NewConditional(Expression* condition, |
| 3467 Expression* then_expression, | 3523 Expression* then_expression, |
| 3468 Expression* else_expression, | 3524 Expression* else_expression, |
| 3469 int position) { | 3525 int position) { |
| 3470 return new (zone_) Conditional(zone_, condition, then_expression, | 3526 return new (zone_) Conditional(zone_, condition, then_expression, |
| 3471 else_expression, position); | 3527 else_expression, position); |
| 3472 } | 3528 } |
| 3473 | 3529 |
| 3474 Assignment* NewAssignment(Token::Value op, | 3530 Assignment* NewAssignment(Token::Value op, |
| 3475 Expression* target, | 3531 Expression* target, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3531 } | 3587 } |
| 3532 | 3588 |
| 3533 ThisFunction* NewThisFunction(int pos) { | 3589 ThisFunction* NewThisFunction(int pos) { |
| 3534 return new (zone_) ThisFunction(zone_, pos); | 3590 return new (zone_) ThisFunction(zone_, pos); |
| 3535 } | 3591 } |
| 3536 | 3592 |
| 3537 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { | 3593 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { |
| 3538 return new (zone_) SuperReference(zone_, this_var, pos); | 3594 return new (zone_) SuperReference(zone_, this_var, pos); |
| 3539 } | 3595 } |
| 3540 | 3596 |
| 3597 // Utilities | |
| 3598 Expression* GetIterator(Expression* iterable) { | |
| 3599 Expression* iterator_symbol_literal = | |
| 3600 NewSymbolLiteral("iterator_symbol", RelocInfo::kNoPosition); | |
| 3601 int pos = iterable->position(); | |
| 3602 Expression* prop = NewProperty(iterable, iterator_symbol_literal, pos); | |
| 3603 ZoneList<Expression*>* args = new (zone_) ZoneList<Expression*>(0, zone_); | |
| 3604 return NewCall(prop, args, pos); | |
| 3605 } | |
| 3606 | |
| 3541 private: | 3607 private: |
| 3542 Zone* zone_; | 3608 Zone* zone_; |
| 3543 AstValueFactory* ast_value_factory_; | 3609 AstValueFactory* ast_value_factory_; |
| 3544 }; | 3610 }; |
| 3545 | 3611 |
| 3546 | 3612 |
| 3547 } } // namespace v8::internal | 3613 } } // namespace v8::internal |
| 3548 | 3614 |
| 3549 #endif // V8_AST_H_ | 3615 #endif // V8_AST_H_ |
| OLD | NEW |