| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/parser.h" | 5 #include "vm/parser.h" |
| 6 | 6 |
| 7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
| 10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 Symbols::ExprTemp(), | 145 Symbols::ExprTemp(), |
| 146 Type::ZoneHandle(Type::DynamicType())); | 146 Type::ZoneHandle(Type::DynamicType())); |
| 147 ASSERT(temp != NULL); | 147 ASSERT(temp != NULL); |
| 148 set_expression_temp_var(temp); | 148 set_expression_temp_var(temp); |
| 149 } | 149 } |
| 150 ASSERT(has_expression_temp_var()); | 150 ASSERT(has_expression_temp_var()); |
| 151 return expression_temp_var(); | 151 return expression_temp_var(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 void ParsedFunction::EnsureFinallyReturnTemp() { | 155 void ParsedFunction::EnsureFinallyReturnTemp(bool is_async) { |
| 156 if (!has_finally_return_temp_var()) { | 156 if (!has_finally_return_temp_var()) { |
| 157 LocalVariable* temp = new(Z) LocalVariable( | 157 LocalVariable* temp = new(Z) LocalVariable( |
| 158 function_.token_pos(), | 158 function_.token_pos(), |
| 159 String::ZoneHandle(Z, Symbols::New(":finally_ret_val")), | 159 String::ZoneHandle(Z, Symbols::New(":finally_ret_val")), |
| 160 Type::ZoneHandle(Z, Type::DynamicType())); | 160 Type::ZoneHandle(Z, Type::DynamicType())); |
| 161 ASSERT(temp != NULL); | 161 ASSERT(temp != NULL); |
| 162 temp->set_is_final(); | 162 temp->set_is_final(); |
| 163 if (is_async) { |
| 164 temp->set_is_captured(); |
| 165 } |
| 163 set_finally_return_temp_var(temp); | 166 set_finally_return_temp_var(temp); |
| 164 } | 167 } |
| 165 ASSERT(has_finally_return_temp_var()); | 168 ASSERT(has_finally_return_temp_var()); |
| 166 } | 169 } |
| 167 | 170 |
| 168 | 171 |
| 169 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { | 172 void ParsedFunction::SetNodeSequence(SequenceNode* node_sequence) { |
| 170 ASSERT(node_sequence_ == NULL); | 173 ASSERT(node_sequence_ == NULL); |
| 171 ASSERT(node_sequence != NULL); | 174 ASSERT(node_sequence != NULL); |
| 172 node_sequence_ = node_sequence; | 175 node_sequence_ = node_sequence; |
| (...skipping 5921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6094 finally_clause = CloseBlock(); | 6097 finally_clause = CloseBlock(); |
| 6095 AstNode* node_to_inline = try_block->GetNodeToInlineFinally(node_index); | 6098 AstNode* node_to_inline = try_block->GetNodeToInlineFinally(node_index); |
| 6096 if (node_to_inline != NULL) { | 6099 if (node_to_inline != NULL) { |
| 6097 InlinedFinallyNode* node = | 6100 InlinedFinallyNode* node = |
| 6098 new(Z) InlinedFinallyNode(try_end_pos, | 6101 new(Z) InlinedFinallyNode(try_end_pos, |
| 6099 finally_clause, | 6102 finally_clause, |
| 6100 context_var, | 6103 context_var, |
| 6101 // No outer try statement | 6104 // No outer try statement |
| 6102 CatchClauseNode::kInvalidTryIndex); | 6105 CatchClauseNode::kInvalidTryIndex); |
| 6103 finally_clause = NULL; | 6106 finally_clause = NULL; |
| 6104 AddFinallyBlockToNode(node_to_inline, node); | 6107 AddFinallyBlockToNode(true, node_to_inline, node); |
| 6105 node_index++; | 6108 node_index++; |
| 6106 } | 6109 } |
| 6107 } while (finally_clause == NULL); | 6110 } while (finally_clause == NULL); |
| 6108 | 6111 |
| 6109 const GrowableObjectArray& handler_types = | 6112 const GrowableObjectArray& handler_types = |
| 6110 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); | 6113 GrowableObjectArray::Handle(Z, GrowableObjectArray::New()); |
| 6111 handler_types.Add(dynamic_type); // Catch block handles all exceptions. | 6114 handler_types.Add(dynamic_type); // Catch block handles all exceptions. |
| 6112 | 6115 |
| 6113 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( | 6116 CatchClauseNode* catch_clause = new(Z) CatchClauseNode( |
| 6114 Scanner::kNoSourcePos, | 6117 Scanner::kNoSourcePos, |
| (...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8762 break; | 8765 break; |
| 8763 } | 8766 } |
| 8764 } | 8767 } |
| 8765 iterator->AddNodeForFinallyInlining(node); | 8768 iterator->AddNodeForFinallyInlining(node); |
| 8766 iterator = iterator->outer_try_block(); | 8769 iterator = iterator->outer_try_block(); |
| 8767 } | 8770 } |
| 8768 } | 8771 } |
| 8769 | 8772 |
| 8770 | 8773 |
| 8771 // Add the inlined finally block to the specified node. | 8774 // Add the inlined finally block to the specified node. |
| 8772 void Parser::AddFinallyBlockToNode(AstNode* node, | 8775 void Parser::AddFinallyBlockToNode(bool is_async, |
| 8776 AstNode* node, |
| 8773 InlinedFinallyNode* finally_node) { | 8777 InlinedFinallyNode* finally_node) { |
| 8774 ReturnNode* return_node = node->AsReturnNode(); | 8778 ReturnNode* return_node = node->AsReturnNode(); |
| 8775 if (return_node != NULL) { | 8779 if (return_node != NULL) { |
| 8776 parsed_function()->EnsureFinallyReturnTemp(); | 8780 parsed_function()->EnsureFinallyReturnTemp(is_async); |
| 8777 return_node->AddInlinedFinallyNode(finally_node); | 8781 return_node->AddInlinedFinallyNode(finally_node); |
| 8778 return; | 8782 return; |
| 8779 } | 8783 } |
| 8780 JumpNode* jump_node = node->AsJumpNode(); | 8784 JumpNode* jump_node = node->AsJumpNode(); |
| 8781 ASSERT(jump_node != NULL); | 8785 ASSERT(jump_node != NULL); |
| 8782 jump_node->AddInlinedFinallyNode(finally_node); | 8786 jump_node->AddInlinedFinallyNode(finally_node); |
| 8783 } | 8787 } |
| 8784 | 8788 |
| 8785 | 8789 |
| 8786 SequenceNode* Parser::ParseCatchClauses( | 8790 SequenceNode* Parser::ParseCatchClauses( |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9170 finally_block = ParseFinallyBlock( | 9174 finally_block = ParseFinallyBlock( |
| 9171 is_async, | 9175 is_async, |
| 9172 exception_var, | 9176 exception_var, |
| 9173 stack_trace_var, | 9177 stack_trace_var, |
| 9174 is_async ? saved_exception_var : exception_var, | 9178 is_async ? saved_exception_var : exception_var, |
| 9175 is_async ? saved_stack_trace_var : stack_trace_var); | 9179 is_async ? saved_stack_trace_var : stack_trace_var); |
| 9176 InlinedFinallyNode* node = new(Z) InlinedFinallyNode(finally_pos, | 9180 InlinedFinallyNode* node = new(Z) InlinedFinallyNode(finally_pos, |
| 9177 finally_block, | 9181 finally_block, |
| 9178 context_var, | 9182 context_var, |
| 9179 outer_try_index); | 9183 outer_try_index); |
| 9180 AddFinallyBlockToNode(node_to_inline, node); | 9184 AddFinallyBlockToNode(is_async, node_to_inline, node); |
| 9181 node_index += 1; | 9185 node_index += 1; |
| 9182 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index); | 9186 node_to_inline = inner_try_block->GetNodeToInlineFinally(node_index); |
| 9183 tokens_iterator_.SetCurrentPosition(finally_pos); | 9187 tokens_iterator_.SetCurrentPosition(finally_pos); |
| 9184 } | 9188 } |
| 9185 finally_block = ParseFinallyBlock( | 9189 finally_block = ParseFinallyBlock( |
| 9186 is_async, | 9190 is_async, |
| 9187 exception_var, | 9191 exception_var, |
| 9188 stack_trace_var, | 9192 stack_trace_var, |
| 9189 is_async ? saved_exception_var : exception_var, | 9193 is_async ? saved_exception_var : exception_var, |
| 9190 is_async ? saved_stack_trace_var : stack_trace_var); | 9194 is_async ? saved_stack_trace_var : stack_trace_var); |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9533 // instead of :exception_var and :stack_trace_var. | 9537 // instead of :exception_var and :stack_trace_var. |
| 9534 // These variables are bound in the block containing the try. | 9538 // These variables are bound in the block containing the try. |
| 9535 // Look in the try scope directly. | 9539 // Look in the try scope directly. |
| 9536 LocalScope* scope = try_blocks_list_->try_block()->scope->parent(); | 9540 LocalScope* scope = try_blocks_list_->try_block()->scope->parent(); |
| 9537 ASSERT(scope != NULL); | 9541 ASSERT(scope != NULL); |
| 9538 LocalVariable* excp_var; | 9542 LocalVariable* excp_var; |
| 9539 LocalVariable* trace_var; | 9543 LocalVariable* trace_var; |
| 9540 if (innermost_function().IsAsyncClosure() || | 9544 if (innermost_function().IsAsyncClosure() || |
| 9541 innermost_function().IsAsyncFunction() || | 9545 innermost_function().IsAsyncFunction() || |
| 9542 innermost_function().IsSyncGenClosure() || | 9546 innermost_function().IsSyncGenClosure() || |
| 9543 innermost_function().IsSyncGenerator()) { | 9547 innermost_function().IsSyncGenerator() || |
| 9548 innermost_function().IsAsyncGenClosure() || |
| 9549 innermost_function().IsAsyncGenerator()) { |
| 9544 excp_var = scope->LocalLookupVariable(Symbols::SavedExceptionVar()); | 9550 excp_var = scope->LocalLookupVariable(Symbols::SavedExceptionVar()); |
| 9545 trace_var = scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); | 9551 trace_var = scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); |
| 9546 } else { | 9552 } else { |
| 9547 excp_var = scope->LocalLookupVariable(Symbols::ExceptionVar()); | 9553 excp_var = scope->LocalLookupVariable(Symbols::ExceptionVar()); |
| 9548 trace_var = scope->LocalLookupVariable(Symbols::StackTraceVar()); | 9554 trace_var = scope->LocalLookupVariable(Symbols::StackTraceVar()); |
| 9549 } | 9555 } |
| 9550 ASSERT(excp_var != NULL); | 9556 ASSERT(excp_var != NULL); |
| 9551 ASSERT(trace_var != NULL); | 9557 ASSERT(trace_var != NULL); |
| 9552 | 9558 |
| 9553 statement = new(Z) ThrowNode( | 9559 statement = new(Z) ThrowNode( |
| (...skipping 3636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13190 void Parser::SkipQualIdent() { | 13196 void Parser::SkipQualIdent() { |
| 13191 ASSERT(IsIdentifier()); | 13197 ASSERT(IsIdentifier()); |
| 13192 ConsumeToken(); | 13198 ConsumeToken(); |
| 13193 if (CurrentToken() == Token::kPERIOD) { | 13199 if (CurrentToken() == Token::kPERIOD) { |
| 13194 ConsumeToken(); // Consume the kPERIOD token. | 13200 ConsumeToken(); // Consume the kPERIOD token. |
| 13195 ExpectIdentifier("identifier expected after '.'"); | 13201 ExpectIdentifier("identifier expected after '.'"); |
| 13196 } | 13202 } |
| 13197 } | 13203 } |
| 13198 | 13204 |
| 13199 } // namespace dart | 13205 } // namespace dart |
| OLD | NEW |