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

Side by Side Diff: dart/frog/leg/resolver.dart

Issue 9417031: Mock up all remaining core library implementation classes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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 } 8 }
9 9
10 class TreeElementMapping implements TreeElements { 10 class TreeElementMapping implements TreeElements {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 if (isConstructor) { 68 if (isConstructor) {
69 resolveConstructorImplementation(element, tree); 69 resolveConstructorImplementation(element, tree);
70 } 70 }
71 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 71 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
72 visitor.useElement(tree, element); 72 visitor.useElement(tree, element);
73 visitor.setupFunction(tree, element); 73 visitor.setupFunction(tree, element);
74 74
75 if (tree.initializers != null) { 75 if (tree.initializers != null) {
76 new InitializerResolver(visitor, element).resolveInitializers(tree); 76 new InitializerResolver(visitor, element).resolveInitializers(tree);
77 } 77 }
78 if (isConstructor) {
79 visitor.inInstanceContext = true;
kasperl 2012/02/17 06:03:31 Do you want to reset the flag to what ever it was
ahe 2012/02/17 07:40:47 I think this is more broken than it lets out. Late
ngeoffray 2012/02/17 10:03:50 It wasn't intended to be a solution for the resolv
ngeoffray 2012/02/17 10:03:50 I don't think you need to set the flag. It's alrea
ahe 2012/02/17 16:26:46 Done.
80 }
78 visitor.visit(tree.body); 81 visitor.visit(tree.body);
79 82
80 // Resolve the type annotations encountered in the method. 83 // Resolve the type annotations encountered in the method.
81 Link<ClassElement> newResolvedClasses = const EmptyLink<ClassElement>(); 84 Link<ClassElement> newResolvedClasses = const EmptyLink<ClassElement>();
82 while (!toResolve.isEmpty()) { 85 while (!toResolve.isEmpty()) {
83 ClassElement classElement = toResolve.removeFirst(); 86 ClassElement classElement = toResolve.removeFirst();
84 if (!classElement.isResolved) { 87 if (!classElement.isResolved) {
85 classElement.resolve(compiler); 88 classElement.resolve(compiler);
86 } 89 }
87 newResolvedClasses = newResolvedClasses.prepend(classElement); 90 newResolvedClasses = newResolvedClasses.prepend(classElement);
(...skipping 28 matching lines...) Expand all
116 name = name.replaceFirst(cls.name.toString(), 119 name = name.replaceFirst(cls.name.toString(),
117 defaultClass.name.toString()); 120 defaultClass.name.toString());
118 constructor.implementation = 121 constructor.implementation =
119 defaultClass.lookupConstructor(new SourceString(name)); 122 defaultClass.lookupConstructor(new SourceString(name));
120 123
121 if (constructor.implementation === null 124 if (constructor.implementation === null
122 && new SourceString(name) == defaultClass.name 125 && new SourceString(name) == defaultClass.name
123 && constructor.functionParameters.parameterCount === 0) { 126 && constructor.functionParameters.parameterCount === 0) {
124 constructor.implementation = defaultClass.getSynthesizedConstructor(); 127 constructor.implementation = defaultClass.getSynthesizedConstructor();
125 } 128 }
126 }
127 if (constructor === null) {
128 error(node.send, MessageKind.CANNOT_FIND_CONSTRUCTOR, [node.send]);
129 return null;
130 }
131 129
132 if (constructor.implementation === null) { 130 if (constructor.implementation === null) {
133 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]); 131 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]);
132 }
134 } 133 }
135 } 134 }
136 135
137 TreeElements resolveVariableElement(Element element) { 136 TreeElements resolveVariableElement(Element element) {
138 Node tree = element.parseNode(compiler); 137 Node tree = element.parseNode(compiler);
139 ResolverVisitor visitor = new ResolverVisitor(compiler, element); 138 ResolverVisitor visitor = new ResolverVisitor(compiler, element);
140 if (tree is SendSet) { 139 if (tree is SendSet) {
141 SendSet send = tree; 140 SendSet send = tree;
142 visitor.visit(send.arguments.head); 141 visitor.visit(send.arguments.head);
143 } 142 }
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 Element target = null; 653 Element target = null;
655 if (node.selector.asIdentifier() === null) { 654 if (node.selector.asIdentifier() === null) {
656 // We are calling a closure returned from an expression. 655 // We are calling a closure returned from an expression.
657 assert(node.selector.asExpression() !== null); 656 assert(node.selector.asExpression() !== null);
658 assert(resolvedReceiver === null); 657 assert(resolvedReceiver === null);
659 visit(node.selector); 658 visit(node.selector);
660 } else { 659 } else {
661 SourceString name = node.selector.asIdentifier().source; 660 SourceString name = node.selector.asIdentifier().source;
662 if (node.receiver === null) { 661 if (node.receiver === null) {
663 target = lookup(node, name); 662 target = lookup(node, name);
664 if (target === null && !enclosingElement.isInstanceMember()) { 663 if (target === null && !inInstanceContext) {
665 error(node, MessageKind.CANNOT_RESOLVE, [name]); 664 error(node, MessageKind.CANNOT_RESOLVE, [name]);
666 } 665 }
667 } else if (node.isSuperCall) { 666 } else if (node.isSuperCall) {
668 if (currentClass !== null) { 667 if (currentClass !== null) {
669 ClassElement superElement = currentClass.superclass; 668 ClassElement superElement = currentClass.superclass;
670 if (superElement !== null) { 669 if (superElement !== null) {
671 // TODO(ngeoffray): The lookup should continue on super 670 // TODO(ngeoffray): The lookup should continue on super
672 // classes. 671 // classes.
673 target = superElement.lookupLocalMember(name); 672 target = superElement.lookupLocalMember(name);
674 } 673 }
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 element = new VariableElement(node.selector.asIdentifier().source, 1226 element = new VariableElement(node.selector.asIdentifier().source,
1228 variables, ElementKind.PARAMETER, enclosingElement, node: node); 1227 variables, ElementKind.PARAMETER, enclosingElement, node: node);
1229 } 1228 }
1230 // Visit the value. The compile time constant handler will 1229 // Visit the value. The compile time constant handler will
1231 // make sure it's a compile time constant. 1230 // make sure it's a compile time constant.
1232 resolveExpression(node.arguments.head); 1231 resolveExpression(node.arguments.head);
1233 compiler.enqueue(new WorkItem.toCompile(element)); 1232 compiler.enqueue(new WorkItem.toCompile(element));
1234 return element; 1233 return element;
1235 } 1234 }
1236 1235
1236 Element visitFunctionExpression(FunctionExpression node) {
1237 // This is a function typed parameter.
1238 // TODO(ahe): Resolve the function type.
1239 return visit(node.name);
1240 }
1241
1237 LinkBuilder<Element> analyzeNodes(Link<Node> link) { 1242 LinkBuilder<Element> analyzeNodes(Link<Node> link) {
1238 LinkBuilder<Element> elements = new LinkBuilder<Element>(); 1243 LinkBuilder<Element> elements = new LinkBuilder<Element>();
1239 for (; !link.isEmpty(); link = link.tail) { 1244 for (; !link.isEmpty(); link = link.tail) {
1240 Element element = link.head.accept(this); 1245 Element element = link.head.accept(this);
1241 if (element != null) { 1246 if (element != null) {
1242 elements.addLast(element); 1247 elements.addLast(element);
1243 } else { 1248 } else {
1244 // If parameter is null, the current node should be the last, 1249 // If parameter is null, the current node should be the last,
1245 // and a list of optional named parameters. 1250 // and a list of optional named parameters.
1246 if (!link.tail.isEmpty() || (link.head is !NodeList)) { 1251 if (!link.tail.isEmpty() || (link.head is !NodeList)) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 class TopScope extends Scope { 1341 class TopScope extends Scope {
1337 LibraryElement get library() => element; 1342 LibraryElement get library() => element;
1338 1343
1339 TopScope(LibraryElement library) : super(null, library); 1344 TopScope(LibraryElement library) : super(null, library);
1340 Element lookup(SourceString name) => library.find(name); 1345 Element lookup(SourceString name) => library.find(name);
1341 1346
1342 Element add(Element element) { 1347 Element add(Element element) {
1343 throw "Cannot add an element in the top scope"; 1348 throw "Cannot add an element in the top scope";
1344 } 1349 }
1345 } 1350 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698