Chromium Code Reviews| 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 part of js_backend; | 5 part of js_backend; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. | 8 * Assigns JavaScript identifiers to Dart variables, class-names and members. |
| 9 */ | 9 */ |
| 10 class MinifyNamer extends Namer with _MinifiedFieldNamer, | 10 class MinifyNamer extends Namer with _MinifiedFieldNamer, |
| 11 _MinifiedOneShotInterceptorNamer { | 11 _MinifyConstructorBodyNamer, _MinifiedOneShotInterceptorNamer { |
| 12 MinifyNamer(Compiler compiler) : super(compiler) { | 12 MinifyNamer(Compiler compiler) : super(compiler) { |
| 13 reserveBackendNames(); | 13 reserveBackendNames(); |
| 14 fieldRegistry = new _FieldNamingRegistry(this); | 14 fieldRegistry = new _FieldNamingRegistry(this); |
| 15 } | 15 } |
| 16 | 16 |
| 17 _FieldNamingRegistry fieldRegistry; | 17 _FieldNamingRegistry fieldRegistry; |
| 18 | 18 |
| 19 String get isolateName => 'I'; | 19 String get isolateName => 'I'; |
| 20 String get isolatePropertiesName => 'p'; | 20 String get isolatePropertiesName => 'p'; |
| 21 bool get shouldMinify => true; | 21 bool get shouldMinify => true; |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 @override | 249 @override |
| 250 jsAst.Name instanceFieldPropertyName(Element element) { | 250 jsAst.Name instanceFieldPropertyName(Element element) { |
| 251 jsAst.Name proposed = _minifiedInstanceFieldPropertyName(element); | 251 jsAst.Name proposed = _minifiedInstanceFieldPropertyName(element); |
| 252 if (proposed != null) { | 252 if (proposed != null) { |
| 253 return proposed; | 253 return proposed; |
| 254 } | 254 } |
| 255 return super.instanceFieldPropertyName(element); | 255 return super.instanceFieldPropertyName(element); |
| 256 } | 256 } |
| 257 } | 257 } |
| 258 | 258 |
| 259 class _ConstructorBodyNamingScope { | |
|
sra1
2015/07/01 16:15:47
Add a comment saying what this is doing and why it
herhut
2015/07/02 09:03:00
Done.
| |
| 260 final int _startIndex; | |
| 261 final List _constructors; | |
| 262 | |
| 263 int get numberOfConstructors => _constructors.length; | |
| 264 | |
| 265 _ConstructorBodyNamingScope _superScope; | |
| 266 | |
| 267 _ConstructorBodyNamingScope.rootScope(ClassElement cls) | |
| 268 : _superScope = null, | |
| 269 _startIndex = 0, | |
| 270 _constructors = cls.constructors.toList(growable: false); | |
| 271 | |
| 272 _ConstructorBodyNamingScope.forClass(ClassElement cls, | |
| 273 _ConstructorBodyNamingScope superScope) | |
| 274 : _superScope = superScope, | |
| 275 _startIndex = superScope._startIndex + superScope.numberOfConstructors, | |
| 276 _constructors = cls.constructors.toList(growable: false); | |
| 277 | |
| 278 // Mixin Applications have constructors but we never generate code for them, | |
| 279 // so they do not count in the inheritance chain. | |
| 280 _ConstructorBodyNamingScope.forMixinApplication(ClassElement cls, | |
| 281 _ConstructorBodyNamingScope superScope) | |
| 282 : _superScope = superScope, | |
| 283 _startIndex = superScope._startIndex + superScope.numberOfConstructors, | |
| 284 _constructors = const []; | |
| 285 | |
| 286 factory _ConstructorBodyNamingScope(ClassElement cls, Map<ClassElement, | |
|
sra1
2015/07/01 16:15:47
break between parameters before breaking within pa
herhut
2015/07/02 09:03:00
Done.
| |
| 287 _ConstructorBodyNamingScope> registry) { | |
| 288 return registry.putIfAbsent(cls, () { | |
| 289 if (cls.superclass == null) { | |
| 290 return new _ConstructorBodyNamingScope.rootScope(cls); | |
| 291 } else if (cls.isMixinApplication) { | |
| 292 return new _ConstructorBodyNamingScope.forMixinApplication(cls, | |
| 293 new _ConstructorBodyNamingScope(cls.superclass, registry)); | |
| 294 } else { | |
| 295 return new _ConstructorBodyNamingScope.forClass(cls, | |
| 296 new _ConstructorBodyNamingScope(cls.superclass, registry)); | |
| 297 } | |
| 298 }); | |
| 299 } | |
| 300 | |
| 301 String constructorBodyKeyFor(ConstructorBodyElement body) { | |
| 302 int position = _constructors.indexOf(body.constructor); | |
| 303 assert(invariant(body, position >= 0, message: "constructor body missing")); | |
| 304 return "@constructorBody@${_startIndex + position}"; | |
| 305 } | |
| 306 } | |
| 307 | |
| 308 abstract class _MinifyConstructorBodyNamer implements Namer { | |
| 309 Map<ClassElement, _ConstructorBodyNamingScope> _constructorBodyScopes = | |
| 310 new Map<ClassElement, _ConstructorBodyNamingScope>(); | |
| 311 | |
| 312 @override | |
| 313 jsAst.Name constructorBodyName(FunctionElement method) { | |
| 314 _ConstructorBodyNamingScope scope = | |
| 315 new _ConstructorBodyNamingScope(method.enclosingClass, | |
| 316 _constructorBodyScopes); | |
| 317 String key = scope.constructorBodyKeyFor(method); | |
| 318 return _disambiguateMemberByKey(key, | |
| 319 () => _proposeNameForConstructorBody(method)); | |
| 320 return _disambiguateInternalMember(method, null); | |
|
sra1
2015/07/01 16:15:47
remove dead code.
I was trying to understand how t
herhut
2015/07/02 09:03:00
Sorry. Done.
| |
| 321 } | |
| 322 } | |
| 323 | |
| 259 abstract class _MinifiedOneShotInterceptorNamer implements Namer { | 324 abstract class _MinifiedOneShotInterceptorNamer implements Namer { |
| 260 /// Property name used for the one-shot interceptor method for the given | 325 /// Property name used for the one-shot interceptor method for the given |
| 261 /// [selector] and return-type specialization. | 326 /// [selector] and return-type specialization. |
| 262 @override | 327 @override |
| 263 jsAst.Name nameForGetOneShotInterceptor(Selector selector, | 328 jsAst.Name nameForGetOneShotInterceptor(Selector selector, |
| 264 Iterable<ClassElement> classes) { | 329 Iterable<ClassElement> classes) { |
| 265 String root = selector.isOperator | 330 String root = selector.isOperator |
| 266 ? operatorNameToIdentifier(selector.name) | 331 ? operatorNameToIdentifier(selector.name) |
| 267 : privateName(selector.memberName); | 332 : privateName(selector.memberName); |
| 268 String prefix = selector.isGetter | 333 String prefix = selector.isGetter |
| 269 ? r"$get" | 334 ? r"$get" |
| 270 : selector.isSetter ? r"$set" : ""; | 335 : selector.isSetter ? r"$set" : ""; |
| 271 String arity = selector.isCall ? "${selector.argumentCount}" : ""; | 336 String arity = selector.isCall ? "${selector.argumentCount}" : ""; |
| 272 String suffix = suffixForGetInterceptor(classes); | 337 String suffix = suffixForGetInterceptor(classes); |
| 273 String fullName = "\$intercepted$prefix\$$root$arity\$$suffix"; | 338 String fullName = "\$intercepted$prefix\$$root$arity\$$suffix"; |
| 274 return _disambiguateInternalGlobal(fullName); | 339 return _disambiguateInternalGlobal(fullName); |
| 275 } | 340 } |
| 276 } | 341 } |
| 277 | 342 |
| OLD | NEW |