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

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

Issue 17450005: Include named parameters in reflection names. (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
« no previous file with comments | « no previous file | dart/tests/lib/mirrors/get_symbol_name_no_such_method_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 1221
1222 String getReflectionNameInternal(elementOrSelector) { 1222 String getReflectionNameInternal(elementOrSelector) {
1223 String name = elementOrSelector.name.slowToString(); 1223 String name = elementOrSelector.name.slowToString();
1224 if (elementOrSelector.isGetter()) return name; 1224 if (elementOrSelector.isGetter()) return name;
1225 if (elementOrSelector.isSetter()) return '$name='; 1225 if (elementOrSelector.isSetter()) return '$name=';
1226 if (elementOrSelector is Selector 1226 if (elementOrSelector is Selector
1227 || elementOrSelector.isFunction() 1227 || elementOrSelector.isFunction()
1228 || elementOrSelector.isConstructor()) { 1228 || elementOrSelector.isConstructor()) {
1229 int requiredParameterCount; 1229 int requiredParameterCount;
1230 int optionalParameterCount; 1230 int optionalParameterCount;
1231 String namedArguments = '';
1231 bool isConstructor; 1232 bool isConstructor;
1232 if (elementOrSelector is Selector) { 1233 if (elementOrSelector is Selector) {
1233 requiredParameterCount = elementOrSelector.argumentCount; 1234 Selector selector = elementOrSelector;
1235 requiredParameterCount = selector.argumentCount;
1234 optionalParameterCount = 0; 1236 optionalParameterCount = 0;
1235 isConstructor = false; 1237 isConstructor = false;
1238 namedArguments = namedParametersAsReflectionNames(selector);
1236 } else { 1239 } else {
1237 FunctionElement function = elementOrSelector; 1240 FunctionElement function = elementOrSelector;
1238 requiredParameterCount = function.requiredParameterCount(compiler); 1241 requiredParameterCount = function.requiredParameterCount(compiler);
1239 optionalParameterCount = function.optionalParameterCount(compiler); 1242 optionalParameterCount = function.optionalParameterCount(compiler);
1240 isConstructor = function.isConstructor(); 1243 isConstructor = function.isConstructor();
1244 FunctionSignature signature = function.computeSignature(compiler);
1245 if (signature.optionalParametersAreNamed) {
1246 Selector selector = new Selector.call(
1247 function.name,
1248 function.getLibrary(),
1249 requiredParameterCount,
1250 optionalParameters.map((e) => e.name).toList());
1251 namedArguments = namedParametersAsReflectionNames(selector);
1252 }
1241 } 1253 }
1242 String suffix = '$name:$requiredParameterCount:$optionalParameterCount'; 1254 String suffix =
1255 '$name:$requiredParameterCount:$optionalParameterCount'
1256 '$namedArguments';
1243 return (isConstructor) ? 'new $suffix' : suffix; 1257 return (isConstructor) ? 'new $suffix' : suffix;
1244 } 1258 }
1245 Element element = elementOrSelector; 1259 Element element = elementOrSelector;
1246 if (element.isGenerativeConstructorBody()) { 1260 if (element.isGenerativeConstructorBody()) {
1247 return null; 1261 return null;
1248 } 1262 }
1249 throw compiler.internalErrorOnElement( 1263 throw compiler.internalErrorOnElement(
1250 element, 'Do not know how to reflect on this $element'); 1264 element, 'Do not know how to reflect on this $element');
1251 } 1265 }
1252 1266
1267 String namedParametersAsReflectionNames(Selector selector) {
1268 if (selector.orderedNamedArguments.isEmpty) return '';
1269 String names =
1270 selector.orderedNamedArguments.map((x) => x.slowToString()).join(':');
1271 return ':$names';
1272 }
1273
1253 /** 1274 /**
1254 * Documentation wanted -- johnniwinther 1275 * Documentation wanted -- johnniwinther
1255 * 1276 *
1256 * Invariant: [classElement] must be a declaration element. 1277 * Invariant: [classElement] must be a declaration element.
1257 */ 1278 */
1258 void emitInstanceMembers(ClassElement classElement, 1279 void emitInstanceMembers(ClassElement classElement,
1259 ClassBuilder builder) { 1280 ClassBuilder builder) {
1260 assert(invariant(classElement, classElement.isDeclaration)); 1281 assert(invariant(classElement, classElement.isDeclaration));
1261 1282
1262 void visitMember(ClassElement enclosing, Element member) { 1283 void visitMember(ClassElement enclosing, Element member) {
(...skipping 2189 matching lines...) Expand 10 before | Expand all | Expand 10 after
3452 3473
3453 const String HOOKS_API_USAGE = """ 3474 const String HOOKS_API_USAGE = """
3454 // The code supports the following hooks: 3475 // The code supports the following hooks:
3455 // dartPrint(message) - if this function is defined it is called 3476 // dartPrint(message) - if this function is defined it is called
3456 // instead of the Dart [print] method. 3477 // instead of the Dart [print] method.
3457 // dartMainRunner(main) - if this function is defined, the Dart [main] 3478 // dartMainRunner(main) - if this function is defined, the Dart [main]
3458 // method will not be invoked directly. 3479 // method will not be invoked directly.
3459 // Instead, a closure that will invoke [main] is 3480 // Instead, a closure that will invoke [main] is
3460 // passed to [dartMainRunner]. 3481 // passed to [dartMainRunner].
3461 """; 3482 """;
OLDNEW
« no previous file with comments | « no previous file | dart/tests/lib/mirrors/get_symbol_name_no_such_method_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698