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

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

Issue 9166010: Implement super calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')
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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 165
166 visit(Node node) { 166 visit(Node node) {
167 if (node == null) return null; 167 if (node == null) return null;
168 return node.accept(this); 168 return node.accept(this);
169 } 169 }
170 170
171 visitIdentifier(Identifier node) { 171 visitIdentifier(Identifier node) {
172 if (node.isThis()) { 172 if (node.isThis()) {
173 if (!inInstanceContext) error(node, MessageKind.NO_THIS_IN_STATIC); 173 if (!inInstanceContext) error(node, MessageKind.NO_THIS_IN_STATIC);
174 return null; 174 return null;
175 } else if (node.isSuper()) {
176 if (!inInstanceContext) error(node, MessageKind.NO_SUPER_IN_STATIC);
177 return null;
175 } else { 178 } else {
176 Element element = lookup(node, node.source); 179 Element element = lookup(node, node.source);
177 if (element == null) { 180 if (element == null) {
178 error(node, MessageKind.CANNOT_RESOLVE, [node]); 181 error(node, MessageKind.CANNOT_RESOLVE, [node]);
179 } 182 }
180 return useElement(node, element); 183 return useElement(node, element);
181 } 184 }
182 } 185 }
183 186
184 visitTypeAnnotation(TypeAnnotation node) { 187 visitTypeAnnotation(TypeAnnotation node) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 322
320 Identifier selector = node.selector.asIdentifier(); 323 Identifier selector = node.selector.asIdentifier();
321 if (selector === null) { 324 if (selector === null) {
322 // We are calling a closure returned from an expression. 325 // We are calling a closure returned from an expression.
323 assert(node.selector.asExpression() !== null); 326 assert(node.selector.asExpression() !== null);
324 assert(receiver === null); 327 assert(receiver === null);
325 visit(node.selector); 328 visit(node.selector);
326 return null; 329 return null;
327 } 330 }
328 331
329 SourceString name = selector.source; 332 SourceString name = selector.asIdentifier().source;
330 // No need to assign an element for a logical operation. 333 // No need to assign an element for a logical operation.
331 if (isLogicalOperator(selector)) return null; 334 if (isLogicalOperator(selector)) return null;
332 335
333 Element target = null; 336 Element target = null;
334 if (node.isOperator) { 337 if (node.receiver !== null
338 && node.receiver.asIdentifier() !== null
339 && node.receiver.asIdentifier().isSuper()) {
340 ClassElement thisElement = enclosingElement.enclosingElement;
ngeoffray 2012/01/10 16:52:50 I think I'd prefer having a classElement field in
karlklose 2012/01/11 12:45:17 Done, added field currentClass.
341 ClassElement superElement = thisElement.superClass;
342 if (superElement === null) {
ngeoffray 2012/01/10 16:52:50 Should we attach the objectElement to the superEle
karlklose 2012/01/11 12:45:17 Done.
343 superElement = compiler.universe.find(compiler.types.OBJECT);
344 }
345 target = superElement.lookupLocalMember(name);
346 if (target == null) {
347 error(node, MessageKind.METHOD_NOT_FOUND, [superElement.name, name]);
348 }
349 } else if (node.isOperator) {
335 return null; 350 return null;
336 } else if (node.receiver === null) { 351 } else if (node.receiver === null) {
337 target = lookup(node, name); 352 target = lookup(node, name);
338 if (target == null && !enclosingElement.isInstanceMember()) { 353 if (target == null && !enclosingElement.isInstanceMember()) {
339 error(node, MessageKind.CANNOT_RESOLVE, [name]); 354 error(node, MessageKind.CANNOT_RESOLVE, [name]);
340 } 355 }
341 } else if (receiver === null) { 356 } else if (receiver === null) {
342 return null; 357 return null;
343 } else if (receiver.kind === ElementKind.CLASS) { 358 } else if (receiver.kind === ElementKind.CLASS) {
344 ClassElement receiverClass = receiver; 359 ClassElement receiverClass = receiver;
345 target = receiverClass.resolve(compiler).lookupLocalMember(name); 360 target = receiverClass.resolve(compiler).lookupLocalMember(name);
346 if (target == null) { 361 if (target == null) {
347 error(node, MessageKind.METHOD_NOT_FOUND, [receiver, name]); 362 error(node, MessageKind.METHOD_NOT_FOUND, [receiver.name, name]);
348 } else if (target.isInstanceMember()) { 363 } else if (target.isInstanceMember()) {
349 error(node, MessageKind.MEMBER_NOT_STATIC, [receiver, name]); 364 error(node, MessageKind.MEMBER_NOT_STATIC, [receiver.name, name]);
350 } 365 }
351 } 366 }
352 return target; 367 return target;
353 } 368 }
354 369
355 visitSend(Send node) { 370 visitSend(Send node) {
356 Element target = resolveSend(node); 371 Element target = resolveSend(node);
357 // TODO(ngeoffray): If target is a field, check that there's a 372 // TODO(ngeoffray): If target is a field, check that there's a
358 // getter. 373 // getter.
359 return useElement(node, target); 374 return useElement(node, target);
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 class TopScope extends Scope { 729 class TopScope extends Scope {
715 Universe universe; 730 Universe universe;
716 731
717 TopScope(Universe this.universe) : super(null, null); 732 TopScope(Universe this.universe) : super(null, null);
718 Element lookup(SourceString name) => universe.find(name); 733 Element lookup(SourceString name) => universe.find(name);
719 734
720 Element add(Element element) { 735 Element add(Element element) {
721 throw "Cannot add an element in the top scope"; 736 throw "Cannot add an element in the top scope";
722 } 737 }
723 } 738 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | frog/leg/ssa/builder.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698