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

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

Issue 16851002: Implement minified MirrorSystem.getName. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 well as in the generated code. */ 69 well as in the generated code. */
70 String isolateProperties; 70 String isolateProperties;
71 String classesCollector; 71 String classesCollector;
72 final Set<ClassElement> neededClasses = new Set<ClassElement>(); 72 final Set<ClassElement> neededClasses = new Set<ClassElement>();
73 final List<ClassElement> regularClasses = <ClassElement>[]; 73 final List<ClassElement> regularClasses = <ClassElement>[];
74 final List<ClassElement> deferredClasses = <ClassElement>[]; 74 final List<ClassElement> deferredClasses = <ClassElement>[];
75 final List<ClassElement> nativeClasses = <ClassElement>[]; 75 final List<ClassElement> nativeClasses = <ClassElement>[];
76 final List<Selector> trivialNsmHandlers = <Selector>[]; 76 final List<Selector> trivialNsmHandlers = <Selector>[];
77 final Map<String, String> mangledFieldNames = <String, String>{}; 77 final Map<String, String> mangledFieldNames = <String, String>{};
78 final Set<String> interceptorInvocationNames = new Set<String>(); 78 final Set<String> interceptorInvocationNames = new Set<String>();
79 final Set<String> recordedUnmangledNames = new Set<String>();
79 80
80 // TODO(ngeoffray): remove this field. 81 // TODO(ngeoffray): remove this field.
81 Set<ClassElement> instantiatedClasses; 82 Set<ClassElement> instantiatedClasses;
82 83
83 final List<jsAst.Expression> boundClosures = <jsAst.Expression>[]; 84 final List<jsAst.Expression> boundClosures = <jsAst.Expression>[];
84 85
85 JavaScriptBackend get backend => compiler.backend; 86 JavaScriptBackend get backend => compiler.backend;
86 87
87 String get _ => compiler.enableMinification ? "" : " "; 88 String get _ => compiler.enableMinification ? "" : " ";
88 String get n => compiler.enableMinification ? "" : "\n"; 89 String get n => compiler.enableMinification ? "" : "\n";
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 member, isInterceptedMethod, invocationName, 1011 member, isInterceptedMethod, invocationName,
1011 parametersBuffer, argumentsBuffer, 1012 parametersBuffer, argumentsBuffer,
1012 indexOfLastOptionalArgumentInParameters); 1013 indexOfLastOptionalArgumentInParameters);
1013 } else { 1014 } else {
1014 body = [js.return_(js('this')[namer.getName(member)](argumentsBuffer))]; 1015 body = [js.return_(js('this')[namer.getName(member)](argumentsBuffer))];
1015 } 1016 }
1016 1017
1017 jsAst.Fun function = js.fun(parametersBuffer, body); 1018 jsAst.Fun function = js.fun(parametersBuffer, body);
1018 1019
1019 defineStub(invocationName, function); 1020 defineStub(invocationName, function);
1021
1022 String reflectionName = getReflectionName(selector);
1023 if (reflectionName != null) {
1024 defineStub('+$reflectionName', js('0'));
1025 }
1020 } 1026 }
1021 1027
1022 void addParameterStubs(FunctionElement member, 1028 void addParameterStubs(FunctionElement member,
1023 DefineStubFunction defineStub) { 1029 DefineStubFunction defineStub) {
1024 // We fill the lists depending on the selector. For example, 1030 // We fill the lists depending on the selector. For example,
1025 // take method foo: 1031 // take method foo:
1026 // foo(a, b, {c, d}); 1032 // foo(a, b, {c, d});
1027 // 1033 //
1028 // We may have multiple ways of calling foo: 1034 // We may have multiple ways of calling foo:
1029 // (1) foo(1, 2); 1035 // (1) foo(1, 2);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 if (!parameters.optionalParameters.isEmpty) { 1204 if (!parameters.optionalParameters.isEmpty) {
1199 addParameterStubs(member, builder.addProperty); 1205 addParameterStubs(member, builder.addProperty);
1200 } 1206 }
1201 } else if (!member.isField()) { 1207 } else if (!member.isField()) {
1202 compiler.internalError('unexpected kind: "${member.kind}"', 1208 compiler.internalError('unexpected kind: "${member.kind}"',
1203 element: member); 1209 element: member);
1204 } 1210 }
1205 emitExtraAccessors(member, builder); 1211 emitExtraAccessors(member, builder);
1206 } 1212 }
1207 1213
1208 String getReflectionName(Element element) { 1214 String getReflectionName(/* Element or Selector */ elementOrSelector) {
kasperl 2013/06/19 09:19:50 I'd probably drop the type comment here and in get
ahe 2013/06/19 12:20:59 Done.
1209 if (!compiler.mirrorsEnabled) return null; 1215 if (!compiler.mirrorsEnabled) return null;
1210 String name = element.name.slowToString(); 1216 String result = getReflectionNameInternal(elementOrSelector);
1211 if (element.isGetter()) return name; 1217 if (recordedUnmangledNames.contains(result)) return null;
1212 if (element.isSetter()) return '$name='; 1218 recordedUnmangledNames.add(result);
1213 if (element.isFunction()) { 1219 return result;
1214 FunctionElement function = element; 1220 }
1215 int requiredParameterCount = function.requiredParameterCount(compiler); 1221
1216 int optionalParameterCount = function.optionalParameterCount(compiler); 1222 String getReflectionNameInternal(
1223 /* Element or Selector */ elementOrSelector) {
1224 String name = elementOrSelector.name.slowToString();
1225 if (elementOrSelector.isGetter()) return name;
1226 if (elementOrSelector.isSetter()) return '$name=';
1227 if (elementOrSelector is Selector || elementOrSelector.isFunction()) {
1228 int requiredParameterCount;
1229 int optionalParameterCount;
1230 bool isConstructor;
1231 if (elementOrSelector is Selector) {
1232 requiredParameterCount = elementOrSelector.argumentCount;
1233 optionalParameterCount = 0;
1234 isConstructor = false;
1235 } else {
1236 FunctionElement function = elementOrSelector;
1237 requiredParameterCount = function.requiredParameterCount(compiler);
1238 optionalParameterCount = function.optionalParameterCount(compiler);
1239 isConstructor = function.isConstructor();
1240 }
1217 String suffix = '$name:$requiredParameterCount:$optionalParameterCount'; 1241 String suffix = '$name:$requiredParameterCount:$optionalParameterCount';
1218 return (function.isConstructor()) ? 'new $suffix' : suffix; 1242 return (isConstructor) ? 'new $suffix' : suffix;
1219 } 1243 }
1244 Element element = elementOrSelector;
1220 if (element.isGenerativeConstructorBody()) { 1245 if (element.isGenerativeConstructorBody()) {
1221 return null; 1246 return null;
1222 } 1247 }
1223 throw compiler.internalErrorOnElement( 1248 throw compiler.internalErrorOnElement(
1224 element, 'Do not know how to reflect on this'); 1249 element, 'Do not know how to reflect on this');
1225 } 1250 }
1226 1251
1227 /** 1252 /**
1228 * Documentation wanted -- johnniwinther 1253 * Documentation wanted -- johnniwinther
1229 * 1254 *
(...skipping 1172 matching lines...) Expand 10 before | Expand all | Expand 10 after
2402 // If we're calling bar on an object of type D, we don't need 2427 // If we're calling bar on an object of type D, we don't need
2403 // the handler either because all objects of type D implement 2428 // the handler either because all objects of type D implement
2404 // bar through inheritance. 2429 // bar through inheritance.
2405 // 2430 //
2406 // If we're calling bar on an object of type A we do need the 2431 // If we're calling bar on an object of type A we do need the
2407 // handler because we may have to call B.noSuchMethod since B 2432 // handler because we may have to call B.noSuchMethod since B
2408 // does not implement bar. 2433 // does not implement bar.
2409 if (mask.willHit(selector, compiler)) continue; 2434 if (mask.willHit(selector, compiler)) continue;
2410 String jsName = namer.invocationMirrorInternalName(selector); 2435 String jsName = namer.invocationMirrorInternalName(selector);
2411 addedJsNames[jsName] = selector; 2436 addedJsNames[jsName] = selector;
2437 String reflectionName = getReflectionName(selector);
2438 if (reflectionName != null) {
2439 mangledFieldNames[jsName] = reflectionName;
2440 }
2412 } 2441 }
2413 } 2442 }
2414 2443
2415 compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers); 2444 compiler.codegenWorld.invokedNames.forEach(addNoSuchMethodHandlers);
2416 compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers); 2445 compiler.codegenWorld.invokedGetters.forEach(addNoSuchMethodHandlers);
2417 compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers); 2446 compiler.codegenWorld.invokedSetters.forEach(addNoSuchMethodHandlers);
2418 2447
2419 // Set flag used by generateMethod helper below. If we have very few 2448 // Set flag used by generateMethod helper below. If we have very few
2420 // handlers we use defineStub for them all, rather than try to generate them 2449 // handlers we use defineStub for them all, rather than try to generate them
2421 // at runtime. 2450 // at runtime.
(...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 3422
3394 const String HOOKS_API_USAGE = """ 3423 const String HOOKS_API_USAGE = """
3395 // The code supports the following hooks: 3424 // The code supports the following hooks:
3396 // dartPrint(message) - if this function is defined it is called 3425 // dartPrint(message) - if this function is defined it is called
3397 // instead of the Dart [print] method. 3426 // instead of the Dart [print] method.
3398 // dartMainRunner(main) - if this function is defined, the Dart [main] 3427 // dartMainRunner(main) - if this function is defined, the Dart [main]
3399 // method will not be invoked directly. 3428 // method will not be invoked directly.
3400 // Instead, a closure that will invoke [main] is 3429 // Instead, a closure that will invoke [main] is
3401 // passed to [dartMainRunner]. 3430 // passed to [dartMainRunner].
3402 """; 3431 """;
OLDNEW
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/lib/js_helper.dart » ('j') | dart/sdk/lib/_internal/lib/js_names.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698