| 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/values.dart' show ConstantValue, PrimitiveConstantValue; | 9 import '../constants/values.dart' show ConstantValue, PrimitiveConstantValue; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 void _buildTryExit(IrBuilder builder) { | 185 void _buildTryExit(IrBuilder builder) { |
| 186 for (Iterable<LocalVariableElement> boxedOnEntry in _boxedTryVariables) { | 186 for (Iterable<LocalVariableElement> boxedOnEntry in _boxedTryVariables) { |
| 187 for (LocalVariableElement variable in boxedOnEntry) { | 187 for (LocalVariableElement variable in boxedOnEntry) { |
| 188 assert(builder.isInMutableVariable(variable)); | 188 assert(builder.isInMutableVariable(variable)); |
| 189 ir.Primitive value = builder.buildLocalVariableGet(variable); | 189 ir.Primitive value = builder.buildLocalVariableGet(variable); |
| 190 builder.environment.update(variable, value); | 190 builder.environment.update(variable, value); |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 |
| 195 /// True if a jump inserted now will escape from a try block. |
| 196 /// |
| 197 /// Concretely, this is true when [enterTry] has been called without |
| 198 /// its corresponding [leaveTry] call. |
| 199 bool get isEscapingTry => _boxedTryVariables.isNotEmpty; |
| 194 } | 200 } |
| 195 | 201 |
| 196 /// A class to collect 'forward' jumps. | 202 /// A class to collect 'forward' jumps. |
| 197 /// | 203 /// |
| 198 /// A forward jump to a continuation in the sense of the CPS translation is | 204 /// A forward jump to a continuation in the sense of the CPS translation is |
| 199 /// a jump where the jump is emitted before any code in the body of the | 205 /// a jump where the jump is emitted before any code in the body of the |
| 200 /// continuation is translated. They have the property that continuation | 206 /// continuation is translated. They have the property that continuation |
| 201 /// parameters and the environment for the translation of the body can be | 207 /// parameters and the environment for the translation of the body can be |
| 202 /// determined based on the invocations, before translating the body. A | 208 /// determined based on the invocations, before translating the body. A |
| 203 /// [ForwardJumpCollector] can encapsulate a continuation where all the | 209 /// [ForwardJumpCollector] can encapsulate a continuation where all the |
| (...skipping 30 matching lines...) Expand all Loading... |
| 234 } | 240 } |
| 235 | 241 |
| 236 Environment get environment { | 242 Environment get environment { |
| 237 if (_continuation == null) _setContinuation(); | 243 if (_continuation == null) _setContinuation(); |
| 238 return _continuationEnvironment; | 244 return _continuationEnvironment; |
| 239 } | 245 } |
| 240 | 246 |
| 241 void addJump(IrBuilder builder, [ir.Primitive value]) { | 247 void addJump(IrBuilder builder, [ir.Primitive value]) { |
| 242 assert(_continuation == null); | 248 assert(_continuation == null); |
| 243 _buildTryExit(builder); | 249 _buildTryExit(builder); |
| 244 ir.InvokeContinuation invoke = new ir.InvokeContinuation.uninitialized(); | 250 ir.InvokeContinuation invoke = new ir.InvokeContinuation.uninitialized( |
| 251 isEscapingTry: isEscapingTry); |
| 245 builder.add(invoke); | 252 builder.add(invoke); |
| 246 _invocations.add(invoke); | 253 _invocations.add(invoke); |
| 247 // Truncate the environment at the invocation site so it only includes | 254 // Truncate the environment at the invocation site so it only includes |
| 248 // values that will be continuation arguments. If an extra value is passed | 255 // values that will be continuation arguments. If an extra value is passed |
| 249 // it will already be included in the continuation environment, but it is | 256 // it will already be included in the continuation environment, but it is |
| 250 // not present in the invocation environment. | 257 // not present in the invocation environment. |
| 251 int delta = builder.environment.length - _continuationEnvironment.length; | 258 int delta = builder.environment.length - _continuationEnvironment.length; |
| 252 if (value != null) ++delta; | 259 if (value != null) ++delta; |
| 253 if (delta > 0) builder.environment.discard(delta); | 260 if (delta > 0) builder.environment.discard(delta); |
| 254 if (value != null) builder.environment.extend(null, value); | 261 if (value != null) builder.environment.extend(null, value); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 // Truncate the environment at the invocation site so it only includes | 360 // Truncate the environment at the invocation site so it only includes |
| 354 // values that will be continuation arguments. If an extra value is passed | 361 // values that will be continuation arguments. If an extra value is passed |
| 355 // it will already be included in the continuation environment, but it is | 362 // it will already be included in the continuation environment, but it is |
| 356 // not present in the invocation environment. | 363 // not present in the invocation environment. |
| 357 int delta = builder.environment.length - _continuationEnvironment.length; | 364 int delta = builder.environment.length - _continuationEnvironment.length; |
| 358 if (value != null) ++delta; | 365 if (value != null) ++delta; |
| 359 if (delta > 0) builder.environment.discard(delta); | 366 if (delta > 0) builder.environment.discard(delta); |
| 360 if (value != null) builder.environment.extend(null, value); | 367 if (value != null) builder.environment.extend(null, value); |
| 361 builder.add(new ir.InvokeContinuation(_continuation, | 368 builder.add(new ir.InvokeContinuation(_continuation, |
| 362 builder.environment.index2value, | 369 builder.environment.index2value, |
| 363 isRecursive: true)); | 370 isRecursive: true, |
| 371 isEscapingTry: isEscapingTry)); |
| 364 builder._current = null; | 372 builder._current = null; |
| 365 } | 373 } |
| 366 } | 374 } |
| 367 | 375 |
| 368 /// Function for building a node in the context of the current builder. | 376 /// Function for building a node in the context of the current builder. |
| 369 typedef ir.Node BuildFunction(node); | 377 typedef ir.Node BuildFunction(node); |
| 370 | 378 |
| 371 /// Function for building nodes in the context of the provided [builder]. | 379 /// Function for building nodes in the context of the provided [builder]. |
| 372 typedef ir.Node SubbuildFunction(IrBuilder builder); | 380 typedef ir.Node SubbuildFunction(IrBuilder builder); |
| 373 | 381 |
| (...skipping 2316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2690 } | 2698 } |
| 2691 | 2699 |
| 2692 class SwitchCaseInfo { | 2700 class SwitchCaseInfo { |
| 2693 final List<ir.Primitive> constants = <ir.Primitive>[]; | 2701 final List<ir.Primitive> constants = <ir.Primitive>[]; |
| 2694 final SubbuildFunction buildBody; | 2702 final SubbuildFunction buildBody; |
| 2695 | 2703 |
| 2696 SwitchCaseInfo(this.buildBody); | 2704 SwitchCaseInfo(this.buildBody); |
| 2697 | 2705 |
| 2698 void addConstant(ir.Primitive constant) => constants.add(constant); | 2706 void addConstant(ir.Primitive constant) => constants.add(constant); |
| 2699 } | 2707 } |
| OLD | NEW |