Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 import '../common.dart'; | 5 import '../common.dart'; |
| 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; | 6 import '../common/codegen.dart' show CodegenRegistry, CodegenWorkItem; |
| 7 import '../common/tasks.dart' show CompilerTask; | 7 import '../common/tasks.dart' show CompilerTask; |
| 8 import '../compiler.dart' show Compiler; | 8 import '../compiler.dart' show Compiler; |
| 9 import '../constants/constant_system.dart'; | 9 import '../constants/constant_system.dart'; |
| 10 import '../constants/values.dart'; | 10 import '../constants/values.dart'; |
| (...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2848 } else { | 2848 } else { |
| 2849 var arguments = [ | 2849 var arguments = [ |
| 2850 returnType, | 2850 returnType, |
| 2851 new js.ArrayInitializer(parameterTypes), | 2851 new js.ArrayInitializer(parameterTypes), |
| 2852 new js.ObjectInitializer(namedParameters) | 2852 new js.ObjectInitializer(namedParameters) |
| 2853 ]; | 2853 ]; |
| 2854 push(js.js('#(#)', [accessHelper('buildNamedFunctionType'), arguments])); | 2854 push(js.js('#(#)', [accessHelper('buildNamedFunctionType'), arguments])); |
| 2855 } | 2855 } |
| 2856 } | 2856 } |
| 2857 | 2857 |
| 2858 void visitTypeInfoReadRaw(HTypeInfoReadRaw node) { | |
| 2859 use(node.inputs[0]); | |
| 2860 js.Expression receiver = pop(); | |
| 2861 push(js.js(r'#.$builtinTypeInfo', receiver)); | |
|
Siggi Cherem (dart-lang)
2016/08/19 18:21:46
I thought $builtinTypeInfo was replaced by $ti, is
sra1
2016/08/19 18:47:43
Yes, the renaming is part of the other CL
| |
| 2862 } | |
| 2863 | |
| 2864 void visitTypeInfoReadVariable(HTypeInfoReadVariable node) { | |
| 2865 TypeVariableElement element = node.variable.element; | |
| 2866 ClassElement context = element.enclosingClass; | |
| 2867 | |
| 2868 int index = element.index; | |
| 2869 use(node.inputs[0]); | |
| 2870 js.Expression receiver = pop(); | |
| 2871 | |
| 2872 if (needsSubstitutionForTypeVariableAccess(context)) { | |
| 2873 js.Expression typeName = | |
| 2874 js.quoteName(backend.namer.runtimeTypeName(context)); | |
| 2875 Element helperElement = helpers.getRuntimeTypeArgument; | |
| 2876 registry.registerStaticUse( | |
| 2877 new StaticUse.staticInvoke(helperElement, CallStructure.THREE_ARGS)); | |
|
Siggi Cherem (dart-lang)
2016/08/19 18:21:46
I'm surprised we never registered this before (eve
sra1
2016/08/19 18:47:43
No bug. It was registered via being lowered to a H
| |
| 2878 js.Expression helper = | |
| 2879 backend.emitter.staticFunctionAccess(helperElement); | |
| 2880 push(js.js( | |
| 2881 r'#(#, #, #)', [helper, receiver, typeName, js.js.number(index)])); | |
| 2882 } else { | |
| 2883 Element helperElement = helpers.getTypeArgumentByIndex; | |
| 2884 registry.registerStaticUse( | |
| 2885 new StaticUse.staticInvoke(helperElement, CallStructure.TWO_ARGS)); | |
| 2886 js.Expression helper = | |
| 2887 backend.emitter.staticFunctionAccess(helperElement); | |
| 2888 push(js.js(r'#(#, #)', [helper, receiver, js.js.number(index)])); | |
| 2889 } | |
| 2890 } | |
| 2891 | |
| 2892 void visitTypeInfoExpression(HTypeInfoExpression node) { | |
| 2893 List<js.Expression> arguments = <js.Expression>[]; | |
| 2894 for (HInstruction input in node.inputs) { | |
| 2895 use(input); | |
| 2896 arguments.add(pop()); | |
| 2897 } | |
| 2898 | |
| 2899 switch (node.kind) { | |
| 2900 case TypeInfoExpressionKind.COMPLETE: | |
| 2901 int index = 0; | |
| 2902 js.Expression result = backend.rtiEncoder.getTypeRepresentation( | |
| 2903 node.dartType, | |
| 2904 (TypeVariableType variable) => arguments[index++]); | |
| 2905 if (index != node.inputs.length) { | |
| 2906 print('$node $index ${node.inputs}'); | |
|
Siggi Cherem (dart-lang)
2016/08/19 18:21:46
delete debug code?
sra1
2016/08/19 18:47:43
Done. That was from debugging https://codereview.c
| |
| 2907 } | |
| 2908 assert(index == node.inputs.length); | |
| 2909 push(result); | |
| 2910 return; | |
| 2911 | |
| 2912 case TypeInfoExpressionKind.INSTANCE: | |
| 2913 // We expect only flat types for the INSTANCE representation. | |
| 2914 assert( | |
| 2915 node.dartType == (node.dartType.element as ClassElement).thisType); | |
| 2916 registry.registerInstantiatedClass(coreClasses.listClass); | |
| 2917 push(new js.ArrayInitializer(arguments) | |
| 2918 .withSourceInformation(node.sourceInformation)); | |
| 2919 } | |
| 2920 } | |
| 2921 | |
| 2922 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | |
| 2923 ClassWorld classWorld = compiler.world; | |
| 2924 if (classWorld.isUsedAsMixin(cls)) return true; | |
| 2925 | |
| 2926 return compiler.world.anyStrictSubclassOf(cls, (ClassElement subclass) { | |
| 2927 return !backend.rti.isTrivialSubstitution(subclass, cls); | |
| 2928 }); | |
| 2929 } | |
| 2930 | |
| 2858 void visitReadTypeVariable(HReadTypeVariable node) { | 2931 void visitReadTypeVariable(HReadTypeVariable node) { |
| 2859 TypeVariableElement element = node.dartType.element; | 2932 TypeVariableElement element = node.dartType.element; |
| 2860 Element helperElement = helpers.convertRtiToRuntimeType; | 2933 Element helperElement = helpers.convertRtiToRuntimeType; |
| 2861 registry.registerStaticUse( | 2934 registry.registerStaticUse( |
| 2862 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG)); | 2935 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG)); |
| 2863 | 2936 |
| 2864 use(node.inputs[0]); | 2937 use(node.inputs[0]); |
| 2865 if (node.hasReceiver) { | 2938 if (node.hasReceiver) { |
| 2866 if (backend.isInterceptorClass(element.enclosingClass)) { | 2939 if (backend.isInterceptorClass(element.enclosingClass)) { |
| 2867 int index = element.index; | 2940 int index = element.index; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2914 registry.registerStaticUse(new StaticUse.staticInvoke( | 2987 registry.registerStaticUse(new StaticUse.staticInvoke( |
| 2915 helper, new CallStructure.unnamed(argumentCount))); | 2988 helper, new CallStructure.unnamed(argumentCount))); |
| 2916 return backend.emitter.staticFunctionAccess(helper); | 2989 return backend.emitter.staticFunctionAccess(helper); |
| 2917 } | 2990 } |
| 2918 | 2991 |
| 2919 @override | 2992 @override |
| 2920 void visitRef(HRef node) { | 2993 void visitRef(HRef node) { |
| 2921 visit(node.value); | 2994 visit(node.value); |
| 2922 } | 2995 } |
| 2923 } | 2996 } |
| OLD | NEW |