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

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

Issue 752553004: dart2js: Support mixins in the new emitter. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix typo. 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
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.js_emitter.program_builder; 5 library dart2js.js_emitter.program_builder;
6 6
7 import 'js_emitter.dart' show computeMixinClass;
7 import 'model.dart'; 8 import 'model.dart';
9
8 import '../common.dart'; 10 import '../common.dart';
9 import '../js/js.dart' as js; 11 import '../js/js.dart' as js;
10 12
11 import '../js_backend/js_backend.dart' show 13 import '../js_backend/js_backend.dart' show
12 Namer, 14 Namer,
13 JavaScriptBackend, 15 JavaScriptBackend,
14 JavaScriptConstantCompiler; 16 JavaScriptConstantCompiler;
15 17
16 import '../closure.dart' show ClosureFieldElement; 18 import '../closure.dart' show ClosureFieldElement;
17 19
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 outputs.setAll(1, deferredOutputs); 73 outputs.setAll(1, deferredOutputs);
72 74
73 Program result = 75 Program result =
74 new Program(outputs, _task.outputContainsConstantList, _buildLoadMap()); 76 new Program(outputs, _task.outputContainsConstantList, _buildLoadMap());
75 77
76 // Resolve the superclass references after we've processed all the classes. 78 // Resolve the superclass references after we've processed all the classes.
77 _classes.forEach((ClassElement element, Class c) { 79 _classes.forEach((ClassElement element, Class c) {
78 if (element.superclass != null) { 80 if (element.superclass != null) {
79 c.setSuperclass(_classes[element.superclass]); 81 c.setSuperclass(_classes[element.superclass]);
80 } 82 }
83 if (element.isMixinApplication) {
84 MixinApplication mixinApplication = c;
85 mixinApplication.setMixinClass(_classes[computeMixinClass(element)]);
86 }
81 }); 87 });
82 88
83 _markEagerClasses(); 89 _markEagerClasses();
84 90
85 return result; 91 return result;
86 } 92 }
87 93
88 void _markEagerClasses() { 94 void _markEagerClasses() {
89 _markEagerInterceptorClasses(); 95 _markEagerInterceptorClasses();
90 } 96 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 237
232 List<Class> classes = elements 238 List<Class> classes = elements
233 .where((e) => e is ClassElement) 239 .where((e) => e is ClassElement)
234 .map(_buildClass) 240 .map(_buildClass)
235 .toList(growable: false); 241 .toList(growable: false);
236 242
237 return new Library(uri, statics, classes); 243 return new Library(uri, statics, classes);
238 } 244 }
239 245
240 Class _buildClass(ClassElement element) { 246 Class _buildClass(ClassElement element) {
241 bool isInstantiated =
242 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element);
243
244 List<Method> methods = []; 247 List<Method> methods = [];
245 List<InstanceField> fields = []; 248 List<InstanceField> fields = [];
246 249
247 void visitMember(ClassElement enclosing, Element member) { 250 void visitMember(ClassElement enclosing, Element member) {
248 assert(invariant(element, member.isDeclaration)); 251 assert(invariant(element, member.isDeclaration));
249 assert(invariant(element, element == enclosing)); 252 assert(invariant(element, element == enclosing));
250 253
251 if (Elements.isNonAbstractInstanceMember(member)) { 254 if (Elements.isNonAbstractInstanceMember(member)) {
252 js.Expression code = backend.generatedCode[member]; 255 js.Expression code = backend.generatedCode[member];
253 // TODO(kasperl): Figure out under which conditions code is null. 256 // TODO(kasperl): Figure out under which conditions code is null.
254 if (code != null) methods.add(_buildMethod(member, code)); 257 if (code != null) methods.add(_buildMethod(member, code));
255 } else if (member.isField && !member.isStatic) { 258 } else if (member.isField && !member.isStatic) {
256 fields.add(_buildInstanceField(member, enclosing)); 259 fields.add(_buildInstanceField(member, enclosing));
257 } 260 }
258 } 261 }
259 262
260 ClassElement implementation = element.implementation; 263 ClassElement implementation = element.implementation;
261 if (isInstantiated) { 264
265 // MixinApplications run through the members of their mixin. Here, we are
266 // only interested in direct members.
267 if (!element.isMixinApplication) {
sigurdm 2014/11/27 09:25:54 What about elements that are not instantiated for
floitsch 2014/11/27 12:35:16 The only ones that I can think of are onlyForRti a
262 implementation.forEachMember(visitMember, includeBackendMembers: true); 268 implementation.forEachMember(visitMember, includeBackendMembers: true);
263 } 269 }
264 String name = namer.getNameOfClass(element); 270 String name = namer.getNameOfClass(element);
265 String holderName = namer.globalObjectFor(element); 271 String holderName = namer.globalObjectFor(element);
266 Holder holder = _registry.registerHolder(holderName); 272 Holder holder = _registry.registerHolder(holderName);
267 bool onlyForRti = 273 bool onlyForRti =
268 _task.typeTestEmitter.rtiNeededClasses.contains(element); 274 _task.typeTestEmitter.rtiNeededClasses.contains(element);
269 Class result = new Class(name, holder, methods, fields, 275 bool isInstantiated =
270 onlyForRti: onlyForRti); 276 _compiler.codegenWorld.directlyInstantiatedClasses.contains(element);
277
278 Class result;
279 if (element.isMixinApplication) {
280 assert(methods.isEmpty);
281 assert(fields.isEmpty);
282 result = new MixinApplication(name, holder,
283 isDirectlyInstantiated: isInstantiated,
284 onlyForRti: onlyForRti);
285 } else {
286 result = new Class(name, holder, methods, fields,
287 isDirectlyInstantiated: isInstantiated,
288 onlyForRti: onlyForRti);
289 }
271 _classes[element] = result; 290 _classes[element] = result;
272 return result; 291 return result;
273 } 292 }
274 293
275 Method _buildMethod(FunctionElement element, js.Expression code) { 294 Method _buildMethod(FunctionElement element, js.Expression code) {
276 String name = namer.getNameOfInstanceMember(element); 295 String name = namer.getNameOfInstanceMember(element);
277 return new Method(name, code); 296 return new Method(name, code);
278 } 297 }
279 298
280 // The getInterceptor methods directly access the prototype of classes. 299 // The getInterceptor methods directly access the prototype of classes.
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 for (ConstantValue constantValue in constantValues) { 418 for (ConstantValue constantValue in constantValues) {
400 assert(!_constants.containsKey(constantValue)); 419 assert(!_constants.containsKey(constantValue));
401 String name = namer.constantName(constantValue); 420 String name = namer.constantName(constantValue);
402 String constantObject = namer.globalObjectForConstant(constantValue); 421 String constantObject = namer.globalObjectForConstant(constantValue);
403 Holder holder = _registry.registerHolder(constantObject); 422 Holder holder = _registry.registerHolder(constantObject);
404 Constant constant = new Constant(name, holder, constantValue); 423 Constant constant = new Constant(name, holder, constantValue);
405 _constants[constantValue] = constant; 424 _constants[constantValue] = constant;
406 }; 425 };
407 } 426 }
408 } 427 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698