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

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

Issue 22903036: Use predicates to check simple function types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 4 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 usedGlobalNames = new Set<String>(), 218 usedGlobalNames = new Set<String>(),
219 usedInstanceNames = new Set<String>(), 219 usedInstanceNames = new Set<String>(),
220 instanceNameMap = new Map<String, String>(), 220 instanceNameMap = new Map<String, String>(),
221 operatorNameMap = new Map<String, String>(), 221 operatorNameMap = new Map<String, String>(),
222 globalNameMap = new Map<String, String>(), 222 globalNameMap = new Map<String, String>(),
223 suggestedGlobalNames = new Map<String, String>(), 223 suggestedGlobalNames = new Map<String, String>(),
224 suggestedInstanceNames = new Map<String, String>(), 224 suggestedInstanceNames = new Map<String, String>(),
225 popularNameCounters = new Map<String, int>(), 225 popularNameCounters = new Map<String, int>(),
226 constantNames = new Map<Constant, String>(), 226 constantNames = new Map<Constant, String>(),
227 constantLongNames = new Map<Constant, String>(), 227 constantLongNames = new Map<Constant, String>(),
228 constantHasher = new ConstantCanonicalHasher(compiler); 228 constantHasher = new ConstantCanonicalHasher(compiler),
229 functionTypeNamer = new FunctionTypeNamer(compiler);
229 230
230 String get isolateName => 'Isolate'; 231 String get isolateName => 'Isolate';
231 String get isolatePropertiesName => r'$isolateProperties'; 232 String get isolatePropertiesName => r'$isolateProperties';
232 /** 233 /**
233 * Some closures must contain their name. The name is stored in 234 * Some closures must contain their name. The name is stored in
234 * [STATIC_CLOSURE_NAME_NAME]. 235 * [STATIC_CLOSURE_NAME_NAME].
235 */ 236 */
236 String get STATIC_CLOSURE_NAME_NAME => r'$name'; 237 String get STATIC_CLOSURE_NAME_NAME => r'$name';
237 SourceString get closureInvocationSelectorName => Compiler.CALL_OPERATOR_NAME; 238 SourceString get closureInvocationSelectorName => Compiler.CALL_OPERATOR_NAME;
238 bool get shouldMinify => false; 239 bool get shouldMinify => false;
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 String functionTypeReturnTypeTag() => r'ret'; 794 String functionTypeReturnTypeTag() => r'ret';
794 795
795 String functionTypeRequiredParametersTag() => r'args'; 796 String functionTypeRequiredParametersTag() => r'args';
796 797
797 String functionTypeOptionalParametersTag() => r'opt'; 798 String functionTypeOptionalParametersTag() => r'opt';
798 799
799 String functionTypeNamedParametersTag() => r'named'; 800 String functionTypeNamedParametersTag() => r'named';
800 801
801 Map<FunctionType,String> functionTypeNameMap = 802 Map<FunctionType,String> functionTypeNameMap =
802 new Map<FunctionType,String>(); 803 new Map<FunctionType,String>();
803 FunctionTypeNamer functionTypeNamer = new FunctionTypeNamer(); 804 final FunctionTypeNamer functionTypeNamer;
804 805
805 String getFunctionTypeName(FunctionType functionType) { 806 String getFunctionTypeName(FunctionType functionType) {
806 return functionTypeNameMap.putIfAbsent(functionType, () { 807 return functionTypeNameMap.putIfAbsent(functionType, () {
807 String proposedName = functionTypeNamer.computeName(functionType); 808 String proposedName = functionTypeNamer.computeName(functionType);
808 String freshName = getFreshName(proposedName, usedInstanceNames, 809 String freshName = getFreshName(proposedName, usedInstanceNames,
809 suggestedInstanceNames, ensureSafe: true); 810 suggestedInstanceNames, ensureSafe: true);
810 return freshName; 811 return freshName;
811 }); 812 });
812 } 813 }
813 814
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 } 1217 }
1217 1218
1218 static int _finish(int hash) { 1219 static int _finish(int hash) {
1219 hash = _MASK & (hash + (((_MASK >> 3) & hash) << 3)); 1220 hash = _MASK & (hash + (((_MASK >> 3) & hash) << 3));
1220 hash = hash & (hash >> 11); 1221 hash = hash & (hash >> 11);
1221 return _MASK & (hash + (((_MASK >> 15) & hash) << 15)); 1222 return _MASK & (hash + (((_MASK >> 15) & hash) << 15));
1222 } 1223 }
1223 } 1224 }
1224 1225
1225 class FunctionTypeNamer extends DartTypeVisitor { 1226 class FunctionTypeNamer extends DartTypeVisitor {
1227 final Compiler compiler;
1226 StringBuffer sb; 1228 StringBuffer sb;
1227 1229
1230 FunctionTypeNamer(this.compiler);
1231
1232 JavaScriptBackend get backend => compiler.backend;
1233
1228 String computeName(DartType type) { 1234 String computeName(DartType type) {
1229 sb = new StringBuffer(); 1235 sb = new StringBuffer();
1230 visit(type); 1236 visit(type);
1231 return sb.toString(); 1237 return sb.toString();
1232 } 1238 }
1233 1239
1234 visit(DartType type) { 1240 visit(DartType type) {
1235 type.accept(this, null); 1241 type.accept(this, null);
1236 } 1242 }
1237 1243
1238 visitType(DartType type, _) { 1244 visitType(DartType type, _) {
1239 sb.write(type.name.slowToString()); 1245 sb.write(type.name.slowToString());
1240 } 1246 }
1241 1247
1242 visitFunctionType(FunctionType type, _) { 1248 visitFunctionType(FunctionType type, _) {
1249 if (backend.rti.isSimpleFunctionType(type)) {
1250 sb.write('args${type.parameterTypes.slowLength()}');
1251 return;
1252 }
1243 visit(type.returnType); 1253 visit(type.returnType);
1244 sb.write('_'); 1254 sb.write('_');
1245 for (Link<DartType> link = type.parameterTypes; 1255 for (Link<DartType> link = type.parameterTypes;
1246 !link.isEmpty; 1256 !link.isEmpty;
1247 link = link.tail) { 1257 link = link.tail) {
1248 sb.write('_'); 1258 sb.write('_');
1249 visit(link.head); 1259 visit(link.head);
1250 } 1260 }
1251 bool first = false; 1261 bool first = false;
1252 for (Link<DartType> link = type.optionalParameterTypes; 1262 for (Link<DartType> link = type.optionalParameterTypes;
(...skipping 14 matching lines...) Expand all
1267 if (!first) { 1277 if (!first) {
1268 sb.write('_'); 1278 sb.write('_');
1269 } 1279 }
1270 sb.write('_'); 1280 sb.write('_');
1271 visit(link.head); 1281 visit(link.head);
1272 first = true; 1282 first = true;
1273 } 1283 }
1274 } 1284 }
1275 } 1285 }
1276 } 1286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698