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

Side by Side Diff: pkg/compiler/lib/src/resolution/class_members.dart

Issue 2000663002: Handle resolvedAst for forwarding constructors and callType on unnamed mixin applications. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Fix test. Created 4 years, 7 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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.resolution.compute_members; 5 library dart2js.resolution.compute_members;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/names.dart' show Identifiers, Names; 8 import '../common/names.dart' show Identifiers, Names;
9 import '../common/resolution.dart' show Resolution; 9 import '../common/resolution.dart' show Resolution;
10 import '../compiler.dart' show Compiler; 10 import '../compiler.dart' show Compiler;
11 import '../dart_types.dart'; 11 import '../dart_types.dart';
12 import '../elements/elements.dart' 12 import '../elements/elements.dart'
13 show 13 show
14 ClassElement, 14 ClassElement,
15 Element, 15 Element,
16 LibraryElement, 16 LibraryElement,
17 Member, 17 Member,
18 MemberElement, 18 MemberElement,
19 MemberSignature, 19 MemberSignature,
20 MixinApplicationElement, 20 MixinApplicationElement,
21 Name; 21 Name;
22 import '../util/util.dart'; 22 import '../util/util.dart';
23 23
24 part 'member_impl.dart'; 24 part 'member_impl.dart';
25 25
26 abstract class MembersCreator { 26 abstract class MembersCreator {
27 final ClassElement cls; 27 final ClassElement cls;
28 final Compiler compiler; 28 final Resolution resolution;
29 29
30 final Iterable<String> computedMemberNames; 30 final Iterable<String> computedMemberNames;
31 final Map<Name, Member> classMembers; 31 final Map<Name, Member> classMembers;
32 32
33 Map<dynamic /* Member | Element */, Set<MessageKind>> reportedMessages = 33 Map<dynamic /* Member | Element */, Set<MessageKind>> reportedMessages =
34 new Map<dynamic, Set<MessageKind>>(); 34 new Map<dynamic, Set<MessageKind>>();
35 35
36 MembersCreator( 36 MembersCreator(
37 Compiler this.compiler, 37 this.resolution, this.cls, this.computedMemberNames, this.classMembers) {
38 ClassElement this.cls,
39 Iterable<String> this.computedMemberNames,
40 Map<Name, Member> this.classMembers) {
41 assert(invariant(cls, cls.isDeclaration, 38 assert(invariant(cls, cls.isDeclaration,
42 message: "Members may only be computed on declarations.")); 39 message: "Members may only be computed on declarations."));
43 } 40 }
44 41
45 DiagnosticReporter get reporter => compiler.reporter; 42 DiagnosticReporter get reporter => resolution.reporter;
46
47 Resolution get resolution => compiler.resolution;
48 43
49 void reportMessage(var marker, MessageKind kind, report()) { 44 void reportMessage(var marker, MessageKind kind, report()) {
50 Set<MessageKind> messages = 45 Set<MessageKind> messages =
51 reportedMessages.putIfAbsent(marker, () => new Set<MessageKind>()); 46 reportedMessages.putIfAbsent(marker, () => new Set<MessageKind>());
52 if (messages.add(kind)) { 47 if (messages.add(kind)) {
53 report(); 48 report();
54 } 49 }
55 } 50 }
56 51
57 bool shouldSkipMember(MemberSignature member) { 52 bool shouldSkipMember(MemberSignature member) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Inherit class and interface members from superclass. 106 // Inherit class and interface members from superclass.
112 void inheritClassMember(DeclaredMember member) { 107 void inheritClassMember(DeclaredMember member) {
113 if (shouldSkipMember(member)) return; 108 if (shouldSkipMember(member)) return;
114 if (!member.isStatic) { 109 if (!member.isStatic) {
115 DeclaredMember inherited = member.inheritFrom(supertype); 110 DeclaredMember inherited = member.inheritFrom(supertype);
116 classMembers[member.name] = inherited; 111 classMembers[member.name] = inherited;
117 } 112 }
118 } 113 }
119 114
120 if (names != null) { 115 if (names != null) {
121 _computeClassMember(compiler, superclass, name, names); 116 _computeClassMember(resolution, superclass, name, names);
122 for (Name memberName in names) { 117 for (Name memberName in names) {
123 inheritClassMember(superclass.lookupClassMember(memberName)); 118 inheritClassMember(superclass.lookupClassMember(memberName));
124 } 119 }
125 } else { 120 } else {
126 computeAllClassMembers(compiler, superclass); 121 computeAllClassMembers(resolution, superclass);
127 superclass.forEachClassMember(inheritClassMember); 122 superclass.forEachClassMember(inheritClassMember);
128 } 123 }
129 } 124 }
130 125
131 /// Compute the members declared or directly mixed in [cls]. 126 /// Compute the members declared or directly mixed in [cls].
132 /// 127 ///
133 /// If [name] and [names] are not null, the computation is restricted to 128 /// If [name] and [names] are not null, the computation is restricted to
134 /// members with these names. 129 /// members with these names.
135 Map<Name, Member> computeClassMembers(String nameText, Setlet<Name> names) { 130 Map<Name, Member> computeClassMembers(String nameText, Setlet<Name> names) {
136 Map<Name, Member> declaredMembers = new Map<Name, Member>(); 131 Map<Name, Member> declaredMembers = new Map<Name, Member>();
(...skipping 11 matching lines...) Expand all
148 DeclaredMember mixedInMember = 143 DeclaredMember mixedInMember =
149 member.inheritFrom(mixinApplication.mixinType); 144 member.inheritFrom(mixinApplication.mixinType);
150 DeclaredMember inherited = classMembers[name]; 145 DeclaredMember inherited = classMembers[name];
151 classMembers[name] = mixedInMember; 146 classMembers[name] = mixedInMember;
152 checkValidOverride(mixedInMember, inherited); 147 checkValidOverride(mixedInMember, inherited);
153 } 148 }
154 } 149 }
155 150
156 if (names != null) { 151 if (names != null) {
157 _computeClassMember( 152 _computeClassMember(
158 compiler, mixinApplication.mixin, nameText, names); 153 resolution, mixinApplication.mixin, nameText, names);
159 for (Name memberName in names) { 154 for (Name memberName in names) {
160 inheritMixinMember( 155 inheritMixinMember(
161 mixinApplication.mixin.lookupClassMember(memberName)); 156 mixinApplication.mixin.lookupClassMember(memberName));
162 } 157 }
163 } else { 158 } else {
164 computeAllClassMembers(compiler, mixinApplication.mixin); 159 computeAllClassMembers(resolution, mixinApplication.mixin);
165 mixinApplication.mixin.forEachClassMember(inheritMixinMember); 160 mixinApplication.mixin.forEachClassMember(inheritMixinMember);
166 } 161 }
167 } 162 }
168 } else { 163 } else {
169 LibraryElement library = cls.library; 164 LibraryElement library = cls.library;
170 InterfaceType thisType = cls.thisType; 165 InterfaceType thisType = cls.thisType;
171 166
172 void createMember(MemberElement element) { 167 void createMember(MemberElement element) {
173 if (element.isConstructor) return; 168 if (element.isConstructor) return;
174 String elementName = element.name; 169 String elementName = element.name;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 302 }
308 // TODO(johnniwinther): If [cls] is not abstract, check that for all 303 // TODO(johnniwinther): If [cls] is not abstract, check that for all
309 // interface members, there is a class member whose type is a subtype of 304 // interface members, there is a class member whose type is a subtype of
310 // the interface member. 305 // the interface member.
311 } 306 }
312 307
313 /// Checks that [cls], if it implements Function, has defined call(). 308 /// Checks that [cls], if it implements Function, has defined call().
314 void checkImplementsFunctionWithCall() { 309 void checkImplementsFunctionWithCall() {
315 assert(!cls.isAbstract); 310 assert(!cls.isAbstract);
316 311
317 ClassElement functionClass = compiler.coreClasses.functionClass; 312 ClassElement functionClass = resolution.coreClasses.functionClass;
318 if (cls.asInstanceOf(functionClass) == null) return; 313 if (cls.asInstanceOf(functionClass) == null) return;
319 if (cls.lookupMember(Identifiers.call) != null) return; 314 if (cls.lookupMember(Identifiers.call) != null) return;
320 // TODO(johnniwinther): Make separate methods for backend exceptions. 315 // TODO(johnniwinther): Make separate methods for backend exceptions.
321 // Avoid warnings on backend implementation classes for closures. 316 // Avoid warnings on backend implementation classes for closures.
322 if (compiler.backend.isBackendLibrary(cls.library)) return; 317 if (resolution.target.isTargetSpecificLibrary(cls.library)) return;
323 318
324 reportMessage(functionClass, MessageKind.UNIMPLEMENTED_METHOD, () { 319 reportMessage(functionClass, MessageKind.UNIMPLEMENTED_METHOD, () {
325 reporter.reportWarningMessage(cls, MessageKind.UNIMPLEMENTED_METHOD_ONE, { 320 reporter.reportWarningMessage(cls, MessageKind.UNIMPLEMENTED_METHOD_ONE, {
326 'class': cls.name, 321 'class': cls.name,
327 'name': Identifiers.call, 322 'name': Identifiers.call,
328 'method': Identifiers.call, 323 'method': Identifiers.call,
329 'declarer': functionClass.name 324 'declarer': functionClass.name
330 }); 325 });
331 }); 326 });
332 } 327 }
(...skipping 28 matching lines...) Expand all
361 superclass = superclass.superclass; 356 superclass = superclass.superclass;
362 } 357 }
363 } 358 }
364 } else { 359 } else {
365 assert(declared.name == superMember.name); 360 assert(declared.name == superMember.name);
366 361
367 if (declared.isStatic) { 362 if (declared.isStatic) {
368 for (Member inherited in superMember.declarations) { 363 for (Member inherited in superMember.declarations) {
369 if (cls == inherited.declarer.element) { 364 if (cls == inherited.declarer.element) {
370 // An error should already have been reported. 365 // An error should already have been reported.
371 assert(invariant(declared.element, compiler.compilationFailed)); 366 assert(invariant(
367 declared.element, resolution.reporter.hasReportedError));
372 continue; 368 continue;
373 } 369 }
374 370
375 reportMessage(inherited.element, MessageKind.NO_STATIC_OVERRIDE, () { 371 reportMessage(inherited.element, MessageKind.NO_STATIC_OVERRIDE, () {
376 reportErrorWithContext( 372 reportErrorWithContext(
377 declared.element, 373 declared.element,
378 MessageKind.NO_STATIC_OVERRIDE, 374 MessageKind.NO_STATIC_OVERRIDE,
379 inherited.element, 375 inherited.element,
380 MessageKind.NO_STATIC_OVERRIDE_CONT); 376 MessageKind.NO_STATIC_OVERRIDE_CONT);
381 }); 377 });
382 } 378 }
383 } 379 }
384 380
385 DartType declaredType = declared.functionType; 381 DartType declaredType = declared.functionType;
386 for (Member inherited in superMember.declarations) { 382 for (Member inherited in superMember.declarations) {
387 if (inherited.element == declared.element) { 383 if (inherited.element == declared.element) {
388 // TODO(ahe): For some reason, "call" elements are repeated in 384 // TODO(ahe): For some reason, "call" elements are repeated in
389 // superMember.declarations. Investigate why. 385 // superMember.declarations. Investigate why.
390 } else if (cls == inherited.declarer.element) { 386 } else if (cls == inherited.declarer.element) {
391 // An error should already have been reported. 387 // An error should already have been reported.
392 assert(invariant(declared.element, compiler.compilationFailed, 388 assert(
393 message: "Member $inherited inherited from its " 389 invariant(declared.element, resolution.reporter.hasReportedError,
394 "declaring class: ${cls}.")); 390 message: "Member $inherited inherited from its "
391 "declaring class: ${cls}."));
395 continue; 392 continue;
396 } 393 }
397 394
398 void reportError(MessageKind errorKind, MessageKind infoKind) { 395 void reportError(MessageKind errorKind, MessageKind infoKind) {
399 reportMessage(inherited.element, MessageKind.INVALID_OVERRIDE_METHOD, 396 reportMessage(inherited.element, MessageKind.INVALID_OVERRIDE_METHOD,
400 () { 397 () {
401 reporter.reportError( 398 reporter.reportError(
402 reporter.createMessage(declared.element, errorKind, { 399 reporter.createMessage(declared.element, errorKind, {
403 'name': declared.name.text, 400 'name': declared.name.text,
404 'class': cls.thisType, 401 'class': cls.thisType,
(...skipping 15 matching lines...) Expand all
420 reportError(MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD, 417 reportError(MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD,
421 MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT); 418 MessageKind.CANNOT_OVERRIDE_FIELD_WITH_METHOD_CONT);
422 } else if (declared.isGetter && inherited.isMethod) { 419 } else if (declared.isGetter && inherited.isMethod) {
423 reportError(MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER, 420 reportError(MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER,
424 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT); 421 MessageKind.CANNOT_OVERRIDE_METHOD_WITH_GETTER_CONT);
425 } else if (declared.isMethod && inherited.isGetter) { 422 } else if (declared.isMethod && inherited.isGetter) {
426 reportError(MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD, 423 reportError(MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD,
427 MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT); 424 MessageKind.CANNOT_OVERRIDE_GETTER_WITH_METHOD_CONT);
428 } else { 425 } else {
429 DartType inheritedType = inherited.functionType; 426 DartType inheritedType = inherited.functionType;
430 if (!compiler.types.isSubtype(declaredType, inheritedType)) { 427 if (!resolution.types.isSubtype(declaredType, inheritedType)) {
431 void reportWarning( 428 void reportWarning(
432 var marker, MessageKind warningKind, MessageKind infoKind) { 429 var marker, MessageKind warningKind, MessageKind infoKind) {
433 reportMessage(marker, MessageKind.INVALID_OVERRIDE_METHOD, () { 430 reportMessage(marker, MessageKind.INVALID_OVERRIDE_METHOD, () {
434 reporter.reportWarning( 431 reporter.reportWarning(
435 reporter.createMessage(declared.element, warningKind, { 432 reporter.createMessage(declared.element, warningKind, {
436 'declaredType': declared.type, 433 'declaredType': declared.type,
437 'name': declared.name.text, 434 'name': declared.name.text,
438 'class': cls.thisType, 435 'class': cls.thisType,
439 'inheritedType': inherited.type, 436 'inheritedType': inherited.type,
440 'inheritedClass': inherited.declarer 437 'inheritedClass': inherited.declarer
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 'memberName': contextElement.name, 501 'memberName': contextElement.name,
505 'className': contextElement.enclosingClass.name 502 'className': contextElement.enclosingClass.name
506 }), 503 }),
507 <DiagnosticMessage>[ 504 <DiagnosticMessage>[
508 reporter.createMessage(contextElement, contextMessage), 505 reporter.createMessage(contextElement, contextMessage),
509 ]); 506 ]);
510 } 507 }
511 508
512 /// Compute all class and interface names by the [name] in [cls]. 509 /// Compute all class and interface names by the [name] in [cls].
513 static void computeClassMembersByName( 510 static void computeClassMembersByName(
514 Compiler compiler, ClassMemberMixin cls, String name) { 511 Resolution resolution, ClassMemberMixin cls, String name) {
515 if (cls.isMemberComputed(name)) return; 512 if (cls.isMemberComputed(name)) return;
516 LibraryElement library = cls.library; 513 LibraryElement library = cls.library;
517 _computeClassMember( 514 _computeClassMember(
518 compiler, 515 resolution,
519 cls, 516 cls,
520 name, 517 name,
521 new Setlet<Name>() 518 new Setlet<Name>()
522 ..add(new Name(name, library)) 519 ..add(new Name(name, library))
523 ..add(new Name(name, library, isSetter: true))); 520 ..add(new Name(name, library, isSetter: true)));
524 } 521 }
525 522
526 static void _computeClassMember(Compiler compiler, ClassMemberMixin cls, 523 static void _computeClassMember(Resolution resolution, ClassMemberMixin cls,
527 String name, Setlet<Name> names) { 524 String name, Setlet<Name> names) {
528 cls.computeClassMember(compiler, name, names); 525 cls.computeClassMember(resolution, name, names);
529 } 526 }
530 527
531 /// Compute all class and interface names in [cls]. 528 /// Compute all class and interface names in [cls].
532 static void computeAllClassMembers(Compiler compiler, ClassMemberMixin cls) { 529 static void computeAllClassMembers(
533 cls.computeAllClassMembers(compiler); 530 Resolution resolution, ClassMemberMixin cls) {
531 cls.computeAllClassMembers(resolution);
534 } 532 }
535 } 533 }
536 534
537 /// Class member creator for classes where the interface members are known to 535 /// Class member creator for classes where the interface members are known to
538 /// be a subset of the class members. 536 /// be a subset of the class members.
539 class ClassMembersCreator extends MembersCreator { 537 class ClassMembersCreator extends MembersCreator {
540 ClassMembersCreator(Compiler compiler, ClassElement cls, 538 ClassMembersCreator(Resolution resolution, ClassElement cls,
541 Iterable<String> computedMemberNames, Map<Name, Member> classMembers) 539 Iterable<String> computedMemberNames, Map<Name, Member> classMembers)
542 : super(compiler, cls, computedMemberNames, classMembers); 540 : super(resolution, cls, computedMemberNames, classMembers);
543 541
544 Map<Name, Member> computeMembers(String name, Setlet<Name> names) { 542 Map<Name, Member> computeMembers(String name, Setlet<Name> names) {
545 computeSuperMembers(name, names); 543 computeSuperMembers(name, names);
546 return computeClassMembers(name, names); 544 return computeClassMembers(name, names);
547 } 545 }
548 546
549 void computeSuperMembers(String name, Setlet<Name> names) { 547 void computeSuperMembers(String name, Setlet<Name> names) {
550 computeSuperClassMembers(name, names); 548 computeSuperClassMembers(name, names);
551 } 549 }
552 550
553 void checkInterfaceImplementation() { 551 void checkInterfaceImplementation() {
554 LibraryElement library = cls.library; 552 LibraryElement library = cls.library;
555 classMembers.forEach((Name name, Member classMember) { 553 classMembers.forEach((Name name, Member classMember) {
556 if (!name.isAccessibleFrom(library)) return; 554 if (!name.isAccessibleFrom(library)) return;
557 checkInterfaceMember(name, classMember, classMember.implementation); 555 checkInterfaceMember(name, classMember, classMember.implementation);
558 }); 556 });
559 } 557 }
560 } 558 }
561 559
562 /// Class Member creator for classes where the interface members might be 560 /// Class Member creator for classes where the interface members might be
563 /// different from the class members. 561 /// different from the class members.
564 class InterfaceMembersCreator extends MembersCreator { 562 class InterfaceMembersCreator extends MembersCreator {
565 final Map<Name, MemberSignature> interfaceMembers; 563 final Map<Name, MemberSignature> interfaceMembers;
566 564
567 InterfaceMembersCreator( 565 InterfaceMembersCreator(
568 Compiler compiler, 566 Resolution resolution,
569 ClassElement cls, 567 ClassElement cls,
570 Iterable<String> computedMemberNames, 568 Iterable<String> computedMemberNames,
571 Map<Name, Member> classMembers, 569 Map<Name, Member> classMembers,
572 Map<Name, MemberSignature> this.interfaceMembers) 570 Map<Name, MemberSignature> this.interfaceMembers)
573 : super(compiler, cls, computedMemberNames, classMembers); 571 : super(resolution, cls, computedMemberNames, classMembers);
574 572
575 Map<Name, Member> computeMembers(String name, Setlet<Name> names) { 573 Map<Name, Member> computeMembers(String name, Setlet<Name> names) {
576 Map<Name, Setlet<Member>> inheritedInterfaceMembers = 574 Map<Name, Setlet<Member>> inheritedInterfaceMembers =
577 computeSuperMembers(name, names); 575 computeSuperMembers(name, names);
578 Map<Name, Member> declaredMembers = computeClassMembers(name, names); 576 Map<Name, Member> declaredMembers = computeClassMembers(name, names);
579 computeInterfaceMembers(inheritedInterfaceMembers, declaredMembers); 577 computeInterfaceMembers(inheritedInterfaceMembers, declaredMembers);
580 return declaredMembers; 578 return declaredMembers;
581 } 579 }
582 580
583 /// Compute the members of the super type(s) of [cls]. The class members are 581 /// Compute the members of the super type(s) of [cls]. The class members are
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 inheritInterfaceMembers(supertype); 625 inheritInterfaceMembers(supertype);
628 } 626 }
629 627
630 // Inherit interface members from superinterfaces. 628 // Inherit interface members from superinterfaces.
631 for (Link<DartType> link = cls.interfaces; 629 for (Link<DartType> link = cls.interfaces;
632 !link.isEmpty; 630 !link.isEmpty;
633 link = link.tail) { 631 link = link.tail) {
634 InterfaceType superinterface = link.head; 632 InterfaceType superinterface = link.head;
635 if (names != null) { 633 if (names != null) {
636 MembersCreator._computeClassMember( 634 MembersCreator._computeClassMember(
637 compiler, superinterface.element, name, names); 635 resolution, superinterface.element, name, names);
638 for (Name memberName in names) { 636 for (Name memberName in names) {
639 inheritInterfaceMember(superinterface, 637 inheritInterfaceMember(superinterface,
640 superinterface.element.lookupInterfaceMember(memberName)); 638 superinterface.element.lookupInterfaceMember(memberName));
641 } 639 }
642 } else { 640 } else {
643 MembersCreator.computeAllClassMembers(compiler, superinterface.element); 641 MembersCreator.computeAllClassMembers(
642 resolution, superinterface.element);
644 inheritInterfaceMembers(superinterface); 643 inheritInterfaceMembers(superinterface);
645 } 644 }
646 } 645 }
647 646
648 return inheritedInterfaceMembers; 647 return inheritedInterfaceMembers;
649 } 648 }
650 649
651 /// Checks that a class member exists for every interface member. 650 /// Checks that a class member exists for every interface member.
652 void checkInterfaceImplementation() { 651 void checkInterfaceImplementation() {
653 LibraryElement library = cls.library; 652 LibraryElement library = cls.library;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 new Map<DartType, Setlet<Member>>(); 689 new Map<DartType, Setlet<Member>>();
691 outer: for (Member inherited in inheritedMembers) { 690 outer: for (Member inherited in inheritedMembers) {
692 if (inherited.isGetter) { 691 if (inherited.isGetter) {
693 someAreGetters = true; 692 someAreGetters = true;
694 if (!allAreGetters) break outer; 693 if (!allAreGetters) break outer;
695 } else { 694 } else {
696 allAreGetters = false; 695 allAreGetters = false;
697 if (someAreGetters) break outer; 696 if (someAreGetters) break outer;
698 } 697 }
699 for (MemberSignature other in inheritedMembers) { 698 for (MemberSignature other in inheritedMembers) {
700 if (!compiler.types 699 if (!resolution.types
701 .isSubtype(inherited.functionType, other.functionType)) { 700 .isSubtype(inherited.functionType, other.functionType)) {
702 continue outer; 701 continue outer;
703 } 702 }
704 } 703 }
705 subtypesOfAllInherited 704 subtypesOfAllInherited
706 .putIfAbsent(inherited.functionType, () => new Setlet<Member>()) 705 .putIfAbsent(inherited.functionType, () => new Setlet<Member>())
707 .add(inherited); 706 .add(inherited);
708 } 707 }
709 if (someAreGetters && !allAreGetters) { 708 if (someAreGetters && !allAreGetters) {
710 DiagnosticMessage warning = reporter.createMessage( 709 DiagnosticMessage warning = reporter.createMessage(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 Iterable<String> computedMemberNames; 825 Iterable<String> computedMemberNames;
827 826
828 /// If `true` interface members are the non-static class member. 827 /// If `true` interface members are the non-static class member.
829 bool interfaceMembersAreClassMembers = true; 828 bool interfaceMembersAreClassMembers = true;
830 829
831 Map<Name, Member> classMembers; 830 Map<Name, Member> classMembers;
832 Map<Name, MemberSignature> interfaceMembers; 831 Map<Name, MemberSignature> interfaceMembers;
833 832
834 /// Creates the necessary maps and [MembersCreator] for compute members of 833 /// Creates the necessary maps and [MembersCreator] for compute members of
835 /// this class. 834 /// this class.
836 MembersCreator _prepareCreator(Compiler compiler) { 835 MembersCreator _prepareCreator(Resolution resolution) {
837 if (classMembers == null) { 836 if (classMembers == null) {
838 ensureResolved(compiler.resolution); 837 ensureResolved(resolution);
839 classMembers = new Map<Name, Member>(); 838 classMembers = new Map<Name, Member>();
840 839
841 if (interfaceMembersAreClassMembers) { 840 if (interfaceMembersAreClassMembers) {
842 ClassMemberMixin superclass = this.superclass; 841 ClassMemberMixin superclass = this.superclass;
843 if ((superclass != null && 842 if ((superclass != null &&
844 (!superclass.interfaceMembersAreClassMembers || 843 (!superclass.interfaceMembersAreClassMembers ||
845 superclass.isMixinApplication)) || 844 superclass.isMixinApplication)) ||
846 !interfaces.isEmpty) { 845 !interfaces.isEmpty) {
847 interfaceMembersAreClassMembers = false; 846 interfaceMembersAreClassMembers = false;
848 } 847 }
849 } 848 }
850 if (!interfaceMembersAreClassMembers) { 849 if (!interfaceMembersAreClassMembers) {
851 interfaceMembers = new Map<Name, MemberSignature>(); 850 interfaceMembers = new Map<Name, MemberSignature>();
852 } 851 }
853 } 852 }
854 return interfaceMembersAreClassMembers 853 return interfaceMembersAreClassMembers
855 ? new ClassMembersCreator( 854 ? new ClassMembersCreator(
856 compiler, this, computedMemberNames, classMembers) 855 resolution, this, computedMemberNames, classMembers)
857 : new InterfaceMembersCreator(compiler, this, computedMemberNames, 856 : new InterfaceMembersCreator(resolution, this, computedMemberNames,
858 classMembers, interfaceMembers); 857 classMembers, interfaceMembers);
859 } 858 }
860 859
861 static Iterable<String> _EMPTY_MEMBERS_NAMES = const <String>[]; 860 static Iterable<String> _EMPTY_MEMBERS_NAMES = const <String>[];
862 861
863 /// Compute the members by the name [name] for this class. [names] collects 862 /// Compute the members by the name [name] for this class. [names] collects
864 /// the set of possible variations of [name], including getter, setter and 863 /// the set of possible variations of [name], including getter, setter and
865 /// and private names. 864 /// and private names.
866 void computeClassMember(Compiler compiler, String name, Setlet<Name> names) { 865 void computeClassMember(
866 Resolution resolution, String name, Setlet<Name> names) {
867 if (isMemberComputed(name)) return; 867 if (isMemberComputed(name)) return;
868 if (Name.isPrivateName(name)) { 868 if (Name.isPrivateName(name)) {
869 names 869 names
870 ..add(new Name(name, library)) 870 ..add(new Name(name, library))
871 ..add(new Name(name, library, isSetter: true)); 871 ..add(new Name(name, library, isSetter: true));
872 } 872 }
873 MembersCreator creator = _prepareCreator(compiler); 873 MembersCreator creator = _prepareCreator(resolution);
874 creator.computeMembersByName(name, names); 874 creator.computeMembersByName(name, names);
875 if (computedMemberNames == null) { 875 if (computedMemberNames == null) {
876 computedMemberNames = _EMPTY_MEMBERS_NAMES; 876 computedMemberNames = _EMPTY_MEMBERS_NAMES;
877 } 877 }
878 if (name != Identifiers.call) { 878 if (name != Identifiers.call) {
879 Setlet<String> set; 879 Setlet<String> set;
880 if (identical(computedMemberNames, _EMPTY_MEMBERS_NAMES)) { 880 if (identical(computedMemberNames, _EMPTY_MEMBERS_NAMES)) {
881 computedMemberNames = set = new Setlet<String>(); 881 computedMemberNames = set = new Setlet<String>();
882 } else { 882 } else {
883 set = computedMemberNames; 883 set = computedMemberNames;
884 } 884 }
885 set.add(name); 885 set.add(name);
886 } 886 }
887 } 887 }
888 888
889 void computeAllClassMembers(Compiler compiler) { 889 void computeAllClassMembers(Resolution resolution) {
890 if (areAllMembersComputed()) return; 890 if (areAllMembersComputed()) return;
891 MembersCreator creator = _prepareCreator(compiler); 891 MembersCreator creator = _prepareCreator(resolution);
892 creator.computeAllMembers(); 892 creator.computeAllMembers();
893 computedMemberNames = null; 893 computedMemberNames = null;
894 assert(invariant(this, areAllMembersComputed())); 894 assert(invariant(this, areAllMembersComputed()));
895 } 895 }
896 896
897 bool areAllMembersComputed() { 897 bool areAllMembersComputed() {
898 return computedMemberNames == null && classMembers != null; 898 return computedMemberNames == null && classMembers != null;
899 } 899 }
900 900
901 bool isMemberComputed(String name) { 901 bool isMemberComputed(String name) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 message: "Members have not been fully computed for $this.")); 934 message: "Members have not been fully computed for $this."));
935 if (interfaceMembersAreClassMembers) { 935 if (interfaceMembersAreClassMembers) {
936 classMembers.forEach((_, member) { 936 classMembers.forEach((_, member) {
937 if (!member.isStatic) f(member); 937 if (!member.isStatic) f(member);
938 }); 938 });
939 } else { 939 } else {
940 interfaceMembers.forEach((_, member) => f(member)); 940 interfaceMembers.forEach((_, member) => f(member));
941 } 941 }
942 } 942 }
943 } 943 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/resolution/class_hierarchy.dart ('k') | pkg/compiler/lib/src/resolution/members.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698