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

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

Issue 10832136: Skeleton typedef type implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Backend updated 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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 compiler, node.parameters, node.returnType, element)); 369 compiler, node.parameters, node.returnType, element));
370 }); 370 });
371 } 371 }
372 372
373 FunctionSignature resolveFunctionExpression(Element element, 373 FunctionSignature resolveFunctionExpression(Element element,
374 FunctionExpression node) { 374 FunctionExpression node) {
375 return measure(() => SignatureResolver.analyze( 375 return measure(() => SignatureResolver.analyze(
376 compiler, node.parameters, node.returnType, element)); 376 compiler, node.parameters, node.returnType, element));
377 } 377 }
378 378
379 FunctionSignature resolveTypedef(TypedefElement element) { 379 void resolveTypedef(TypedefElement element) {
ahe 2012/08/16 13:22:58 Could you make this look more like resolveClass an
Johnni Winther 2012/08/17 11:15:19 I will do that in a later CL.
380 if (element.isResolved || element.isBeingResolved) return;
381 element.isBeingResolved = true;
380 return compiler.withCurrentElement(element, () { 382 return compiler.withCurrentElement(element, () {
ahe 2012/08/16 13:22:58 You can use: ..., () => measure() { This is short
Johnni Winther 2012/08/17 11:15:19 I will do that in a later CL.
381 Typedef node = 383 measure(() {
384 Typedef node =
382 compiler.parser.measure(() => element.parseNode(compiler)); 385 compiler.parser.measure(() => element.parseNode(compiler));
383 return measure(() => SignatureResolver.analyze( 386 TypedefResolverVisitor visitor =
384 compiler, node.formals, node.returnType, element)); 387 new TypedefResolverVisitor(compiler, element);
388 visitor.visit(node);
389
390 element.isBeingResolved = false;
391 element.isResolved = true;
392 });
385 }); 393 });
386 } 394 }
387 395
388 FunctionType computeFunctionType(Element element, 396 FunctionType computeFunctionType(Element element,
389 FunctionSignature signature) { 397 FunctionSignature signature) {
390 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); 398 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>();
391 for (Link<Element> link = signature.requiredParameters; 399 for (Link<Element> link = signature.requiredParameters;
392 !link.isEmpty(); 400 !link.isEmpty();
393 link = link.tail) { 401 link = link.tail) {
394 parameterTypes.addLast(link.head.computeType(compiler)); 402 parameterTypes.addLast(link.head.computeType(compiler));
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 Link<Type> arguments = 813 Link<Type> arguments =
806 resolveTypeArguments(node, cls.typeVariables, scope, 814 resolveTypeArguments(node, cls.typeVariables, scope,
807 onFailure, whenResolved); 815 onFailure, whenResolved);
808 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) { 816 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) {
809 // Use the canonical type if it has no type parameters. 817 // Use the canonical type if it has no type parameters.
810 type = cls.computeType(compiler); 818 type = cls.computeType(compiler);
811 } else { 819 } else {
812 type = new InterfaceType(cls, arguments); 820 type = new InterfaceType(cls, arguments);
813 } 821 }
814 } else if (element.isTypedef()) { 822 } else if (element.isTypedef()) {
815 type = element.computeType(compiler); 823 TypedefElement typdef = element;
824 // TODO(ahe): Should be [ensureResolved].
ahe 2012/08/16 13:22:58 I think you have to do this now :-)
Johnni Winther 2012/08/17 11:15:19 I will do that in a later CL.
825 compiler.resolveTypedef(typdef);
826 typdef.computeType(compiler);
827 Link<Type> arguments = resolveTypeArguments(
828 node, typdef.typeVariables,
829 scope, onFailure, whenResolved);
830 if (typdef.typeVariables.isEmpty() && arguments.isEmpty()) {
831 // Return the canonical type if it has no type parameters.
832 type = typdef.computeType(compiler);
833 } else {
834 type = new TypedefType(typdef, arguments);
835 }
816 } else if (element.isTypeVariable()) { 836 } else if (element.isTypeVariable()) {
817 type = element.computeType(compiler); 837 type = element.computeType(compiler);
818 } else { 838 } else {
819 compiler.cancel("unexpected element kind ${element.kind}", 839 compiler.cancel("unexpected element kind ${element.kind}",
820 node: node); 840 node: node);
821 } 841 }
822 } 842 }
823 whenResolved(node, type); 843 whenResolved(node, type);
824 return type; 844 return type;
825 } 845 }
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 } else { 1765 } else {
1746 variableElement.bound = compiler.objectClass.computeType(compiler); 1766 variableElement.bound = compiler.objectClass.computeType(compiler);
1747 } 1767 }
1748 nodeLink = nodeLink.tail; 1768 nodeLink = nodeLink.tail;
1749 typeLink = typeLink.tail; 1769 typeLink = typeLink.tail;
1750 } 1770 }
1751 assert(typeLink.isEmpty()); 1771 assert(typeLink.isEmpty());
1752 } 1772 }
1753 } 1773 }
1754 1774
1775 class TypedefResolverVisitor extends TypeDefinitionVisitor {
1776 TypedefElement get element() => super.element;
1777
1778 TypedefResolverVisitor(Compiler compiler, TypedefElement typedefElement)
1779 : super(compiler, typedefElement);
1780
1781 visitTypedef(Typedef node) {
1782 TypedefType type = element.computeType(compiler);
1783 scope = new TypeDeclarationScope(scope, element);
1784 resolveTypeVariableBounds(node.typeParameters);
1785
1786 element.functionSignature = SignatureResolver.analyze(
1787 compiler, node.formals, node.returnType, element);
1788
1789 element.alias = compiler.computeFunctionType(
1790 element, element.functionSignature);
1791
1792 // TODO(johnniwinther): Check for cyclic references in the typedef alias.
1793 }
1794 }
1795
1755 /** 1796 /**
1756 * The implementation of [ResolverTask.resolveClass]. 1797 * The implementation of [ResolverTask.resolveClass].
1757 * 1798 *
1758 * This visitor has to be extra careful as it is building the basic 1799 * This visitor has to be extra careful as it is building the basic
1759 * element information, and cannot safely look at other elements as 1800 * element information, and cannot safely look at other elements as
1760 * this may lead to cycles. 1801 * this may lead to cycles.
1761 * 1802 *
1762 * This visitor can assume that the supertypes have already been 1803 * This visitor can assume that the supertypes have already been
1763 * resolved, but it cannot call [ResolverTask.resolveClass] directly 1804 * resolved, but it cannot call [ResolverTask.resolveClass] directly
1764 * or indirectly (through [ClassElement.ensureResolved]) for any other 1805 * or indirectly (through [ClassElement.ensureResolved]) for any other
1765 * types. 1806 * types.
1766 */ 1807 */
1767 class ClassResolverVisitor extends TypeDefinitionVisitor { 1808 class ClassResolverVisitor extends TypeDefinitionVisitor {
1768 ClassElement get element() => super.element; 1809 ClassElement get element() => super.element;
1769 1810
1770 ClassResolverVisitor(Compiler compiler, ClassElement classElement) 1811 ClassResolverVisitor(Compiler compiler, ClassElement classElement)
1771 : super(compiler, classElement); 1812 : super(compiler, classElement);
1772 1813
1773 Type visitClassNode(ClassNode node) { 1814 visitClassNode(ClassNode node) {
ngeoffray 2012/08/16 12:45:44 Why this change?
Johnni Winther 2012/08/17 11:15:19 A leftover from another change which hasn't been c
1774 compiler.ensure(element !== null); 1815 compiler.ensure(element !== null);
1775 compiler.ensure(element.resolutionState == ClassElement.STATE_STARTED); 1816 compiler.ensure(element.resolutionState == ClassElement.STATE_STARTED);
1776 1817
1777 InterfaceType type = element.computeType(compiler); 1818 InterfaceType type = element.computeType(compiler);
1778 scope = new TypeDeclarationScope(scope, element); 1819 scope = new TypeDeclarationScope(scope, element);
1779 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet. 1820 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet.
1780 // As a side-effect, this may get us back here trying to 1821 // As a side-effect, this may get us back here trying to
1781 // resolve this class again. 1822 // resolve this class again.
1782 resolveTypeVariableBounds(node.typeParameters); 1823 resolveTypeVariableBounds(node.typeParameters);
1783 1824
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 TopScope(LibraryElement library) : super(null, library); 2442 TopScope(LibraryElement library) : super(null, library);
2402 Element lookup(SourceString name) { 2443 Element lookup(SourceString name) {
2403 return library.find(name); 2444 return library.find(name);
2404 } 2445 }
2405 2446
2406 Element add(Element newElement) { 2447 Element add(Element newElement) {
2407 throw "Cannot add an element in the top scope"; 2448 throw "Cannot add an element in the top scope";
2408 } 2449 }
2409 String toString() => '$element'; 2450 String toString() => '$element';
2410 } 2451 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698