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 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 3006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3017 private: | 3017 private: |
3018 Parser::FunctionState* function_state_; | 3018 Parser::FunctionState* function_state_; |
3019 bool old_value_; | 3019 bool old_value_; |
3020 }; | 3020 }; |
3021 | 3021 |
3022 // Collects all return expressions at tail call position in this scope | 3022 // Collects all return expressions at tail call position in this scope |
3023 // to a separate list. | 3023 // to a separate list. |
3024 class Parser::CollectExpressionsInTailPositionToListScope { | 3024 class Parser::CollectExpressionsInTailPositionToListScope { |
3025 public: | 3025 public: |
3026 CollectExpressionsInTailPositionToListScope( | 3026 CollectExpressionsInTailPositionToListScope( |
3027 Parser::FunctionState* function_state, List<Expression*>* list) | 3027 Parser::FunctionState* function_state, ZoneList<Expression*>* list) |
3028 : function_state_(function_state), list_(list) { | 3028 : function_state_(function_state), list_(list) { |
3029 function_state->expressions_in_tail_position().Swap(list_); | 3029 function_state->expressions_in_tail_position().Swap(list_); |
3030 } | 3030 } |
3031 ~CollectExpressionsInTailPositionToListScope() { | 3031 ~CollectExpressionsInTailPositionToListScope() { |
3032 function_state_->expressions_in_tail_position().Swap(list_); | 3032 function_state_->expressions_in_tail_position().Swap(list_); |
3033 } | 3033 } |
3034 | 3034 |
3035 private: | 3035 private: |
3036 Parser::FunctionState* function_state_; | 3036 Parser::FunctionState* function_state_; |
3037 List<Expression*>* list_; | 3037 ZoneList<Expression*>* list_; |
3038 }; | 3038 }; |
3039 | 3039 |
3040 TryStatement* Parser::ParseTryStatement(bool* ok) { | 3040 TryStatement* Parser::ParseTryStatement(bool* ok) { |
3041 // TryStatement :: | 3041 // TryStatement :: |
3042 // 'try' Block Catch | 3042 // 'try' Block Catch |
3043 // 'try' Block Finally | 3043 // 'try' Block Finally |
3044 // 'try' Block Catch Finally | 3044 // 'try' Block Catch Finally |
3045 // | 3045 // |
3046 // Catch :: | 3046 // Catch :: |
3047 // 'catch' '(' Identifier ')' Block | 3047 // 'catch' '(' Identifier ')' Block |
(...skipping 13 matching lines...) Expand all Loading... |
3061 Token::Value tok = peek(); | 3061 Token::Value tok = peek(); |
3062 if (tok != Token::CATCH && tok != Token::FINALLY) { | 3062 if (tok != Token::CATCH && tok != Token::FINALLY) { |
3063 ReportMessage(MessageTemplate::kNoCatchOrFinally); | 3063 ReportMessage(MessageTemplate::kNoCatchOrFinally); |
3064 *ok = false; | 3064 *ok = false; |
3065 return NULL; | 3065 return NULL; |
3066 } | 3066 } |
3067 | 3067 |
3068 Scope* catch_scope = NULL; | 3068 Scope* catch_scope = NULL; |
3069 Variable* catch_variable = NULL; | 3069 Variable* catch_variable = NULL; |
3070 Block* catch_block = NULL; | 3070 Block* catch_block = NULL; |
3071 List<Expression*> expressions_in_tail_position_in_catch_block; | 3071 ZoneList<Expression*> expressions_in_tail_position_in_catch_block(0, zone()); |
3072 if (tok == Token::CATCH) { | 3072 if (tok == Token::CATCH) { |
3073 Consume(Token::CATCH); | 3073 Consume(Token::CATCH); |
3074 | 3074 |
3075 Expect(Token::LPAREN, CHECK_OK); | 3075 Expect(Token::LPAREN, CHECK_OK); |
3076 catch_scope = NewScope(scope_, CATCH_SCOPE); | 3076 catch_scope = NewScope(scope_, CATCH_SCOPE); |
3077 catch_scope->set_start_position(scanner()->location().beg_pos); | 3077 catch_scope->set_start_position(scanner()->location().beg_pos); |
3078 | 3078 |
3079 ExpressionClassifier pattern_classifier(this); | 3079 ExpressionClassifier pattern_classifier(this); |
3080 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); | 3080 Expression* pattern = ParsePrimaryExpression(&pattern_classifier, CHECK_OK); |
3081 ValidateBindingPattern(&pattern_classifier, CHECK_OK); | 3081 ValidateBindingPattern(&pattern_classifier, CHECK_OK); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3167 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); | 3167 try_block = factory()->NewBlock(NULL, 1, false, RelocInfo::kNoPosition); |
3168 try_block->statements()->Add(statement, zone()); | 3168 try_block->statements()->Add(statement, zone()); |
3169 catch_block = NULL; // Clear to indicate it's been handled. | 3169 catch_block = NULL; // Clear to indicate it's been handled. |
3170 } | 3170 } |
3171 | 3171 |
3172 TryStatement* result = NULL; | 3172 TryStatement* result = NULL; |
3173 if (catch_block != NULL) { | 3173 if (catch_block != NULL) { |
3174 // For a try-catch construct append return expressions from the catch block | 3174 // For a try-catch construct append return expressions from the catch block |
3175 // to the list of return expressions. | 3175 // to the list of return expressions. |
3176 function_state_->expressions_in_tail_position().AddAll( | 3176 function_state_->expressions_in_tail_position().AddAll( |
3177 expressions_in_tail_position_in_catch_block); | 3177 expressions_in_tail_position_in_catch_block, zone()); |
3178 | 3178 |
3179 DCHECK(finally_block == NULL); | 3179 DCHECK(finally_block == NULL); |
3180 DCHECK(catch_scope != NULL && catch_variable != NULL); | 3180 DCHECK(catch_scope != NULL && catch_variable != NULL); |
3181 result = factory()->NewTryCatchStatement(try_block, catch_scope, | 3181 result = factory()->NewTryCatchStatement(try_block, catch_scope, |
3182 catch_variable, catch_block, pos); | 3182 catch_variable, catch_block, pos); |
3183 } else { | 3183 } else { |
3184 DCHECK(finally_block != NULL); | 3184 DCHECK(finally_block != NULL); |
3185 result = factory()->NewTryFinallyStatement(try_block, finally_block, pos); | 3185 result = factory()->NewTryFinallyStatement(try_block, finally_block, pos); |
3186 } | 3186 } |
3187 | 3187 |
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4794 result->Set(kFunctionNameAssignmentIndex, | 4794 result->Set(kFunctionNameAssignmentIndex, |
4795 factory()->NewExpressionStatement( | 4795 factory()->NewExpressionStatement( |
4796 factory()->NewAssignment(Token::INIT, fproxy, | 4796 factory()->NewAssignment(Token::INIT, fproxy, |
4797 factory()->NewThisFunction(pos), | 4797 factory()->NewThisFunction(pos), |
4798 RelocInfo::kNoPosition), | 4798 RelocInfo::kNoPosition), |
4799 RelocInfo::kNoPosition)); | 4799 RelocInfo::kNoPosition)); |
4800 } | 4800 } |
4801 | 4801 |
4802 // ES6 14.6.1 Static Semantics: IsInTailPosition | 4802 // ES6 14.6.1 Static Semantics: IsInTailPosition |
4803 // Mark collected return expressions that are in tail call position. | 4803 // Mark collected return expressions that are in tail call position. |
4804 const List<Expression*>& expressions_in_tail_position = | 4804 const ZoneList<Expression*>& expressions_in_tail_position = |
4805 function_state_->expressions_in_tail_position(); | 4805 function_state_->expressions_in_tail_position(); |
4806 for (int i = 0; i < expressions_in_tail_position.length(); ++i) { | 4806 for (int i = 0; i < expressions_in_tail_position.length(); ++i) { |
4807 expressions_in_tail_position[i]->MarkTail(); | 4807 expressions_in_tail_position[i]->MarkTail(); |
4808 } | 4808 } |
4809 return result; | 4809 return result; |
4810 } | 4810 } |
4811 | 4811 |
4812 | 4812 |
4813 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( | 4813 PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser( |
4814 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) { | 4814 SingletonLogger* logger, Scanner::BookmarkScope* bookmark) { |
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5534 parser_->RewriteDestructuringAssignments(); | 5534 parser_->RewriteDestructuringAssignments(); |
5535 } | 5535 } |
5536 | 5536 |
5537 | 5537 |
5538 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, | 5538 void ParserTraits::RewriteNonPattern(Type::ExpressionClassifier* classifier, |
5539 bool* ok) { | 5539 bool* ok) { |
5540 parser_->RewriteNonPattern(classifier, ok); | 5540 parser_->RewriteNonPattern(classifier, ok); |
5541 } | 5541 } |
5542 | 5542 |
5543 | 5543 |
| 5544 ZoneList<typename ParserTraits::Type::ExpressionClassifier::Error>* |
| 5545 ParserTraits::GetReportedErrorList() const { |
| 5546 return parser_->function_state_->GetReportedErrorList(); |
| 5547 } |
| 5548 |
| 5549 |
5544 Zone* ParserTraits::zone() const { | 5550 Zone* ParserTraits::zone() const { |
5545 return parser_->function_state_->scope()->zone(); | 5551 return parser_->function_state_->scope()->zone(); |
5546 } | 5552 } |
5547 | 5553 |
5548 | 5554 |
5549 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { | 5555 ZoneList<Expression*>* ParserTraits::GetNonPatternList() const { |
5550 return parser_->function_state_->non_patterns_to_rewrite(); | 5556 return parser_->function_state_->non_patterns_to_rewrite(); |
5551 } | 5557 } |
5552 | 5558 |
5553 | 5559 |
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6379 | 6385 |
6380 statements->Add(get_return, zone); | 6386 statements->Add(get_return, zone); |
6381 statements->Add(check_return, zone); | 6387 statements->Add(check_return, zone); |
6382 statements->Add(call_return, zone); | 6388 statements->Add(call_return, zone); |
6383 statements->Add(validate_output, zone); | 6389 statements->Add(validate_output, zone); |
6384 } | 6390 } |
6385 | 6391 |
6386 | 6392 |
6387 } // namespace internal | 6393 } // namespace internal |
6388 } // namespace v8 | 6394 } // namespace v8 |
OLD | NEW |