| OLD | NEW |
| 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 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 NodeList nodes = parameterNodes.head; | 649 NodeList nodes = parameterNodes.head; |
| 650 parameterNodes = nodes.nodes; | 650 parameterNodes = nodes.nodes; |
| 651 } | 651 } |
| 652 VariableDefinitions variableDefinitions = parameterNodes.head; | 652 VariableDefinitions variableDefinitions = parameterNodes.head; |
| 653 Node parameterNode = variableDefinitions.definitions.nodes.head; | 653 Node parameterNode = variableDefinitions.definitions.nodes.head; |
| 654 // Field parameters (this.x) are not visible inside the constructor. The | 654 // Field parameters (this.x) are not visible inside the constructor. The |
| 655 // fields they reference are visible, but must be resolved independently. | 655 // fields they reference are visible, but must be resolved independently. |
| 656 if (element.kind == ElementKind.FIELD_PARAMETER) { | 656 if (element.kind == ElementKind.FIELD_PARAMETER) { |
| 657 useElement(parameterNode, element); | 657 useElement(parameterNode, element); |
| 658 } else { | 658 } else { |
| 659 defineElement(variableDefinitions.definitions.nodes.head, element);
| 659 defineElement(variableDefinitions.definitions.nodes.head, element); |
| 660 } | 660 } |
| 661 parameterNodes = parameterNodes.tail; | 661 parameterNodes = parameterNodes.tail; |
| 662 }); | 662 }); |
| 663 } | 663 } |
| 664 | 664 |
| 665 Element visitClassNode(ClassNode node) { | 665 Element visitClassNode(ClassNode node) { |
| 666 cancel(node, "shouldn't be called"); | 666 cancel(node, "shouldn't be called"); |
| 667 } | 667 } |
| 668 | 668 |
| 669 visitIn(Node node, Scope scope) { | 669 visitIn(Node node, Scope scope) { |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 visitLabeledStatement(LabeledStatement node) { | 1084 visitLabeledStatement(LabeledStatement node) { |
| 1085 String labelName = node.label.source.slowToString(); | 1085 String labelName = node.label.source.slowToString(); |
| 1086 LabelElement existingElement = statementScope.lookupLabel(labelName); | 1086 LabelElement existingElement = statementScope.lookupLabel(labelName); |
| 1087 if (existingElement !== null) { | 1087 if (existingElement !== null) { |
| 1088 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); | 1088 warning(node.label, MessageKind.DUPLICATE_LABEL, [labelName]); |
| 1089 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); | 1089 warning(existingElement.label, MessageKind.EXISTING_LABEL, [labelName]); |
| 1090 } | 1090 } |
| 1091 Node body = node.getBody(); | 1091 Node body = node.getBody(); |
| 1092 TargetElement TargetElement = getOrCreateTargetElement(body); | 1092 TargetElement targetElement = getOrCreateTargetElement(body); |
| 1093 | 1093 |
| 1094 LabelElement element = TargetElement.addLabel(node.label, labelName); | 1094 LabelElement element = targetElement.addLabel(node.label, labelName); |
| 1095 statementScope.enterLabelScope(element); | 1095 statementScope.enterLabelScope(element); |
| 1096 visit(node.statement); | 1096 visit(node.statement); |
| 1097 statementScope.exitLabelScope(); | 1097 statementScope.exitLabelScope(); |
| 1098 if (element.isTarget) { | 1098 if (element.isTarget) { |
| 1099 mapping[node.label] = element; | 1099 mapping[node.label] = element; |
| 1100 } else { | 1100 } else { |
| 1101 warning(node.label, MessageKind.UNUSED_LABEL, [labelName]); | 1101 warning(node.label, MessageKind.UNUSED_LABEL, [labelName]); |
| 1102 } | 1102 } |
| 1103 if (!TargetElement.isBreakTarget && mapping[body] === TargetElement) { | 1103 if (!targetElement.isTarget && mapping[body] === targetElement) { |
| 1104 // If the body is itself a break or continue for another target, it | 1104 // If the body is itself a break or continue for another target, it |
| 1105 // might have updated its mapping to the label it actaully does target. | 1105 // might have updated its mapping to the target it actually does target. |
| 1106 mapping.remove(body); | 1106 mapping.remove(body); |
| 1107 } | 1107 } |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 visitLiteralMap(LiteralMap node) { | 1110 visitLiteralMap(LiteralMap node) { |
| 1111 node.visitChildren(this); | 1111 node.visitChildren(this); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 visitLiteralMapEntry(LiteralMapEntry node) { | 1114 visitLiteralMapEntry(LiteralMapEntry node) { |
| 1115 node.visitChildren(this); | 1115 node.visitChildren(this); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 SourceString name = node.selector.asIdentifier().source; | 1517 SourceString name = node.selector.asIdentifier().source; |
| 1518 Element fieldElement = currentClass.lookupLocalMember(name); | 1518 Element fieldElement = currentClass.lookupLocalMember(name); |
| 1519 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { | 1519 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { |
| 1520 error(node, MessageKind.NOT_A_FIELD, [name]); | 1520 error(node, MessageKind.NOT_A_FIELD, [name]); |
| 1521 } else if (!fieldElement.isInstanceMember()) { | 1521 } else if (!fieldElement.isInstanceMember()) { |
| 1522 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); | 1522 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); |
| 1523 } | 1523 } |
| 1524 Element variables = new VariableListElement.node(currentDefinitions, | 1524 Element variables = new VariableListElement.node(currentDefinitions, |
| 1525 ElementKind.VARIABLE_LIST, enclosingElement); | 1525 ElementKind.VARIABLE_LIST, enclosingElement); |
| 1526 element = new FieldParameterElement(node.selector.asIdentifier().source, | 1526 element = new FieldParameterElement(node.selector.asIdentifier().source, |
| 1527 fieldElement, variables, enclosingElement, node); | 1527 fieldElement, variables, enclosingElement, node); |
| 1528 } | 1528 } |
| 1529 return element; | 1529 return element; |
| 1530 } | 1530 } |
| 1531 | 1531 |
| 1532 Element visitSendSet(SendSet node) { | 1532 Element visitSendSet(SendSet node) { |
| 1533 Element element; | 1533 Element element; |
| 1534 if (node.receiver != null) { | 1534 if (node.receiver != null) { |
| 1535 element = visitSend(node); | 1535 element = visitSend(node); |
| 1536 } else if (node.selector.asIdentifier() != null) { | 1536 } else if (node.selector.asIdentifier() != null) { |
| 1537 Element variables = new VariableListElement.node(currentDefinitions, | 1537 Element variables = new VariableListElement.node(currentDefinitions, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1750 | 1750 |
| 1751 TopScope(LibraryElement library) : super(null, library); | 1751 TopScope(LibraryElement library) : super(null, library); |
| 1752 Element lookup(SourceString name) { | 1752 Element lookup(SourceString name) { |
| 1753 return library.find(name); | 1753 return library.find(name); |
| 1754 } | 1754 } |
| 1755 | 1755 |
| 1756 Element add(Element element) { | 1756 Element add(Element element) { |
| 1757 throw "Cannot add an element in the top scope"; | 1757 throw "Cannot add an element in the top scope"; |
| 1758 } | 1758 } |
| 1759 } | 1759 } |
| OLD | NEW |