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

Unified Diff: pkg/analyzer2dart/lib/src/cps_generator.dart

Issue 702453002: Support for-in in analyzer2dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 1 month 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
« no previous file with comments | « no previous file | pkg/analyzer2dart/test/end2end_data.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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));
+ }
}
« no previous file with comments | « no previous file | pkg/analyzer2dart/test/end2end_data.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698