Index: sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
index 1d52f469ec7bd065f07fe41756bc24db5948c18c..cc6b7f670aecadeeea196528c34c1961804b323c 100644 |
--- a/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/namer.dart |
@@ -723,6 +723,41 @@ class Namer implements ClosureNamer { |
String operatorAsPrefix() => r'$as'; |
+ String operatorSignature() => r'$signature'; |
+ |
+ String functionTypeTag() => r'func'; |
+ |
+ String functionTypeVoidReturnTag() => r'void'; |
+ |
+ String functionTypeReturnTypeTag() => r'ret'; |
+ |
+ String functionTypeRequiredParametersTag() => r'args'; |
+ |
+ String functionTypeOptionalParametersTag() => r'opt'; |
+ |
+ String functionTypeNamedParametersTag() => r'named'; |
+ |
+ Map<FunctionType,String> functionTypeNameMap = |
+ new Map<FunctionType,String>(); |
+ FunctionTypeNamer functionTypeNamer = new FunctionTypeNamer(); |
+ |
+ String getFunctionTypeName(FunctionType functionType) { |
+ return functionTypeNameMap.putIfAbsent(functionType, () { |
+ String proposedName = functionTypeNamer.computeName(functionType); |
+ String freshName = getFreshName(proposedName, usedInstanceNames, |
+ suggestedInstanceNames, ensureSafe: true); |
+ return freshName; |
+ }); |
+ } |
+ |
+ String operatorIsType(DartType type) { |
+ if (type.kind == TypeKind.FUNCTION) { |
+ // TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
+ return '${operatorIsPrefix()}_${getFunctionTypeName(type)}'; |
+ } |
+ return operatorIs(type.element); |
+ } |
+ |
String operatorIs(Element element) { |
// TODO(erikcorry): Reduce from $isx to ix when we are minifying. |
return '${operatorIsPrefix()}${getName(element)}'; |
@@ -744,6 +779,20 @@ class Namer implements ClosureNamer { |
return '${operatorAsPrefix()}${getName(element)}'; |
} |
+ String signatureLocation(FunctionType type) { |
+ ClassElement classElement = Types.getClassContext(type); |
+ if (classElement != null) { |
+ return '${isolateAccess(classElement)}'; |
+ } else { |
+ return '${CURRENT_ISOLATE}'; |
karlklose
2013/03/22 13:17:46
No {} needed.
Johnni Winther
2013/06/21 12:19:14
I like them, anyway!
|
+ } |
+ } |
+ |
+ String signatureName(FunctionType type) { |
+ String signature = '${operatorSignature()}_${getFunctionTypeName(type)}'; |
+ return '${signatureLocation(type)}.$signature'; |
+ } |
+ |
String safeName(String name) => _safeName(name, jsReserved); |
String safeVariableName(String name) => _safeName(name, jsVariableReserved); |
@@ -797,3 +846,47 @@ class Namer implements ClosureNamer { |
} |
} |
} |
+ |
+class FunctionTypeNamer extends DartTypeVisitor { |
+ StringBuffer sb; |
+ |
+ String computeName(DartType type) { |
+ sb = new StringBuffer(); |
+ visit(type); |
+ return sb.toString(); |
+ } |
+ |
+ visit(DartType type) { |
+ type.accept(this, null); |
+ } |
+ |
+ visitType(DartType type, _) { |
+ sb.write(type.name.slowToString()); |
+ } |
+ |
+ visitFunctionType(FunctionType type, _) { |
+ visit(type.returnType); |
+ sb.write('_'); |
+ for (Link<DartType> link = type.parameterTypes; |
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ for (Link<DartType> link = type.optionalParameterTypes; |
karlklose
2013/03/22 13:17:46
Don't we need a separator between the sets of para
Johnni Winther
2013/06/21 12:19:14
Done.
|
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ if (!type.namedParameterTypes.isEmpty) { |
+ for (Link<DartType> link = type.namedParameterTypes; |
+ !link.isEmpty; |
+ link = link.tail) { |
+ sb.write('_'); |
+ visit(link.head); |
+ } |
+ } |
+ } |
+ |
+} |