| 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 '../core_types.dart' show CoreClasses, CoreTypes; | 9 import '../core_types.dart' show CommonElements; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| 11 import '../elements/elements.dart'; | 11 import '../elements/elements.dart'; |
| 12 import '../elements/modelx.dart' | 12 import '../elements/modelx.dart' |
| 13 show | 13 show |
| 14 BaseClassElementX, | 14 BaseClassElementX, |
| 15 ErroneousElementX, | 15 ErroneousElementX, |
| 16 MixinApplicationElementX, | 16 MixinApplicationElementX, |
| 17 SynthesizedConstructorElementX, | 17 SynthesizedConstructorElementX, |
| 18 TypeVariableElementX, | 18 TypeVariableElementX, |
| 19 UnnamedMixinApplicationElementX; | 19 UnnamedMixinApplicationElementX; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 Scope scope; | 32 Scope scope; |
| 33 final TypeDeclarationElement enclosingElement; | 33 final TypeDeclarationElement enclosingElement; |
| 34 TypeDeclarationElement get element => enclosingElement; | 34 TypeDeclarationElement get element => enclosingElement; |
| 35 | 35 |
| 36 TypeDefinitionVisitor(Resolution resolution, TypeDeclarationElement element, | 36 TypeDefinitionVisitor(Resolution resolution, TypeDeclarationElement element, |
| 37 ResolutionRegistry registry) | 37 ResolutionRegistry registry) |
| 38 : this.enclosingElement = element, | 38 : this.enclosingElement = element, |
| 39 scope = Scope.buildEnclosingScope(element), | 39 scope = Scope.buildEnclosingScope(element), |
| 40 super(resolution, registry); | 40 super(resolution, registry); |
| 41 | 41 |
| 42 CoreTypes get coreTypes => resolution.coreTypes; | 42 CommonElements get commonElements => resolution.commonElements; |
| 43 | 43 |
| 44 DartType get objectType => coreTypes.objectType; | 44 DartType get objectType => commonElements.objectType; |
| 45 | 45 |
| 46 void resolveTypeVariableBounds(NodeList node) { | 46 void resolveTypeVariableBounds(NodeList node) { |
| 47 if (node == null) return; | 47 if (node == null) return; |
| 48 | 48 |
| 49 Setlet<String> nameSet = new Setlet<String>(); | 49 Setlet<String> nameSet = new Setlet<String>(); |
| 50 // Resolve the bounds of type variables. | 50 // Resolve the bounds of type variables. |
| 51 Iterator<DartType> types = element.typeVariables.iterator; | 51 Iterator<DartType> types = element.typeVariables.iterator; |
| 52 Link<Node> nodeLink = node.nodes; | 52 Link<Node> nodeLink = node.nodes; |
| 53 while (!nodeLink.isEmpty) { | 53 while (!nodeLink.isEmpty) { |
| 54 types.moveNext(); | 54 types.moveNext(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 element.supertype = objectType; | 236 element.supertype = objectType; |
| 237 element.interfaces = const Link<DartType>(); | 237 element.interfaces = const Link<DartType>(); |
| 238 calculateAllSupertypes(element); | 238 calculateAllSupertypes(element); |
| 239 | 239 |
| 240 if (node.names.nodes.isEmpty) { | 240 if (node.names.nodes.isEmpty) { |
| 241 reporter.reportErrorMessage( | 241 reporter.reportErrorMessage( |
| 242 node, MessageKind.EMPTY_ENUM_DECLARATION, {'enumName': element.name}); | 242 node, MessageKind.EMPTY_ENUM_DECLARATION, {'enumName': element.name}); |
| 243 } | 243 } |
| 244 | 244 |
| 245 EnumCreator creator = | 245 EnumCreator creator = |
| 246 new EnumCreator(reporter, resolution.coreTypes, element); | 246 new EnumCreator(reporter, resolution.commonElements, element); |
| 247 creator.createMembers(); | 247 creator.createMembers(); |
| 248 return enumType; | 248 return enumType; |
| 249 } | 249 } |
| 250 | 250 |
| 251 /// Resolves the mixed type for [mixinNode] and checks that the mixin type | 251 /// Resolves the mixed type for [mixinNode] and checks that the mixin type |
| 252 /// is a valid, non-blacklisted interface type. The mixin type is returned. | 252 /// is a valid, non-blacklisted interface type. The mixin type is returned. |
| 253 DartType checkMixinType(TypeAnnotation mixinNode) { | 253 DartType checkMixinType(TypeAnnotation mixinNode) { |
| 254 DartType mixinType = resolveType(mixinNode); | 254 DartType mixinType = resolveType(mixinNode); |
| 255 if (isBlackListed(mixinType)) { | 255 if (isBlackListed(mixinType)) { |
| 256 reporter.reportErrorMessage( | 256 reporter.reportErrorMessage( |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 * | 528 * |
| 529 * This order makes sure that if a class implements an interface twice with | 529 * This order makes sure that if a class implements an interface twice with |
| 530 * different type arguments, the type used in the most specific class comes | 530 * different type arguments, the type used in the most specific class comes |
| 531 * first. | 531 * first. |
| 532 */ | 532 */ |
| 533 void calculateAllSupertypes(BaseClassElementX cls) { | 533 void calculateAllSupertypes(BaseClassElementX cls) { |
| 534 if (cls.allSupertypesAndSelf != null) return; | 534 if (cls.allSupertypesAndSelf != null) return; |
| 535 final DartType supertype = cls.supertype; | 535 final DartType supertype = cls.supertype; |
| 536 if (supertype != null) { | 536 if (supertype != null) { |
| 537 cls.allSupertypesAndSelf = new OrderedTypeSetBuilder(cls, | 537 cls.allSupertypesAndSelf = new OrderedTypeSetBuilder(cls, |
| 538 reporter: reporter, objectType: coreTypes.objectType) | 538 reporter: reporter, objectType: commonElements.objectType) |
| 539 .createOrderedTypeSet(supertype, cls.interfaces); | 539 .createOrderedTypeSet(supertype, cls.interfaces); |
| 540 } else { | 540 } else { |
| 541 assert(cls == resolution.coreClasses.objectClass); | 541 assert(cls == resolution.commonElements.objectClass); |
| 542 cls.allSupertypesAndSelf = | 542 cls.allSupertypesAndSelf = |
| 543 new OrderedTypeSet.singleton(cls.computeType(resolution)); | 543 new OrderedTypeSet.singleton(cls.computeType(resolution)); |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 | 546 |
| 547 isBlackListed(DartType type) { | 547 isBlackListed(DartType type) { |
| 548 LibraryElement lib = element.library; | 548 LibraryElement lib = element.library; |
| 549 return !identical(lib, resolution.commonElements.coreLibrary) && | 549 return !identical(lib, resolution.commonElements.coreLibrary) && |
| 550 !resolution.target.isTargetSpecificLibrary(lib) && | 550 !resolution.target.isTargetSpecificLibrary(lib) && |
| 551 (type.isDynamic || | 551 (type.isDynamic || |
| 552 type == coreTypes.boolType || | 552 type == commonElements.boolType || |
| 553 type == coreTypes.numType || | 553 type == commonElements.numType || |
| 554 type == coreTypes.intType || | 554 type == commonElements.intType || |
| 555 type == coreTypes.doubleType || | 555 type == commonElements.doubleType || |
| 556 type == coreTypes.stringType || | 556 type == commonElements.stringType || |
| 557 type == coreTypes.nullType); | 557 type == commonElements.nullType); |
| 558 } | 558 } |
| 559 } | 559 } |
| 560 | 560 |
| 561 class ClassSupertypeResolver extends CommonResolverVisitor { | 561 class ClassSupertypeResolver extends CommonResolverVisitor { |
| 562 Scope context; | 562 Scope context; |
| 563 ClassElement classElement; | 563 ClassElement classElement; |
| 564 | 564 |
| 565 ClassSupertypeResolver(Resolution resolution, ClassElement cls) | 565 ClassSupertypeResolver(Resolution resolution, ClassElement cls) |
| 566 : context = Scope.buildEnclosingScope(cls), | 566 : context = Scope.buildEnclosingScope(cls), |
| 567 this.classElement = cls, | 567 this.classElement = cls, |
| 568 super(resolution); | 568 super(resolution); |
| 569 | 569 |
| 570 CoreClasses get coreClasses => resolution.coreClasses; | 570 CommonElements get commonElements => resolution.commonElements; |
| 571 | 571 |
| 572 void loadSupertype(ClassElement element, Node from) { | 572 void loadSupertype(ClassElement element, Node from) { |
| 573 if (!element.isResolved) { | 573 if (!element.isResolved) { |
| 574 resolution.resolver.loadSupertypes(element, from); | 574 resolution.resolver.loadSupertypes(element, from); |
| 575 element.ensureResolved(resolution); | 575 element.ensureResolved(resolution); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 | 578 |
| 579 void visitNodeList(NodeList node) { | 579 void visitNodeList(NodeList node) { |
| 580 if (node != null) { | 580 if (node != null) { |
| 581 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { | 581 for (Link<Node> link = node.nodes; !link.isEmpty; link = link.tail) { |
| 582 link.head.accept(this); | 582 link.head.accept(this); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 | 586 |
| 587 void visitClassNode(ClassNode node) { | 587 void visitClassNode(ClassNode node) { |
| 588 if (node.superclass == null) { | 588 if (node.superclass == null) { |
| 589 if (classElement != coreClasses.objectClass) { | 589 if (classElement != commonElements.objectClass) { |
| 590 loadSupertype(coreClasses.objectClass, node); | 590 loadSupertype(commonElements.objectClass, node); |
| 591 } | 591 } |
| 592 } else { | 592 } else { |
| 593 node.superclass.accept(this); | 593 node.superclass.accept(this); |
| 594 } | 594 } |
| 595 visitNodeList(node.interfaces); | 595 visitNodeList(node.interfaces); |
| 596 } | 596 } |
| 597 | 597 |
| 598 void visitEnum(Enum node) { | 598 void visitEnum(Enum node) { |
| 599 loadSupertype(coreClasses.objectClass, node); | 599 loadSupertype(commonElements.objectClass, node); |
| 600 } | 600 } |
| 601 | 601 |
| 602 void visitMixinApplication(MixinApplication node) { | 602 void visitMixinApplication(MixinApplication node) { |
| 603 node.superclass.accept(this); | 603 node.superclass.accept(this); |
| 604 visitNodeList(node.mixins); | 604 visitNodeList(node.mixins); |
| 605 } | 605 } |
| 606 | 606 |
| 607 void visitNamedMixinApplication(NamedMixinApplication node) { | 607 void visitNamedMixinApplication(NamedMixinApplication node) { |
| 608 node.superclass.accept(this); | 608 node.superclass.accept(this); |
| 609 visitNodeList(node.mixins); | 609 visitNodeList(node.mixins); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 638 Identifier selector = node.selector.asIdentifier(); | 638 Identifier selector = node.selector.asIdentifier(); |
| 639 var e = prefixElement.lookupLocalMember(selector.source); | 639 var e = prefixElement.lookupLocalMember(selector.source); |
| 640 if (e == null || !e.impliesType) { | 640 if (e == null || !e.impliesType) { |
| 641 reporter.reportErrorMessage(node.selector, | 641 reporter.reportErrorMessage(node.selector, |
| 642 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector}); | 642 MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': node.selector}); |
| 643 return; | 643 return; |
| 644 } | 644 } |
| 645 loadSupertype(e, node); | 645 loadSupertype(e, node); |
| 646 } | 646 } |
| 647 } | 647 } |
| OLD | NEW |