| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 * The returned id is guaranteed to be a valid JS-id. | 64 * The returned id is guaranteed to be a valid JS-id. |
| 65 */ | 65 */ |
| 66 String _computeGuess(Element element) { | 66 String _computeGuess(Element element) { |
| 67 assert(!element.isInstanceMember()); | 67 assert(!element.isInstanceMember()); |
| 68 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { | 68 if (element.kind == ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 69 FunctionElement functionElement = element; | 69 FunctionElement functionElement = element; |
| 70 return instanceMethodName( | 70 return instanceMethodName( |
| 71 element.name, functionElement.parameterCount(compiler)); | 71 element.name, functionElement.parameterCount(compiler)); |
| 72 } else { | 72 } else { |
| 73 // TODO(floitsch): deal with named constructors. | 73 // TODO(floitsch): deal with named constructors. |
| 74 String name = '${element.name}'; | 74 String name; |
| 75 if (element.kind == ElementKind.FUNCTION) { | 75 if (element.kind == ElementKind.GETTER) { |
| 76 name = getterName(element.name); |
| 77 } else if (element.kind == ElementKind.SETTER) { |
| 78 name = setterName(element.name); |
| 79 } else if (element.kind == ElementKind.FUNCTION) { |
| 76 FunctionElement functionElement = element; | 80 FunctionElement functionElement = element; |
| 77 name = '$name\$${functionElement.parameterCount(compiler)}'; | 81 name = '${element.name}\$${functionElement.parameterCount(compiler)}'; |
| 82 } else { |
| 83 name = '${element.name}'; |
| 78 } | 84 } |
| 79 // Prefix the name with '$' if it is reserved. | 85 // Prefix the name with '$' if it is reserved. |
| 80 if (jsReserved.contains(name)) { | 86 if (jsReserved.contains(name)) { |
| 81 name = "\$$name"; | 87 name = "\$$name"; |
| 82 assert(!jsReserved.contains(name)); | 88 assert(!jsReserved.contains(name)); |
| 83 } | 89 } |
| 84 return name; | 90 return name; |
| 85 } | 91 } |
| 86 } | 92 } |
| 87 | 93 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 switch (element.kind) { | 130 switch (element.kind) { |
| 125 case ElementKind.VARIABLE: | 131 case ElementKind.VARIABLE: |
| 126 case ElementKind.PARAMETER: | 132 case ElementKind.PARAMETER: |
| 127 // The name is not guaranteed to be unique. | 133 // The name is not guaranteed to be unique. |
| 128 return guess; | 134 return guess; |
| 129 | 135 |
| 130 case ElementKind.GENERATIVE_CONSTRUCTOR: | 136 case ElementKind.GENERATIVE_CONSTRUCTOR: |
| 131 case ElementKind.FUNCTION: | 137 case ElementKind.FUNCTION: |
| 132 case ElementKind.CLASS: | 138 case ElementKind.CLASS: |
| 133 case ElementKind.FIELD: | 139 case ElementKind.FIELD: |
| 140 case ElementKind.GETTER: |
| 141 case ElementKind.SETTER: |
| 134 // We need to make sure the name is unique. | 142 // We need to make sure the name is unique. |
| 135 int usedCount = usedGlobals[guess]; | 143 int usedCount = usedGlobals[guess]; |
| 136 if (usedCount === null) { | 144 if (usedCount === null) { |
| 137 // No element with this name has been used before. | 145 // No element with this name has been used before. |
| 138 usedGlobals[guess] = 1; | 146 usedGlobals[guess] = 1; |
| 139 globals[element] = guess; | 147 globals[element] = guess; |
| 140 return guess; | 148 return guess; |
| 141 } else { | 149 } else { |
| 142 // Not the first time we see an element with this name. Append a | 150 // Not the first time we see an element with this name. Append a |
| 143 // number to make it unique. | 151 // number to make it unique. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 171 } | 179 } |
| 172 | 180 |
| 173 String isolateBailoutAccess(Element element) { | 181 String isolateBailoutAccess(Element element) { |
| 174 return '${isolateAccess(element)}\$bailout'; | 182 return '${isolateAccess(element)}\$bailout'; |
| 175 } | 183 } |
| 176 | 184 |
| 177 String operatorIs(ClassElement element) { | 185 String operatorIs(ClassElement element) { |
| 178 return 'is\$${getName(element)}'; | 186 return 'is\$${getName(element)}'; |
| 179 } | 187 } |
| 180 } | 188 } |
| OLD | NEW |