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 closurelib; | 7 import '../closure.dart' as closurelib; |
8 import '../closure.dart' hide ClosureScope; | 8 import '../closure.dart' hide ClosureScope; |
9 import '../constants/expressions.dart'; | 9 import '../constants/expressions.dart'; |
10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
(...skipping 1151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 FunctionElement function, | 1162 FunctionElement function, |
1163 ast.Node index, | 1163 ast.Node index, |
1164 ast.Node rhs, | 1164 ast.Node rhs, |
1165 _) { | 1165 _) { |
1166 return irBuilder.buildSuperIndexSet(function, visit(index), visit(rhs)); | 1166 return irBuilder.buildSuperIndexSet(function, visit(index), visit(rhs)); |
1167 } | 1167 } |
1168 | 1168 |
1169 ir.Primitive translateCompounds( | 1169 ir.Primitive translateCompounds( |
1170 {ir.Primitive getValue(), | 1170 {ir.Primitive getValue(), |
1171 CompoundRhs rhs, | 1171 CompoundRhs rhs, |
1172 void setValue(ir.Primitive value)}) { | 1172 void setValue(ir.Primitive value), |
| 1173 Selector operatorSelector}) { |
1173 ir.Primitive value = getValue(); | 1174 ir.Primitive value = getValue(); |
1174 op.BinaryOperator operator = rhs.operator; | 1175 op.BinaryOperator operator = rhs.operator; |
1175 if (operator.kind == op.BinaryOperatorKind.IF_NULL) { | 1176 if (operator.kind == op.BinaryOperatorKind.IF_NULL) { |
1176 // Unlike other compound operators if-null conditionally will not do the | 1177 // Unlike other compound operators if-null conditionally will not do the |
1177 // assignment operation. | 1178 // assignment operation. |
1178 return irBuilder.buildIfNull(value, nested(() { | 1179 return irBuilder.buildIfNull(value, nested(() { |
1179 ir.Primitive newValue = build(rhs.rhs); | 1180 ir.Primitive newValue = build(rhs.rhs); |
1180 setValue(newValue); | 1181 setValue(newValue); |
1181 return newValue; | 1182 return newValue; |
1182 })); | 1183 })); |
1183 } | 1184 } |
1184 | 1185 |
1185 Selector operatorSelector = | 1186 if (operatorSelector == null) { |
1186 new Selector.binaryOperator(operator.selectorName); | 1187 operatorSelector = new Selector.binaryOperator(operator.selectorName); |
| 1188 } |
1187 ir.Primitive rhsValue; | 1189 ir.Primitive rhsValue; |
1188 if (rhs.kind == CompoundKind.ASSIGNMENT) { | 1190 if (rhs.kind == CompoundKind.ASSIGNMENT) { |
1189 rhsValue = visit(rhs.rhs); | 1191 rhsValue = visit(rhs.rhs); |
1190 } else { | 1192 } else { |
1191 rhsValue = irBuilder.buildIntegerConstant(1); | 1193 rhsValue = irBuilder.buildIntegerConstant(1); |
1192 } | 1194 } |
1193 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue]; | 1195 List<ir.Primitive> arguments = <ir.Primitive>[rhsValue]; |
1194 arguments = normalizeDynamicArguments( | 1196 arguments = normalizeDynamicArguments( |
1195 operatorSelector.callStructure, arguments); | 1197 operatorSelector.callStructure, arguments); |
1196 ir.Primitive result = | 1198 ir.Primitive result = |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1284 |
1283 @override | 1285 @override |
1284 ir.Primitive handleTypeLiteralConstantCompounds( | 1286 ir.Primitive handleTypeLiteralConstantCompounds( |
1285 ast.SendSet node, | 1287 ast.SendSet node, |
1286 ConstantExpression constant, | 1288 ConstantExpression constant, |
1287 CompoundRhs rhs, | 1289 CompoundRhs rhs, |
1288 arg) { | 1290 arg) { |
1289 return translateCompounds( | 1291 return translateCompounds( |
1290 getValue: () => buildConstantExpression(constant), | 1292 getValue: () => buildConstantExpression(constant), |
1291 rhs: rhs, | 1293 rhs: rhs, |
1292 setValue: (value) {}); // The binary operator will throw before this. | 1294 setValue: (value) {}, // The binary operator will throw before this. |
| 1295 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1293 } | 1296 } |
1294 | 1297 |
1295 @override | 1298 @override |
1296 ir.Primitive handleDynamicCompounds( | 1299 ir.Primitive handleDynamicCompounds( |
1297 ast.Send node, | 1300 ast.Send node, |
1298 ast.Node receiver, | 1301 ast.Node receiver, |
1299 CompoundRhs rhs, | 1302 CompoundRhs rhs, |
1300 Selector getterSelector, | 1303 Selector getterSelector, |
1301 Selector setterSelector, | 1304 Selector setterSelector, |
1302 arg) { | 1305 arg) { |
1303 ir.Primitive target = translateReceiver(receiver); | 1306 ir.Primitive target = translateReceiver(receiver); |
1304 ir.Primitive helper() { | 1307 ir.Primitive helper() { |
1305 return translateCompounds( | 1308 return translateCompounds( |
1306 getValue: () => irBuilder.buildDynamicGet(target, getterSelector), | 1309 getValue: () => irBuilder.buildDynamicGet(target, getterSelector), |
1307 rhs: rhs, | 1310 rhs: rhs, |
1308 setValue: (ir.Primitive result) { | 1311 setValue: (ir.Primitive result) { |
1309 irBuilder.buildDynamicSet(target, setterSelector, result); | 1312 irBuilder.buildDynamicSet(target, setterSelector, result); |
1310 }); | 1313 }, |
| 1314 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1311 } | 1315 } |
1312 return node.isConditional | 1316 return node.isConditional |
1313 ? irBuilder.buildIfNotNullSend(target, nested(helper)) | 1317 ? irBuilder.buildIfNotNullSend(target, nested(helper)) |
1314 : helper(); | 1318 : helper(); |
1315 } | 1319 } |
1316 | 1320 |
1317 ir.Primitive buildLocalNoSuchSetter(Local local, ir.Primitive value) { | 1321 ir.Primitive buildLocalNoSuchSetter(Local local, ir.Primitive value) { |
1318 Selector selector = new Selector.setter(local.name, null); | 1322 Selector selector = new Selector.setter(local.name, null); |
1319 return buildStaticNoSuchMethod(selector, [value]); | 1323 return buildStaticNoSuchMethod(selector, [value]); |
1320 } | 1324 } |
(...skipping 13 matching lines...) Expand all Loading... |
1334 return irBuilder.buildLocalVariableGet(local); | 1338 return irBuilder.buildLocalVariableGet(local); |
1335 } | 1339 } |
1336 }, | 1340 }, |
1337 rhs: rhs, | 1341 rhs: rhs, |
1338 setValue: (ir.Primitive result) { | 1342 setValue: (ir.Primitive result) { |
1339 if (isSetterValid) { | 1343 if (isSetterValid) { |
1340 irBuilder.buildLocalVariableSet(local, result); | 1344 irBuilder.buildLocalVariableSet(local, result); |
1341 } else { | 1345 } else { |
1342 return buildLocalNoSuchSetter(local, result); | 1346 return buildLocalNoSuchSetter(local, result); |
1343 } | 1347 } |
1344 }); | 1348 }, |
| 1349 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1345 } | 1350 } |
1346 | 1351 |
1347 ir.Primitive buildStaticNoSuchGetter(Element element) { | 1352 ir.Primitive buildStaticNoSuchGetter(Element element) { |
1348 return buildStaticNoSuchMethod( | 1353 return buildStaticNoSuchMethod( |
1349 new Selector.getter(element.name, element.library), | 1354 new Selector.getter(element.name, element.library), |
1350 const <ir.Primitive>[]); | 1355 const <ir.Primitive>[]); |
1351 } | 1356 } |
1352 | 1357 |
1353 ir.Primitive buildStaticNoSuchSetter(Element element, ir.Primitive value) { | 1358 ir.Primitive buildStaticNoSuchSetter(Element element, ir.Primitive value) { |
1354 return buildStaticNoSuchMethod( | 1359 return buildStaticNoSuchMethod( |
(...skipping 29 matching lines...) Expand all Loading... |
1384 switch (setterKind) { | 1389 switch (setterKind) { |
1385 case CompoundSetter.FIELD: | 1390 case CompoundSetter.FIELD: |
1386 return irBuilder.buildStaticFieldSet(setter, result); | 1391 return irBuilder.buildStaticFieldSet(setter, result); |
1387 case CompoundSetter.SETTER: | 1392 case CompoundSetter.SETTER: |
1388 return irBuilder.buildStaticSetterSet(setter, result); | 1393 return irBuilder.buildStaticSetterSet(setter, result); |
1389 case CompoundSetter.INVALID: | 1394 case CompoundSetter.INVALID: |
1390 // TODO(johnniwinther): Ensure [setter] is non null. | 1395 // TODO(johnniwinther): Ensure [setter] is non null. |
1391 return buildStaticNoSuchSetter( | 1396 return buildStaticNoSuchSetter( |
1392 setter != null ? setter : getter, result); | 1397 setter != null ? setter : getter, result); |
1393 } | 1398 } |
1394 }); | 1399 }, |
| 1400 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1395 } | 1401 } |
1396 | 1402 |
1397 ir.Primitive buildSuperNoSuchGetter(Element element) { | 1403 ir.Primitive buildSuperNoSuchGetter(Element element) { |
1398 return buildInstanceNoSuchMethod( | 1404 return buildInstanceNoSuchMethod( |
1399 new Selector.getter(element.name, element.library), | 1405 new Selector.getter(element.name, element.library), |
1400 const <ir.Primitive>[]); | 1406 const <ir.Primitive>[]); |
1401 } | 1407 } |
1402 | 1408 |
1403 ir.Primitive buildSuperNoSuchSetter(Element element, ir.Primitive value) { | 1409 ir.Primitive buildSuperNoSuchSetter(Element element, ir.Primitive value) { |
1404 return buildInstanceNoSuchMethod( | 1410 return buildInstanceNoSuchMethod( |
(...skipping 27 matching lines...) Expand all Loading... |
1432 rhs: rhs, | 1438 rhs: rhs, |
1433 setValue: (ir.Primitive result) { | 1439 setValue: (ir.Primitive result) { |
1434 switch (setterKind) { | 1440 switch (setterKind) { |
1435 case CompoundSetter.FIELD: | 1441 case CompoundSetter.FIELD: |
1436 return irBuilder.buildSuperFieldSet(setter, result); | 1442 return irBuilder.buildSuperFieldSet(setter, result); |
1437 case CompoundSetter.SETTER: | 1443 case CompoundSetter.SETTER: |
1438 return irBuilder.buildSuperSetterSet(setter, result); | 1444 return irBuilder.buildSuperSetterSet(setter, result); |
1439 case CompoundSetter.INVALID: | 1445 case CompoundSetter.INVALID: |
1440 return buildSuperNoSuchSetter(setter, result); | 1446 return buildSuperNoSuchSetter(setter, result); |
1441 } | 1447 } |
1442 }); | 1448 }, |
| 1449 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1443 } | 1450 } |
1444 | 1451 |
1445 @override | 1452 @override |
1446 ir.Primitive handleTypeVariableTypeLiteralCompounds( | 1453 ir.Primitive handleTypeVariableTypeLiteralCompounds( |
1447 ast.SendSet node, | 1454 ast.SendSet node, |
1448 TypeVariableElement typeVariable, | 1455 TypeVariableElement typeVariable, |
1449 CompoundRhs rhs, | 1456 CompoundRhs rhs, |
1450 arg) { | 1457 arg) { |
1451 return translateCompounds( | 1458 return translateCompounds( |
1452 getValue: () => irBuilder.buildReifyTypeVariable(typeVariable.type), | 1459 getValue: () => irBuilder.buildReifyTypeVariable(typeVariable.type), |
1453 rhs: rhs, | 1460 rhs: rhs, |
1454 setValue: (value) {}); // The binary operator will throw before this. | 1461 setValue: (value) {}, // The binary operator will throw before this. |
| 1462 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1455 } | 1463 } |
1456 | 1464 |
1457 @override | 1465 @override |
1458 ir.Primitive handleIndexCompounds( | 1466 ir.Primitive handleIndexCompounds( |
1459 ast.SendSet node, | 1467 ast.SendSet node, |
1460 ast.Node receiver, | 1468 ast.Node receiver, |
1461 ast.Node index, | 1469 ast.Node index, |
1462 CompoundRhs rhs, | 1470 CompoundRhs rhs, |
1463 arg) { | 1471 arg) { |
1464 ir.Primitive target = visit(receiver); | 1472 ir.Primitive target = visit(receiver); |
1465 ir.Primitive indexValue = visit(index); | 1473 ir.Primitive indexValue = visit(index); |
1466 return translateCompounds( | 1474 return translateCompounds( |
1467 getValue: () { | 1475 getValue: () { |
1468 Selector selector = new Selector.index(); | 1476 Selector selector = new Selector.index(); |
1469 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; | 1477 List<ir.Primitive> arguments = <ir.Primitive>[indexValue]; |
1470 arguments = | 1478 arguments = |
1471 normalizeDynamicArguments(selector.callStructure, arguments); | 1479 normalizeDynamicArguments(selector.callStructure, arguments); |
1472 return irBuilder.buildDynamicInvocation(target, selector, arguments); | 1480 return irBuilder.buildDynamicInvocation(target, selector, arguments); |
1473 }, | 1481 }, |
1474 rhs: rhs, | 1482 rhs: rhs, |
1475 setValue: (ir.Primitive result) { | 1483 setValue: (ir.Primitive result) { |
1476 irBuilder.buildDynamicIndexSet(target, indexValue, result); | 1484 irBuilder.buildDynamicIndexSet(target, indexValue, result); |
1477 }); | 1485 }, |
| 1486 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1478 } | 1487 } |
1479 | 1488 |
1480 @override | 1489 @override |
1481 ir.Primitive handleSuperIndexCompounds( | 1490 ir.Primitive handleSuperIndexCompounds( |
1482 ast.SendSet node, | 1491 ast.SendSet node, |
1483 Element indexFunction, | 1492 Element indexFunction, |
1484 Element indexSetFunction, | 1493 Element indexSetFunction, |
1485 ast.Node index, | 1494 ast.Node index, |
1486 CompoundRhs rhs, | 1495 CompoundRhs rhs, |
1487 arg, | 1496 arg, |
(...skipping 10 matching lines...) Expand all Loading... |
1498 } | 1507 } |
1499 }, | 1508 }, |
1500 rhs: rhs, | 1509 rhs: rhs, |
1501 setValue: (ir.Primitive result) { | 1510 setValue: (ir.Primitive result) { |
1502 if (isSetterValid) { | 1511 if (isSetterValid) { |
1503 irBuilder.buildSuperIndexSet(indexSetFunction, indexValue, result); | 1512 irBuilder.buildSuperIndexSet(indexSetFunction, indexValue, result); |
1504 } else { | 1513 } else { |
1505 buildInstanceNoSuchMethod( | 1514 buildInstanceNoSuchMethod( |
1506 new Selector.indexSet(), <ir.Primitive>[indexValue, result]); | 1515 new Selector.indexSet(), <ir.Primitive>[indexValue, result]); |
1507 } | 1516 } |
1508 }); | 1517 }, |
| 1518 operatorSelector: elements.getOperatorSelectorInComplexSendSet(node)); |
1509 } | 1519 } |
1510 | 1520 |
1511 /// Evaluates a string interpolation and appends each part to [accumulator] | 1521 /// Evaluates a string interpolation and appends each part to [accumulator] |
1512 /// (after stringify conversion). | 1522 /// (after stringify conversion). |
1513 void buildStringParts(ast.Node node, List<ir.Primitive> accumulator) { | 1523 void buildStringParts(ast.Node node, List<ir.Primitive> accumulator) { |
1514 if (node is ast.StringJuxtaposition) { | 1524 if (node is ast.StringJuxtaposition) { |
1515 buildStringParts(node.first, accumulator); | 1525 buildStringParts(node.first, accumulator); |
1516 buildStringParts(node.second, accumulator); | 1526 buildStringParts(node.second, accumulator); |
1517 } else if (node is ast.StringInterpolation) { | 1527 } else if (node is ast.StringInterpolation) { |
1518 buildStringParts(node.string, accumulator); | 1528 buildStringParts(node.string, accumulator); |
(...skipping 1657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 } | 3186 } |
3177 | 3187 |
3178 processSetStatic(ir.SetStatic node) { | 3188 processSetStatic(ir.SetStatic node) { |
3179 node.body = replacementFor(node.body); | 3189 node.body = replacementFor(node.body); |
3180 } | 3190 } |
3181 | 3191 |
3182 processContinuation(ir.Continuation node) { | 3192 processContinuation(ir.Continuation node) { |
3183 node.body = replacementFor(node.body); | 3193 node.body = replacementFor(node.body); |
3184 } | 3194 } |
3185 } | 3195 } |
OLD | NEW |