Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Side by Side Diff: dart/pkg/dart2js_incremental/lib/library_updater.dart

Issue 750653002: Checked mode fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 import 'package:compiler/src/util/util.dart' show 62 import 'package:compiler/src/util/util.dart' show
63 Link, 63 Link,
64 LinkBuilder; 64 LinkBuilder;
65 65
66 import 'package:compiler/src/elements/modelx.dart' show 66 import 'package:compiler/src/elements/modelx.dart' show
67 ClassElementX, 67 ClassElementX,
68 CompilationUnitElementX, 68 CompilationUnitElementX,
69 DeclarationSite, 69 DeclarationSite,
70 ElementX, 70 ElementX,
71 FieldElementX,
71 LibraryElementX; 72 LibraryElementX;
72 73
73 import 'diff.dart' show 74 import 'diff.dart' show
74 Difference, 75 Difference,
75 computeDifference; 76 computeDifference;
76 77
77 typedef void Logger(message); 78 typedef void Logger(message);
78 79
79 typedef bool Reuser( 80 typedef bool Reuser(
80 Token diffToken, 81 Token diffToken,
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 element.ensureResolved(compiler); 504 element.ensureResolved(compiler);
504 } 505 }
505 } 506 }
506 compiler.processQueue(compiler.enqueuer.resolution, null); 507 compiler.processQueue(compiler.enqueuer.resolution, null);
507 508
508 compiler.phase = Compiler.PHASE_DONE_RESOLVING; 509 compiler.phase = Compiler.PHASE_DONE_RESOLVING;
509 510
510 // TODO(ahe): Clean this up. Don't call this method in analyze-only mode. 511 // TODO(ahe): Clean this up. Don't call this method in analyze-only mode.
511 if (compiler.analyzeOnly) return "/* analyze only */"; 512 if (compiler.analyzeOnly) return "/* analyze only */";
512 513
513 Set<PartialClassElement> changedClasses = 514 Set<ClassElementX> changedClasses =
514 new Set<PartialClassElement>.from(_classesWithSchemaChanges); 515 new Set<ClassElementX>.from(_classesWithSchemaChanges);
515 for (Element element in updatedElements) { 516 for (Element element in updatedElements) {
516 if (!element.isClass) { 517 if (!element.isClass) {
517 compiler.enqueuer.codegen.addToWorkList(element); 518 compiler.enqueuer.codegen.addToWorkList(element);
518 } else { 519 } else {
519 changedClasses.add(element); 520 changedClasses.add(element);
520 } 521 }
521 } 522 }
522 compiler.processQueue(compiler.enqueuer.codegen, null); 523 compiler.processQueue(compiler.enqueuer.codegen, null);
523 524
524 List<jsAst.Statement> updates = <jsAst.Statement>[]; 525 List<jsAst.Statement> updates = <jsAst.Statement>[];
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 ClassElement superclass = cls.superclass; 557 ClassElement superclass = cls.superclass;
557 jsAst.Node superAccess = 558 jsAst.Node superAccess =
558 superclass == null ? js('null') : namer.elementAccess(superclass); 559 superclass == null ? js('null') : namer.elementAccess(superclass);
559 jsAst.Node classAccess = namer.elementAccess(cls); 560 jsAst.Node classAccess = namer.elementAccess(cls);
560 updates.add( 561 updates.add(
561 js.statement( 562 js.statement(
562 r'# = self.$dart_unsafe_eval.schemaChange(#, #, #)', 563 r'# = self.$dart_unsafe_eval.schemaChange(#, #, #)',
563 [classAccess, invokeDefineClass(cls), classAccess, superAccess])); 564 [classAccess, invokeDefineClass(cls), classAccess, superAccess]));
564 } 565 }
565 566
566 for (RemovedFunctionUpdate update in removals) { 567 for (RemovalUpdate update in removals) {
567 update.writeUpdateJsOn(updates); 568 update.writeUpdateJsOn(updates);
568 } 569 }
569 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 570 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
570 if (!element.isField) { 571 if (!element.isField) {
571 updates.add(computeMemberUpdateJs(element)); 572 updates.add(computeMemberUpdateJs(element));
572 } 573 }
573 } 574 }
574 575
575 if (updates.length == 1) { 576 if (updates.length == 1) {
576 return prettyPrintJs(updates.single); 577 return prettyPrintJs(updates.single);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 : super(compiler); 719 : super(compiler);
719 720
720 bool get isRemoval => true; 721 bool get isRemoval => true;
721 722
722 void writeUpdateJsOn(List<jsAst.Statement> updates); 723 void writeUpdateJsOn(List<jsAst.Statement> updates);
723 724
724 void removeFromEnclosing() { 725 void removeFromEnclosing() {
725 // TODO(ahe): Need to recompute duplicated elements logic again. Simplest 726 // TODO(ahe): Need to recompute duplicated elements logic again. Simplest
726 // solution is probably to remove all elements from enclosing scope and add 727 // solution is probably to remove all elements from enclosing scope and add
727 // them back. 728 // them back.
728 PartialClassElement cls = element.enclosingClass; 729 if (element.isTopLevel) {
729 if (cls == null) {
730 removeFromLibrary(element.library); 730 removeFromLibrary(element.library);
731 } else { 731 } else {
732 removeFromEnclosingClass(cls); 732 removeFromEnclosingClass(element.enclosingClass);
733 } 733 }
734 } 734 }
735 735
736 void removeFromEnclosingClass(PartialClassElement cls) { 736 void removeFromEnclosingClass(PartialClassElement cls) {
737 cls.localMembersCache = null; 737 cls.localMembersCache = null;
738 cls.localMembersReversed = 738 cls.localMembersReversed = cls.localMembersReversed.copyWithout(element);
739 copyLinkWithout(element, cls.localMembersReversed);
740 cls.localScope.contents.remove(element.name); 739 cls.localScope.contents.remove(element.name);
741 } 740 }
742 741
743 void removeFromLibrary(LibraryElementX library) { 742 void removeFromLibrary(LibraryElementX library) {
744 library.localMembers = copyLinkWithout(element, library.localMembers); 743 library.localMembers = library.localMembers.copyWithout(element);
745 library.localScope.contents.remove(element.name); 744 library.localScope.contents.remove(element.name);
746 } 745 }
747
748 Link copyLinkWithout(e, Link link) {
749 // TODO(ahe): Consider adding to [Link].
750 LinkBuilder copy = new LinkBuilder();
751
752 for (; !link.isEmpty; link = link.tail) {
753 if (link.head != e) {
754 copy.addLast(e);
755 }
756 }
757
758 return copy.toLink(link);
759 }
760 } 746 }
761 747
762 class RemovedFunctionUpdate extends RemovalUpdate 748 class RemovedFunctionUpdate extends RemovalUpdate
763 with JsFeatures, ReuseFunction { 749 with JsFeatures, ReuseFunction {
764 final PartialFunctionElement element; 750 final PartialFunctionElement element;
765 751
766 /// Name of property to remove using JavaScript "delete". Null for 752 /// Name of property to remove using JavaScript "delete". Null for
767 /// non-instance methods. 753 /// non-instance methods.
768 String name; 754 String name;
769 755
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 } 843 }
858 844
859 PartialClassElement apply() { 845 PartialClassElement apply() {
860 if (!wasStateCaptured) { 846 if (!wasStateCaptured) {
861 throw new StateError("captureState must be called before apply."); 847 throw new StateError("captureState must be called before apply.");
862 } 848 }
863 849
864 removeFromEnclosing(); 850 removeFromEnclosing();
865 851
866 element.forEachLocalMember((ElementX member) { 852 element.forEachLocalMember((ElementX member) {
867 compiler.forgetElement(before); 853 compiler.forgetElement(member);
868 member.reuseElement(); 854 member.reuseElement();
869 }); 855 });
870 856
871 compiler.forgetElement(element); 857 compiler.forgetElement(element);
872 element.reuseElement(); 858 element.reuseElement();
873 859
874 return null; 860 return null;
875 } 861 }
876 862
877 void writeUpdateJsOn(List<jsAst.Statement> updates) { 863 void writeUpdateJsOn(List<jsAst.Statement> updates) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 942
957 943
958 class ClassUpdate extends Update with JsFeatures { 944 class ClassUpdate extends Update with JsFeatures {
959 final PartialClassElement before; 945 final PartialClassElement before;
960 946
961 final PartialClassElement after; 947 final PartialClassElement after;
962 948
963 ClassUpdate(Compiler compiler, this.before, this.after) 949 ClassUpdate(Compiler compiler, this.before, this.after)
964 : super(compiler); 950 : super(compiler);
965 951
966 PartialFunctionElement apply() { 952 PartialClassElement apply() {
967 patchElement(); 953 patchElement();
968 reuseElement(); 954 reuseElement();
969 return before; 955 return before;
970 } 956 }
971 957
972 /// Destructively change the tokens in [before] to match those of [after]. 958 /// Destructively change the tokens in [before] to match those of [after].
973 void patchElement() { 959 void patchElement() {
974 before.cachedNode = after.cachedNode; 960 before.cachedNode = after.cachedNode;
975 before.beginToken = after.beginToken; 961 before.beginToken = after.beginToken;
976 before.endToken = after.endToken; 962 before.endToken = after.endToken;
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 1068
1083 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter; 1069 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter;
1084 1070
1085 List<String> computeFields(ClassElement cls) { 1071 List<String> computeFields(ClassElement cls) {
1086 // TODO(ahe): Rewrite for new emitter. 1072 // TODO(ahe): Rewrite for new emitter.
1087 ClassBuilder builder = new ClassBuilder(cls, namer); 1073 ClassBuilder builder = new ClassBuilder(cls, namer);
1088 classEmitter.emitFields(cls, builder, ""); 1074 classEmitter.emitFields(cls, builder, "");
1089 return builder.fields; 1075 return builder.fields;
1090 } 1076 }
1091 } 1077 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698