Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(119)

Side by Side Diff: runtime/vm/kernel_to_il.cc

Issue 2512653002: Merge of source position information from kernel-sdk. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2451 Fragment FlowGraphBuilder::Return() { 2452 Fragment FlowGraphBuilder::Return() {
2452 Value* value = Pop(); 2453 Value* value = Pop();
2453 ASSERT(stack_ == NULL); 2454 ASSERT(stack_ == NULL);
2454 ReturnInstr* return_instr = 2455 ReturnInstr* return_instr =
2455 new (Z) ReturnInstr(TokenPosition::kNoSource, value); 2456 new (Z) ReturnInstr(TokenPosition::kNoSource, value);
2456 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr); 2457 if (exit_collector_ != NULL) exit_collector_->AddExit(return_instr);
2457 return Fragment(return_instr).closed(); 2458 return Fragment(return_instr).closed();
2458 } 2459 }
2459 2460
2460 2461
2461 Fragment FlowGraphBuilder::StaticCall(const Function& target, 2462 Fragment FlowGraphBuilder::StaticCall(TokenPosition position,
2463 const Function& target,
2462 intptr_t argument_count) { 2464 intptr_t argument_count) {
2463 return StaticCall(target, argument_count, Array::null_array()); 2465 return StaticCall(position, target, argument_count, Array::null_array());
2464 } 2466 }
2465 2467
2466 2468
2467 static intptr_t GetResultCidOfListFactory(Zone* zone, 2469 static intptr_t GetResultCidOfListFactory(Zone* zone,
2468 const Function& function, 2470 const Function& function,
2469 intptr_t argument_count) { 2471 intptr_t argument_count) {
2470 if (!function.IsFactory()) { 2472 if (!function.IsFactory()) {
2471 return kDynamicCid; 2473 return kDynamicCid;
2472 } 2474 }
2473 2475
2474 const dart::Class& owner = dart::Class::Handle(zone, function.Owner()); 2476 const dart::Class& owner = dart::Class::Handle(zone, function.Owner());
2475 if ((owner.library() != dart::Library::CoreLibrary()) && 2477 if ((owner.library() != dart::Library::CoreLibrary()) &&
2476 (owner.library() != dart::Library::TypedDataLibrary())) { 2478 (owner.library() != dart::Library::TypedDataLibrary())) {
2477 return kDynamicCid; 2479 return kDynamicCid;
2478 } 2480 }
2479 2481
2480 if ((owner.Name() == Symbols::List().raw()) && 2482 if ((owner.Name() == Symbols::List().raw()) &&
2481 (function.name() == Symbols::ListFactory().raw())) { 2483 (function.name() == Symbols::ListFactory().raw())) {
2482 ASSERT(argument_count == 1 || argument_count == 2); 2484 ASSERT(argument_count == 1 || argument_count == 2);
2483 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid; 2485 return (argument_count == 1) ? kGrowableObjectArrayCid : kArrayCid;
2484 } 2486 }
2485 return FactoryRecognizer::ResultCid(function); 2487 return FactoryRecognizer::ResultCid(function);
2486 } 2488 }
2487 2489
2488 2490
2489 Fragment FlowGraphBuilder::StaticCall(const Function& target, 2491 Fragment FlowGraphBuilder::StaticCall(TokenPosition position,
2492 const Function& target,
2490 intptr_t argument_count, 2493 intptr_t argument_count,
2491 const Array& argument_names) { 2494 const Array& argument_names) {
2492 ArgumentArray arguments = GetArguments(argument_count); 2495 ArgumentArray arguments = GetArguments(argument_count);
2493 StaticCallInstr* call = 2496 StaticCallInstr* call = new (Z) StaticCallInstr(
2494 new (Z) StaticCallInstr(TokenPosition::kNoSource, target, argument_names, 2497 position, target, argument_names, arguments, ic_data_array_);
2495 arguments, ic_data_array_);
2496 const intptr_t list_cid = 2498 const intptr_t list_cid =
2497 GetResultCidOfListFactory(Z, target, argument_count); 2499 GetResultCidOfListFactory(Z, target, argument_count);
2498 if (list_cid != kDynamicCid) { 2500 if (list_cid != kDynamicCid) {
2499 call->set_result_cid(list_cid); 2501 call->set_result_cid(list_cid);
2500 call->set_is_known_list_constructor(true); 2502 call->set_is_known_list_constructor(true);
2501 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) { 2503 } else if (target.recognized_kind() != MethodRecognizer::kUnknown) {
2502 call->set_result_cid(MethodRecognizer::ResultCid(target)); 2504 call->set_result_cid(MethodRecognizer::ResultCid(target));
2503 } 2505 }
2504 Push(call); 2506 Push(call);
2505 return Fragment(call); 2507 return Fragment(call);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2622 2624
2623 instructions += NullConstant(); 2625 instructions += NullConstant();
2624 instructions += PushArgument(); // line 2626 instructions += PushArgument(); // line
2625 2627
2626 instructions += IntConstant(0); 2628 instructions += IntConstant(0);
2627 instructions += PushArgument(); // column 2629 instructions += PushArgument(); // column
2628 2630
2629 instructions += Constant(H.DartSymbol("Malformed type.")); 2631 instructions += Constant(H.DartSymbol("Malformed type."));
2630 instructions += PushArgument(); // message 2632 instructions += PushArgument(); // message
2631 2633
2632 instructions += StaticCall(constructor, 5); 2634 instructions += StaticCall(TokenPosition::kNoSource, constructor, 5);
2633 instructions += Drop(); 2635 instructions += Drop();
2634 2636
2635 // Throw the exception 2637 // Throw the exception
2636 instructions += PushArgument(); 2638 instructions += PushArgument();
2637 instructions += ThrowException(); 2639 instructions += ThrowException(TokenPosition::kNoSource);
2638 2640
2639 return instructions; 2641 return instructions;
2640 } 2642 }
2641 2643
2642 2644
2643 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() { 2645 Fragment FlowGraphBuilder::ThrowNoSuchMethodError() {
2644 const dart::Class& klass = dart::Class::ZoneHandle( 2646 const dart::Class& klass = dart::Class::ZoneHandle(
2645 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError())); 2647 Z, dart::Library::LookupCoreClass(Symbols::NoSuchMethodError()));
2646 ASSERT(!klass.IsNull()); 2648 ASSERT(!klass.IsNull());
2647 const dart::Function& throw_function = dart::Function::ZoneHandle( 2649 const dart::Function& throw_function = dart::Function::ZoneHandle(
(...skipping 14 matching lines...) Expand all
2662 2664
2663 instructions += NullConstant(); 2665 instructions += NullConstant();
2664 instructions += PushArgument(); // arguments 2666 instructions += PushArgument(); // arguments
2665 2667
2666 instructions += NullConstant(); 2668 instructions += NullConstant();
2667 instructions += PushArgument(); // argumentNames 2669 instructions += PushArgument(); // argumentNames
2668 2670
2669 instructions += NullConstant(); 2671 instructions += NullConstant();
2670 instructions += PushArgument(); // existingArgumentNames 2672 instructions += PushArgument(); // existingArgumentNames
2671 2673
2672 instructions += StaticCall(throw_function, 6); 2674 instructions += StaticCall(TokenPosition::kNoSource, throw_function, 6);
2673 // Leave "result" on the stack since callers expect it to be there (even 2675 // Leave "result" on the stack since callers expect it to be there (even
2674 // though the function will result in an exception). 2676 // though the function will result in an exception).
2675 2677
2676 return instructions; 2678 return instructions;
2677 } 2679 }
2678 2680
2679 2681
2680 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember( 2682 dart::RawFunction* FlowGraphBuilder::LookupMethodByMember(
2681 Member* target, 2683 Member* target,
2682 const dart::String& method_name) { 2684 const dart::String& method_name) {
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
3424 for (intptr_t i = 0; i < named_argument_count; i++) { 3426 for (intptr_t i = 0; i < named_argument_count; i++) {
3425 VariableDeclaration* variable = kernel_function->named_parameters()[i]; 3427 VariableDeclaration* variable = kernel_function->named_parameters()[i];
3426 body += LoadLocal(LookupVariable(variable)); 3428 body += LoadLocal(LookupVariable(variable));
3427 body += PushArgument(); 3429 body += PushArgument();
3428 argument_names.SetAt(i, H.DartSymbol(variable->name())); 3430 argument_names.SetAt(i, H.DartSymbol(variable->name()));
3429 } 3431 }
3430 } 3432 }
3431 // Forward them to the target. 3433 // Forward them to the target.
3432 intptr_t argument_count = positional_argument_count + named_argument_count; 3434 intptr_t argument_count = positional_argument_count + named_argument_count;
3433 if (!target.is_static()) ++argument_count; 3435 if (!target.is_static()) ++argument_count;
3434 body += StaticCall(target, argument_count, argument_names); 3436 body += StaticCall(TokenPosition::kNoSource, target, argument_count,
3437 argument_names);
3435 3438
3436 // Return the result. 3439 // Return the result.
3437 body += Return(); 3440 body += Return();
3438 3441
3439 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3442 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3440 } 3443 }
3441 3444
3442 3445
3443 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher( 3446 FlowGraph* FlowGraphBuilder::BuildGraphOfNoSuchMethodDispatcher(
3444 const Function& function) { 3447 const Function& function) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
3511 body += Constant(Bool::False()); 3514 body += Constant(Bool::False());
3512 body += PushArgument(); 3515 body += PushArgument();
3513 3516
3514 const dart::Class& mirror_class = dart::Class::Handle( 3517 const dart::Class& mirror_class = dart::Class::Handle(
3515 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror())); 3518 Z, dart::Library::LookupCoreClass(Symbols::InvocationMirror()));
3516 ASSERT(!mirror_class.IsNull()); 3519 ASSERT(!mirror_class.IsNull());
3517 const Function& allocation_function = Function::ZoneHandle( 3520 const Function& allocation_function = Function::ZoneHandle(
3518 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName( 3521 Z, mirror_class.LookupStaticFunction(dart::Library::PrivateCoreLibName(
3519 Symbols::AllocateInvocationMirror()))); 3522 Symbols::AllocateInvocationMirror())));
3520 ASSERT(!allocation_function.IsNull()); 3523 ASSERT(!allocation_function.IsNull());
3521 body += StaticCall(allocation_function, 4); 3524 body += StaticCall(TokenPosition::kMinSource, allocation_function, 4);
3522 body += PushArgument(); // For the call to noSuchMethod. 3525 body += PushArgument(); // For the call to noSuchMethod.
3523 3526
3524 ArgumentsDescriptor two_arguments( 3527 ArgumentsDescriptor two_arguments(
3525 Array::Handle(Z, ArgumentsDescriptor::New(2))); 3528 Array::Handle(Z, ArgumentsDescriptor::New(2)));
3526 Function& no_such_method = 3529 Function& no_such_method =
3527 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass( 3530 Function::ZoneHandle(Z, Resolver::ResolveDynamicForReceiverClass(
3528 dart::Class::Handle(Z, function.Owner()), 3531 dart::Class::Handle(Z, function.Owner()),
3529 Symbols::NoSuchMethod(), two_arguments)); 3532 Symbols::NoSuchMethod(), two_arguments));
3530 if (no_such_method.IsNull()) { 3533 if (no_such_method.IsNull()) {
3531 // If noSuchMethod is not found on the receiver class, call 3534 // If noSuchMethod is not found on the receiver class, call
3532 // Object.noSuchMethod. 3535 // Object.noSuchMethod.
3533 no_such_method = Resolver::ResolveDynamicForReceiverClass( 3536 no_such_method = Resolver::ResolveDynamicForReceiverClass(
3534 dart::Class::Handle(Z, I->object_store()->object_class()), 3537 dart::Class::Handle(Z, I->object_store()->object_class()),
3535 Symbols::NoSuchMethod(), two_arguments); 3538 Symbols::NoSuchMethod(), two_arguments);
3536 } 3539 }
3537 body += StaticCall(no_such_method, 2); 3540 body += StaticCall(TokenPosition::kMinSource, no_such_method, 2);
3538 body += Return(); 3541 body += Return();
3539 3542
3540 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3543 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3541 } 3544 }
3542 3545
3543 3546
3544 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher( 3547 FlowGraph* FlowGraphBuilder::BuildGraphOfInvokeFieldDispatcher(
3545 const Function& function) { 3548 const Function& function) {
3546 // Find the name of the field we should dispatch to. 3549 // Find the name of the field we should dispatch to.
3547 const dart::Class& owner = dart::Class::Handle(Z, function.Owner()); 3550 const dart::Class& owner = dart::Class::Handle(Z, function.Owner());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
3591 LocalVariable* closure = NULL; 3594 LocalVariable* closure = NULL;
3592 if (is_closure_call) { 3595 if (is_closure_call) {
3593 closure = scope->VariableAt(0); 3596 closure = scope->VariableAt(0);
3594 3597
3595 // The closure itself is the first argument. 3598 // The closure itself is the first argument.
3596 body += LoadLocal(closure); 3599 body += LoadLocal(closure);
3597 } else { 3600 } else {
3598 // Invoke the getter to get the field value. 3601 // Invoke the getter to get the field value.
3599 body += LoadLocal(scope->VariableAt(0)); 3602 body += LoadLocal(scope->VariableAt(0));
3600 body += PushArgument(); 3603 body += PushArgument();
3601 body += InstanceCall(getter_name, Token::kGET, 1); 3604 body +=
3605 InstanceCall(TokenPosition::kMinSource, getter_name, Token::kGET, 1);
3602 } 3606 }
3603 3607
3604 body += PushArgument(); 3608 body += PushArgument();
3605 3609
3606 // Push all arguments onto the stack. 3610 // Push all arguments onto the stack.
3607 intptr_t pos = 1; 3611 intptr_t pos = 1;
3608 for (; pos < descriptor.Count(); pos++) { 3612 for (; pos < descriptor.Count(); pos++) {
3609 body += LoadLocal(scope->VariableAt(pos)); 3613 body += LoadLocal(scope->VariableAt(pos));
3610 body += PushArgument(); 3614 body += PushArgument();
3611 } 3615 }
3612 3616
3613 if (is_closure_call) { 3617 if (is_closure_call) {
3614 // Lookup the function in the closure. 3618 // Lookup the function in the closure.
3615 body += LoadLocal(closure); 3619 body += LoadLocal(closure);
3616 body += LoadField(Closure::function_offset()); 3620 body += LoadField(Closure::function_offset());
3617 3621
3618 body += ClosureCall(descriptor.Count(), argument_names); 3622 body += ClosureCall(descriptor.Count(), argument_names);
3619 } else { 3623 } else {
3620 body += InstanceCall(Symbols::Call(), Token::kILLEGAL, descriptor.Count(), 3624 body += InstanceCall(TokenPosition::kMinSource, Symbols::Call(),
3621 argument_names); 3625 Token::kILLEGAL, descriptor.Count(), argument_names);
3622 } 3626 }
3623 3627
3624 body += Return(); 3628 body += Return();
3625 3629
3626 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1); 3630 return new (Z) FlowGraph(*parsed_function_, graph_entry_, next_block_id_ - 1);
3627 } 3631 }
3628 3632
3629 3633
3630 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) { 3634 void FlowGraphBuilder::SetupDefaultParameterValues(FunctionNode* function) {
3631 intptr_t num_optional_parameters = 3635 intptr_t num_optional_parameters =
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3724 instructions += LoadLocal(scopes_->this_variable); 3728 instructions += LoadLocal(scopes_->this_variable);
3725 instructions += PushArgument(); 3729 instructions += PushArgument();
3726 3730
3727 ASSERT(init->arguments()->types().length() == 0); 3731 ASSERT(init->arguments()->types().length() == 0);
3728 Array& argument_names = Array::ZoneHandle(Z); 3732 Array& argument_names = Array::ZoneHandle(Z);
3729 instructions += TranslateArguments(init->arguments(), &argument_names); 3733 instructions += TranslateArguments(init->arguments(), &argument_names);
3730 3734
3731 const Function& target = Function::ZoneHandle( 3735 const Function& target = Function::ZoneHandle(
3732 Z, H.LookupConstructorByKernelConstructor(init->target())); 3736 Z, H.LookupConstructorByKernelConstructor(init->target()));
3733 intptr_t argument_count = init->arguments()->count() + 1; 3737 intptr_t argument_count = init->arguments()->count() + 1;
3734 instructions += StaticCall(target, argument_count, argument_names); 3738 instructions += StaticCall(TokenPosition::kNoSource, target,
3739 argument_count, argument_names);
3735 instructions += Drop(); 3740 instructions += Drop();
3736 } else if (initializer->IsRedirectingInitializer()) { 3741 } else if (initializer->IsRedirectingInitializer()) {
3737 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer); 3742 RedirectingInitializer* init = RedirectingInitializer::Cast(initializer);
3738 3743
3739 instructions += LoadLocal(scopes_->this_variable); 3744 instructions += LoadLocal(scopes_->this_variable);
3740 instructions += PushArgument(); 3745 instructions += PushArgument();
3741 3746
3742 ASSERT(init->arguments()->types().length() == 0); 3747 ASSERT(init->arguments()->types().length() == 0);
3743 Array& argument_names = Array::ZoneHandle(Z); 3748 Array& argument_names = Array::ZoneHandle(Z);
3744 instructions += TranslateArguments(init->arguments(), &argument_names); 3749 instructions += TranslateArguments(init->arguments(), &argument_names);
3745 3750
3746 const Function& target = Function::ZoneHandle( 3751 const Function& target = Function::ZoneHandle(
3747 Z, H.LookupConstructorByKernelConstructor(init->target())); 3752 Z, H.LookupConstructorByKernelConstructor(init->target()));
3748 intptr_t argument_count = init->arguments()->count() + 1; 3753 intptr_t argument_count = init->arguments()->count() + 1;
3749 instructions += StaticCall(target, argument_count, argument_names); 3754 instructions += StaticCall(TokenPosition::kNoSource, target,
3755 argument_count, argument_names);
3750 instructions += Drop(); 3756 instructions += Drop();
3751 } else if (initializer->IsLocalInitializer()) { 3757 } else if (initializer->IsLocalInitializer()) {
3752 // The other initializers following this one might read the variable. This 3758 // The other initializers following this one might read the variable. This
3753 // is used e.g. for evaluating the arguments to a super call first, run 3759 // is used e.g. for evaluating the arguments to a super call first, run
3754 // normal field initializers next and then make the actual super call: 3760 // normal field initializers next and then make the actual super call:
3755 // 3761 //
3756 // The frontend converts 3762 // The frontend converts
3757 // 3763 //
3758 // class A { 3764 // class A {
3759 // var x; 3765 // var x;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node)); 4172 fragment_ = Constant(constant_evaluator_.EvaluateExpression(node));
4167 } else { 4173 } else {
4168 const dart::Class& owner = dart::Class::Handle(Z, field.Owner()); 4174 const dart::Class& owner = dart::Class::Handle(Z, field.Owner());
4169 const dart::String& getter_name = H.DartGetterName(kernel_field->name()); 4175 const dart::String& getter_name = H.DartGetterName(kernel_field->name());
4170 const Function& getter = 4176 const Function& getter =
4171 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name)); 4177 Function::ZoneHandle(Z, owner.LookupStaticFunction(getter_name));
4172 if (getter.IsNull() || !field.has_initializer()) { 4178 if (getter.IsNull() || !field.has_initializer()) {
4173 Fragment instructions = Constant(field); 4179 Fragment instructions = Constant(field);
4174 fragment_ = instructions + LoadStaticField(); 4180 fragment_ = instructions + LoadStaticField();
4175 } else { 4181 } else {
4176 fragment_ = StaticCall(getter, 0); 4182 fragment_ = StaticCall(node->position(), getter, 0);
4177 } 4183 }
4178 } 4184 }
4179 } else { 4185 } else {
4180 Procedure* procedure = Procedure::Cast(target); 4186 Procedure* procedure = Procedure::Cast(target);
4181 const Function& target = Function::ZoneHandle( 4187 const Function& target = Function::ZoneHandle(
4182 Z, H.LookupStaticMethodByKernelProcedure(procedure)); 4188 Z, H.LookupStaticMethodByKernelProcedure(procedure));
4183 4189
4184 if (procedure->kind() == Procedure::kGetter) { 4190 if (procedure->kind() == Procedure::kGetter) {
4185 fragment_ = StaticCall(target, 0); 4191 fragment_ = StaticCall(node->position(), target, 0);
4186 } else if (procedure->kind() == Procedure::kMethod) { 4192 } else if (procedure->kind() == Procedure::kMethod) {
4187 ASSERT(procedure->IsStatic()); 4193 ASSERT(procedure->IsStatic());
4188 Function& closure_function = 4194 Function& closure_function =
4189 Function::ZoneHandle(Z, target.ImplicitClosureFunction()); 4195 Function::ZoneHandle(Z, target.ImplicitClosureFunction());
4190 closure_function.set_kernel_function(target.kernel_function()); 4196 closure_function.set_kernel_function(target.kernel_function());
4191 const Instance& closure = 4197 const Instance& closure =
4192 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure()); 4198 Instance::ZoneHandle(Z, closure_function.ImplicitStaticClosure());
4193 fragment_ = Constant(closure); 4199 fragment_ = Constant(closure);
4194 } else { 4200 } else {
4195 UNIMPLEMENTED(); 4201 UNIMPLEMENTED();
(...skipping 20 matching lines...) Expand all
4216 LocalVariable* variable = MakeTemporary(); 4222 LocalVariable* variable = MakeTemporary();
4217 4223
4218 // Prepare argument. 4224 // Prepare argument.
4219 instructions += LoadLocal(variable); 4225 instructions += LoadLocal(variable);
4220 instructions += PushArgument(); 4226 instructions += PushArgument();
4221 4227
4222 // Invoke the setter function. 4228 // Invoke the setter function.
4223 Procedure* procedure = Procedure::Cast(target); 4229 Procedure* procedure = Procedure::Cast(target);
4224 const Function& target = Function::ZoneHandle( 4230 const Function& target = Function::ZoneHandle(
4225 Z, H.LookupStaticMethodByKernelProcedure(procedure)); 4231 Z, H.LookupStaticMethodByKernelProcedure(procedure));
4226 instructions += StaticCall(target, 1); 4232 instructions += StaticCall(node->position(), target, 1);
4227 4233
4228 // Drop the unused result & leave the stored value on the stack. 4234 // Drop the unused result & leave the stored value on the stack.
4229 fragment_ = instructions + Drop(); 4235 fragment_ = instructions + Drop();
4230 } 4236 }
4231 } 4237 }
4232 4238
4233 4239
4234 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) { 4240 void FlowGraphBuilder::VisitPropertyGet(PropertyGet* node) {
4235 Fragment instructions = TranslateExpression(node->receiver()); 4241 Fragment instructions = TranslateExpression(node->receiver());
4236 instructions += PushArgument(); 4242 instructions += PushArgument();
4237 const dart::String& getter_name = H.DartGetterName(node->name()); 4243 const dart::String& getter_name = H.DartGetterName(node->name());
4238 fragment_ = instructions + InstanceCall(getter_name, Token::kGET, 1); 4244 fragment_ = instructions +
4245 InstanceCall(node->position(), getter_name, Token::kGET, 1);
4239 } 4246 }
4240 4247
4241 4248
4242 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) { 4249 void FlowGraphBuilder::VisitPropertySet(PropertySet* node) {
4243 Fragment instructions(NullConstant()); 4250 Fragment instructions(NullConstant());
4244 LocalVariable* variable = MakeTemporary(); 4251 LocalVariable* variable = MakeTemporary();
4245 instructions += TranslateExpression(node->receiver()); 4252 instructions += TranslateExpression(node->receiver());
4246 instructions += PushArgument(); 4253 instructions += PushArgument();
4247 instructions += TranslateExpression(node->value()); 4254 instructions += TranslateExpression(node->value());
4248 instructions += StoreLocal(variable); 4255 instructions += StoreLocal(variable);
4249 instructions += PushArgument(); 4256 instructions += PushArgument();
4250 4257
4251 const dart::String& setter_name = H.DartSetterName(node->name()); 4258 const dart::String& setter_name = H.DartSetterName(node->name());
4252 instructions += InstanceCall(setter_name, Token::kSET, 2); 4259 instructions += InstanceCall(node->position(), setter_name, Token::kSET, 2);
4253 fragment_ = instructions + Drop(); 4260 fragment_ = instructions + Drop();
4254 } 4261 }
4255 4262
4256 4263
4257 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) { 4264 void FlowGraphBuilder::VisitDirectPropertyGet(DirectPropertyGet* node) {
4258 Function& target = Function::ZoneHandle(Z); 4265 Function& target = Function::ZoneHandle(Z);
4259 if (node->target()->IsProcedure()) { 4266 if (node->target()->IsProcedure()) {
4260 Procedure* kernel_procedure = Procedure::Cast(node->target()); 4267 Procedure* kernel_procedure = Procedure::Cast(node->target());
4261 Name* kernel_name = kernel_procedure->name(); 4268 Name* kernel_name = kernel_procedure->name();
4262 if (kernel_procedure->kind() == Procedure::kGetter) { 4269 if (kernel_procedure->kind() == Procedure::kGetter) {
4263 target = 4270 target =
4264 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name)); 4271 LookupMethodByMember(kernel_procedure, H.DartGetterName(kernel_name));
4265 } else { 4272 } else {
4266 target = 4273 target =
4267 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name)); 4274 LookupMethodByMember(kernel_procedure, H.DartMethodName(kernel_name));
4268 target = target.ImplicitClosureFunction(); 4275 target = target.ImplicitClosureFunction();
4269 ASSERT(!target.IsNull()); 4276 ASSERT(!target.IsNull());
4270 fragment_ = BuildImplicitClosureCreation(target); 4277 fragment_ = BuildImplicitClosureCreation(target);
4271 return; 4278 return;
4272 } 4279 }
4273 } else { 4280 } else {
4274 ASSERT(node->target()->IsField()); 4281 ASSERT(node->target()->IsField());
4275 const dart::String& getter_name = H.DartGetterName(node->target()->name()); 4282 const dart::String& getter_name = H.DartGetterName(node->target()->name());
4276 target = LookupMethodByMember(node->target(), getter_name); 4283 target = LookupMethodByMember(node->target(), getter_name);
4277 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction()); 4284 ASSERT(target.IsGetterFunction() || target.IsImplicitGetterFunction());
4278 } 4285 }
4279 4286
4280 Fragment instructions = TranslateExpression(node->receiver()); 4287 Fragment instructions = TranslateExpression(node->receiver());
4281 instructions += PushArgument(); 4288 instructions += PushArgument();
4282 fragment_ = instructions + StaticCall(target, 1); 4289 fragment_ = instructions + StaticCall(node->position(), target, 1);
4283 } 4290 }
4284 4291
4285 4292
4286 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) { 4293 void FlowGraphBuilder::VisitDirectPropertySet(DirectPropertySet* node) {
4287 const dart::String& method_name = H.DartSetterName(node->target()->name()); 4294 const dart::String& method_name = H.DartSetterName(node->target()->name());
4288 const Function& target = Function::ZoneHandle( 4295 const Function& target = Function::ZoneHandle(
4289 Z, LookupMethodByMember(node->target(), method_name)); 4296 Z, LookupMethodByMember(node->target(), method_name));
4290 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction()); 4297 ASSERT(target.IsSetterFunction() || target.IsImplicitSetterFunction());
4291 4298
4292 Fragment instructions(NullConstant()); 4299 Fragment instructions(NullConstant());
4293 LocalVariable* value = MakeTemporary(); 4300 LocalVariable* value = MakeTemporary();
4294 instructions += TranslateExpression(node->receiver()); 4301 instructions += TranslateExpression(node->receiver());
4295 instructions += PushArgument(); 4302 instructions += PushArgument();
4296 instructions += TranslateExpression(node->value()); 4303 instructions += TranslateExpression(node->value());
4297 instructions += StoreLocal(value); 4304 instructions += StoreLocal(value);
4298 instructions += PushArgument(); 4305 instructions += PushArgument();
4299 instructions += StaticCall(target, 2); 4306 instructions += StaticCall(node->position(), target, 2);
4300 4307
4301 fragment_ = instructions + Drop(); 4308 fragment_ = instructions + Drop();
4302 } 4309 }
4303 4310
4304 4311
4305 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) { 4312 void FlowGraphBuilder::VisitStaticInvocation(StaticInvocation* node) {
4306 const Function& target = Function::ZoneHandle( 4313 const Function& target = Function::ZoneHandle(
4307 Z, H.LookupStaticMethodByKernelProcedure(node->procedure())); 4314 Z, H.LookupStaticMethodByKernelProcedure(node->procedure()));
4308 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner()); 4315 const dart::Class& klass = dart::Class::ZoneHandle(Z, target.Owner());
4309 intptr_t argument_count = node->arguments()->count(); 4316 intptr_t argument_count = node->arguments()->count();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 (target.name() == Symbols::Identical().raw())) { 4381 (target.name() == Symbols::Identical().raw())) {
4375 ASSERT(argument_count == 2); 4382 ASSERT(argument_count == 2);
4376 4383
4377 List<Expression>& positional = node->arguments()->positional(); 4384 List<Expression>& positional = node->arguments()->positional();
4378 for (intptr_t i = 0; i < positional.length(); ++i) { 4385 for (intptr_t i = 0; i < positional.length(); ++i) {
4379 instructions += TranslateExpression(positional[i]); 4386 instructions += TranslateExpression(positional[i]);
4380 } 4387 }
4381 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true); 4388 instructions += StrictCompare(Token::kEQ_STRICT, /*number_check=*/true);
4382 } else { 4389 } else {
4383 instructions += TranslateArguments(node->arguments(), NULL); 4390 instructions += TranslateArguments(node->arguments(), NULL);
4384 instructions += StaticCall(target, argument_count, argument_names); 4391 instructions +=
4392 StaticCall(node->position(), target, argument_count, argument_names);
4385 4393
4386 if (target.IsGenerativeConstructor()) { 4394 if (target.IsGenerativeConstructor()) {
4387 // Drop the result of the constructor call and leave [instance_variable] 4395 // Drop the result of the constructor call and leave [instance_variable]
4388 // on top-of-stack. 4396 // on top-of-stack.
4389 instructions += Drop(); 4397 instructions += Drop();
4390 } 4398 }
4391 } 4399 }
4392 4400
4393 fragment_ = instructions; 4401 fragment_ = instructions;
4394 } 4402 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4431 instructions += TranslateArguments(node->arguments(), &argument_names); 4439 instructions += TranslateArguments(node->arguments(), &argument_names);
4432 4440
4433 intptr_t num_args_checked = 1; 4441 intptr_t num_args_checked = 1;
4434 // If we have a special operation (e.g. +/-/==) we mark both arguments as 4442 // If we have a special operation (e.g. +/-/==) we mark both arguments as
4435 // to be checked. 4443 // to be checked.
4436 if (token_kind != Token::kILLEGAL) { 4444 if (token_kind != Token::kILLEGAL) {
4437 ASSERT(argument_count <= 2); 4445 ASSERT(argument_count <= 2);
4438 num_args_checked = argument_count; 4446 num_args_checked = argument_count;
4439 } 4447 }
4440 4448
4441 fragment_ = instructions + InstanceCall(name, token_kind, argument_count, 4449 fragment_ = instructions + InstanceCall(node->position(), name, token_kind,
4442 argument_names, num_args_checked); 4450 argument_count, argument_names,
4451 num_args_checked);
4443 } 4452 }
4444 4453
4445 4454
4446 void FlowGraphBuilder::VisitDirectMethodInvocation( 4455 void FlowGraphBuilder::VisitDirectMethodInvocation(
4447 DirectMethodInvocation* node) { 4456 DirectMethodInvocation* node) {
4448 const dart::String& method_name = H.DartMethodName(node->target()->name()); 4457 const dart::String& method_name = H.DartMethodName(node->target()->name());
4449 const Function& target = Function::ZoneHandle( 4458 const Function& target = Function::ZoneHandle(
4450 Z, LookupMethodByMember(node->target(), method_name)); 4459 Z, LookupMethodByMember(node->target(), method_name));
4451 4460
4452 intptr_t argument_count = node->arguments()->count() + 1; 4461 intptr_t argument_count = node->arguments()->count() + 1;
4453 Array& argument_names = Array::ZoneHandle(Z); 4462 Array& argument_names = Array::ZoneHandle(Z);
4454 4463
4455 ASSERT(node->arguments()->types().length() == 0); 4464 ASSERT(node->arguments()->types().length() == 0);
4456 Fragment instructions = TranslateExpression(node->receiver()); 4465 Fragment instructions = TranslateExpression(node->receiver());
4457 instructions += PushArgument(); 4466 instructions += PushArgument();
4458 instructions += TranslateArguments(node->arguments(), &argument_names); 4467 instructions += TranslateArguments(node->arguments(), &argument_names);
4459 fragment_ = instructions + StaticCall(target, argument_count, argument_names); 4468 fragment_ = instructions + StaticCall(node->position(), target,
4469 argument_count, argument_names);
4460 } 4470 }
4461 4471
4462 4472
4463 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) { 4473 void FlowGraphBuilder::VisitConstructorInvocation(ConstructorInvocation* node) {
4464 if (node->is_const()) { 4474 if (node->is_const()) {
4465 fragment_ = 4475 fragment_ =
4466 Constant(constant_evaluator_.EvaluateConstructorInvocation(node)); 4476 Constant(constant_evaluator_.EvaluateConstructorInvocation(node));
4467 return; 4477 return;
4468 } 4478 }
4469 4479
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4509 4519
4510 instructions += LoadLocal(variable); 4520 instructions += LoadLocal(variable);
4511 instructions += PushArgument(); 4521 instructions += PushArgument();
4512 4522
4513 Array& argument_names = Array::ZoneHandle(Z); 4523 Array& argument_names = Array::ZoneHandle(Z);
4514 instructions += TranslateArguments(node->arguments(), &argument_names); 4524 instructions += TranslateArguments(node->arguments(), &argument_names);
4515 4525
4516 const Function& target = Function::ZoneHandle( 4526 const Function& target = Function::ZoneHandle(
4517 Z, H.LookupConstructorByKernelConstructor(klass, node->target())); 4527 Z, H.LookupConstructorByKernelConstructor(klass, node->target()));
4518 intptr_t argument_count = node->arguments()->count() + 1; 4528 intptr_t argument_count = node->arguments()->count() + 1;
4519 instructions += StaticCall(target, argument_count, argument_names); 4529 instructions +=
4530 StaticCall(node->position(), target, argument_count, argument_names);
4520 fragment_ = instructions + Drop(); 4531 fragment_ = instructions + Drop();
4521 } 4532 }
4522 4533
4523 4534
4524 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) { 4535 void FlowGraphBuilder::VisitIsExpression(IsExpression* node) {
4525 Fragment instructions = TranslateExpression(node->operand()); 4536 Fragment instructions = TranslateExpression(node->operand());
4526 4537
4527 // The VM does not like an instanceOf call with a dynamic type. We need to 4538 // The VM does not like an instanceOf call with a dynamic type. We need to
4528 // special case this situation. 4539 // special case this situation.
4529 const Type& object_type = Type::Handle(Z, Type::ObjectType()); 4540 const Type& object_type = Type::Handle(Z, Type::ObjectType());
(...skipping 22 matching lines...) Expand all
4552 } 4563 }
4553 instructions += PushArgument(); // Type arguments. 4564 instructions += PushArgument(); // Type arguments.
4554 4565
4555 instructions += Constant(type); 4566 instructions += Constant(type);
4556 instructions += PushArgument(); // Type. 4567 instructions += PushArgument(); // Type.
4557 4568
4558 instructions += Constant(Bool::False()); 4569 instructions += Constant(Bool::False());
4559 instructions += PushArgument(); // Negate?. 4570 instructions += PushArgument(); // Negate?.
4560 4571
4561 instructions += 4572 instructions +=
4562 InstanceCall(dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), 4573 InstanceCall(TokenPosition::kNoSource,
4574 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
4563 Token::kIS, 4); 4575 Token::kIS, 4);
4564 } 4576 }
4565 4577
4566 fragment_ = instructions; 4578 fragment_ = instructions;
4567 } 4579 }
4568 4580
4569 4581
4570 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) { 4582 void FlowGraphBuilder::VisitAsExpression(AsExpression* node) {
4571 Fragment instructions = TranslateExpression(node->operand()); 4583 Fragment instructions = TranslateExpression(node->operand());
4572 4584
(...skipping 19 matching lines...) Expand all
4592 instructions += LoadInstantiatorTypeArguments(); 4604 instructions += LoadInstantiatorTypeArguments();
4593 } else { 4605 } else {
4594 instructions += NullConstant(); 4606 instructions += NullConstant();
4595 } 4607 }
4596 instructions += PushArgument(); // Type arguments. 4608 instructions += PushArgument(); // Type arguments.
4597 4609
4598 instructions += Constant(type); 4610 instructions += Constant(type);
4599 instructions += PushArgument(); // Type. 4611 instructions += PushArgument(); // Type.
4600 4612
4601 instructions += InstanceCall( 4613 instructions += InstanceCall(
4614 TokenPosition::kNoSource,
4602 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3); 4615 dart::Library::PrivateCoreLibName(Symbols::_as()), Token::kAS, 3);
4603 } 4616 }
4604 4617
4605 fragment_ = instructions; 4618 fragment_ = instructions;
4606 } 4619 }
4607 4620
4608 4621
4609 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) { 4622 void FlowGraphBuilder::VisitConditionalExpression(ConditionalExpression* node) {
4610 bool negate; 4623 bool negate;
4611 Fragment instructions = TranslateCondition(node->condition(), &negate); 4624 Fragment instructions = TranslateCondition(node->condition(), &negate);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
4738 instructions += Drop(); 4751 instructions += Drop();
4739 } 4752 }
4740 } 4753 }
4741 instructions += PushArgument(); // The array. 4754 instructions += PushArgument(); // The array.
4742 4755
4743 const dart::Class& factory_class = 4756 const dart::Class& factory_class =
4744 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List())); 4757 dart::Class::Handle(Z, dart::Library::LookupCoreClass(Symbols::List()));
4745 const Function& factory_method = Function::ZoneHandle( 4758 const Function& factory_method = Function::ZoneHandle(
4746 Z, factory_class.LookupFactory( 4759 Z, factory_class.LookupFactory(
4747 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory()))); 4760 dart::Library::PrivateCoreLibName(Symbols::ListLiteralFactory())));
4748 fragment_ = instructions + StaticCall(factory_method, 2); 4761 fragment_ = instructions + StaticCall(node->position(), factory_method, 2);
4749 } 4762 }
4750 4763
4751 4764
4752 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) { 4765 void FlowGraphBuilder::VisitMapLiteral(MapLiteral* node) {
4753 if (node->is_const()) { 4766 if (node->is_const()) {
4754 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node)); 4767 fragment_ = Constant(constant_evaluator_.EvaluateMapLiteral(node));
4755 return; 4768 return;
4756 } 4769 }
4757 4770
4758 const dart::Class& map_class = 4771 const dart::Class& map_class =
(...skipping 30 matching lines...) Expand all
4789 4802
4790 instructions += LoadLocal(array); 4803 instructions += LoadLocal(array);
4791 instructions += IntConstant(2 * i + 1); 4804 instructions += IntConstant(2 * i + 1);
4792 instructions += TranslateExpression(entries[i]->value()); 4805 instructions += TranslateExpression(entries[i]->value());
4793 instructions += StoreIndexed(kArrayCid); 4806 instructions += StoreIndexed(kArrayCid);
4794 instructions += Drop(); 4807 instructions += Drop();
4795 } 4808 }
4796 } 4809 }
4797 instructions += PushArgument(); // The array. 4810 instructions += PushArgument(); // The array.
4798 4811
4799 fragment_ = instructions + StaticCall(factory_method, 2); 4812 fragment_ = instructions + StaticCall(node->position(), factory_method, 2);
4800 } 4813 }
4801 4814
4802 4815
4803 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) { 4816 void FlowGraphBuilder::VisitFunctionExpression(FunctionExpression* node) {
4804 fragment_ = TranslateFunctionNode(node->function(), node); 4817 fragment_ = TranslateFunctionNode(node->function(), node);
4805 } 4818 }
4806 4819
4807 4820
4808 void FlowGraphBuilder::VisitLet(Let* node) { 4821 void FlowGraphBuilder::VisitLet(Let* node) {
4809 Fragment instructions = TranslateStatement(node->variable()); 4822 Fragment instructions = TranslateStatement(node->variable());
4810 instructions += TranslateExpression(node->body()); 4823 instructions += TranslateExpression(node->body());
4811 fragment_ = instructions; 4824 fragment_ = instructions;
4812 } 4825 }
4813 4826
4814 4827
4815 void FlowGraphBuilder::VisitThrow(Throw* node) { 4828 void FlowGraphBuilder::VisitThrow(Throw* node) {
4816 Fragment instructions; 4829 Fragment instructions;
4817 4830
4818 instructions += TranslateExpression(node->expression()); 4831 instructions += TranslateExpression(node->expression());
4819 instructions += PushArgument(); 4832 instructions += PushArgument();
4820 instructions += ThrowException(); 4833 instructions += ThrowException(node->position());
4821 ASSERT(instructions.is_closed()); 4834 ASSERT(instructions.is_closed());
4822 4835
4823 fragment_ = instructions; 4836 fragment_ = instructions;
4824 } 4837 }
4825 4838
4826 4839
4827 void FlowGraphBuilder::VisitRethrow(Rethrow* node) { 4840 void FlowGraphBuilder::VisitRethrow(Rethrow* node) {
4828 Fragment instructions; 4841 Fragment instructions;
4829 4842
4830 instructions += LoadLocal(catch_block_->exception_var()); 4843 instructions += LoadLocal(catch_block_->exception_var());
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
5094 fragment_ = loop; 5107 fragment_ = loop;
5095 } 5108 }
5096 5109
5097 5110
5098 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) { 5111 void FlowGraphBuilder::VisitForInStatement(ForInStatement* node) {
5099 Fragment instructions = TranslateExpression(node->iterable()); 5112 Fragment instructions = TranslateExpression(node->iterable());
5100 instructions += PushArgument(); 5113 instructions += PushArgument();
5101 5114
5102 const dart::String& iterator_getter = dart::String::ZoneHandle( 5115 const dart::String& iterator_getter = dart::String::ZoneHandle(
5103 Z, dart::Field::GetterSymbol(Symbols::Iterator())); 5116 Z, dart::Field::GetterSymbol(Symbols::Iterator()));
5104 instructions += InstanceCall(iterator_getter, Token::kGET, 1); 5117 instructions +=
5118 InstanceCall(TokenPosition::kNoSource, iterator_getter, Token::kGET, 1);
5105 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_]; 5119 LocalVariable* iterator = scopes_->iterator_variables[for_in_depth_];
5106 instructions += StoreLocal(iterator); 5120 instructions += StoreLocal(iterator);
5107 instructions += Drop(); 5121 instructions += Drop();
5108 5122
5109 ++for_in_depth_; 5123 ++for_in_depth_;
5110 ++loop_depth_; 5124 ++loop_depth_;
5111 Fragment condition = LoadLocal(iterator); 5125 Fragment condition = LoadLocal(iterator);
5112 condition += PushArgument(); 5126 condition += PushArgument();
5113 condition += InstanceCall(Symbols::MoveNext(), Token::kILLEGAL, 1); 5127 condition += InstanceCall(TokenPosition::kNoSource, Symbols::MoveNext(),
5128 Token::kILLEGAL, 1);
5114 TargetEntryInstr* body_entry; 5129 TargetEntryInstr* body_entry;
5115 TargetEntryInstr* loop_exit; 5130 TargetEntryInstr* loop_exit;
5116 condition += BranchIfTrue(&body_entry, &loop_exit); 5131 condition += BranchIfTrue(&body_entry, &loop_exit);
5117 5132
5118 Fragment body(body_entry); 5133 Fragment body(body_entry);
5119 body += EnterScope(node); 5134 body += EnterScope(node);
5120 body += LoadLocal(iterator); 5135 body += LoadLocal(iterator);
5121 body += PushArgument(); 5136 body += PushArgument();
5122 const dart::String& current_getter = dart::String::ZoneHandle( 5137 const dart::String& current_getter = dart::String::ZoneHandle(
5123 Z, dart::Field::GetterSymbol(Symbols::Current())); 5138 Z, dart::Field::GetterSymbol(Symbols::Current()));
5124 body += InstanceCall(current_getter, Token::kGET, 1); 5139 body +=
5140 InstanceCall(TokenPosition::kNoSource, current_getter, Token::kGET, 1);
5125 body += StoreLocal(LookupVariable(node->variable())); 5141 body += StoreLocal(LookupVariable(node->variable()));
5126 body += Drop(); 5142 body += Drop();
5127 body += TranslateStatement(node->body()); 5143 body += TranslateStatement(node->body());
5128 body += ExitScope(node); 5144 body += ExitScope(node);
5129 5145
5130 if (body.is_open()) { 5146 if (body.is_open()) {
5131 JoinEntryInstr* join = BuildJoinEntry(); 5147 JoinEntryInstr* join = BuildJoinEntry();
5132 instructions += Goto(join); 5148 instructions += Goto(join);
5133 body += Goto(join); 5149 body += Goto(join);
5134 5150
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
5235 // Call _AssertionError._create constructor. 5251 // Call _AssertionError._create constructor.
5236 body_fragment += LoadLocal(instance); 5252 body_fragment += LoadLocal(instance);
5237 body_fragment += PushArgument(); // this 5253 body_fragment += PushArgument(); // this
5238 5254
5239 body_fragment += Constant(url); 5255 body_fragment += Constant(url);
5240 body_fragment += PushArgument(); // url 5256 body_fragment += PushArgument(); // url
5241 5257
5242 body_fragment += NullConstant(); 5258 body_fragment += NullConstant();
5243 body_fragment += PushArgument(); // line 5259 body_fragment += PushArgument(); // line
5244 5260
5245 body_fragment += StaticCall(constructor, 3); 5261 body_fragment += StaticCall(TokenPosition::kNoSource, constructor, 3);
5246 body_fragment += Drop(); 5262 body_fragment += Drop();
5247 5263
5248 // Throw the exception 5264 // Throw the exception
5249 body_fragment += PushArgument(); 5265 body_fragment += PushArgument();
5250 body_fragment += ThrowException(); 5266 body_fragment += ThrowException(TokenPosition::kNoSource);
5251 body_fragment += Drop(); 5267 body_fragment += Drop();
5252 } 5268 }
5253 5269
5254 // If there is an implicit fall-through we have one [SwitchCase] and 5270 // If there is an implicit fall-through we have one [SwitchCase] and
5255 // multiple expressions, e.g. 5271 // multiple expressions, e.g.
5256 // 5272 //
5257 // switch(expr) { 5273 // switch(expr) {
5258 // case a: 5274 // case a:
5259 // case b: 5275 // case b:
5260 // <stmt-body> 5276 // <stmt-body>
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5304 5320
5305 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) { 5321 for (intptr_t j = 0; j < switch_case->expressions().length(); j++) {
5306 TargetEntryInstr* then; 5322 TargetEntryInstr* then;
5307 TargetEntryInstr* otherwise; 5323 TargetEntryInstr* otherwise;
5308 5324
5309 current_instructions += Constant(constant_evaluator_.EvaluateExpression( 5325 current_instructions += Constant(constant_evaluator_.EvaluateExpression(
5310 switch_case->expressions()[j])); 5326 switch_case->expressions()[j]));
5311 current_instructions += PushArgument(); 5327 current_instructions += PushArgument();
5312 current_instructions += LoadLocal(scopes_->switch_variable); 5328 current_instructions += LoadLocal(scopes_->switch_variable);
5313 current_instructions += PushArgument(); 5329 current_instructions += PushArgument();
5314 current_instructions += 5330 current_instructions += InstanceCall(
5315 InstanceCall(Symbols::EqualOperator(), Token::kEQ, 5331 TokenPosition::kNoSource, Symbols::EqualOperator(), Token::kEQ,
5316 /*argument_count=*/2, 5332 /*argument_count=*/2,
5317 /*num_args_checked=*/2); 5333 /*num_args_checked=*/2);
5318 current_instructions += BranchIfTrue(&then, &otherwise); 5334 current_instructions += BranchIfTrue(&then, &otherwise);
5319 5335
5320 Fragment then_fragment(then); 5336 Fragment then_fragment(then);
5321 5337
5322 if (body_join != NULL) { 5338 if (body_join != NULL) {
5323 // There are several branches to the body, so we will make a goto to 5339 // There are several branches to the body, so we will make a goto to
5324 // the join block (the real body has already been prepended with a 5340 // the join block (the real body has already been prepended with a
5325 // join instruction). 5341 // join instruction).
5326 then_fragment += Goto(body_join); 5342 then_fragment += Goto(body_join);
5327 } else { 5343 } else {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
5427 5443
5428 otherwise_fragment += Constant(url); 5444 otherwise_fragment += Constant(url);
5429 otherwise_fragment += PushArgument(); // url 5445 otherwise_fragment += PushArgument(); // url
5430 5446
5431 otherwise_fragment += IntConstant(0); 5447 otherwise_fragment += IntConstant(0);
5432 otherwise_fragment += PushArgument(); // line 5448 otherwise_fragment += PushArgument(); // line
5433 5449
5434 otherwise_fragment += IntConstant(0); 5450 otherwise_fragment += IntConstant(0);
5435 otherwise_fragment += PushArgument(); // column 5451 otherwise_fragment += PushArgument(); // column
5436 5452
5437 otherwise_fragment += StaticCall(constructor, 5); 5453 otherwise_fragment += StaticCall(TokenPosition::kNoSource, constructor, 5);
5438 otherwise_fragment += Drop(); 5454 otherwise_fragment += Drop();
5439 5455
5440 // Throw _AssertionError exception. 5456 // Throw _AssertionError exception.
5441 otherwise_fragment += PushArgument(); 5457 otherwise_fragment += PushArgument();
5442 otherwise_fragment += ThrowException(); 5458 otherwise_fragment += ThrowException(TokenPosition::kNoSource);
5443 otherwise_fragment += Drop(); 5459 otherwise_fragment += Drop();
5444 5460
5445 fragment_ = Fragment(instructions.entry, then); 5461 fragment_ = Fragment(instructions.entry, then);
5446 } 5462 }
5447 5463
5448 5464
5449 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) { 5465 void FlowGraphBuilder::VisitTryFinally(TryFinally* node) {
5450 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally"); 5466 InlineBailout("kernel::FlowgraphBuilder::VisitTryFinally");
5451 5467
5452 // There are 5 different cases where we need to execute the finally block: 5468 // 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
5587 } else { 5603 } else {
5588 catch_body += LoadLocal(CurrentException()); 5604 catch_body += LoadLocal(CurrentException());
5589 catch_body += PushArgument(); // exception 5605 catch_body += PushArgument(); // exception
5590 catch_body += NullConstant(); 5606 catch_body += NullConstant();
5591 catch_body += PushArgument(); // type arguments 5607 catch_body += PushArgument(); // type arguments
5592 catch_body += Constant(*type_guard); 5608 catch_body += Constant(*type_guard);
5593 catch_body += PushArgument(); // guard type 5609 catch_body += PushArgument(); // guard type
5594 catch_body += Constant(Object::bool_false()); 5610 catch_body += Constant(Object::bool_false());
5595 catch_body += PushArgument(); // negate 5611 catch_body += PushArgument(); // negate
5596 catch_body += InstanceCall( 5612 catch_body += InstanceCall(
5613 TokenPosition::kNoSource,
5597 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()), 5614 dart::Library::PrivateCoreLibName(Symbols::_instanceOf()),
5598 Token::kIS, 4); 5615 Token::kIS, 4);
5599 5616
5600 TargetEntryInstr* catch_entry; 5617 TargetEntryInstr* catch_entry;
5601 TargetEntryInstr* next_catch_entry; 5618 TargetEntryInstr* next_catch_entry;
5602 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry); 5619 catch_body += BranchIfTrue(&catch_entry, &next_catch_entry);
5603 5620
5604 Fragment(catch_entry) + catch_handler_body; 5621 Fragment(catch_entry) + catch_handler_body;
5605 catch_body = Fragment(next_catch_entry); 5622 catch_body = Fragment(next_catch_entry);
5606 } 5623 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
5704 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node, 5721 Fragment FlowGraphBuilder::TranslateFunctionNode(FunctionNode* node,
5705 TreeNode* parent) { 5722 TreeNode* parent) {
5706 // The VM has a per-isolate table of functions indexed by the enclosing 5723 // The VM has a per-isolate table of functions indexed by the enclosing
5707 // function and token position. We don't have token positions, so we've 5724 // function and token position. We don't have token positions, so we've
5708 // simply numbered the immediately-nested functions with respect to the 5725 // simply numbered the immediately-nested functions with respect to the
5709 // parent. 5726 // parent.
5710 Function& function = Function::ZoneHandle(Z); 5727 Function& function = Function::ZoneHandle(Z);
5711 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) { 5728 for (intptr_t i = 0; i < scopes_->function_scopes.length(); ++i) {
5712 if (scopes_->function_scopes[i].function != node) continue; 5729 if (scopes_->function_scopes[i].function != node) continue;
5713 5730
5731 // NOTE: This is not TokenPosition in the general sense!
5714 function = I->LookupClosureFunction(parsed_function_->function(), 5732 function = I->LookupClosureFunction(parsed_function_->function(),
5715 TokenPosition(i)); 5733 TokenPosition(i));
5716 if (function.IsNull()) { 5734 if (function.IsNull()) {
5717 const dart::String* name; 5735 const dart::String* name;
5718 if (parent->IsFunctionExpression()) { 5736 if (parent->IsFunctionExpression()) {
5719 name = &Symbols::AnonymousClosure(); 5737 name = &Symbols::AnonymousClosure();
5720 } else { 5738 } else {
5721 ASSERT(parent->IsFunctionDeclaration()); 5739 ASSERT(parent->IsFunctionDeclaration());
5722 name = &H.DartSymbol( 5740 name = &H.DartSymbol(
5723 FunctionDeclaration::Cast(parent)->variable()->name()); 5741 FunctionDeclaration::Cast(parent)->variable()->name());
5724 } 5742 }
5743 // NOTE: This is not TokenPosition in the general sense!
5725 function = Function::NewClosureFunction( 5744 function = Function::NewClosureFunction(
5726 *name, parsed_function_->function(), TokenPosition(i)); 5745 *name, parsed_function_->function(), TokenPosition(i));
5727 function.set_is_debuggable(false); 5746 function.set_is_debuggable(false);
5728 LocalScope* scope = scopes_->function_scopes[i].scope; 5747 LocalScope* scope = scopes_->function_scopes[i].scope;
5729 const ContextScope& context_scope = 5748 const ContextScope& context_scope =
5730 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); 5749 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_));
5731 function.set_context_scope(context_scope); 5750 function.set_context_scope(context_scope);
5732 function.set_kernel_function(node); 5751 function.set_kernel_function(node);
5733 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), 5752 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z),
5734 function, node, 5753 function, node,
(...skipping 27 matching lines...) Expand all
5762 instructions += LoadLocal(parsed_function_->current_context_var()); 5781 instructions += LoadLocal(parsed_function_->current_context_var());
5763 instructions += StoreInstanceField(Closure::context_offset()); 5782 instructions += StoreInstanceField(Closure::context_offset());
5764 5783
5765 return instructions; 5784 return instructions;
5766 } 5785 }
5767 5786
5768 5787
5769 } // namespace kernel 5788 } // namespace kernel
5770 } // namespace dart 5789 } // namespace dart
5771 #endif // !defined(DART_PRECOMPILED_RUNTIME) 5790 #endif // !defined(DART_PRECOMPILED_RUNTIME)
OLDNEW
« no previous file with comments | « runtime/vm/kernel_to_il.h ('k') | runtime/vm/object.h » ('j') | runtime/vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698