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

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

Issue 9567041: Implement prefixes in NewExpression. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 1430
1431 visitTypeAnnotation(TypeAnnotation node) { 1431 visitTypeAnnotation(TypeAnnotation node) {
1432 // TODO(ahe): Do not ignore type arguments. 1432 // TODO(ahe): Do not ignore type arguments.
1433 return visit(node.typeName); 1433 return visit(node.typeName);
1434 } 1434 }
1435 1435
1436 visitSend(Send node) { 1436 visitSend(Send node) {
1437 Element e = visit(node.receiver); 1437 Element e = visit(node.receiver);
1438 if (e === null) return null; // TODO(ahe): Return erroneous element. 1438 if (e === null) return null; // TODO(ahe): Return erroneous element.
1439 1439
1440 Identifier name = node.selector.asIdentifier();
1441 if (name === null) {
karlklose 2012/03/07 12:34:39 This could fit in one line.
ahe 2012/03/07 21:56:08 Done.
1442 internalError(node.selector, 'unexpected node');
1443 }
1444
1440 if (e.kind === ElementKind.CLASS) { 1445 if (e.kind === ElementKind.CLASS) {
1441 ClassElement cls = e; 1446 ClassElement cls = e;
1442 cls.resolve(compiler); 1447 cls.resolve(compiler);
1443 compiler.resolver.toResolve.add(cls); 1448 compiler.resolver.toResolve.add(cls);
1444 if (cls.isInterface() && (cls.defaultClass === null)) { 1449 if (cls.isInterface() && (cls.defaultClass === null)) {
1445 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE, 1450 error(node.receiver, MessageKind.CANNOT_INSTANTIATE_INTERFACE,
1446 [cls.name]); 1451 [cls.name]);
1447 } 1452 }
1448 Identifier name = node.selector.asIdentifier();
1449 if (name === null) {
1450 internalError(node.selector, 'unexpected node');
1451 }
1452 SourceString constructorName = 1453 SourceString constructorName =
1453 Elements.constructConstructorName(cls.name, name.source); 1454 Elements.constructConstructorName(cls.name, name.source);
1454 FunctionElement constructor = cls.lookupConstructor(constructorName); 1455 FunctionElement constructor = cls.lookupConstructor(constructorName);
1455 if (constructor === null) { 1456 if (constructor === null) {
1456 error(name, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]); 1457 error(name, MessageKind.CANNOT_FIND_CONSTRUCTOR, [name]);
1457 } 1458 }
1458 e = constructor; 1459 e = constructor;
1460 } else if (e.kind === ElementKind.PREFIX) {
1461 PrefixElement prefix = e;
1462 e = prefix.library.lookupLocalMember(name.source);
1463 if (e === null) {
1464 error(name, MessageKind.CANNOT_RESOLVE, [name]);
1465 // TODO(ahe): Return erroneous element.
1466 } else if (e.kind !== ElementKind.CLASS) {
1467 error(node, MessageKind.NOT_A_TYPE, [name]);
1468 }
1459 } else { 1469 } else {
1460 internalError(node.resolve, 'unexpected element $e'); 1470 internalError(node.receiver, 'unexpected element $e');
1461 } 1471 }
1462 return e; 1472 return e;
1463 } 1473 }
1464 1474
1465 Element visitIdentifier(Identifier node) { 1475 Element visitIdentifier(Identifier node) {
1466 SourceString name = node.source; 1476 SourceString name = node.source;
1467 Element e = resolver.lookup(node, name); 1477 Element e = resolver.lookup(node, name);
1468 if (e === null) { 1478 if (e === null) {
1469 error(node, MessageKind.CANNOT_RESOLVE, [name]); 1479 error(node, MessageKind.CANNOT_RESOLVE, [name]);
1470 // TODO(ahe): Return erroneous element. 1480 // TODO(ahe): Return erroneous element.
1471 } else if (e.kind !== ElementKind.CLASS) { 1481 } else if (e.kind !== ElementKind.CLASS && e.kind !== ElementKind.PREFIX) {
1472 error(node, MessageKind.NOT_A_TYPE, [name]); 1482 error(node, MessageKind.NOT_A_TYPE, [name]);
1473 } 1483 }
1474 return e; 1484 return e;
1475 } 1485 }
1476 } 1486 }
1477 1487
1478 class Scope { 1488 class Scope {
1479 final Element element; 1489 final Element element;
1480 final Scope parent; 1490 final Scope parent;
1481 1491
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 class TopScope extends Scope { 1539 class TopScope extends Scope {
1530 LibraryElement get library() => element; 1540 LibraryElement get library() => element;
1531 1541
1532 TopScope(LibraryElement library) : super(null, library); 1542 TopScope(LibraryElement library) : super(null, library);
1533 Element lookup(SourceString name) => library.find(name); 1543 Element lookup(SourceString name) => library.find(name);
1534 1544
1535 Element add(Element element) { 1545 Element add(Element element) {
1536 throw "Cannot add an element in the top scope"; 1546 throw "Cannot add an element in the top scope";
1537 } 1547 }
1538 } 1548 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698