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

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

Issue 9019018: Fix resolver for fields uses in constructors. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years 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
« no previous file with comments | « no previous file | dart/frog/tests/leg/src/ResolverTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 class TreeElements { 5 class TreeElements {
6 Map<Node, Element> map; 6 Map<Node, Element> map;
7 TreeElements() : map = new LinkedHashMap<Node, Element>(); 7 TreeElements() : map = new LinkedHashMap<Node, Element>();
8 operator []=(Node node, Element element) => map[node] = element; 8 operator []=(Node node, Element element) => map[node] = element;
9 operator [](Node node) => map[node]; 9 operator [](Node node) => map[node];
10 } 10 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 final Compiler compiler; 112 final Compiler compiler;
113 final TreeElements mapping; 113 final TreeElements mapping;
114 final Element enclosingElement; 114 final Element enclosingElement;
115 bool inInstanceContext; 115 bool inInstanceContext;
116 Scope context; 116 Scope context;
117 117
118 ResolverVisitor(Compiler compiler, Element element) 118 ResolverVisitor(Compiler compiler, Element element)
119 : this.compiler = compiler, 119 : this.compiler = compiler,
120 this.mapping = new TreeElements(), 120 this.mapping = new TreeElements(),
121 this.enclosingElement = element, 121 this.enclosingElement = element,
122 inInstanceContext = element.isInstanceMember(), 122 inInstanceContext =
123 element.isInstanceMember() || element.kind == ElementKind.CONSTRUCTOR,
123 this.context = element.isMember() 124 this.context = element.isMember()
124 ? new ClassScope(element.enclosingElement, compiler.universe) 125 ? new ClassScope(element.enclosingElement, compiler.universe)
125 : new TopScope(compiler.universe); 126 : new TopScope(compiler.universe);
126 127
127 ResolverVisitor.from(ResolverVisitor other) 128 ResolverVisitor.from(ResolverVisitor other)
128 : compiler = other.compiler, 129 : compiler = other.compiler,
129 mapping = other.mapping, 130 mapping = other.mapping,
130 enclosingElement = other.enclosingElement, 131 enclosingElement = other.enclosingElement,
131 inInstanceContext = other.inInstanceContext, 132 inInstanceContext = other.inInstanceContext,
132 context = other.context; 133 context = other.context;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 Identifier selector = node.selector; 369 Identifier selector = node.selector;
369 SourceString name = selector.source; 370 SourceString name = selector.source;
370 // No need to assign an element for a logical operation. 371 // No need to assign an element for a logical operation.
371 if (isLogicalOperator(selector)) return null; 372 if (isLogicalOperator(selector)) return null;
372 373
373 Element target = null; 374 Element target = null;
374 if (node.isOperator) { 375 if (node.isOperator) {
375 SourceString opName = mapOperatorToMethodName(name, node.isPrefix); 376 SourceString opName = mapOperatorToMethodName(name, node.isPrefix);
376 target = compiler.universe.find(opName); 377 target = compiler.universe.find(opName);
377 } else if (node.receiver === null) { 378 } else if (node.receiver === null) {
378 target = visit(selector); 379 target = lookup(node, name);
379 if (target == null && !enclosingElement.isInstanceMember()) { 380 if (target == null && !enclosingElement.isInstanceMember()) {
380 error(node, MessageKind.CANNOT_RESOLVE, [name]); 381 error(node, MessageKind.CANNOT_RESOLVE, [name]);
381 } 382 }
382 } else if (receiver === null) { 383 } else if (receiver === null) {
383 return null; 384 return null;
384 } else if (receiver.kind === ElementKind.CLASS) { 385 } else if (receiver.kind === ElementKind.CLASS) {
385 ClassElement receiverClass = receiver; 386 ClassElement receiverClass = receiver;
386 target = receiverClass.resolve(compiler).lookupLocalMember(name); 387 target = receiverClass.resolve(compiler).lookupLocalMember(name);
387 if (target == null) { 388 if (target == null) {
388 error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]); 389 error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]);
(...skipping 23 matching lines...) Expand all
412 SourceString name = mapAssignmentOperatorToMethodName(op.source); 413 SourceString name = mapAssignmentOperatorToMethodName(op.source);
413 Element operatorElement = compiler.universe.find(name); 414 Element operatorElement = compiler.universe.find(name);
414 useElement(op, operatorElement); 415 useElement(op, operatorElement);
415 // Resolve the getter for the lhs (receiver+selector). 416 // Resolve the getter for the lhs (receiver+selector).
416 // Currently this is the same as the setter. 417 // Currently this is the same as the setter.
417 // TODO(ngeoffray): Adapt for fields. 418 // TODO(ngeoffray): Adapt for fields.
418 Element getter; 419 Element getter;
419 if (node.isIndex) { 420 if (node.isIndex) {
420 getter = target; 421 getter = target;
421 } else { 422 } else {
422 getter = visit(node.selector); 423 // TODO(ngeoffray): Find the getter from the setter.
424 getter = context.lookup(node.selector.asIdentifier().source);
423 } 425 }
424 useElement(node.selector, getter); 426 useElement(node.selector, getter);
425 } 427 }
426 if (node.isIndex) { 428 if (node.isIndex) {
427 assert(target.name.stringValue === 'index'); 429 assert(target.name.stringValue === 'index');
428 target = compiler.universe.find(const SourceString('indexSet')); 430 target = compiler.universe.find(const SourceString('indexSet'));
429 } 431 }
430 return useElement(node, target); 432 return useElement(node, target);
431 } 433 }
432 434
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 class TopScope extends Scope { 688 class TopScope extends Scope {
687 Universe universe; 689 Universe universe;
688 690
689 TopScope(Universe this.universe) : super(null, null); 691 TopScope(Universe this.universe) : super(null, null);
690 Element lookup(SourceString name) => universe.find(name); 692 Element lookup(SourceString name) => universe.find(name);
691 693
692 Element add(Element element) { 694 Element add(Element element) {
693 throw "Cannot add an element in the top scope"; 695 throw "Cannot add an element in the top scope";
694 } 696 }
695 } 697 }
OLDNEW
« no previous file with comments | « no previous file | dart/frog/tests/leg/src/ResolverTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698