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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 const VERBOSE_OPTIMIZER_HINTS = false; | 7 const VERBOSE_OPTIMIZER_HINTS = false; |
| 8 | 8 |
| 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { | 9 class JavaScriptItemCompilationContext extends ItemCompilationContext { |
| 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); | 10 final Set<HInstruction> boundsChecked = new Set<HInstruction>(); |
| (...skipping 2973 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2984 } | 2984 } |
| 2985 | 2985 |
| 2986 void onTypeVariableExpression(Registry registry) { | 2986 void onTypeVariableExpression(Registry registry) { |
| 2987 assert(registry.isForResolution); | 2987 assert(registry.isForResolution); |
| 2988 registerBackendStaticInvocation(backend.getSetRuntimeTypeInfo(), registry); | 2988 registerBackendStaticInvocation(backend.getSetRuntimeTypeInfo(), registry); |
| 2989 registerBackendStaticInvocation(backend.getGetRuntimeTypeInfo(), registry); | 2989 registerBackendStaticInvocation(backend.getGetRuntimeTypeInfo(), registry); |
| 2990 backend.registerGetRuntimeTypeArgument(registry); | 2990 backend.registerGetRuntimeTypeArgument(registry); |
| 2991 registerBackendInstantiation(backend.compiler.listClass, registry); | 2991 registerBackendInstantiation(backend.compiler.listClass, registry); |
| 2992 registerBackendStaticInvocation(backend.getRuntimeTypeToString(), registry); | 2992 registerBackendStaticInvocation(backend.getRuntimeTypeToString(), registry); |
| 2993 registerBackendStaticInvocation(backend.getCreateRuntimeType(), registry); | 2993 registerBackendStaticInvocation(backend.getCreateRuntimeType(), registry); |
| 2994 needsInt(registry); // Needed for accessing the type variable literal. | |
|
karlklose
2015/09/11 12:21:15
Maybe we should make these comments into string ar
Johnni Winther
2015/09/11 12:38:36
Done.
| |
| 2994 } | 2995 } |
| 2995 | 2996 |
| 2996 // TODO(johnniwinther): Maybe split this into [onAssertType] and [onTestType]. | 2997 // TODO(johnniwinther): Maybe split this into [onAssertType] and [onTestType]. |
| 2997 void onIsCheck(DartType type, Registry registry) { | 2998 void onIsCheck(DartType type, Registry registry) { |
| 2998 assert(registry.isForResolution); | 2999 assert(registry.isForResolution); |
| 2999 type = type.unalias(backend.compiler); | 3000 type = type.unalias(backend.compiler); |
| 3000 registerBackendInstantiation(backend.compiler.boolClass, registry); | 3001 registerBackendInstantiation(backend.compiler.boolClass, registry); |
| 3001 bool inCheckedMode = backend.compiler.enableTypeAssertions; | 3002 bool inCheckedMode = backend.compiler.enableTypeAssertions; |
| 3002 if (inCheckedMode) { | 3003 if (inCheckedMode) { |
| 3003 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); | 3004 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3044 assert(registry.isForResolution); | 3045 assert(registry.isForResolution); |
| 3045 registerBackendStaticInvocation(backend.getThrowTypeError(), registry); | 3046 registerBackendStaticInvocation(backend.getThrowTypeError(), registry); |
| 3046 registerBackendStaticInvocation(backend.getAssertIsSubtype(), registry); | 3047 registerBackendStaticInvocation(backend.getAssertIsSubtype(), registry); |
| 3047 } | 3048 } |
| 3048 | 3049 |
| 3049 void onAbstractClassInstantiation(Registry registry) { | 3050 void onAbstractClassInstantiation(Registry registry) { |
| 3050 assert(registry.isForResolution); | 3051 assert(registry.isForResolution); |
| 3051 registerBackendStaticInvocation( | 3052 registerBackendStaticInvocation( |
| 3052 backend.getThrowAbstractClassInstantiationError(), registry); | 3053 backend.getThrowAbstractClassInstantiationError(), registry); |
| 3053 // Also register the types of the arguments passed to this method. | 3054 // Also register the types of the arguments passed to this method. |
| 3054 registerBackendInstantiation(backend.compiler.stringClass, registry); | 3055 needsString(registry); // Needed to encode the message. |
| 3055 } | 3056 } |
| 3056 | 3057 |
| 3057 void onFallThroughError(Registry registry) { | 3058 void onFallThroughError(Registry registry) { |
| 3058 assert(registry.isForResolution); | 3059 assert(registry.isForResolution); |
| 3059 registerBackendStaticInvocation(backend.getFallThroughError(), registry); | 3060 registerBackendStaticInvocation(backend.getFallThroughError(), registry); |
| 3060 } | 3061 } |
| 3061 | 3062 |
| 3062 void onAsCheck(DartType type, Registry registry) { | 3063 void onAsCheck(DartType type, Registry registry) { |
| 3063 assert(registry.isForResolution); | 3064 assert(registry.isForResolution); |
| 3064 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); | 3065 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); |
| 3065 } | 3066 } |
| 3066 | 3067 |
| 3067 void onThrowNoSuchMethod(Registry registry) { | 3068 void onThrowNoSuchMethod(Registry registry) { |
| 3068 assert(registry.isForResolution); | 3069 assert(registry.isForResolution); |
| 3069 registerBackendStaticInvocation(backend.getThrowNoSuchMethod(), registry); | 3070 registerBackendStaticInvocation(backend.getThrowNoSuchMethod(), registry); |
| 3070 // Also register the types of the arguments passed to this method. | 3071 // Also register the types of the arguments passed to this method. |
| 3071 registerBackendInstantiation(backend.compiler.listClass, registry); | 3072 needsList(registry); // Needed to encode the arguments. |
| 3072 registerBackendInstantiation(backend.compiler.stringClass, registry); | 3073 needsString(registry); // Needed to encode the name. |
| 3073 } | 3074 } |
| 3074 | 3075 |
| 3075 void onThrowRuntimeError(Registry registry) { | 3076 void onThrowRuntimeError(Registry registry) { |
| 3076 assert(registry.isForResolution); | 3077 assert(registry.isForResolution); |
| 3077 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); | 3078 registerBackendStaticInvocation(backend.getThrowRuntimeError(), registry); |
| 3078 // Also register the types of the arguments passed to this method. | 3079 // Also register the types of the arguments passed to this method. |
| 3079 registerBackendInstantiation(backend.compiler.stringClass, registry); | 3080 registerBackendInstantiation(backend.compiler.stringClass, registry); |
| 3080 } | 3081 } |
| 3081 | 3082 |
| 3082 void onCompileTimeError(Registry registry, ErroneousElement error) { | 3083 void onCompileTimeError(Registry registry, ErroneousElement error) { |
| 3083 if (backend.compiler.generateCodeWithCompileTimeErrors) { | 3084 if (backend.compiler.generateCodeWithCompileTimeErrors) { |
| 3084 // TODO(johnniwinther): This should have its own uncatchable error. | 3085 // TODO(johnniwinther): This should have its own uncatchable error. |
| 3085 onThrowRuntimeError(registry); | 3086 onThrowRuntimeError(registry); |
| 3086 } | 3087 } |
| 3087 } | 3088 } |
| 3088 | 3089 |
| 3089 void onSuperNoSuchMethod(Registry registry) { | 3090 void onSuperNoSuchMethod(Registry registry) { |
| 3090 assert(registry.isForResolution); | 3091 assert(registry.isForResolution); |
| 3091 registerBackendStaticInvocation( | 3092 registerBackendStaticInvocation( |
| 3092 backend.getCreateInvocationMirror(), registry); | 3093 backend.getCreateInvocationMirror(), registry); |
| 3093 registerBackendStaticInvocation( | 3094 registerBackendStaticInvocation( |
| 3094 backend.compiler.objectClass.lookupLocalMember( | 3095 backend.compiler.objectClass.lookupLocalMember( |
| 3095 Identifiers.noSuchMethod_), | 3096 Identifiers.noSuchMethod_), |
| 3096 registry); | 3097 registry); |
| 3097 registerBackendInstantiation(backend.compiler.listClass, registry); | 3098 needsInt(registry); // Needed to encode the invocation kind. |
| 3098 registerBackendInstantiation(backend.compiler.stringClass, registry); | 3099 needsList(registry); // Needed to encode the arguments. |
| 3100 needsString(registry); // Needed to encode the name. | |
| 3099 } | 3101 } |
| 3100 | 3102 |
| 3101 void onMapLiteral(ResolutionRegistry registry, | 3103 void onMapLiteral(ResolutionRegistry registry, |
| 3102 DartType type, | 3104 DartType type, |
| 3103 bool isConstant) { | 3105 bool isConstant) { |
| 3104 assert(registry.isForResolution); | 3106 assert(registry.isForResolution); |
| 3105 void enqueue(String name) { | 3107 void enqueue(String name) { |
| 3106 Element e = backend.find(backend.jsHelperLibrary, name); | 3108 Element e = backend.find(backend.jsHelperLibrary, name); |
| 3107 registerBackendInstantiation(e, registry); | 3109 registerBackendInstantiation(e, registry); |
| 3108 } | 3110 } |
| 3109 | 3111 |
| 3110 if (isConstant) { | 3112 if (isConstant) { |
| 3111 enqueue(JavaScriptMapConstant.DART_CLASS); | 3113 enqueue(JavaScriptMapConstant.DART_CLASS); |
| 3112 enqueue(JavaScriptMapConstant.DART_PROTO_CLASS); | 3114 enqueue(JavaScriptMapConstant.DART_PROTO_CLASS); |
| 3113 enqueue(JavaScriptMapConstant.DART_STRING_CLASS); | 3115 enqueue(JavaScriptMapConstant.DART_STRING_CLASS); |
| 3114 enqueue(JavaScriptMapConstant.DART_GENERAL_CLASS); | 3116 enqueue(JavaScriptMapConstant.DART_GENERAL_CLASS); |
| 3115 } else { | 3117 } else { |
| 3116 registry.registerInstantiatedType(type); | 3118 registry.registerInstantiatedType(type); |
| 3117 } | 3119 } |
| 3118 } | 3120 } |
| 3119 | 3121 |
| 3120 /// Called when resolving the `Symbol` constructor. | 3122 /// Called when resolving the `Symbol` constructor. |
| 3121 void onSymbolConstructor(Registry registry) { | 3123 void onSymbolConstructor(Registry registry) { |
| 3122 assert(registry.isForResolution); | 3124 assert(registry.isForResolution); |
| 3123 // Make sure that _internals.Symbol.validated is registered. | 3125 // Make sure that _internals.Symbol.validated is registered. |
| 3124 assert(backend.compiler.symbolValidatedConstructor != null); | 3126 assert(backend.compiler.symbolValidatedConstructor != null); |
| 3125 registerBackendStaticInvocation( | 3127 registerBackendStaticInvocation( |
| 3126 backend.compiler.symbolValidatedConstructor, registry); | 3128 backend.compiler.symbolValidatedConstructor, registry); |
| 3127 } | 3129 } |
| 3130 | |
| 3131 /// Called when resolving a prefix or postfix expression. | |
| 3132 void onIncDecOperation(Registry registry) { | |
| 3133 needsInt(registry); // Need for the `+ 1` or `- 1` operation. | |
| 3134 } | |
| 3135 | |
| 3136 /// Helper for registering that `int` is needed. | |
| 3137 void needsInt(Registry registry) { | |
| 3138 registerBackendInstantiation(backend.compiler.intClass, registry); | |
| 3139 } | |
| 3140 | |
| 3141 /// Helper for registering that `List` is needed. | |
| 3142 void needsList(Registry registry) { | |
| 3143 registerBackendInstantiation(backend.compiler.listClass, registry); | |
| 3144 } | |
| 3145 | |
| 3146 /// Helper for registering that `String` is needed. | |
| 3147 void needsString(Registry registry) { | |
| 3148 registerBackendInstantiation(backend.compiler.stringClass, registry); | |
| 3149 } | |
| 3128 } | 3150 } |
| 3129 | 3151 |
| 3130 /// Records that [constant] is used by the element behind [registry]. | 3152 /// Records that [constant] is used by the element behind [registry]. |
| 3131 class Dependency { | 3153 class Dependency { |
| 3132 final ConstantValue constant; | 3154 final ConstantValue constant; |
| 3133 final Element annotatedElement; | 3155 final Element annotatedElement; |
| 3134 | 3156 |
| 3135 const Dependency(this.constant, this.annotatedElement); | 3157 const Dependency(this.constant, this.annotatedElement); |
| 3136 } | 3158 } |
| OLD | NEW |