| 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 '../constants/constant_system.dart'; | 7 import '../constants/constant_system.dart'; |
| 8 import '../constants/expressions.dart'; | 8 import '../constants/expressions.dart'; |
| 9 import '../constants/values.dart' show PrimitiveConstantValue; | 9 import '../constants/values.dart' show PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 /// Mutable variables are treated as boxed. Writes to them are observable | 481 /// Mutable variables are treated as boxed. Writes to them are observable |
| 482 /// side effects. | 482 /// side effects. |
| 483 Map<Local, ir.MutableVariable> mutableVariables; | 483 Map<Local, ir.MutableVariable> mutableVariables; |
| 484 | 484 |
| 485 /// True if [local] should currently be accessed from a [ir.MutableVariable]. | 485 /// True if [local] should currently be accessed from a [ir.MutableVariable]. |
| 486 bool isInMutableVariable(Local local) { | 486 bool isInMutableVariable(Local local) { |
| 487 return mutableVariables.containsKey(local); | 487 return mutableVariables.containsKey(local); |
| 488 } | 488 } |
| 489 | 489 |
| 490 /// Creates a [ir.MutableVariable] for the given local. | 490 /// Creates a [ir.MutableVariable] for the given local. |
| 491 void makeMutableVariable(Local local) { | 491 void makeMutableVariable(Local local, [ClosureClassMap closureMap]) { |
| 492 mutableVariables[local] = | 492 ExecutableElement owner; |
| 493 new ir.MutableVariable(local.executableContext, local); | 493 if (closureMap == null || closureMap.closureClassElement == null) { |
| 494 owner = local.executableContext; |
| 495 } else { |
| 496 assert(local.executableContext == closureMap.closureElement); |
| 497 owner = closureMap.callElement; |
| 498 } |
| 499 mutableVariables[local] = new ir.MutableVariable(owner, local); |
| 494 } | 500 } |
| 495 | 501 |
| 496 /// Remove an [ir.MutableVariable] for a local. | 502 /// Remove an [ir.MutableVariable] for a local. |
| 497 /// | 503 /// |
| 498 /// Subsequent access to the local will be direct rather than through the | 504 /// Subsequent access to the local will be direct rather than through the |
| 499 /// mutable variable. | 505 /// mutable variable. |
| 500 void removeMutableVariable(Local local) { | 506 void removeMutableVariable(Local local) { |
| 501 mutableVariables.remove(local); | 507 mutableVariables.remove(local); |
| 502 } | 508 } |
| 503 | 509 |
| (...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1699 /// Creates a try-statement. | 1705 /// Creates a try-statement. |
| 1700 /// | 1706 /// |
| 1701 /// [tryInfo] provides information on local variables declared and boxed | 1707 /// [tryInfo] provides information on local variables declared and boxed |
| 1702 /// within this try statement. | 1708 /// within this try statement. |
| 1703 /// [buildTryBlock] builds the try block. | 1709 /// [buildTryBlock] builds the try block. |
| 1704 /// [catchClauseInfos] provides access to the catch type, exception variable, | 1710 /// [catchClauseInfos] provides access to the catch type, exception variable, |
| 1705 /// and stack trace variable, and a function for building the catch block. | 1711 /// and stack trace variable, and a function for building the catch block. |
| 1706 void buildTry( | 1712 void buildTry( |
| 1707 {TryStatementInfo tryStatementInfo, | 1713 {TryStatementInfo tryStatementInfo, |
| 1708 SubbuildFunction buildTryBlock, | 1714 SubbuildFunction buildTryBlock, |
| 1709 List<CatchClauseInfo> catchClauseInfos: const <CatchClauseInfo>[]}) { | 1715 List<CatchClauseInfo> catchClauseInfos: const <CatchClauseInfo>[], |
| 1716 ClosureClassMap closureClassMap}) { |
| 1710 assert(isOpen); | 1717 assert(isOpen); |
| 1711 | 1718 |
| 1712 // Catch handlers are in scope for their body. The CPS translation of | 1719 // Catch handlers are in scope for their body. The CPS translation of |
| 1713 // [[try tryBlock catch (e) catchBlock; successor]] is: | 1720 // [[try tryBlock catch (e) catchBlock; successor]] is: |
| 1714 // | 1721 // |
| 1715 // let cont join(v0, v1, ...) = [[successor]] in | 1722 // let cont join(v0, v1, ...) = [[successor]] in |
| 1716 // let mutable m0 = x0 in | 1723 // let mutable m0 = x0 in |
| 1717 // let mutable m1 = x1 in | 1724 // let mutable m1 = x1 in |
| 1718 // ... | 1725 // ... |
| 1719 // let handler catch_(e) = | 1726 // let handler catch_(e) = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1741 JumpCollector join = new ForwardJumpCollector(environment); | 1748 JumpCollector join = new ForwardJumpCollector(environment); |
| 1742 IrBuilder tryCatchBuilder = makeDelimitedBuilder(); | 1749 IrBuilder tryCatchBuilder = makeDelimitedBuilder(); |
| 1743 | 1750 |
| 1744 // Variables treated as mutable in a try are not mutable outside of it. | 1751 // Variables treated as mutable in a try are not mutable outside of it. |
| 1745 // Work with a copy of the outer builder's mutable variables. | 1752 // Work with a copy of the outer builder's mutable variables. |
| 1746 tryCatchBuilder.mutableVariables = | 1753 tryCatchBuilder.mutableVariables = |
| 1747 new Map<Local, ir.MutableVariable>.from(mutableVariables); | 1754 new Map<Local, ir.MutableVariable>.from(mutableVariables); |
| 1748 for (LocalVariableElement variable in tryStatementInfo.boxedOnEntry) { | 1755 for (LocalVariableElement variable in tryStatementInfo.boxedOnEntry) { |
| 1749 assert(!tryCatchBuilder.isInMutableVariable(variable)); | 1756 assert(!tryCatchBuilder.isInMutableVariable(variable)); |
| 1750 ir.Primitive value = tryCatchBuilder.buildLocalVariableGet(variable); | 1757 ir.Primitive value = tryCatchBuilder.buildLocalVariableGet(variable); |
| 1751 tryCatchBuilder.makeMutableVariable(variable); | 1758 tryCatchBuilder.makeMutableVariable(variable, closureClassMap); |
| 1752 tryCatchBuilder.declareLocalVariable(variable, initialValue: value); | 1759 tryCatchBuilder.declareLocalVariable(variable, initialValue: value); |
| 1753 } | 1760 } |
| 1754 | 1761 |
| 1755 IrBuilder tryBuilder = tryCatchBuilder.makeDelimitedBuilder(); | 1762 IrBuilder tryBuilder = tryCatchBuilder.makeDelimitedBuilder(); |
| 1756 | 1763 |
| 1757 void interceptJumps(JumpCollector collector) { | 1764 void interceptJumps(JumpCollector collector) { |
| 1758 collector.enterTry(tryStatementInfo.boxedOnEntry); | 1765 collector.enterTry(tryStatementInfo.boxedOnEntry); |
| 1759 } | 1766 } |
| 1760 void restoreJumps(JumpCollector collector) { | 1767 void restoreJumps(JumpCollector collector) { |
| 1761 collector.leaveTry(); | 1768 collector.leaveTry(); |
| (...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 } | 2662 } |
| 2656 | 2663 |
| 2657 /// Synthetic parameter to a JavaScript factory method that takes the type | 2664 /// Synthetic parameter to a JavaScript factory method that takes the type |
| 2658 /// argument given for the type variable [variable]. | 2665 /// argument given for the type variable [variable]. |
| 2659 class TypeInformationParameter implements Local { | 2666 class TypeInformationParameter implements Local { |
| 2660 final TypeVariableElement variable; | 2667 final TypeVariableElement variable; |
| 2661 final ExecutableElement executableContext; | 2668 final ExecutableElement executableContext; |
| 2662 TypeInformationParameter(this.variable, this.executableContext); | 2669 TypeInformationParameter(this.variable, this.executableContext); |
| 2663 String get name => variable.name; | 2670 String get name => variable.name; |
| 2664 } | 2671 } |
| OLD | NEW |