| 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 part of resolution; | 5 part of resolution; |
| 6 | 6 |
| 7 abstract class TreeElements { | 7 abstract class TreeElements { |
| 8 Element get currentElement; | 8 Element get currentElement; |
| 9 Setlet<Node> get superUses; | 9 Setlet<Node> get superUses; |
| 10 | 10 |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 668 * Warning: do not call this method directly. It should only be | 668 * Warning: do not call this method directly. It should only be |
| 669 * called by [resolveClass] and [ClassSupertypeResolver]. | 669 * called by [resolveClass] and [ClassSupertypeResolver]. |
| 670 */ | 670 */ |
| 671 void loadSupertypes(BaseClassElementX cls, Spannable from) { | 671 void loadSupertypes(BaseClassElementX cls, Spannable from) { |
| 672 compiler.withCurrentElement(cls, () => measure(() { | 672 compiler.withCurrentElement(cls, () => measure(() { |
| 673 if (cls.supertypeLoadState == STATE_DONE) return; | 673 if (cls.supertypeLoadState == STATE_DONE) return; |
| 674 if (cls.supertypeLoadState == STATE_STARTED) { | 674 if (cls.supertypeLoadState == STATE_STARTED) { |
| 675 compiler.reportError(from, MessageKind.CYCLIC_CLASS_HIERARCHY, | 675 compiler.reportError(from, MessageKind.CYCLIC_CLASS_HIERARCHY, |
| 676 {'className': cls.name}); | 676 {'className': cls.name}); |
| 677 cls.supertypeLoadState = STATE_DONE; | 677 cls.supertypeLoadState = STATE_DONE; |
| 678 cls.hasIncompleteHierarchy = true; |
| 678 cls.allSupertypesAndSelf = | 679 cls.allSupertypesAndSelf = |
| 679 compiler.objectClass.allSupertypesAndSelf.extendClass( | 680 compiler.objectClass.allSupertypesAndSelf.extendClass( |
| 680 cls.computeType(compiler)); | 681 cls.computeType(compiler)); |
| 681 cls.supertype = cls.allSupertypes.head; | 682 cls.supertype = cls.allSupertypes.head; |
| 682 assert(invariant(from, cls.supertype != null, | 683 assert(invariant(from, cls.supertype != null, |
| 683 message: 'Missing supertype on cyclic class $cls.')); | 684 message: 'Missing supertype on cyclic class $cls.')); |
| 685 cls.interfaces = const Link<DartType>(); |
| 684 return; | 686 return; |
| 685 } | 687 } |
| 686 cls.supertypeLoadState = STATE_STARTED; | 688 cls.supertypeLoadState = STATE_STARTED; |
| 687 compiler.withCurrentElement(cls, () { | 689 compiler.withCurrentElement(cls, () { |
| 688 // TODO(ahe): Cache the node in cls. | 690 // TODO(ahe): Cache the node in cls. |
| 689 cls.parseNode(compiler).accept( | 691 cls.parseNode(compiler).accept( |
| 690 new ClassSupertypeResolver(compiler, cls)); | 692 new ClassSupertypeResolver(compiler, cls)); |
| 691 if (cls.supertypeLoadState != STATE_DONE) { | 693 if (cls.supertypeLoadState != STATE_DONE) { |
| 692 cls.supertypeLoadState = STATE_DONE; | 694 cls.supertypeLoadState = STATE_DONE; |
| 693 } | 695 } |
| 694 }); | 696 }); |
| 695 })); | 697 })); |
| 696 } | 698 } |
| 697 | 699 |
| 698 // TODO(johnniwinther): Remove this queue when resolution has been split into | 700 // TODO(johnniwinther): Remove this queue when resolution has been split into |
| 699 // syntax and semantic resolution. | 701 // syntax and semantic resolution. |
| 700 ClassElement currentlyResolvedClass; | 702 TypeDeclarationElement currentlyResolvedTypeDeclaration; |
| 701 Queue<ClassElement> pendingClassesToBeResolved = new Queue<ClassElement>(); | 703 Queue<ClassElement> pendingClassesToBeResolved = new Queue<ClassElement>(); |
| 704 Queue<ClassElement> pendingClassesToBePostProcessed = |
| 705 new Queue<ClassElement>(); |
| 706 |
| 707 /// Resolve [element] using [resolveTypeDeclaration]. |
| 708 /// |
| 709 /// This methods ensure that class declarations encountered through type |
| 710 /// annotations during the resolution of [element] are resolved after |
| 711 /// [element] has been resolved. |
| 712 // TODO(johnniwinther): Encapsulate this functionality in a |
| 713 // 'TypeDeclarationResolver'. |
| 714 _resolveTypeDeclaration(TypeDeclarationElement element, |
| 715 resolveTypeDeclaration()) { |
| 716 TypeDeclarationElement previousResolvedTypeDeclaration = |
| 717 currentlyResolvedTypeDeclaration; |
| 718 currentlyResolvedTypeDeclaration = element; |
| 719 var result = resolveTypeDeclaration(); |
| 720 if (previousResolvedTypeDeclaration == null) { |
| 721 do { |
| 722 while (!pendingClassesToBeResolved.isEmpty) { |
| 723 pendingClassesToBeResolved.removeFirst().ensureResolved(compiler); |
| 724 } |
| 725 while (!pendingClassesToBePostProcessed.isEmpty) { |
| 726 _postProcessClassElement( |
| 727 pendingClassesToBePostProcessed.removeFirst()); |
| 728 } |
| 729 } while (!pendingClassesToBeResolved.isEmpty); |
| 730 assert(pendingClassesToBeResolved.isEmpty); |
| 731 assert(pendingClassesToBePostProcessed.isEmpty); |
| 732 } |
| 733 currentlyResolvedTypeDeclaration = previousResolvedTypeDeclaration; |
| 734 return result; |
| 735 } |
| 702 | 736 |
| 703 /** | 737 /** |
| 704 * Resolve the class [element]. | 738 * Resolve the class [element]. |
| 705 * | 739 * |
| 706 * Before calling this method, [element] was constructed by the | 740 * Before calling this method, [element] was constructed by the |
| 707 * scanner and most fields are null or empty. This method fills in | 741 * scanner and most fields are null or empty. This method fills in |
| 708 * these fields and also ensure that the supertypes of [element] are | 742 * these fields and also ensure that the supertypes of [element] are |
| 709 * resolved. | 743 * resolved. |
| 710 * | 744 * |
| 711 * Warning: Do not call this method directly. Instead use | 745 * Warning: Do not call this method directly. Instead use |
| 712 * [:element.ensureResolved(compiler):]. | 746 * [:element.ensureResolved(compiler):]. |
| 713 */ | 747 */ |
| 714 void resolveClass(ClassElement element) { | 748 void resolveClass(ClassElement element) { |
| 715 ClassElement previousResolvedClass = currentlyResolvedClass; | 749 _resolveTypeDeclaration(element, () { |
| 716 currentlyResolvedClass = element; | 750 // TODO(johnniwinther): Store the mapping in the resolution enqueuer. |
| 717 // TODO(johnniwinther): Store the mapping in the resolution enqueuer. | 751 TreeElementMapping mapping = new TreeElementMapping(element); |
| 718 TreeElementMapping mapping = new TreeElementMapping(element); | 752 resolveClassInternal(element, mapping); |
| 719 resolveClassInternal(element, mapping); | 753 }); |
| 720 if (previousResolvedClass == null) { | |
| 721 while (!pendingClassesToBeResolved.isEmpty) { | |
| 722 pendingClassesToBeResolved.removeFirst().ensureResolved(compiler); | |
| 723 } | |
| 724 } | |
| 725 currentlyResolvedClass = previousResolvedClass; | |
| 726 } | 754 } |
| 727 | 755 |
| 728 void _ensureClassWillBeResolved(ClassElement element) { | 756 void _ensureClassWillBeResolved(ClassElement element) { |
| 729 if (currentlyResolvedClass == null) { | 757 if (currentlyResolvedTypeDeclaration == null) { |
| 730 element.ensureResolved(compiler); | 758 element.ensureResolved(compiler); |
| 731 } else { | 759 } else { |
| 732 pendingClassesToBeResolved.add(element); | 760 pendingClassesToBeResolved.add(element); |
| 733 } | 761 } |
| 734 } | 762 } |
| 735 | 763 |
| 736 void resolveClassInternal(BaseClassElementX element, | 764 void resolveClassInternal(BaseClassElementX element, |
| 737 TreeElementMapping mapping) { | 765 TreeElementMapping mapping) { |
| 738 if (!element.isPatch) { | 766 if (!element.isPatch) { |
| 739 compiler.withCurrentElement(element, () => measure(() { | 767 compiler.withCurrentElement(element, () => measure(() { |
| 740 assert(element.resolutionState == STATE_NOT_STARTED); | 768 assert(element.resolutionState == STATE_NOT_STARTED); |
| 741 element.resolutionState = STATE_STARTED; | 769 element.resolutionState = STATE_STARTED; |
| 742 Node tree = element.parseNode(compiler); | 770 Node tree = element.parseNode(compiler); |
| 743 loadSupertypes(element, tree); | 771 loadSupertypes(element, tree); |
| 744 | 772 |
| 745 ClassResolverVisitor visitor = | 773 ClassResolverVisitor visitor = |
| 746 new ClassResolverVisitor(compiler, element, mapping); | 774 new ClassResolverVisitor(compiler, element, mapping); |
| 747 visitor.visit(tree); | 775 visitor.visit(tree); |
| 748 element.resolutionState = STATE_DONE; | 776 element.resolutionState = STATE_DONE; |
| 749 compiler.onClassResolved(element); | 777 compiler.onClassResolved(element); |
| 778 pendingClassesToBePostProcessed.add(element); |
| 750 })); | 779 })); |
| 751 if (element.isPatched) { | 780 if (element.isPatched) { |
| 752 // Ensure handling patch after origin. | 781 // Ensure handling patch after origin. |
| 753 element.patch.ensureResolved(compiler); | 782 element.patch.ensureResolved(compiler); |
| 754 } | 783 } |
| 755 } else { // Handle patch classes: | 784 } else { // Handle patch classes: |
| 756 element.resolutionState = STATE_STARTED; | 785 element.resolutionState = STATE_STARTED; |
| 757 // Ensure handling origin before patch. | 786 // Ensure handling origin before patch. |
| 758 element.origin.ensureResolved(compiler); | 787 element.origin.ensureResolved(compiler); |
| 759 // Ensure that the type is computed. | 788 // Ensure that the type is computed. |
| 760 element.computeType(compiler); | 789 element.computeType(compiler); |
| 761 // Copy class hiearchy from origin. | 790 // Copy class hiearchy from origin. |
| 762 element.supertype = element.origin.supertype; | 791 element.supertype = element.origin.supertype; |
| 763 element.interfaces = element.origin.interfaces; | 792 element.interfaces = element.origin.interfaces; |
| 764 element.allSupertypesAndSelf = element.origin.allSupertypesAndSelf; | 793 element.allSupertypesAndSelf = element.origin.allSupertypesAndSelf; |
| 765 // Stepwise assignment to ensure invariant. | 794 // Stepwise assignment to ensure invariant. |
| 766 element.supertypeLoadState = STATE_STARTED; | 795 element.supertypeLoadState = STATE_STARTED; |
| 767 element.supertypeLoadState = STATE_DONE; | 796 element.supertypeLoadState = STATE_DONE; |
| 768 element.resolutionState = STATE_DONE; | 797 element.resolutionState = STATE_DONE; |
| 769 // TODO(johnniwinther): Check matching type variables and | 798 // TODO(johnniwinther): Check matching type variables and |
| 770 // empty extends/implements clauses. | 799 // empty extends/implements clauses. |
| 771 } | 800 } |
| 801 } |
| 802 |
| 803 void _postProcessClassElement(BaseClassElementX element) { |
| 772 for (MetadataAnnotation metadata in element.metadata) { | 804 for (MetadataAnnotation metadata in element.metadata) { |
| 773 metadata.ensureResolved(compiler); | 805 metadata.ensureResolved(compiler); |
| 774 if (!element.isProxy && metadata.value == compiler.proxyConstant) { | 806 if (!element.isProxy && metadata.value == compiler.proxyConstant) { |
| 775 element.isProxy = true; | 807 element.isProxy = true; |
| 776 } | 808 } |
| 777 } | 809 } |
| 778 | 810 |
| 779 // Force resolution of metadata on non-instance members since they may be | 811 // Force resolution of metadata on non-instance members since they may be |
| 780 // inspected by the backend while emitting. Metadata on instance members is | 812 // inspected by the backend while emitting. Metadata on instance members is |
| 781 // handled as a result of processing instantiated class members in the | 813 // handled as a result of processing instantiated class members in the |
| 782 // enqueuer. | 814 // enqueuer. |
| 783 // TODO(ahe): Avoid this eager resolution. | 815 // TODO(ahe): Avoid this eager resolution. |
| 784 element.forEachMember((_, Element member) { | 816 element.forEachMember((_, Element member) { |
| 785 if (!member.isInstanceMember()) { | 817 if (!member.isInstanceMember()) { |
| 786 compiler.withCurrentElement(member, () { | 818 compiler.withCurrentElement(member, () { |
| 787 for (MetadataAnnotation metadata in member.metadata) { | 819 for (MetadataAnnotation metadata in member.metadata) { |
| 788 metadata.ensureResolved(compiler); | 820 metadata.ensureResolved(compiler); |
| 789 } | 821 } |
| 790 }); | 822 }); |
| 791 } | 823 } |
| 792 }); | 824 }); |
| 825 |
| 826 MembersCreator.computeClassMembers(compiler, element); |
| 793 } | 827 } |
| 794 | 828 |
| 795 void checkClass(ClassElement element) { | 829 void checkClass(ClassElement element) { |
| 796 if (element.isMixinApplication) { | 830 if (element.isMixinApplication) { |
| 797 checkMixinApplication(element); | 831 checkMixinApplication(element); |
| 798 } else { | 832 } else { |
| 799 checkClassMembers(element); | 833 checkClassMembers(element); |
| 800 } | 834 } |
| 801 } | 835 } |
| 802 | 836 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 void checkUserDefinableOperator(Element member) { | 1020 void checkUserDefinableOperator(Element member) { |
| 987 FunctionElement function = member.asFunctionElement(); | 1021 FunctionElement function = member.asFunctionElement(); |
| 988 if (function == null) return; | 1022 if (function == null) return; |
| 989 String value = member.name; | 1023 String value = member.name; |
| 990 if (value == null) return; | 1024 if (value == null) return; |
| 991 if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; | 1025 if (!(isUserDefinableOperator(value) || identical(value, 'unary-'))) return; |
| 992 | 1026 |
| 993 bool isMinus = false; | 1027 bool isMinus = false; |
| 994 int requiredParameterCount; | 1028 int requiredParameterCount; |
| 995 MessageKind messageKind; | 1029 MessageKind messageKind; |
| 996 FunctionSignature signature = function.computeSignature(compiler); | |
| 997 if (identical(value, 'unary-')) { | 1030 if (identical(value, 'unary-')) { |
| 998 isMinus = true; | 1031 isMinus = true; |
| 999 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; | 1032 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; |
| 1000 requiredParameterCount = 0; | 1033 requiredParameterCount = 0; |
| 1001 } else if (isMinusOperator(value)) { | 1034 } else if (isMinusOperator(value)) { |
| 1002 isMinus = true; | 1035 isMinus = true; |
| 1003 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; | 1036 messageKind = MessageKind.MINUS_OPERATOR_BAD_ARITY; |
| 1004 requiredParameterCount = 1; | 1037 requiredParameterCount = 1; |
| 1005 } else if (isUnaryOperator(value)) { | 1038 } else if (isUnaryOperator(value)) { |
| 1006 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; | 1039 messageKind = MessageKind.UNARY_OPERATOR_BAD_ARITY; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 | 1121 |
| 1089 reportErrorWithContext(Element errorneousElement, | 1122 reportErrorWithContext(Element errorneousElement, |
| 1090 MessageKind errorMessage, | 1123 MessageKind errorMessage, |
| 1091 Element contextElement, | 1124 Element contextElement, |
| 1092 MessageKind contextMessage) { | 1125 MessageKind contextMessage) { |
| 1093 compiler.reportError( | 1126 compiler.reportError( |
| 1094 errorneousElement, | 1127 errorneousElement, |
| 1095 errorMessage, | 1128 errorMessage, |
| 1096 {'memberName': contextElement.name, | 1129 {'memberName': contextElement.name, |
| 1097 'className': contextElement.getEnclosingClass().name}); | 1130 'className': contextElement.getEnclosingClass().name}); |
| 1098 compiler.reportMessage( | 1131 compiler.reportInfo(contextElement, contextMessage); |
| 1099 compiler.spanFromElement(contextElement), | |
| 1100 contextMessage.error(), | |
| 1101 Diagnostic.INFO); | |
| 1102 } | 1132 } |
| 1103 | 1133 |
| 1104 void checkValidOverride(Element member, Element superMember) { | 1134 void checkValidOverride(Element member, Element superMember) { |
| 1105 if (superMember == null) return; | 1135 if (superMember == null) return; |
| 1106 if (member.modifiers.isStatic()) { | 1136 if (member.modifiers.isStatic()) { |
| 1107 reportErrorWithContext( | 1137 reportErrorWithContext( |
| 1108 member, MessageKind.NO_STATIC_OVERRIDE, | 1138 member, MessageKind.NO_STATIC_OVERRIDE, |
| 1109 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT); | 1139 superMember, MessageKind.NO_STATIC_OVERRIDE_CONT); |
| 1110 } else { | 1140 } else { |
| 1111 FunctionElement superFunction = superMember.asFunctionElement(); | 1141 FunctionElement superFunction = superMember.asFunctionElement(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 } | 1189 } |
| 1160 | 1190 |
| 1161 FunctionSignature resolveFunctionExpression(Element element, | 1191 FunctionSignature resolveFunctionExpression(Element element, |
| 1162 FunctionExpression node) { | 1192 FunctionExpression node) { |
| 1163 return measure(() => SignatureResolver.analyze( | 1193 return measure(() => SignatureResolver.analyze( |
| 1164 compiler, node.parameters, node.returnType, element)); | 1194 compiler, node.parameters, node.returnType, element)); |
| 1165 } | 1195 } |
| 1166 | 1196 |
| 1167 TreeElements resolveTypedef(TypedefElementX element) { | 1197 TreeElements resolveTypedef(TypedefElementX element) { |
| 1168 if (element.isResolved) return element.mapping; | 1198 if (element.isResolved) return element.mapping; |
| 1169 TreeElementMapping mapping = new TreeElementMapping(element); | 1199 return _resolveTypeDeclaration(element, () { |
| 1170 // TODO(johnniwinther): Store the mapping in the resolution enqueuer. | 1200 TreeElementMapping mapping = new TreeElementMapping(element); |
| 1171 element.mapping = mapping; | 1201 // TODO(johnniwinther): Store the mapping in the resolution enqueuer. |
| 1172 return compiler.withCurrentElement(element, () { | 1202 element.mapping = mapping; |
| 1173 return measure(() { | 1203 return compiler.withCurrentElement(element, () { |
| 1174 Typedef node = | 1204 return measure(() { |
| 1175 compiler.parser.measure(() => element.parseNode(compiler)); | 1205 Typedef node = |
| 1176 TypedefResolverVisitor visitor = | 1206 compiler.parser.measure(() => element.parseNode(compiler)); |
| 1177 new TypedefResolverVisitor(compiler, element, mapping); | 1207 TypedefResolverVisitor visitor = |
| 1178 visitor.visit(node); | 1208 new TypedefResolverVisitor(compiler, element, mapping); |
| 1209 visitor.visit(node); |
| 1179 | 1210 |
| 1180 return mapping; | 1211 return mapping; |
| 1212 }); |
| 1181 }); | 1213 }); |
| 1182 }); | 1214 }); |
| 1183 } | 1215 } |
| 1184 | 1216 |
| 1185 FunctionType computeFunctionType(Element element, | 1217 FunctionType computeFunctionType(Element element, |
| 1186 FunctionSignature signature) { | 1218 FunctionSignature signature) { |
| 1187 var parameterTypes = new LinkBuilder<DartType>(); | 1219 var parameterTypes = new LinkBuilder<DartType>(); |
| 1188 for (Element parameter in signature.requiredParameters) { | 1220 for (Element parameter in signature.requiredParameters) { |
| 1189 parameterTypes.addLast(parameter.computeType(compiler)); | 1221 parameterTypes.addLast(parameter.computeType(compiler)); |
| 1190 } | 1222 } |
| (...skipping 2665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3856 compiler.internalError( | 3888 compiler.internalError( |
| 3857 "Cannot resolve default superclass for $element", | 3889 "Cannot resolve default superclass for $element", |
| 3858 node: node); | 3890 node: node); |
| 3859 } else { | 3891 } else { |
| 3860 superElement.ensureResolved(compiler); | 3892 superElement.ensureResolved(compiler); |
| 3861 } | 3893 } |
| 3862 element.supertype = superElement.computeType(compiler); | 3894 element.supertype = superElement.computeType(compiler); |
| 3863 } | 3895 } |
| 3864 } | 3896 } |
| 3865 | 3897 |
| 3866 assert(element.interfaces == null); | 3898 if (element.interfaces == null) { |
| 3867 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); | 3899 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); |
| 3900 } else { |
| 3901 assert(invariant(element, element.hasIncompleteHierarchy)); |
| 3902 } |
| 3868 calculateAllSupertypes(element); | 3903 calculateAllSupertypes(element); |
| 3869 | 3904 |
| 3870 if (!element.hasConstructor) { | 3905 if (!element.hasConstructor) { |
| 3871 Element superMember = | 3906 Element superMember = |
| 3872 element.superclass.localLookup(''); | 3907 element.superclass.localLookup(''); |
| 3873 if (superMember == null || !superMember.isGenerativeConstructor()) { | 3908 if (superMember == null || !superMember.isGenerativeConstructor()) { |
| 3874 DualKind kind = MessageKind.CANNOT_FIND_CONSTRUCTOR; | 3909 DualKind kind = MessageKind.CANNOT_FIND_CONSTRUCTOR; |
| 3875 Map arguments = {'constructorName': ''}; | 3910 Map arguments = {'constructorName': ''}; |
| 3876 // TODO(ahe): Why is this a compile-time error? Or if it is an error, | 3911 // TODO(ahe): Why is this a compile-time error? Or if it is an error, |
| 3877 // why do we bother to registerThrowNoSuchMethod below? | 3912 // why do we bother to registerThrowNoSuchMethod below? |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3931 } | 3966 } |
| 3932 | 3967 |
| 3933 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { | 3968 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { |
| 3934 String superName = supertype.name; | 3969 String superName = supertype.name; |
| 3935 String mixinName = mixinType.name; | 3970 String mixinName = mixinType.name; |
| 3936 MixinApplicationElementX mixinApplication = new MixinApplicationElementX( | 3971 MixinApplicationElementX mixinApplication = new MixinApplicationElementX( |
| 3937 "${superName}+${mixinName}", | 3972 "${superName}+${mixinName}", |
| 3938 element.getCompilationUnit(), | 3973 element.getCompilationUnit(), |
| 3939 compiler.getNextFreeClassId(), | 3974 compiler.getNextFreeClassId(), |
| 3940 node, | 3975 node, |
| 3941 Modifiers.EMPTY); // TODO(kasperl): Should this be abstract? | 3976 new Modifiers.withFlags(new NodeList.empty(), Modifiers.FLAG_ABSTRACT)); |
| 3942 // Create synthetic type variables for the mixin application. | 3977 // Create synthetic type variables for the mixin application. |
| 3943 LinkBuilder<DartType> typeVariablesBuilder = new LinkBuilder<DartType>(); | 3978 LinkBuilder<DartType> typeVariablesBuilder = new LinkBuilder<DartType>(); |
| 3944 element.typeVariables.forEach((TypeVariableType type) { | 3979 element.typeVariables.forEach((TypeVariableType type) { |
| 3945 TypeVariableElementX typeVariableElement = new TypeVariableElementX( | 3980 TypeVariableElementX typeVariableElement = new TypeVariableElementX( |
| 3946 type.name, mixinApplication, type.element.parseNode(compiler)); | 3981 type.name, mixinApplication, type.element.parseNode(compiler)); |
| 3947 TypeVariableType typeVariable = new TypeVariableType(typeVariableElement); | 3982 TypeVariableType typeVariable = new TypeVariableType(typeVariableElement); |
| 3948 typeVariablesBuilder.addLast(typeVariable); | 3983 typeVariablesBuilder.addLast(typeVariable); |
| 3949 }); | 3984 }); |
| 3950 Link<DartType> typeVariables = typeVariablesBuilder.toLink(); | 3985 Link<DartType> typeVariables = typeVariablesBuilder.toLink(); |
| 3951 // Setup bounds on the synthetic type variables. | 3986 // Setup bounds on the synthetic type variables. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4003 NamedMixinApplication namedMixinApplication = | 4038 NamedMixinApplication namedMixinApplication = |
| 4004 node.asNamedMixinApplication(); | 4039 node.asNamedMixinApplication(); |
| 4005 Link<DartType> interfaces = (namedMixinApplication != null) | 4040 Link<DartType> interfaces = (namedMixinApplication != null) |
| 4006 ? resolveInterfaces(namedMixinApplication.interfaces, | 4041 ? resolveInterfaces(namedMixinApplication.interfaces, |
| 4007 namedMixinApplication.superclass) | 4042 namedMixinApplication.superclass) |
| 4008 : const Link<DartType>(); | 4043 : const Link<DartType>(); |
| 4009 | 4044 |
| 4010 // The class that is the result of a mixin application implements | 4045 // The class that is the result of a mixin application implements |
| 4011 // the interface of the class that was mixed in so always prepend | 4046 // the interface of the class that was mixed in so always prepend |
| 4012 // that to the interface list. | 4047 // that to the interface list. |
| 4013 | 4048 if (mixinApplication.interfaces == null) { |
| 4014 interfaces = interfaces.prepend(mixinType); | 4049 if (mixinType.kind == TypeKind.INTERFACE) { |
| 4015 assert(mixinApplication.interfaces == null); | 4050 // Avoid malformed types in the interfaces. |
| 4016 mixinApplication.interfaces = interfaces; | 4051 interfaces = interfaces.prepend(mixinType); |
| 4052 } |
| 4053 mixinApplication.interfaces = interfaces; |
| 4054 } else { |
| 4055 assert(invariant(mixinApplication, |
| 4056 mixinApplication.hasIncompleteHierarchy)); |
| 4057 } |
| 4017 | 4058 |
| 4018 ClassElement superclass = supertype.element; | 4059 ClassElement superclass = supertype.element; |
| 4019 if (mixinType.kind != TypeKind.INTERFACE) { | 4060 if (mixinType.kind != TypeKind.INTERFACE) { |
| 4061 mixinApplication.hasIncompleteHierarchy = true; |
| 4020 mixinApplication.allSupertypesAndSelf = superclass.allSupertypesAndSelf; | 4062 mixinApplication.allSupertypesAndSelf = superclass.allSupertypesAndSelf; |
| 4021 return; | 4063 return; |
| 4022 } | 4064 } |
| 4023 | 4065 |
| 4024 assert(mixinApplication.mixinType == null); | 4066 assert(mixinApplication.mixinType == null); |
| 4025 mixinApplication.mixinType = resolveMixinFor(mixinApplication, mixinType); | 4067 mixinApplication.mixinType = resolveMixinFor(mixinApplication, mixinType); |
| 4026 | 4068 |
| 4027 // Create forwarding constructors for constructor defined in the superclass | 4069 // Create forwarding constructors for constructor defined in the superclass |
| 4028 // because they are now hidden by the mixin application. | 4070 // because they are now hidden by the mixin application. |
| 4029 superclass.forEachLocalMember((Element member) { | 4071 superclass.forEachLocalMember((Element member) { |
| (...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4777 return finishConstructorReference(visit(expression), | 4819 return finishConstructorReference(visit(expression), |
| 4778 expression, expression); | 4820 expression, expression); |
| 4779 } | 4821 } |
| 4780 } | 4822 } |
| 4781 | 4823 |
| 4782 /// Looks up [name] in [scope] and unwraps the result. | 4824 /// Looks up [name] in [scope] and unwraps the result. |
| 4783 Element lookupInScope(Compiler compiler, Node node, | 4825 Element lookupInScope(Compiler compiler, Node node, |
| 4784 Scope scope, String name) { | 4826 Scope scope, String name) { |
| 4785 return Elements.unwrap(scope.lookup(name), compiler, node); | 4827 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 4786 } | 4828 } |
| OLD | NEW |