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

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

Issue 9699033: Introduce FieldParameterElement. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments and create a separate map for the fields. 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return measure(() { 42 return measure(() {
43 switch (element.kind) { 43 switch (element.kind) {
44 case ElementKind.GENERATIVE_CONSTRUCTOR: 44 case ElementKind.GENERATIVE_CONSTRUCTOR:
45 case ElementKind.FUNCTION: 45 case ElementKind.FUNCTION:
46 case ElementKind.GETTER: 46 case ElementKind.GETTER:
47 case ElementKind.SETTER: 47 case ElementKind.SETTER:
48 return resolveMethodElement(element); 48 return resolveMethodElement(element);
49 49
50 case ElementKind.FIELD: 50 case ElementKind.FIELD:
51 case ElementKind.PARAMETER: 51 case ElementKind.PARAMETER:
52 case ElementKind.FIELD_PARAMETER:
52 return resolveVariableElement(element); 53 return resolveVariableElement(element);
53 54
54 default: 55 default:
55 compiler.unimplemented( 56 compiler.unimplemented(
56 "resolver", node: element.parseNode(compiler)); 57 "resolver", node: element.parseNode(compiler));
57 } 58 }
58 }); 59 });
59 } 60 }
60 61
61 SourceString getConstructorName(Send node) { 62 SourceString getConstructorName(Send node) {
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 // Put the parameters in scope. 642 // Put the parameters in scope.
642 FunctionParameters functionParameters = 643 FunctionParameters functionParameters =
643 function.computeParameters(compiler); 644 function.computeParameters(compiler);
644 Link<Node> parameterNodes = node.parameters.nodes; 645 Link<Node> parameterNodes = node.parameters.nodes;
645 functionParameters.forEachParameter((Element element) { 646 functionParameters.forEachParameter((Element element) {
646 if (element == functionParameters.optionalParameters.head) { 647 if (element == functionParameters.optionalParameters.head) {
647 NodeList nodes = parameterNodes.head; 648 NodeList nodes = parameterNodes.head;
648 parameterNodes = nodes.nodes; 649 parameterNodes = nodes.nodes;
649 } 650 }
650 VariableDefinitions variableDefinitions = parameterNodes.head; 651 VariableDefinitions variableDefinitions = parameterNodes.head;
651 defineElement(variableDefinitions.definitions.nodes.head, element); 652 Node parameterNode = variableDefinitions.definitions.nodes.head;
653 // Field parameters (this.x) are not visible inside the constructor. The
654 // fields they reference are visible, but must be resolved independently.
655 if (element.kind == ElementKind.FIELD_PARAMETER) {
656 useElement(parameterNode, element);
657 } else {
658 defineElement(variableDefinitions.definitions.nodes.head, element);
659 }
652 parameterNodes = parameterNodes.tail; 660 parameterNodes = parameterNodes.tail;
653 }); 661 });
654 } 662 }
655 663
656 Element visitClassNode(ClassNode node) { 664 Element visitClassNode(ClassNode node) {
657 cancel(node, "shouldn't be called"); 665 cancel(node, "shouldn't be called");
658 } 666 }
659 667
660 visitIn(Node node, Scope scope) { 668 visitIn(Node node, Scope scope) {
661 context = scope; 669 context = scope;
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 return element; 1426 return element;
1419 } 1427 }
1420 1428
1421 Element visitIdentifier(Identifier node) { 1429 Element visitIdentifier(Identifier node) {
1422 Element variables = new VariableListElement.node(currentDefinitions, 1430 Element variables = new VariableListElement.node(currentDefinitions,
1423 ElementKind.VARIABLE_LIST, enclosingElement); 1431 ElementKind.VARIABLE_LIST, enclosingElement);
1424 return new VariableElement(node.source, variables, 1432 return new VariableElement(node.source, variables,
1425 ElementKind.PARAMETER, enclosingElement, node: node); 1433 ElementKind.PARAMETER, enclosingElement, node: node);
1426 } 1434 }
1427 1435
1428 Element visitSend(Send node) { 1436 // The only valid [Send] can be in constructors and must be of the form
1429 Element element; 1437 // [:this.x:] (where [:x:] represents an instance field).
1438 FieldParameterElement visitSend(Send node) {
1439 FieldParameterElement element;
1430 if (node.receiver.asIdentifier() === null || 1440 if (node.receiver.asIdentifier() === null ||
1431 !node.receiver.asIdentifier().isThis()) { 1441 !node.receiver.asIdentifier().isThis()) {
1432 error(node, MessageKind.INVALID_PARAMETER, []); 1442 error(node, MessageKind.INVALID_PARAMETER, []);
1433 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { 1443 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) {
1434 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); 1444 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []);
1435 } else { 1445 } else {
1436 if (node.selector.asIdentifier() == null) { 1446 if (node.selector.asIdentifier() == null) {
1437 cancel(node, 1447 cancel(node,
1438 'internal error: unimplemented receiver on parameter send'); 1448 'internal error: unimplemented receiver on parameter send');
1439 } 1449 }
1440 SourceString name = node.selector.asIdentifier().source; 1450 SourceString name = node.selector.asIdentifier().source;
1441 element = currentClass.lookupLocalMember(name); 1451 Element fieldElement = currentClass.lookupLocalMember(name);
1442 if (element.kind !== ElementKind.FIELD) { 1452 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) {
1443 error(node, MessageKind.NOT_A_FIELD, [name]); 1453 error(node, MessageKind.NOT_A_FIELD, [name]);
1444 } else if (!element.isInstanceMember()) { 1454 } else if (!fieldElement.isInstanceMember()) {
1445 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); 1455 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]);
1446 } 1456 }
1457 Element variables = new VariableListElement.node(currentDefinitions,
1458 ElementKind.VARIABLE_LIST, enclosingElement);
1459 element = new FieldParameterElement(node.selector.asIdentifier().source,
1460 fieldElement, variables, enclosingElement, node);
1447 } 1461 }
1448 // TODO(ngeoffray): it's not right to put the field element in
1449 // the parameters element. Create another element instead.
1450 return element; 1462 return element;
1451 } 1463 }
1452 1464
1453 Element visitSendSet(SendSet node) { 1465 Element visitSendSet(SendSet node) {
1454 Element element; 1466 Element element;
1455 if (node.receiver != null) { 1467 if (node.receiver != null) {
1456 // TODO(ngeoffray): it's not right to put the field element in
1457 // the parameters element. Create another element instead.
1458 element = visitSend(node); 1468 element = visitSend(node);
1459 } else if (node.selector.asIdentifier() != null) { 1469 } else if (node.selector.asIdentifier() != null) {
1460 Element variables = new VariableListElement.node(currentDefinitions, 1470 Element variables = new VariableListElement.node(currentDefinitions,
1461 ElementKind.VARIABLE_LIST, enclosingElement); 1471 ElementKind.VARIABLE_LIST, enclosingElement);
1462 element = new VariableElement(node.selector.asIdentifier().source, 1472 element = new VariableElement(node.selector.asIdentifier().source,
1463 variables, ElementKind.PARAMETER, enclosingElement, node: node); 1473 variables, ElementKind.PARAMETER, enclosingElement, node: node);
1464 } 1474 }
1465 // Visit the value. The compile time constant handler will 1475 // Visit the value. The compile time constant handler will
1466 // make sure it's a compile time constant. 1476 // make sure it's a compile time constant.
1467 resolveExpression(node.arguments.head); 1477 resolveExpression(node.arguments.head);
(...skipping 10 matching lines...) Expand all
1478 LinkBuilder<Element> analyzeNodes(Link<Node> link) { 1488 LinkBuilder<Element> analyzeNodes(Link<Node> link) {
1479 LinkBuilder<Element> elements = new LinkBuilder<Element>(); 1489 LinkBuilder<Element> elements = new LinkBuilder<Element>();
1480 for (; !link.isEmpty(); link = link.tail) { 1490 for (; !link.isEmpty(); link = link.tail) {
1481 Element element = link.head.accept(this); 1491 Element element = link.head.accept(this);
1482 if (element != null) { 1492 if (element != null) {
1483 elements.addLast(element); 1493 elements.addLast(element);
1484 } else { 1494 } else {
1485 // If parameter is null, the current node should be the last, 1495 // If parameter is null, the current node should be the last,
1486 // and a list of optional named parameters. 1496 // and a list of optional named parameters.
1487 if (!link.tail.isEmpty() || (link.head is !NodeList)) { 1497 if (!link.tail.isEmpty() || (link.head is !NodeList)) {
1488 internalError(link.head, "expected expected optional parameters"); 1498 internalError(link.head, "expected optional parameters");
1489 } 1499 }
1490 } 1500 }
1491 } 1501 }
1492 return elements; 1502 return elements;
1493 } 1503 }
1494 1504
1495 static FunctionParameters analyze(Compiler compiler, 1505 static FunctionParameters analyze(Compiler compiler,
1496 FunctionElement element) { 1506 FunctionElement element) {
1497 FunctionExpression node = element.parseNode(compiler); 1507 FunctionExpression node = element.parseNode(compiler);
1498 SignatureResolver visitor = new SignatureResolver(compiler, element); 1508 SignatureResolver visitor = new SignatureResolver(compiler, element);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 class TopScope extends Scope { 1666 class TopScope extends Scope {
1657 LibraryElement get library() => element; 1667 LibraryElement get library() => element;
1658 1668
1659 TopScope(LibraryElement library) : super(null, library); 1669 TopScope(LibraryElement library) : super(null, library);
1660 Element lookup(SourceString name) => library.find(name); 1670 Element lookup(SourceString name) => library.find(name);
1661 1671
1662 Element add(Element element) { 1672 Element add(Element element) {
1663 throw "Cannot add an element in the top scope"; 1673 throw "Cannot add an element in the top scope";
1664 } 1674 }
1665 } 1675 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698