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

Unified Diff: sdk/lib/_internal/compiler/implementation/scanner/listener.dart

Issue 24488004: Implement correct scoping rules for variables. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 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: sdk/lib/_internal/compiler/implementation/scanner/listener.dart
diff --git a/sdk/lib/_internal/compiler/implementation/scanner/listener.dart b/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
index dc912fb6dc637361375f5330459e94aaddb676c0..7eefb79a8798e7599dca94dc2736d097d01875bd 100644
--- a/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
+++ b/sdk/lib/_internal/compiler/implementation/scanner/listener.dart
@@ -1072,12 +1072,24 @@ class ElementListener extends Listener {
}
NodeList makeNodeList(int count, Token beginToken, Token endToken,
- String delimiter) {
+ String delimiter,
+ {List<VariableDefinitions> declarations}) {
ahe 2013/09/26 07:48:07 Please don't use named arguments. They add call ov
Link<Node> poppedNodes = const Link<Node>();
for (; count > 0; --count) {
// This effectively reverses the order of nodes so they end up
// in correct (source) order.
- poppedNodes = poppedNodes.prepend(popNode());
+ Node node = popNode();
+ poppedNodes = poppedNodes.prepend(node);
+ if (declarations != null) {
+ Node potentialDeclaration = node;
+ if (node.asLabeledStatement() != null) {
+ LabeledStatement labelled = potentialDeclaration;
+ potentialDeclaration = labelled.statement;
+ }
+ if (potentialDeclaration.asVariableDefinitions() != null) {
+ declarations.add(potentialDeclaration);
+ }
+ }
}
SourceString sourceDelimiter =
(delimiter == null) ? null : new SourceString(delimiter);
@@ -1454,7 +1466,10 @@ class NodeListener extends ElementListener {
if (count == 0 && beginToken == null) {
pushNode(new EmptyStatement(endToken));
} else {
- pushNode(new Block(makeNodeList(count, beginToken, endToken, null)));
+ List<VariableDefinitions> declarations = <VariableDefinitions>[];
ahe 2013/09/26 07:48:07 This is what we have a link builder for. Please us
+ pushNode(new Block(makeNodeList(count, beginToken, endToken, null,
+ declarations: declarations),
+ new Link<VariableDefinitions>.fromList(declarations)));
}
}
@@ -1529,7 +1544,10 @@ class NodeListener extends ElementListener {
}
void endBlock(int count, Token beginToken, Token endToken) {
- pushNode(new Block(makeNodeList(count, beginToken, endToken, null)));
+ List<VariableDefinitions> declarations = <VariableDefinitions>[];
+ pushNode(new Block(makeNodeList(count, beginToken, endToken, null,
+ declarations: declarations),
+ new Link<VariableDefinitions>.fromList(declarations)));
}
void endThrowExpression(Token throwToken, Token endToken) {
@@ -1730,11 +1748,13 @@ class NodeListener extends ElementListener {
void handleSwitchCase(int labelCount, int caseCount,
Token defaultKeyword, int statementCount,
Token firstToken, Token endToken) {
- NodeList statements = makeNodeList(statementCount, null, null, null);
+ List<VariableDefinitions> declarations = <VariableDefinitions>[];
+ NodeList statements = makeNodeList(statementCount, null, null, null,
+ declarations: declarations);
NodeList labelsAndCases =
makeNodeList(labelCount + caseCount, null, null, null);
pushNode(new SwitchCase(labelsAndCases, defaultKeyword, statements,
- firstToken));
+ firstToken, new Link<VariableDefinitions>.fromList(declarations)));
}
void handleBreakStatement(bool hasTarget,

Powered by Google App Engine
This is Rietveld 408576698