| 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_incremental.library_updater; | 5 library dart2js_incremental.library_updater; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 Future; | 8 Future; |
| 9 | 9 |
| 10 import 'dart:convert' show | 10 import 'dart:convert' show |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 ClassNode, | 37 ClassNode, |
| 38 FunctionExpression, | 38 FunctionExpression, |
| 39 NodeList; | 39 NodeList; |
| 40 | 40 |
| 41 import 'package:compiler/src/js/js.dart' show | 41 import 'package:compiler/src/js/js.dart' show |
| 42 js; | 42 js; |
| 43 | 43 |
| 44 import 'package:compiler/src/js/js.dart' as jsAst; | 44 import 'package:compiler/src/js/js.dart' as jsAst; |
| 45 | 45 |
| 46 import 'package:compiler/src/js_emitter/js_emitter.dart' show | 46 import 'package:compiler/src/js_emitter/js_emitter.dart' show |
| 47 ClassBuilder, |
| 48 ClassEmitter, |
| 47 CodeEmitterTask, | 49 CodeEmitterTask, |
| 48 MemberInfo; | 50 MemberInfo, |
| 51 computeMixinClass; |
| 49 | 52 |
| 50 import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' | 53 import 'package:_internal/compiler/js_lib/shared/embedded_names.dart' |
| 51 as embeddedNames; | 54 as embeddedNames; |
| 52 | 55 |
| 53 import 'package:compiler/src/js_backend/js_backend.dart' show | 56 import 'package:compiler/src/js_backend/js_backend.dart' show |
| 54 JavaScriptBackend, | 57 JavaScriptBackend, |
| 55 Namer; | 58 Namer; |
| 56 | 59 |
| 57 import 'package:compiler/src/util/util.dart' show | 60 import 'package:compiler/src/util/util.dart' show |
| 58 Link, | 61 Link, |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 compiler.enqueuer.codegen.addToWorkList(element); | 406 compiler.enqueuer.codegen.addToWorkList(element); |
| 404 } | 407 } |
| 405 compiler.processQueue(compiler.enqueuer.codegen, null); | 408 compiler.processQueue(compiler.enqueuer.codegen, null); |
| 406 | 409 |
| 407 List<jsAst.Statement> updates = <jsAst.Statement>[]; | 410 List<jsAst.Statement> updates = <jsAst.Statement>[]; |
| 408 | 411 |
| 409 Set newClasses = | 412 Set newClasses = |
| 410 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); | 413 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); |
| 411 newClasses.removeAll(existingClasses); | 414 newClasses.removeAll(existingClasses); |
| 412 | 415 |
| 416 List<jsAst.Statement> inherits = <jsAst.Statement>[]; |
| 417 |
| 413 for (ClassElementX cls in newClasses) { | 418 for (ClassElementX cls in newClasses) { |
| 414 jsAst.Node access = namer.elementAccess(cls); | 419 jsAst.Node classAccess = namer.elementAccess(cls); |
| 415 String name = namer.getNameOfClass(cls); | 420 String name = namer.getNameOfClass(cls); |
| 416 | 421 |
| 417 // TODO(ahe): Compute arguments. | 422 var descriptor = js('Object.create(null)'); |
| 418 List<jsAst.Node> arguments = <jsAst.Node>[]; | |
| 419 | 423 |
| 420 // TODO(ahe): Compute statements, that is initializers. | 424 jsAst.Statement defineClass = js.statement( |
| 421 List<jsAst.Statement> statements = <jsAst.Statement>[]; | 425 r''' |
| 426 # = (new Function( |
| 427 "$collectedClasses", "$desc", |
| 428 self.$dart_unsafe_eval.defineClass(#, #) +"\n;return " + #))({#: #}) |
| 429 ''', |
| 430 [classAccess, |
| 431 js.string(name), js.stringArray(computeFields(cls)), |
| 432 js.string(name), |
| 433 js.string(name), descriptor]); |
| 422 | 434 |
| 423 updates.add( | 435 updates.add(defineClass); |
| 424 js.statement( | 436 |
| 425 '# = function $name(#) {#}', [access, arguments, statements])); | 437 ClassElement superclass = cls.superclass; |
| 438 if (superclass != null) { |
| 439 jsAst.Node superAccess = namer.elementAccess(superclass); |
| 440 inherits.add( |
| 441 js.statement( |
| 442 r'self.$dart_unsafe_eval.inheritFrom(#, #)', |
| 443 [classAccess, superAccess])); |
| 444 } |
| 426 } | 445 } |
| 427 | 446 |
| 428 for (ClassElementX cls in newClasses) { | 447 updates.addAll(inherits); |
| 429 if (cls.isObject) continue; | |
| 430 jsAst.Node classAccess = namer.elementAccess(cls); | |
| 431 jsAst.Node superAccess = namer.elementAccess(cls.superclass); | |
| 432 | |
| 433 updates.add( | |
| 434 js.statement( | |
| 435 r'self.$dart_unsafe_eval.inheritFrom(#, #)', | |
| 436 [classAccess, superAccess])); | |
| 437 } | |
| 438 | 448 |
| 439 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { | 449 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { |
| 440 if (!element.isField) { | 450 if (!element.isField) { |
| 441 updates.add(computeMemberUpdateJs(element)); | 451 updates.add(computeMemberUpdateJs(element)); |
| 442 } | 452 } |
| 443 } | 453 } |
| 444 for (RemovedFunctionUpdate update in removals) { | 454 for (RemovedFunctionUpdate update in removals) { |
| 445 update.writeUpdateJsOn(updates); | 455 update.writeUpdateJsOn(updates); |
| 446 } | 456 } |
| 447 | 457 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 printer.blockOutWithoutBraces(node); | 509 printer.blockOutWithoutBraces(node); |
| 500 return printer.outBuffer.getText(); | 510 return printer.outBuffer.getText(); |
| 501 } | 511 } |
| 502 | 512 |
| 503 String callNameFor(FunctionElement element) { | 513 String callNameFor(FunctionElement element) { |
| 504 // TODO(ahe): Call a method in the compiler to obtain this name. | 514 // TODO(ahe): Call a method in the compiler to obtain this name. |
| 505 String callPrefix = namer.callPrefix; | 515 String callPrefix = namer.callPrefix; |
| 506 int parameterCount = element.functionSignature.parameterCount; | 516 int parameterCount = element.functionSignature.parameterCount; |
| 507 return '$callPrefix\$$parameterCount'; | 517 return '$callPrefix\$$parameterCount'; |
| 508 } | 518 } |
| 519 |
| 520 List<String> computeFields(ClassElement cls) { |
| 521 return new EmitterHelper(compiler).computeFields(cls); |
| 522 } |
| 509 } | 523 } |
| 510 | 524 |
| 511 /// Represents an update (aka patch) of [before] to [after]. We use the word | 525 /// Represents an update (aka patch) of [before] to [after]. We use the word |
| 512 /// "update" to avoid confusion with the compiler feature of "patch" methods. | 526 /// "update" to avoid confusion with the compiler feature of "patch" methods. |
| 513 abstract class Update { | 527 abstract class Update { |
| 514 final Compiler compiler; | 528 final Compiler compiler; |
| 515 | 529 |
| 516 PartialElement get before; | 530 PartialElement get before; |
| 517 | 531 |
| 518 PartialElement get after; | 532 PartialElement get after; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 | 761 |
| 748 abstract class JsFeatures { | 762 abstract class JsFeatures { |
| 749 Compiler get compiler; | 763 Compiler get compiler; |
| 750 | 764 |
| 751 JavaScriptBackend get backend => compiler.backend; | 765 JavaScriptBackend get backend => compiler.backend; |
| 752 | 766 |
| 753 Namer get namer => backend.namer; | 767 Namer get namer => backend.namer; |
| 754 | 768 |
| 755 CodeEmitterTask get emitter => backend.emitter; | 769 CodeEmitterTask get emitter => backend.emitter; |
| 756 } | 770 } |
| 771 |
| 772 class EmitterHelper extends JsFeatures { |
| 773 final Compiler compiler; |
| 774 |
| 775 EmitterHelper(this.compiler); |
| 776 |
| 777 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter; |
| 778 |
| 779 List<String> computeFields(ClassElement cls) { |
| 780 // TODO(ahe): Rewrite for new emitter. |
| 781 ClassBuilder builder = new ClassBuilder(cls, namer); |
| 782 classEmitter.emitFields(cls, builder, ""); |
| 783 return builder.fields; |
| 784 } |
| 785 } |
| OLD | NEW |