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

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

Issue 10441071: Use the typedef arity to know how to invoke a closure given by the dom. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 6 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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if (element.isResolved) return; 226 if (element.isResolved) return;
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) {
ahe 2012/05/29 15:43:49 Wrap in compiler.withCurrentElement
ngeoffray 2012/05/29 15:51:42 Done.
237 return measure(() => SignatureResolver.analyze(compiler, element)); 237 FunctionExpression node =
238 compiler.parser.measure(() => element.parseNode(compiler));
239 return measure(() => SignatureResolver.analyze(
240 compiler, node.parameters, node.returnType, element));
241 }
242
243 FunctionSignature resolveTypedef(TypedefElement element) {
ahe 2012/05/29 15:43:49 Wrap in compiler.withCurrentElement
ngeoffray 2012/05/29 15:51:42 Done.
244 Typedef node =
245 compiler.parser.measure(() => element.parseNode(compiler));
246 return measure(() => SignatureResolver.analyze(
247 compiler, node.formals, node.returnType, element));
248 }
249
250 FunctionType computeFunctionType(Element element,
251 FunctionSignature signature) {
252 LinkBuilder<Type> parameterTypes = new LinkBuilder<Type>();
253 for (Link<Element> link = signature.requiredParameters;
254 !link.isEmpty();
255 link = link.tail) {
256 parameterTypes.addLast(link.head.computeType(compiler));
257 // TODO(karlklose): optional parameters.
258 }
259 return new FunctionType(signature.returnType,
260 parameterTypes.toLink(),
261 element);
238 } 262 }
239 263
240 error(Node node, MessageKind kind, [arguments = const []]) { 264 error(Node node, MessageKind kind, [arguments = const []]) {
241 ResolutionError message = new ResolutionError(kind, arguments); 265 ResolutionError message = new ResolutionError(kind, arguments);
242 compiler.reportError(node, message); 266 compiler.reportError(node, message);
243 } 267 }
244 } 268 }
245 269
246 class InitializerResolver { 270 class InitializerResolver {
247 final ResolverVisitor visitor; 271 final ResolverVisitor visitor;
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT); 1147 report(node.typeArguments, MessageKind.MISSING_TYPE_ARGUMENT);
1124 } 1148 }
1125 } 1149 }
1126 if (cls.typeParameters.length == 0) { 1150 if (cls.typeParameters.length == 0) {
1127 // Return the canonical type if it has no type parameters. 1151 // Return the canonical type if it has no type parameters.
1128 type = cls.computeType(compiler); 1152 type = cls.computeType(compiler);
1129 } else { 1153 } else {
1130 type = new InterfaceType(cls, arguments.toLink()); 1154 type = new InterfaceType(cls, arguments.toLink());
1131 } 1155 }
1132 } else if (element.isTypedef()) { 1156 } else if (element.isTypedef()) {
1133 // TODO(ngeoffray): This is a hack to help us get support for the 1157 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()) { 1158 } else if (element.isTypeVariable()) {
1140 type = element.computeType(compiler); 1159 type = element.computeType(compiler);
1141 } else { 1160 } else {
1142 compiler.cancel("unexpected element kind ${element.kind}", 1161 compiler.cancel("unexpected element kind ${element.kind}",
1143 node: node); 1162 node: node);
1144 } 1163 }
1145 } 1164 }
1146 return useType(node, type); 1165 return useType(node, type);
1147 } 1166 }
1148 1167
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
1753 // and a list of optional named parameters. 1772 // and a list of optional named parameters.
1754 if (!link.tail.isEmpty() || (link.head is !NodeList)) { 1773 if (!link.tail.isEmpty() || (link.head is !NodeList)) {
1755 internalError(link.head, "expected optional parameters"); 1774 internalError(link.head, "expected optional parameters");
1756 } 1775 }
1757 } 1776 }
1758 } 1777 }
1759 return elements; 1778 return elements;
1760 } 1779 }
1761 1780
1762 static FunctionSignature analyze(Compiler compiler, 1781 static FunctionSignature analyze(Compiler compiler,
1763 FunctionElement element) { 1782 NodeList formalParameters,
1764 FunctionExpression node = 1783 Node returnNode,
1765 compiler.parser.measure(() => element.parseNode(compiler)); 1784 Element element) {
1766 SignatureResolver visitor = new SignatureResolver(compiler, element); 1785 SignatureResolver visitor = new SignatureResolver(compiler, element);
1767 Link<Node> nodes = node.parameters.nodes; 1786 LinkBuilder<Element> parametersBuilder =
1768 LinkBuilder<Element> parametersBuilder = visitor.analyzeNodes(nodes); 1787 visitor.analyzeNodes(formalParameters.nodes);
1769 Link<Element> parameters = parametersBuilder.toLink(); 1788 Link<Element> parameters = parametersBuilder.toLink();
1770 Type returnType = 1789 Type returnType =
1771 compiler.resolveTypeAnnotation(element, node.returnType); 1790 compiler.resolveTypeAnnotation(element, returnNode);
1772 return new FunctionSignature(parameters, 1791 return new FunctionSignature(parameters,
1773 visitor.optionalParameters, 1792 visitor.optionalParameters,
1774 parametersBuilder.length, 1793 parametersBuilder.length,
1775 visitor.optionalParameterCount, 1794 visitor.optionalParameterCount,
1776 returnType); 1795 returnType);
1777 } 1796 }
1778 1797
1779 // TODO(ahe): This is temporary. 1798 // TODO(ahe): This is temporary.
1780 void resolveExpression(Node node) { 1799 void resolveExpression(Node node) {
1781 if (node == null) return; 1800 if (node == null) return;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 1960
1942 TopScope(LibraryElement library) : super(null, library); 1961 TopScope(LibraryElement library) : super(null, library);
1943 Element lookup(SourceString name) { 1962 Element lookup(SourceString name) {
1944 return library.find(name); 1963 return library.find(name);
1945 } 1964 }
1946 1965
1947 Element add(Element newElement) { 1966 Element add(Element newElement) {
1948 throw "Cannot add an element in the top scope"; 1967 throw "Cannot add an element in the top scope";
1949 } 1968 }
1950 } 1969 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698