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 '../constants/expressions.dart'; | 7 import '../constants/expressions.dart'; |
| 8 import '../constants/values.dart' show PrimitiveConstantValue; | 8 import '../constants/values.dart' show PrimitiveConstantValue; |
| 9 import '../dart_types.dart'; | 9 import '../dart_types.dart'; |
| 10 import '../dart2jslib.dart'; | 10 import '../dart2jslib.dart'; |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 /// or put it in its box, if necessary. | 469 /// or put it in its box, if necessary. |
| 470 void _createFunctionParameter(Local parameterElement); | 470 void _createFunctionParameter(Local parameterElement); |
| 471 void _createThisParameter(); | 471 void _createThisParameter(); |
| 472 | 472 |
| 473 /// Creates an access to the receiver from the current (or enclosing) method. | 473 /// Creates an access to the receiver from the current (or enclosing) method. |
| 474 /// | 474 /// |
| 475 /// If inside a closure class, [buildThis] will redirect access through | 475 /// If inside a closure class, [buildThis] will redirect access through |
| 476 /// closure fields in order to access the receiver from the enclosing method. | 476 /// closure fields in order to access the receiver from the enclosing method. |
| 477 ir.Primitive buildThis(); | 477 ir.Primitive buildThis(); |
| 478 | 478 |
| 479 // TODO(johnniwinther): Make these field final and remove the default values | 479 // TODO(johnniwinther): Make these field final and remove the default values |
|
Kevin Millikin (Google)
2015/04/15 15:14:58
I guess this comment was referring to the field I
| |
| 480 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin. | 480 // when [IrBuilder] is a property of [IrBuilderVisitor] instead of a mixin. |
| 481 | 481 |
| 482 final List<ir.Parameter> _parameters = <ir.Parameter>[]; | |
| 483 | |
| 484 IrBuilderDelimitedState state; | 482 IrBuilderDelimitedState state; |
| 485 | 483 |
| 486 /// A map from variable indexes to their values. | 484 /// A map from variable indexes to their values. |
| 487 /// | 485 /// |
| 488 /// [BoxLocal]s map to their box. [LocalElement]s that are boxed are not | 486 /// [BoxLocal]s map to their box. [LocalElement]s that are boxed are not |
| 489 /// in the map; look up their [BoxLocal] instead. | 487 /// in the map; look up their [BoxLocal] instead. |
| 490 Environment environment; | 488 Environment environment; |
| 491 | 489 |
| 492 // The IR builder maintains a context, which is an expression with a hole in | 490 // The IR builder maintains a context, which is an expression with a hole in |
| 493 // it. The hole represents the focus where new expressions can be added. | 491 // it. The hole represents the focus where new expressions can be added. |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 ..environment = new Environment.empty(); | 553 ..environment = new Environment.empty(); |
| 556 } | 554 } |
| 557 | 555 |
| 558 bool get isOpen => _root == null || _current != null; | 556 bool get isOpen => _root == null || _current != null; |
| 559 | 557 |
| 560 | 558 |
| 561 void buildFieldInitializerHeader({ClosureScope closureScope}) { | 559 void buildFieldInitializerHeader({ClosureScope closureScope}) { |
| 562 _enterScope(closureScope); | 560 _enterScope(closureScope); |
| 563 } | 561 } |
| 564 | 562 |
| 565 List<ir.Primitive> buildFunctionHeader(Iterable<Local> parameters, | 563 void buildFunctionHeader(Iterable<Local> parameters, |
| 566 {ClosureScope closureScope, | 564 {ClosureScope closureScope, |
| 567 ClosureEnvironment env}) { | 565 ClosureEnvironment env}) { |
| 568 _createThisParameter(); | 566 _createThisParameter(); |
| 569 _enterClosureEnvironment(env); | 567 _enterClosureEnvironment(env); |
| 570 _enterScope(closureScope); | 568 _enterScope(closureScope); |
| 571 parameters.forEach(_createFunctionParameter); | 569 parameters.forEach(_createFunctionParameter); |
| 572 return _parameters; | |
| 573 } | 570 } |
| 574 | 571 |
| 575 /// Creates a parameter for [local] and adds it to the current environment. | 572 /// Creates a parameter for [local] and adds it to the current environment. |
| 576 ir.Parameter createLocalParameter(Local local) { | 573 ir.Parameter createLocalParameter(Local local) { |
| 577 ir.Parameter parameter = new ir.Parameter(local); | 574 ir.Parameter parameter = new ir.Parameter(local); |
| 578 _parameters.add(parameter); | |
| 579 environment.extend(local, parameter); | 575 environment.extend(local, parameter); |
| 580 return parameter; | 576 return parameter; |
| 581 } | 577 } |
| 582 | 578 |
| 583 /// Adds the constant [variableElement] to the environment with [value] as its | 579 /// Adds the constant [variableElement] to the environment with [value] as its |
| 584 /// constant value. | 580 /// constant value. |
| 585 void declareLocalConstant(LocalVariableElement variableElement, | 581 void declareLocalConstant(LocalVariableElement variableElement, |
| 586 ConstantExpression value) { | 582 ConstantExpression value) { |
| 587 state.localConstants.add(new ConstDeclaration(variableElement, value)); | 583 state.localConstants.add(new ConstDeclaration(variableElement, value)); |
| 588 } | 584 } |
| (...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2183 ir.Primitive value = | 2179 ir.Primitive value = |
| 2184 addPrimitive(new ir.GetMutableVariable(mutableVariable)); | 2180 addPrimitive(new ir.GetMutableVariable(mutableVariable)); |
| 2185 environment.update(loopVariable, value); | 2181 environment.update(loopVariable, value); |
| 2186 dartState.registerizedMutableVariables.add(loopVariable); | 2182 dartState.registerizedMutableVariables.add(loopVariable); |
| 2187 } | 2183 } |
| 2188 } | 2184 } |
| 2189 } | 2185 } |
| 2190 | 2186 |
| 2191 void _createFunctionParameter(Local parameterElement) { | 2187 void _createFunctionParameter(Local parameterElement) { |
| 2192 ir.Parameter parameter = new ir.Parameter(parameterElement); | 2188 ir.Parameter parameter = new ir.Parameter(parameterElement); |
| 2193 _parameters.add(parameter); | |
| 2194 if (isInMutableVariable(parameterElement)) { | 2189 if (isInMutableVariable(parameterElement)) { |
| 2195 state.functionParameters.add(getMutableVariable(parameterElement)); | 2190 state.functionParameters.add(getMutableVariable(parameterElement)); |
| 2196 } else { | 2191 } else { |
| 2197 state.functionParameters.add(parameter); | 2192 state.functionParameters.add(parameter); |
| 2198 environment.extend(parameterElement, parameter); | 2193 environment.extend(parameterElement, parameter); |
| 2199 } | 2194 } |
| 2200 } | 2195 } |
| 2201 | 2196 |
| 2202 void _createThisParameter() { | 2197 void _createThisParameter() { |
| 2203 void create() { | 2198 void create() { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2392 scope.capturedVariables.forEach((Local local, ClosureLocation location) { | 2387 scope.capturedVariables.forEach((Local local, ClosureLocation location) { |
| 2393 assert(!jsState.boxedVariables.containsKey(local)); | 2388 assert(!jsState.boxedVariables.containsKey(local)); |
| 2394 if (location.isBox) { | 2389 if (location.isBox) { |
| 2395 jsState.boxedVariables[local] = location; | 2390 jsState.boxedVariables[local] = location; |
| 2396 } | 2391 } |
| 2397 }); | 2392 }); |
| 2398 } | 2393 } |
| 2399 | 2394 |
| 2400 void _createFunctionParameter(Local parameterElement) { | 2395 void _createFunctionParameter(Local parameterElement) { |
| 2401 ir.Parameter parameter = new ir.Parameter(parameterElement); | 2396 ir.Parameter parameter = new ir.Parameter(parameterElement); |
| 2402 _parameters.add(parameter); | |
| 2403 state.functionParameters.add(parameter); | 2397 state.functionParameters.add(parameter); |
| 2404 ClosureLocation location = jsState.boxedVariables[parameterElement]; | 2398 ClosureLocation location = jsState.boxedVariables[parameterElement]; |
| 2405 if (location != null) { | 2399 if (location != null) { |
| 2406 add(new ir.SetField(environment.lookup(location.box), | 2400 add(new ir.SetField(environment.lookup(location.box), |
| 2407 location.field, | 2401 location.field, |
| 2408 parameter)); | 2402 parameter)); |
| 2409 } else { | 2403 } else { |
| 2410 environment.extend(parameterElement, parameter); | 2404 environment.extend(parameterElement, parameter); |
| 2411 } | 2405 } |
| 2412 } | 2406 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2698 } | 2692 } |
| 2699 | 2693 |
| 2700 /// Synthetic parameter to a JavaScript factory method that takes the type | 2694 /// Synthetic parameter to a JavaScript factory method that takes the type |
| 2701 /// argument given for the type variable [variable]. | 2695 /// argument given for the type variable [variable]. |
| 2702 class TypeInformationParameter implements Local { | 2696 class TypeInformationParameter implements Local { |
| 2703 final TypeVariableElement variable; | 2697 final TypeVariableElement variable; |
| 2704 final ExecutableElement executableContext; | 2698 final ExecutableElement executableContext; |
| 2705 TypeInformationParameter(this.variable, this.executableContext); | 2699 TypeInformationParameter(this.variable, this.executableContext); |
| 2706 String get name => variable.name; | 2700 String get name => variable.name; |
| 2707 } | 2701 } |
| OLD | NEW |