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

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

Issue 10363003: Compute function types together with the parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move computation of function type. Created 8 years, 7 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 FunctionParameters resolveSignature(FunctionElement element) { 236 FunctionSignature resolveSignature(FunctionElement element) {
237 return measure(() => SignatureResolver.analyze(compiler, element)); 237 return measure(() => SignatureResolver.analyze(compiler, element));
238 } 238 }
239 239
240 error(Node node, MessageKind kind, [arguments = const []]) { 240 error(Node node, MessageKind kind, [arguments = const []]) {
241 ResolutionError message = new ResolutionError(kind, arguments); 241 ResolutionError message = new ResolutionError(kind, arguments);
242 compiler.reportError(node, message); 242 compiler.reportError(node, message);
243 } 243 }
244 } 244 }
245 245
246 class InitializerResolver { 246 class InitializerResolver {
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 if (type !== null) { 670 if (type !== null) {
671 mapping.setType(annotation, type); 671 mapping.setType(annotation, type);
672 useElement(annotation, type.element); 672 useElement(annotation, type.element);
673 } 673 }
674 return type; 674 return type;
675 } 675 }
676 676
677 void setupFunction(FunctionExpression node, FunctionElement function) { 677 void setupFunction(FunctionExpression node, FunctionElement function) {
678 context = new MethodScope(context, function); 678 context = new MethodScope(context, function);
679 // Put the parameters in scope. 679 // Put the parameters in scope.
680 FunctionParameters functionParameters = 680 FunctionSignature functionParameters =
681 function.computeParameters(compiler); 681 function.computeSignature(compiler);
682 Link<Node> parameterNodes = node.parameters.nodes; 682 Link<Node> parameterNodes = node.parameters.nodes;
683 functionParameters.forEachParameter((Element element) { 683 functionParameters.forEachParameter((Element element) {
684 if (element == functionParameters.optionalParameters.head) { 684 if (element == functionParameters.optionalParameters.head) {
685 NodeList nodes = parameterNodes.head; 685 NodeList nodes = parameterNodes.head;
686 parameterNodes = nodes.nodes; 686 parameterNodes = nodes.nodes;
687 } 687 }
688 VariableDefinitions variableDefinitions = parameterNodes.head; 688 VariableDefinitions variableDefinitions = parameterNodes.head;
689 Node parameterNode = variableDefinitions.definitions.nodes.head; 689 Node parameterNode = variableDefinitions.definitions.nodes.head;
690 initializerDo(parameterNode, (n) => n.accept(this)); 690 initializerDo(parameterNode, (n) => n.accept(this));
691 // Field parameters (this.x) are not visible inside the constructor. The 691 // Field parameters (this.x) are not visible inside the constructor. The
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 if (node.beginToken.stringValue !== '[') { 1632 if (node.beginToken.stringValue !== '[') {
1633 internalError(node, "expected optional parameters"); 1633 internalError(node, "expected optional parameters");
1634 } 1634 }
1635 LinkBuilder<Element> elements = analyzeNodes(node.nodes); 1635 LinkBuilder<Element> elements = analyzeNodes(node.nodes);
1636 optionalParameterCount = elements.length; 1636 optionalParameterCount = elements.length;
1637 optionalParameters = elements.toLink(); 1637 optionalParameters = elements.toLink();
1638 return null; 1638 return null;
1639 } 1639 }
1640 1640
1641 Element visitVariableDefinitions(VariableDefinitions node) { 1641 Element visitVariableDefinitions(VariableDefinitions node) {
1642 resolveType(node.type);
1643
1644 Link<Node> definitions = node.definitions.nodes; 1642 Link<Node> definitions = node.definitions.nodes;
1645 if (definitions.isEmpty()) { 1643 if (definitions.isEmpty()) {
1646 cancel(node, 'internal error: no parameter definition'); 1644 cancel(node, 'internal error: no parameter definition');
1647 return null; 1645 return null;
1648 } 1646 }
1649 if (!definitions.tail.isEmpty()) { 1647 if (!definitions.tail.isEmpty()) {
1650 cancel(definitions.tail.head, 'internal error: extra definition'); 1648 cancel(definitions.tail.head, 'internal error: extra definition');
1651 return null; 1649 return null;
1652 } 1650 }
1653 Node definition = definitions.head; 1651 Node definition = definitions.head;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 // If parameter is null, the current node should be the last, 1731 // If parameter is null, the current node should be the last,
1734 // and a list of optional named parameters. 1732 // and a list of optional named parameters.
1735 if (!link.tail.isEmpty() || (link.head is !NodeList)) { 1733 if (!link.tail.isEmpty() || (link.head is !NodeList)) {
1736 internalError(link.head, "expected optional parameters"); 1734 internalError(link.head, "expected optional parameters");
1737 } 1735 }
1738 } 1736 }
1739 } 1737 }
1740 return elements; 1738 return elements;
1741 } 1739 }
1742 1740
1743 static FunctionParameters analyze(Compiler compiler, 1741 static FunctionSignature analyze(Compiler compiler,
1744 FunctionElement element) { 1742 FunctionElement element) {
1745 FunctionExpression node = element.parseNode(compiler); 1743 FunctionExpression node =
1744 compiler.parser.measure(() => element.parseNode(compiler));
1746 SignatureResolver visitor = new SignatureResolver(compiler, element); 1745 SignatureResolver visitor = new SignatureResolver(compiler, element);
1747 Link<Node> nodes = node.parameters.nodes; 1746 Link<Node> nodes = node.parameters.nodes;
1748 LinkBuilder<Element> parameters = visitor.analyzeNodes(nodes); 1747 LinkBuilder<Element> parametersBuilder = visitor.analyzeNodes(nodes);
1749 return new FunctionParameters(parameters.toLink(), 1748 Link<Element> parameters = parametersBuilder.toLink();
1750 visitor.optionalParameters, 1749 Type returnType =
1751 parameters.length, 1750 compiler.resolveTypeAnnotation(element, node.returnType);
1752 visitor.optionalParameterCount); 1751 return new FunctionSignature(parameters,
1752 visitor.optionalParameters,
1753 parametersBuilder.length,
1754 visitor.optionalParameterCount,
1755 returnType);
1753 } 1756 }
1754 1757
1755 // TODO(ahe): This is temporary. 1758 // TODO(ahe): This is temporary.
1756 void resolveExpression(Node node) { 1759 void resolveExpression(Node node) {
1757 if (node == null) return; 1760 if (node == null) return;
1758 node.accept(new ResolverVisitor(compiler, enclosingElement)); 1761 node.accept(new ResolverVisitor(compiler, enclosingElement));
1759 } 1762 }
1760 1763
1761 // TODO(ahe): This is temporary. 1764 // TODO(ahe): This is temporary.
1762 void resolveType(Node node) {
1763 if (node == null) return;
1764 node.accept(new ResolverVisitor(compiler, enclosingElement));
1765 }
1766
1767 // TODO(ahe): This is temporary.
1768 ClassElement get currentClass() { 1765 ClassElement get currentClass() {
1769 return enclosingElement.isMember() 1766 return enclosingElement.isMember()
1770 ? enclosingElement.enclosingElement : null; 1767 ? enclosingElement.enclosingElement : null;
1771 } 1768 }
1772 } 1769 }
1773 1770
1774 class ConstructorResolver extends CommonResolverVisitor<Element> { 1771 class ConstructorResolver extends CommonResolverVisitor<Element> {
1775 final ResolverVisitor resolver; 1772 final ResolverVisitor resolver;
1776 ConstructorResolver(Compiler compiler, this.resolver) : super(compiler); 1773 ConstructorResolver(Compiler compiler, this.resolver) : super(compiler);
1777 1774
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1923 1920
1924 TopScope(LibraryElement library) : super(null, library); 1921 TopScope(LibraryElement library) : super(null, library);
1925 Element lookup(SourceString name) { 1922 Element lookup(SourceString name) {
1926 return library.find(name); 1923 return library.find(name);
1927 } 1924 }
1928 1925
1929 Element add(Element newElement) { 1926 Element add(Element newElement) {
1930 throw "Cannot add an element in the top scope"; 1927 throw "Cannot add an element in the top scope";
1931 } 1928 }
1932 } 1929 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/native_handler.dart ('k') | lib/compiler/implementation/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698