| 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 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 } | 1650 } |
| 1651 visitIn(node.formals, blockScope); | 1651 visitIn(node.formals, blockScope); |
| 1652 visitIn(node.block, blockScope); | 1652 visitIn(node.block, blockScope); |
| 1653 } | 1653 } |
| 1654 | 1654 |
| 1655 visitTypedef(Typedef node) { | 1655 visitTypedef(Typedef node) { |
| 1656 unimplemented(node, 'typedef'); | 1656 unimplemented(node, 'typedef'); |
| 1657 } | 1657 } |
| 1658 } | 1658 } |
| 1659 | 1659 |
| 1660 class TypeDefinitionVisitor extends CommonResolverVisitor<Type> { |
| 1661 Scope scope; |
| 1662 TypeDeclarationElement element; |
| 1663 TypeResolver typeResolver; |
| 1664 |
| 1665 TypeDefinitionVisitor(Compiler compiler, TypeDeclarationElement element) |
| 1666 : this.element = element, |
| 1667 scope = element.enclosingElement.buildScope(), |
| 1668 typeResolver = new TypeResolver(compiler), |
| 1669 super(compiler); |
| 1670 |
| 1671 void resolveTypeVariableBounds(NodeList node) { |
| 1672 if (node === null) return; |
| 1673 |
| 1674 var nameSet = new Set<SourceString>(); |
| 1675 // Resolve the bounds of type variables. |
| 1676 Link<Type> typeLink = element.typeVariables; |
| 1677 Link<Node> nodeLink = node.nodes; |
| 1678 while (!nodeLink.isEmpty()) { |
| 1679 TypeVariableType typeVariable = typeLink.head; |
| 1680 SourceString typeName = typeVariable.name; |
| 1681 TypeVariable typeNode = nodeLink.head; |
| 1682 if (nameSet.contains(typeName)) { |
| 1683 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); |
| 1684 } |
| 1685 nameSet.add(typeName); |
| 1686 |
| 1687 TypeVariableElement variableElement = typeVariable.element; |
| 1688 if (typeNode.bound !== null) { |
| 1689 Type boundType = typeResolver.resolveTypeAnnotation( |
| 1690 typeNode.bound, inScope: scope, onFailure: warning); |
| 1691 if (boundType !== null && boundType.element == variableElement) { |
| 1692 // TODO(johnniwinther): Check for more general cycles, like |
| 1693 // [: <A extends B, B extends C, C extends B> :]. |
| 1694 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, |
| 1695 [variableElement.name]); |
| 1696 } else if (boundType !== null) { |
| 1697 variableElement.bound = boundType; |
| 1698 } else { |
| 1699 // TODO(johnniwinther): Should be an erroneous type. |
| 1700 variableElement.bound = compiler.objectClass.computeType(compiler); |
| 1701 } |
| 1702 } else { |
| 1703 variableElement.bound = compiler.objectClass.computeType(compiler); |
| 1704 } |
| 1705 nodeLink = nodeLink.tail; |
| 1706 typeLink = typeLink.tail; |
| 1707 } |
| 1708 assert(typeLink.isEmpty()); |
| 1709 } |
| 1710 } |
| 1711 |
| 1660 class ClassResolverVisitor extends TypeDefinitionVisitor { | 1712 class ClassResolverVisitor extends TypeDefinitionVisitor { |
| 1661 ClassElement get element() => super.element; | 1713 ClassElement get element() => super.element; |
| 1662 | 1714 |
| 1663 ClassResolverVisitor(Compiler compiler, ClassElement classElement) | 1715 ClassResolverVisitor(Compiler compiler, ClassElement classElement) |
| 1664 : super(compiler, classElement); | 1716 : super(compiler, classElement); |
| 1665 | 1717 |
| 1666 Type visitClassNode(ClassNode node) { | 1718 Type visitClassNode(ClassNode node) { |
| 1667 compiler.ensure(element !== null); | 1719 compiler.ensure(element !== null); |
| 1668 compiler.ensure(!element.isResolved); | 1720 compiler.ensure(!element.isResolved); |
| 1669 | 1721 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 type.element === compiler.boolClass || | 1899 type.element === compiler.boolClass || |
| 1848 type.element === compiler.numClass || | 1900 type.element === compiler.numClass || |
| 1849 type.element === compiler.intClass || | 1901 type.element === compiler.intClass || |
| 1850 type.element === compiler.doubleClass || | 1902 type.element === compiler.doubleClass || |
| 1851 type.element === compiler.stringClass || | 1903 type.element === compiler.stringClass || |
| 1852 type.element === compiler.nullClass || | 1904 type.element === compiler.nullClass || |
| 1853 type.element === compiler.functionClass); | 1905 type.element === compiler.functionClass); |
| 1854 } | 1906 } |
| 1855 } | 1907 } |
| 1856 | 1908 |
| 1857 class TypeDefinitionVisitor extends CommonResolverVisitor<Type> { | |
| 1858 Scope scope; | |
| 1859 TypeDeclarationElement element; | |
| 1860 TypeResolver typeResolver; | |
| 1861 | |
| 1862 TypeDefinitionVisitor(Compiler compiler, TypeDeclarationElement element) | |
| 1863 : this.element = element, | |
| 1864 scope = element.enclosingElement.buildScope(), | |
| 1865 typeResolver = new TypeResolver(compiler), | |
| 1866 super(compiler); | |
| 1867 | |
| 1868 void resolveTypeVariableBounds(NodeList node) { | |
| 1869 if (node === null) return; | |
| 1870 | |
| 1871 var nameSet = new Set<SourceString>(); | |
| 1872 // Resolve the bounds of type variables. | |
| 1873 Link<Type> typeLink = element.typeVariables; | |
| 1874 Link<Node> nodeLink = node.nodes; | |
| 1875 while (!nodeLink.isEmpty()) { | |
| 1876 TypeVariableType typeVariable = typeLink.head; | |
| 1877 SourceString typeName = typeVariable.name; | |
| 1878 TypeVariable typeNode = nodeLink.head; | |
| 1879 if (nameSet.contains(typeName)) { | |
| 1880 error(typeNode, MessageKind.DUPLICATE_TYPE_VARIABLE_NAME, [typeName]); | |
| 1881 } | |
| 1882 nameSet.add(typeName); | |
| 1883 | |
| 1884 TypeVariableElement variableElement = typeVariable.element; | |
| 1885 if (typeNode.bound !== null) { | |
| 1886 Type boundType = typeResolver.resolveTypeAnnotation( | |
| 1887 typeNode.bound, inScope: scope, onFailure: warning); | |
| 1888 if (boundType !== null && boundType.element == variableElement) { | |
| 1889 // TODO(johnniwinther): Check for more general cycles, like | |
| 1890 // [: <A extends B, B extends C, C extends B> :]. | |
| 1891 warning(node, MessageKind.CYCLIC_TYPE_VARIABLE, | |
| 1892 [variableElement.name]); | |
| 1893 } else if (boundType !== null) { | |
| 1894 variableElement.bound = boundType; | |
| 1895 } else { | |
| 1896 // TODO(johnniwinther): Should be an erroneous type. | |
| 1897 variableElement.bound = compiler.objectClass.computeType(compiler); | |
| 1898 } | |
| 1899 } else { | |
| 1900 variableElement.bound = compiler.objectClass.computeType(compiler); | |
| 1901 } | |
| 1902 nodeLink = nodeLink.tail; | |
| 1903 typeLink = typeLink.tail; | |
| 1904 } | |
| 1905 assert(typeLink.isEmpty()); | |
| 1906 } | |
| 1907 } | |
| 1908 | |
| 1909 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { | 1909 class VariableDefinitionsVisitor extends CommonResolverVisitor<SourceString> { |
| 1910 VariableDefinitions definitions; | 1910 VariableDefinitions definitions; |
| 1911 ResolverVisitor resolver; | 1911 ResolverVisitor resolver; |
| 1912 ElementKind kind; | 1912 ElementKind kind; |
| 1913 VariableListElement variables; | 1913 VariableListElement variables; |
| 1914 | 1914 |
| 1915 VariableDefinitionsVisitor(Compiler compiler, | 1915 VariableDefinitionsVisitor(Compiler compiler, |
| 1916 this.definitions, this.resolver, this.kind) | 1916 this.definitions, this.resolver, this.kind) |
| 1917 : super(compiler) | 1917 : super(compiler) |
| 1918 { | 1918 { |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2301 TopScope(LibraryElement library) : super(null, library); | 2301 TopScope(LibraryElement library) : super(null, library); |
| 2302 Element lookup(SourceString name) { | 2302 Element lookup(SourceString name) { |
| 2303 return library.find(name); | 2303 return library.find(name); |
| 2304 } | 2304 } |
| 2305 | 2305 |
| 2306 Element add(Element newElement) { | 2306 Element add(Element newElement) { |
| 2307 throw "Cannot add an element in the top scope"; | 2307 throw "Cannot add an element in the top scope"; |
| 2308 } | 2308 } |
| 2309 String toString() => '$element'; | 2309 String toString() => '$element'; |
| 2310 } | 2310 } |
| OLD | NEW |