| 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 final Map<String, LibraryElement> shortPrivateNameOwners; | 23 final Map<String, LibraryElement> shortPrivateNameOwners; |
| 24 | 24 |
| 25 final Map<Constant, String> constantNames; | 25 final Map<Constant, String> constantNames; |
| 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 shortPrivateNameOwners = new Map<String, LibraryElement>(), | 30 shortPrivateNameOwners = new Map<String, LibraryElement>(), |
| 31 constantNames = new Map<Constant, String>(); | 31 constantNames = new Map<Constant, String>(); |
| 32 | 32 |
| 33 final String CURRENT_ISOLATE = @'$'; | 33 final String CURRENT_ISOLATE = r'$'; |
| 34 final String ISOLATE = 'Isolate'; | 34 final String ISOLATE = 'Isolate'; |
| 35 final String ISOLATE_PROPERTIES = @"$isolateProperties"; | 35 final String ISOLATE_PROPERTIES = r"$isolateProperties"; |
| 36 /** Some closures must contain their name. The name is stored in | 36 /** Some closures must contain their name. The name is stored in |
| 37 * [STATIC_CLOSURE_NAME_NAME]. */ | 37 * [STATIC_CLOSURE_NAME_NAME]. */ |
| 38 final String STATIC_CLOSURE_NAME_NAME = @'$name'; | 38 final String STATIC_CLOSURE_NAME_NAME = r'$name'; |
| 39 static const SourceString CLOSURE_INVOCATION_NAME = | 39 static const SourceString CLOSURE_INVOCATION_NAME = |
| 40 Compiler.CALL_OPERATOR_NAME; | 40 Compiler.CALL_OPERATOR_NAME; |
| 41 | 41 |
| 42 String constantName(Constant constant) { | 42 String constantName(Constant constant) { |
| 43 // In the current implementation it doesn't make sense to give names to | 43 // In the current implementation it doesn't make sense to give names to |
| 44 // function constants since the function-implementation itself serves as | 44 // function constants since the function-implementation itself serves as |
| 45 // constant and can be accessed directly. | 45 // constant and can be accessed directly. |
| 46 assert(!constant.isFunction()); | 46 assert(!constant.isFunction()); |
| 47 String result = constantNames[constant]; | 47 String result = constantNames[constant]; |
| 48 if (result === null) { | 48 if (result === null) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 assert(!name.isPrivate()); | 124 assert(!name.isPrivate()); |
| 125 return '${name.slowToString()}\$$arity'; | 125 return '${name.slowToString()}\$$arity'; |
| 126 } | 126 } |
| 127 | 127 |
| 128 String instanceMethodInvocationName(LibraryElement lib, SourceString name, | 128 String instanceMethodInvocationName(LibraryElement lib, SourceString name, |
| 129 Selector selector) { | 129 Selector selector) { |
| 130 // TODO(floitsch): mangle, while preserving uniqueness. | 130 // TODO(floitsch): mangle, while preserving uniqueness. |
| 131 StringBuffer buffer = new StringBuffer(); | 131 StringBuffer buffer = new StringBuffer(); |
| 132 List<SourceString> names = selector.getOrderedNamedArguments(); | 132 List<SourceString> names = selector.getOrderedNamedArguments(); |
| 133 for (SourceString argumentName in names) { | 133 for (SourceString argumentName in names) { |
| 134 buffer.add(@'$'); | 134 buffer.add(r'$'); |
| 135 argumentName.printOn(buffer); | 135 argumentName.printOn(buffer); |
| 136 } | 136 } |
| 137 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; | 137 return '${privateName(lib, name)}\$${selector.argumentCount}$buffer'; |
| 138 } | 138 } |
| 139 | 139 |
| 140 String instanceFieldName(LibraryElement libraryElement, SourceString name) { | 140 String instanceFieldName(LibraryElement libraryElement, SourceString name) { |
| 141 String proposedName = privateName(libraryElement, name); | 141 String proposedName = privateName(libraryElement, name); |
| 142 return safeName(proposedName); | 142 return safeName(proposedName); |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 303 } |
| 304 | 304 |
| 305 String safeName(String name) { | 305 String safeName(String name) { |
| 306 if (jsReserved.contains(name) || name.startsWith('\$')) { | 306 if (jsReserved.contains(name) || name.startsWith('\$')) { |
| 307 name = "\$$name"; | 307 name = "\$$name"; |
| 308 assert(!jsReserved.contains(name)); | 308 assert(!jsReserved.contains(name)); |
| 309 } | 309 } |
| 310 return name; | 310 return name; |
| 311 } | 311 } |
| 312 } | 312 } |
| OLD | NEW |