OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.class_hierarchy; | 5 library dart2js.resolution.class_hierarchy; |
6 | 6 |
7 import '../common.dart'; | 7 import '../common.dart'; |
8 import '../common/resolution.dart' show Resolution; | 8 import '../common/resolution.dart' show Resolution; |
9 import '../common_elements.dart' show CommonElements; | 9 import '../common_elements.dart' show CommonElements; |
10 import '../elements/resolution_types.dart'; | 10 import '../elements/resolution_types.dart'; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } else { | 172 } else { |
173 superElement.ensureResolved(resolution); | 173 superElement.ensureResolved(resolution); |
174 } | 174 } |
175 element.supertype = superElement.computeType(resolution); | 175 element.supertype = superElement.computeType(resolution); |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 if (element.interfaces == null) { | 179 if (element.interfaces == null) { |
180 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); | 180 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); |
181 } else { | 181 } else { |
182 assert(invariant(element, element.hasIncompleteHierarchy)); | 182 assert(element.hasIncompleteHierarchy, failedAt(element)); |
183 } | 183 } |
184 calculateAllSupertypes(element); | 184 calculateAllSupertypes(element); |
185 | 185 |
186 if (!element.hasConstructor) { | 186 if (!element.hasConstructor) { |
187 Element superMember = element.superclass.localLookup(''); | 187 Element superMember = element.superclass.localLookup(''); |
188 if (superMember == null) { | 188 if (superMember == null) { |
189 MessageKind kind = MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR; | 189 MessageKind kind = MessageKind.CANNOT_FIND_UNNAMED_CONSTRUCTOR; |
190 Map arguments = {'className': element.superclass.name}; | 190 Map arguments = {'className': element.superclass.name}; |
191 // TODO(ahe): Why is this a compile-time error? Or if it is an error, | 191 // TODO(ahe): Why is this a compile-time error? Or if it is an error, |
192 // why do we bother to registerThrowNoSuchMethod below? | 192 // why do we bother to registerThrowNoSuchMethod below? |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 constructor.computeType(resolution); | 352 constructor.computeType(resolution); |
353 return constructor; | 353 return constructor; |
354 } | 354 } |
355 | 355 |
356 void doApplyMixinTo(MixinApplicationElementX mixinApplication, | 356 void doApplyMixinTo(MixinApplicationElementX mixinApplication, |
357 ResolutionDartType supertype, ResolutionDartType mixinType) { | 357 ResolutionDartType supertype, ResolutionDartType mixinType) { |
358 Node node = mixinApplication.parseNode(resolution.parsingContext); | 358 Node node = mixinApplication.parseNode(resolution.parsingContext); |
359 | 359 |
360 if (mixinApplication.supertype != null) { | 360 if (mixinApplication.supertype != null) { |
361 // [supertype] is not null if there was a cycle. | 361 // [supertype] is not null if there was a cycle. |
362 assert(invariant(node, reporter.hasReportedError)); | 362 assert(reporter.hasReportedError, failedAt(node)); |
363 supertype = mixinApplication.supertype; | 363 supertype = mixinApplication.supertype; |
364 assert(invariant(node, supertype.isObject)); | 364 assert(supertype.isObject, failedAt(node)); |
365 } else { | 365 } else { |
366 mixinApplication.supertype = supertype; | 366 mixinApplication.supertype = supertype; |
367 } | 367 } |
368 | 368 |
369 // Named mixin application may have an 'implements' clause. | 369 // Named mixin application may have an 'implements' clause. |
370 NamedMixinApplication namedMixinApplication = | 370 NamedMixinApplication namedMixinApplication = |
371 node.asNamedMixinApplication(); | 371 node.asNamedMixinApplication(); |
372 Link<ResolutionDartType> interfaces = (namedMixinApplication != null) | 372 Link<ResolutionDartType> interfaces = (namedMixinApplication != null) |
373 ? resolveInterfaces( | 373 ? resolveInterfaces( |
374 namedMixinApplication.interfaces, namedMixinApplication.superclass) | 374 namedMixinApplication.interfaces, namedMixinApplication.superclass) |
375 : const Link<ResolutionDartType>(); | 375 : const Link<ResolutionDartType>(); |
376 | 376 |
377 // The class that is the result of a mixin application implements | 377 // The class that is the result of a mixin application implements |
378 // the interface of the class that was mixed in so always prepend | 378 // the interface of the class that was mixed in so always prepend |
379 // that to the interface list. | 379 // that to the interface list. |
380 if (mixinApplication.interfaces == null) { | 380 if (mixinApplication.interfaces == null) { |
381 if (mixinType.isInterfaceType) { | 381 if (mixinType.isInterfaceType) { |
382 // Avoid malformed types in the interfaces. | 382 // Avoid malformed types in the interfaces. |
383 interfaces = interfaces.prepend(mixinType); | 383 interfaces = interfaces.prepend(mixinType); |
384 } | 384 } |
385 mixinApplication.interfaces = interfaces; | 385 mixinApplication.interfaces = interfaces; |
386 } else { | 386 } else { |
387 assert( | 387 assert( |
388 invariant(mixinApplication, mixinApplication.hasIncompleteHierarchy)); | 388 mixinApplication.hasIncompleteHierarchy, failedAt(mixinApplication)); |
389 } | 389 } |
390 | 390 |
391 ClassElement superclass = supertype.element; | 391 ClassElement superclass = supertype.element; |
392 if (mixinType.kind != ResolutionTypeKind.INTERFACE) { | 392 if (mixinType.kind != ResolutionTypeKind.INTERFACE) { |
393 mixinApplication.hasIncompleteHierarchy = true; | 393 mixinApplication.hasIncompleteHierarchy = true; |
394 mixinApplication.allSupertypesAndSelf = superclass.allSupertypesAndSelf; | 394 mixinApplication.allSupertypesAndSelf = superclass.allSupertypesAndSelf; |
395 return; | 395 return; |
396 } | 396 } |
397 | 397 |
398 assert(mixinApplication.mixinType == null); | 398 assert(mixinApplication.mixinType == null); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 Identifier selector = node.selector.asIdentifier(); | 646 Identifier selector = node.selector.asIdentifier(); |
647 var e = prefixElement.lookupLocalMember(selector.source); | 647 var e = prefixElement.lookupLocalMember(selector.source); |
648 if (e == null || !e.impliesType) { | 648 if (e == null || !e.impliesType) { |
649 reporter.reportErrorMessage(node.selector, | 649 reporter.reportErrorMessage(node.selector, |
650 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector}); | 650 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector}); |
651 return; | 651 return; |
652 } | 652 } |
653 loadSupertype(e, node); | 653 loadSupertype(e, node); |
654 } | 654 } |
655 } | 655 } |
OLD | NEW |