| 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 /** | 5 /** |
| 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 6 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 7 */ | 7 */ |
| 8 class Namer { | 8 class Namer { |
| 9 final Compiler compiler; | 9 final Compiler compiler; |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 final String ISOLATE = "Isolate"; | 32 final String ISOLATE = "Isolate"; |
| 33 | 33 |
| 34 | 34 |
| 35 String closureInvocationName(Selector selector) { | 35 String closureInvocationName(Selector selector) { |
| 36 // TODO(floitsch): mangle, while not conflicting with instance names. | 36 // TODO(floitsch): mangle, while not conflicting with instance names. |
| 37 return instanceMethodInvocationName(CLOSURE_INVOCATION_NAME, selector); | 37 return instanceMethodInvocationName(CLOSURE_INVOCATION_NAME, selector); |
| 38 } | 38 } |
| 39 | 39 |
| 40 String instanceMethodName(SourceString name, int arity) { | 40 String instanceMethodName(SourceString name, int arity) { |
| 41 // TODO(floitsch): mangle, while preserving uniqueness. | 41 // TODO(floitsch): mangle, while preserving uniqueness. |
| 42 return '$name\$$arity'; | 42 return '${name.slowToString()}\$$arity'; |
| 43 } | 43 } |
| 44 | 44 |
| 45 String instanceMethodInvocationName(SourceString name, Selector selector) { | 45 String instanceMethodInvocationName(SourceString name, Selector selector) { |
| 46 // TODO(floitsch): mangle, while preserving uniqueness. | 46 // TODO(floitsch): mangle, while preserving uniqueness. |
| 47 StringBuffer buffer = new StringBuffer(); | 47 StringBuffer buffer = new StringBuffer(); |
| 48 List<SourceString> names = selector.getOrderedNamedArguments(); | 48 List<SourceString> names = selector.getOrderedNamedArguments(); |
| 49 for (SourceString name in names) { | 49 for (SourceString name in names) { |
| 50 buffer.add('\$$name'); | 50 buffer.add(@'$'); |
| 51 name.printOn(buffer); |
| 51 } | 52 } |
| 52 return '$name\$${selector.argumentCount}$buffer'; | 53 return '${name.slowToString()}\$${selector.argumentCount}$buffer'; |
| 53 } | 54 } |
| 54 | 55 |
| 55 String instanceFieldName(SourceString name) { | 56 String instanceFieldName(SourceString name) { |
| 56 return '$name'; | 57 return name.slowToString(); |
| 57 } | 58 } |
| 58 | 59 |
| 59 String setterName(SourceString name) { | 60 String setterName(SourceString name) { |
| 60 return 'set\$$name'; | 61 return 'set\$${name.slowToString()}'; |
| 61 } | 62 } |
| 62 | 63 |
| 63 String getterName(SourceString name) { | 64 String getterName(SourceString name) { |
| 64 return 'get\$$name'; | 65 return 'get\$${name.slowToString()}'; |
| 65 } | 66 } |
| 66 | 67 |
| 67 String getFreshGlobalName(String proposedName) { | 68 String getFreshGlobalName(String proposedName) { |
| 68 int usedCount = usedGlobals[proposedName]; | 69 int usedCount = usedGlobals[proposedName]; |
| 69 if (usedCount === null) { | 70 if (usedCount === null) { |
| 70 // No element with this name has been used before. | 71 // No element with this name has been used before. |
| 71 usedGlobals[proposedName] = 1; | 72 usedGlobals[proposedName] = 1; |
| 72 return proposedName; | 73 return proposedName; |
| 73 } else { | 74 } else { |
| 74 // Not the first time we see this name. Append a number to make it unique. | 75 // Not the first time we see this name. Append a number to make it unique. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 94 element.name, functionElement.parameterCount(compiler)); | 95 element.name, functionElement.parameterCount(compiler)); |
| 95 } else { | 96 } else { |
| 96 // TODO(floitsch): deal with named constructors. | 97 // TODO(floitsch): deal with named constructors. |
| 97 String name; | 98 String name; |
| 98 if (element.kind == ElementKind.GETTER) { | 99 if (element.kind == ElementKind.GETTER) { |
| 99 name = getterName(element.name); | 100 name = getterName(element.name); |
| 100 } else if (element.kind == ElementKind.SETTER) { | 101 } else if (element.kind == ElementKind.SETTER) { |
| 101 name = setterName(element.name); | 102 name = setterName(element.name); |
| 102 } else if (element.kind == ElementKind.FUNCTION) { | 103 } else if (element.kind == ElementKind.FUNCTION) { |
| 103 FunctionElement functionElement = element; | 104 FunctionElement functionElement = element; |
| 104 name = '${element.name}\$${functionElement.parameterCount(compiler)}'; | 105 name = element.name.slowToString(); |
| 106 name = '$name\$${functionElement.parameterCount(compiler)}'; |
| 105 } else { | 107 } else { |
| 106 name = '${element.name}'; | 108 name = '${element.name.slowToString()}'; |
| 107 } | 109 } |
| 108 // Prefix the name with '$' if it is reserved. | 110 // Prefix the name with '$' if it is reserved. |
| 109 if (jsReserved.contains(name)) { | 111 if (jsReserved.contains(name)) { |
| 110 name = "\$$name"; | 112 name = "\$$name"; |
| 111 assert(!jsReserved.contains(name)); | 113 assert(!jsReserved.contains(name)); |
| 112 } | 114 } |
| 113 return name; | 115 return name; |
| 114 } | 116 } |
| 115 } | 117 } |
| 116 | 118 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 187 } |
| 186 | 188 |
| 187 String isolateBailoutAccess(Element element) { | 189 String isolateBailoutAccess(Element element) { |
| 188 return '${isolateAccess(element)}\$bailout'; | 190 return '${isolateAccess(element)}\$bailout'; |
| 189 } | 191 } |
| 190 | 192 |
| 191 String operatorIs(ClassElement element) { | 193 String operatorIs(ClassElement element) { |
| 192 return 'is\$${getName(element)}'; | 194 return 'is\$${getName(element)}'; |
| 193 } | 195 } |
| 194 } | 196 } |
| OLD | NEW |