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

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

Issue 12250002: dart2js: In minified mode shorter getter and setter names. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 * Assigns JavaScript identifiers to Dart variables, class-names and members. 8 * Assigns JavaScript identifiers to Dart variables, class-names and members.
9 */ 9 */
10 class Namer implements ClosureNamer { 10 class Namer implements ClosureNamer {
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 _jsVariableReserved = new Set<String>(); 167 _jsVariableReserved = new Set<String>();
168 _jsVariableReserved.addAll(javaScriptKeywords); 168 _jsVariableReserved.addAll(javaScriptKeywords);
169 _jsVariableReserved.addAll(reservedPropertySymbols); 169 _jsVariableReserved.addAll(reservedPropertySymbols);
170 _jsVariableReserved.addAll(reservedGlobalSymbols); 170 _jsVariableReserved.addAll(reservedGlobalSymbols);
171 } 171 }
172 return _jsVariableReserved; 172 return _jsVariableReserved;
173 } 173 }
174 174
175 final String CURRENT_ISOLATE = r'$'; 175 final String CURRENT_ISOLATE = r'$';
176 176
177 final String getterPrefix = r'get$';
178 final String setterPrefix = r'set$';
179
177 /** 180 /**
178 * Map from top-level or static elements to their unique identifiers provided 181 * Map from top-level or static elements to their unique identifiers provided
179 * by [getName]. 182 * by [getName].
180 * 183 *
181 * Invariant: Keys must be declaration elements. 184 * Invariant: Keys must be declaration elements.
182 */ 185 */
183 final Compiler compiler; 186 final Compiler compiler;
184 final Map<Element, String> globals; 187 final Map<Element, String> globals;
185 final Map<Selector, String> oneShotInterceptorNames; 188 final Map<Selector, String> oneShotInterceptorNames;
186 final Map<String, LibraryElement> shortPrivateNameOwners; 189 final Map<String, LibraryElement> shortPrivateNameOwners;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 // is generated by string concatenation in applyFunction from 340 // is generated by string concatenation in applyFunction from
338 // js_helper.dart. 341 // js_helper.dart.
339 var proposedName = '$base\$$arity'; 342 var proposedName = '$base\$$arity';
340 if (name == closureInvocationSelectorName) return proposedName; 343 if (name == closureInvocationSelectorName) return proposedName;
341 return getMappedInstanceName(proposedName); 344 return getMappedInstanceName(proposedName);
342 } 345 }
343 346
344 String invocationName(Selector selector) { 347 String invocationName(Selector selector) {
345 if (selector.isGetter()) { 348 if (selector.isGetter()) {
346 String proposedName = privateName(selector.library, selector.name); 349 String proposedName = privateName(selector.library, selector.name);
347 return 'get\$${getMappedInstanceName(proposedName)}'; 350 return '$getterPrefix${getMappedInstanceName(proposedName)}';
348 } else if (selector.isSetter()) { 351 } else if (selector.isSetter()) {
349 String proposedName = privateName(selector.library, selector.name); 352 String proposedName = privateName(selector.library, selector.name);
350 return 'set\$${getMappedInstanceName(proposedName)}'; 353 return '$setterPrefix${getMappedInstanceName(proposedName)}';
351 } else { 354 } else {
352 SourceString name = selector.name; 355 SourceString name = selector.name;
353 if (selector.kind == SelectorKind.OPERATOR 356 if (selector.kind == SelectorKind.OPERATOR
354 || selector.kind == SelectorKind.INDEX) { 357 || selector.kind == SelectorKind.INDEX) {
355 name = operatorNameToIdentifier(name); 358 name = operatorNameToIdentifier(name);
356 assert(name != selector.name); 359 assert(name != selector.name);
357 return getMappedOperatorName(name.slowToString()); 360 return getMappedOperatorName(name.slowToString());
358 } 361 }
359 assert(name == operatorNameToIdentifier(name)); 362 assert(name == operatorNameToIdentifier(name));
360 StringBuffer buffer = new StringBuffer(); 363 StringBuffer buffer = new StringBuffer();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 String className = getName(fieldElement.getEnclosingClass()); 407 String className = getName(fieldElement.getEnclosingClass());
405 String instanceName = instanceFieldName(fieldElement); 408 String instanceName = instanceFieldName(fieldElement);
406 return getMappedInstanceName('$libraryName\$$className\$$instanceName'); 409 return getMappedInstanceName('$libraryName\$$className\$$instanceName');
407 } 410 }
408 411
409 String setterName(Element element) { 412 String setterName(Element element) {
410 // We dynamically create setters from the field-name. The setter name must 413 // We dynamically create setters from the field-name. The setter name must
411 // therefore be derived from the instance field-name. 414 // therefore be derived from the instance field-name.
412 LibraryElement library = element.getLibrary(); 415 LibraryElement library = element.getLibrary();
413 String name = getMappedInstanceName(privateName(library, element.name)); 416 String name = getMappedInstanceName(privateName(library, element.name));
414 return 'set\$$name'; 417 return '$setterPrefix$name';
415 } 418 }
416 419
417 String setterNameFromAccessorName(String name) { 420 String setterNameFromAccessorName(String name) {
418 // We dynamically create setters from the field-name. The setter name must 421 // We dynamically create setters from the field-name. The setter name must
419 // therefore be derived from the instance field-name. 422 // therefore be derived from the instance field-name.
420 return 'set\$$name'; 423 return '$setterPrefix$name';
421 } 424 }
422 425
423 String publicGetterName(SourceString name) { 426 String publicGetterName(SourceString name) {
424 // We dynamically create getters from the field-name. The getter name must 427 // We dynamically create getters from the field-name. The getter name must
425 // therefore be derived from the instance field-name. 428 // therefore be derived from the instance field-name.
426 String fieldName = getMappedInstanceName(name.slowToString()); 429 String fieldName = getMappedInstanceName(name.slowToString());
427 return 'get\$$fieldName'; 430 return '$getterPrefix$fieldName';
428 } 431 }
429 432
430 String getterNameFromAccessorName(String name) { 433 String getterNameFromAccessorName(String name) {
431 // We dynamically create getters from the field-name. The getter name must 434 // We dynamically create getters from the field-name. The getter name must
432 // therefore be derived from the instance field-name. 435 // therefore be derived from the instance field-name.
433 return 'get\$$name'; 436 return '$getterPrefix$name';
434 } 437 }
435 438
436 String getterName(Element element) { 439 String getterName(Element element) {
437 // We dynamically create getters from the field-name. The getter name must 440 // We dynamically create getters from the field-name. The getter name must
438 // therefore be derived from the instance field-name. 441 // therefore be derived from the instance field-name.
439 LibraryElement library = element.getLibrary(); 442 LibraryElement library = element.getLibrary();
440 String name = getMappedInstanceName(privateName(library, element.name)); 443 String name = getMappedInstanceName(privateName(library, element.name));
441 return 'get\$$name'; 444 return '$getterPrefix$name';
442 } 445 }
443 446
444 String getMappedGlobalName(String proposedName) { 447 String getMappedGlobalName(String proposedName) {
445 var newName = globalNameMap[proposedName]; 448 var newName = globalNameMap[proposedName];
446 if (newName == null) { 449 if (newName == null) {
447 newName = getFreshName(proposedName, usedGlobalNames, 450 newName = getFreshName(proposedName, usedGlobalNames,
448 suggestedGlobalNames, ensureSafe: true); 451 suggestedGlobalNames, ensureSafe: true);
449 globalNameMap[proposedName] = newName; 452 globalNameMap[proposedName] = newName;
450 } 453 }
451 return newName; 454 return newName;
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 globals[element] = result; 643 globals[element] = result;
641 return result; 644 return result;
642 } 645 }
643 compiler.internalError('getName for unknown kind: ${element.kind}', 646 compiler.internalError('getName for unknown kind: ${element.kind}',
644 node: element.parseNode(compiler)); 647 node: element.parseNode(compiler));
645 } 648 }
646 } 649 }
647 650
648 String getLazyInitializerName(Element element) { 651 String getLazyInitializerName(Element element) {
649 assert(Elements.isStaticOrTopLevelField(element)); 652 assert(Elements.isStaticOrTopLevelField(element));
650 return getMappedGlobalName("get\$${getName(element)}"); 653 return getMappedGlobalName("$getterPrefix${getName(element)}");
651 } 654 }
652 655
653 String isolatePropertiesAccess(Element element) { 656 String isolatePropertiesAccess(Element element) {
654 return "$isolateName.$isolatePropertiesName.${getName(element)}"; 657 return "$isolateName.$isolatePropertiesName.${getName(element)}";
655 } 658 }
656 659
657 String isolateAccess(Element element) { 660 String isolateAccess(Element element) {
658 return "$CURRENT_ISOLATE.${getName(element)}"; 661 return "$CURRENT_ISOLATE.${getName(element)}";
659 } 662 }
660 663
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 return const SourceString(r'$or'); 754 return const SourceString(r'$or');
752 } else if (value == '-') { 755 } else if (value == '-') {
753 return const SourceString(r'$sub'); 756 return const SourceString(r'$sub');
754 } else if (value == 'unary-') { 757 } else if (value == 'unary-') {
755 return const SourceString(r'$negate'); 758 return const SourceString(r'$negate');
756 } else { 759 } else {
757 return name; 760 return name;
758 } 761 }
759 } 762 }
760 } 763 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698