| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library dart2js.js_emitter.program_builder; | 5 library dart2js.js_emitter.program_builder; |
| 6 | 6 |
| 7 import 'js_emitter.dart' show computeMixinClass; | 7 import 'js_emitter.dart' show computeMixinClass; |
| 8 import 'model.dart'; | 8 import 'model.dart'; |
| 9 | 9 |
| 10 import '../common.dart'; | 10 import '../common.dart'; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 _registry.registerHolder(r'$'); | 73 _registry.registerHolder(r'$'); |
| 74 | 74 |
| 75 MainFragment mainOutput = _buildMainOutput(_registry.mainLibrariesMap); | 75 MainFragment mainOutput = _buildMainOutput(_registry.mainLibrariesMap); |
| 76 Iterable<Fragment> deferredOutputs = _registry.deferredLibrariesMap | 76 Iterable<Fragment> deferredOutputs = _registry.deferredLibrariesMap |
| 77 .map((librariesMap) => _buildDeferredOutput(mainOutput, librariesMap)); | 77 .map((librariesMap) => _buildDeferredOutput(mainOutput, librariesMap)); |
| 78 | 78 |
| 79 List<Fragment> outputs = new List<Fragment>(_registry.librariesMapCount); | 79 List<Fragment> outputs = new List<Fragment>(_registry.librariesMapCount); |
| 80 outputs[0] = mainOutput; | 80 outputs[0] = mainOutput; |
| 81 outputs.setAll(1, deferredOutputs); | 81 outputs.setAll(1, deferredOutputs); |
| 82 | 82 |
| 83 Program result = | 83 List<Class> nativeClasses = _task.nativeClasses |
| 84 new Program(outputs, _task.outputContainsConstantList, _buildLoadMap()); | 84 .map((ClassElement classElement) { |
| 85 Class result = _classes[classElement]; |
| 86 return (result == null) ? _buildClass(classElement) : result; |
| 87 }) |
| 88 .toList(); |
| 85 | 89 |
| 86 // Resolve the superclass references after we've processed all the classes. | 90 // Resolve the superclass references after we've processed all the classes. |
| 87 _classes.forEach((ClassElement element, Class c) { | 91 _classes.forEach((ClassElement element, Class c) { |
| 88 if (element.superclass != null) { | 92 if (element.superclass != null) { |
| 89 c.setSuperclass(_classes[element.superclass]); | 93 c.setSuperclass(_classes[element.superclass]); |
| 94 assert(c.superclass != null); |
| 90 } | 95 } |
| 91 if (c is MixinApplication) { | 96 if (c is MixinApplication) { |
| 92 c.setMixinClass(_classes[computeMixinClass(element)]); | 97 c.setMixinClass(_classes[computeMixinClass(element)]); |
| 98 assert(c.mixinClass != null); |
| 93 } | 99 } |
| 94 }); | 100 }); |
| 95 | 101 |
| 96 _markEagerClasses(); | 102 _markEagerClasses(); |
| 97 | 103 |
| 98 return result; | 104 return new Program(outputs, |
| 105 nativeClasses, |
| 106 _task.outputContainsConstantList, |
| 107 _buildLoadMap()); |
| 99 } | 108 } |
| 100 | 109 |
| 101 void _markEagerClasses() { | 110 void _markEagerClasses() { |
| 102 _markEagerInterceptorClasses(); | 111 _markEagerInterceptorClasses(); |
| 103 } | 112 } |
| 104 | 113 |
| 105 /// Builds a map from loadId to outputs-to-load. | 114 /// Builds a map from loadId to outputs-to-load. |
| 106 Map<String, List<Fragment>> _buildLoadMap() { | 115 Map<String, List<Fragment>> _buildLoadMap() { |
| 107 List<OutputUnit> convertHunks(List<OutputUnit> hunks) { | 116 List<OutputUnit> convertHunks(List<OutputUnit> hunks) { |
| 108 return hunks.map((OutputUnit unit) => _outputs[unit]) | 117 return hunks.map((OutputUnit unit) => _outputs[unit]) |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 301 |
| 293 String name = namer.getNameOfClass(element); | 302 String name = namer.getNameOfClass(element); |
| 294 String holderName = namer.globalObjectFor(element); | 303 String holderName = namer.globalObjectFor(element); |
| 295 Holder holder = _registry.registerHolder(holderName); | 304 Holder holder = _registry.registerHolder(holderName); |
| 296 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); | 305 bool onlyForRti = _task.typeTestRegistry.rtiNeededClasses.contains(element); |
| 297 bool isInstantiated = | 306 bool isInstantiated = |
| 298 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element); | 307 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element); |
| 299 | 308 |
| 300 Class result; | 309 Class result; |
| 301 if (element.isMixinApplication && !onlyForRti) { | 310 if (element.isMixinApplication && !onlyForRti) { |
| 311 assert(!element.isNative); |
| 302 result = new MixinApplication(element, | 312 result = new MixinApplication(element, |
| 303 name, holder, methods, fields, | 313 name, holder, methods, fields, |
| 304 isDirectlyInstantiated: isInstantiated, | 314 isDirectlyInstantiated: isInstantiated, |
| 305 onlyForRti: onlyForRti); | 315 onlyForRti: onlyForRti); |
| 306 } else { | 316 } else { |
| 307 result = new Class(element, | 317 result = new Class(element, |
| 308 name, holder, methods, fields, | 318 name, holder, methods, fields, |
| 309 isDirectlyInstantiated: isInstantiated, | 319 isDirectlyInstantiated: isInstantiated, |
| 310 onlyForRti: onlyForRti); | 320 onlyForRti: onlyForRti, |
| 321 isNative: element.isNative); |
| 311 } | 322 } |
| 312 _classes[element] = result; | 323 _classes[element] = result; |
| 313 return result; | 324 return result; |
| 314 } | 325 } |
| 315 | 326 |
| 316 Method _buildMethod(FunctionElement element, js.Expression code) { | 327 Method _buildMethod(FunctionElement element, js.Expression code) { |
| 317 String name = namer.getNameOfInstanceMember(element); | 328 String name = namer.getNameOfInstanceMember(element); |
| 318 // TODO(floitsch): compute `needsTearOff`. | 329 // TODO(floitsch): compute `needsTearOff`. |
| 319 return new Method(element, name, code, needsTearOff: false); | 330 return new Method(element, name, code, needsTearOff: false); |
| 320 } | 331 } |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 _registry.registerConstant(outputUnit, constantValue); | 457 _registry.registerConstant(outputUnit, constantValue); |
| 447 assert(!_constants.containsKey(constantValue)); | 458 assert(!_constants.containsKey(constantValue)); |
| 448 String name = namer.constantName(constantValue); | 459 String name = namer.constantName(constantValue); |
| 449 String constantObject = namer.globalObjectForConstant(constantValue); | 460 String constantObject = namer.globalObjectForConstant(constantValue); |
| 450 Holder holder = _registry.registerHolder(constantObject); | 461 Holder holder = _registry.registerHolder(constantObject); |
| 451 Constant constant = new Constant(name, holder, constantValue); | 462 Constant constant = new Constant(name, holder, constantValue); |
| 452 _constants[constantValue] = constant; | 463 _constants[constantValue] = constant; |
| 453 } | 464 } |
| 454 } | 465 } |
| 455 } | 466 } |
| OLD | NEW |