Index: pkg/analyzer2dart/lib/src/cps_generator.dart |
diff --git a/pkg/analyzer2dart/lib/src/cps_generator.dart b/pkg/analyzer2dart/lib/src/cps_generator.dart |
index 60d2335c201499798b7af8265e46b176356cbcec..45e2701aadb657f4aeb05cc62820cb5f0eab4951 100644 |
--- a/pkg/analyzer2dart/lib/src/cps_generator.dart |
+++ b/pkg/analyzer2dart/lib/src/cps_generator.dart |
@@ -31,6 +31,8 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
Source get currentSource => element.source; |
+ analyzer.LibraryElement get currentLibrary => element.library; |
+ |
ir.Node visit(AstNode node) => node.accept(this); |
@override |
@@ -343,4 +345,45 @@ class CpsGeneratingVisitor extends SemanticVisitor<ir.Node> |
irBuilder.buildWhile(buildCondition: subbuild(node.condition), |
buildBody: subbuild(node.body)); |
} |
+ |
+ @override |
+ visitDeclaredIdentifier(DeclaredIdentifier node) { |
+ giveUp(node, "Unexpected node: DeclaredIdentifier"); |
+ } |
+ |
+ @override |
+ visitForEachStatement(ForEachStatement node) { |
+ SubbuildFunction buildVariableDeclaration; |
+ dart2js.Element variableElement; |
+ Selector variableSelector; |
+ if (node.identifier != null) { |
+ AccessSemantics accessSemantics = |
+ node.identifier.accept(ACCESS_SEMANTICS_VISITOR); |
+ if (accessSemantics.kind == AccessKind.DYNAMIC) { |
+ variableSelector = new Selector.setter( |
+ node.identifier.name, converter.convertElement(currentLibrary)); |
+ } else if (accessSemantics.element != null) { |
+ variableElement = converter.convertElement(accessSemantics.element); |
+ variableSelector = new Selector.setter( |
+ variableElement.name, |
+ converter.convertElement(accessSemantics.element.library)); |
+ } else { |
+ giveUp(node, 'For-in of unresolved variable: $accessSemantics'); |
+ } |
+ } else { |
+ assert(invariant( |
+ node, node.loopVariable != null, "Loop variable expected")); |
+ variableElement = converter.convertElement(node.loopVariable.element); |
+ buildVariableDeclaration = (IrBuilder builder) { |
+ builder.declareLocalVariable(variableElement); |
+ }; |
+ } |
+ // TODO(johnniwinther): Support `for-in` as a jump target. |
+ irBuilder.buildForIn( |
+ buildExpression: subbuild(node.iterable), |
+ buildVariableDeclaration: buildVariableDeclaration, |
+ variableElement: variableElement, |
+ variableSelector: variableSelector, |
+ buildBody: subbuild(node.body)); |
+ } |
} |