| OLD | NEW | 
|---|
| 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  Loading... | 
| 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           ir.Primitive current = irBuilder.buildDynamicInvocation( | 
|  | 1153               iterator, | 
|  | 1154               Selectors.current, | 
|  | 1155               elements.getCurrentTypeMask(node), | 
|  | 1156               <ir.Primitive>[]); | 
|  | 1157           Element variable = elements.getForInVariable(node); | 
|  | 1158           if (Elements.isLocal(variable)) { | 
|  | 1159             if (node.declaredIdentifier.asVariableDefinitions() != null) { | 
|  | 1160               irBuilder.declareLocalVariable(variable); | 
|  | 1161             } | 
|  | 1162             irBuilder.buildLocalVariableSet(variable, current); | 
|  | 1163           } else if (Elements.isError(variable) || | 
|  | 1164                      Elements.isMalformed(variable)) { | 
|  | 1165             Selector selector = | 
|  | 1166                 new Selector.setter(new Name(variable.name, variable.library)); | 
|  | 1167             List<ir.Primitive> args = <ir.Primitive>[current]; | 
|  | 1168             // Note the comparison below.  It can be the case that an element | 
|  | 1169             // isError and isMalformed. | 
|  | 1170             if (Elements.isError(variable)) { | 
|  | 1171               irBuilder.buildStaticNoSuchMethod(selector, args); | 
|  | 1172             } else { | 
|  | 1173               irBuilder.buildErroneousInvocation(variable, selector, args); | 
|  | 1174             } | 
|  | 1175           } else if (Elements.isStaticOrTopLevel(variable)) { | 
|  | 1176             if (variable.isField) { | 
|  | 1177               irBuilder.addPrimitive(new ir.SetStatic(variable, current)); | 
|  | 1178             } else { | 
|  | 1179               irBuilder.buildStaticSetterSet(variable, current); | 
|  | 1180             } | 
|  | 1181           } else { | 
|  | 1182             ir.Primitive receiver = irBuilder.buildThis(); | 
|  | 1183             ast.Node identifier = node.declaredIdentifier; | 
|  | 1184             irBuilder.buildDynamicSet( | 
|  | 1185                 receiver, | 
|  | 1186                 elements.getSelector(identifier), | 
|  | 1187                 elements.getTypeMask(identifier), | 
|  | 1188                 current); | 
|  | 1189           } | 
|  | 1190           visit(node.body); | 
|  | 1191         }); | 
|  | 1192       } | 
|  | 1193 | 
|  | 1194       builder.buildWhile( | 
|  | 1195           buildCondition: buildLoopCondition, | 
|  | 1196           buildBody: buildLoopBody, | 
|  | 1197           target: elements.getTargetDefinition(node), | 
|  | 1198           closureScope: getClosureScopeForNode(node)); | 
|  | 1199     } | 
|  | 1200 | 
|  | 1201     ir.Node buildFinallyBody(IrBuilder builder) { | 
|  | 1202       ir.Primitive cancellation = builder.buildDynamicInvocation( | 
|  | 1203           iterator, | 
|  | 1204           Selectors.cancel, | 
|  | 1205           backend.dynamicType, | 
|  | 1206           <ir.Primitive>[], | 
|  | 1207           sourceInformation: sourceInformationBuilder.buildGeneric(node)); | 
|  | 1208       return builder.addPrimitive(new ir.Await(cancellation)); | 
|  | 1209     } | 
|  | 1210 | 
|  | 1211     irBuilder.buildTryFinally(new TryStatementInfo(), buildTryBody, | 
|  | 1212         buildFinallyBody); | 
| 1116   } | 1213   } | 
| 1117 | 1214 | 
| 1118   visitAwait(ast.Await node) { | 1215   visitAwait(ast.Await node) { | 
| 1119     assert(irBuilder.isOpen); | 1216     assert(irBuilder.isOpen); | 
| 1120     ir.Primitive value = visit(node.expression); | 1217     ir.Primitive value = visit(node.expression); | 
| 1121     return irBuilder.addPrimitive(new ir.Await(value)); | 1218     return irBuilder.addPrimitive(new ir.Await(value)); | 
| 1122   } | 1219   } | 
| 1123 | 1220 | 
| 1124   visitYield(ast.Yield node) { | 1221   visitYield(ast.Yield node) { | 
| 1125     assert(irBuilder.isOpen); | 1222     assert(irBuilder.isOpen); | 
| (...skipping 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3915   } | 4012   } | 
| 3916 | 4013 | 
| 3917   Element get closureConverter { | 4014   Element get closureConverter { | 
| 3918     return _backend.helpers.closureConverter; | 4015     return _backend.helpers.closureConverter; | 
| 3919   } | 4016   } | 
| 3920 | 4017 | 
| 3921   void addNativeMethod(FunctionElement function) { | 4018   void addNativeMethod(FunctionElement function) { | 
| 3922     _backend.emitter.nativeEmitter.nativeMethods.add(function); | 4019     _backend.emitter.nativeEmitter.nativeMethods.add(function); | 
| 3923   } | 4020   } | 
| 3924 } | 4021 } | 
| OLD | NEW | 
|---|