Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart2js.ir_builder; | 5 library dart2js.ir_builder; |
| 6 | 6 |
| 7 import '../compile_time_constants.dart' show BackendConstantEnvironment; | 7 import '../compile_time_constants.dart' show BackendConstantEnvironment; |
| 8 import '../constants/constant_system.dart'; | 8 import '../constants/constant_system.dart'; |
| 9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
| 10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; | 10 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; |
| (...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1637 // in [[body]]; continue(v, ...) | 1637 // in [[body]]; continue(v, ...) |
| 1638 loopBuilder.add( | 1638 loopBuilder.add( |
| 1639 new ir.LetCont(continueCollector.continuation, | 1639 new ir.LetCont(continueCollector.continuation, |
| 1640 bodyBuilder._root)); | 1640 bodyBuilder._root)); |
| 1641 | 1641 |
| 1642 // And tie it all together. | 1642 // And tie it all together. |
| 1643 add(new ir.LetCont(breakCollector.continuation, loopBuilder._root)); | 1643 add(new ir.LetCont(breakCollector.continuation, loopBuilder._root)); |
| 1644 environment = breakCollector.environment; | 1644 environment = breakCollector.environment; |
| 1645 } | 1645 } |
| 1646 | 1646 |
| 1647 void buildSimpleSwitch(JumpTarget target, | |
| 1648 ir.Primitive value, | |
| 1649 List<SwitchCaseInfo> cases, | |
| 1650 SwitchCaseInfo defaultCase, | |
| 1651 Element error, | |
| 1652 SourceInformation sourceInformation) { | |
| 1653 assert(isOpen); | |
| 1654 JumpCollector join = new ForwardJumpCollector(environment, target: target); | |
| 1655 | |
| 1656 IrBuilder casesBuilder = makeDelimitedBuilder(); | |
| 1657 casesBuilder.state.breakCollectors.add(join); | |
| 1658 for (SwitchCaseInfo caseInfo in cases) { | |
|
asgerf
2015/06/19 12:47:34
Anonymize buildRight? I don't understand the name
Kevin Millikin (Google)
2015/06/19 12:59:52
Yeah, that's how I wrote it in my head, but I want
| |
| 1659 buildConditionFrom(int index) { | |
| 1660 ir.Primitive buildRight(IrBuilder builder) { | |
| 1661 ir.Primitive comparison = builder.addPrimitive( | |
| 1662 new ir.Identical(value, caseInfo.constants[index])); | |
| 1663 return (index == caseInfo.constants.length - 1) | |
| 1664 ? comparison | |
| 1665 : builder.buildLogicalOperator( | |
| 1666 comparison, buildConditionFrom(index + 1), isLazyOr: true); | |
| 1667 } | |
| 1668 return buildRight; | |
| 1669 } | |
| 1670 | |
| 1671 ir.Primitive condition = buildConditionFrom(0)(casesBuilder); | |
| 1672 IrBuilder thenBuilder = makeDelimitedBuilder(); | |
| 1673 caseInfo.buildBody(thenBuilder); | |
| 1674 if (thenBuilder.isOpen) { | |
| 1675 // It is a runtime error to reach the end of a switch case, unless | |
| 1676 // it is the last case. | |
| 1677 if (caseInfo == cases.last && defaultCase == null) { | |
| 1678 thenBuilder.jumpTo(join); | |
| 1679 } else { | |
| 1680 ir.Primitive exception = thenBuilder._buildInvokeStatic( | |
| 1681 error, | |
| 1682 new Selector.fromElement(error), | |
| 1683 <ir.Primitive>[], | |
| 1684 sourceInformation); | |
| 1685 thenBuilder.buildThrow(exception); | |
| 1686 } | |
| 1687 } | |
| 1688 | |
| 1689 ir.Continuation thenContinuation = new ir.Continuation([]); | |
| 1690 thenContinuation.body = thenBuilder._root; | |
| 1691 ir.Continuation elseContinuation = new ir.Continuation([]); | |
| 1692 casesBuilder.add( | |
| 1693 new ir.LetCont.many(<ir.Continuation>[elseContinuation, | |
| 1694 thenContinuation], | |
| 1695 new ir.Branch(new ir.IsTrue(condition), | |
| 1696 thenContinuation, | |
| 1697 elseContinuation))); | |
|
asgerf
2015/06/19 12:47:34
The rule that the first continuation of LetCont be
Kevin Millikin (Google)
2015/06/19 12:59:52
There is a comment everywhere else, I'll duplicate
| |
| 1698 } | |
| 1699 | |
| 1700 if (defaultCase != null) { | |
| 1701 defaultCase.buildBody(casesBuilder); | |
| 1702 } | |
| 1703 if (casesBuilder.isOpen) casesBuilder.jumpTo(join); | |
| 1704 | |
| 1705 casesBuilder.state.breakCollectors.removeLast(); | |
| 1706 | |
| 1707 if (!join.isEmpty) { | |
| 1708 add(new ir.LetCont(join.continuation, casesBuilder._root)); | |
| 1709 environment = join.environment; | |
| 1710 } else if (casesBuilder._root != null) { | |
| 1711 add(casesBuilder._root); | |
| 1712 _current = casesBuilder._current; | |
| 1713 environment = casesBuilder.environment; | |
| 1714 } else { | |
| 1715 // The translation of the cases did not emit any code. | |
| 1716 } | |
| 1717 } | |
| 1718 | |
| 1647 /// Creates a try-statement. | 1719 /// Creates a try-statement. |
| 1648 /// | 1720 /// |
| 1649 /// [tryInfo] provides information on local variables declared and boxed | 1721 /// [tryInfo] provides information on local variables declared and boxed |
| 1650 /// within this try statement. | 1722 /// within this try statement. |
| 1651 /// [buildTryBlock] builds the try block. | 1723 /// [buildTryBlock] builds the try block. |
| 1652 /// [catchClauseInfos] provides access to the catch type, exception variable, | 1724 /// [catchClauseInfos] provides access to the catch type, exception variable, |
| 1653 /// and stack trace variable, and a function for building the catch block. | 1725 /// and stack trace variable, and a function for building the catch block. |
| 1654 void buildTry( | 1726 void buildTry( |
| 1655 {TryStatementInfo tryStatementInfo, | 1727 {TryStatementInfo tryStatementInfo, |
| 1656 SubbuildFunction buildTryBlock, | 1728 SubbuildFunction buildTryBlock, |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2524 final DartType type; | 2596 final DartType type; |
| 2525 final LocalVariableElement exceptionVariable; | 2597 final LocalVariableElement exceptionVariable; |
| 2526 final LocalVariableElement stackTraceVariable; | 2598 final LocalVariableElement stackTraceVariable; |
| 2527 final SubbuildFunction buildCatchBlock; | 2599 final SubbuildFunction buildCatchBlock; |
| 2528 | 2600 |
| 2529 CatchClauseInfo({this.type, | 2601 CatchClauseInfo({this.type, |
| 2530 this.exceptionVariable, | 2602 this.exceptionVariable, |
| 2531 this.stackTraceVariable, | 2603 this.stackTraceVariable, |
| 2532 this.buildCatchBlock}); | 2604 this.buildCatchBlock}); |
| 2533 } | 2605 } |
| 2606 | |
| 2607 class SwitchCaseInfo { | |
| 2608 final List<ir.Primitive> constants = <ir.Primitive>[]; | |
| 2609 final SubbuildFunction buildBody; | |
| 2610 | |
| 2611 SwitchCaseInfo(this.buildBody); | |
| 2612 | |
| 2613 void addConstant(ir.Primitive constant) => constants.add(constant); | |
| 2614 } | |
| OLD | NEW |