| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 interface HVisitor<R> { | 5 interface HVisitor<R> { |
| 6 R visitAdd(HAdd node); | 6 R visitAdd(HAdd node); |
| 7 R visitBailoutTarget(HBailoutTarget node); | 7 R visitBailoutTarget(HBailoutTarget node); |
| 8 R visitBitAnd(HBitAnd node); | 8 R visitBitAnd(HBitAnd node); |
| 9 R visitBitNot(HBitNot node); | 9 R visitBitNot(HBitNot node); |
| 10 R visitBitOr(HBitOr node); | 10 R visitBitOr(HBitOr node); |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 return HType.ARRAY; | 1094 return HType.ARRAY; |
| 1095 } | 1095 } |
| 1096 } | 1096 } |
| 1097 return HType.UNKNOWN; | 1097 return HType.UNKNOWN; |
| 1098 } | 1098 } |
| 1099 | 1099 |
| 1100 bool hasExpectedType() => builtinJsName != null; | 1100 bool hasExpectedType() => builtinJsName != null; |
| 1101 | 1101 |
| 1102 HInstruction fold() { | 1102 HInstruction fold() { |
| 1103 if (name == const SourceString('length') && inputs[1].isLiteralString()) { | 1103 if (name == const SourceString('length') && inputs[1].isLiteralString()) { |
| 1104 // TODO(lrn): Account for escapes in string. | 1104 HLiteral input = inputs[1]; |
| 1105 DartString string = input.value; |
| 1106 return new HLiteral(string.length, HType.INTEGER); |
| 1105 } | 1107 } |
| 1106 return this; | 1108 return this; |
| 1107 } | 1109 } |
| 1108 | 1110 |
| 1109 void prepareGvn() { | 1111 void prepareGvn() { |
| 1110 if (builtinJsName == 'length') { | 1112 if (builtinJsName == 'length') { |
| 1111 assert(!hasSideEffects()); | 1113 assert(!hasSideEffects()); |
| 1112 } else { | 1114 } else { |
| 1113 setAllSideEffects(); | 1115 setAllSideEffects(); |
| 1114 } | 1116 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1235 HType computeDesiredInputType(HInstruction input) { | 1237 HType computeDesiredInputType(HInstruction input) { |
| 1236 // TODO(floitsch): we want the target to be a function. | 1238 // TODO(floitsch): we want the target to be a function. |
| 1237 if (input == target) return HType.UNKNOWN; | 1239 if (input == target) return HType.UNKNOWN; |
| 1238 if (isString() || left.isString()) { | 1240 if (isString() || left.isString()) { |
| 1239 return (input == left) ? HType.STRING : HType.UNKNOWN; | 1241 return (input == left) ? HType.STRING : HType.UNKNOWN; |
| 1240 } | 1242 } |
| 1241 if (right.isString()) return HType.STRING; | 1243 if (right.isString()) return HType.STRING; |
| 1242 if (isNumber() || left.isNumber() || right.isNumber()) return HType.NUMBER; | 1244 if (isNumber() || left.isNumber() || right.isNumber()) return HType.NUMBER; |
| 1243 return HType.UNKNOWN; | 1245 return HType.UNKNOWN; |
| 1244 } | 1246 } |
| 1247 |
| 1248 HInstruction fold() { |
| 1249 if (left.isLiteralString() && right is HLiteral) { |
| 1250 HLiteral op1 = left; |
| 1251 HLiteral op2 = right; |
| 1252 DartString leftString = op1.value; |
| 1253 DartString otherString = null; |
| 1254 if (right.isLiteralString()) { |
| 1255 otherString = op2.value; |
| 1256 } else { |
| 1257 assert(op2.isLiteralNumber() || |
| 1258 op2.isLiteralBoolean() || |
| 1259 op2.isLiteralNull()); |
| 1260 String string = op2.value.toString(); |
| 1261 otherString = new DartString.literal(string); |
| 1262 } |
| 1263 DartString cons = new ConsDartString(leftString, otherString); |
| 1264 return new HLiteral(cons, HType.STRING); |
| 1265 } |
| 1266 return super.fold(); |
| 1267 } |
| 1245 } | 1268 } |
| 1246 | 1269 |
| 1247 class HDivide extends HBinaryArithmetic { | 1270 class HDivide extends HBinaryArithmetic { |
| 1248 HDivide(HStatic target, HInstruction left, HInstruction right) | 1271 HDivide(HStatic target, HInstruction left, HInstruction right) |
| 1249 : super(target, left, right); | 1272 : super(target, left, right); |
| 1250 accept(HVisitor visitor) => visitor.visitDivide(this); | 1273 accept(HVisitor visitor) => visitor.visitDivide(this); |
| 1251 num evaluate(num a, num b) => a / b; | 1274 num evaluate(num a, num b) => a / b; |
| 1252 bool typeEquals(other) => other is HDivide; | 1275 bool typeEquals(other) => other is HDivide; |
| 1253 bool dataEquals(HInstruction other) => true; | 1276 bool dataEquals(HInstruction other) => true; |
| 1254 } | 1277 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 return this; | 1314 return this; |
| 1292 } | 1315 } |
| 1293 return super.fold(); | 1316 return super.fold(); |
| 1294 } | 1317 } |
| 1295 | 1318 |
| 1296 num evaluate(num a, num b) => a ~/ b; | 1319 num evaluate(num a, num b) => a ~/ b; |
| 1297 bool typeEquals(other) => other is HTruncatingDivide; | 1320 bool typeEquals(other) => other is HTruncatingDivide; |
| 1298 bool dataEquals(HInstruction other) => true; | 1321 bool dataEquals(HInstruction other) => true; |
| 1299 } | 1322 } |
| 1300 | 1323 |
| 1324 |
| 1325 class ConsDartStringIterator implements Iterator<int> { |
| 1326 Iterator<int> current; |
| 1327 DartString right; |
| 1328 bool hasNextLookAhead; |
| 1329 ConsDartStringIterator(ConsDartString cons) |
| 1330 : current = cons.left.iterator(), |
| 1331 right = cons.right { |
| 1332 hasNextLookAhead = current.hasNext(); |
| 1333 if (!hasNextLookAhead) { |
| 1334 nextPart(); |
| 1335 } |
| 1336 } |
| 1337 bool hasNext() { |
| 1338 return hasNextLookAhead; |
| 1339 } |
| 1340 int next() { |
| 1341 assert(hasNextLookAhead); |
| 1342 int result = current.next(); |
| 1343 hasNextLookAhead = current.hasNext(); |
| 1344 if (!hasNextLookAhead) { |
| 1345 nextPart(); |
| 1346 } |
| 1347 return result; |
| 1348 } |
| 1349 void nextPart() { |
| 1350 if (right !== null) { |
| 1351 current = right.iterator(); |
| 1352 right = null; |
| 1353 hasNextLookAhead = current.hasNext(); |
| 1354 } |
| 1355 } |
| 1356 } |
| 1357 |
| 1358 class ConsDartString extends DartString { |
| 1359 final DartString left; |
| 1360 final DartString right; |
| 1361 final int length; |
| 1362 int hashCache = null; |
| 1363 String toStringCache; |
| 1364 ConsDartString(DartString left, DartString right) |
| 1365 : this.left = left, |
| 1366 this.right = right, |
| 1367 length = left.length + right.length; |
| 1368 |
| 1369 Iterator<int> iterator() => new ConsDartStringIterator(this); |
| 1370 |
| 1371 String toString() { |
| 1372 if (toStringCache !== null) return toStringCache; |
| 1373 toStringCache = left.toString().concat(right.toString()); |
| 1374 return toStringCache; |
| 1375 } |
| 1376 } |
| 1377 |
| 1378 |
| 1301 // TODO(floitsch): Should HBinaryArithmetic really be the super class of | 1379 // TODO(floitsch): Should HBinaryArithmetic really be the super class of |
| 1302 // HBinaryBitOp? | 1380 // HBinaryBitOp? |
| 1303 class HBinaryBitOp extends HBinaryArithmetic { | 1381 class HBinaryBitOp extends HBinaryArithmetic { |
| 1304 HBinaryBitOp(HStatic target, HInstruction left, HInstruction right) | 1382 HBinaryBitOp(HStatic target, HInstruction left, HInstruction right) |
| 1305 : super(target, left, right); | 1383 : super(target, left, right); |
| 1306 | 1384 |
| 1307 HType computeType() { | 1385 HType computeType() { |
| 1308 HType type = computeInputsType(); | 1386 HType type = computeInputsType(); |
| 1309 builtin = type.isInteger(); | 1387 builtin = type.isInteger(); |
| 1310 if (!type.isUnknown()) return type; | 1388 if (!type.isUnknown()) return type; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 } | 1655 } |
| 1578 | 1656 |
| 1579 // Literals have the type they have. It can't be changed. | 1657 // Literals have the type they have. It can't be changed. |
| 1580 bool updateType() => false; | 1658 bool updateType() => false; |
| 1581 | 1659 |
| 1582 bool hasExpectedType() => true; | 1660 bool hasExpectedType() => true; |
| 1583 | 1661 |
| 1584 bool isLiteralBoolean() => value is bool; | 1662 bool isLiteralBoolean() => value is bool; |
| 1585 bool isLiteralNull() => value === null; | 1663 bool isLiteralNull() => value === null; |
| 1586 bool isLiteralNumber() => value is num; | 1664 bool isLiteralNumber() => value is num; |
| 1587 bool isLiteralString() => value is QuotedString; | 1665 bool isLiteralString() => value is DartString; |
| 1588 bool typeEquals(other) => other is HLiteral; | 1666 bool typeEquals(other) => other is HLiteral; |
| 1589 bool dataEquals(HLiteral other) => value == other.value; | 1667 bool dataEquals(HLiteral other) => value == other.value; |
| 1590 } | 1668 } |
| 1591 | 1669 |
| 1592 class HNot extends HInstruction { | 1670 class HNot extends HInstruction { |
| 1593 HNot(HInstruction value) : super(<HInstruction>[value]); | 1671 HNot(HInstruction value) : super(<HInstruction>[value]); |
| 1594 void prepareGvn() { | 1672 void prepareGvn() { |
| 1595 assert(!hasSideEffects()); | 1673 assert(!hasSideEffects()); |
| 1596 setUseGvn(); | 1674 setUseGvn(); |
| 1597 } | 1675 } |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1989 | 2067 |
| 1990 HInstruction get expression() => inputs[0]; | 2068 HInstruction get expression() => inputs[0]; |
| 1991 | 2069 |
| 1992 HType computeType() => HType.BOOLEAN; | 2070 HType computeType() => HType.BOOLEAN; |
| 1993 bool hasExpectedType() => true; | 2071 bool hasExpectedType() => true; |
| 1994 | 2072 |
| 1995 accept(HVisitor visitor) => visitor.visitIs(this); | 2073 accept(HVisitor visitor) => visitor.visitIs(this); |
| 1996 | 2074 |
| 1997 toString() => "$expression is $typeExpression"; | 2075 toString() => "$expression is $typeExpression"; |
| 1998 } | 2076 } |
| OLD | NEW |