| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 Map<Element, String> globals; | 24 Map<Element, String> globals; |
| 25 Map<String, int> usedGlobals; | 25 Map<String, int> usedGlobals; |
| 26 | 26 |
| 27 Namer(this.compiler) | 27 Namer(this.compiler) |
| 28 : globals = new Map<Element, String>(), | 28 : globals = new Map<Element, String>(), |
| 29 usedGlobals = new Map<String, int>(); | 29 usedGlobals = new Map<String, int>(); |
| 30 | 30 |
| 31 final String CURRENT_ISOLATE = "\$"; | 31 final String CURRENT_ISOLATE = "\$"; |
| 32 final String ISOLATE = "Isolate"; | 32 final String ISOLATE = "Isolate"; |
| 33 final String ISOLATE_PROPERTIES = "\$isolateProperties"; |
| 33 | 34 |
| 34 | 35 |
| 35 String closureInvocationName(Selector selector) { | 36 String closureInvocationName(Selector selector) { |
| 36 // TODO(floitsch): mangle, while not conflicting with instance names. | 37 // TODO(floitsch): mangle, while not conflicting with instance names. |
| 37 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, | 38 return instanceMethodInvocationName(null, CLOSURE_INVOCATION_NAME, |
| 38 selector); | 39 selector); |
| 39 } | 40 } |
| 40 | 41 |
| 41 String privateName(LibraryElement lib, SourceString name) { | 42 String privateName(LibraryElement lib, SourceString name) { |
| 42 if (name.isPrivate()) { | 43 if (name.isPrivate()) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 globals[element] = result; | 183 globals[element] = result; |
| 183 return result; | 184 return result; |
| 184 | 185 |
| 185 default: | 186 default: |
| 186 compiler.internalError('getName for unknown kind: ${element.kind}', | 187 compiler.internalError('getName for unknown kind: ${element.kind}', |
| 187 node: element.parseNode(compiler)); | 188 node: element.parseNode(compiler)); |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 } | 191 } |
| 191 | 192 |
| 193 String isolatePropertiesAccess(Element element) { |
| 194 return "$ISOLATE.$ISOLATE_PROPERTIES.${getName(element)}"; |
| 195 } |
| 196 |
| 197 String isolatePropertiesAccessForConstant(String constantName) { |
| 198 return "$ISOLATE.$ISOLATE_PROPERTIES.$constantName"; |
| 199 } |
| 200 |
| 192 String isolateAccess(Element element) { | 201 String isolateAccess(Element element) { |
| 193 return "$CURRENT_ISOLATE.${getName(element)}"; | 202 return "$CURRENT_ISOLATE.${getName(element)}"; |
| 194 } | 203 } |
| 195 | 204 |
| 196 String isolatePropertyAccess(Element element) { | |
| 197 return "$ISOLATE.prototype.${getName(element)}"; | |
| 198 } | |
| 199 | |
| 200 String isolateBailoutAccess(Element element) { | 205 String isolateBailoutAccess(Element element) { |
| 201 return '${isolateAccess(element)}\$bailout'; | 206 return '${isolateAccess(element)}\$bailout'; |
| 202 } | 207 } |
| 203 | 208 |
| 204 String operatorIs(Element element) { | 209 String operatorIs(Element element) { |
| 205 return 'is\$${getName(element)}'; | 210 return 'is\$${getName(element)}'; |
| 206 } | 211 } |
| 207 | 212 |
| 208 String safeName(String name) { | 213 String safeName(String name) { |
| 209 if (jsReserved.contains(name) || name.startsWith('\$')) { | 214 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 210 name = "\$$name"; | 215 name = "\$$name"; |
| 211 assert(!jsReserved.contains(name)); | 216 assert(!jsReserved.contains(name)); |
| 212 } | 217 } |
| 213 return name; | 218 return name; |
| 214 } | 219 } |
| 215 } | 220 } |
| OLD | NEW |