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 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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 compiler, node.parameters, node.returnType, element)); | 361 compiler, node.parameters, node.returnType, element)); |
362 }); | 362 }); |
363 } | 363 } |
364 | 364 |
365 FunctionSignature resolveFunctionExpression(Element element, | 365 FunctionSignature resolveFunctionExpression(Element element, |
366 FunctionExpression node) { | 366 FunctionExpression node) { |
367 return measure(() => SignatureResolver.analyze( | 367 return measure(() => SignatureResolver.analyze( |
368 compiler, node.parameters, node.returnType, element)); | 368 compiler, node.parameters, node.returnType, element)); |
369 } | 369 } |
370 | 370 |
371 FunctionSignature resolveTypedef(TypedefElement element) { | 371 void resolveTypedef(TypedefElement element) { |
| 372 if (element.isResolved || element.isBeingResolved) return; |
| 373 element.isBeingResolved = true; |
372 return compiler.withCurrentElement(element, () { | 374 return compiler.withCurrentElement(element, () { |
373 Typedef node = | 375 measure(() { |
| 376 Typedef node = |
374 compiler.parser.measure(() => element.parseNode(compiler)); | 377 compiler.parser.measure(() => element.parseNode(compiler)); |
375 return measure(() => SignatureResolver.analyze( | 378 TypedefResolverVisitor visitor = |
376 compiler, node.formals, node.returnType, element)); | 379 new TypedefResolverVisitor(compiler, element); |
| 380 visitor.visit(node); |
| 381 |
| 382 element.isBeingResolved = false; |
| 383 element.isResolved = true; |
| 384 }); |
377 }); | 385 }); |
378 } | 386 } |
379 | 387 |
380 FunctionType computeFunctionType(Element element, | 388 FunctionType computeFunctionType(Element element, |
381 FunctionSignature signature) { | 389 FunctionSignature signature) { |
382 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); | 390 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); |
383 for (Link<Element> link = signature.requiredParameters; | 391 for (Link<Element> link = signature.requiredParameters; |
384 !link.isEmpty(); | 392 !link.isEmpty(); |
385 link = link.tail) { | 393 link = link.tail) { |
386 parameterTypes.addLast(link.head.computeType(compiler)); | 394 parameterTypes.addLast(link.head.computeType(compiler)); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 Link<Type> arguments = | 810 Link<Type> arguments = |
803 resolveTypeArguments(node, cls.typeVariables, scope, | 811 resolveTypeArguments(node, cls.typeVariables, scope, |
804 onFailure, whenResolved); | 812 onFailure, whenResolved); |
805 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) { | 813 if (cls.typeVariables.isEmpty() && arguments.isEmpty()) { |
806 // Use the canonical type if it has no type parameters. | 814 // Use the canonical type if it has no type parameters. |
807 type = cls.computeType(compiler); | 815 type = cls.computeType(compiler); |
808 } else { | 816 } else { |
809 type = new InterfaceType(cls, arguments); | 817 type = new InterfaceType(cls, arguments); |
810 } | 818 } |
811 } else if (element.isTypedef()) { | 819 } else if (element.isTypedef()) { |
812 type = element.computeType(compiler); | 820 TypedefElement typdef = element; |
| 821 // TODO(ahe): Should be [ensureResolved]. |
| 822 compiler.resolveTypedef(typdef); |
| 823 typdef.computeType(compiler); |
| 824 Link<Type> arguments = resolveTypeArguments( |
| 825 node, typdef.typeVariables, |
| 826 scope, onFailure, whenResolved); |
| 827 if (typdef.typeVariables.isEmpty() && arguments.isEmpty()) { |
| 828 // Return the canonical type if it has no type parameters. |
| 829 type = typdef.computeType(compiler); |
| 830 } else { |
| 831 type = new TypedefType(typdef, arguments); |
| 832 } |
813 } else if (element.isTypeVariable()) { | 833 } else if (element.isTypeVariable()) { |
814 type = element.computeType(compiler); | 834 type = element.computeType(compiler); |
815 } else { | 835 } else { |
816 compiler.cancel("unexpected element kind ${element.kind}", | 836 compiler.cancel("unexpected element kind ${element.kind}", |
817 node: node); | 837 node: node); |
818 } | 838 } |
819 } | 839 } |
820 whenResolved(node, type); | 840 whenResolved(node, type); |
821 return type; | 841 return type; |
822 } | 842 } |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1775 } else { | 1795 } else { |
1776 variableElement.bound = compiler.objectClass.computeType(compiler); | 1796 variableElement.bound = compiler.objectClass.computeType(compiler); |
1777 } | 1797 } |
1778 nodeLink = nodeLink.tail; | 1798 nodeLink = nodeLink.tail; |
1779 typeLink = typeLink.tail; | 1799 typeLink = typeLink.tail; |
1780 } | 1800 } |
1781 assert(typeLink.isEmpty()); | 1801 assert(typeLink.isEmpty()); |
1782 } | 1802 } |
1783 } | 1803 } |
1784 | 1804 |
| 1805 class TypedefResolverVisitor extends TypeDefinitionVisitor { |
| 1806 TypedefElement get element() => super.element; |
| 1807 |
| 1808 TypedefResolverVisitor(Compiler compiler, TypedefElement typedefElement) |
| 1809 : super(compiler, typedefElement); |
| 1810 |
| 1811 visitTypedef(Typedef node) { |
| 1812 TypedefType type = element.computeType(compiler); |
| 1813 scope = new TypeDeclarationScope(scope, element); |
| 1814 resolveTypeVariableBounds(node.typeParameters); |
| 1815 |
| 1816 element.functionSignature = SignatureResolver.analyze( |
| 1817 compiler, node.formals, node.returnType, element); |
| 1818 |
| 1819 element.alias = compiler.computeFunctionType( |
| 1820 element, element.functionSignature); |
| 1821 |
| 1822 // TODO(johnniwinther): Check for cyclic references in the typedef alias. |
| 1823 } |
| 1824 } |
| 1825 |
1785 /** | 1826 /** |
1786 * The implementation of [ResolverTask.resolveClass]. | 1827 * The implementation of [ResolverTask.resolveClass]. |
1787 * | 1828 * |
1788 * This visitor has to be extra careful as it is building the basic | 1829 * This visitor has to be extra careful as it is building the basic |
1789 * element information, and cannot safely look at other elements as | 1830 * element information, and cannot safely look at other elements as |
1790 * this may lead to cycles. | 1831 * this may lead to cycles. |
1791 * | 1832 * |
1792 * This visitor can assume that the supertypes have already been | 1833 * This visitor can assume that the supertypes have already been |
1793 * resolved, but it cannot call [ResolverTask.resolveClass] directly | 1834 * resolved, but it cannot call [ResolverTask.resolveClass] directly |
1794 * or indirectly (through [ClassElement.ensureResolved]) for any other | 1835 * or indirectly (through [ClassElement.ensureResolved]) for any other |
(...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 TopScope(LibraryElement library) : super(null, library); | 2472 TopScope(LibraryElement library) : super(null, library); |
2432 Element lookup(SourceString name) { | 2473 Element lookup(SourceString name) { |
2433 return library.find(name); | 2474 return library.find(name); |
2434 } | 2475 } |
2435 | 2476 |
2436 Element add(Element newElement) { | 2477 Element add(Element newElement) { |
2437 throw "Cannot add an element in the top scope"; | 2478 throw "Cannot add an element in the top scope"; |
2438 } | 2479 } |
2439 String toString() => '$element'; | 2480 String toString() => '$element'; |
2440 } | 2481 } |
OLD | NEW |