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

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

Issue 2603263002: Prefix resolution_types with Resolution. (Closed)
Patch Set: Rebased Created 3 years, 11 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 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 String get functionTypeVoidReturnTag => r'v'; 1468 String get functionTypeVoidReturnTag => r'v';
1469 1469
1470 String get functionTypeReturnTypeTag => r'ret'; 1470 String get functionTypeReturnTypeTag => r'ret';
1471 1471
1472 String get functionTypeRequiredParametersTag => r'args'; 1472 String get functionTypeRequiredParametersTag => r'args';
1473 1473
1474 String get functionTypeOptionalParametersTag => r'opt'; 1474 String get functionTypeOptionalParametersTag => r'opt';
1475 1475
1476 String get functionTypeNamedParametersTag => r'named'; 1476 String get functionTypeNamedParametersTag => r'named';
1477 1477
1478 Map<FunctionType, jsAst.Name> functionTypeNameMap = 1478 Map<ResolutionFunctionType, jsAst.Name> functionTypeNameMap =
1479 new HashMap<FunctionType, jsAst.Name>(); 1479 new HashMap<ResolutionFunctionType, jsAst.Name>();
1480 final FunctionTypeNamer functionTypeNamer; 1480 final FunctionTypeNamer functionTypeNamer;
1481 1481
1482 jsAst.Name getFunctionTypeName(FunctionType functionType) { 1482 jsAst.Name getFunctionTypeName(ResolutionFunctionType functionType) {
1483 return functionTypeNameMap.putIfAbsent(functionType, () { 1483 return functionTypeNameMap.putIfAbsent(functionType, () {
1484 String proposedName = functionTypeNamer.computeName(functionType); 1484 String proposedName = functionTypeNamer.computeName(functionType);
1485 return getFreshName(instanceScope, proposedName); 1485 return getFreshName(instanceScope, proposedName);
1486 }); 1486 });
1487 } 1487 }
1488 1488
1489 jsAst.Name operatorIsType(DartType type) { 1489 jsAst.Name operatorIsType(ResolutionDartType type) {
1490 if (type.isFunctionType) { 1490 if (type.isFunctionType) {
1491 // TODO(erikcorry): Reduce from $isx to ix when we are minifying. 1491 // TODO(erikcorry): Reduce from $isx to ix when we are minifying.
1492 return new CompoundName([ 1492 return new CompoundName([
1493 new StringBackedName(operatorIsPrefix), 1493 new StringBackedName(operatorIsPrefix),
1494 _literalUnderscore, 1494 _literalUnderscore,
1495 getFunctionTypeName(type) 1495 getFunctionTypeName(type)
1496 ]); 1496 ]);
1497 } 1497 }
1498 return operatorIs(type.element); 1498 return operatorIs(type.element);
1499 } 1499 }
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 if (failed) return; 1785 if (failed) return;
1786 _visit(constant.fields[field]); 1786 _visit(constant.fields[field]);
1787 }, includeSuperAndInjectedMembers: true); 1787 }, includeSuperAndInjectedMembers: true);
1788 } 1788 }
1789 1789
1790 @override 1790 @override
1791 void visitType(TypeConstantValue constant, [_]) { 1791 void visitType(TypeConstantValue constant, [_]) {
1792 // Generates something like 'Type_String_k8F', using the simple name of the 1792 // Generates something like 'Type_String_k8F', using the simple name of the
1793 // type and a hash to disambiguate the same name in different libraries. 1793 // type and a hash to disambiguate the same name in different libraries.
1794 addRoot('Type'); 1794 addRoot('Type');
1795 DartType type = constant.representedType; 1795 ResolutionDartType type = constant.representedType;
1796 String name = type.element?.name; 1796 String name = type.element?.name;
1797 if (name == null) { 1797 if (name == null) {
1798 // e.g. DartType 'dynamic' has no element. 1798 // e.g. DartType 'dynamic' has no element.
1799 name = rtiEncoder.getTypeRepresentationForTypeConstant(type); 1799 name = rtiEncoder.getTypeRepresentationForTypeConstant(type);
1800 } 1800 }
1801 addIdentifier(name); 1801 addIdentifier(name);
1802 add(getHashTag(constant, 3)); 1802 add(getHashTag(constant, 3));
1803 } 1803 }
1804 1804
1805 @override 1805 @override
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1907 int visitConstructed(ConstructedConstantValue constant, [_]) { 1907 int visitConstructed(ConstructedConstantValue constant, [_]) {
1908 int hash = _hashString(3, constant.type.element.name); 1908 int hash = _hashString(3, constant.type.element.name);
1909 constant.type.element.forEachInstanceField((_, FieldElement field) { 1909 constant.type.element.forEachInstanceField((_, FieldElement field) {
1910 hash = _combine(hash, _visit(constant.fields[field])); 1910 hash = _combine(hash, _visit(constant.fields[field]));
1911 }, includeSuperAndInjectedMembers: true); 1911 }, includeSuperAndInjectedMembers: true);
1912 return hash; 1912 return hash;
1913 } 1913 }
1914 1914
1915 @override 1915 @override
1916 int visitType(TypeConstantValue constant, [_]) { 1916 int visitType(TypeConstantValue constant, [_]) {
1917 DartType type = constant.representedType; 1917 ResolutionDartType type = constant.representedType;
1918 // This name includes the library name and type parameters. 1918 // This name includes the library name and type parameters.
1919 String name = rtiEncoder.getTypeRepresentationForTypeConstant(type); 1919 String name = rtiEncoder.getTypeRepresentationForTypeConstant(type);
1920 return _hashString(4, name); 1920 return _hashString(4, name);
1921 } 1921 }
1922 1922
1923 @override 1923 @override
1924 int visitInterceptor(InterceptorConstantValue constant, [_]) { 1924 int visitInterceptor(InterceptorConstantValue constant, [_]) {
1925 String typeName = constant.dispatchedType.element.name; 1925 String typeName = constant.dispatchedType.element.name;
1926 return _hashString(5, typeName); 1926 return _hashString(5, typeName);
1927 } 1927 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2021 return _MASK & (hash + (((_MASK >> 15) & hash) << 15)); 2021 return _MASK & (hash + (((_MASK >> 15) & hash) << 15));
2022 } 2022 }
2023 } 2023 }
2024 2024
2025 class FunctionTypeNamer extends BaseDartTypeVisitor { 2025 class FunctionTypeNamer extends BaseDartTypeVisitor {
2026 final RuntimeTypesEncoder rtiEncoder; 2026 final RuntimeTypesEncoder rtiEncoder;
2027 StringBuffer sb; 2027 StringBuffer sb;
2028 2028
2029 FunctionTypeNamer(this.rtiEncoder); 2029 FunctionTypeNamer(this.rtiEncoder);
2030 2030
2031 String computeName(DartType type) { 2031 String computeName(ResolutionDartType type) {
2032 sb = new StringBuffer(); 2032 sb = new StringBuffer();
2033 visit(type); 2033 visit(type);
2034 return sb.toString(); 2034 return sb.toString();
2035 } 2035 }
2036 2036
2037 visit(DartType type, [_]) { 2037 visit(ResolutionDartType type, [_]) {
2038 type.accept(this, null); 2038 type.accept(this, null);
2039 } 2039 }
2040 2040
2041 visitType(DartType type, _) { 2041 visitType(ResolutionDartType type, _) {
2042 sb.write(type.name); 2042 sb.write(type.name);
2043 } 2043 }
2044 2044
2045 visitFunctionType(FunctionType type, _) { 2045 visitFunctionType(ResolutionFunctionType type, _) {
2046 if (rtiEncoder.isSimpleFunctionType(type)) { 2046 if (rtiEncoder.isSimpleFunctionType(type)) {
2047 sb.write('args${type.parameterTypes.length}'); 2047 sb.write('args${type.parameterTypes.length}');
2048 return; 2048 return;
2049 } 2049 }
2050 visit(type.returnType); 2050 visit(type.returnType);
2051 sb.write('_'); 2051 sb.write('_');
2052 for (DartType parameter in type.parameterTypes) { 2052 for (ResolutionDartType parameter in type.parameterTypes) {
2053 sb.write('_'); 2053 sb.write('_');
2054 visit(parameter); 2054 visit(parameter);
2055 } 2055 }
2056 bool first = false; 2056 bool first = false;
2057 for (DartType parameter in type.optionalParameterTypes) { 2057 for (ResolutionDartType parameter in type.optionalParameterTypes) {
2058 if (!first) { 2058 if (!first) {
2059 sb.write('_'); 2059 sb.write('_');
2060 } 2060 }
2061 sb.write('_'); 2061 sb.write('_');
2062 visit(parameter); 2062 visit(parameter);
2063 first = true; 2063 first = true;
2064 } 2064 }
2065 if (!type.namedParameterTypes.isEmpty) { 2065 if (!type.namedParameterTypes.isEmpty) {
2066 first = false; 2066 first = false;
2067 for (DartType parameter in type.namedParameterTypes) { 2067 for (ResolutionDartType parameter in type.namedParameterTypes) {
2068 if (!first) { 2068 if (!first) {
2069 sb.write('_'); 2069 sb.write('_');
2070 } 2070 }
2071 sb.write('_'); 2071 sb.write('_');
2072 visit(parameter); 2072 visit(parameter);
2073 first = true; 2073 first = true;
2074 } 2074 }
2075 } 2075 }
2076 } 2076 }
2077 } 2077 }
(...skipping 17 matching lines...) Expand all
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 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/lookup_map_analysis.dart ('k') | pkg/compiler/lib/src/js_backend/patch_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698