| 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_task; | 5 library dart2js.ir_builder_task; |
| 6 | 6 |
| 7 import '../closure.dart' as closure; | 7 import '../closure.dart' as closure; |
| 8 import '../common.dart'; | 8 import '../common.dart'; |
| 9 import '../common/names.dart' show | 9 import '../common/names.dart' show |
| 10 Names, | 10 Names, |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 /// 5. Returns the created object. | 375 /// 5. Returns the created object. |
| 376 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) { | 376 ir.FunctionDefinition buildConstructor(ConstructorElement constructor) { |
| 377 // TODO(asgerf): Optimization: If constructor is redirecting, then just | 377 // TODO(asgerf): Optimization: If constructor is redirecting, then just |
| 378 // evaluate arguments and call the target constructor. | 378 // evaluate arguments and call the target constructor. |
| 379 constructor = constructor.implementation; | 379 constructor = constructor.implementation; |
| 380 ClassElement classElement = constructor.enclosingClass.implementation; | 380 ClassElement classElement = constructor.enclosingClass.implementation; |
| 381 | 381 |
| 382 IrBuilder builder = getBuilderFor(constructor); | 382 IrBuilder builder = getBuilderFor(constructor); |
| 383 | 383 |
| 384 final bool requiresTypeInformation = | 384 final bool requiresTypeInformation = |
| 385 builder.program.requiresRuntimeTypesFor(classElement); | 385 builder.program.requiresRuntimeTypesFor(classElement); |
| 386 | 386 |
| 387 return withBuilder(builder, () { | 387 return withBuilder(builder, () { |
| 388 // Setup parameters and create a box if anything is captured. | 388 // Setup parameters and create a box if anything is captured. |
| 389 List<Local> parameters = <Local>[]; | 389 List<Local> parameters = <Local>[]; |
| 390 constructor.functionSignature.orderedForEachParameter( | 390 constructor.functionSignature.orderedForEachParameter( |
| 391 (ParameterElement p) => parameters.add(p)); | 391 (ParameterElement p) => parameters.add(p)); |
| 392 | 392 |
| 393 int firstTypeArgumentParameterIndex; | 393 int firstTypeArgumentParameterIndex; |
| 394 | 394 |
| 395 // If instances of the class may need runtime type information, we add a | 395 // If instances of the class may need runtime type information, we add a |
| 396 // synthetic parameter for each type parameter. | 396 // synthetic parameter for each type parameter. |
| 397 if (requiresTypeInformation) { | 397 if (requiresTypeInformation) { |
| 398 firstTypeArgumentParameterIndex = parameters.length; | 398 firstTypeArgumentParameterIndex = parameters.length; |
| 399 classElement.typeVariables.forEach((TypeVariableType variable) { | 399 classElement.typeVariables.forEach((TypeVariableType variable) { |
| 400 parameters.add(new closure.TypeVariableLocal(variable, constructor)); | 400 parameters.add(new closure.TypeVariableLocal(variable, constructor)); |
| 401 }); | 401 }); |
| 402 } else { | 402 } else { |
| 403 classElement.typeVariables.forEach((TypeVariableType variable) { | 403 classElement.typeVariables.forEach((TypeVariableType variable) { |
| 404 irBuilder.declareTypeVariable(variable, const DynamicType()); | 404 irBuilder.declareTypeVariable(variable, const DynamicType()); |
| 405 }); | 405 }); |
| 406 } | 406 } |
| 407 | 407 |
| 408 // Create IR parameters and setup the environment. | 408 // Create IR parameters and setup the environment. |
| 409 List<ir.Parameter> irParameters = builder.buildFunctionHeader(parameters, | 409 List<ir.Parameter> irParameters = builder.buildFunctionHeader(parameters, |
| 410 closureScope: getClosureScopeForFunction(constructor)); | 410 closureScope: getClosureScopeForFunction(constructor)); |
| 411 | 411 |
| 412 // Create a list of the values of all type argument parameters, if any. | 412 // Create a list of the values of all type argument parameters, if any. |
| 413 List<ir.Primitive> typeInformation; | 413 ir.Primitive typeInformation; |
| 414 if (requiresTypeInformation) { | 414 if (requiresTypeInformation) { |
| 415 typeInformation = irParameters.sublist(firstTypeArgumentParameterIndex); | 415 typeInformation = new ir.TypeExpression( |
| 416 ir.TypeExpressionKind.INSTANCE, |
| 417 classElement.thisType, |
| 418 irParameters.sublist(firstTypeArgumentParameterIndex)); |
| 419 irBuilder.add(new ir.LetPrim(typeInformation)); |
| 416 } else { | 420 } else { |
| 417 typeInformation = const <ir.Primitive>[]; | 421 typeInformation = null; |
| 418 } | 422 } |
| 419 | 423 |
| 420 // -- Load values for type variables declared on super classes -- | 424 // -- Load values for type variables declared on super classes -- |
| 421 // Field initializers for super classes can reference these, so they | 425 // Field initializers for super classes can reference these, so they |
| 422 // must be available before evaluating field initializers. | 426 // must be available before evaluating field initializers. |
| 423 // This could be interleaved with field initialization, but we choose do | 427 // This could be interleaved with field initialization, but we choose do |
| 424 // get it out of the way here to avoid complications with mixins. | 428 // get it out of the way here to avoid complications with mixins. |
| 425 loadTypeVariablesForSuperClasses(classElement); | 429 loadTypeVariablesForSuperClasses(classElement); |
| 426 | 430 |
| 427 /// Maps each field from this class or a superclass to its initial value. | 431 /// Maps each field from this class or a superclass to its initial value. |
| (...skipping 3395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3823 } | 3827 } |
| 3824 | 3828 |
| 3825 Element get closureConverter { | 3829 Element get closureConverter { |
| 3826 return _backend.helpers.closureConverter; | 3830 return _backend.helpers.closureConverter; |
| 3827 } | 3831 } |
| 3828 | 3832 |
| 3829 void addNativeMethod(FunctionElement function) { | 3833 void addNativeMethod(FunctionElement function) { |
| 3830 _backend.emitter.nativeEmitter.nativeMethods.add(function); | 3834 _backend.emitter.nativeEmitter.nativeMethods.add(function); |
| 3831 } | 3835 } |
| 3832 } | 3836 } |
| OLD | NEW |