| 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 static Set<String> _jsReserved = null; | 9 static Set<String> _jsReserved = null; |
| 10 Set<String> get jsReserved() { | 10 Set<String> get jsReserved() { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // TODO(floitsch): mangle, while preserving uniqueness. | 32 // TODO(floitsch): mangle, while preserving uniqueness. |
| 33 return candidate; | 33 return candidate; |
| 34 } | 34 } |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * The constructor-body name is computed from the corresponding | 37 * The constructor-body name is computed from the corresponding |
| 38 * constructor element because, in the case of a super-initialization, the | 38 * constructor element because, in the case of a super-initialization, the |
| 39 * body element is not accessible. | 39 * body element is not accessible. |
| 40 */ | 40 */ |
| 41 String constructorBodyName(Element element) { | 41 String constructorBodyName(Element element) { |
| 42 assert(element.kind == ElementKind.CONSTRUCTOR); | 42 assert(element.kind == ElementKind.GENERATIVE_CONSTRUCTOR); |
| 43 // TODO(floitsch): the constructor-body name must not conflict with other | 43 // TODO(floitsch): the constructor-body name must not conflict with other |
| 44 // instance fields. | 44 // instance fields. |
| 45 // TOD(floitsch): deal with named constructors. | 45 // TOD(floitsch): deal with named constructors. |
| 46 return instanceName(element.name); | 46 return instanceName(element.name); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Returns a preferred JS-id for the given element. The returned id is | 50 * Returns a preferred JS-id for the given element. The returned id is |
| 51 * guaranteed to be a valid JS-id. | 51 * guaranteed to be a valid JS-id. |
| 52 * | 52 * |
| 53 * For instance-members the returned strings are guaranteed not to clash. For | 53 * For instance-members the returned strings are guaranteed not to clash. For |
| 54 * static variables there might be clashes. In the latter case the caller | 54 * static variables there might be clashes. In the latter case the caller |
| 55 * needs to ensure uniqueness. | 55 * needs to ensure uniqueness. |
| 56 */ | 56 */ |
| 57 String getName(Element element) { | 57 String getName(Element element) { |
| 58 switch (element.kind) { | 58 switch (element.kind) { |
| 59 case ElementKind.CONSTRUCTOR_BODY: | 59 case ElementKind.GENERATIVE_CONSTRUCTOR_BODY: |
| 60 ConstructorBodyElement bodyElement = element; | 60 ConstructorBodyElement bodyElement = element; |
| 61 return constructorBodyName(bodyElement.constructor); | 61 return constructorBodyName(bodyElement.constructor); |
| 62 | 62 |
| 63 case ElementKind.CONSTRUCTOR: | 63 case ElementKind.GENERATIVE_CONSTRUCTOR: |
| 64 default: | 64 default: |
| 65 if (element.isInstanceMember()) { | 65 if (element.isInstanceMember()) { |
| 66 return instanceName(element.name); | 66 return instanceName(element.name); |
| 67 } | 67 } |
| 68 // TODO(floitsch): deal with named constructors. | 68 // TODO(floitsch): deal with named constructors. |
| 69 String name = '${element.name}'; | 69 String name = '${element.name}'; |
| 70 // Prefix the name with '$' if it is reserved. | 70 // Prefix the name with '$' if it is reserved. |
| 71 if (jsReserved.contains(name)) { | 71 if (jsReserved.contains(name)) { |
| 72 name = "\$$name"; | 72 name = "\$$name"; |
| 73 assert(!jsReserved.contains(name)); | 73 assert(!jsReserved.contains(name)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if (jsId === null) jsId = define(element); | 117 if (jsId === null) jsId = define(element); |
| 118 return "$currentIsolate.$jsId"; | 118 return "$currentIsolate.$jsId"; |
| 119 } | 119 } |
| 120 | 120 |
| 121 String isolatePropertyAccess(Element element) { | 121 String isolatePropertyAccess(Element element) { |
| 122 String jsId = globals[element]; | 122 String jsId = globals[element]; |
| 123 if (jsId === null) jsId = define(element); | 123 if (jsId === null) jsId = define(element); |
| 124 return "$isolate.prototype.$jsId"; | 124 return "$isolate.prototype.$jsId"; |
| 125 } | 125 } |
| 126 } | 126 } |
| OLD | NEW |