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

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

Issue 9378008: Support anonymous functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
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
« no previous file with comments | « no previous file | frog/leg/ssa/builder.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) 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 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 424 }
425 } else { 425 } else {
426 ClassElement cls = element; 426 ClassElement cls = element;
427 compiler.resolver.toResolve.add(element); 427 compiler.resolver.toResolve.add(element);
428 // TODO(ahe): This should be a Type. 428 // TODO(ahe): This should be a Type.
429 useElement(node, element); 429 useElement(node, element);
430 } 430 }
431 return element; 431 return element;
432 } 432 }
433 433
434 Element defineElement(Node node, Element element) { 434 Element defineElement(Node node, Element element,
435 [bool doAddToScope = true]) {
435 compiler.ensure(element !== null); 436 compiler.ensure(element !== null);
436 mapping[node] = element; 437 mapping[node] = element;
437 Element existing = context.add(element); 438 if (doAddToScope) {
438 if (existing != element) { 439 Element existing = context.add(element);
439 error(node, MessageKind.DUPLICATE_DEFINITION, [node]); 440 if (existing != element) {
441 error(node, MessageKind.DUPLICATE_DEFINITION, [node]);
442 }
440 } 443 }
441 return element; 444 return element;
442 } 445 }
443 446
444 Element useElement(Node node, Element element) { 447 Element useElement(Node node, Element element) {
445 if (element === null) return null; 448 if (element === null) return null;
446 return mapping[node] = element; 449 return mapping[node] = element;
447 } 450 }
448 451
449 void setupFunction(FunctionExpression node, FunctionElement function) { 452 void setupFunction(FunctionExpression node, FunctionElement function) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 visitFor(For node) { 492 visitFor(For node) {
490 Scope scope = new BlockScope(context); 493 Scope scope = new BlockScope(context);
491 visitIn(node.initializer, scope); 494 visitIn(node.initializer, scope);
492 visitIn(node.condition, scope); 495 visitIn(node.condition, scope);
493 visitIn(node.update, scope); 496 visitIn(node.update, scope);
494 visitIn(node.body, scope); 497 visitIn(node.body, scope);
495 } 498 }
496 499
497 visitFunctionExpression(FunctionExpression node) { 500 visitFunctionExpression(FunctionExpression node) {
498 visit(node.returnType); 501 visit(node.returnType);
502 SourceString name;
499 if (node.name === null) { 503 if (node.name === null) {
500 cancel(node, "anonymous functions are not implemented"); 504 name = const SourceString("");
505 } else {
506 name = node.name.asIdentifier().source;
501 } 507 }
502 SourceString name = node.name.asIdentifier().source;
503 FunctionElement enclosingElement = new FunctionElement.node( 508 FunctionElement enclosingElement = new FunctionElement.node(
504 name, node, ElementKind.FUNCTION, new Modifiers.empty(), 509 name, node, ElementKind.FUNCTION, new Modifiers.empty(),
505 context.element); 510 context.element);
506 defineElement(node, enclosingElement); 511 defineElement(node, enclosingElement, doAddToScope: node.name !== null);
507 setupFunction(node, enclosingElement); 512 setupFunction(node, enclosingElement);
508 513
509 visit(node.body); 514 visit(node.body);
510 context = context.parent; 515 context = context.parent;
511 return enclosingElement; 516 return enclosingElement;
512 } 517 }
513 518
514 visitIf(If node) { 519 visitIf(If node) {
515 visit(node.condition); 520 visit(node.condition);
516 visit(node.thenPart); 521 visit(node.thenPart);
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 class TopScope extends Scope { 1154 class TopScope extends Scope {
1150 LibraryElement get library() => element; 1155 LibraryElement get library() => element;
1151 1156
1152 TopScope(LibraryElement library) : super(null, library); 1157 TopScope(LibraryElement library) : super(null, library);
1153 Element lookup(SourceString name) => library.find(name); 1158 Element lookup(SourceString name) => library.find(name);
1154 1159
1155 Element add(Element element) { 1160 Element add(Element element) {
1156 throw "Cannot add an element in the top scope"; 1161 throw "Cannot add an element in the top scope";
1157 } 1162 }
1158 } 1163 }
OLDNEW
« no previous file with comments | « no previous file | frog/leg/ssa/builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698