| OLD | NEW |
| 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 |
| 11 import '../closure.dart'; | 11 import '../closure.dart'; |
| 12 import '../common.dart'; | 12 import '../common.dart'; |
| 13 import '../common/names.dart' show Identifiers, Selectors; | 13 import '../common/names.dart' show Identifiers, Selectors; |
| 14 import '../compiler.dart' show Compiler; | 14 import '../compiler.dart' show Compiler; |
| 15 import '../constants/values.dart'; | 15 import '../constants/values.dart'; |
| 16 import '../core_types.dart' show CoreClasses; | 16 import '../core_types.dart' show CommonElements; |
| 17 import '../dart_types.dart'; | 17 import '../dart_types.dart'; |
| 18 import '../diagnostics/invariant.dart' show DEBUG_MODE; | 18 import '../diagnostics/invariant.dart' show DEBUG_MODE; |
| 19 import '../elements/elements.dart'; | 19 import '../elements/elements.dart'; |
| 20 import '../elements/entities.dart'; | 20 import '../elements/entities.dart'; |
| 21 import '../js/js.dart' as jsAst; | 21 import '../js/js.dart' as jsAst; |
| 22 import '../js/js.dart' show js; | 22 import '../js/js.dart' show js; |
| 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 '../util/characters.dart'; | 26 import '../util/characters.dart'; |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 _literalAsyncPrefix = new StringBackedName(asyncPrefix); | 468 _literalAsyncPrefix = new StringBackedName(asyncPrefix); |
| 469 _literalGetterPrefix = new StringBackedName(getterPrefix); | 469 _literalGetterPrefix = new StringBackedName(getterPrefix); |
| 470 _literalSetterPrefix = new StringBackedName(setterPrefix); | 470 _literalSetterPrefix = new StringBackedName(setterPrefix); |
| 471 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix); | 471 _literalLazyGetterPrefix = new StringBackedName(lazyGetterPrefix); |
| 472 } | 472 } |
| 473 | 473 |
| 474 BackendHelpers get helpers => backend.helpers; | 474 BackendHelpers get helpers => backend.helpers; |
| 475 | 475 |
| 476 DiagnosticReporter get reporter => backend.reporter; | 476 DiagnosticReporter get reporter => backend.reporter; |
| 477 | 477 |
| 478 CoreClasses get coreClasses => closedWorld.coreClasses; | 478 CommonElements get commonElements => closedWorld.commonElements; |
| 479 | 479 |
| 480 String get deferredTypesName => 'deferredTypes'; | 480 String get deferredTypesName => 'deferredTypes'; |
| 481 String get isolateName => 'Isolate'; | 481 String get isolateName => 'Isolate'; |
| 482 String get isolatePropertiesName => r'$isolateProperties'; | 482 String get isolatePropertiesName => r'$isolateProperties'; |
| 483 jsAst.Name get noSuchMethodName => invocationName(Selectors.noSuchMethod_); | 483 jsAst.Name get noSuchMethodName => invocationName(Selectors.noSuchMethod_); |
| 484 | 484 |
| 485 /** | 485 /** |
| 486 * Some closures must contain their name. The name is stored in | 486 * Some closures must contain their name. The name is stored in |
| 487 * [STATIC_CLOSURE_NAME_NAME]. | 487 * [STATIC_CLOSURE_NAME_NAME]. |
| 488 */ | 488 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 return asName(functionTypeReturnTypeTag); | 543 return asName(functionTypeReturnTypeTag); |
| 544 case JsGetName.FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG: | 544 case JsGetName.FUNCTION_TYPE_REQUIRED_PARAMETERS_TAG: |
| 545 return asName(functionTypeRequiredParametersTag); | 545 return asName(functionTypeRequiredParametersTag); |
| 546 case JsGetName.FUNCTION_TYPE_OPTIONAL_PARAMETERS_TAG: | 546 case JsGetName.FUNCTION_TYPE_OPTIONAL_PARAMETERS_TAG: |
| 547 return asName(functionTypeOptionalParametersTag); | 547 return asName(functionTypeOptionalParametersTag); |
| 548 case JsGetName.FUNCTION_TYPE_NAMED_PARAMETERS_TAG: | 548 case JsGetName.FUNCTION_TYPE_NAMED_PARAMETERS_TAG: |
| 549 return asName(functionTypeNamedParametersTag); | 549 return asName(functionTypeNamedParametersTag); |
| 550 case JsGetName.IS_INDEXABLE_FIELD_NAME: | 550 case JsGetName.IS_INDEXABLE_FIELD_NAME: |
| 551 return operatorIs(helpers.jsIndexingBehaviorInterface); | 551 return operatorIs(helpers.jsIndexingBehaviorInterface); |
| 552 case JsGetName.NULL_CLASS_TYPE_NAME: | 552 case JsGetName.NULL_CLASS_TYPE_NAME: |
| 553 return runtimeTypeName(coreClasses.nullClass); | 553 return runtimeTypeName(commonElements.nullClass); |
| 554 case JsGetName.OBJECT_CLASS_TYPE_NAME: | 554 case JsGetName.OBJECT_CLASS_TYPE_NAME: |
| 555 return runtimeTypeName(coreClasses.objectClass); | 555 return runtimeTypeName(commonElements.objectClass); |
| 556 case JsGetName.FUNCTION_CLASS_TYPE_NAME: | 556 case JsGetName.FUNCTION_CLASS_TYPE_NAME: |
| 557 return runtimeTypeName(coreClasses.functionClass); | 557 return runtimeTypeName(commonElements.functionClass); |
| 558 default: | 558 default: |
| 559 reporter.reportErrorMessage(node, MessageKind.GENERIC, | 559 reporter.reportErrorMessage(node, MessageKind.GENERIC, |
| 560 {'text': 'Error: Namer has no name for "$name".'}); | 560 {'text': 'Error: Namer has no name for "$name".'}); |
| 561 return asName('BROKEN'); | 561 return asName('BROKEN'); |
| 562 } | 562 } |
| 563 } | 563 } |
| 564 | 564 |
| 565 /// Return a reference to the given [name]. | 565 /// Return a reference to the given [name]. |
| 566 /// | 566 /// |
| 567 /// This is used to ensure that every use site of a name has a unique node so | 567 /// This is used to ensure that every use site of a name has a unique node so |
| (...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 String disambiguated = name; | 1246 String disambiguated = name; |
| 1247 for (int c = 0; libraryLongNames.containsValue(disambiguated); c++) { | 1247 for (int c = 0; libraryLongNames.containsValue(disambiguated); c++) { |
| 1248 disambiguated = "$name$c"; | 1248 disambiguated = "$name$c"; |
| 1249 } | 1249 } |
| 1250 libraryLongNames[library] = disambiguated; | 1250 libraryLongNames[library] = disambiguated; |
| 1251 return disambiguated; | 1251 return disambiguated; |
| 1252 } | 1252 } |
| 1253 | 1253 |
| 1254 String suffixForGetInterceptor(Iterable<ClassEntity> classes) { | 1254 String suffixForGetInterceptor(Iterable<ClassEntity> classes) { |
| 1255 String abbreviate(ClassElement cls) { | 1255 String abbreviate(ClassElement cls) { |
| 1256 if (cls == coreClasses.objectClass) return "o"; | 1256 if (cls == commonElements.objectClass) return "o"; |
| 1257 if (cls == helpers.jsStringClass) return "s"; | 1257 if (cls == helpers.jsStringClass) return "s"; |
| 1258 if (cls == helpers.jsArrayClass) return "a"; | 1258 if (cls == helpers.jsArrayClass) return "a"; |
| 1259 if (cls == helpers.jsDoubleClass) return "d"; | 1259 if (cls == helpers.jsDoubleClass) return "d"; |
| 1260 if (cls == helpers.jsIntClass) return "i"; | 1260 if (cls == helpers.jsIntClass) return "i"; |
| 1261 if (cls == helpers.jsNumberClass) return "n"; | 1261 if (cls == helpers.jsNumberClass) return "n"; |
| 1262 if (cls == helpers.jsNullClass) return "u"; | 1262 if (cls == helpers.jsNullClass) return "u"; |
| 1263 if (cls == helpers.jsBoolClass) return "b"; | 1263 if (cls == helpers.jsBoolClass) return "b"; |
| 1264 if (cls == helpers.jsInterceptorClass) return "I"; | 1264 if (cls == helpers.jsInterceptorClass) return "I"; |
| 1265 return cls.name; | 1265 return cls.name; |
| 1266 } | 1266 } |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2095 void addSuggestion(String original, String suggestion) { | 2095 void addSuggestion(String original, String suggestion) { |
| 2096 assert(!_suggestedNames.containsKey(original)); | 2096 assert(!_suggestedNames.containsKey(original)); |
| 2097 _suggestedNames[original] = suggestion; | 2097 _suggestedNames[original] = suggestion; |
| 2098 } | 2098 } |
| 2099 | 2099 |
| 2100 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); | 2100 bool hasSuggestion(String original) => _suggestedNames.containsKey(original); |
| 2101 bool isSuggestion(String candidate) { | 2101 bool isSuggestion(String candidate) { |
| 2102 return _suggestedNames.containsValue(candidate); | 2102 return _suggestedNames.containsValue(candidate); |
| 2103 } | 2103 } |
| 2104 } | 2104 } |
| OLD | NEW |