| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 measure(() { | 227 measure(() { |
| 228 ClassNode tree = element.parseNode(compiler); | 228 ClassNode tree = element.parseNode(compiler); |
| 229 ClassResolverVisitor visitor = | 229 ClassResolverVisitor visitor = |
| 230 new ClassResolverVisitor(compiler, element.getLibrary(), element); | 230 new ClassResolverVisitor(compiler, element.getLibrary(), element); |
| 231 visitor.visit(tree); | 231 visitor.visit(tree); |
| 232 element.isResolved = true; | 232 element.isResolved = true; |
| 233 }); | 233 }); |
| 234 } | 234 } |
| 235 | 235 |
| 236 FunctionSignature resolveSignature(FunctionElement element) { | 236 FunctionSignature resolveSignature(FunctionElement element) { |
| 237 return measure(() => SignatureResolver.analyze(compiler, element)); | 237 return compiler.withCurrentElement(element, () { |
| 238 FunctionExpression node = |
| 239 compiler.parser.measure(() => element.parseNode(compiler)); |
| 240 return measure(() => SignatureResolver.analyze( |
| 241 compiler, node.parameters, node.returnType, element)); |
| 242 }); |
| 243 } |
| 244 |
| 245 FunctionSignature resolveTypedef(TypedefElement element) { |
| 246 return compiler.withCurrentElement(element, () { |
| 247 Typedef node = |
| 248 compiler.parser.measure(() => element.parseNode(compiler)); |
| 249 return measure(() => SignatureResolver.analyze( |
| 250 compiler, node.formals, node.returnType, element)); |
| 251 }); |
| 252 } |
| 253 |
| 254 FunctionType computeFunctionType(Element element, |
| 255 FunctionSignature signature) { |
| 256 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>(); |
| 257 for (Link<Element> link = signature.requiredParameters; |
| 258 !link.isEmpty(); |
| 259 link = link.tail) { |
| 260 parameterTypes.addLast(link.head.computeType(compiler)); |
| 261 // TODO(karlklose): optional parameters. |
| 262 } |
| 263 return new FunctionType(signature.returnType, |
| 264 parameterTypes.toLink(), |
| 265 element); |
| 238 } | 266 } |
| 239 | 267 |
| 240 error(Node node, MessageKind kind, [arguments = const []]) { | 268 error(Node node, MessageKind kind, [arguments = const []]) { |
| 241 ResolutionError message = new ResolutionError(kind, arguments); | 269 ResolutionError message = new ResolutionError(kind, arguments); |
| 242 compiler.reportError(node, message); | 270 compiler.reportError(node, message); |
| 243 } | 271 } |
| 244 } | 272 } |
| 245 | 273 |
| 246 class InitializerResolver { | 274 class InitializerResolver { |
| 247 final ResolverVisitor visitor; | 275 final ResolverVisitor visitor; |
| (...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); | 1151 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); |
| 1124 } | 1152 } |
| 1125 } | 1153 } |
| 1126 if (cls.typeParameters.length == 0) { | 1154 if (cls.typeParameters.length == 0) { |
| 1127 // Return the canonical type if it has no type parameters. | 1155 // Return the canonical type if it has no type parameters. |
| 1128 type = cls.computeType(compiler); | 1156 type = cls.computeType(compiler); |
| 1129 } else { | 1157 } else { |
| 1130 type = new InterfaceType(cls, arguments.toLink()); | 1158 type = new InterfaceType(cls, arguments.toLink()); |
| 1131 } | 1159 } |
| 1132 } else if (element.isTypedef()) { | 1160 } else if (element.isTypedef()) { |
| 1133 // TODO(ngeoffray): This is a hack to help us get support for the | 1161 type = element.computeType(compiler); |
| 1134 // DOM library. | |
| 1135 // TODO(ngeoffray): The list of types for the argument is wrong. | |
| 1136 type = new FunctionType(compiler.types.dynamicType, | |
| 1137 const EmptyLink<Type>(), | |
| 1138 element); | |
| 1139 } else if (element.isTypeVariable()) { | 1162 } else if (element.isTypeVariable()) { |
| 1140 type = element.computeType(compiler); | 1163 type = element.computeType(compiler); |
| 1141 } else { | 1164 } else { |
| 1142 compiler.cancel("unexpected element kind ${element.kind}", | 1165 compiler.cancel("unexpected element kind ${element.kind}", |
| 1143 node: node); | 1166 node: node); |
| 1144 } | 1167 } |
| 1145 } | 1168 } |
| 1146 return useType(node, type); | 1169 return useType(node, type); |
| 1147 } | 1170 } |
| 1148 | 1171 |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 // and a list of optional named parameters. | 1776 // and a list of optional named parameters. |
| 1754 if (!link.tail.isEmpty() || (link.head is !NodeList)) { | 1777 if (!link.tail.isEmpty() || (link.head is !NodeList)) { |
| 1755 internalError(link.head, "expected optional parameters"); | 1778 internalError(link.head, "expected optional parameters"); |
| 1756 } | 1779 } |
| 1757 } | 1780 } |
| 1758 } | 1781 } |
| 1759 return elements; | 1782 return elements; |
| 1760 } | 1783 } |
| 1761 | 1784 |
| 1762 static FunctionSignature analyze(Compiler compiler, | 1785 static FunctionSignature analyze(Compiler compiler, |
| 1763 FunctionElement element) { | 1786 NodeList formalParameters, |
| 1764 FunctionExpression node = | 1787 Node returnNode, |
| 1765 compiler.parser.measure(() => element.parseNode(compiler)); | 1788 Element element) { |
| 1766 SignatureResolver visitor = new SignatureResolver(compiler, element); | 1789 SignatureResolver visitor = new SignatureResolver(compiler, element); |
| 1767 Link<Node> nodes = node.parameters.nodes; | 1790 LinkBuilder<Element> parametersBuilder = |
| 1768 LinkBuilder<Element> parametersBuilder = visitor.analyzeNodes(nodes); | 1791 visitor.analyzeNodes(formalParameters.nodes); |
| 1769 Link<Element> parameters = parametersBuilder.toLink(); | 1792 Link<Element> parameters = parametersBuilder.toLink(); |
| 1770 Type returnType = | 1793 Type returnType = |
| 1771 compiler.resolveTypeAnnotation(element, node.returnType); | 1794 compiler.resolveTypeAnnotation(element, returnNode); |
| 1772 return new FunctionSignature(parameters, | 1795 return new FunctionSignature(parameters, |
| 1773 visitor.optionalParameters, | 1796 visitor.optionalParameters, |
| 1774 parametersBuilder.length, | 1797 parametersBuilder.length, |
| 1775 visitor.optionalParameterCount, | 1798 visitor.optionalParameterCount, |
| 1776 returnType); | 1799 returnType); |
| 1777 } | 1800 } |
| 1778 | 1801 |
| 1779 // TODO(ahe): This is temporary. | 1802 // TODO(ahe): This is temporary. |
| 1780 void resolveExpression(Node node) { | 1803 void resolveExpression(Node node) { |
| 1781 if (node == null) return; | 1804 if (node == null) return; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1941 | 1964 |
| 1942 TopScope(LibraryElement library) : super(null, library); | 1965 TopScope(LibraryElement library) : super(null, library); |
| 1943 Element lookup(SourceString name) { | 1966 Element lookup(SourceString name) { |
| 1944 return library.find(name); | 1967 return library.find(name); |
| 1945 } | 1968 } |
| 1946 | 1969 |
| 1947 Element add(Element newElement) { | 1970 Element add(Element newElement) { |
| 1948 throw "Cannot add an element in the top scope"; | 1971 throw "Cannot add an element in the top scope"; |
| 1949 } | 1972 } |
| 1950 } | 1973 } |
| OLD | NEW |