| OLD | NEW |
| 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 '../elements/resolution_types.dart'; | 10 import '../elements/resolution_types.dart'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 final Resolution resolution; | 27 final Resolution resolution; |
| 28 | 28 |
| 29 final Iterable<String> computedMemberNames; | 29 final Iterable<String> computedMemberNames; |
| 30 final Map<Name, Member> classMembers; | 30 final Map<Name, Member> classMembers; |
| 31 | 31 |
| 32 Map<dynamic /* Member | Element */, Set<MessageKind>> reportedMessages = | 32 Map<dynamic /* Member | Element */, Set<MessageKind>> reportedMessages = |
| 33 new Map<dynamic, Set<MessageKind>>(); | 33 new Map<dynamic, Set<MessageKind>>(); |
| 34 | 34 |
| 35 MembersCreator( | 35 MembersCreator( |
| 36 this.resolution, this.cls, this.computedMemberNames, this.classMembers) { | 36 this.resolution, this.cls, this.computedMemberNames, this.classMembers) { |
| 37 assert(invariant(cls, cls.isDeclaration, | 37 assert(cls.isDeclaration, |
| 38 message: "Members may only be computed on declarations.")); | 38 failedAt(cls, "Members may only be computed on declarations.")); |
| 39 } | 39 } |
| 40 | 40 |
| 41 DiagnosticReporter get reporter => resolution.reporter; | 41 DiagnosticReporter get reporter => resolution.reporter; |
| 42 | 42 |
| 43 void reportMessage(var marker, MessageKind kind, report()) { | 43 void reportMessage(var marker, MessageKind kind, report()) { |
| 44 Set<MessageKind> messages = | 44 Set<MessageKind> messages = |
| 45 reportedMessages.putIfAbsent(marker, () => new Set<MessageKind>()); | 45 reportedMessages.putIfAbsent(marker, () => new Set<MessageKind>()); |
| 46 if (messages.add(kind)) { | 46 if (messages.add(kind)) { |
| 47 report(); | 47 report(); |
| 48 } | 48 } |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 ResolutionFunctionType functionType = element.computeType(resolution); | 206 ResolutionFunctionType functionType = element.computeType(resolution); |
| 207 ResolutionDartType type; | 207 ResolutionDartType type; |
| 208 if (!functionType.parameterTypes.isEmpty) { | 208 if (!functionType.parameterTypes.isEmpty) { |
| 209 type = functionType.parameterTypes.first; | 209 type = functionType.parameterTypes.first; |
| 210 } else { | 210 } else { |
| 211 type = const ResolutionDynamicType(); | 211 type = const ResolutionDynamicType(); |
| 212 } | 212 } |
| 213 name = name.setter; | 213 name = name.setter; |
| 214 addDeclaredMember(name, type, functionType); | 214 addDeclaredMember(name, type, functionType); |
| 215 } else { | 215 } else { |
| 216 assert(invariant(element, element.isFunction)); | 216 assert(element.isFunction, failedAt(element)); |
| 217 ResolutionFunctionType type = element.computeType(resolution); | 217 ResolutionFunctionType type = element.computeType(resolution); |
| 218 addDeclaredMember(name, type, type); | 218 addDeclaredMember(name, type, type); |
| 219 } | 219 } |
| 220 } | 220 } |
| 221 | 221 |
| 222 cls.forEachLocalMember(createMember); | 222 cls.forEachLocalMember(createMember); |
| 223 if (cls.isPatched) { | 223 if (cls.isPatched) { |
| 224 cls.implementation.forEachLocalMember((Element element) { | 224 cls.implementation.forEachLocalMember((Element element) { |
| 225 if (element.isDeclaration) { | 225 if (element.isDeclaration) { |
| 226 createMember(element); | 226 createMember(element); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 superclass = superclass.superclass; | 359 superclass = superclass.superclass; |
| 360 } | 360 } |
| 361 } | 361 } |
| 362 } else { | 362 } else { |
| 363 assert(declared.name == superMember.name); | 363 assert(declared.name == superMember.name); |
| 364 | 364 |
| 365 if (declared.isStatic) { | 365 if (declared.isStatic) { |
| 366 for (Member inherited in superMember.declarations) { | 366 for (Member inherited in superMember.declarations) { |
| 367 if (cls == inherited.declarer.element) { | 367 if (cls == inherited.declarer.element) { |
| 368 // An error should already have been reported. | 368 // An error should already have been reported. |
| 369 assert(invariant( | 369 assert(resolution.reporter.hasReportedError, |
| 370 declared.element, resolution.reporter.hasReportedError)); | 370 failedAt(declared.element)); |
| 371 continue; | 371 continue; |
| 372 } | 372 } |
| 373 | 373 |
| 374 reportMessage(inherited.element, MessageKind.NO_STATIC_OVERRIDE, () { | 374 reportMessage(inherited.element, MessageKind.NO_STATIC_OVERRIDE, () { |
| 375 reportErrorWithContext( | 375 reportErrorWithContext( |
| 376 declared.element, | 376 declared.element, |
| 377 MessageKind.NO_STATIC_OVERRIDE, | 377 MessageKind.NO_STATIC_OVERRIDE, |
| 378 inherited.element, | 378 inherited.element, |
| 379 MessageKind.NO_STATIC_OVERRIDE_CONT); | 379 MessageKind.NO_STATIC_OVERRIDE_CONT); |
| 380 }); | 380 }); |
| 381 } | 381 } |
| 382 } | 382 } |
| 383 | 383 |
| 384 ResolutionDartType declaredType = declared.functionType; | 384 ResolutionDartType declaredType = declared.functionType; |
| 385 for (Member inherited in superMember.declarations) { | 385 for (Member inherited in superMember.declarations) { |
| 386 if (inherited.element == declared.element) { | 386 if (inherited.element == declared.element) { |
| 387 // TODO(ahe): For some reason, "call" elements are repeated in | 387 // TODO(ahe): For some reason, "call" elements are repeated in |
| 388 // superMember.declarations. Investigate why. | 388 // superMember.declarations. Investigate why. |
| 389 } else if (cls == inherited.declarer.element) { | 389 } else if (cls == inherited.declarer.element) { |
| 390 // An error should already have been reported. | 390 // An error should already have been reported. |
| 391 assert( | 391 assert( |
| 392 invariant(declared.element, resolution.reporter.hasReportedError, | 392 resolution.reporter.hasReportedError, |
| 393 message: "Member $inherited inherited from its " | 393 failedAt( |
| 394 "declaring class: ${cls}.")); | 394 declared.element, |
| 395 "Member $inherited inherited from its " |
| 396 "declaring class: ${cls}.")); |
| 395 continue; | 397 continue; |
| 396 } | 398 } |
| 397 | 399 |
| 398 void reportError(MessageKind errorKind, MessageKind infoKind) { | 400 void reportError(MessageKind errorKind, MessageKind infoKind) { |
| 399 reportMessage(inherited.element, MessageKind.INVALID_OVERRIDE_METHOD, | 401 reportMessage(inherited.element, MessageKind.INVALID_OVERRIDE_METHOD, |
| 400 () { | 402 () { |
| 401 reporter.reportError( | 403 reporter.reportError( |
| 402 reporter.createMessage(declared.element, errorKind, { | 404 reporter.createMessage(declared.element, errorKind, { |
| 403 'name': declared.name.text, | 405 'name': declared.name.text, |
| 404 'class': cls.thisType, | 406 'class': cls.thisType, |
| (...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 failedAt(this, "Members have not been fully computed for $this.")); | 961 failedAt(this, "Members have not been fully computed for $this.")); |
| 960 if (interfaceMembersAreClassMembers) { | 962 if (interfaceMembersAreClassMembers) { |
| 961 classMembers.forEach((_, member) { | 963 classMembers.forEach((_, member) { |
| 962 if (!member.isStatic) f(member); | 964 if (!member.isStatic) f(member); |
| 963 }); | 965 }); |
| 964 } else { | 966 } else { |
| 965 interfaceMembers.forEach((_, member) => f(member)); | 967 interfaceMembers.forEach((_, member) => f(member)); |
| 966 } | 968 } |
| 967 } | 969 } |
| 968 } | 970 } |
| OLD | NEW |