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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "vm/ast_printer.h" | 8 #include "vm/ast_printer.h" |
9 #include "vm/bit_vector.h" | 9 #include "vm/bit_vector.h" |
10 #include "vm/code_descriptors.h" | 10 #include "vm/code_descriptors.h" |
(...skipping 3280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3291 | 3291 |
3292 // The outermost function sequence cannot contain a label. | 3292 // The outermost function sequence cannot contain a label. |
3293 ASSERT((node->label() == NULL) || | 3293 ASSERT((node->label() == NULL) || |
3294 (node != owner()->parsed_function()->node_sequence())); | 3294 (node != owner()->parsed_function()->node_sequence())); |
3295 owner()->set_context_level(previous_context_level); | 3295 owner()->set_context_level(previous_context_level); |
3296 } | 3296 } |
3297 | 3297 |
3298 | 3298 |
3299 void EffectGraphVisitor::VisitCatchClauseNode(CatchClauseNode* node) { | 3299 void EffectGraphVisitor::VisitCatchClauseNode(CatchClauseNode* node) { |
3300 InlineBailout("EffectGraphVisitor::VisitCatchClauseNode (exception)"); | 3300 InlineBailout("EffectGraphVisitor::VisitCatchClauseNode (exception)"); |
3301 // NOTE: The implicit variables ':saved_context', ':exception_var' | |
3302 // and ':stacktrace_var' can never be captured variables. | |
3303 // Restores CTX from local variable ':saved_context'. | 3301 // Restores CTX from local variable ':saved_context'. |
3304 AddInstruction( | |
3305 new CatchEntryInstr(node->exception_var(), node->stacktrace_var())); | |
3306 BuildRestoreContext(node->context_var()); | 3302 BuildRestoreContext(node->context_var()); |
3307 | 3303 |
3308 EffectGraphVisitor for_catch(owner(), temp_index()); | 3304 EffectGraphVisitor for_catch(owner(), temp_index()); |
3309 node->VisitChildren(&for_catch); | 3305 node->VisitChildren(&for_catch); |
3310 Append(for_catch); | 3306 Append(for_catch); |
3311 } | 3307 } |
3312 | 3308 |
3313 | 3309 |
3314 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { | 3310 void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) { |
3315 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)"); | 3311 InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)"); |
(...skipping 20 matching lines...) Expand all Loading... | |
3336 | 3332 |
3337 Goto(try_entry); | 3333 Goto(try_entry); |
3338 AppendFragment(try_entry, for_try); | 3334 AppendFragment(try_entry, for_try); |
3339 exit_ = for_try.exit_; | 3335 exit_ = for_try.exit_; |
3340 | 3336 |
3341 // We are done generating code for the try block. | 3337 // We are done generating code for the try block. |
3342 owner()->set_try_index(original_handler_index); | 3338 owner()->set_try_index(original_handler_index); |
3343 | 3339 |
3344 CatchClauseNode* catch_block = node->catch_block(); | 3340 CatchClauseNode* catch_block = node->catch_block(); |
3345 SequenceNode* finally_block = node->finally_block(); | 3341 SequenceNode* finally_block = node->finally_block(); |
3346 if (catch_block != NULL) { | |
3347 // If there is a finally block, it is the handler for code in the catch | |
3348 // block. | |
3349 intptr_t catch_handler_index = (finally_block == NULL) | |
3350 ? original_handler_index | |
3351 : catch_block->catch_handler_index(); | |
3352 | 3342 |
3353 owner()->set_try_index(catch_handler_index); | 3343 // If there is a finally block, it is the handler for code in the catch |
3354 EffectGraphVisitor for_catch(owner(), temp_index()); | 3344 // block. |
3355 catch_block->Visit(&for_catch); | 3345 intptr_t catch_handler_index = (finally_block == NULL) |
srdjan
2013/08/07 18:46:17
const
Florian Schneider
2013/08/08 07:39:57
Done.
| |
3356 CatchBlockEntryInstr* catch_entry = | 3346 ? original_handler_index |
3357 new CatchBlockEntryInstr(owner()->AllocateBlockId(), | 3347 : catch_block->catch_handler_index(); |
3358 catch_handler_index, | |
3359 catch_block->handler_types(), | |
3360 try_handler_index); | |
3361 owner()->AddCatchEntry(catch_entry); | |
3362 ASSERT(!for_catch.is_open()); | |
3363 AppendFragment(catch_entry, for_catch); | |
3364 if (node->end_catch_label() != NULL) { | |
3365 JoinEntryInstr* join = node->end_catch_label()->join_for_continue(); | |
3366 if (join != NULL) { | |
3367 if (is_open()) Goto(join); | |
3368 exit_ = join; | |
3369 } | |
3370 } | |
3371 | 3348 |
3372 if (finally_block != NULL) { | 3349 owner()->set_try_index(catch_handler_index); |
3373 // Create a handler for the code in the catch block, containing the | 3350 EffectGraphVisitor for_catch(owner(), temp_index()); |
3374 // code in the finally block. | 3351 catch_block->Visit(&for_catch); |
3375 owner()->set_try_index(original_handler_index); | |
3376 EffectGraphVisitor for_finally(owner(), temp_index()); | |
3377 for_finally.AddInstruction( | |
3378 new CatchEntryInstr(catch_block->exception_var(), | |
3379 catch_block->stacktrace_var())); | |
3380 for_finally.BuildRestoreContext(catch_block->context_var()); | |
3381 | 3352 |
3382 finally_block->Visit(&for_finally); | 3353 // NOTE: The implicit variables ':saved_context', ':exception_var' |
3383 if (for_finally.is_open()) { | 3354 // and ':stacktrace_var' can never be captured variables. |
3384 // Rethrow the exception. Manually build the graph for rethrow. | 3355 ASSERT(!catch_block->exception_var().is_captured()); |
3385 Value* exception = for_finally.Bind( | 3356 ASSERT(!catch_block->stacktrace_var().is_captured()); |
3386 for_finally.BuildLoadLocal(catch_block->exception_var())); | |
3387 for_finally.PushArgument(exception); | |
3388 Value* stacktrace = for_finally.Bind( | |
3389 for_finally.BuildLoadLocal(catch_block->stacktrace_var())); | |
3390 for_finally.PushArgument(stacktrace); | |
3391 for_finally.AddInstruction(new ReThrowInstr(catch_block->token_pos())); | |
3392 for_finally.CloseFragment(); | |
3393 } | |
3394 ASSERT(!for_finally.is_open()); | |
3395 | 3357 |
3396 const Array& types = Array::ZoneHandle(Array::New(1, Heap::kOld)); | 3358 CatchBlockEntryInstr* catch_entry = |
3397 types.SetAt(0, Type::Handle(Type::DynamicType())); | 3359 new CatchBlockEntryInstr(owner()->AllocateBlockId(), |
3398 CatchBlockEntryInstr* finally_entry = | 3360 catch_handler_index, |
3399 new CatchBlockEntryInstr(owner()->AllocateBlockId(), | 3361 catch_block->handler_types(), |
3400 original_handler_index, | 3362 try_handler_index, |
3401 types, | 3363 catch_block->exception_var(), |
3402 catch_handler_index); | 3364 catch_block->stacktrace_var()); |
3403 owner()->AddCatchEntry(finally_entry); | 3365 owner()->AddCatchEntry(catch_entry); |
3404 AppendFragment(finally_entry, for_finally); | 3366 ASSERT(!for_catch.is_open()); |
3367 AppendFragment(catch_entry, for_catch); | |
3368 if (node->end_catch_label() != NULL) { | |
3369 JoinEntryInstr* join = node->end_catch_label()->join_for_continue(); | |
3370 if (join != NULL) { | |
3371 if (is_open()) Goto(join); | |
3372 exit_ = join; | |
3405 } | 3373 } |
3406 } | 3374 } |
3375 | |
3376 if (finally_block != NULL) { | |
3377 // Create a handler for the code in the catch block, containing the | |
3378 // code in the finally block. | |
3379 owner()->set_try_index(original_handler_index); | |
3380 EffectGraphVisitor for_finally(owner(), temp_index()); | |
3381 for_finally.BuildRestoreContext(catch_block->context_var()); | |
3382 | |
3383 finally_block->Visit(&for_finally); | |
3384 if (for_finally.is_open()) { | |
3385 // Rethrow the exception. Manually build the graph for rethrow. | |
3386 Value* exception = for_finally.Bind( | |
3387 for_finally.BuildLoadLocal(catch_block->exception_var())); | |
3388 for_finally.PushArgument(exception); | |
3389 Value* stacktrace = for_finally.Bind( | |
3390 for_finally.BuildLoadLocal(catch_block->stacktrace_var())); | |
3391 for_finally.PushArgument(stacktrace); | |
3392 for_finally.AddInstruction(new ReThrowInstr(catch_block->token_pos())); | |
3393 for_finally.CloseFragment(); | |
3394 } | |
3395 ASSERT(!for_finally.is_open()); | |
3396 | |
3397 const Array& types = Array::ZoneHandle(Array::New(1, Heap::kOld)); | |
3398 types.SetAt(0, Type::Handle(Type::DynamicType())); | |
3399 CatchBlockEntryInstr* finally_entry = | |
3400 new CatchBlockEntryInstr(owner()->AllocateBlockId(), | |
3401 original_handler_index, | |
3402 types, | |
3403 catch_handler_index, | |
3404 catch_block->exception_var(), | |
3405 catch_block->stacktrace_var()); | |
3406 owner()->AddCatchEntry(finally_entry); | |
3407 AppendFragment(finally_entry, for_finally); | |
3408 } | |
3409 | |
3407 // Generate code for the finally block if one exists. | 3410 // Generate code for the finally block if one exists. |
3408 if ((finally_block != NULL) && is_open()) { | 3411 if ((finally_block != NULL) && is_open()) { |
3409 EffectGraphVisitor for_finally_block(owner(), temp_index()); | 3412 EffectGraphVisitor for_finally_block(owner(), temp_index()); |
3410 finally_block->Visit(&for_finally_block); | 3413 finally_block->Visit(&for_finally_block); |
3411 Append(for_finally_block); | 3414 Append(for_finally_block); |
3412 } | 3415 } |
3413 } | 3416 } |
3414 | 3417 |
3415 | 3418 |
3416 // Looks up dynamic method noSuchMethod in target_class | 3419 // Looks up dynamic method noSuchMethod in target_class |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3623 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 3626 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; |
3624 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 3627 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
3625 OS::SNPrint(chars, len, kFormat, function_name, reason); | 3628 OS::SNPrint(chars, len, kFormat, function_name, reason); |
3626 const Error& error = Error::Handle( | 3629 const Error& error = Error::Handle( |
3627 LanguageError::New(String::Handle(String::New(chars)))); | 3630 LanguageError::New(String::Handle(String::New(chars)))); |
3628 Isolate::Current()->long_jump_base()->Jump(1, error); | 3631 Isolate::Current()->long_jump_base()->Jump(1, error); |
3629 } | 3632 } |
3630 | 3633 |
3631 | 3634 |
3632 } // namespace dart | 3635 } // namespace dart |
OLD | NEW |