Commit ba392346 authored by Thomas Hartmann's avatar Thomas Hartmann Committed by Christian Kamm
Browse files

QmlJS: Adding IntValue and RealValue

This allows to distinguish between int an real numbers

Reviewed-by: Christian Kamm
parent e9fd078e
......@@ -870,13 +870,13 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
} else if (typeName == QLatin1String("bool")) {
value = engine()->booleanValue();
} else if (typeName == QLatin1String("int")
|| typeName == QLatin1String("float")
|| typeName == QLatin1String("double")
|| typeName == QLatin1String("qreal")
|| typeName == QLatin1String("long")
// ### Review: more types here?
) {
value = engine()->numberValue();
|| typeName == QLatin1String("long")) {
value = engine()->intValue();
} else if (typeName == QLatin1String("float")
|| typeName == QLatin1String("double")
|| typeName == QLatin1String("qreal")) {
// ### Review: more types here?
value = engine()->realValue();
} else if (typeName == QLatin1String("QFont")) {
value = engine()->qmlFontObject();
} else if (typeName == QLatin1String("QPoint")
......@@ -1318,6 +1318,17 @@ const NumberValue *Value::asNumberValue() const
return 0;
}
const IntValue *Value::asIntValue() const
{
return 0;
}
const RealValue *Value::asRealValue() const
{
return 0;
}
const BooleanValue *Value::asBooleanValue() const
{
return 0;
......@@ -1381,6 +1392,17 @@ const NumberValue *NumberValue::asNumberValue() const
return this;
}
const RealValue *RealValue::asRealValue() const
{
return this;
}
const IntValue *IntValue::asIntValue() const
{
return this;
}
void NumberValue::accept(ValueVisitor *visitor) const
{
visitor->visit(this);
......@@ -2526,6 +2548,15 @@ const NumberValue *Engine::numberValue() const
return &_numberValue;
}
const RealValue *Engine::realValue() const
{
return &_realValue;
}
const IntValue *Engine::intValue() const
{
return &_intValue;
}
const BooleanValue *Engine::booleanValue() const
{
return &_booleanValue;
......
......@@ -57,6 +57,8 @@ class Value;
class NullValue;
class UndefinedValue;
class NumberValue;
class IntValue;
class RealValue;
class BooleanValue;
class StringValue;
class ObjectValue;
......@@ -109,6 +111,8 @@ public:
virtual const NullValue *asNullValue() const;
virtual const UndefinedValue *asUndefinedValue() const;
virtual const NumberValue *asNumberValue() const;
virtual const IntValue *asIntValue() const;
virtual const RealValue *asRealValue() const;
virtual const BooleanValue *asBooleanValue() const;
virtual const StringValue *asStringValue() const;
virtual const ObjectValue *asObjectValue() const;
......@@ -142,6 +146,18 @@ template <> Q_INLINE_TEMPLATE const NumberValue *value_cast(const Value *v)
else return 0;
}
template <> Q_INLINE_TEMPLATE const IntValue *value_cast(const Value *v)
{
if (v) return v->asIntValue();
else return 0;
}
template <> Q_INLINE_TEMPLATE const RealValue *value_cast(const Value *v)
{
if (v) return v->asRealValue();
else return 0;
}
template <> Q_INLINE_TEMPLATE const BooleanValue *value_cast(const Value *v)
{
if (v) return v->asBooleanValue();
......@@ -208,6 +224,19 @@ public:
virtual void accept(ValueVisitor *visitor) const;
};
class QMLJS_EXPORT RealValue: public NumberValue
{
public:
virtual const RealValue *asRealValue() const;
};
class QMLJS_EXPORT IntValue: public NumberValue
{
public:
virtual const IntValue *asIntValue() const;
};
class QMLJS_EXPORT BooleanValue: public Value
{
public:
......@@ -649,6 +678,8 @@ public:
const NullValue *nullValue() const;
const UndefinedValue *undefinedValue() const;
const NumberValue *numberValue() const;
const RealValue *realValue() const;
const IntValue *intValue() const;
const BooleanValue *booleanValue() const;
const StringValue *stringValue() const;
const ColorValue *colorValue() const;
......@@ -747,6 +778,8 @@ private:
NullValue _nullValue;
UndefinedValue _undefinedValue;
NumberValue _numberValue;
RealValue _realValue;
IntValue _intValue;
BooleanValue _booleanValue;
StringValue _stringValue;
ColorValue _colorValue;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment