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

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: Fix typo. 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 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 cancel(node, 'function type parameters not supported'); 1421 cancel(node, 'function type parameters not supported');
1414 } 1422 }
1415 currentDefinitions = node; 1423 currentDefinitions = node;
1416 Element element = definition.accept(this); 1424 Element element = definition.accept(this);
1417 currentDefinitions = null; 1425 currentDefinitions = null;
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);
ngeoffray 2012/03/15 10:06:01 Maybe add a helper method for creating the variabl
floitsch 2012/03/15 14:11:04 Only created twice now, and once as a VariableElem
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 FieldParameterElement visitSend(Send node) {
ngeoffray 2012/03/15 10:06:01 Please add a comment that the only valid Send you
floitsch 2012/03/15 14:11:04 Done.
1429 Element element; 1437 FieldParameterElement element;
1430 if (node.receiver.asIdentifier() === null || 1438 if (node.receiver.asIdentifier() === null ||
1431 !node.receiver.asIdentifier().isThis()) { 1439 !node.receiver.asIdentifier().isThis()) {
1432 error(node, MessageKind.INVALID_PARAMETER, []); 1440 error(node, MessageKind.INVALID_PARAMETER, []);
1433 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { 1441 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) {
1434 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); 1442 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []);
1435 } else { 1443 } else {
1436 if (node.selector.asIdentifier() == null) { 1444 if (node.selector.asIdentifier() == null) {
1437 cancel(node, 1445 cancel(node,
1438 'internal error: unimplemented receiver on parameter send'); 1446 'internal error: unimplemented receiver on parameter send');
1439 } 1447 }
1440 SourceString name = node.selector.asIdentifier().source; 1448 SourceString name = node.selector.asIdentifier().source;
1441 element = currentClass.lookupLocalMember(name); 1449 Element fieldElement = currentClass.lookupLocalMember(name);
1442 if (element.kind !== ElementKind.FIELD) { 1450 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) {
1443 error(node, MessageKind.NOT_A_FIELD, [name]); 1451 error(node, MessageKind.NOT_A_FIELD, [name]);
1444 } else if (!element.isInstanceMember()) { 1452 } else if (!fieldElement.isInstanceMember()) {
1445 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); 1453 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]);
1446 } 1454 }
1455 Element variables = new VariableListElement.node(currentDefinitions,
1456 ElementKind.VARIABLE_LIST, enclosingElement);
ngeoffray 2012/03/15 10:06:01 4 space
floitsch 2012/03/15 14:11:04 Done.
1457 element = new FieldParameterElement(node.selector.asIdentifier().source,
1458 fieldElement, variables, enclosingElement, node: node);
ngeoffray 2012/03/15 10:06:01 ditto
floitsch 2012/03/15 14:11:04 Done.
1447 } 1459 }
1448 // TODO(ngeoffray): it's not right to put the field element in
1449 // the parameters element. Create another element instead.
1450 return element; 1460 return element;
1451 } 1461 }
1452 1462
1453 Element visitSendSet(SendSet node) { 1463 Element visitSendSet(SendSet node) {
1454 Element element; 1464 Element element;
1455 if (node.receiver != null) { 1465 if (node.receiver != null) {
1456 // TODO(ngeoffray): it's not right to put the field element in 1466 FieldParameterElement fieldParameterElement = visitSend(node);
1457 // the parameters element. Create another element instead. 1467 Element fieldElement = fieldParameterElement.fieldElement;
1458 element = visitSend(node); 1468 Element variables = new VariableListElement.node(currentDefinitions,
1469 ElementKind.VARIABLE_LIST, enclosingElement);
ngeoffray 2012/03/15 10:06:01 Why do you need to create a new element? fieldPara
floitsch 2012/03/15 14:11:04 Done.
1470 element = new FieldParameterElement(node.selector.asIdentifier().source,
1471 fieldElement, variables, enclosingElement, node: node);
1459 } else if (node.selector.asIdentifier() != null) { 1472 } else if (node.selector.asIdentifier() != null) {
1460 Element variables = new VariableListElement.node(currentDefinitions, 1473 Element variables = new VariableListElement.node(currentDefinitions,
1461 ElementKind.VARIABLE_LIST, enclosingElement); 1474 ElementKind.VARIABLE_LIST, enclosingElement);
1462 element = new VariableElement(node.selector.asIdentifier().source, 1475 element = new VariableElement(node.selector.asIdentifier().source,
1463 variables, ElementKind.PARAMETER, enclosingElement, node: node); 1476 variables, ElementKind.PARAMETER, enclosingElement, node: node);
1464 } 1477 }
1465 // Visit the value. The compile time constant handler will 1478 // Visit the value. The compile time constant handler will
1466 // make sure it's a compile time constant. 1479 // make sure it's a compile time constant.
1467 resolveExpression(node.arguments.head); 1480 resolveExpression(node.arguments.head);
1468 compiler.enqueue(new WorkItem.toCompile(element)); 1481 compiler.enqueue(new WorkItem.toCompile(element));
1469 return element; 1482 return element;
1470 } 1483 }
1471 1484
1472 Element visitFunctionExpression(FunctionExpression node) { 1485 Element visitFunctionExpression(FunctionExpression node) {
1473 // This is a function typed parameter. 1486 // This is a function typed parameter.
1474 // TODO(ahe): Resolve the function type. 1487 // TODO(ahe): Resolve the function type.
1475 return visit(node.name); 1488 return visit(node.name);
1476 } 1489 }
1477 1490
1478 LinkBuilder<Element> analyzeNodes(Link<Node> link) { 1491 LinkBuilder<Element> analyzeNodes(Link<Node> link) {
1479 LinkBuilder<Element> elements = new LinkBuilder<Element>(); 1492 LinkBuilder<Element> elements = new LinkBuilder<Element>();
1480 for (; !link.isEmpty(); link = link.tail) { 1493 for (; !link.isEmpty(); link = link.tail) {
1481 Element element = link.head.accept(this); 1494 Element element = link.head.accept(this);
1482 if (element != null) { 1495 if (element != null) {
1483 elements.addLast(element); 1496 elements.addLast(element);
1484 } else { 1497 } else {
1485 // If parameter is null, the current node should be the last, 1498 // If parameter is null, the current node should be the last,
1486 // and a list of optional named parameters. 1499 // and a list of optional named parameters.
1487 if (!link.tail.isEmpty() || (link.head is !NodeList)) { 1500 if (!link.tail.isEmpty() || (link.head is !NodeList)) {
1488 internalError(link.head, "expected expected optional parameters"); 1501 internalError(link.head, "expected optional parameters");
1489 } 1502 }
1490 } 1503 }
1491 } 1504 }
1492 return elements; 1505 return elements;
1493 } 1506 }
1494 1507
1495 static FunctionParameters analyze(Compiler compiler, 1508 static FunctionParameters analyze(Compiler compiler,
1496 FunctionElement element) { 1509 FunctionElement element) {
1497 FunctionExpression node = element.parseNode(compiler); 1510 FunctionExpression node = element.parseNode(compiler);
1498 SignatureResolver visitor = new SignatureResolver(compiler, element); 1511 SignatureResolver visitor = new SignatureResolver(compiler, element);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 class TopScope extends Scope { 1669 class TopScope extends Scope {
1657 LibraryElement get library() => element; 1670 LibraryElement get library() => element;
1658 1671
1659 TopScope(LibraryElement library) : super(null, library); 1672 TopScope(LibraryElement library) : super(null, library);
1660 Element lookup(SourceString name) => library.find(name); 1673 Element lookup(SourceString name) => library.find(name);
1661 1674
1662 Element add(Element element) { 1675 Element add(Element element) {
1663 throw "Cannot add an element in the top scope"; 1676 throw "Cannot add an element in the top scope";
1664 } 1677 }
1665 } 1678 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698