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

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

Issue 10829168: Revert "Skeleton typedef type implementation" (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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 compiler, node.parameters, node.returnType, element)); 337 compiler, node.parameters, node.returnType, element));
338 }); 338 });
339 } 339 }
340 340
341 FunctionSignature resolveFunctionExpression(Element element, 341 FunctionSignature resolveFunctionExpression(Element element,
342 FunctionExpression node) { 342 FunctionExpression node) {
343 return measure(() => SignatureResolver.analyze( 343 return measure(() => SignatureResolver.analyze(
344 compiler, node.parameters, node.returnType, element)); 344 compiler, node.parameters, node.returnType, element));
345 } 345 }
346 346
347 void resolveTypedef(TypedefElement element) { 347 FunctionSignature resolveTypedef(TypedefElement element) {
348 return compiler.withCurrentElement(element, () { 348 return compiler.withCurrentElement(element, () {
349 measure(() { 349 Typedef node =
350 Typedef node =
351 compiler.parser.measure(() => element.parseNode(compiler)); 350 compiler.parser.measure(() => element.parseNode(compiler));
352 TypedefResolverVisitor visitor = 351 return measure(() => SignatureResolver.analyze(
353 new TypedefResolverVisitor(compiler, element); 352 compiler, node.formals, node.returnType, element));
354 visitor.visit(node);
355 });
356 }); 353 });
357 } 354 }
358 355
359 FunctionType computeFunctionType(Element element, 356 FunctionType computeFunctionType(Element element,
360 FunctionSignature signature) { 357 FunctionSignature signature) {
361 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); 358 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>();
362 for (Link<Element> link = signature.requiredParameters; 359 for (Link<Element> link = signature.requiredParameters;
363 !link.isEmpty(); 360 !link.isEmpty();
364 link = link.tail) { 361 link = link.tail) {
365 parameterTypes.addLast(link.head.computeType(compiler)); 362 parameterTypes.addLast(link.head.computeType(compiler));
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (element === null) { 762 if (element === null) {
766 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]); 763 onFailure(node, MessageKind.CANNOT_RESOLVE_TYPE, [node.typeName]);
767 } else if (!element.impliesType()) { 764 } else if (!element.impliesType()) {
768 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]); 765 onFailure(node, MessageKind.NOT_A_TYPE, [node.typeName]);
769 } else { 766 } else {
770 if (element === compiler.types.voidType.element || 767 if (element === compiler.types.voidType.element ||
771 element === compiler.types.dynamicType.element) { 768 element === compiler.types.dynamicType.element) {
772 type = element.computeType(compiler); 769 type = element.computeType(compiler);
773 } else if (element.isClass()) { 770 } else if (element.isClass()) {
774 ClassElement cls = element; 771 ClassElement cls = element;
775 // TODO(ahe): Should be [ensureResolved]. 772 if (!cls.isResolved) compiler.resolveClass(cls);
776 compiler.resolver.toResolve.add(cls);
777 cls.computeType(compiler);
778 Link<Type> arguments = 773 Link<Type> arguments =
779 resolveTypeArguments(node, cls.typeVariables, scope, 774 resolveTypeArguments(node, cls.typeVariables, scope,
780 onFailure, whenResolved); 775 onFailure, whenResolved);
781 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) { 776 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) {
782 // Use the canonical type if it has no type parameters. 777 // Use the canonical type if it has no type parameters.
783 type = cls.computeType(compiler); 778 type = cls.computeType(compiler);
784 } else { 779 } else {
785 type = new InterfaceType(cls, arguments); 780 type = new InterfaceType(cls, arguments);
786 } 781 }
787 } else if (element.isTypedef()) { 782 } else if (element.isTypedef()) {
788 TypedefElement typdef = element; 783 type = element.computeType(compiler);
789 // TODO(ahe): Should be [ensureResolved].
790 typdef.computeType(compiler);
791 Link<Type> arguments = resolveTypeArguments(
792 node, typdef.typeVariables,
793 scope, onFailure, whenResolved);
794 if (typdef.typeVariables.isEmpty() && arguments.isEmpty()) {
795 // Return the canonical type if it has no type parameters.
796 type = typdef.computeType(compiler);
797 } else {
798 type = new TypedefType(typdef, arguments);
799 }
800 } else if (element.isTypeVariable()) { 784 } else if (element.isTypeVariable()) {
801 type = element.computeType(compiler); 785 type = element.computeType(compiler);
802 } else { 786 } else {
803 compiler.cancel("unexpected element kind ${element.kind}", 787 compiler.cancel("unexpected element kind ${element.kind}",
804 node: node); 788 node: node);
805 } 789 }
806 } 790 }
807 whenResolved(node, type); 791 whenResolved(node, type);
808 return type; 792 return type;
809 } 793 }
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 } else { 1702 } else {
1719 variableElement.bound = compiler.objectClass.computeType(compiler); 1703 variableElement.bound = compiler.objectClass.computeType(compiler);
1720 } 1704 }
1721 nodeLink = nodeLink.tail; 1705 nodeLink = nodeLink.tail;
1722 typeLink = typeLink.tail; 1706 typeLink = typeLink.tail;
1723 } 1707 }
1724 assert(typeLink.isEmpty()); 1708 assert(typeLink.isEmpty());
1725 } 1709 }
1726 } 1710 }
1727 1711
1728 class TypedefResolverVisitor extends TypeDefinitionVisitor {
1729 TypedefElement get element() => super.element;
1730
1731 TypedefResolverVisitor(Compiler compiler, TypedefElement typedefElement)
1732 : super(compiler, typedefElement);
1733
1734 visitTypedef(Typedef node) {
1735 TypedefType type = element.computeType(compiler);
1736 scope = new TypeDeclarationScope(scope, element);
1737 resolveTypeVariableBounds(node.typeParameters);
1738
1739 element.functionSignature = SignatureResolver.analyze(
1740 compiler, node.formals, node.returnType, element);
1741
1742 element.alias = compiler.computeFunctionType(
1743 element, element.functionSignature);
1744
1745 // TODO(johnniwinther): Check for cyclic references in the typedef alias.
1746 }
1747 }
1748
1749 class ClassResolverVisitor extends TypeDefinitionVisitor { 1712 class ClassResolverVisitor extends TypeDefinitionVisitor {
1750 ClassElement get element() => super.element; 1713 ClassElement get element() => super.element;
1751 1714
1752 ClassResolverVisitor(Compiler compiler, ClassElement classElement) 1715 ClassResolverVisitor(Compiler compiler, ClassElement classElement)
1753 : super(compiler, classElement); 1716 : super(compiler, classElement);
1754 1717
1755 visitClassNode(ClassNode node) { 1718 Type visitClassNode(ClassNode node) {
1756 compiler.ensure(element !== null); 1719 compiler.ensure(element !== null);
1757 compiler.ensure(!element.isResolved); 1720 compiler.ensure(!element.isResolved);
1758 1721
1759 InterfaceType type = element.computeType(compiler); 1722 InterfaceType type = element.computeType(compiler);
1760 scope = new TypeDeclarationScope(scope, element); 1723 scope = new TypeDeclarationScope(scope, element);
1761 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet. 1724 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet.
1762 // As a side-effect, this may get us back here trying to 1725 // As a side-effect, this may get us back here trying to
1763 // resolve this class again. 1726 // resolve this class again.
1764 resolveTypeVariableBounds(node.typeParameters); 1727 resolveTypeVariableBounds(node.typeParameters);
1765 1728
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
2338 TopScope(LibraryElement library) : super(null, library); 2301 TopScope(LibraryElement library) : super(null, library);
2339 Element lookup(SourceString name) { 2302 Element lookup(SourceString name) {
2340 return library.find(name); 2303 return library.find(name);
2341 } 2304 }
2342 2305
2343 Element add(Element newElement) { 2306 Element add(Element newElement) {
2344 throw "Cannot add an element in the top scope"; 2307 throw "Cannot add an element in the top scope";
2345 } 2308 }
2346 String toString() => '$element'; 2309 String toString() => '$element';
2347 } 2310 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/elements/elements.dart ('k') | lib/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698