| 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.new_js_emitter.model_emitter; | 5 library dart2js.new_js_emitter.model_emitter; |
| 6 | 6 |
| 7 import '../../dart2jslib.dart' show Compiler; | 7 import '../../dart2jslib.dart' show Compiler; |
| 8 import '../../js/js.dart' as js; | 8 import '../../js/js.dart' as js; |
| 9 import '../../js_backend/js_backend.dart' show | 9 import '../../js_backend/js_backend.dart' show |
| 10 JavaScriptBackend, | 10 JavaScriptBackend, |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 List<js.Statement> instantiations = | 300 List<js.Statement> instantiations = |
| 301 libraries.expand((Library library) => library.classes) | 301 libraries.expand((Library library) => library.classes) |
| 302 .where((Class cls) => cls.isEager) | 302 .where((Class cls) => cls.isEager) |
| 303 .map(createInstantiation) | 303 .map(createInstantiation) |
| 304 .toList(growable: false); | 304 .toList(growable: false); |
| 305 return new js.Block(instantiations); | 305 return new js.Block(instantiations); |
| 306 } | 306 } |
| 307 | 307 |
| 308 js.Expression emitLibrary(Library library) { | 308 js.Expression emitLibrary(Library library) { |
| 309 Iterable staticDescriptors = library.statics.expand((StaticMethod e) => | 309 Iterable staticDescriptors = library.statics.expand(emitStaticMethod); |
| 310 [ js.string(e.name), js.number(e.holder.index), emitStaticMethod(e) ]); | |
| 311 Iterable classDescriptors = library.classes.expand((Class e) => | 310 Iterable classDescriptors = library.classes.expand((Class e) => |
| 312 [ js.string(e.name), js.number(e.holder.index), emitClass(e) ]); | 311 [ js.string(e.name), js.number(e.holder.index), emitClass(e) ]); |
| 313 | 312 |
| 314 js.Expression staticArray = | 313 js.Expression staticArray = |
| 315 new js.ArrayInitializer(staticDescriptors.toList(growable: false)); | 314 new js.ArrayInitializer(staticDescriptors.toList(growable: false)); |
| 316 js.Expression classArray = | 315 js.Expression classArray = |
| 317 new js.ArrayInitializer(classDescriptors.toList(growable: false)); | 316 new js.ArrayInitializer(classDescriptors.toList(growable: false)); |
| 318 | 317 |
| 319 return new js.ArrayInitializer([staticArray, classArray]); | 318 return new js.ArrayInitializer([staticArray, classArray]); |
| 320 } | 319 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 List elements = [js.string(cls.superclassName), | 388 List elements = [js.string(cls.superclassName), |
| 390 js.number(cls.superclassHolderIndex)]; | 389 js.number(cls.superclassHolderIndex)]; |
| 391 | 390 |
| 392 if (cls.isMixinApplication) { | 391 if (cls.isMixinApplication) { |
| 393 MixinApplication mixin = cls; | 392 MixinApplication mixin = cls; |
| 394 elements.add(js.string(mixin.mixinClass.name)); | 393 elements.add(js.string(mixin.mixinClass.name)); |
| 395 elements.add(js.number(mixin.mixinClass.holder.index)); | 394 elements.add(js.number(mixin.mixinClass.holder.index)); |
| 396 } else { | 395 } else { |
| 397 elements.add(_generateConstructor(cls)); | 396 elements.add(_generateConstructor(cls)); |
| 398 } | 397 } |
| 399 Iterable<Method> methods = cls.methods; | 398 Iterable<Method> methods = cls.methods.expand((Method method) { |
| 399 // TODO(floitsch): can there be anything else than a DartMethod? |
| 400 if (method is DartMethod) { |
| 401 return [method]..addAll(method.parameterStubs); |
| 402 } else { |
| 403 return [method]; |
| 404 } |
| 405 }); |
| 400 Iterable<Method> isChecks = cls.isChecks; | 406 Iterable<Method> isChecks = cls.isChecks; |
| 401 Iterable<Method> gettersSetters = _generateGettersSetters(cls); | 407 Iterable<Method> gettersSetters = _generateGettersSetters(cls); |
| 402 Iterable<Method> allMethods = | 408 Iterable<Method> allMethods = |
| 403 [methods, isChecks, gettersSetters].expand((x) => x); | 409 [methods, isChecks, gettersSetters].expand((x) => x); |
| 404 elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code])); | 410 elements.addAll(allMethods.expand((e) => [js.string(e.name), e.code])); |
| 405 return unparse(compiler, new js.ArrayInitializer(elements)); | 411 return unparse(compiler, new js.ArrayInitializer(elements)); |
| 406 } | 412 } |
| 407 | 413 |
| 408 js.Expression emitLazyInitializer(StaticField field) { | 414 js.Expression emitLazyInitializer(StaticField field) { |
| 409 assert(field.isLazy); | 415 assert(field.isLazy); |
| 410 return unparse(compiler, field.code); | 416 return unparse(compiler, field.code); |
| 411 } | 417 } |
| 412 | 418 |
| 413 js.Expression emitStaticMethod(StaticMethod method) { | 419 Iterable<js.Expression> emitStaticMethod(StaticMethod method) { |
| 414 return unparse(compiler, method.code); | 420 js.Expression holderIndex = js.number(method.holder.index); |
| 421 List<js.Expression> output = <js.Expression>[]; |
| 422 |
| 423 void _addMethod(Method method) { |
| 424 js.Expression unparsed = unparse(compiler, method.code); |
| 425 output.add(js.string(method.name)); |
| 426 output.add(holderIndex); |
| 427 output.add(unparsed); |
| 428 } |
| 429 |
| 430 _addMethod(method); |
| 431 // TODO(floitsch): can there be anything else than a StaticDartMethod? |
| 432 if (method is StaticDartMethod) { |
| 433 method.parameterStubs.forEach(_addMethod); |
| 434 } |
| 435 return output; |
| 415 } | 436 } |
| 416 | 437 |
| 417 static final String boilerplate = """ | 438 static final String boilerplate = """ |
| 418 { | 439 { |
| 419 // Declare deferred-initializer global. | 440 // Declare deferred-initializer global. |
| 420 #deferredInitializer; | 441 #deferredInitializer; |
| 421 | 442 |
| 422 !function(start, program) { | 443 !function(start, program) { |
| 423 | 444 |
| 424 // Initialize holder objects. | 445 // Initialize holder objects. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 | 623 |
| 603 var end = Date.now(); | 624 var end = Date.now(); |
| 604 print('Setup: ' + (end - start) + ' ms.'); | 625 print('Setup: ' + (end - start) + ' ms.'); |
| 605 | 626 |
| 606 #main(); // Start main. | 627 #main(); // Start main. |
| 607 | 628 |
| 608 }(Date.now(), #code) | 629 }(Date.now(), #code) |
| 609 }"""; | 630 }"""; |
| 610 | 631 |
| 611 } | 632 } |
| OLD | NEW |