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 #include "vm/flags.h" | 6 #include "vm/flags.h" |
7 | 7 |
8 #ifndef DART_PRECOMPILED_RUNTIME | 8 #ifndef DART_PRECOMPILED_RUNTIME |
9 | 9 |
10 #include "lib/invocation_mirror.h" | 10 #include "lib/invocation_mirror.h" |
(...skipping 6357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6368 // to load the stack trace object (:stack_trace_var) into the stack | 6368 // to load the stack trace object (:stack_trace_var) into the stack |
6369 // trace variable specified in this block. | 6369 // trace variable specified in this block. |
6370 current_block_->statements->Add(new (Z) StoreLocalNode( | 6370 current_block_->statements->Add(new (Z) StoreLocalNode( |
6371 TokenPosition::kNoSource, stack_trace_param.var, | 6371 TokenPosition::kNoSource, stack_trace_param.var, |
6372 new (Z) LoadLocalNode(TokenPosition::kNoSource, stack_trace_var))); | 6372 new (Z) LoadLocalNode(TokenPosition::kNoSource, stack_trace_var))); |
6373 } | 6373 } |
6374 LocalVariable* saved_exception_var = | 6374 LocalVariable* saved_exception_var = |
6375 try_scope->LocalLookupVariable(Symbols::SavedExceptionVar()); | 6375 try_scope->LocalLookupVariable(Symbols::SavedExceptionVar()); |
6376 LocalVariable* saved_stack_trace_var = | 6376 LocalVariable* saved_stack_trace_var = |
6377 try_scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); | 6377 try_scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); |
6378 SaveExceptionAndStacktrace(current_block_->statements, exception_var, | 6378 SaveExceptionAndStackTrace(current_block_->statements, exception_var, |
6379 stack_trace_var, saved_exception_var, | 6379 stack_trace_var, saved_exception_var, |
6380 saved_stack_trace_var); | 6380 saved_stack_trace_var); |
6381 | 6381 |
6382 // Catch block: add the error to the stream. | 6382 // Catch block: add the error to the stream. |
6383 // :controller.AddError(:exception, :stack_trace); | 6383 // :controller.AddError(:exception, :stack_trace); |
6384 // return; // The finally block will close the stream. | 6384 // return; // The finally block will close the stream. |
6385 LocalVariable* controller = | 6385 LocalVariable* controller = |
6386 current_block_->scope->LookupVariable(Symbols::Controller(), false); | 6386 current_block_->scope->LookupVariable(Symbols::Controller(), false); |
6387 ASSERT(controller != NULL); | 6387 ASSERT(controller != NULL); |
6388 ArgumentListNode* args = new (Z) ArgumentListNode(TokenPosition::kNoSource); | 6388 ArgumentListNode* args = new (Z) ArgumentListNode(TokenPosition::kNoSource); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6516 // trace variable specified in this block. | 6516 // trace variable specified in this block. |
6517 ASSERT(stack_trace_var != NULL); | 6517 ASSERT(stack_trace_var != NULL); |
6518 current_block_->statements->Add(new (Z) StoreLocalNode( | 6518 current_block_->statements->Add(new (Z) StoreLocalNode( |
6519 TokenPosition::kNoSource, stack_trace_param.var, | 6519 TokenPosition::kNoSource, stack_trace_param.var, |
6520 new (Z) LoadLocalNode(TokenPosition::kNoSource, stack_trace_var))); | 6520 new (Z) LoadLocalNode(TokenPosition::kNoSource, stack_trace_var))); |
6521 } | 6521 } |
6522 LocalVariable* saved_exception_var = | 6522 LocalVariable* saved_exception_var = |
6523 try_scope->LocalLookupVariable(Symbols::SavedExceptionVar()); | 6523 try_scope->LocalLookupVariable(Symbols::SavedExceptionVar()); |
6524 LocalVariable* saved_stack_trace_var = | 6524 LocalVariable* saved_stack_trace_var = |
6525 try_scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); | 6525 try_scope->LocalLookupVariable(Symbols::SavedStackTraceVar()); |
6526 SaveExceptionAndStacktrace(current_block_->statements, exception_var, | 6526 SaveExceptionAndStackTrace(current_block_->statements, exception_var, |
6527 stack_trace_var, saved_exception_var, | 6527 stack_trace_var, saved_exception_var, |
6528 saved_stack_trace_var); | 6528 saved_stack_trace_var); |
6529 | 6529 |
6530 // Complete the async future with an error. This catch block executes | 6530 // Complete the async future with an error. This catch block executes |
6531 // unconditionally, there is no need to generate a type check for. | 6531 // unconditionally, there is no need to generate a type check for. |
6532 LocalVariable* async_completer = | 6532 LocalVariable* async_completer = |
6533 current_block_->scope->LookupVariable(Symbols::AsyncCompleter(), false); | 6533 current_block_->scope->LookupVariable(Symbols::AsyncCompleter(), false); |
6534 ASSERT(async_completer != NULL); | 6534 ASSERT(async_completer != NULL); |
6535 ArgumentListNode* completer_args = | 6535 ArgumentListNode* completer_args = |
6536 new (Z) ArgumentListNode(TokenPosition::kNoSource); | 6536 new (Z) ArgumentListNode(TokenPosition::kNoSource); |
(...skipping 2683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9220 } | 9220 } |
9221 stack_trace_param->var = var; | 9221 stack_trace_param->var = var; |
9222 } | 9222 } |
9223 } | 9223 } |
9224 | 9224 |
9225 | 9225 |
9226 // Generate code to load the exception object (:exception_var) into | 9226 // Generate code to load the exception object (:exception_var) into |
9227 // the saved exception variable (:saved_exception_var) used to rethrow. | 9227 // the saved exception variable (:saved_exception_var) used to rethrow. |
9228 // Generate code to load the stack trace object (:stack_trace_var) into | 9228 // Generate code to load the stack trace object (:stack_trace_var) into |
9229 // the saved stacktrace variable (:saved_stack_trace_var) used to rethrow. | 9229 // the saved stacktrace variable (:saved_stack_trace_var) used to rethrow. |
9230 void Parser::SaveExceptionAndStacktrace(SequenceNode* statements, | 9230 void Parser::SaveExceptionAndStackTrace(SequenceNode* statements, |
9231 LocalVariable* exception_var, | 9231 LocalVariable* exception_var, |
9232 LocalVariable* stack_trace_var, | 9232 LocalVariable* stack_trace_var, |
9233 LocalVariable* saved_exception_var, | 9233 LocalVariable* saved_exception_var, |
9234 LocalVariable* saved_stack_trace_var) { | 9234 LocalVariable* saved_stack_trace_var) { |
9235 ASSERT(innermost_function().IsAsyncClosure() || | 9235 ASSERT(innermost_function().IsAsyncClosure() || |
9236 innermost_function().IsAsyncFunction() || | 9236 innermost_function().IsAsyncFunction() || |
9237 innermost_function().IsSyncGenClosure() || | 9237 innermost_function().IsSyncGenClosure() || |
9238 innermost_function().IsSyncGenerator() || | 9238 innermost_function().IsSyncGenerator() || |
9239 innermost_function().IsAsyncGenClosure() || | 9239 innermost_function().IsAsyncGenClosure() || |
9240 innermost_function().IsAsyncGenerator()); | 9240 innermost_function().IsAsyncGenerator()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9293 current_block_->statements->Add(new (Z) StoreLocalNode( | 9293 current_block_->statements->Add(new (Z) StoreLocalNode( |
9294 TokenPosition::kNoSource, saved_try_ctx, | 9294 TokenPosition::kNoSource, saved_try_ctx, |
9295 new (Z) | 9295 new (Z) |
9296 LoadLocalNode(TokenPosition::kNoSource, async_saved_try_ctx))); | 9296 LoadLocalNode(TokenPosition::kNoSource, async_saved_try_ctx))); |
9297 } | 9297 } |
9298 } | 9298 } |
9299 // We need to save the exception variables as in catch clauses, whether | 9299 // We need to save the exception variables as in catch clauses, whether |
9300 // there is an outer try or not. Note that this is only necessary if the | 9300 // there is an outer try or not. Note that this is only necessary if the |
9301 // finally clause contains an await or yield. | 9301 // finally clause contains an await or yield. |
9302 // TODO(hausner): Optimize. | 9302 // TODO(hausner): Optimize. |
9303 SaveExceptionAndStacktrace(current_block_->statements, exception_var, | 9303 SaveExceptionAndStackTrace(current_block_->statements, exception_var, |
9304 stack_trace_var, rethrow_exception_var, | 9304 stack_trace_var, rethrow_exception_var, |
9305 rethrow_stack_trace_var); | 9305 rethrow_stack_trace_var); |
9306 } | 9306 } |
9307 | 9307 |
9308 if (parse) { | 9308 if (parse) { |
9309 ParseStatementSequence(); | 9309 ParseStatementSequence(); |
9310 ExpectToken(Token::kRBRACE); | 9310 ExpectToken(Token::kRBRACE); |
9311 } | 9311 } |
9312 SequenceNode* finally_clause = CloseBlock(); | 9312 SequenceNode* finally_clause = CloseBlock(); |
9313 if (try_stack_ != NULL) { | 9313 if (try_stack_ != NULL) { |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9574 LocalVariable* saved_try_ctx = | 9574 LocalVariable* saved_try_ctx = |
9575 LookupSavedTryContextVar(scope->parent()); | 9575 LookupSavedTryContextVar(scope->parent()); |
9576 LocalVariable* async_saved_try_ctx = LookupAsyncSavedTryContextVar( | 9576 LocalVariable* async_saved_try_ctx = LookupAsyncSavedTryContextVar( |
9577 T, async_temp_scope_, try_block->try_index()); | 9577 T, async_temp_scope_, try_block->try_index()); |
9578 async_code->Add(new (Z) StoreLocalNode( | 9578 async_code->Add(new (Z) StoreLocalNode( |
9579 TokenPosition::kNoSource, saved_try_ctx, | 9579 TokenPosition::kNoSource, saved_try_ctx, |
9580 new (Z) | 9580 new (Z) |
9581 LoadLocalNode(TokenPosition::kNoSource, async_saved_try_ctx))); | 9581 LoadLocalNode(TokenPosition::kNoSource, async_saved_try_ctx))); |
9582 } | 9582 } |
9583 } | 9583 } |
9584 SaveExceptionAndStacktrace(async_code, exception_var, stack_trace_var, | 9584 SaveExceptionAndStackTrace(async_code, exception_var, stack_trace_var, |
9585 rethrow_exception_var, rethrow_stack_trace_var); | 9585 rethrow_exception_var, rethrow_stack_trace_var); |
9586 // The async_code node sequence contains code to restore the context (if | 9586 // The async_code node sequence contains code to restore the context (if |
9587 // an outer try block is present) and code to save the exception and | 9587 // an outer try block is present) and code to save the exception and |
9588 // stack trace variables. | 9588 // stack trace variables. |
9589 // This async code is inserted before the current node sequence containing | 9589 // This async code is inserted before the current node sequence containing |
9590 // the chain of if/then/else handling all catch clauses. | 9590 // the chain of if/then/else handling all catch clauses. |
9591 async_code->Add(current); | 9591 async_code->Add(current); |
9592 current = async_code; | 9592 current = async_code; |
9593 } | 9593 } |
9594 return current; | 9594 return current; |
(...skipping 4889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14484 const ArgumentListNode& function_args, | 14484 const ArgumentListNode& function_args, |
14485 const LocalVariable* temp_for_last_arg, | 14485 const LocalVariable* temp_for_last_arg, |
14486 bool is_super_invocation) { | 14486 bool is_super_invocation) { |
14487 UNREACHABLE(); | 14487 UNREACHABLE(); |
14488 return NULL; | 14488 return NULL; |
14489 } | 14489 } |
14490 | 14490 |
14491 } // namespace dart | 14491 } // namespace dart |
14492 | 14492 |
14493 #endif // DART_PRECOMPILED_RUNTIME | 14493 #endif // DART_PRECOMPILED_RUNTIME |
OLD | NEW |