OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library tree_ir_builder; | 5 library tree_ir_builder; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../constants/values.dart'; | 8 import '../constants/values.dart'; |
9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; | 9 import '../cps_ir/cps_ir_nodes.dart' as cps_ir; |
10 import '../elements/elements.dart'; | 10 import '../elements/elements.dart'; |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 NodeCallback visitLetHandler(cps_ir.LetHandler node) => (Statement next) { | 390 NodeCallback visitLetHandler(cps_ir.LetHandler node) => (Statement next) { |
391 List<Variable> catchParameters = | 391 List<Variable> catchParameters = |
392 node.handler.parameters.map(getVariable).toList(); | 392 node.handler.parameters.map(getVariable).toList(); |
393 Statement catchBody = translateExpression(node.handler.body); | 393 Statement catchBody = translateExpression(node.handler.body); |
394 return new Try(next, catchParameters, catchBody); | 394 return new Try(next, catchParameters, catchBody); |
395 }; | 395 }; |
396 | 396 |
397 NodeCallback visitLetMutable(cps_ir.LetMutable node) { | 397 NodeCallback visitLetMutable(cps_ir.LetMutable node) { |
398 Variable variable = addMutableVariable(node.variable); | 398 Variable variable = addMutableVariable(node.variable); |
399 Expression value = getVariableUse(node.value); | 399 Expression value = getVariableUse(node.valueRef); |
400 return (Statement next) => Assign.makeStatement(variable, value, next); | 400 return (Statement next) => Assign.makeStatement(variable, value, next); |
401 } | 401 } |
402 | 402 |
403 /************************** TAIL EXPRESSIONS **************************/ | 403 /************************** TAIL EXPRESSIONS **************************/ |
404 // | 404 // |
405 // Visit methods for tail expressions must return a statement directly | 405 // Visit methods for tail expressions must return a statement directly |
406 // (not a function like interior and call expressions). | 406 // (not a function like interior and call expressions). |
407 | 407 |
408 Statement visitThrow(cps_ir.Throw node) { | 408 Statement visitThrow(cps_ir.Throw node) { |
409 Expression value = getVariableUse(node.value); | 409 Expression value = getVariableUse(node.valueRef); |
410 return new Throw(value); | 410 return new Throw(value); |
411 } | 411 } |
412 | 412 |
413 Statement visitUnreachable(cps_ir.Unreachable node) { | 413 Statement visitUnreachable(cps_ir.Unreachable node) { |
414 return new Unreachable(); | 414 return new Unreachable(); |
415 } | 415 } |
416 | 416 |
417 Statement visitInvokeContinuation(cps_ir.InvokeContinuation node) { | 417 Statement visitInvokeContinuation(cps_ir.InvokeContinuation node) { |
418 // Invocations of the return continuation are translated to returns. | 418 // Invocations of the return continuation are translated to returns. |
419 // Other continuation invocations are replaced with assignments of the | 419 // Other continuation invocations are replaced with assignments of the |
420 // arguments to formal parameter variables, followed by the body if | 420 // arguments to formal parameter variables, followed by the body if |
421 // the continuation is singly reference or a break if it is multiply | 421 // the continuation is singly reference or a break if it is multiply |
422 // referenced. | 422 // referenced. |
423 cps_ir.Continuation cont = node.continuation.definition; | 423 cps_ir.Continuation cont = node.continuation; |
424 if (cont == returnContinuation) { | 424 if (cont == returnContinuation) { |
425 assert(node.arguments.length == 1); | 425 assert(node.argumentRefs.length == 1); |
426 return new Return(getVariableUse(node.arguments.single), | 426 return new Return(getVariableUse(node.argumentRefs.single), |
427 sourceInformation: node.sourceInformation); | 427 sourceInformation: node.sourceInformation); |
428 } else { | 428 } else { |
429 List<Expression> arguments = translateArguments(node.arguments); | 429 List<Expression> arguments = translateArguments(node.argumentRefs); |
430 return buildPhiAssignments(cont.parameters, arguments, | 430 return buildPhiAssignments(cont.parameters, arguments, |
431 () { | 431 () { |
432 // Translate invocations of recursive and non-recursive | 432 // Translate invocations of recursive and non-recursive |
433 // continuations differently. | 433 // continuations differently. |
434 // * Non-recursive continuations | 434 // * Non-recursive continuations |
435 // - If there is one use, translate the continuation body | 435 // - If there is one use, translate the continuation body |
436 // inline at the invocation site. | 436 // inline at the invocation site. |
437 // - If there are multiple uses, translate to Break. | 437 // - If there are multiple uses, translate to Break. |
438 // * Recursive continuations | 438 // * Recursive continuations |
439 // - There is a single non-recursive invocation. Translate | 439 // - There is a single non-recursive invocation. Translate |
440 // the continuation body inline as a labeled loop at the | 440 // the continuation body inline as a labeled loop at the |
441 // invocation site. | 441 // invocation site. |
442 // - Translate the recursive invocations to Continue. | 442 // - Translate the recursive invocations to Continue. |
443 if (cont.isRecursive) { | 443 if (cont.isRecursive) { |
444 return node.isRecursive | 444 return node.isRecursive |
445 ? new Continue(getLabel(cont)) | 445 ? new Continue(getLabel(cont)) |
446 : new WhileTrue(getLabel(cont), | 446 : new WhileTrue(getLabel(cont), |
447 translateExpression(cont.body)); | 447 translateExpression(cont.body)); |
448 } else { | 448 } else { |
449 return cont.hasExactlyOneUse && !node.isEscapingTry | 449 return cont.hasExactlyOneUse && !node.isEscapingTry |
450 ? translateExpression(cont.body) | 450 ? translateExpression(cont.body) |
451 : new Break(getLabel(cont)); | 451 : new Break(getLabel(cont)); |
452 } | 452 } |
453 }); | 453 }); |
454 } | 454 } |
455 } | 455 } |
456 | 456 |
457 /// Translates a branch condition to a tree expression. | 457 /// Translates a branch condition to a tree expression. |
458 Expression translateCondition(cps_ir.Branch branch) { | 458 Expression translateCondition(cps_ir.Branch branch) { |
459 Expression value = getVariableUse(branch.condition); | 459 Expression value = getVariableUse(branch.conditionRef); |
460 if (branch.isStrictCheck) { | 460 if (branch.isStrictCheck) { |
461 return new ApplyBuiltinOperator( | 461 return new ApplyBuiltinOperator( |
462 BuiltinOperator.StrictEq, | 462 BuiltinOperator.StrictEq, |
463 <Expression>[value, new Constant(new TrueConstantValue())]); | 463 <Expression>[value, new Constant(new TrueConstantValue())]); |
464 } else { | 464 } else { |
465 return value; | 465 return value; |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
469 Statement visitBranch(cps_ir.Branch node) { | 469 Statement visitBranch(cps_ir.Branch node) { |
470 Expression condition = translateCondition(node); | 470 Expression condition = translateCondition(node); |
471 Statement thenStatement, elseStatement; | 471 Statement thenStatement, elseStatement; |
472 cps_ir.Continuation cont = node.trueContinuation.definition; | 472 cps_ir.Continuation cont = node.trueContinuation; |
473 assert(cont.parameters.isEmpty); | 473 assert(cont.parameters.isEmpty); |
474 thenStatement = cont.hasExactlyOneUse | 474 thenStatement = cont.hasExactlyOneUse |
475 ? translateExpression(cont.body) | 475 ? translateExpression(cont.body) |
476 : new Break(labels[cont]); | 476 : new Break(labels[cont]); |
477 cont = node.falseContinuation.definition; | 477 cont = node.falseContinuation; |
478 assert(cont.parameters.isEmpty); | 478 assert(cont.parameters.isEmpty); |
479 elseStatement = cont.hasExactlyOneUse | 479 elseStatement = cont.hasExactlyOneUse |
480 ? translateExpression(cont.body) | 480 ? translateExpression(cont.body) |
481 : new Break(labels[cont]); | 481 : new Break(labels[cont]); |
482 return new If(condition, thenStatement, elseStatement); | 482 return new If(condition, thenStatement, elseStatement); |
483 } | 483 } |
484 | 484 |
485 | 485 |
486 /************************** PRIMITIVES **************************/ | 486 /************************** PRIMITIVES **************************/ |
487 // | 487 // |
488 // Visit methods for primitives must return an expression. | 488 // Visit methods for primitives must return an expression. |
489 // | 489 // |
490 | 490 |
491 Expression visitSetField(cps_ir.SetField node) { | 491 Expression visitSetField(cps_ir.SetField node) { |
492 return new SetField(getVariableUse(node.object), | 492 return new SetField(getVariableUse(node.objectRef), |
493 node.field, | 493 node.field, |
494 getVariableUse(node.value)); | 494 getVariableUse(node.valueRef)); |
495 } | 495 } |
496 | 496 |
497 Expression visitInterceptor(cps_ir.Interceptor node) { | 497 Expression visitInterceptor(cps_ir.Interceptor node) { |
498 return new Interceptor(getVariableUse(node.input), | 498 return new Interceptor(getVariableUse(node.inputRef), |
499 node.interceptedClasses, | 499 node.interceptedClasses, |
500 node.sourceInformation); | 500 node.sourceInformation); |
501 } | 501 } |
502 | 502 |
503 Expression visitCreateInstance(cps_ir.CreateInstance node) { | 503 Expression visitCreateInstance(cps_ir.CreateInstance node) { |
504 return new CreateInstance( | 504 return new CreateInstance( |
505 node.classElement, | 505 node.classElement, |
506 translateArguments(node.arguments), | 506 translateArguments(node.argumentRefs), |
507 getVariableUseOrNull(node.typeInformation), | 507 getVariableUseOrNull(node.typeInformationRef), |
508 node.sourceInformation); | 508 node.sourceInformation); |
509 } | 509 } |
510 | 510 |
511 Expression visitGetField(cps_ir.GetField node) { | 511 Expression visitGetField(cps_ir.GetField node) { |
512 return new GetField(getVariableUse(node.object), node.field, | 512 return new GetField(getVariableUse(node.objectRef), node.field, |
513 objectIsNotNull: !node.object.definition.type.isNullable); | 513 objectIsNotNull: !node.object.type.isNullable); |
514 } | 514 } |
515 | 515 |
516 Expression visitCreateBox(cps_ir.CreateBox node) { | 516 Expression visitCreateBox(cps_ir.CreateBox node) { |
517 return new CreateBox(); | 517 return new CreateBox(); |
518 } | 518 } |
519 | 519 |
520 Expression visitCreateInvocationMirror(cps_ir.CreateInvocationMirror node) { | 520 Expression visitCreateInvocationMirror(cps_ir.CreateInvocationMirror node) { |
521 return new CreateInvocationMirror( | 521 return new CreateInvocationMirror( |
522 node.selector, | 522 node.selector, |
523 translateArguments(node.arguments)); | 523 translateArguments(node.argumentRefs)); |
524 } | 524 } |
525 | 525 |
526 Expression visitGetMutable(cps_ir.GetMutable node) { | 526 Expression visitGetMutable(cps_ir.GetMutable node) { |
527 return getMutableVariableUse(node.variable); | 527 return getMutableVariableUse(node.variableRef); |
528 } | 528 } |
529 | 529 |
530 Expression visitSetMutable(cps_ir.SetMutable node) { | 530 Expression visitSetMutable(cps_ir.SetMutable node) { |
531 Variable variable = getMutableVariable(node.variable.definition); | 531 Variable variable = getMutableVariable(node.variable); |
532 Expression value = getVariableUse(node.value); | 532 Expression value = getVariableUse(node.valueRef); |
533 return new Assign(variable, value); | 533 return new Assign(variable, value); |
534 } | 534 } |
535 | 535 |
536 Expression visitConstant(cps_ir.Constant node) { | 536 Expression visitConstant(cps_ir.Constant node) { |
537 return new Constant(node.value, sourceInformation: node.sourceInformation); | 537 return new Constant(node.value, sourceInformation: node.sourceInformation); |
538 } | 538 } |
539 | 539 |
540 Expression visitLiteralList(cps_ir.LiteralList node) { | 540 Expression visitLiteralList(cps_ir.LiteralList node) { |
541 return new LiteralList( | 541 return new LiteralList( |
542 node.dartType, | 542 node.dartType, |
543 translateArguments(node.values)); | 543 translateArguments(node.valueRefs)); |
544 } | 544 } |
545 | 545 |
546 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { | 546 Expression visitReifyRuntimeType(cps_ir.ReifyRuntimeType node) { |
547 return new ReifyRuntimeType( | 547 return new ReifyRuntimeType( |
548 getVariableUse(node.value), node.sourceInformation); | 548 getVariableUse(node.valueRef), node.sourceInformation); |
549 } | 549 } |
550 | 550 |
551 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { | 551 Expression visitReadTypeVariable(cps_ir.ReadTypeVariable node) { |
552 return new ReadTypeVariable( | 552 return new ReadTypeVariable( |
553 node.variable, | 553 node.variable, |
554 getVariableUse(node.target), | 554 getVariableUse(node.targetRef), |
555 node.sourceInformation); | 555 node.sourceInformation); |
556 } | 556 } |
557 | 557 |
558 Expression visitTypeExpression(cps_ir.TypeExpression node) { | 558 Expression visitTypeExpression(cps_ir.TypeExpression node) { |
559 return new TypeExpression( | 559 return new TypeExpression( |
560 node.kind, | 560 node.kind, |
561 node.dartType, | 561 node.dartType, |
562 node.arguments.map(getVariableUse).toList()); | 562 node.argumentRefs.map(getVariableUse).toList()); |
563 } | 563 } |
564 | 564 |
565 Expression visitTypeTest(cps_ir.TypeTest node) { | 565 Expression visitTypeTest(cps_ir.TypeTest node) { |
566 Expression value = getVariableUse(node.value); | 566 Expression value = getVariableUse(node.valueRef); |
567 List<Expression> typeArgs = translateArguments(node.typeArguments); | 567 List<Expression> typeArgs = translateArguments(node.typeArgumentRefs); |
568 return new TypeOperator(value, node.dartType, typeArgs, isTypeTest: true); | 568 return new TypeOperator(value, node.dartType, typeArgs, isTypeTest: true); |
569 } | 569 } |
570 | 570 |
571 Expression visitTypeTestViaFlag(cps_ir.TypeTestViaFlag node) { | 571 Expression visitTypeTestViaFlag(cps_ir.TypeTestViaFlag node) { |
572 Expression value = getVariableUse(node.interceptor); | 572 Expression value = getVariableUse(node.interceptorRef); |
573 // TODO(sra): Move !! to cps_ir level. | 573 // TODO(sra): Move !! to cps_ir level. |
574 return new Not(new Not(new GetTypeTestProperty(value, node.dartType))); | 574 return new Not(new Not(new GetTypeTestProperty(value, node.dartType))); |
575 } | 575 } |
576 | 576 |
577 Expression visitGetStatic(cps_ir.GetStatic node) { | 577 Expression visitGetStatic(cps_ir.GetStatic node) { |
578 return new GetStatic(node.element, node.sourceInformation); | 578 return new GetStatic(node.element, node.sourceInformation); |
579 } | 579 } |
580 | 580 |
581 Expression visitSetStatic(cps_ir.SetStatic node) { | 581 Expression visitSetStatic(cps_ir.SetStatic node) { |
582 return new SetStatic( | 582 return new SetStatic( |
583 node.element, | 583 node.element, |
584 getVariableUse(node.value), | 584 getVariableUse(node.valueRef), |
585 node.sourceInformation); | 585 node.sourceInformation); |
586 } | 586 } |
587 | 587 |
588 Expression visitApplyBuiltinOperator(cps_ir.ApplyBuiltinOperator node) { | 588 Expression visitApplyBuiltinOperator(cps_ir.ApplyBuiltinOperator node) { |
589 if (node.operator == BuiltinOperator.IsFalsy) { | 589 if (node.operator == BuiltinOperator.IsFalsy) { |
590 return new Not(getVariableUse(node.arguments.single)); | 590 return new Not(getVariableUse(node.argumentRefs.single)); |
591 } | 591 } |
592 return new ApplyBuiltinOperator(node.operator, | 592 return new ApplyBuiltinOperator(node.operator, |
593 translateArguments(node.arguments)); | 593 translateArguments(node.argumentRefs)); |
594 } | 594 } |
595 | 595 |
596 Expression visitApplyBuiltinMethod(cps_ir.ApplyBuiltinMethod node) { | 596 Expression visitApplyBuiltinMethod(cps_ir.ApplyBuiltinMethod node) { |
597 return new ApplyBuiltinMethod(node.method, | 597 return new ApplyBuiltinMethod(node.method, |
598 getVariableUse(node.receiver), | 598 getVariableUse(node.receiverRef), |
599 translateArguments(node.arguments), | 599 translateArguments(node.argumentRefs), |
600 receiverIsNotNull: !node.receiver.definition.type.isNullable); | 600 receiverIsNotNull: !node.receiver.type.isNullable); |
601 } | 601 } |
602 | 602 |
603 Expression visitGetLength(cps_ir.GetLength node) { | 603 Expression visitGetLength(cps_ir.GetLength node) { |
604 return new GetLength(getVariableUse(node.object)); | 604 return new GetLength(getVariableUse(node.objectRef)); |
605 } | 605 } |
606 | 606 |
607 Expression visitGetIndex(cps_ir.GetIndex node) { | 607 Expression visitGetIndex(cps_ir.GetIndex node) { |
608 return new GetIndex(getVariableUse(node.object), | 608 return new GetIndex(getVariableUse(node.objectRef), |
609 getVariableUse(node.index)); | 609 getVariableUse(node.indexRef)); |
610 } | 610 } |
611 | 611 |
612 Expression visitSetIndex(cps_ir.SetIndex node) { | 612 Expression visitSetIndex(cps_ir.SetIndex node) { |
613 return new SetIndex(getVariableUse(node.object), | 613 return new SetIndex(getVariableUse(node.objectRef), |
614 getVariableUse(node.index), | 614 getVariableUse(node.indexRef), |
615 getVariableUse(node.value)); | 615 getVariableUse(node.valueRef)); |
616 } | 616 } |
617 | 617 |
618 Expression visitInvokeStatic(cps_ir.InvokeStatic node) { | 618 Expression visitInvokeStatic(cps_ir.InvokeStatic node) { |
619 List<Expression> arguments = translateArguments(node.arguments); | 619 List<Expression> arguments = translateArguments(node.argumentRefs); |
620 return new InvokeStatic(node.target, node.selector, arguments, | 620 return new InvokeStatic(node.target, node.selector, arguments, |
621 node.sourceInformation); | 621 node.sourceInformation); |
622 } | 622 } |
623 | 623 |
624 Expression visitInvokeMethod(cps_ir.InvokeMethod node) { | 624 Expression visitInvokeMethod(cps_ir.InvokeMethod node) { |
625 if (node.callingConvention == cps_ir.CallingConvention.OneShotIntercepted) { | 625 if (node.callingConvention == cps_ir.CallingConvention.OneShotIntercepted) { |
626 List<Expression> arguments = new List.generate( | 626 List<Expression> arguments = new List.generate( |
627 1 + node.arguments.length, | 627 1 + node.argumentRefs.length, |
628 (n) => getVariableUse(n == 0 ? node.receiver : node.arguments[n - 1]), | 628 (n) => getVariableUse(n == 0 ? node.receiverRef : node.argumentRefs[n
- 1]), |
629 growable: false); | 629 growable: false); |
630 return new OneShotInterceptor(node.selector, node.mask, arguments, | 630 return new OneShotInterceptor(node.selector, node.mask, arguments, |
631 node.sourceInformation); | 631 node.sourceInformation); |
632 } | 632 } |
633 InvokeMethod invoke = new InvokeMethod( | 633 InvokeMethod invoke = new InvokeMethod( |
634 getVariableUse(node.receiver), | 634 getVariableUse(node.receiverRef), |
635 node.selector, | 635 node.selector, |
636 node.mask, | 636 node.mask, |
637 translateArguments(node.arguments), | 637 translateArguments(node.argumentRefs), |
638 node.sourceInformation); | 638 node.sourceInformation); |
639 // Sometimes we know the Dart receiver is non-null because it has been | 639 // Sometimes we know the Dart receiver is non-null because it has been |
640 // refined, which implies that the JS receiver also can not be null at the | 640 // refined, which implies that the JS receiver also can not be null at the |
641 // use-site. Interceptors are not refined, so this information is not | 641 // use-site. Interceptors are not refined, so this information is not |
642 // always available on the JS receiver. | 642 // always available on the JS receiver. |
643 // Also check the JS receiver's type, however, because sometimes we know an | 643 // Also check the JS receiver's type, however, because sometimes we know an |
644 // interceptor is non-null because it intercepts JSNull. | 644 // interceptor is non-null because it intercepts JSNull. |
645 invoke.receiverIsNotNull = | 645 invoke.receiverIsNotNull = |
646 !node.dartReceiver.type.isNullable || | 646 !node.dartReceiver.type.isNullable || |
647 !node.receiver.definition.type.isNullable; | 647 !node.receiver.type.isNullable; |
648 return invoke; | 648 return invoke; |
649 } | 649 } |
650 | 650 |
651 Expression visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { | 651 Expression visitInvokeMethodDirectly(cps_ir.InvokeMethodDirectly node) { |
652 Expression receiver = getVariableUse(node.receiver); | 652 Expression receiver = getVariableUse(node.receiverRef); |
653 List<Expression> arguments = translateArguments(node.arguments); | 653 List<Expression> arguments = translateArguments(node.argumentRefs); |
654 return new InvokeMethodDirectly(receiver, node.target, | 654 return new InvokeMethodDirectly(receiver, node.target, |
655 node.selector, arguments, node.sourceInformation); | 655 node.selector, arguments, node.sourceInformation); |
656 } | 656 } |
657 | 657 |
658 Expression visitTypeCast(cps_ir.TypeCast node) { | 658 Expression visitTypeCast(cps_ir.TypeCast node) { |
659 Expression value = getVariableUse(node.value); | 659 Expression value = getVariableUse(node.valueRef); |
660 List<Expression> typeArgs = translateArguments(node.typeArguments); | 660 List<Expression> typeArgs = translateArguments(node.typeArgumentRefs); |
661 return new TypeOperator(value, node.dartType, typeArgs, isTypeTest: false); | 661 return new TypeOperator(value, node.dartType, typeArgs, isTypeTest: false); |
662 } | 662 } |
663 | 663 |
664 Expression visitInvokeConstructor(cps_ir.InvokeConstructor node) { | 664 Expression visitInvokeConstructor(cps_ir.InvokeConstructor node) { |
665 List<Expression> arguments = translateArguments(node.arguments); | 665 List<Expression> arguments = translateArguments(node.argumentRefs); |
666 return new InvokeConstructor( | 666 return new InvokeConstructor( |
667 node.dartType, | 667 node.dartType, |
668 node.target, | 668 node.target, |
669 node.selector, | 669 node.selector, |
670 arguments, | 670 arguments, |
671 node.sourceInformation); | 671 node.sourceInformation); |
672 } | 672 } |
673 | 673 |
674 visitForeignCode(cps_ir.ForeignCode node) { | 674 visitForeignCode(cps_ir.ForeignCode node) { |
675 List<Expression> arguments = | 675 List<Expression> arguments = |
676 node.arguments.map(getVariableUse).toList(growable: false); | 676 node.argumentRefs.map(getVariableUse).toList(growable: false); |
677 List<bool> nullableArguments = node.arguments | 677 List<bool> nullableArguments = node.argumentRefs |
678 .map((argument) => argument.definition.type.isNullable) | 678 .map((argument) => argument.definition.type.isNullable) |
679 .toList(growable: false); | 679 .toList(growable: false); |
680 if (node.codeTemplate.isExpression) { | 680 if (node.codeTemplate.isExpression) { |
681 return new ForeignExpression( | 681 return new ForeignExpression( |
682 node.codeTemplate, | 682 node.codeTemplate, |
683 node.type, | 683 node.type, |
684 arguments, | 684 arguments, |
685 node.nativeBehavior, | 685 node.nativeBehavior, |
686 nullableArguments, | 686 nullableArguments, |
687 node.dependency); | 687 node.dependency); |
688 } else { | 688 } else { |
689 return (Statement next) { | 689 return (Statement next) { |
690 assert(next is Unreachable); // We are not using the `next` statement. | 690 assert(next is Unreachable); // We are not using the `next` statement. |
691 return new ForeignStatement( | 691 return new ForeignStatement( |
692 node.codeTemplate, | 692 node.codeTemplate, |
693 node.type, | 693 node.type, |
694 arguments, | 694 arguments, |
695 node.nativeBehavior, | 695 node.nativeBehavior, |
696 nullableArguments, | 696 nullableArguments, |
697 node.dependency); | 697 node.dependency); |
698 }; | 698 }; |
699 } | 699 } |
700 } | 700 } |
701 | 701 |
702 visitReceiverCheck(cps_ir.ReceiverCheck node) => (Statement next) { | 702 visitReceiverCheck(cps_ir.ReceiverCheck node) => (Statement next) { |
703 // The CPS IR uses 'isNullCheck' because the semantics are important. | 703 // The CPS IR uses 'isNullCheck' because the semantics are important. |
704 // In the Tree IR, syntax is more important, so the receiver check uses | 704 // In the Tree IR, syntax is more important, so the receiver check uses |
705 // "useInvoke" to denote if an invocation should be emitted. | 705 // "useInvoke" to denote if an invocation should be emitted. |
706 return new ReceiverCheck( | 706 return new ReceiverCheck( |
707 condition: getVariableUseOrNull(node.condition), | 707 condition: getVariableUseOrNull(node.conditionRef), |
708 value: getVariableUse(node.value), | 708 value: getVariableUse(node.valueRef), |
709 selector: node.selector, | 709 selector: node.selector, |
710 useSelector: node.useSelector, | 710 useSelector: node.useSelector, |
711 useInvoke: !node.isNullCheck, | 711 useInvoke: !node.isNullCheck, |
712 next: next, | 712 next: next, |
713 sourceInformation: node.sourceInformation); | 713 sourceInformation: node.sourceInformation); |
714 }; | 714 }; |
715 | 715 |
716 Expression visitGetLazyStatic(cps_ir.GetLazyStatic node) { | 716 Expression visitGetLazyStatic(cps_ir.GetLazyStatic node) { |
717 return new GetStatic.lazy(node.element, node.sourceInformation); | 717 return new GetStatic.lazy(node.element, node.sourceInformation); |
718 } | 718 } |
719 | 719 |
720 @override | 720 @override |
721 NodeCallback visitYield(cps_ir.Yield node) { | 721 NodeCallback visitYield(cps_ir.Yield node) { |
722 return (Statement next) { | 722 return (Statement next) { |
723 return new Yield(getVariableUse(node.input), node.hasStar, next); | 723 return new Yield(getVariableUse(node.inputRef), node.hasStar, next); |
724 }; | 724 }; |
725 } | 725 } |
726 | 726 |
727 @override | 727 @override |
728 Expression visitAwait(cps_ir.Await node) { | 728 Expression visitAwait(cps_ir.Await node) { |
729 return new Await(getVariableUse(node.input)); | 729 return new Await(getVariableUse(node.inputRef)); |
730 } | 730 } |
731 | 731 |
732 @override | 732 @override |
733 visitRefinement(cps_ir.Refinement node) { | 733 visitRefinement(cps_ir.Refinement node) { |
734 return (Statement next) => next; // Compile to nothing. | 734 return (Statement next) => next; // Compile to nothing. |
735 } | 735 } |
736 | 736 |
737 /********** UNUSED VISIT METHODS *************/ | 737 /********** UNUSED VISIT METHODS *************/ |
738 | 738 |
739 unexpectedNode(cps_ir.Node node) { | 739 unexpectedNode(cps_ir.Node node) { |
740 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node'); | 740 internalError(CURRENT_ELEMENT_SPANNABLE, 'Unexpected IR node: $node'); |
741 } | 741 } |
742 | 742 |
743 visitFunctionDefinition(cps_ir.FunctionDefinition node) { | 743 visitFunctionDefinition(cps_ir.FunctionDefinition node) { |
744 unexpectedNode(node); | 744 unexpectedNode(node); |
745 } | 745 } |
746 visitParameter(cps_ir.Parameter node) => unexpectedNode(node); | 746 visitParameter(cps_ir.Parameter node) => unexpectedNode(node); |
747 visitContinuation(cps_ir.Continuation node) => unexpectedNode(node); | 747 visitContinuation(cps_ir.Continuation node) => unexpectedNode(node); |
748 visitMutableVariable(cps_ir.MutableVariable node) => unexpectedNode(node); | 748 visitMutableVariable(cps_ir.MutableVariable node) => unexpectedNode(node); |
749 visitRethrow(cps_ir.Rethrow node) => unexpectedNode(node); | 749 visitRethrow(cps_ir.Rethrow node) => unexpectedNode(node); |
750 visitBoundsCheck(cps_ir.BoundsCheck node) => unexpectedNode(node); | 750 visitBoundsCheck(cps_ir.BoundsCheck node) => unexpectedNode(node); |
751 } | 751 } |
OLD | NEW |