| 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_backend/dart_backend.dart' show DartBackend; | 9 import '../dart_backend/dart_backend.dart' show DartBackend; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 /// Execute [f] with [builder] as the current builder. | 140 /// Execute [f] with [builder] as the current builder. |
| 141 withBuilder(IrBuilder builder, f()) { | 141 withBuilder(IrBuilder builder, f()) { |
| 142 assert(builder != null); | 142 assert(builder != null); |
| 143 IrBuilder prev = _irBuilder; | 143 IrBuilder prev = _irBuilder; |
| 144 _irBuilder = builder; | 144 _irBuilder = builder; |
| 145 var result = f(); | 145 var result = f(); |
| 146 _irBuilder = prev; | 146 _irBuilder = prev; |
| 147 return result; | 147 return result; |
| 148 } | 148 } |
| 149 | 149 |
| 150 /// `true` if an [IrBuilder] is currently set up. |
| 151 bool get hasIrBuilder => _irBuilder != null; |
| 152 |
| 150 /// The current builder. | 153 /// The current builder. |
| 151 IrBuilder get irBuilder { | 154 IrBuilder get irBuilder { |
| 152 assert(_irBuilder != null); | 155 assert(_irBuilder != null); |
| 153 return _irBuilder; | 156 return _irBuilder; |
| 154 } | 157 } |
| 155 | 158 |
| 156 /// Visits the [node]. | 159 /// Visits the [node]. |
| 157 ir.Primitive visit(N node); | 160 ir.Primitive visit(N node); |
| 158 | 161 |
| 159 /// Builds and returns the [ir.Node] for [node] or returns `null` if | 162 /// Builds and returns the [ir.Node] for [node] or returns `null` if |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 * such as `foo(){ }`. | 530 * such as `foo(){ }`. |
| 528 */ | 531 */ |
| 529 void _ensureReturn() { | 532 void _ensureReturn() { |
| 530 if (!isOpen) return; | 533 if (!isOpen) return; |
| 531 ir.Constant constant = buildNullLiteral(); | 534 ir.Constant constant = buildNullLiteral(); |
| 532 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); | 535 add(new ir.InvokeContinuation(state.returnContinuation, [constant])); |
| 533 _current = null; | 536 _current = null; |
| 534 } | 537 } |
| 535 | 538 |
| 536 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as | 539 /// Create a [ir.FieldDefinition] for the current [Element] using [_root] as |
| 537 /// the body. | 540 /// the body using [initializer] as the initial value. |
| 538 ir.FieldDefinition makeFieldDefinition() { | 541 ir.FieldDefinition makeFieldDefinition(ir.Primitive initializer) { |
| 539 return new ir.FieldDefinition(state.currentElement, | 542 if (initializer == null) { |
| 540 state.returnContinuation, | 543 return new ir.FieldDefinition.withoutInitializer(state.currentElement); |
| 541 _root); | 544 } else { |
| 545 buildReturn(initializer); |
| 546 return new ir.FieldDefinition(state.currentElement, |
| 547 state.returnContinuation, |
| 548 _root); |
| 549 } |
| 542 } | 550 } |
| 543 | 551 |
| 544 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. | 552 /// Create a [ir.FunctionDefinition] for [element] using [_root] as the body. |
| 545 /// | 553 /// |
| 546 /// Parameters must be created before the construction of the body using | 554 /// Parameters must be created before the construction of the body using |
| 547 /// [createParameter]. | 555 /// [createParameter]. |
| 548 ir.FunctionDefinition buildFunctionDefinition( | 556 ir.FunctionDefinition makeFunctionDefinition( |
| 549 List<ConstantExpression> defaults) { | 557 List<ConstantExpression> defaults) { |
| 550 FunctionElement element = state.currentElement; | 558 FunctionElement element = state.currentElement; |
| 551 if (element.isAbstract || element.isExternal) { | 559 if (element.isAbstract || element.isExternal) { |
| 552 assert(invariant(element, _root == null, | 560 assert(invariant(element, _root == null, |
| 553 message: "Non-empty body for abstract method $element: $_root")); | 561 message: "Non-empty body for abstract method $element: $_root")); |
| 554 assert(invariant(element, state.localConstants.isEmpty, | 562 assert(invariant(element, state.localConstants.isEmpty, |
| 555 message: "Local constants for abstract method $element: " | 563 message: "Local constants for abstract method $element: " |
| 556 "${state.localConstants}")); | 564 "${state.localConstants}")); |
| 557 return new ir.FunctionDefinition.abstract( | 565 return new ir.FunctionDefinition.abstract( |
| 558 element, _parameters, defaults); | 566 element, _parameters, defaults); |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1462 index = 0; | 1470 index = 0; |
| 1463 for (int i = 0; i < environment.length; ++i) { | 1471 for (int i = 0; i < environment.length; ++i) { |
| 1464 if (common[i] == null) { | 1472 if (common[i] == null) { |
| 1465 environment.index2value[i] = parameters[index++]; | 1473 environment.index2value[i] = parameters[index++]; |
| 1466 } | 1474 } |
| 1467 } | 1475 } |
| 1468 | 1476 |
| 1469 return join; | 1477 return join; |
| 1470 } | 1478 } |
| 1471 } | 1479 } |
| OLD | NEW |