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

Side by Side Diff: pkg/compiler/lib/src/kernel/env.dart

Issue 3005823002: Handle forwarding constructors to unnamed mixin applications (Closed)
Patch Set: Updated cf. comments Created 3 years, 3 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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.kernel.env; 5 library dart2js.kernel.env;
6 6
7 import 'package:kernel/ast.dart' as ir; 7 import 'package:kernel/ast.dart' as ir;
8 import 'package:kernel/clone.dart'; 8 import 'package:kernel/clone.dart';
9 import 'package:kernel/type_algebra.dart'; 9 import 'package:kernel/type_algebra.dart';
10 10
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 251 }
252 var superInitializer = new ir.SuperInitializer(superclassConstructor, 252 var superInitializer = new ir.SuperInitializer(superclassConstructor,
253 new ir.Arguments(positionalArguments, named: namedArguments)); 253 new ir.Arguments(positionalArguments, named: namedArguments));
254 254
255 // Assemble the constructor. 255 // Assemble the constructor.
256 return new ir.Constructor(function, 256 return new ir.Constructor(function,
257 name: superclassConstructor.name, 257 name: superclassConstructor.name,
258 initializers: <ir.Initializer>[superInitializer]); 258 initializers: <ir.Initializer>[superInitializer]);
259 } 259 }
260 260
261 void _ensureMaps() { 261 void _ensureMaps(KernelToElementMapBase elementMap) {
262 if (_memberMap == null) { 262 if (_memberMap == null) {
263 _memberMap = <String, ir.Member>{}; 263 _memberMap = <String, ir.Member>{};
264 _setterMap = <String, ir.Member>{}; 264 _setterMap = <String, ir.Member>{};
265 _constructorMap = <String, ir.Member>{}; 265 _constructorMap = <String, ir.Member>{};
266 266
267 void addMembers(ir.Class c, {bool includeStatic}) { 267 void addMembers(ir.Class c, {bool includeStatic}) {
268 for (ir.Member member in c.members) { 268 for (ir.Member member in c.members) {
269 if (member.name.name.contains('#')) { 269 if (member.name.name.contains('#')) {
270 // Skip synthetic .dill members. 270 // Skip synthetic .dill members.
271 continue; 271 continue;
(...skipping 23 matching lines...) Expand all
295 } 295 }
296 } 296 }
297 } 297 }
298 298
299 if (cls.mixedInClass != null) { 299 if (cls.mixedInClass != null) {
300 addMembers(cls.mixedInClass, includeStatic: false); 300 addMembers(cls.mixedInClass, includeStatic: false);
301 } 301 }
302 addMembers(cls, includeStatic: true); 302 addMembers(cls, includeStatic: true);
303 303
304 if (isUnnamedMixinApplication && _constructorMap.isEmpty) { 304 if (isUnnamedMixinApplication && _constructorMap.isEmpty) {
305 // Ensure that constructors are created for the superclass in case it
306 // is also an unnamed mixin application.
307 ClassEntity superclass = elementMap.getClass(cls.superclass);
308 elementMap.elementEnvironment.lookupConstructor(superclass, '');
309
305 // Unnamed mixin applications have no constructors when read from .dill. 310 // Unnamed mixin applications have no constructors when read from .dill.
306 // For each generative constructor in the superclass we make a 311 // For each generative constructor in the superclass we make a
307 // corresponding forwarding constructor in the subclass. 312 // corresponding forwarding constructor in the subclass.
308 // 313 //
309 // This code is copied from 314 // This code is copied from
310 // 'package:kernel/transformations/mixin_full_resolution.dart' 315 // 'package:kernel/transformations/mixin_full_resolution.dart'
311 var superclassSubstitution = getSubstitutionMap(cls.supertype); 316 var superclassSubstitution = getSubstitutionMap(cls.supertype);
312 var superclassCloner = 317 var superclassCloner =
313 new CloneVisitor(typeSubstitution: superclassSubstitution); 318 new CloneVisitor(typeSubstitution: superclassSubstitution);
319
314 for (var superclassConstructor in cls.superclass.constructors) { 320 for (var superclassConstructor in cls.superclass.constructors) {
315 var forwardingConstructor = _buildForwardingConstructor( 321 var forwardingConstructor = _buildForwardingConstructor(
316 superclassCloner, superclassConstructor); 322 superclassCloner, superclassConstructor);
317 cls.addMember(forwardingConstructor); 323 cls.addMember(forwardingConstructor);
318 _constructorMap[forwardingConstructor.name.name] = 324 _constructorMap[forwardingConstructor.name.name] =
319 forwardingConstructor; 325 forwardingConstructor;
320 } 326 }
321 } 327 }
322 } 328 }
323 } 329 }
324 330
325 /// Return the [MemberEntity] for the member [name] in [cls]. If [setter] is 331 /// Return the [MemberEntity] for the member [name] in [cls]. If [setter] is
326 /// `true`, the setter or assignable field corresponding to [name] is 332 /// `true`, the setter or assignable field corresponding to [name] is
327 /// returned. 333 /// returned.
328 MemberEntity lookupMember(KernelToElementMap elementMap, String name, 334 MemberEntity lookupMember(KernelToElementMap elementMap, String name,
329 {bool setter: false}) { 335 {bool setter: false}) {
330 _ensureMaps(); 336 _ensureMaps(elementMap);
331 ir.Member member = setter ? _setterMap[name] : _memberMap[name]; 337 ir.Member member = setter ? _setterMap[name] : _memberMap[name];
332 return member != null ? elementMap.getMember(member) : null; 338 return member != null ? elementMap.getMember(member) : null;
333 } 339 }
334 340
335 /// Calls [f] for each member of [cls]. 341 /// Calls [f] for each member of [cls].
336 void forEachMember( 342 void forEachMember(
337 KernelToElementMap elementMap, void f(MemberEntity member)) { 343 KernelToElementMap elementMap, void f(MemberEntity member)) {
338 _ensureMaps(); 344 _ensureMaps(elementMap);
339 _memberMap.values.forEach((ir.Member member) { 345 _memberMap.values.forEach((ir.Member member) {
340 f(elementMap.getMember(member)); 346 f(elementMap.getMember(member));
341 }); 347 });
342 for (ir.Member member in _setterMap.values) { 348 for (ir.Member member in _setterMap.values) {
343 if (member is ir.Procedure) { 349 if (member is ir.Procedure) {
344 f(elementMap.getMember(member)); 350 f(elementMap.getMember(member));
345 } else { 351 } else {
346 // Skip fields; these are also in _memberMap. 352 // Skip fields; these are also in _memberMap.
347 } 353 }
348 } 354 }
349 } 355 }
350 356
351 /// Return the [ConstructorEntity] for the constructor [name] in [cls]. 357 /// Return the [ConstructorEntity] for the constructor [name] in [cls].
352 ConstructorEntity lookupConstructor( 358 ConstructorEntity lookupConstructor(
353 KernelToElementMap elementMap, String name) { 359 KernelToElementMap elementMap, String name) {
354 _ensureMaps(); 360 _ensureMaps(elementMap);
355 ir.Member constructor = _constructorMap[name]; 361 ir.Member constructor = _constructorMap[name];
356 return constructor != null ? elementMap.getConstructor(constructor) : null; 362 return constructor != null ? elementMap.getConstructor(constructor) : null;
357 } 363 }
358 364
359 /// Calls [f] for each constructor of [cls]. 365 /// Calls [f] for each constructor of [cls].
360 void forEachConstructor( 366 void forEachConstructor(
361 KernelToElementMap elementMap, void f(ConstructorEntity constructor)) { 367 KernelToElementMap elementMap, void f(ConstructorEntity constructor)) {
362 _ensureMaps(); 368 _ensureMaps(elementMap);
363 _constructorMap.values.forEach((ir.Member constructor) { 369 _constructorMap.values.forEach((ir.Member constructor) {
364 f(elementMap.getConstructor(constructor)); 370 f(elementMap.getConstructor(constructor));
365 }); 371 });
366 } 372 }
367 373
368 void addConstructorBody(ConstructorBodyEntity constructorBody) { 374 void addConstructorBody(ConstructorBodyEntity constructorBody) {
369 _constructorBodyList ??= <ConstructorBodyEntity>[]; 375 _constructorBodyList ??= <ConstructorBodyEntity>[];
370 _constructorBodyList.add(constructorBody); 376 _constructorBodyList.add(constructorBody);
371 } 377 }
372 378
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 } 655 }
650 } 656 }
651 657
652 class TypedefData { 658 class TypedefData {
653 final ir.Typedef node; 659 final ir.Typedef node;
654 final TypedefEntity element; 660 final TypedefEntity element;
655 final TypedefType rawType; 661 final TypedefType rawType;
656 662
657 TypedefData(this.node, this.element, this.rawType); 663 TypedefData(this.node, this.element, this.rawType);
658 } 664 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698