aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4isel_util_p.h
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@me.com>2013-07-30 16:43:10 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-08-20 11:48:01 +0200
commitb9f692776ceac02faf778f552f61568c222dbea4 (patch)
treea613f8e4466647dcd01ce64ce505efe060ebfdfd /src/qml/compiler/qv4isel_util_p.h
parentc69fc9e9e070c151d636a501450976be15cf0bac (diff)
Various fixes to the optimizer.
Mainly type inference and type propagation. Also added constant/copy propagation pass, which is disabled for the moment. Change-Id: I286c1fbced0d175be76868e870ca92c0da88babd Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/compiler/qv4isel_util_p.h')
-rw-r--r--src/qml/compiler/qv4isel_util_p.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/qml/compiler/qv4isel_util_p.h b/src/qml/compiler/qv4isel_util_p.h
index a422150dd0..c5c9386ff5 100644
--- a/src/qml/compiler/qv4isel_util_p.h
+++ b/src/qml/compiler/qv4isel_util_p.h
@@ -49,6 +49,20 @@ QT_BEGIN_NAMESPACE
namespace QQmlJS {
+inline bool canConvertToSignedInteger(double value)
+{
+ int ival = (int) value;
+ // +0 != -0, so we need to convert to double when negating 0
+ return ival == value && !(value == 0 && isNegative(value));
+}
+
+inline bool canConvertToUnsignedInteger(double value)
+{
+ unsigned uval = (unsigned) value;
+ // +0 != -0, so we need to convert to double when negating 0
+ return uval == value && !(value == 0 && isNegative(value));
+}
+
inline QV4::Value convertToValue(V4IR::Const *c)
{
switch (c->type) {
@@ -68,8 +82,7 @@ inline QV4::Value convertToValue(V4IR::Const *c)
return QV4::Value::fromDouble(c->value);
case V4IR::NumberType: {
int ival = (int)c->value;
- // +0 != -0, so we need to convert to double when negating 0
- if (ival == c->value && !(c->value == 0 && isNegative(c->value))) {
+ if (canConvertToSignedInteger(c->value)) {
return QV4::Value::fromInt32(ival);
} else {
return QV4::Value::fromDouble(c->value);