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

Side by Side Diff: pkg/compiler/lib/src/js_backend/namer.dart

Issue 2884233002: Use entities in runtime_types (Closed)
Patch Set: Remove debug print Created 3 years, 7 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
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 library js_backend.namer; 5 library js_backend.namer;
6 6
7 import 'dart:collection' show HashMap; 7 import 'dart:collection' show HashMap;
8 8
9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName; 9 import 'package:js_runtime/shared/embedded_names.dart' show JsGetName;
10 10
(...skipping 12 matching lines...) Expand all
23 import '../tree/tree.dart'; 23 import '../tree/tree.dart';
24 import '../universe/call_structure.dart' show CallStructure; 24 import '../universe/call_structure.dart' show CallStructure;
25 import '../universe/selector.dart' show Selector, SelectorKind; 25 import '../universe/selector.dart' show Selector, SelectorKind;
26 import '../universe/world_builder.dart' show CodegenWorldBuilder; 26 import '../universe/world_builder.dart' show CodegenWorldBuilder;
27 import 'package:front_end/src/fasta/scanner/characters.dart'; 27 import 'package:front_end/src/fasta/scanner/characters.dart';
28 import '../util/util.dart'; 28 import '../util/util.dart';
29 import '../world.dart' show ClosedWorld; 29 import '../world.dart' show ClosedWorld;
30 import 'backend.dart'; 30 import 'backend.dart';
31 import 'constant_system_javascript.dart'; 31 import 'constant_system_javascript.dart';
32 import 'native_data.dart'; 32 import 'native_data.dart';
33 import 'runtime_types.dart';
33 34
34 part 'field_naming_mixin.dart'; 35 part 'field_naming_mixin.dart';
35 part 'frequency_namer.dart'; 36 part 'frequency_namer.dart';
36 part 'minify_namer.dart'; 37 part 'minify_namer.dart';
37 part 'namer_names.dart'; 38 part 'namer_names.dart';
38 39
39 /** 40 /**
40 * Assigns JavaScript identifiers to Dart variables, class-names and members. 41 * Assigns JavaScript identifiers to Dart variables, class-names and members.
41 * 42 *
42 * Names are generated through three stages: 43 * Names are generated through three stages:
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 shortPrivateNameOwners.putIfAbsent(text, () => library); 745 shortPrivateNameOwners.putIfAbsent(text, () => library);
745 746
746 if (owner == library) { 747 if (owner == library) {
747 return text; 748 return text;
748 } else { 749 } else {
749 // Make sure to return a private name that starts with _ so it 750 // Make sure to return a private name that starts with _ so it
750 // cannot clash with any public names. 751 // cannot clash with any public names.
751 // The name is still not guaranteed to be unique, since both the library 752 // The name is still not guaranteed to be unique, since both the library
752 // name and originalName could contain $ symbols and as the library 753 // name and originalName could contain $ symbols and as the library
753 // name itself might clash. 754 // name itself might clash.
754 String libraryName = _proposeNameForGlobal(library); 755 String libraryName = _proposeNameForLibrary(library);
755 return "_$libraryName\$$text"; 756 return "_$libraryName\$$text";
756 } 757 }
757 } 758 }
758 759
759 String _proposeNameForConstructorBody(ConstructorBodyElement method) { 760 String _proposeNameForConstructorBody(ConstructorBodyElement method) {
760 String name = Elements.reconstructConstructorNameSourceString(method); 761 String name = Elements.reconstructConstructorNameSourceString(method);
761 // We include the method suffix on constructor bodies. It has no purpose, 762 // We include the method suffix on constructor bodies. It has no purpose,
762 // but this way it produces the same names as previous versions of the 763 // but this way it produces the same names as previous versions of the
763 // Namer class did. 764 // Namer class did.
764 List<String> suffix = callSuffixForSignature(method.functionSignature); 765 List<String> suffix = callSuffixForSignature(method.functionSignature);
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 return '${className}_${Elements.reconstructConstructorName(element)}'; 1263 return '${className}_${Elements.reconstructConstructorName(element)}';
1263 } 1264 }
1264 if (Elements.isStaticOrTopLevel(element)) { 1265 if (Elements.isStaticOrTopLevel(element)) {
1265 if (element.isClassMember) { 1266 if (element.isClassMember) {
1266 ClassElement enclosingClass = element.enclosingClass; 1267 ClassElement enclosingClass = element.enclosingClass;
1267 return '${enclosingClass.name}_${element.name}'; 1268 return '${enclosingClass.name}_${element.name}';
1268 } 1269 }
1269 return element.name.replaceAll('+', '_'); 1270 return element.name.replaceAll('+', '_');
1270 } 1271 }
1271 if (element.isLibrary) { 1272 if (element.isLibrary) {
1272 return _proposeNameForLibrary(element); 1273 LibraryElement library = element;
1274 return _proposeNameForLibrary(library);
1273 } 1275 }
1274 return element.name; 1276 return element.name;
1275 } 1277 }
1276 1278
1277 /** 1279 /**
1278 * Returns a proposed name for the given [LibraryElement]. 1280 * Returns a proposed name for the given [LibraryElement].
1279 * The returned id is guaranteed to be a valid JavaScript identifier. 1281 * The returned id is guaranteed to be a valid JavaScript identifier.
1280 */ 1282 */
1281 // TODO(sra): Pre-process libraries to assign [libraryLongNames] in a way that 1283 // TODO(sra): Pre-process libraries to assign [libraryLongNames] in a way that
1282 // is independent of the order of calls to namer. 1284 // is independent of the order of calls to namer.
1283 String _proposeNameForLibrary(LibraryElement library) { 1285 String _proposeNameForLibrary(LibraryEntity library) {
1284 String name = libraryLongNames[library]; 1286 String name = libraryLongNames[library];
1285 if (name != null) return name; 1287 if (name != null) return name;
1286 // Use the 'file' name, e.g. "package:expect/expect.dart" -> "expect" 1288 // Use the 'file' name, e.g. "package:expect/expect.dart" -> "expect"
1287 name = library.canonicalUri.path; 1289 name = library.canonicalUri.path;
1288 name = name.substring(name.lastIndexOf('/') + 1); 1290 name = name.substring(name.lastIndexOf('/') + 1);
1289 if (name.contains('.')) { 1291 if (name.contains('.')) {
1290 // Drop file extension. 1292 // Drop file extension.
1291 name = name.substring(0, name.lastIndexOf('.')); 1293 name = name.substring(0, name.lastIndexOf('.'));
1292 } 1294 }
1293 // The filename based name can contain all kinds of nasty characters. Make 1295 // The filename based name can contain all kinds of nasty characters. Make
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1507 assert(Elements.isStaticOrTopLevelField(element)); 1509 assert(Elements.isStaticOrTopLevelField(element));
1508 jsAst.Name name = _disambiguateGlobal(element); 1510 jsAst.Name name = _disambiguateGlobal(element);
1509 // These are not real dart getters, so do not use GetterName; 1511 // These are not real dart getters, so do not use GetterName;
1510 return deriveLazyInitializerName(name); 1512 return deriveLazyInitializerName(name);
1511 } 1513 }
1512 1514
1513 jsAst.Name staticClosureName(Element element) { 1515 jsAst.Name staticClosureName(Element element) {
1514 assert(Elements.isStaticOrTopLevelFunction(element)); 1516 assert(Elements.isStaticOrTopLevelFunction(element));
1515 String enclosing = 1517 String enclosing =
1516 element.enclosingClass == null ? "" : element.enclosingClass.name; 1518 element.enclosingClass == null ? "" : element.enclosingClass.name;
1517 String library = _proposeNameForGlobal(element.library); 1519 String library = _proposeNameForLibrary(element.library);
1518 return _disambiguateInternalGlobal( 1520 return _disambiguateInternalGlobal(
1519 "${library}_${enclosing}_${element.name}\$closure"); 1521 "${library}_${enclosing}_${element.name}\$closure");
1520 } 1522 }
1521 1523
1522 // This name is used as part of the name of a TypeConstant 1524 // This name is used as part of the name of a TypeConstant
1523 String uniqueNameForTypeConstantElement(Element element) { 1525 String uniqueNameForTypeConstantElement(
1526 LibraryEntity library, Entity element) {
1524 // TODO(sra): If we replace the period with an identifier character, 1527 // TODO(sra): If we replace the period with an identifier character,
1525 // TypeConstants will have better names in unminified code. 1528 // TypeConstants will have better names in unminified code.
1526 String library = _proposeNameForGlobal(element.library); 1529 String libraryName = _proposeNameForLibrary(library);
1527 return "${library}.${element.name}"; 1530 return "${libraryName}.${element.name}";
1528 } 1531 }
1529 1532
1530 String globalObjectForConstant(ConstantValue constant) => 'C'; 1533 String globalObjectForConstant(ConstantValue constant) => 'C';
1531 1534
1532 String get operatorIsPrefix => r'$is'; 1535 String get operatorIsPrefix => r'$is';
1533 1536
1534 String get operatorAsPrefix => r'$as'; 1537 String get operatorAsPrefix => r'$as';
1535 1538
1536 String get operatorSignature => r'$signature'; 1539 String get operatorSignature => r'$signature';
1537 1540
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
2186 void addSuggestion(String original, String suggestion) { 2189 void addSuggestion(String original, String suggestion) {
2187 assert(!_suggestedNames.containsKey(original)); 2190 assert(!_suggestedNames.containsKey(original));
2188 _suggestedNames[original] = suggestion; 2191 _suggestedNames[original] = suggestion;
2189 } 2192 }
2190 2193
2191 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); 2194 bool hasSuggestion(String original) => _suggestedNames.containsKey(original);
2192 bool isSuggestion(String candidate) { 2195 bool isSuggestion(String candidate) {
2193 return _suggestedNames.containsValue(candidate); 2196 return _suggestedNames.containsValue(candidate);
2194 } 2197 }
2195 } 2198 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698