OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2280 return Fragment(new (Z) GotoInstr(destination)).closed(); | 2280 return Fragment(new (Z) GotoInstr(destination)).closed(); |
2281 } | 2281 } |
2282 | 2282 |
2283 | 2283 |
2284 Fragment FlowGraphBuilder::IntConstant(int64_t value) { | 2284 Fragment FlowGraphBuilder::IntConstant(int64_t value) { |
2285 return Fragment( | 2285 return Fragment( |
2286 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)))); | 2286 Constant(Integer::ZoneHandle(Z, Integer::New(value, Heap::kOld)))); |
2287 } | 2287 } |
2288 | 2288 |
2289 | 2289 |
2290 Fragment FlowGraphBuilder::InstanceCall(const dart::String& name, | 2290 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
| 2291 const dart::String& name, |
2291 Token::Kind kind, | 2292 Token::Kind kind, |
2292 intptr_t argument_count, | 2293 intptr_t argument_count, |
2293 intptr_t num_args_checked) { | 2294 intptr_t num_args_checked) { |
2294 return InstanceCall(name, kind, argument_count, Array::null_array(), | 2295 return InstanceCall(position, name, kind, argument_count, Array::null_array(), |
2295 num_args_checked); | 2296 num_args_checked); |
2296 } | 2297 } |
2297 | 2298 |
2298 | 2299 |
2299 Fragment FlowGraphBuilder::InstanceCall(const dart::String& name, | 2300 Fragment FlowGraphBuilder::InstanceCall(TokenPosition position, |
| 2301 const dart::String& name, |
2300 Token::Kind kind, | 2302 Token::Kind kind, |
2301 intptr_t argument_count, | 2303 intptr_t argument_count, |
2302 const Array& argument_names, | 2304 const Array& argument_names, |
2303 intptr_t num_args_checked) { | 2305 intptr_t num_args_checked) { |
2304 ArgumentArray arguments = GetArguments(argument_count); | 2306 ArgumentArray arguments = GetArguments(argument_count); |
2305 InstanceCallInstr* call = new (Z) | 2307 InstanceCallInstr* call = |
2306 InstanceCallInstr(TokenPosition::kNoSource, name, kind, arguments, | 2308 new (Z) InstanceCallInstr(position, name, kind, arguments, argument_names, |
2307 argument_names, num_args_checked, ic_data_array_); | 2309 num_args_checked, ic_data_array_); |
2308 Push(call); | 2310 Push(call); |
2309 return Fragment(call); | 2311 return Fragment(call); |
2310 } | 2312 } |
2311 | 2313 |
2312 | 2314 |
2313 Fragment FlowGraphBuilder::ClosureCall(int argument_count, | 2315 Fragment FlowGraphBuilder::ClosureCall(int argument_count, |
2314 const Array& argument_names) { | 2316 const Array& argument_names) { |
2315 Value* function = Pop(); | 2317 Value* function = Pop(); |
2316 ArgumentArray arguments = GetArguments(argument_count); | 2318 ArgumentArray arguments = GetArguments(argument_count); |
2317 ClosureCallInstr* call = new (Z) ClosureCallInstr( | 2319 ClosureCallInstr* call = new (Z) ClosureCallInstr( |
2318 function, arguments, argument_names, TokenPosition::kNoSource); | 2320 function, arguments, argument_names, TokenPosition::kNoSource); |
2319 Push(call); | 2321 Push(call); |
2320 return Fragment(call); | 2322 return Fragment(call); |
2321 } | 2323 } |
2322 | 2324 |
2323 | 2325 |
2324 Fragment FlowGraphBuilder::ThrowException() { | 2326 Fragment FlowGraphBuilder::ThrowException(TokenPosition position) { |
2325 Fragment instructions; | 2327 Fragment instructions; |
2326 instructions += Drop(); | 2328 instructions += Drop(); |
2327 instructions += | 2329 instructions += Fragment(new (Z) ThrowInstr(position)).closed(); |
2328 Fragment(new (Z) ThrowInstr(TokenPosition::kNoSource)).closed(); | |
2329 // Use it's side effect of leaving a constant on the stack (does not change | 2330 // Use it's side effect of leaving a constant on the stack (does not change |
2330 // the graph). | 2331 // the graph). |
2331 NullConstant(); | 2332 NullConstant(); |
2332 | 2333 |
2333 pending_argument_count_ -= 1; | 2334 pending_argument_count_ -= 1; |
2334 | 2335 |
2335 return instructions; | 2336 return instructions; |
2336 } | 2337 } |
2337 | 2338 |
2338 | 2339 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2464 Fragment FlowGraphBuilder::Return() { | 2465 Fragment FlowGraphBuilder::Return() { |
2465 Value* value = Pop(); | 2466 Value* value = Pop(); |
2466 ASSERT(stack_ == NULL); | 2467 ASSERT(stack_ == NULL); |
2467 ReturnInstr* return_instr = | 2468 ReturnInstr* return_instr = |
2468 new (Z) ReturnInstr(TokenPosition::kNoSource, value); | 2469 new (Z) ReturnInstr(TokenPosition::kNoSource, value); |
2469 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr); | 2470 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr); |
2470 return Fragment(return_instr).closed(); | 2471 return Fragment(return_instr).closed(); |
2471 } | 2472 } |
2472 | 2473 |
2473 | 2474 |
2474 Fragment FlowGraphBuilder::StaticCall(const Function& target, | 2475 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, |
| 2476 const Function& target, |
2475 intptr_t argument_count) { | 2477 intptr_t argument_count) { |
2476 return StaticCall(target, argument_count, Array::null_array()); | 2478 return StaticCall(position, target, argument_count, Array::null_array()); |
2477 } | 2479 } |
2478 | 2480 |
2479 | 2481 |
2480 static intptr_t GetResultCidOfListFactory(Zone* zone, | 2482 static intptr_t GetResultCidOfListFactory(Zone* zone, |
2481 const Function& function, | 2483 const Function& function, |
2482 intptr_t argument_count) { | 2484 intptr_t argument_count) { |
2483 if (!function.IsFactory()) { | 2485 if (!function.IsFactory()) { |
2484 return kDynamicCid; | 2486 return kDynamicCid; |
2485 } | 2487 } |
2486 | 2488 |
2487 const dart::Class& owner = dart::Class::Handle(zone, function.Owner()); | 2489 const dart::Class& owner = dart::Class::Handle(zone, function.Owner()); |
2488 if ((owner.library() != dart::Library::CoreLibrary()) && | 2490 if ((owner.library() != dart::Library::CoreLibrary()) && |
2489 (owner.library() != dart::Library::TypedDataLibrary())) { | 2491 (owner.library() != dart::Library::TypedDataLibrary())) { |
2490 return kDynamicCid; | 2492 return kDynamicCid; |
2491 } | 2493 } |
2492 | 2494 |
2493 if ((owner.Name() == Symbols::List().raw()) && | 2495 if ((owner.Name() == Symbols::List().raw()) && |
2494 (function.name() == Symbols::ListFactory().raw())) { | 2496 (function.name() == Symbols::ListFactory().raw())) { |
2495 ASSERT(argument_count == 1 || argument_count == 2); | 2497 ASSERT(argument_count == 1 || argument_count == 2); |
2496 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid; | 2498 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid; |
2497 } | 2499 } |
2498 return FactoryRecognizer::ResultCid(function); | 2500 return FactoryRecognizer::ResultCid(function); |
2499 } | 2501 } |
2500 | 2502 |
2501 | 2503 |
2502 Fragment FlowGraphBuilder::StaticCall(const Function& target, | 2504 Fragment FlowGraphBuilder::StaticCall(TokenPosition position, |
| 2505 const Function& target, |
2503 intptr_t argument_count, | 2506 intptr_t argument_count, |
2504 const Array& argument_names) { | 2507 const Array& argument_names) { |
2505 ArgumentArray arguments = GetArguments(argument_count); | 2508 ArgumentArray arguments = GetArguments(argument_count); |
2506 StaticCallInstr* call = | 2509 StaticCallInstr* call = new (Z) StaticCallInstr( |
2507 new (Z) StaticCallInstr(TokenPosition::kNoSource, target, argument_names, | 2510 position, target, argument_names, arguments, ic_data_array_); |
2508 arguments, ic_data_array_); | |
2509 const intptr_t list_cid = | 2511 const intptr_t list_cid = |
2510 GetResultCidOfListFactory(Z, target, argument_count); | 2512 GetResultCidOfListFactory(Z, target, argument_count); |
2511 if (list_cid != kDynamicCid) { | 2513 if (list_cid != kDynamicCid) { |
2512 call->set_result_cid(list_cid); | 2514 call->set_result_cid(list_cid); |
2513 call->set_is_known_list_constructor(true); | 2515 call->set_is_known_list_constructor(true); |
2514 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { | 2516 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { |
2515 call->set_result_cid(MethodRecognizer::ResultCid(target)); | 2517 call->set_result_cid(MethodRecognizer::ResultCid(target)); |
2516 } | 2518 } |
2517 Push(call); | 2519 Push(call); |
2518 return Fragment(call); | 2520 return Fragment(call); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2638 | 2640 |
2639 instructions += NullConstant(); | 2641 instructions += NullConstant(); |
2640 instructions += PushArgument(); // line | 2642 instructions += PushArgument(); // line |
2641 | 2643 |
2642 instructions += IntConstant(0); | 2644 instructions += IntConstant(0); |
2643 instructions += PushArgument(); // column | 2645 instructions += PushArgument(); // column |
2644 | 2646 |
2645 instructions += Constant(H.DartSymbol("Malformed type.")); | 2647 instructions += Constant(H.DartSymbol("Malformed type.")); |
2646 instructions += PushArgument(); // message | 2648 instructions += PushArgument(); // message |
2647 | 2649 |
2648 instructions += StaticCall(constructor, 5); | 2650 instructions += StaticCall(TokenPosition::kNoSource, constructor, 5); |
2649 instructions += Drop(); | 2651 instructions += Drop(); |
2650 | 2652 |
2651 // Throw the exception | 2653 // Throw the exception |
2652 instructions += PushArgument(); | 2654 instructions += PushArgument(); |
2653 instructions += ThrowException(); | 2655 instructions += ThrowException(TokenPosition::kNoSource); |
2654 | 2656 |
2655 return instructions; | 2657 return instructions; |
2656 } | 2658 } |
2657 | 2659 |
2658 | 2660 |
2659 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() { | 2661 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() { |
2660 const dart::Class& klass = dart::Class::ZoneHandle( | 2662 const dart::Class& klass = dart::Class::ZoneHandle( |
2661 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError())); | 2663 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError())); |
2662 ASSERT(!klass.IsNull()); | 2664 ASSERT(!klass.IsNull()); |
2663 const dart::Function& throw_function = dart::Function::ZoneHandle( | 2665 const dart::Function& throw_function = dart::Function::ZoneHandle( |
(...skipping 14 matching lines...) Expand all Loading... |
2678 | 2680 |
2679 instructions += NullConstant(); | 2681 instructions += NullConstant(); |
2680 instructions += PushArgument(); // arguments | 2682 instructions += PushArgument(); // arguments |
2681 | 2683 |
2682 instructions += NullConstant(); | 2684 instructions += NullConstant(); |
2683 instructions += PushArgument(); // argumentNames | 2685 instructions += PushArgument(); // argumentNames |
2684 | 2686 |
2685 instructions += NullConstant(); | 2687 instructions += NullConstant(); |
2686 instructions += PushArgument(); // existingArgumentNames | 2688 instructions += PushArgument(); // existingArgumentNames |
2687 | 2689 |
2688 instructions += StaticCall(throw_function, 6); | 2690 instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6); |
2689 // Leave "result" on the stack since callers expect it to be there (even | 2691 // Leave "result" on the stack since callers expect it to be there (even |
2690 // though the function will result in an exception). | 2692 // though the function will result in an exception). |
2691 | 2693 |
2692 return instructions; | 2694 return instructions; |
2693 } | 2695 } |
2694 | 2696 |
2695 | 2697 |
2696 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( | 2698 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( |
2697 Member* target, | 2699 Member* target, |
2698 const dart::String& method_name) { | 2700 const dart::String& method_name) { |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3440 for (intptr_t i = 0; i < named_argument_count; i++) { | 3442 for (intptr_t i = 0; i < named_argument_count; i++) { |
3441 VariableDeclaration* variable = kernel_function->named_parameters()[i]; | 3443 VariableDeclaration* variable = kernel_function->named_parameters()[i]; |
3442 body += LoadLocal(LookupVariable(variable)); | 3444 body += LoadLocal(LookupVariable(variable)); |
3443 body += PushArgument(); | 3445 body += PushArgument(); |
3444 argument_names.SetAt(i, H.DartSymbol(variable->name())); | 3446 argument_names.SetAt(i, H.DartSymbol(variable->name())); |
3445 } | 3447 } |
3446 } | 3448 } |
3447 // Forward them to the target. | 3449 // Forward them to the target. |
3448 intptr_t argument_count = positional_argument_count + named_argument_count; | 3450 intptr_t argument_count = positional_argument_count + named_argument_count; |
3449 if (!target.is_static()) ++argument_count; | 3451 if (!target.is_static()) ++argument_count; |
3450 body += StaticCall(target, argument_count, argument_names); | 3452 body += StaticCall(TokenPosition::kNoSource, target, argument_count, |
| 3453 argument_names); |
3451 | 3454 |
3452 // Return the result. | 3455 // Return the result. |
3453 body += Return(); | 3456 body += Return(); |
3454 | 3457 |
3455 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); | 3458 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); |
3456 } | 3459 } |
3457 | 3460 |
3458 | 3461 |
3459 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( | 3462 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( |
3460 const Function& function) { | 3463 const Function& function) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3527 body += Constant(Bool::False()); | 3530 body += Constant(Bool::False()); |
3528 body += PushArgument(); | 3531 body += PushArgument(); |
3529 | 3532 |
3530 const dart::Class& mirror_class = dart::Class::Handle( | 3533 const dart::Class& mirror_class = dart::Class::Handle( |
3531 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); | 3534 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); |
3532 ASSERT(!mirror_class.IsNull()); | 3535 ASSERT(!mirror_class.IsNull()); |
3533 const Function& allocation_function = Function::ZoneHandle( | 3536 const Function& allocation_function = Function::ZoneHandle( |
3534 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( | 3537 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( |
3535 Symbols::AllocateInvocationMirror()))); | 3538 Symbols::AllocateInvocationMirror()))); |
3536 ASSERT(!allocation_function.IsNull()); | 3539 ASSERT(!allocation_function.IsNull()); |
3537 body += StaticCall(allocation_function, 4); | 3540 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4); |
3538 body += PushArgument(); // For the call to noSuchMethod. | 3541 body += PushArgument(); // For the call to noSuchMethod. |
3539 | 3542 |
3540 ArgumentsDescriptor two_arguments( | 3543 ArgumentsDescriptor two_arguments( |
3541 Array::Handle(Z, ArgumentsDescriptor::New(2))); | 3544 Array::Handle(Z, ArgumentsDescriptor::New(2))); |
3542 Function& no_such_method = | 3545 Function& no_such_method = |
3543 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( | 3546 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( |
3544 dart::Class::Handle(Z, function.Owner()), | 3547 dart::Class::Handle(Z, function.Owner()), |
3545 Symbols::NoSuchMethod(), two_arguments)); | 3548 Symbols::NoSuchMethod(), two_arguments)); |
3546 if (no_such_method.IsNull()) { | 3549 if (no_such_method.IsNull()) { |
3547 // If noSuchMethod is not found on the receiver class, call | 3550 // If noSuchMethod is not found on the receiver class, call |
3548 // Object.noSuchMethod. | 3551 // Object.noSuchMethod. |
3549 no_such_method = Resolver::ResolveDynamicForReceiverClass( | 3552 no_such_method = Resolver::ResolveDynamicForReceiverClass( |
3550 dart::Class::Handle(Z, I->object_store()->object_class()), | 3553 dart::Class::Handle(Z, I->object_store()->object_class()), |
3551 Symbols::NoSuchMethod(), two_arguments); | 3554 Symbols::NoSuchMethod(), two_arguments); |
3552 } | 3555 } |
3553 body += StaticCall(no_such_method, 2); | 3556 body += StaticCall(TokenPosition::kMinSource, no_such_method, 2); |
3554 body += Return(); | 3557 body += Return(); |
3555 | 3558 |
3556 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); | 3559 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); |
3557 } | 3560 } |
3558 | 3561 |
3559 | 3562 |
3560 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( | 3563 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( |
3561 const Function& function) { | 3564 const Function& function) { |
3562 // Find the name of the field we should dispatch to. | 3565 // Find the name of the field we should dispatch to. |
3563 const dart::Class& owner = dart::Class::Handle(Z, function.Owner()); | 3566 const dart::Class& owner = dart::Class::Handle(Z, function.Owner()); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3607 LocalVariable* closure = NULL; | 3610 LocalVariable* closure = NULL; |
3608 if (is_closure_call) { | 3611 if (is_closure_call) { |
3609 closure = scope->VariableAt(0); | 3612 closure = scope->VariableAt(0); |
3610 | 3613 |
3611 // The closure itself is the first argument. | 3614 // The closure itself is the first argument. |
3612 body += LoadLocal(closure); | 3615 body += LoadLocal(closure); |
3613 } else { | 3616 } else { |
3614 // Invoke the getter to get the field value. | 3617 // Invoke the getter to get the field value. |
3615 body += LoadLocal(scope->VariableAt(0)); | 3618 body += LoadLocal(scope->VariableAt(0)); |
3616 body += PushArgument(); | 3619 body += PushArgument(); |
3617 body += InstanceCall(getter_name, Token::kGET, 1); | 3620 body += |
| 3621 InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1); |
3618 } | 3622 } |
3619 | 3623 |
3620 body += PushArgument(); | 3624 body += PushArgument(); |
3621 | 3625 |
3622 // Push all arguments onto the stack. | 3626 // Push all arguments onto the stack. |
3623 intptr_t pos = 1; | 3627 intptr_t pos = 1; |
3624 for (; pos < descriptor.Count(); pos++) { | 3628 for (; pos < descriptor.Count(); pos++) { |
3625 body += LoadLocal(scope->VariableAt(pos)); | 3629 body += LoadLocal(scope->VariableAt(pos)); |
3626 body += PushArgument(); | 3630 body += PushArgument(); |
3627 } | 3631 } |
3628 | 3632 |
3629 if (is_closure_call) { | 3633 if (is_closure_call) { |
3630 // Lookup the function in the closure. | 3634 // Lookup the function in the closure. |
3631 body += LoadLocal(closure); | 3635 body += LoadLocal(closure); |
3632 body += LoadField(Closure::function_offset()); | 3636 body += LoadField(Closure::function_offset()); |
3633 | 3637 |
3634 body += ClosureCall(descriptor.Count(), argument_names); | 3638 body += ClosureCall(descriptor.Count(), argument_names); |
3635 } else { | 3639 } else { |
3636 body += InstanceCall(Symbols::Call(), Token::kILLEGAL, descriptor.Count(), | 3640 body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(), |
3637 argument_names); | 3641 Token::kILLEGAL, descriptor.Count(), argument_names); |
3638 } | 3642 } |
3639 | 3643 |
3640 body += Return(); | 3644 body += Return(); |
3641 | 3645 |
3642 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); | 3646 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); |
3643 } | 3647 } |
3644 | 3648 |
3645 | 3649 |
3646 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) { | 3650 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) { |
3647 intptr_t num_optional_parameters = | 3651 intptr_t num_optional_parameters = |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3740 instructions += LoadLocal(scopes_->this_variable); | 3744 instructions += LoadLocal(scopes_->this_variable); |
3741 instructions += PushArgument(); | 3745 instructions += PushArgument(); |
3742 | 3746 |
3743 ASSERT(init->arguments()->types().length() == 0); | 3747 ASSERT(init->arguments()->types().length() == 0); |
3744 Array& argument_names = Array::ZoneHandle(Z); | 3748 Array& argument_names = Array::ZoneHandle(Z); |
3745 instructions += TranslateArguments(init->arguments(), &argument_names); | 3749 instructions += TranslateArguments(init->arguments(), &argument_names); |
3746 | 3750 |
3747 const Function& target = Function::ZoneHandle( | 3751 const Function& target = Function::ZoneHandle( |
3748 Z, H.LookupConstructorByKernelConstructor(init->target())); | 3752 Z, H.LookupConstructorByKernelConstructor(init->target())); |
3749 intptr_t argument_count = init->arguments()->count() + 1; | 3753 intptr_t argument_count = init->arguments()->count() + 1; |
3750 instructions += StaticCall(target, argument_count, argument_names); | 3754 instructions += StaticCall(TokenPosition::kNoSource, target, |
| 3755 argument_count, argument_names); |
3751 instructions += Drop(); | 3756 instructions += Drop(); |
3752 } else if (initializer->IsRedirectingInitializer()) { | 3757 } else if (initializer->IsRedirectingInitializer()) { |
3753 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer); | 3758 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer); |
3754 | 3759 |
3755 instructions += LoadLocal(scopes_->this_variable); | 3760 instructions += LoadLocal(scopes_->this_variable); |
3756 instructions += PushArgument(); | 3761 instructions += PushArgument(); |
3757 | 3762 |
3758 ASSERT(init->arguments()->types().length() == 0); | 3763 ASSERT(init->arguments()->types().length() == 0); |
3759 Array& argument_names = Array::ZoneHandle(Z); | 3764 Array& argument_names = Array::ZoneHandle(Z); |
3760 instructions += TranslateArguments(init->arguments(), &argument_names); | 3765 instructions += TranslateArguments(init->arguments(), &argument_names); |
3761 | 3766 |
3762 const Function& target = Function::ZoneHandle( | 3767 const Function& target = Function::ZoneHandle( |
3763 Z, H.LookupConstructorByKernelConstructor(init->target())); | 3768 Z, H.LookupConstructorByKernelConstructor(init->target())); |
3764 intptr_t argument_count = init->arguments()->count() + 1; | 3769 intptr_t argument_count = init->arguments()->count() + 1; |
3765 instructions += StaticCall(target, argument_count, argument_names); | 3770 instructions += StaticCall(TokenPosition::kNoSource, target, |
| 3771 argument_count, argument_names); |
3766 instructions += Drop(); | 3772 instructions += Drop(); |
3767 } else if (initializer->IsLocalInitializer()) { | 3773 } else if (initializer->IsLocalInitializer()) { |
3768 // The other initializers following this one might read the variable. This | 3774 // The other initializers following this one might read the variable. This |
3769 // is used e.g. for evaluating the arguments to a super call first, run | 3775 // is used e.g. for evaluating the arguments to a super call first, run |
3770 // normal field initializers next and then make the actual super call: | 3776 // normal field initializers next and then make the actual super call: |
3771 // | 3777 // |
3772 // The frontend converts | 3778 // The frontend converts |
3773 // | 3779 // |
3774 // class A { | 3780 // class A { |
3775 // var x; | 3781 // var x; |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4182 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); | 4188 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); |
4183 } else { | 4189 } else { |
4184 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); | 4190 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); |
4185 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); | 4191 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); |
4186 const Function& getter = | 4192 const Function& getter = |
4187 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); | 4193 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); |
4188 if (getter.IsNull() || !field.has_initializer()) { | 4194 if (getter.IsNull() || !field.has_initializer()) { |
4189 Fragment instructions = Constant(field); | 4195 Fragment instructions = Constant(field); |
4190 fragment_ = instructions + LoadStaticField(); | 4196 fragment_ = instructions + LoadStaticField(); |
4191 } else { | 4197 } else { |
4192 fragment_ = StaticCall(getter, 0); | 4198 fragment_ = StaticCall(node->position(), getter, 0); |
4193 } | 4199 } |
4194 } | 4200 } |
4195 } else { | 4201 } else { |
4196 Procedure* procedure = Procedure::Cast(target); | 4202 Procedure* procedure = Procedure::Cast(target); |
4197 const Function& target = Function::ZoneHandle( | 4203 const Function& target = Function::ZoneHandle( |
4198 Z, H.LookupStaticMethodByKernelProcedure(procedure)); | 4204 Z, H.LookupStaticMethodByKernelProcedure(procedure)); |
4199 | 4205 |
4200 if (procedure->kind() == Procedure::kGetter) { | 4206 if (procedure->kind() == Procedure::kGetter) { |
4201 fragment_ = StaticCall(target, 0); | 4207 fragment_ = StaticCall(node->position(), target, 0); |
4202 } else if (procedure->kind() == Procedure::kMethod) { | 4208 } else if (procedure->kind() == Procedure::kMethod) { |
4203 ASSERT(procedure->IsStatic()); | 4209 ASSERT(procedure->IsStatic()); |
4204 Function& closure_function = | 4210 Function& closure_function = |
4205 Function::ZoneHandle(Z, target.ImplicitClosureFunction()); | 4211 Function::ZoneHandle(Z, target.ImplicitClosureFunction()); |
4206 closure_function.set_kernel_function(target.kernel_function()); | 4212 closure_function.set_kernel_function(target.kernel_function()); |
4207 const Instance& closure = | 4213 const Instance& closure = |
4208 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure()); | 4214 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure()); |
4209 fragment_ = Constant(closure); | 4215 fragment_ = Constant(closure); |
4210 } else { | 4216 } else { |
4211 UNIMPLEMENTED(); | 4217 UNIMPLEMENTED(); |
(...skipping 20 matching lines...) Expand all Loading... |
4232 LocalVariable* variable = MakeTemporary(); | 4238 LocalVariable* variable = MakeTemporary(); |
4233 | 4239 |
4234 // Prepare argument. | 4240 // Prepare argument. |
4235 instructions += LoadLocal(variable); | 4241 instructions += LoadLocal(variable); |
4236 instructions += PushArgument(); | 4242 instructions += PushArgument(); |
4237 | 4243 |
4238 // Invoke the setter function. | 4244 // Invoke the setter function. |
4239 Procedure* procedure = Procedure::Cast(target); | 4245 Procedure* procedure = Procedure::Cast(target); |
4240 const Function& target = Function::ZoneHandle( | 4246 const Function& target = Function::ZoneHandle( |
4241 Z, H.LookupStaticMethodByKernelProcedure(procedure)); | 4247 Z, H.LookupStaticMethodByKernelProcedure(procedure)); |
4242 instructions += StaticCall(target, 1); | 4248 instructions += StaticCall(node->position(), target, 1); |
4243 | 4249 |
4244 // Drop the unused result & leave the stored value on the stack. | 4250 // Drop the unused result & leave the stored value on the stack. |
4245 fragment_ = instructions + Drop(); | 4251 fragment_ = instructions + Drop(); |
4246 } | 4252 } |
4247 } | 4253 } |
4248 | 4254 |
4249 | 4255 |
4250 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { | 4256 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { |
4251 Fragment instructions = TranslateExpression(node->receiver()); | 4257 Fragment instructions = TranslateExpression(node->receiver()); |
4252 instructions += PushArgument(); | 4258 instructions += PushArgument(); |
4253 const dart::String& getter_name = H.DartGetterName(node->name()); | 4259 const dart::String& getter_name = H.DartGetterName(node->name()); |
4254 fragment_ = instructions + InstanceCall(getter_name, Token::kGET, 1); | 4260 fragment_ = instructions + |
| 4261 InstanceCall(node->position(), getter_name, Token::kGET, 1); |
4255 } | 4262 } |
4256 | 4263 |
4257 | 4264 |
4258 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) { | 4265 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) { |
4259 Fragment instructions(NullConstant()); | 4266 Fragment instructions(NullConstant()); |
4260 LocalVariable* variable = MakeTemporary(); | 4267 LocalVariable* variable = MakeTemporary(); |
4261 instructions += TranslateExpression(node->receiver()); | 4268 instructions += TranslateExpression(node->receiver()); |
4262 instructions += PushArgument(); | 4269 instructions += PushArgument(); |
4263 instructions += TranslateExpression(node->value()); | 4270 instructions += TranslateExpression(node->value()); |
4264 instructions += StoreLocal(variable); | 4271 instructions += StoreLocal(variable); |
4265 instructions += PushArgument(); | 4272 instructions += PushArgument(); |
4266 | 4273 |
4267 const dart::String& setter_name = H.DartSetterName(node->name()); | 4274 const dart::String& setter_name = H.DartSetterName(node->name()); |
4268 instructions += InstanceCall(setter_name, Token::kSET, 2); | 4275 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2); |
4269 fragment_ = instructions + Drop(); | 4276 fragment_ = instructions + Drop(); |
4270 } | 4277 } |
4271 | 4278 |
4272 | 4279 |
4273 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { | 4280 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { |
4274 Function& target = Function::ZoneHandle(Z); | 4281 Function& target = Function::ZoneHandle(Z); |
4275 if (node->target()->IsProcedure()) { | 4282 if (node->target()->IsProcedure()) { |
4276 Procedure* kernel_procedure = Procedure::Cast(node->target()); | 4283 Procedure* kernel_procedure = Procedure::Cast(node->target()); |
4277 Name* kernel_name = kernel_procedure->name(); | 4284 Name* kernel_name = kernel_procedure->name(); |
4278 if (kernel_procedure->kind() == Procedure::kGetter) { | 4285 if (kernel_procedure->kind() == Procedure::kGetter) { |
4279 target = | 4286 target = |
4280 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name)); | 4287 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name)); |
4281 } else { | 4288 } else { |
4282 target = | 4289 target = |
4283 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name)); | 4290 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name)); |
4284 target = target.ImplicitClosureFunction(); | 4291 target = target.ImplicitClosureFunction(); |
4285 ASSERT(!target.IsNull()); | 4292 ASSERT(!target.IsNull()); |
4286 fragment_ = BuildImplicitClosureCreation(target); | 4293 fragment_ = BuildImplicitClosureCreation(target); |
4287 return; | 4294 return; |
4288 } | 4295 } |
4289 } else { | 4296 } else { |
4290 ASSERT(node->target()->IsField()); | 4297 ASSERT(node->target()->IsField()); |
4291 const dart::String& getter_name = H.DartGetterName(node->target()->name()); | 4298 const dart::String& getter_name = H.DartGetterName(node->target()->name()); |
4292 target = LookupMethodByMember(node->target(), getter_name); | 4299 target = LookupMethodByMember(node->target(), getter_name); |
4293 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); | 4300 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); |
4294 } | 4301 } |
4295 | 4302 |
4296 Fragment instructions = TranslateExpression(node->receiver()); | 4303 Fragment instructions = TranslateExpression(node->receiver()); |
4297 instructions += PushArgument(); | 4304 instructions += PushArgument(); |
4298 fragment_ = instructions + StaticCall(target, 1); | 4305 fragment_ = instructions + StaticCall(node->position(), target, 1); |
4299 } | 4306 } |
4300 | 4307 |
4301 | 4308 |
4302 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { | 4309 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { |
4303 const dart::String& method_name = H.DartSetterName(node->target()->name()); | 4310 const dart::String& method_name = H.DartSetterName(node->target()->name()); |
4304 const Function& target = Function::ZoneHandle( | 4311 const Function& target = Function::ZoneHandle( |
4305 Z, LookupMethodByMember(node->target(), method_name)); | 4312 Z, LookupMethodByMember(node->target(), method_name)); |
4306 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); | 4313 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); |
4307 | 4314 |
4308 Fragment instructions(NullConstant()); | 4315 Fragment instructions(NullConstant()); |
4309 LocalVariable* value = MakeTemporary(); | 4316 LocalVariable* value = MakeTemporary(); |
4310 instructions += TranslateExpression(node->receiver()); | 4317 instructions += TranslateExpression(node->receiver()); |
4311 instructions += PushArgument(); | 4318 instructions += PushArgument(); |
4312 instructions += TranslateExpression(node->value()); | 4319 instructions += TranslateExpression(node->value()); |
4313 instructions += StoreLocal(value); | 4320 instructions += StoreLocal(value); |
4314 instructions += PushArgument(); | 4321 instructions += PushArgument(); |
4315 instructions += StaticCall(target, 2); | 4322 instructions += StaticCall(node->position(), target, 2); |
4316 | 4323 |
4317 fragment_ = instructions + Drop(); | 4324 fragment_ = instructions + Drop(); |
4318 } | 4325 } |
4319 | 4326 |
4320 | 4327 |
4321 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) { | 4328 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) { |
4322 const Function& target = Function::ZoneHandle( | 4329 const Function& target = Function::ZoneHandle( |
4323 Z, H.LookupStaticMethodByKernelProcedure(node->procedure())); | 4330 Z, H.LookupStaticMethodByKernelProcedure(node->procedure())); |
4324 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner()); | 4331 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner()); |
4325 intptr_t argument_count = node->arguments()->count(); | 4332 intptr_t argument_count = node->arguments()->count(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4390 (target.name() == Symbols::Identical().raw())) { | 4397 (target.name() == Symbols::Identical().raw())) { |
4391 ASSERT(argument_count == 2); | 4398 ASSERT(argument_count == 2); |
4392 | 4399 |
4393 List<Expression>& positional = node->arguments()->positional(); | 4400 List<Expression>& positional = node->arguments()->positional(); |
4394 for (intptr_t i = 0; i < positional.length(); ++i) { | 4401 for (intptr_t i = 0; i < positional.length(); ++i) { |
4395 instructions += TranslateExpression(positional[i]); | 4402 instructions += TranslateExpression(positional[i]); |
4396 } | 4403 } |
4397 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true); | 4404 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true); |
4398 } else { | 4405 } else { |
4399 instructions += TranslateArguments(node->arguments(), NULL); | 4406 instructions += TranslateArguments(node->arguments(), NULL); |
4400 instructions += StaticCall(target, argument_count, argument_names); | 4407 instructions += |
| 4408 StaticCall(node->position(), target, argument_count, argument_names); |
4401 | 4409 |
4402 if (target.IsGenerativeConstructor()) { | 4410 if (target.IsGenerativeConstructor()) { |
4403 // Drop the result of the constructor call and leave [instance_variable] | 4411 // Drop the result of the constructor call and leave [instance_variable] |
4404 // on top-of-stack. | 4412 // on top-of-stack. |
4405 instructions += Drop(); | 4413 instructions += Drop(); |
4406 } | 4414 } |
4407 } | 4415 } |
4408 | 4416 |
4409 fragment_ = instructions; | 4417 fragment_ = instructions; |
4410 } | 4418 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4447 instructions += TranslateArguments(node->arguments(), &argument_names); | 4455 instructions += TranslateArguments(node->arguments(), &argument_names); |
4448 | 4456 |
4449 intptr_t num_args_checked = 1; | 4457 intptr_t num_args_checked = 1; |
4450 // If we have a special operation (e.g. +/-/==) we mark both arguments as | 4458 // If we have a special operation (e.g. +/-/==) we mark both arguments as |
4451 // to be checked. | 4459 // to be checked. |
4452 if (token_kind != Token::kILLEGAL) { | 4460 if (token_kind != Token::kILLEGAL) { |
4453 ASSERT(argument_count <= 2); | 4461 ASSERT(argument_count <= 2); |
4454 num_args_checked = argument_count; | 4462 num_args_checked = argument_count; |
4455 } | 4463 } |
4456 | 4464 |
4457 fragment_ = instructions + InstanceCall(name, token_kind, argument_count, | 4465 fragment_ = instructions + InstanceCall(node->position(), name, token_kind, |
4458 argument_names, num_args_checked); | 4466 argument_count, argument_names, |
| 4467 num_args_checked); |
4459 } | 4468 } |
4460 | 4469 |
4461 | 4470 |
4462 void FlowGraphBuilder::VisitDirectMethodInvocation( | 4471 void FlowGraphBuilder::VisitDirectMethodInvocation( |
4463 DirectMethodInvocation* node) { | 4472 DirectMethodInvocation* node) { |
4464 const dart::String& method_name = H.DartMethodName(node->target()->name()); | 4473 const dart::String& method_name = H.DartMethodName(node->target()->name()); |
4465 const Function& target = Function::ZoneHandle( | 4474 const Function& target = Function::ZoneHandle( |
4466 Z, LookupMethodByMember(node->target(), method_name)); | 4475 Z, LookupMethodByMember(node->target(), method_name)); |
4467 | 4476 |
4468 intptr_t argument_count = node->arguments()->count() + 1; | 4477 intptr_t argument_count = node->arguments()->count() + 1; |
4469 Array& argument_names = Array::ZoneHandle(Z); | 4478 Array& argument_names = Array::ZoneHandle(Z); |
4470 | 4479 |
4471 ASSERT(node->arguments()->types().length() == 0); | 4480 ASSERT(node->arguments()->types().length() == 0); |
4472 Fragment instructions = TranslateExpression(node->receiver()); | 4481 Fragment instructions = TranslateExpression(node->receiver()); |
4473 instructions += PushArgument(); | 4482 instructions += PushArgument(); |
4474 instructions += TranslateArguments(node->arguments(), &argument_names); | 4483 instructions += TranslateArguments(node->arguments(), &argument_names); |
4475 fragment_ = instructions + StaticCall(target, argument_count, argument_names); | 4484 fragment_ = instructions + StaticCall(node->position(), target, |
| 4485 argument_count, argument_names); |
4476 } | 4486 } |
4477 | 4487 |
4478 | 4488 |
4479 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { | 4489 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { |
4480 if (node->is_const()) { | 4490 if (node->is_const()) { |
4481 fragment_ = | 4491 fragment_ = |
4482 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); | 4492 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); |
4483 return; | 4493 return; |
4484 } | 4494 } |
4485 | 4495 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4525 | 4535 |
4526 instructions += LoadLocal(variable); | 4536 instructions += LoadLocal(variable); |
4527 instructions += PushArgument(); | 4537 instructions += PushArgument(); |
4528 | 4538 |
4529 Array& argument_names = Array::ZoneHandle(Z); | 4539 Array& argument_names = Array::ZoneHandle(Z); |
4530 instructions += TranslateArguments(node->arguments(), &argument_names); | 4540 instructions += TranslateArguments(node->arguments(), &argument_names); |
4531 | 4541 |
4532 const Function& target = Function::ZoneHandle( | 4542 const Function& target = Function::ZoneHandle( |
4533 Z, H.LookupConstructorByKernelConstructor(klass, node->target())); | 4543 Z, H.LookupConstructorByKernelConstructor(klass, node->target())); |
4534 intptr_t argument_count = node->arguments()->count() + 1; | 4544 intptr_t argument_count = node->arguments()->count() + 1; |
4535 instructions += StaticCall(target, argument_count, argument_names); | 4545 instructions += |
| 4546 StaticCall(node->position(), target, argument_count, argument_names); |
4536 fragment_ = instructions + Drop(); | 4547 fragment_ = instructions + Drop(); |
4537 } | 4548 } |
4538 | 4549 |
4539 | 4550 |
4540 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) { | 4551 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) { |
4541 Fragment instructions = TranslateExpression(node->operand()); | 4552 Fragment instructions = TranslateExpression(node->operand()); |
4542 | 4553 |
4543 // The VM does not like an instanceOf call with a dynamic type. We need to | 4554 // The VM does not like an instanceOf call with a dynamic type. We need to |
4544 // special case this situation. | 4555 // special case this situation. |
4545 const Type& object_type = Type::Handle(Z, Type::ObjectType()); | 4556 const Type& object_type = Type::Handle(Z, Type::ObjectType()); |
(...skipping 22 matching lines...) Expand all Loading... |
4568 } | 4579 } |
4569 instructions += PushArgument(); // Type arguments. | 4580 instructions += PushArgument(); // Type arguments. |
4570 | 4581 |
4571 instructions += Constant(type); | 4582 instructions += Constant(type); |
4572 instructions += PushArgument(); // Type. | 4583 instructions += PushArgument(); // Type. |
4573 | 4584 |
4574 instructions += Constant(Bool::False()); | 4585 instructions += Constant(Bool::False()); |
4575 instructions += PushArgument(); // Negate?. | 4586 instructions += PushArgument(); // Negate?. |
4576 | 4587 |
4577 instructions += | 4588 instructions += |
4578 InstanceCall(dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), | 4589 InstanceCall(TokenPosition::kNoSource, |
| 4590 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), |
4579 Token::kIS, 4); | 4591 Token::kIS, 4); |
4580 } | 4592 } |
4581 | 4593 |
4582 fragment_ = instructions; | 4594 fragment_ = instructions; |
4583 } | 4595 } |
4584 | 4596 |
4585 | 4597 |
4586 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { | 4598 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { |
4587 Fragment instructions = TranslateExpression(node->operand()); | 4599 Fragment instructions = TranslateExpression(node->operand()); |
4588 | 4600 |
(...skipping 19 matching lines...) Expand all Loading... |
4608 instructions += LoadInstantiatorTypeArguments(); | 4620 instructions += LoadInstantiatorTypeArguments(); |
4609 } else { | 4621 } else { |
4610 instructions += NullConstant(); | 4622 instructions += NullConstant(); |
4611 } | 4623 } |
4612 instructions += PushArgument(); // Type arguments. | 4624 instructions += PushArgument(); // Type arguments. |
4613 | 4625 |
4614 instructions += Constant(type); | 4626 instructions += Constant(type); |
4615 instructions += PushArgument(); // Type. | 4627 instructions += PushArgument(); // Type. |
4616 | 4628 |
4617 instructions += InstanceCall( | 4629 instructions += InstanceCall( |
| 4630 TokenPosition::kNoSource, |
4618 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3); | 4631 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3); |
4619 } | 4632 } |
4620 | 4633 |
4621 fragment_ = instructions; | 4634 fragment_ = instructions; |
4622 } | 4635 } |
4623 | 4636 |
4624 | 4637 |
4625 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { | 4638 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { |
4626 bool negate; | 4639 bool negate; |
4627 Fragment instructions = TranslateCondition(node->condition(), &negate); | 4640 Fragment instructions = TranslateCondition(node->condition(), &negate); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4754 instructions += Drop(); | 4767 instructions += Drop(); |
4755 } | 4768 } |
4756 } | 4769 } |
4757 instructions += PushArgument(); // The array. | 4770 instructions += PushArgument(); // The array. |
4758 | 4771 |
4759 const dart::Class& factory_class = | 4772 const dart::Class& factory_class = |
4760 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List())); | 4773 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List())); |
4761 const Function& factory_method = Function::ZoneHandle( | 4774 const Function& factory_method = Function::ZoneHandle( |
4762 Z, factory_class.LookupFactory( | 4775 Z, factory_class.LookupFactory( |
4763 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); | 4776 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); |
4764 fragment_ = instructions + StaticCall(factory_method, 2); | 4777 fragment_ = instructions + StaticCall(node->position(), factory_method, 2); |
4765 } | 4778 } |
4766 | 4779 |
4767 | 4780 |
4768 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) { | 4781 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) { |
4769 if (node->is_const()) { | 4782 if (node->is_const()) { |
4770 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node)); | 4783 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node)); |
4771 return; | 4784 return; |
4772 } | 4785 } |
4773 | 4786 |
4774 const dart::Class& map_class = | 4787 const dart::Class& map_class = |
(...skipping 30 matching lines...) Expand all Loading... |
4805 | 4818 |
4806 instructions += LoadLocal(array); | 4819 instructions += LoadLocal(array); |
4807 instructions += IntConstant(2 * i + 1); | 4820 instructions += IntConstant(2 * i + 1); |
4808 instructions += TranslateExpression(entries[i]->value()); | 4821 instructions += TranslateExpression(entries[i]->value()); |
4809 instructions += StoreIndexed(kArrayCid); | 4822 instructions += StoreIndexed(kArrayCid); |
4810 instructions += Drop(); | 4823 instructions += Drop(); |
4811 } | 4824 } |
4812 } | 4825 } |
4813 instructions += PushArgument(); // The array. | 4826 instructions += PushArgument(); // The array. |
4814 | 4827 |
4815 fragment_ = instructions + StaticCall(factory_method, 2); | 4828 fragment_ = instructions + StaticCall(node->position(), factory_method, 2); |
4816 } | 4829 } |
4817 | 4830 |
4818 | 4831 |
4819 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) { | 4832 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) { |
4820 fragment_ = TranslateFunctionNode(node->function(), node); | 4833 fragment_ = TranslateFunctionNode(node->function(), node); |
4821 } | 4834 } |
4822 | 4835 |
4823 | 4836 |
4824 void FlowGraphBuilder::VisitLet(Let* node) { | 4837 void FlowGraphBuilder::VisitLet(Let* node) { |
4825 Fragment instructions = TranslateStatement(node->variable()); | 4838 Fragment instructions = TranslateStatement(node->variable()); |
4826 instructions += TranslateExpression(node->body()); | 4839 instructions += TranslateExpression(node->body()); |
4827 fragment_ = instructions; | 4840 fragment_ = instructions; |
4828 } | 4841 } |
4829 | 4842 |
4830 | 4843 |
4831 void FlowGraphBuilder::VisitThrow(Throw* node) { | 4844 void FlowGraphBuilder::VisitThrow(Throw* node) { |
4832 Fragment instructions; | 4845 Fragment instructions; |
4833 | 4846 |
4834 instructions += TranslateExpression(node->expression()); | 4847 instructions += TranslateExpression(node->expression()); |
4835 instructions += PushArgument(); | 4848 instructions += PushArgument(); |
4836 instructions += ThrowException(); | 4849 instructions += ThrowException(node->position()); |
4837 ASSERT(instructions.is_closed()); | 4850 ASSERT(instructions.is_closed()); |
4838 | 4851 |
4839 fragment_ = instructions; | 4852 fragment_ = instructions; |
4840 } | 4853 } |
4841 | 4854 |
4842 | 4855 |
4843 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { | 4856 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { |
4844 Fragment instructions; | 4857 Fragment instructions; |
4845 | 4858 |
4846 instructions += LoadLocal(catch_block_->exception_var()); | 4859 instructions += LoadLocal(catch_block_->exception_var()); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5110 fragment_ = loop; | 5123 fragment_ = loop; |
5111 } | 5124 } |
5112 | 5125 |
5113 | 5126 |
5114 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { | 5127 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { |
5115 Fragment instructions = TranslateExpression(node->iterable()); | 5128 Fragment instructions = TranslateExpression(node->iterable()); |
5116 instructions += PushArgument(); | 5129 instructions += PushArgument(); |
5117 | 5130 |
5118 const dart::String& iterator_getter = dart::String::ZoneHandle( | 5131 const dart::String& iterator_getter = dart::String::ZoneHandle( |
5119 Z, dart::Field::GetterSymbol(Symbols::Iterator())); | 5132 Z, dart::Field::GetterSymbol(Symbols::Iterator())); |
5120 instructions += InstanceCall(iterator_getter, Token::kGET, 1); | 5133 instructions += |
| 5134 InstanceCall(TokenPosition::kNoSource, iterator_getter, Token::kGET, 1); |
5121 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_]; | 5135 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_]; |
5122 instructions += StoreLocal(iterator); | 5136 instructions += StoreLocal(iterator); |
5123 instructions += Drop(); | 5137 instructions += Drop(); |
5124 | 5138 |
5125 ++for_in_depth_; | 5139 ++for_in_depth_; |
5126 ++loop_depth_; | 5140 ++loop_depth_; |
5127 Fragment condition = LoadLocal(iterator); | 5141 Fragment condition = LoadLocal(iterator); |
5128 condition += PushArgument(); | 5142 condition += PushArgument(); |
5129 condition += InstanceCall(Symbols::MoveNext(), Token::kILLEGAL, 1); | 5143 condition += InstanceCall(TokenPosition::kNoSource, Symbols::MoveNext(), |
| 5144 Token::kILLEGAL, 1); |
5130 TargetEntryInstr* body_entry; | 5145 TargetEntryInstr* body_entry; |
5131 TargetEntryInstr* loop_exit; | 5146 TargetEntryInstr* loop_exit; |
5132 condition += BranchIfTrue(&body_entry, &loop_exit); | 5147 condition += BranchIfTrue(&body_entry, &loop_exit); |
5133 | 5148 |
5134 Fragment body(body_entry); | 5149 Fragment body(body_entry); |
5135 body += EnterScope(node); | 5150 body += EnterScope(node); |
5136 body += LoadLocal(iterator); | 5151 body += LoadLocal(iterator); |
5137 body += PushArgument(); | 5152 body += PushArgument(); |
5138 const dart::String& current_getter = dart::String::ZoneHandle( | 5153 const dart::String& current_getter = dart::String::ZoneHandle( |
5139 Z, dart::Field::GetterSymbol(Symbols::Current())); | 5154 Z, dart::Field::GetterSymbol(Symbols::Current())); |
5140 body += InstanceCall(current_getter, Token::kGET, 1); | 5155 body += |
| 5156 InstanceCall(TokenPosition::kNoSource, current_getter, Token::kGET, 1); |
5141 body += StoreLocal(LookupVariable(node->variable())); | 5157 body += StoreLocal(LookupVariable(node->variable())); |
5142 body += Drop(); | 5158 body += Drop(); |
5143 body += TranslateStatement(node->body()); | 5159 body += TranslateStatement(node->body()); |
5144 body += ExitScope(node); | 5160 body += ExitScope(node); |
5145 | 5161 |
5146 if (body.is_open()) { | 5162 if (body.is_open()) { |
5147 JoinEntryInstr* join = BuildJoinEntry(); | 5163 JoinEntryInstr* join = BuildJoinEntry(); |
5148 instructions += Goto(join); | 5164 instructions += Goto(join); |
5149 body += Goto(join); | 5165 body += Goto(join); |
5150 | 5166 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5251 // Call _AssertionError._create constructor. | 5267 // Call _AssertionError._create constructor. |
5252 body_fragment += LoadLocal(instance); | 5268 body_fragment += LoadLocal(instance); |
5253 body_fragment += PushArgument(); // this | 5269 body_fragment += PushArgument(); // this |
5254 | 5270 |
5255 body_fragment += Constant(url); | 5271 body_fragment += Constant(url); |
5256 body_fragment += PushArgument(); // url | 5272 body_fragment += PushArgument(); // url |
5257 | 5273 |
5258 body_fragment += NullConstant(); | 5274 body_fragment += NullConstant(); |
5259 body_fragment += PushArgument(); // line | 5275 body_fragment += PushArgument(); // line |
5260 | 5276 |
5261 body_fragment += StaticCall(constructor, 3); | 5277 body_fragment += StaticCall(TokenPosition::kNoSource, constructor, 3); |
5262 body_fragment += Drop(); | 5278 body_fragment += Drop(); |
5263 | 5279 |
5264 // Throw the exception | 5280 // Throw the exception |
5265 body_fragment += PushArgument(); | 5281 body_fragment += PushArgument(); |
5266 body_fragment += ThrowException(); | 5282 body_fragment += ThrowException(TokenPosition::kNoSource); |
5267 body_fragment += Drop(); | 5283 body_fragment += Drop(); |
5268 } | 5284 } |
5269 | 5285 |
5270 // If there is an implicit fall-through we have one [SwitchCase] and | 5286 // If there is an implicit fall-through we have one [SwitchCase] and |
5271 // multiple expressions, e.g. | 5287 // multiple expressions, e.g. |
5272 // | 5288 // |
5273 // switch(expr) { | 5289 // switch(expr) { |
5274 // case a: | 5290 // case a: |
5275 // case b: | 5291 // case b: |
5276 // <stmt-body> | 5292 // <stmt-body> |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5320 | 5336 |
5321 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) { | 5337 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) { |
5322 TargetEntryInstr* then; | 5338 TargetEntryInstr* then; |
5323 TargetEntryInstr* otherwise; | 5339 TargetEntryInstr* otherwise; |
5324 | 5340 |
5325 current_instructions += Constant(constant_evaluator_.EvaluateExpression( | 5341 current_instructions += Constant(constant_evaluator_.EvaluateExpression( |
5326 switch_case->expressions()[j])); | 5342 switch_case->expressions()[j])); |
5327 current_instructions += PushArgument(); | 5343 current_instructions += PushArgument(); |
5328 current_instructions += LoadLocal(scopes_->switch_variable); | 5344 current_instructions += LoadLocal(scopes_->switch_variable); |
5329 current_instructions += PushArgument(); | 5345 current_instructions += PushArgument(); |
5330 current_instructions += | 5346 current_instructions += InstanceCall( |
5331 InstanceCall(Symbols::EqualOperator(), Token::kEQ, | 5347 TokenPosition::kNoSource, Symbols::EqualOperator(), Token::kEQ, |
5332 /*argument_count=*/2, | 5348 /*argument_count=*/2, |
5333 /*num_args_checked=*/2); | 5349 /*num_args_checked=*/2); |
5334 current_instructions += BranchIfTrue(&then, &otherwise); | 5350 current_instructions += BranchIfTrue(&then, &otherwise); |
5335 | 5351 |
5336 Fragment then_fragment(then); | 5352 Fragment then_fragment(then); |
5337 | 5353 |
5338 if (body_join != NULL) { | 5354 if (body_join != NULL) { |
5339 // There are several branches to the body, so we will make a goto to | 5355 // There are several branches to the body, so we will make a goto to |
5340 // the join block (the real body has already been prepended with a | 5356 // the join block (the real body has already been prepended with a |
5341 // join instruction). | 5357 // join instruction). |
5342 then_fragment += Goto(body_join); | 5358 then_fragment += Goto(body_join); |
5343 } else { | 5359 } else { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5443 | 5459 |
5444 otherwise_fragment += Constant(url); | 5460 otherwise_fragment += Constant(url); |
5445 otherwise_fragment += PushArgument(); // url | 5461 otherwise_fragment += PushArgument(); // url |
5446 | 5462 |
5447 otherwise_fragment += IntConstant(0); | 5463 otherwise_fragment += IntConstant(0); |
5448 otherwise_fragment += PushArgument(); // line | 5464 otherwise_fragment += PushArgument(); // line |
5449 | 5465 |
5450 otherwise_fragment += IntConstant(0); | 5466 otherwise_fragment += IntConstant(0); |
5451 otherwise_fragment += PushArgument(); // column | 5467 otherwise_fragment += PushArgument(); // column |
5452 | 5468 |
5453 otherwise_fragment += StaticCall(constructor, 5); | 5469 otherwise_fragment += StaticCall(TokenPosition::kNoSource, constructor, 5); |
5454 otherwise_fragment += Drop(); | 5470 otherwise_fragment += Drop(); |
5455 | 5471 |
5456 // Throw _AssertionError exception. | 5472 // Throw _AssertionError exception. |
5457 otherwise_fragment += PushArgument(); | 5473 otherwise_fragment += PushArgument(); |
5458 otherwise_fragment += ThrowException(); | 5474 otherwise_fragment += ThrowException(TokenPosition::kNoSource); |
5459 otherwise_fragment += Drop(); | 5475 otherwise_fragment += Drop(); |
5460 | 5476 |
5461 fragment_ = Fragment(instructions.entry, then); | 5477 fragment_ = Fragment(instructions.entry, then); |
5462 } | 5478 } |
5463 | 5479 |
5464 | 5480 |
5465 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) { | 5481 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) { |
5466 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally"); | 5482 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally"); |
5467 | 5483 |
5468 // There are 5 different cases where we need to execute the finally block: | 5484 // There are 5 different cases where we need to execute the finally block: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5603 } else { | 5619 } else { |
5604 catch_body += LoadLocal(CurrentException()); | 5620 catch_body += LoadLocal(CurrentException()); |
5605 catch_body += PushArgument(); // exception | 5621 catch_body += PushArgument(); // exception |
5606 catch_body += NullConstant(); | 5622 catch_body += NullConstant(); |
5607 catch_body += PushArgument(); // type arguments | 5623 catch_body += PushArgument(); // type arguments |
5608 catch_body += Constant(*type_guard); | 5624 catch_body += Constant(*type_guard); |
5609 catch_body += PushArgument(); // guard type | 5625 catch_body += PushArgument(); // guard type |
5610 catch_body += Constant(Object::bool_false()); | 5626 catch_body += Constant(Object::bool_false()); |
5611 catch_body += PushArgument(); // negate | 5627 catch_body += PushArgument(); // negate |
5612 catch_body += InstanceCall( | 5628 catch_body += InstanceCall( |
| 5629 TokenPosition::kNoSource, |
5613 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), | 5630 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), |
5614 Token::kIS, 4); | 5631 Token::kIS, 4); |
5615 | 5632 |
5616 TargetEntryInstr* catch_entry; | 5633 TargetEntryInstr* catch_entry; |
5617 TargetEntryInstr* next_catch_entry; | 5634 TargetEntryInstr* next_catch_entry; |
5618 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); | 5635 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); |
5619 | 5636 |
5620 Fragment(catch_entry) + catch_handler_body; | 5637 Fragment(catch_entry) + catch_handler_body; |
5621 catch_body = Fragment(next_catch_entry); | 5638 catch_body = Fragment(next_catch_entry); |
5622 } | 5639 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5720 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, | 5737 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, |
5721 TreeNode* parent) { | 5738 TreeNode* parent) { |
5722 // The VM has a per-isolate table of functions indexed by the enclosing | 5739 // The VM has a per-isolate table of functions indexed by the enclosing |
5723 // function and token position. We don't have token positions, so we've | 5740 // function and token position. We don't have token positions, so we've |
5724 // simply numbered the immediately-nested functions with respect to the | 5741 // simply numbered the immediately-nested functions with respect to the |
5725 // parent. | 5742 // parent. |
5726 Function& function = Function::ZoneHandle(Z); | 5743 Function& function = Function::ZoneHandle(Z); |
5727 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) { | 5744 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) { |
5728 if (scopes_->function_scopes[i].function != node) continue; | 5745 if (scopes_->function_scopes[i].function != node) continue; |
5729 | 5746 |
| 5747 // NOTE: This is not TokenPosition in the general sense! |
5730 function = I->LookupClosureFunction(parsed_function_->function(), | 5748 function = I->LookupClosureFunction(parsed_function_->function(), |
5731 TokenPosition(i)); | 5749 TokenPosition(i)); |
5732 if (function.IsNull()) { | 5750 if (function.IsNull()) { |
5733 const dart::String* name; | 5751 const dart::String* name; |
5734 if (parent->IsFunctionExpression()) { | 5752 if (parent->IsFunctionExpression()) { |
5735 name = &Symbols::AnonymousClosure(); | 5753 name = &Symbols::AnonymousClosure(); |
5736 } else { | 5754 } else { |
5737 ASSERT(parent->IsFunctionDeclaration()); | 5755 ASSERT(parent->IsFunctionDeclaration()); |
5738 name = &H.DartSymbol( | 5756 name = &H.DartSymbol( |
5739 FunctionDeclaration::Cast(parent)->variable()->name()); | 5757 FunctionDeclaration::Cast(parent)->variable()->name()); |
5740 } | 5758 } |
| 5759 // NOTE: This is not TokenPosition in the general sense! |
5741 function = Function::NewClosureFunction( | 5760 function = Function::NewClosureFunction( |
5742 *name, parsed_function_->function(), TokenPosition(i)); | 5761 *name, parsed_function_->function(), TokenPosition(i)); |
5743 function.set_is_debuggable(false); | 5762 function.set_is_debuggable(false); |
5744 LocalScope* scope = scopes_->function_scopes[i].scope; | 5763 LocalScope* scope = scopes_->function_scopes[i].scope; |
5745 const ContextScope& context_scope = | 5764 const ContextScope& context_scope = |
5746 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); | 5765 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); |
5747 function.set_context_scope(context_scope); | 5766 function.set_context_scope(context_scope); |
5748 function.set_kernel_function(node); | 5767 function.set_kernel_function(node); |
5749 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), | 5768 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), |
5750 function, node, | 5769 function, node, |
(...skipping 27 matching lines...) Expand all Loading... |
5778 instructions += LoadLocal(parsed_function_->current_context_var()); | 5797 instructions += LoadLocal(parsed_function_->current_context_var()); |
5779 instructions += StoreInstanceField(Closure::context_offset()); | 5798 instructions += StoreInstanceField(Closure::context_offset()); |
5780 | 5799 |
5781 return instructions; | 5800 return instructions; |
5782 } | 5801 } |
5783 | 5802 |
5784 | 5803 |
5785 } // namespace kernel | 5804 } // namespace kernel |
5786 } // namespace dart | 5805 } // namespace dart |
5787 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 5806 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |