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

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

Issue 736893003: Refactor superclass change. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r41891 Created 6 years 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
« no previous file with comments | « dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 Set newClasses = 474 Set newClasses =
475 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses); 475 new Set.from(compiler.codegenWorld.directlyInstantiatedClasses);
476 newClasses.removeAll(existingClasses); 476 newClasses.removeAll(existingClasses);
477 477
478 List<jsAst.Statement> inherits = <jsAst.Statement>[]; 478 List<jsAst.Statement> inherits = <jsAst.Statement>[];
479 479
480 for (ClassElementX cls in newClasses) { 480 for (ClassElementX cls in newClasses) {
481 jsAst.Node classAccess = namer.elementAccess(cls); 481 jsAst.Node classAccess = namer.elementAccess(cls);
482 String name = namer.getNameOfClass(cls); 482 String name = namer.getNameOfClass(cls);
483 483
484 var descriptor = js('Object.create(null)'); 484 updates.add(
485 485 js.statement(
486 jsAst.Statement defineClass = js.statement( 486 r'# = #', [classAccess, invokeDefineClass(cls)]));
487 r'''
488 # = (new Function(
489 "$collectedClasses", "$desc",
490 self.$dart_unsafe_eval.defineClass(#, #) +"\n;return " + #))({#: #})
491 ''',
492 [classAccess,
493 js.string(name), js.stringArray(computeFields(cls)),
494 js.string(name),
495 js.string(name), descriptor]);
496
497 updates.add(defineClass);
498 487
499 ClassElement superclass = cls.superclass; 488 ClassElement superclass = cls.superclass;
500 if (superclass != null) { 489 if (superclass != null) {
501 jsAst.Node superAccess = namer.elementAccess(superclass); 490 jsAst.Node superAccess = namer.elementAccess(superclass);
502 inherits.add( 491 inherits.add(
503 js.statement( 492 js.statement(
504 r'self.$dart_unsafe_eval.inheritFrom(#, #)', 493 r'self.$dart_unsafe_eval.inheritFrom(#, #)',
505 [classAccess, superAccess])); 494 [classAccess, superAccess]));
506 } 495 }
507 } 496 }
508 497
498 // Call inheritFrom after all classes have been created. This way we don't
499 // need to sort the classes by having superclasses defined before their
500 // subclasses.
509 updates.addAll(inherits); 501 updates.addAll(inherits);
510 502
511 for (ClassElementX cls in changedClasses) { 503 for (ClassElementX cls in changedClasses) {
512 ClassElement superclass = cls.superclass; 504 ClassElement superclass = cls.superclass;
513 if (superclass != null) { 505 jsAst.Node superAccess =
514 jsAst.Node classAccess = namer.elementAccess(cls); 506 superclass == null ? js('null') : namer.elementAccess(superclass);
515 jsAst.Node superAccess = namer.elementAccess(superclass); 507 jsAst.Node classAccess = namer.elementAccess(cls);
516 updates.add( 508 updates.add(
517 js.statement( 509 js.statement(
518 r'#.prototype.__proto__ = #.prototype', 510 r'# = self.$dart_unsafe_eval.schemaChange(#, #, #)',
519 [classAccess, superAccess])); 511 [classAccess, invokeDefineClass(cls), classAccess, superAccess]));
520 updates.add(
521 js.statement(
522 r'#.prototype.constructor = #',
523 [classAccess, classAccess]));
524 }
525 } 512 }
526 513
527 for (RemovedFunctionUpdate update in removals) { 514 for (RemovedFunctionUpdate update in removals) {
528 update.writeUpdateJsOn(updates); 515 update.writeUpdateJsOn(updates);
529 } 516 }
530 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) { 517 for (Element element in compiler.enqueuer.codegen.newlyEnqueuedElements) {
531 if (!element.isField) { 518 if (!element.isField) {
532 updates.add(computeMemberUpdateJs(element)); 519 updates.add(computeMemberUpdateJs(element));
533 } 520 }
534 } 521 }
535 522
536 if (updates.length == 1) { 523 if (updates.length == 1) {
537 return prettyPrintJs(updates.single); 524 return prettyPrintJs(updates.single);
538 } else { 525 } else {
539 return prettyPrintJs(js.statement('{#}', [updates])); 526 return prettyPrintJs(js.statement('{#}', [updates]));
540 } 527 }
541 } 528 }
542 529
530 jsAst.Expression invokeDefineClass(ClassElementX cls) {
531 String name = namer.getNameOfClass(cls);
532 var descriptor = js('Object.create(null)');
533 return js(
534 r'''
535 (new Function(
536 "$collectedClasses", "$desc",
537 self.$dart_unsafe_eval.defineClass(#, #) +"\n;return " + #))({#: #})''',
538 [js.string(name), js.stringArray(computeFields(cls)),
539 js.string(name),
540 js.string(name), descriptor]);
541 }
542
543 jsAst.Node computeMemberUpdateJs(Element element) { 543 jsAst.Node computeMemberUpdateJs(Element element) {
544 MemberInfo info = emitter.oldEmitter.containerBuilder 544 MemberInfo info = emitter.oldEmitter.containerBuilder
545 .analyzeMemberMethod(element); 545 .analyzeMemberMethod(element);
546 if (info == null) { 546 if (info == null) {
547 compiler.internalError(element, '${element.runtimeType}'); 547 compiler.internalError(element, '${element.runtimeType}');
548 } 548 }
549 String name = info.name; 549 String name = info.name;
550 jsAst.Node function = info.code; 550 jsAst.Node function = info.code;
551 List<jsAst.Statement> statements = <jsAst.Statement>[]; 551 List<jsAst.Statement> statements = <jsAst.Statement>[];
552 if (element.isInstanceMember) { 552 if (element.isInstanceMember) {
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 1010
1011 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter; 1011 ClassEmitter get classEmitter => backend.emitter.oldEmitter.classEmitter;
1012 1012
1013 List<String> computeFields(ClassElement cls) { 1013 List<String> computeFields(ClassElement cls) {
1014 // TODO(ahe): Rewrite for new emitter. 1014 // TODO(ahe): Rewrite for new emitter.
1015 ClassBuilder builder = new ClassBuilder(cls, namer); 1015 ClassBuilder builder = new ClassBuilder(cls, namer);
1016 classEmitter.emitFields(cls, builder, ""); 1016 classEmitter.emitFields(cls, builder, "");
1017 return builder.fields; 1017 return builder.fields;
1018 } 1018 }
1019 } 1019 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/js_emitter/old_emitter/emitter.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698