Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(341)

Side by Side Diff: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart

Issue 23003031: Extract interceptor calls from raw is-checks. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Populate interceptedClasses dynamically Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /** 7 /**
8 * A function element that represents a closure call. The signature is copied 8 * A function element that represents a closure call. The signature is copied
9 * from the given element. 9 * from the given element.
10 */ 10 */
(...skipping 3009 matching lines...) Expand 10 before | Expand all | Expand 10 after
3020 dartMainRunner(function() { ${mainCall}; }); 3020 dartMainRunner(function() { ${mainCall}; });
3021 } else { 3021 } else {
3022 ${mainCall}; 3022 ${mainCall};
3023 } 3023 }
3024 })$N"""); 3024 })$N""");
3025 addComment('END invoke [main].', buffer); 3025 addComment('END invoke [main].', buffer);
3026 } 3026 }
3027 3027
3028 void emitGetInterceptorMethod(CodeBuffer buffer, 3028 void emitGetInterceptorMethod(CodeBuffer buffer,
3029 String key, 3029 String key,
3030 Iterable<ClassElement> classes) { 3030 Set<ClassElement> classes) {
3031 jsAst.Statement buildReturnInterceptor(ClassElement cls) { 3031 jsAst.Statement buildReturnInterceptor(ClassElement cls) {
3032 return js.return_(js(namer.isolateAccess(cls))['prototype']); 3032 return js.return_(js(namer.isolateAccess(cls))['prototype']);
3033 } 3033 }
3034 3034
3035 /** 3035 /**
3036 * Build a JavaScrit AST node for doing a type check on 3036 * Build a JavaScrit AST node for doing a type check on
3037 * [cls]. [cls] must be an interceptor class. 3037 * [cls]. [cls] must be an interceptor class.
3038 */ 3038 */
3039 jsAst.Statement buildInterceptorCheck(ClassElement cls) { 3039 jsAst.Statement buildInterceptorCheck(ClassElement cls) {
3040 jsAst.Expression condition; 3040 jsAst.Expression condition;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3095 if (anyNativeClasses) { 3095 if (anyNativeClasses) {
3096 if (Elements.isNativeOrExtendsNative(cls)) hasNative = true; 3096 if (Elements.isNativeOrExtendsNative(cls)) hasNative = true;
3097 } 3097 }
3098 } 3098 }
3099 } 3099 }
3100 if (hasDouble) { 3100 if (hasDouble) {
3101 hasNumber = true; 3101 hasNumber = true;
3102 } 3102 }
3103 if (hasInt) hasNumber = true; 3103 if (hasInt) hasNumber = true;
3104 3104
3105 if (classes == backend.interceptedClasses) { 3105 if (classes.containsAll(backend.interceptedClasses)) {
3106 // I.e. this is the general interceptor. 3106 // I.e. this is the general interceptor.
3107 hasNative = anyNativeClasses; 3107 hasNative = anyNativeClasses;
3108 } 3108 }
3109 3109
3110 jsAst.Block block = new jsAst.Block.empty(); 3110 jsAst.Block block = new jsAst.Block.empty();
3111 3111
3112 if (hasNumber) { 3112 if (hasNumber) {
3113 jsAst.Statement whenNumber; 3113 jsAst.Statement whenNumber;
3114 3114
3115 /// Note: there are two number classes in play: Dart's [num], 3115 /// Note: there are two number classes in play: Dart's [num],
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
3185 buffer.write(jsAst.prettyPrint( 3185 buffer.write(jsAst.prettyPrint(
3186 js('$isolateProperties.$key = #', js.fun(['receiver'], block)), 3186 js('$isolateProperties.$key = #', js.fun(['receiver'], block)),
3187 compiler)); 3187 compiler));
3188 buffer.write(N); 3188 buffer.write(N);
3189 } 3189 }
3190 3190
3191 /** 3191 /**
3192 * Emit all versions of the [:getInterceptor:] method. 3192 * Emit all versions of the [:getInterceptor:] method.
3193 */ 3193 */
3194 void emitGetInterceptorMethods(CodeBuffer buffer) { 3194 void emitGetInterceptorMethods(CodeBuffer buffer) {
3195 var specializedGetInterceptors = backend.specializedGetInterceptors; 3195 Map<String, Set<ClassElement>> specializedGetInterceptors =
3196 backend.specializedGetInterceptors;
3196 for (String name in specializedGetInterceptors.keys.toList()..sort()) { 3197 for (String name in specializedGetInterceptors.keys.toList()..sort()) {
3197 Iterable<ClassElement> classes = specializedGetInterceptors[name]; 3198 Set<ClassElement> classes = specializedGetInterceptors[name];
3198 emitGetInterceptorMethod(buffer, name, classes); 3199 emitGetInterceptorMethod(buffer, name, classes);
3199 } 3200 }
3200 } 3201 }
3201 3202
3202 /** 3203 /**
3203 * Compute all the classes that must be emitted. 3204 * Compute all the classes that must be emitted.
3204 */ 3205 */
3205 void computeNeededClasses() { 3206 void computeNeededClasses() {
3206 instantiatedClasses = 3207 instantiatedClasses =
3207 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter()) 3208 compiler.codegenWorld.instantiatedClasses.where(computeClassFilter())
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
4157 4158
4158 const String HOOKS_API_USAGE = """ 4159 const String HOOKS_API_USAGE = """
4159 // The code supports the following hooks: 4160 // The code supports the following hooks:
4160 // dartPrint(message) - if this function is defined it is called 4161 // dartPrint(message) - if this function is defined it is called
4161 // instead of the Dart [print] method. 4162 // instead of the Dart [print] method.
4162 // dartMainRunner(main) - if this function is defined, the Dart [main] 4163 // dartMainRunner(main) - if this function is defined, the Dart [main]
4163 // method will not be invoked directly. 4164 // method will not be invoked directly.
4164 // Instead, a closure that will invoke [main] is 4165 // Instead, a closure that will invoke [main] is
4165 // passed to [dartMainRunner]. 4166 // passed to [dartMainRunner].
4166 """; 4167 """;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698