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

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

Issue 8949039: Make sure a class is resolved before looking up its elements. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
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
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 target = compiler.universe.find(opName); 301 target = compiler.universe.find(opName);
302 } else if (node.receiver === null) { 302 } else if (node.receiver === null) {
303 target = context.lookup(name); 303 target = context.lookup(name);
304 if (target == null && !enclosingElement.isInstanceMember()) { 304 if (target == null && !enclosingElement.isInstanceMember()) {
305 error(node, MessageKind.CANNOT_RESOLVE, [name]); 305 error(node, MessageKind.CANNOT_RESOLVE, [name]);
306 } 306 }
307 } else if (receiver === null) { 307 } else if (receiver === null) {
308 return null; 308 return null;
309 } else if (receiver.kind === ElementKind.CLASS) { 309 } else if (receiver.kind === ElementKind.CLASS) {
310 ClassElement receiverClass = receiver; 310 ClassElement receiverClass = receiver;
311 target = receiverClass.lookupLocalElement(name); 311 target = receiverClass.resolve(compiler).lookupLocalElement(name);
312 if (target == null) { 312 if (target == null) {
313 error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]); 313 error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]);
314 } else if (target.isInstanceMember()) { 314 } else if (target.isInstanceMember()) {
315 error(node, MessageKind.MEMBER_NOT_STATIC, [receiver, name]); 315 error(node, MessageKind.MEMBER_NOT_STATIC, [receiver, name]);
316 } 316 }
317 } 317 }
318 return target; 318 return target;
319 } 319 }
320 320
321 visitSend(Send node) { 321 visitSend(Send node) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 405 }
406 406
407 visitNewExpression(NewExpression node) { 407 visitNewExpression(NewExpression node) {
408 visit(node.send.argumentsNode); 408 visit(node.send.argumentsNode);
409 409
410 ClassElement cls = visit(node.send.selector); 410 ClassElement cls = visit(node.send.selector);
411 Element constructor = null; 411 Element constructor = null;
412 if (cls !== null) { 412 if (cls !== null) {
413 // TODO(ngeoffray): set constructor-name correctly. 413 // TODO(ngeoffray): set constructor-name correctly.
414 SourceString name = cls.name; 414 SourceString name = cls.name;
415 // TODO(ngeoffray): define what isResolved means. Also, pass the 415 constructor = cls.resolve(compiler).lookupLocalElement(name);
416 // needed element to resolve?
417 if (!cls.isResolved) compiler.resolveType(cls);
418 constructor = cls.lookupLocalElement(name);
419 if (name == cls.name 416 if (name == cls.name
420 && constructor === null 417 && constructor === null
421 && node.send.argumentsNode.isEmpty()) { 418 && node.send.argumentsNode.isEmpty()) {
422 constructor = cls.getSynthesizedConstructor(); 419 constructor = cls.getSynthesizedConstructor();
423 } 420 }
424 if (constructor === null) { 421 if (constructor === null) {
425 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR, [node]); 422 error(node, MessageKind.CANNOT_FIND_CONSTRUCTOR, [node]);
426 } 423 }
427 } 424 }
428 425
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 return resolver.mapping[node.definitions.nodes.head]; 552 return resolver.mapping[node.definitions.nodes.head];
556 } 553 }
557 554
558 visit(Node node) => node.accept(this); 555 visit(Node node) => node.accept(this);
559 } 556 }
560 557
561 class Scope { 558 class Scope {
562 final Element element; 559 final Element element;
563 final Scope parent; 560 final Scope parent;
564 561
565 Map<SourceString, Element> get elements() => const {};
566
567 Scope(this.parent, this.element); 562 Scope(this.parent, this.element);
568 abstract Element add(Element element); 563 abstract Element add(Element element);
569 abstract Element lookup(Element element); 564 abstract Element lookup(Element element);
570 } 565 }
571 566
572 class MethodScope extends Scope { 567 class MethodScope extends Scope {
573 final Map<SourceString, Element> elements; 568 final Map<SourceString, Element> elements;
574 569
575 MethodScope(Scope parent, Element element) 570 MethodScope(Scope parent, Element element)
576 : super(parent, element), this.elements = {}; 571 : super(parent, element), this.elements = {};
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 class TopScope extends Scope { 611 class TopScope extends Scope {
617 Universe universe; 612 Universe universe;
618 613
619 TopScope(Universe this.universe) : super(null, null); 614 TopScope(Universe this.universe) : super(null, null);
620 Element lookup(SourceString name) => universe.find(name); 615 Element lookup(SourceString name) => universe.find(name);
621 616
622 Element add(Element element) { 617 Element add(Element element) {
623 throw "Cannot add an element in the top scope"; 618 throw "Cannot add an element in the top scope";
624 } 619 }
625 } 620 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698