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

Side by Side Diff: pkg/compiler/lib/src/cps_ir/cps_ir_builder_task.dart

Issue 1686973002: Dart2js CPS: Implement 'await for'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library dart2js.ir_builder_task; 5 library dart2js.ir_builder_task;
6 6
7 import '../closure.dart' as closure; 7 import '../closure.dart' as closure;
8 import '../common.dart'; 8 import '../common.dart';
9 import '../common/names.dart' show 9 import '../common/names.dart' show
10 Identifiers, 10 Identifiers,
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 1104
1105 visitWhile(ast.While node) { 1105 visitWhile(ast.While node) {
1106 irBuilder.buildWhile( 1106 irBuilder.buildWhile(
1107 buildCondition: subbuild(node.condition), 1107 buildCondition: subbuild(node.condition),
1108 buildBody: subbuild(node.body), 1108 buildBody: subbuild(node.body),
1109 target: elements.getTargetDefinition(node), 1109 target: elements.getTargetDefinition(node),
1110 closureScope: getClosureScopeForNode(node)); 1110 closureScope: getClosureScopeForNode(node));
1111 } 1111 }
1112 1112
1113 visitAsyncForIn(ast.AsyncForIn node) { 1113 visitAsyncForIn(ast.AsyncForIn node) {
1114 // await for is not yet implemented. 1114 // Translate await for into a loop over a StreamIterator. The source
1115 return giveup(node, 'await for'); 1115 // statement:
1116 //
1117 // await for (<decl> in <stream>) <body>
1118 //
1119 // is translated as if it were:
1120 //
1121 // var iterator = new StreamIterator(<stream>);
1122 // try {
1123 // while (await iterator.hasNext()) {
1124 // <decl> = await iterator.current;
1125 // <body>
1126 // }
1127 // } finally {
1128 // await iterator.cancel();
1129 // }
1130 ir.Primitive stream = visit(node.expression);
1131 ir.Primitive dummyTypeArgument = irBuilder.buildNullConstant();
1132 ConstructorElement constructor = helpers.streamIteratorConstructor;
1133 ir.Primitive iterator = irBuilder.addPrimitive(new ir.InvokeConstructor(
1134 constructor.enclosingClass.thisType,
1135 constructor,
1136 new Selector.callConstructor(constructor.memberName, 1),
1137 <ir.Primitive>[stream, dummyTypeArgument],
1138 sourceInformationBuilder.buildGeneric(node)));
1139
1140 ir.Node buildTryBody(IrBuilder builder) {
1141 ir.Node buildLoopCondition(IrBuilder builder) {
1142 ir.Primitive moveNext = builder.buildDynamicInvocation(
1143 iterator,
1144 Selectors.moveNext,
1145 elements.getMoveNextTypeMask(node),
1146 <ir.Primitive>[]);
1147 return builder.addPrimitive(new ir.Await(moveNext));
1148 }
1149
1150 ir.Node buildLoopBody(IrBuilder builder) {
1151 return withBuilder(builder, () {
1152 ast.Node identifier = node.declaredIdentifier;
1153 ast.VariableDefinitions declaration =
1154 identifier.asVariableDefinitions();
1155 if (declaration != null) {
1156 visit(declaration);
1157 }
asgerf 2016/02/10 13:03:27 Instead of visiting the declaration, I think it wo
Kevin Millikin (Google) 2016/02/10 13:27:41 OK, I can do that. I wrote it this way just becau
1158 ir.Primitive current = irBuilder.buildDynamicInvocation(
1159 iterator,
1160 Selectors.current,
1161 elements.getCurrentTypeMask(node),
1162 <ir.Primitive>[]);
1163 Element variable = elements.getForInVariable(node);
1164 if (Elements.isLocal(variable)) {
1165 irBuilder.buildLocalVariableSet(variable, current);
1166 } else if (Elements.isError(variable) ||
1167 Elements.isMalformed(variable)) {
1168 Selector selector =
1169 new Selector.setter(new Name(variable.name, variable.library));
1170 List<ir.Primitive> args = <ir.Primitive>[current];
1171 // Note the comparison below. It can be the case that an element
1172 // isError and isMalformed.
1173 if (Elements.isError(variable)) {
1174 irBuilder.buildStaticNoSuchMethod(selector, args);
1175 } else {
1176 irBuilder.buildErroneousInvocation(variable, selector, args);
1177 }
1178 } else if (Elements.isStaticOrTopLevel(variable)) {
1179 if (variable.isField) {
1180 irBuilder.addPrimitive(new ir.SetStatic(variable, current));
1181 } else {
1182 irBuilder.buildStaticSetterSet(variable, current);
1183 }
1184 } else {
1185 ir.Primitive receiver = irBuilder.buildThis();
1186 irBuilder.buildDynamicSet(
1187 receiver,
1188 elements.getSelector(identifier),
1189 elements.getTypeMask(identifier),
1190 current);
1191 }
1192 visit(node.body);
1193 });
1194 }
1195
1196 builder.buildWhile(
1197 buildCondition: buildLoopCondition,
1198 buildBody: buildLoopBody,
1199 target: elements.getTargetDefinition(node),
1200 closureScope: getClosureScopeForNode(node));
1201 }
1202
1203 ir.Node buildFinallyBody(IrBuilder builder) {
1204 ir.Primitive cancellation = builder.buildDynamicInvocation(
1205 iterator,
1206 Selectors.cancel,
1207 backend.dynamicType,
1208 <ir.Primitive>[],
1209 sourceInformation: sourceInformationBuilder.buildGeneric(node));
1210 return builder.addPrimitive(new ir.Await(cancellation));
1211 }
1212
1213 irBuilder.buildTryFinally(new TryStatementInfo(), buildTryBody,
1214 buildFinallyBody);
1116 } 1215 }
1117 1216
1118 visitAwait(ast.Await node) { 1217 visitAwait(ast.Await node) {
1119 assert(irBuilder.isOpen); 1218 assert(irBuilder.isOpen);
1120 ir.Primitive value = visit(node.expression); 1219 ir.Primitive value = visit(node.expression);
1121 return irBuilder.addPrimitive(new ir.Await(value)); 1220 return irBuilder.addPrimitive(new ir.Await(value));
1122 } 1221 }
1123 1222
1124 visitYield(ast.Yield node) { 1223 visitYield(ast.Yield node) {
1125 assert(irBuilder.isOpen); 1224 assert(irBuilder.isOpen);
(...skipping 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after
3915 } 4014 }
3916 4015
3917 Element get closureConverter { 4016 Element get closureConverter {
3918 return _backend.helpers.closureConverter; 4017 return _backend.helpers.closureConverter;
3919 } 4018 }
3920 4019
3921 void addNativeMethod(FunctionElement function) { 4020 void addNativeMethod(FunctionElement function) {
3922 _backend.emitter.nativeEmitter.nativeMethods.add(function); 4021 _backend.emitter.nativeEmitter.nativeMethods.add(function);
3923 } 4022 }
3924 } 4023 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/cps_ir/cps_ir_builder.dart ('k') | pkg/compiler/lib/src/tree_ir/optimization/pull_into_initializers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698