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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 | 115 |
116 final List<FailedUpdate> _failedUpdates = <FailedUpdate>[]; | 116 final List<FailedUpdate> _failedUpdates = <FailedUpdate>[]; |
117 | 117 |
118 final Set<ElementX> _elementsToInvalidate = new Set<ElementX>(); | 118 final Set<ElementX> _elementsToInvalidate = new Set<ElementX>(); |
119 | 119 |
120 final Set<ElementX> _removedElements = new Set<ElementX>(); | 120 final Set<ElementX> _removedElements = new Set<ElementX>(); |
121 | 121 |
122 final Set<ClassElementX> _classesWithSchemaChanges = | 122 final Set<ClassElementX> _classesWithSchemaChanges = |
123 new Set<ClassElementX>(); | 123 new Set<ClassElementX>(); |
124 | 124 |
| 125 final Set<ClassElementX> _existingClasses = new Set(); |
| 126 |
125 LibraryUpdater( | 127 LibraryUpdater( |
126 this.compiler, | 128 this.compiler, |
127 this.inputProvider, | 129 this.inputProvider, |
128 this.uri, | 130 this.uri, |
129 this.logTime, | 131 this.logTime, |
130 this.logVerbose); | 132 this.logVerbose) { |
| 133 if (compiler != null) { |
| 134 _existingClasses.addAll(emitter.neededClasses); |
| 135 } |
| 136 } |
131 | 137 |
132 /// When [true], updates must be applied (using [applyUpdates]) before the | 138 /// When [true], updates must be applied (using [applyUpdates]) before the |
133 /// [compiler]'s state correctly reflects the updated program. | 139 /// [compiler]'s state correctly reflects the updated program. |
134 bool get hasPendingUpdates => !updates.isEmpty; | 140 bool get hasPendingUpdates => !updates.isEmpty; |
135 | 141 |
136 bool get failed => !_failedUpdates.isEmpty; | 142 bool get failed => !_failedUpdates.isEmpty; |
137 | 143 |
138 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. | 144 /// Used as tear-off passed to [LibraryLoaderTask.resetAsync]. |
139 Future<bool> reuseLibrary(LibraryElement library) { | 145 Future<bool> reuseLibrary(LibraryElement library) { |
140 assert(compiler != null); | 146 assert(compiler != null); |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 removals.add(update); | 533 removals.add(update); |
528 } | 534 } |
529 } else { | 535 } else { |
530 elementsToInvalidate.add(element); | 536 elementsToInvalidate.add(element); |
531 } | 537 } |
532 } | 538 } |
533 return elementsToInvalidate; | 539 return elementsToInvalidate; |
534 } | 540 } |
535 | 541 |
536 String computeUpdateJs() { | 542 String computeUpdateJs() { |
537 Set existingClasses = | |
538 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); | |
539 | |
540 List<Update> removals = <Update>[]; | 543 List<Update> removals = <Update>[]; |
541 List<Element> updatedElements = applyUpdates(removals); | 544 List<Element> updatedElements = applyUpdates(removals); |
542 if (compiler.progress != null) { | 545 if (compiler.progress != null) { |
543 compiler.progress.reset(); | 546 compiler.progress.reset(); |
544 } | 547 } |
545 for (Element element in updatedElements) { | 548 for (Element element in updatedElements) { |
546 if (!element.isClass) { | 549 if (!element.isClass) { |
547 compiler.enqueuer.resolution.addToWorkList(element); | 550 compiler.enqueuer.resolution.addToWorkList(element); |
548 } else { | 551 } else { |
549 NO_WARN(element).ensureResolved(compiler); | 552 NO_WARN(element).ensureResolved(compiler); |
(...skipping 12 matching lines...) Expand all Loading... |
562 if (!element.isClass) { | 565 if (!element.isClass) { |
563 compiler.enqueuer.codegen.addToWorkList(element); | 566 compiler.enqueuer.codegen.addToWorkList(element); |
564 } else { | 567 } else { |
565 changedClasses.add(element); | 568 changedClasses.add(element); |
566 } | 569 } |
567 } | 570 } |
568 compiler.processQueue(compiler.enqueuer.codegen, null); | 571 compiler.processQueue(compiler.enqueuer.codegen, null); |
569 | 572 |
570 List<jsAst.Statement> updates = <jsAst.Statement>[]; | 573 List<jsAst.Statement> updates = <jsAst.Statement>[]; |
571 | 574 |
572 Set newClasses = | 575 Set newClasses = new Set.from( |
573 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); | 576 compiler.codegenWorld.allInstantiatedClasses.where( |
574 newClasses.removeAll(existingClasses); | 577 emitter.computeClassFilter())); |
| 578 newClasses.removeAll(_existingClasses); |
575 | 579 |
576 List<jsAst.Statement> inherits = <jsAst.Statement>[]; | 580 List<jsAst.Statement> inherits = <jsAst.Statement>[]; |
577 | 581 |
578 for (ClassElementX cls in newClasses) { | 582 for (ClassElementX cls in newClasses) { |
579 jsAst.Node classAccess = emitter.classAccess(cls); | 583 jsAst.Node classAccess = emitter.classAccess(cls); |
580 String name = namer.getNameOfClass(cls); | 584 String name = namer.getNameOfClass(cls); |
581 | 585 |
582 updates.add( | 586 updates.add( |
583 js.statement( | 587 js.statement( |
584 r'# = #', [classAccess, invokeDefineClass(cls)])); | 588 r'# = #', [classAccess, invokeDefineClass(cls)])); |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 List<String> computeFields(ClassElement cls) { | 1149 List<String> computeFields(ClassElement cls) { |
1146 // TODO(ahe): Rewrite for new emitter. | 1150 // TODO(ahe): Rewrite for new emitter. |
1147 ClassBuilder builder = new ClassBuilder(cls, namer); | 1151 ClassBuilder builder = new ClassBuilder(cls, namer); |
1148 classEmitter.emitFields(cls, builder, ""); | 1152 classEmitter.emitFields(cls, builder, ""); |
1149 return builder.fields; | 1153 return builder.fields; |
1150 } | 1154 } |
1151 } | 1155 } |
1152 | 1156 |
1153 // TODO(ahe): Remove this method. | 1157 // TODO(ahe): Remove this method. |
1154 NO_WARN(x) => x; | 1158 NO_WARN(x) => x; |
OLD | NEW |