| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import '../../closure.dart' show ClosureFieldElement; | 7 import '../../closure.dart' show ClosureFieldElement; |
| 8 import '../../common.dart'; | 8 import '../../common.dart'; |
| 9 import '../../common/names.dart' show Names, Selectors; | 9 import '../../common/names.dart' show Names, Selectors; |
| 10 import '../../compiler.dart' show Compiler; | 10 import '../../compiler.dart' show Compiler; |
| 11 import '../../constants/values.dart' | 11 import '../../constants/values.dart' |
| 12 show ConstantValue, InterceptorConstantValue; | 12 show ConstantValue, InterceptorConstantValue; |
| 13 import '../../core_types.dart' show CommonElements; | 13 import '../../core_types.dart' show CommonElements; |
| 14 import '../../elements/resolution_types.dart' | 14 import '../../elements/resolution_types.dart' |
| 15 show DartType, FunctionType, TypedefType; | 15 show ResolutionDartType, ResolutionFunctionType, ResolutionTypedefType; |
| 16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; | 16 import '../../deferred_load.dart' show DeferredLoadTask, OutputUnit; |
| 17 import '../../elements/elements.dart' | 17 import '../../elements/elements.dart' |
| 18 show | 18 show |
| 19 ClassElement, | 19 ClassElement, |
| 20 Element, | 20 Element, |
| 21 Elements, | 21 Elements, |
| 22 FieldElement, | 22 FieldElement, |
| 23 FunctionElement, | 23 FunctionElement, |
| 24 FunctionSignature, | 24 FunctionSignature, |
| 25 GetterElement, | 25 GetterElement, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 interceptorClass.callStubs.add(_buildStubMethod(stubName, | 377 interceptorClass.callStubs.add(_buildStubMethod(stubName, |
| 378 js.js('function(obj, v) { return obj.# = v }', [jsName]), | 378 js.js('function(obj, v) { return obj.# = v }', [jsName]), |
| 379 element: member)); | 379 element: member)); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Generating stubs for direct calls and stubs for call-through | 384 // Generating stubs for direct calls and stubs for call-through |
| 385 // of getters that happen to be functions. | 385 // of getters that happen to be functions. |
| 386 bool isFunctionLike = false; | 386 bool isFunctionLike = false; |
| 387 FunctionType functionType = null; | 387 ResolutionFunctionType functionType = null; |
| 388 | 388 |
| 389 if (member.isFunction) { | 389 if (member.isFunction) { |
| 390 FunctionElement fn = member; | 390 FunctionElement fn = member; |
| 391 functionType = fn.type; | 391 functionType = fn.type; |
| 392 } else if (member.isGetter) { | 392 } else if (member.isGetter) { |
| 393 if (_compiler.options.trustTypeAnnotations) { | 393 if (_compiler.options.trustTypeAnnotations) { |
| 394 GetterElement getter = member; | 394 GetterElement getter = member; |
| 395 DartType returnType = getter.type.returnType; | 395 ResolutionDartType returnType = getter.type.returnType; |
| 396 if (returnType.isFunctionType) { | 396 if (returnType.isFunctionType) { |
| 397 functionType = returnType; | 397 functionType = returnType; |
| 398 } else if (returnType.treatAsDynamic || | 398 } else if (returnType.treatAsDynamic || |
| 399 _compiler.types.isSubtype( | 399 _compiler.types.isSubtype( |
| 400 returnType, backend.commonElements.functionType)) { | 400 returnType, backend.commonElements.functionType)) { |
| 401 if (returnType.isTypedef) { | 401 if (returnType.isTypedef) { |
| 402 TypedefType typedef = returnType; | 402 ResolutionTypedefType typedef = returnType; |
| 403 // TODO(jacobr): can we just use typdef.unaliased instead? | 403 // TODO(jacobr): can we just use typdef.unaliased instead? |
| 404 functionType = typedef.element.functionSignature.type; | 404 functionType = typedef.element.functionSignature.type; |
| 405 } else { | 405 } else { |
| 406 // Other misc function type such as commonElements.Function. | 406 // Other misc function type such as commonElements.Function. |
| 407 // Allow any number of arguments. | 407 // Allow any number of arguments. |
| 408 isFunctionLike = true; | 408 isFunctionLike = true; |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 } else { | 411 } else { |
| 412 isFunctionLike = true; | 412 isFunctionLike = true; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 755 assert(invariant(element, !element.isConstructor)); | 755 assert(invariant(element, !element.isConstructor)); |
| 756 } | 756 } |
| 757 | 757 |
| 758 js.Name callName = null; | 758 js.Name callName = null; |
| 759 if (canTearOff) { | 759 if (canTearOff) { |
| 760 Selector callSelector = | 760 Selector callSelector = |
| 761 new Selector.fromElement(element).toCallSelector(); | 761 new Selector.fromElement(element).toCallSelector(); |
| 762 callName = namer.invocationName(callSelector); | 762 callName = namer.invocationName(callSelector); |
| 763 } | 763 } |
| 764 | 764 |
| 765 DartType memberType; | 765 ResolutionDartType memberType; |
| 766 if (element.isGenerativeConstructorBody) { | 766 if (element.isGenerativeConstructorBody) { |
| 767 // TODO(herhut): Why does this need to be normalized away? We never need | 767 // TODO(herhut): Why does this need to be normalized away? We never need |
| 768 // this information anyway as they cannot be torn off or | 768 // this information anyway as they cannot be torn off or |
| 769 // reflected. | 769 // reflected. |
| 770 var body = element; | 770 var body = element; |
| 771 memberType = body.constructor.type; | 771 memberType = body.constructor.type; |
| 772 } else { | 772 } else { |
| 773 memberType = element.type; | 773 memberType = element.type; |
| 774 } | 774 } |
| 775 | 775 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 795 tearOffName: tearOffName, | 795 tearOffName: tearOffName, |
| 796 isClosureCallMethod: isClosureCallMethod, | 796 isClosureCallMethod: isClosureCallMethod, |
| 797 aliasName: aliasName, | 797 aliasName: aliasName, |
| 798 canBeApplied: canBeApplied, | 798 canBeApplied: canBeApplied, |
| 799 canBeReflected: canBeReflected, | 799 canBeReflected: canBeReflected, |
| 800 requiredParameterCount: requiredParameterCount, | 800 requiredParameterCount: requiredParameterCount, |
| 801 optionalParameterDefaultValues: optionalParameterDefaultValues, | 801 optionalParameterDefaultValues: optionalParameterDefaultValues, |
| 802 functionType: functionType); | 802 functionType: functionType); |
| 803 } | 803 } |
| 804 | 804 |
| 805 js.Expression _generateFunctionType(DartType type, OutputUnit outputUnit) { | 805 js.Expression _generateFunctionType( |
| 806 ResolutionDartType type, OutputUnit outputUnit) { |
| 806 if (type.containsTypeVariables) { | 807 if (type.containsTypeVariables) { |
| 807 js.Expression thisAccess = js.js(r'this.$receiver'); | 808 js.Expression thisAccess = js.js(r'this.$receiver'); |
| 808 return backend.rtiEncoder.getSignatureEncoding(type, thisAccess); | 809 return backend.rtiEncoder.getSignatureEncoding(type, thisAccess); |
| 809 } else { | 810 } else { |
| 810 return backend.emitter.metadataCollector | 811 return backend.emitter.metadataCollector |
| 811 .reifyTypeForOutputUnit(type, outputUnit); | 812 .reifyTypeForOutputUnit(type, outputUnit); |
| 812 } | 813 } |
| 813 } | 814 } |
| 814 | 815 |
| 815 List<ParameterStubMethod> _generateParameterStubs( | 816 List<ParameterStubMethod> _generateParameterStubs( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 js.Name tearOffName = | 940 js.Name tearOffName = |
| 940 needsTearOff ? namer.staticClosureName(element) : null; | 941 needsTearOff ? namer.staticClosureName(element) : null; |
| 941 | 942 |
| 942 js.Name callName = null; | 943 js.Name callName = null; |
| 943 if (needsTearOff) { | 944 if (needsTearOff) { |
| 944 Selector callSelector = | 945 Selector callSelector = |
| 945 new Selector.fromElement(element).toCallSelector(); | 946 new Selector.fromElement(element).toCallSelector(); |
| 946 callName = namer.invocationName(callSelector); | 947 callName = namer.invocationName(callSelector); |
| 947 } | 948 } |
| 948 js.Expression functionType; | 949 js.Expression functionType; |
| 949 DartType type = element.type; | 950 ResolutionDartType type = element.type; |
| 950 if (needsTearOff || canBeReflected) { | 951 if (needsTearOff || canBeReflected) { |
| 951 OutputUnit outputUnit = | 952 OutputUnit outputUnit = |
| 952 _compiler.deferredLoadTask.outputUnitForElement(element); | 953 _compiler.deferredLoadTask.outputUnitForElement(element); |
| 953 functionType = _generateFunctionType(type, outputUnit); | 954 functionType = _generateFunctionType(type, outputUnit); |
| 954 } | 955 } |
| 955 | 956 |
| 956 int requiredParameterCount; | 957 int requiredParameterCount; |
| 957 var /* List | Map */ optionalParameterDefaultValues; | 958 var /* List | Map */ optionalParameterDefaultValues; |
| 958 if (canBeApplied || canBeReflected) { | 959 if (canBeApplied || canBeReflected) { |
| 959 FunctionSignature signature = element.functionSignature; | 960 FunctionSignature signature = element.functionSignature; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 989 Constant constant = new Constant(name, holder, constantValue); | 990 Constant constant = new Constant(name, holder, constantValue); |
| 990 _constants[constantValue] = constant; | 991 _constants[constantValue] = constant; |
| 991 } | 992 } |
| 992 } | 993 } |
| 993 | 994 |
| 994 Holder _registerStaticStateHolder() { | 995 Holder _registerStaticStateHolder() { |
| 995 return _registry.registerHolder(namer.staticStateHolder, | 996 return _registry.registerHolder(namer.staticStateHolder, |
| 996 isStaticStateHolder: true); | 997 isStaticStateHolder: true); |
| 997 } | 998 } |
| 998 } | 999 } |
| OLD | NEW |