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

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

Issue 10834146: Revert resolver from https://chromiumcodereview.appspot.com/10824062 (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
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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, Node typeNode) { 702 Element resolveTypeName(Scope context, TypeAnnotation node) {
703 Identifier typeName = typeNode.asIdentifier(); 703 Identifier typeName = node.typeName.asIdentifier();
704 Send send = typeNode.asSend(); 704 Send send = node.typeName.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) {
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 return type;
762 }
763
764 Type resolveTypeAnnotationInContext(Scope context, TypeAnnotation node, 747 Type resolveTypeAnnotationInContext(Scope context, TypeAnnotation node,
765 onFailure, whenResolved) { 748 onFailure, whenResolved) {
766 Element element = resolveTypeName(context, node.typeName); 749 Element element = resolveTypeName(context, node);
767 Type type; 750 Type type;
768 if (element === null) { 751 if (element === null) {
769 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 752 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
770 } else if (!element.impliesType()) { 753 } else if (!element.impliesType()) {
771 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); 754 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]);
772 } else { 755 } else {
773 if (element === compiler.types.voidType.element || 756 if (element === compiler.types.voidType.element ||
774 element === compiler.types.dynamicType.element) { 757 element === compiler.types.dynamicType.element) {
775 type = element.computeType(compiler); 758 type = element.computeType(compiler);
776 } else if (element.isClass()) { 759 } else if (element.isClass()) {
777 ClassElement cls = element; 760 ClassElement cls = element;
778 if (!cls.isResolved) compiler.resolveClass(cls); 761 if (!cls.isResolved) compiler.resolveClass(cls);
779 LinkBuilder<Type> arguments = new LinkBuilder<Type>(); 762 LinkBuilder<Type> arguments = new LinkBuilder<Type>();
780 if (node.typeArguments !== null) { 763 if (node.typeArguments !== null) {
781 int index = 0; 764 int index = 0;
782 for (Link<Node> typeArguments = node.typeArguments.nodes; 765 for (Link<Node> typeArguments = node.typeArguments.nodes;
783 !typeArguments.isEmpty(); 766 !typeArguments.isEmpty();
784 typeArguments = typeArguments.tail) { 767 typeArguments = typeArguments.tail) {
785 if (++index > cls.typeParameters.length) { 768 if (++index > cls.typeParameters.length) {
786 onFailure(typeArguments.head, 769 onFailure(typeArguments.head,
787 MessageKind.ADDITIONAL_TYPE_ARGUMENT); 770 MessageKind.ADDITIONAL_TYPE_ARGUMENT);
788 } 771 }
789 // TypeVariable may happen in default clause of an interface. 772 Type argType = resolveTypeAnnotationInContext(context,
790 Type argType; 773 typeArguments.head,
791 if (typeArguments.head is TypeVariable) { 774 onFailure,
792 argType = resolveTypeVariableInContext( 775 whenResolved);
793 new ClassScope(cls, cls.getLibrary()), typeArguments.head,
794 onFailure);
795 } else {
796 argType = resolveTypeAnnotationInContext(context,
797 typeArguments.head, onFailure, whenResolved);
798 }
799 arguments.addLast(argType); 776 arguments.addLast(argType);
800 } 777 }
801 if (index < cls.typeParameters.length) { 778 if (index < cls.typeParameters.length) {
802 onFailure(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); 779 onFailure(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT);
803 } 780 }
804 } 781 }
805 if (cls.typeParameters.length == 0) { 782 if (cls.typeParameters.length == 0) {
806 // Return the canonical type if it has no type parameters. 783 // Return the canonical type if it has no type parameters.
807 type = cls.computeType(compiler); 784 type = cls.computeType(compiler);
808 } else { 785 } else {
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 2212
2236 TopScope(LibraryElement library) : super(null, library); 2213 TopScope(LibraryElement library) : super(null, library);
2237 Element lookup(SourceString name) { 2214 Element lookup(SourceString name) {
2238 return library.find(name); 2215 return library.find(name);
2239 } 2216 }
2240 2217
2241 Element add(Element newElement) { 2218 Element add(Element newElement) {
2242 throw "Cannot add an element in the top scope"; 2219 throw "Cannot add an element in the top scope";
2243 } 2220 }
2244 } 2221 }
OLDNEW
« no previous file with comments | « no previous file | tests/compiler/dart2js/unparser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698