| 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 2840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2851 } | 2851 } |
| 2852 | 2852 |
| 2853 void visitTypeInfoReadRaw(HTypeInfoReadRaw node) { | 2853 void visitTypeInfoReadRaw(HTypeInfoReadRaw node) { |
| 2854 use(node.inputs[0]); | 2854 use(node.inputs[0]); |
| 2855 js.Expression receiver = pop(); | 2855 js.Expression receiver = pop(); |
| 2856 push(js.js(r'#.#', [receiver, backend.namer.rtiFieldName])); | 2856 push(js.js(r'#.#', [receiver, backend.namer.rtiFieldName])); |
| 2857 } | 2857 } |
| 2858 | 2858 |
| 2859 void visitTypeInfoReadVariable(HTypeInfoReadVariable node) { | 2859 void visitTypeInfoReadVariable(HTypeInfoReadVariable node) { |
| 2860 TypeVariableElement element = node.variable.element; | 2860 TypeVariableElement element = node.variable.element; |
| 2861 ClassElement context = element.enclosingClass; | |
| 2862 | 2861 |
| 2863 int index = element.index; | 2862 int index = element.index; |
| 2864 use(node.inputs[0]); | 2863 HInstruction object = node.object; |
| 2864 use(object); |
| 2865 js.Expression receiver = pop(); | 2865 js.Expression receiver = pop(); |
| 2866 | 2866 |
| 2867 if (needsSubstitutionForTypeVariableAccess(context)) { | 2867 if (typeVariableAccessNeedsSubstitution(element, object.instructionType)) { |
| 2868 js.Expression typeName = | 2868 js.Expression typeName = |
| 2869 js.quoteName(backend.namer.runtimeTypeName(context)); | 2869 js.quoteName(backend.namer.runtimeTypeName(element.enclosingClass)); |
| 2870 Element helperElement = helpers.getRuntimeTypeArgument; | 2870 Element helperElement = helpers.getRuntimeTypeArgument; |
| 2871 registry.registerStaticUse( | 2871 registry.registerStaticUse( |
| 2872 new StaticUse.staticInvoke(helperElement, CallStructure.THREE_ARGS)); | 2872 new StaticUse.staticInvoke(helperElement, CallStructure.THREE_ARGS)); |
| 2873 js.Expression helper = | 2873 js.Expression helper = |
| 2874 backend.emitter.staticFunctionAccess(helperElement); | 2874 backend.emitter.staticFunctionAccess(helperElement); |
| 2875 push(js.js( | 2875 push(js.js( |
| 2876 r'#(#, #, #)', [helper, receiver, typeName, js.js.number(index)])); | 2876 r'#(#, #, #)', [helper, receiver, typeName, js.js.number(index)])); |
| 2877 } else { | 2877 } else { |
| 2878 Element helperElement = helpers.getTypeArgumentByIndex; | 2878 Element helperElement = helpers.getTypeArgumentByIndex; |
| 2879 registry.registerStaticUse( | 2879 registry.registerStaticUse( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2903 case TypeInfoExpressionKind.INSTANCE: | 2903 case TypeInfoExpressionKind.INSTANCE: |
| 2904 // We expect only flat types for the INSTANCE representation. | 2904 // We expect only flat types for the INSTANCE representation. |
| 2905 assert( | 2905 assert( |
| 2906 node.dartType == (node.dartType.element as ClassElement).thisType); | 2906 node.dartType == (node.dartType.element as ClassElement).thisType); |
| 2907 registry.registerInstantiatedClass(coreClasses.listClass); | 2907 registry.registerInstantiatedClass(coreClasses.listClass); |
| 2908 push(new js.ArrayInitializer(arguments) | 2908 push(new js.ArrayInitializer(arguments) |
| 2909 .withSourceInformation(node.sourceInformation)); | 2909 .withSourceInformation(node.sourceInformation)); |
| 2910 } | 2910 } |
| 2911 } | 2911 } |
| 2912 | 2912 |
| 2913 bool needsSubstitutionForTypeVariableAccess(ClassElement cls) { | 2913 bool typeVariableAccessNeedsSubstitution( |
| 2914 TypeVariableElement element, TypeMask receiverMask) { |
| 2915 ClassElement cls = element.enclosingClass; |
| 2914 ClassWorld classWorld = compiler.closedWorld; | 2916 ClassWorld classWorld = compiler.closedWorld; |
| 2917 |
| 2918 // See if the receiver type narrows the set of classes to ones that can be |
| 2919 // indexed. |
| 2920 // TODO(sra): Currently the only convenient query is [singleClass]. We |
| 2921 // should iterate over all the concrete classes in [receiverMask]. |
| 2922 ClassElement receiverClass = receiverMask.singleClass(classWorld); |
| 2923 if (receiverClass != null) { |
| 2924 if (backend.rti.isTrivialSubstitution(receiverClass, cls)) { |
| 2925 return false; |
| 2926 } |
| 2927 } |
| 2928 |
| 2915 if (classWorld.isUsedAsMixin(cls)) return true; | 2929 if (classWorld.isUsedAsMixin(cls)) return true; |
| 2916 | 2930 |
| 2917 return compiler.closedWorld.anyStrictSubclassOf(cls, | 2931 return classWorld.anyStrictSubclassOf(cls, (ClassElement subclass) { |
| 2918 (ClassElement subclass) { | |
| 2919 return !backend.rti.isTrivialSubstitution(subclass, cls); | 2932 return !backend.rti.isTrivialSubstitution(subclass, cls); |
| 2920 }); | 2933 }); |
| 2921 } | 2934 } |
| 2922 | 2935 |
| 2923 void visitReadTypeVariable(HReadTypeVariable node) { | 2936 void visitReadTypeVariable(HReadTypeVariable node) { |
| 2924 TypeVariableElement element = node.dartType.element; | 2937 TypeVariableElement element = node.dartType.element; |
| 2925 Element helperElement = helpers.convertRtiToRuntimeType; | 2938 Element helperElement = helpers.convertRtiToRuntimeType; |
| 2926 registry.registerStaticUse( | 2939 registry.registerStaticUse( |
| 2927 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG)); | 2940 new StaticUse.staticInvoke(helperElement, CallStructure.ONE_ARG)); |
| 2928 | 2941 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2986 registry.registerStaticUse(new StaticUse.staticInvoke( | 2999 registry.registerStaticUse(new StaticUse.staticInvoke( |
| 2987 helper, new CallStructure.unnamed(argumentCount))); | 3000 helper, new CallStructure.unnamed(argumentCount))); |
| 2988 return backend.emitter.staticFunctionAccess(helper); | 3001 return backend.emitter.staticFunctionAccess(helper); |
| 2989 } | 3002 } |
| 2990 | 3003 |
| 2991 @override | 3004 @override |
| 2992 void visitRef(HRef node) { | 3005 void visitRef(HRef node) { |
| 2993 visit(node.value); | 3006 visit(node.value); |
| 2994 } | 3007 } |
| 2995 } | 3008 } |
| OLD | NEW |