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

Side by Side Diff: lib/compiler/implementation/resolver.dart

Issue 10824062: dart2dart (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 4 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 | Annotate | Revision Log
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 interface TreeElements { 5 interface TreeElements {
6 Element operator[](Node node); 6 Element operator[](Node node);
7 Selector getSelector(Send send); 7 Selector getSelector(Send send);
8 Type getType(TypeAnnotation annotation); 8 Type getType(TypeAnnotation annotation);
9 } 9 }
10 10
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 nestingLevel--; 692 nestingLevel--;
693 breakTargetStack = breakTargetStack.tail; 693 breakTargetStack = breakTargetStack.tail;
694 labels = labels.outer; 694 labels = labels.outer;
695 } 695 }
696 } 696 }
697 697
698 class TypeResolver { 698 class TypeResolver {
699 final Compiler compiler; 699 final Compiler compiler;
700 TypeResolver(this.compiler); 700 TypeResolver(this.compiler);
701 701
702 Element resolveTypeName(Scope context, TypeAnnotation node) { 702 Element resolveTypeName(Scope context, Node typeNode) {
703 Identifier typeName = node.typeName.asIdentifier(); 703 Identifier typeName = typeNode.asIdentifier();
704 Send send = node.typeName.asSend(); 704 Send send = typeNode.asSend();
705 if (send !== null) { 705 if (send !== null) {
706 typeName = send.selector; 706 typeName = send.selector;
707 } 707 }
708 if (typeName.source.stringValue === 'void') { 708 if (typeName.source.stringValue === 'void') {
709 return compiler.types.voidType.element; 709 return compiler.types.voidType.element;
710 } else if (send !== null) { 710 } else if (send !== null) {
711 Element e = context.lookup(send.receiver.asIdentifier().source); 711 Element e = context.lookup(send.receiver.asIdentifier().source);
712 if (e !== null && e.kind === ElementKind.PREFIX) { 712 if (e !== null && e.kind === ElementKind.PREFIX) {
713 // The receiver is a prefix. Lookup in the imported members. 713 // The receiver is a prefix. Lookup in the imported members.
714 PrefixElement prefix = e; 714 PrefixElement prefix = e;
(...skipping 22 matching lines...) Expand all
737 if (inClass !== null) { 737 if (inClass !== null) {
738 inContext = new ClassScope(inClass, inClass.getLibrary()); 738 inContext = new ClassScope(inClass, inClass.getLibrary());
739 } 739 }
740 if (inContext === null) { 740 if (inContext === null) {
741 compiler.internalError('resolveTypeAnnotation: no scope specified'); 741 compiler.internalError('resolveTypeAnnotation: no scope specified');
742 } 742 }
743 return resolveTypeAnnotationInContext(inContext, node, onFailure, 743 return resolveTypeAnnotationInContext(inContext, node, onFailure,
744 whenResolved); 744 whenResolved);
745 } 745 }
746 746
747 Type resolveTypeVariableInContext(Scope context, TypeVariable node,
748 onFailure, whenResolved) {
Anton Muhin 2012/07/27 11:15:34 do you need this whenResolved?
Roman 2012/07/27 11:32:45 Removed.
749 Element element = resolveTypeName(context, node.name);
750 Type type;
751 if (element === null) {
752 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.name]);
753 } else if (!element.impliesType()) {
754 onFailure(node, MessageKind.NOT_A_TYPE, [node.name]);
755 } else if (element.isTypeVariable()) {
756 type = element.computeType(compiler);
757 } else {
758 compiler.cancel("unexpected element kind ${element.kind}",
759 node: node);
760 }
761 whenResolved(node, type);
762 return type;
763 }
764
747 Type resolveTypeAnnotationInContext(Scope context, TypeAnnotation node, 765 Type resolveTypeAnnotationInContext(Scope context, TypeAnnotation node,
748 onFailure, whenResolved) { 766 onFailure, whenResolved) {
749 Element element = resolveTypeName(context, node); 767 Element element = resolveTypeName(context, node.typeName);
750 Type type; 768 Type type;
751 if (element === null) { 769 if (element === null) {
752 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 770 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
753 } else if (!element.impliesType()) { 771 } else if (!element.impliesType()) {
754 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); 772 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]);
755 } else { 773 } else {
756 if (element === compiler.types.voidType.element || 774 if (element === compiler.types.voidType.element ||
757 element === compiler.types.dynamicType.element) { 775 element === compiler.types.dynamicType.element) {
758 type = element.computeType(compiler); 776 type = element.computeType(compiler);
759 } else if (element.isClass()) { 777 } else if (element.isClass()) {
760 ClassElement cls = element; 778 ClassElement cls = element;
761 if (!cls.isResolved) compiler.resolveClass(cls); 779 if (!cls.isResolved) compiler.resolveClass(cls);
762 LinkBuilder<Type> arguments = new LinkBuilder<Type>(); 780 LinkBuilder<Type> arguments = new LinkBuilder<Type>();
763 if (node.typeArguments !== null) { 781 if (node.typeArguments !== null) {
764 int index = 0; 782 int index = 0;
765 for (Link<Node> typeArguments = node.typeArguments.nodes; 783 for (Link<Node> typeArguments = node.typeArguments.nodes;
766 !typeArguments.isEmpty(); 784 !typeArguments.isEmpty();
767 typeArguments = typeArguments.tail) { 785 typeArguments = typeArguments.tail) {
768 if (++index > cls.typeParameters.length) { 786 if (++index > cls.typeParameters.length) {
769 onFailure(typeArguments.head, 787 onFailure(typeArguments.head,
770 MessageKind.ADDITIONAL_TYPE_ARGUMENT); 788 MessageKind.ADDITIONAL_TYPE_ARGUMENT);
771 } 789 }
772 Type argType = resolveTypeAnnotationInContext(context, 790 // TypeVariable may happen in default clause of an interface.
773 typeArguments.head, 791 Type argType;
774 onFailure, 792 if (typeArguments.head is TypeVariable) {
775 whenResolved); 793 argType = resolveTypeVariableInContext(
794 new ClassScope(cls, cls.getLibrary()), typeArguments.head,
795 onFailure, (n, t) {});
796 } else {
797 argType = resolveTypeAnnotationInContext(context,
798 typeArguments.head, onFailure, whenResolved);
799 }
776 arguments.addLast(argType); 800 arguments.addLast(argType);
777 } 801 }
778 if (index < cls.typeParameters.length) { 802 if (index < cls.typeParameters.length) {
779 onFailure(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); 803 onFailure(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT);
780 } 804 }
781 } 805 }
782 if (cls.typeParameters.length == 0) { 806 if (cls.typeParameters.length == 0) {
783 // Return the canonical type if it has no type parameters. 807 // Return the canonical type if it has no type parameters.
784 type = cls.computeType(compiler); 808 type = cls.computeType(compiler);
785 } else { 809 } else {
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
2212 2236
2213 TopScope(LibraryElement library) : super(null, library); 2237 TopScope(LibraryElement library) : super(null, library);
2214 Element lookup(SourceString name) { 2238 Element lookup(SourceString name) {
2215 return library.find(name); 2239 return library.find(name);
2216 } 2240 }
2217 2241
2218 Element add(Element newElement) { 2242 Element add(Element newElement) {
2219 throw "Cannot add an element in the top scope"; 2243 throw "Cannot add an element in the top scope";
2220 } 2244 }
2221 } 2245 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698