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

Side by Side Diff: pkg/compiler/lib/src/js_emitter/new_emitter/model_emitter.dart

Issue 900423003: dart2js: add constructor for directly instatiated mixin classes in the new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 months 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 | « no previous file | 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.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 '../../dart_types.dart' show DartType; 8 import '../../dart_types.dart' show DartType;
9 import '../../elements/elements.dart' show ClassElement; 9 import '../../elements/elements.dart' show ClassElement;
10 import '../../js/js.dart' as js; 10 import '../../js/js.dart' as js;
(...skipping 15 matching lines...) Expand all
26 IS_HUNK_LOADED, 26 IS_HUNK_LOADED,
27 LEAF_TAGS, 27 LEAF_TAGS,
28 MANGLED_GLOBAL_NAMES, 28 MANGLED_GLOBAL_NAMES,
29 METADATA, 29 METADATA,
30 TYPE_TO_INTERCEPTOR_MAP; 30 TYPE_TO_INTERCEPTOR_MAP;
31 31
32 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode; 32 import '../js_emitter.dart' show NativeGenerator, buildTearOffCode;
33 import '../model.dart'; 33 import '../model.dart';
34 34
35 35
36
37 class ModelEmitter { 36 class ModelEmitter {
38 final Compiler compiler; 37 final Compiler compiler;
39 final Namer namer; 38 final Namer namer;
40 final ConstantEmitter constantEmitter; 39 final ConstantEmitter constantEmitter;
41 final NativeEmitter nativeEmitter; 40 final NativeEmitter nativeEmitter;
42 41
43 JavaScriptBackend get backend => compiler.backend; 42 JavaScriptBackend get backend => compiler.backend;
44 43
45 /// For deferred loading we communicate the initializers via this global var. 44 /// For deferred loading we communicate the initializers via this global var.
46 static const String deferredInitializersGlobal = 45 static const String deferredInitializersGlobal =
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 Iterable<Method> setters = cls.fields 458 Iterable<Method> setters = cls.fields
460 .where((Field field) => field.needsUncheckedSetter) 459 .where((Field field) => field.needsUncheckedSetter)
461 .map(_generateSetter); 460 .map(_generateSetter);
462 461
463 return [getters, setters].expand((x) => x); 462 return [getters, setters].expand((x) => x);
464 } 463 }
465 464
466 // This string should be referenced wherever JavaScript code makes assumptions 465 // This string should be referenced wherever JavaScript code makes assumptions
467 // on the mixin format. 466 // on the mixin format.
468 static final String mixinFormatDescription = 467 static final String mixinFormatDescription =
469 "Mixins have no constructor, but a reference to their mixin class."; 468 "Mixins have a reference to their mixin class followed by a constructor" +
floitsch 2015/02/06 12:41:19 "Mixins have a reference to their mixin class at t
floitsch 2015/02/06 12:41:20 You don't need the "+" if two string literals are
zarah 2015/02/06 14:27:09 Done.
zarah 2015/02/06 14:27:09 Done.
469 "function in the case they have been directly instatiated";
floitsch 2015/02/06 12:41:19 "instantiated.";
zarah 2015/02/06 14:27:09 Acknowledged.
470 470
471 js.Expression emitClass(Class cls) { 471 js.Expression emitClass(Class cls) {
472 List elements = [js.string(cls.superclassName), 472 List elements = [js.string(cls.superclassName),
473 js.number(cls.superclassHolderIndex)]; 473 js.number(cls.superclassHolderIndex)];
474 474
475 if (cls.isMixinApplication) { 475 if (cls.isMixinApplication) {
476 MixinApplication mixin = cls; 476 MixinApplication mixin = cls;
477 elements.add(js.string(mixin.mixinClass.name)); 477 elements.add(js.string(mixin.mixinClass.name));
478 elements.add(js.number(mixin.mixinClass.holder.index)); 478 elements.add(js.number(mixin.mixinClass.holder.index));
479 if (cls.isDirectlyInstantiated) {
480 elements.add(_generateConstructor(cls));
481 }
479 } else { 482 } else {
480 elements.add(_generateConstructor(cls)); 483 elements.add(_generateConstructor(cls));
481 } 484 }
482 Iterable<Method> methods = cls.methods; 485 Iterable<Method> methods = cls.methods;
483 Iterable<Method> isChecks = cls.isChecks; 486 Iterable<Method> isChecks = cls.isChecks;
484 Iterable<Method> callStubs = cls.callStubs; 487 Iterable<Method> callStubs = cls.callStubs;
485 Iterable<Method> noSuchMethodStubs = cls.noSuchMethodStubs; 488 Iterable<Method> noSuchMethodStubs = cls.noSuchMethodStubs;
486 Iterable<Method> gettersSetters = _generateGettersSetters(cls); 489 Iterable<Method> gettersSetters = _generateGettersSetters(cls);
487 Iterable<Method> allMethods = 490 Iterable<Method> allMethods =
488 [methods, isChecks, callStubs, noSuchMethodStubs, gettersSetters] 491 [methods, isChecks, callStubs, noSuchMethodStubs, gettersSetters]
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 } 796 }
794 797
795 #tearOff; 798 #tearOff;
796 799
797 #parseFunctionDescriptor; 800 #parseFunctionDescriptor;
798 801
799 function compileConstructor(name, descriptor) { 802 function compileConstructor(name, descriptor) {
800 descriptor = compile(name, descriptor); 803 descriptor = compile(name, descriptor);
801 var prototype = determinePrototype(descriptor); 804 var prototype = determinePrototype(descriptor);
802 var constructor; 805 var constructor;
806 var functionsIndex;
803 // $mixinFormatDescription. 807 // $mixinFormatDescription.
804 if (typeof descriptor[2] !== 'function') { 808 if (typeof descriptor[2] !== 'function') {
805 constructor = compileMixinConstructor(name, prototype, descriptor); 809 compileMixinConstructor(name, prototype, descriptor);
806 for (var i = 4; i < descriptor.length; i += 2) { 810 // The mixin application has been directly instatiated and hence it has a
floitsch 2015/02/06 12:41:20 // Descriptor[4] contains the constructor if the m
zarah 2015/02/06 14:27:09 Done.
807 parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]); 811 // construtor function.
floitsch 2015/02/06 12:41:19 constructor
zarah 2015/02/06 14:27:09 Acknowledged.
812 if (typeof descriptor[4] === 'function') {
813 constructor = descriptor[4];
814 functionsIndex = 5;
815 } else {
816 constructor = function() {};
817 functionsIndex = 4;
808 } 818 }
809 } else { 819 } else {
810 constructor = descriptor[2]; 820 constructor = descriptor[2];
811 for (var i = 3; i < descriptor.length; i += 2) { 821 functionsIndex = 3;
812 parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]);
813 }
814 } 822 }
823
824 for (var i = functionsIndex; i < descriptor.length; i += 2) {
825 parseFunctionDescriptor(prototype, descriptor[i], descriptor[i + 1]);
826 }
827
815 constructor.builtin\$cls = name; // Needed for RTI. 828 constructor.builtin\$cls = name; // Needed for RTI.
816 constructor.prototype = prototype; 829 constructor.prototype = prototype;
817 prototype[#operatorIsPrefix + name] = constructor; 830 prototype[#operatorIsPrefix + name] = constructor;
818 prototype.constructor = constructor; 831 prototype.constructor = constructor;
819 return constructor; 832 return constructor;
820 } 833 }
821 834
822 function compileMixinConstructor(name, prototype, descriptor) { 835 function compileMixinConstructor(name, prototype, descriptor) {
floitsch 2015/02/06 12:41:19 Doesn't do the constructor anymore. copyMixedInMe
floitsch 2015/02/06 12:41:19 name seems to be unused. -> remove. Maybe pass in
zarah 2015/02/06 14:27:09 Done.
zarah 2015/02/06 14:27:09 Done.
823 // $mixinFormatDescription. 836 // $mixinFormatDescription.
824 var mixinName = descriptor[2]; 837 var mixinName = descriptor[2];
825 var mixinHolderIndex = descriptor[3]; 838 var mixinHolderIndex = descriptor[3];
826 var mixin = holders[mixinHolderIndex][mixinName].ensureResolved(); 839 var mixin = holders[mixinHolderIndex][mixinName].ensureResolved();
827 var mixinPrototype = mixin.prototype; 840 var mixinPrototype = mixin.prototype;
828 841
829 // Fill the prototype with the mixin's properties. 842 // Fill the prototype with the mixin's properties.
830 var mixinProperties = Object.keys(mixinPrototype); 843 var mixinProperties = Object.keys(mixinPrototype);
831 for (var i = 0; i < mixinProperties.length; i++) { 844 for (var i = 0; i < mixinProperties.length; i++) {
832 var p = mixinProperties[i]; 845 var p = mixinProperties[i];
833 prototype[p] = mixinPrototype[p]; 846 prototype[p] = mixinPrototype[p];
834 } 847 }
835 // Since this is a mixin application the constructor will actually never
836 // be invoked. We only use its prototype for the application's subclasses.
837 var constructor = function() {};
838 return constructor;
839 } 848 }
840 849
841 function determinePrototype(descriptor) { 850 function determinePrototype(descriptor) {
842 var superclassName = descriptor[0]; 851 var superclassName = descriptor[0];
843 if (!superclassName) return { }; 852 if (!superclassName) return { };
844 853
845 // Look up the superclass constructor function in the right holder. 854 // Look up the superclass constructor function in the right holder.
846 var holderIndex = descriptor[1]; 855 var holderIndex = descriptor[1];
847 var superclass = holders[holderIndex][superclassName].ensureResolved(); 856 var superclass = holders[holderIndex][superclassName].ensureResolved();
848 857
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 915
907 var end = Date.now(); 916 var end = Date.now();
908 print('Setup: ' + (end - start) + ' ms.'); 917 print('Setup: ' + (end - start) + ' ms.');
909 918
910 #main(); // Start main. 919 #main(); // Start main.
911 920
912 }(Date.now(), #code) 921 }(Date.now(), #code)
913 }"""; 922 }""";
914 923
915 } 924 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698