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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: frog/leg/resolver.dart
diff --git a/frog/leg/resolver.dart b/frog/leg/resolver.dart
index 3b5390ad5fec7e21a9e4e231c73c5156450a5902..7939b55ea863f8c00175b0c3d36e77be67d892cf 100644
--- a/frog/leg/resolver.dart
+++ b/frog/leg/resolver.dart
@@ -49,6 +49,7 @@ class ResolverTask extends CompilerTask {
case ElementKind.FIELD:
case ElementKind.PARAMETER:
+ case ElementKind.FIELD_PARAMETER:
return resolveVariableElement(element);
default:
@@ -648,7 +649,14 @@ class ResolverVisitor extends CommonResolverVisitor<Element> {
parameterNodes = nodes.nodes;
}
VariableDefinitions variableDefinitions = parameterNodes.head;
- defineElement(variableDefinitions.definitions.nodes.head, element);
+ Node parameterNode = variableDefinitions.definitions.nodes.head;
+ // Field parameters (this.x) are not visible inside the constructor. The
+ // fields they reference are visible, but must be resolved independently.
+ if (element.kind == ElementKind.FIELD_PARAMETER) {
+ useElement(parameterNode, element);
+ } else {
+ defineElement(variableDefinitions.definitions.nodes.head, element);
+ }
parameterNodes = parameterNodes.tail;
});
}
@@ -1425,8 +1433,8 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
ElementKind.PARAMETER, enclosingElement, node: node);
}
- Element visitSend(Send node) {
- Element element;
+ 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.
+ FieldParameterElement element;
if (node.receiver.asIdentifier() === null ||
!node.receiver.asIdentifier().isThis()) {
error(node, MessageKind.INVALID_PARAMETER, []);
@@ -1438,24 +1446,29 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
'internal error: unimplemented receiver on parameter send');
}
SourceString name = node.selector.asIdentifier().source;
- element = currentClass.lookupLocalMember(name);
- if (element.kind !== ElementKind.FIELD) {
+ Element fieldElement = currentClass.lookupLocalMember(name);
+ if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) {
error(node, MessageKind.NOT_A_FIELD, [name]);
- } else if (!element.isInstanceMember()) {
+ } else if (!fieldElement.isInstanceMember()) {
error(node, MessageKind.NOT_INSTANCE_FIELD, [name]);
}
+ Element variables = new VariableListElement.node(currentDefinitions,
+ ElementKind.VARIABLE_LIST, enclosingElement);
ngeoffray 2012/03/15 10:06:01 4 space
floitsch 2012/03/15 14:11:04 Done.
+ element = new FieldParameterElement(node.selector.asIdentifier().source,
+ fieldElement, variables, enclosingElement, node: node);
ngeoffray 2012/03/15 10:06:01 ditto
floitsch 2012/03/15 14:11:04 Done.
}
- // TODO(ngeoffray): it's not right to put the field element in
- // the parameters element. Create another element instead.
return element;
}
Element visitSendSet(SendSet node) {
Element element;
if (node.receiver != null) {
- // TODO(ngeoffray): it's not right to put the field element in
- // the parameters element. Create another element instead.
- element = visitSend(node);
+ FieldParameterElement fieldParameterElement = visitSend(node);
+ Element fieldElement = fieldParameterElement.fieldElement;
+ Element variables = new VariableListElement.node(currentDefinitions,
+ 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.
+ element = new FieldParameterElement(node.selector.asIdentifier().source,
+ fieldElement, variables, enclosingElement, node: node);
} else if (node.selector.asIdentifier() != null) {
Element variables = new VariableListElement.node(currentDefinitions,
ElementKind.VARIABLE_LIST, enclosingElement);
@@ -1485,7 +1498,7 @@ class SignatureResolver extends CommonResolverVisitor<Element> {
// If parameter is null, the current node should be the last,
// and a list of optional named parameters.
if (!link.tail.isEmpty() || (link.head is !NodeList)) {
- internalError(link.head, "expected expected optional parameters");
+ internalError(link.head, "expected optional parameters");
}
}
}

Powered by Google App Engine
This is Rietveld 408576698