QmlJS: Add more value_casts.

And switch all existing dynamic_casts to value_casts.

Change-Id: I93b89358e4802080f40b332074c64f4e91a2bc4c
Reviewed-on: http://codereview.qt-project.org/6311
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Reviewed-by: Fawzi Mohamed <fawzi.mohamed@nokia.com>
This commit is contained in:
Christian Kamm
2011-10-10 10:55:37 +02:00
parent 572b3a180b
commit 7ed717ca62
14 changed files with 161 additions and 63 deletions

View File

@@ -81,7 +81,7 @@ public:
virtual void visit(const NumberValue *value) virtual void visit(const NumberValue *value)
{ {
if (const QmlEnumValue *enumValue = dynamic_cast<const QmlEnumValue *>(value)) { if (const QmlEnumValue *enumValue = value_cast<QmlEnumValue>(value)) {
if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) { if (StringLiteral *stringLiteral = cast<StringLiteral *>(_ast)) {
const QString valueName = stringLiteral->value.toString(); const QString valueName = stringLiteral->value.toString();
@@ -643,7 +643,7 @@ void Check::visitQmlObject(Node *ast, UiQualifiedId *typeId,
const ObjectValue *lastPrototype = prototypes.last(); const ObjectValue *lastPrototype = prototypes.last();
if (iter.error() == PrototypeIterator::ReferenceResolutionError) { if (iter.error() == PrototypeIterator::ReferenceResolutionError) {
if (const QmlPrototypeReference *ref = if (const QmlPrototypeReference *ref =
dynamic_cast<const QmlPrototypeReference *>(lastPrototype->prototype())) { value_cast<QmlPrototypeReference>(lastPrototype->prototype())) {
addMessage(ErrCouldNotResolvePrototypeOf, typeErrorLocation, addMessage(ErrCouldNotResolvePrototypeOf, typeErrorLocation,
toString(ref->qmlTypeName()), lastPrototype->className()); toString(ref->qmlTypeName()), lastPrototype->className());
} else { } else {
@@ -778,7 +778,7 @@ bool Check::visit(IdentifierExpression *)
// _lastValue = evaluator.reference(ast); // _lastValue = evaluator.reference(ast);
// if (!_lastValue) // if (!_lastValue)
// addMessage(ErrUnknownIdentifier, ast->identifierToken); // addMessage(ErrUnknownIdentifier, ast->identifierToken);
// if (const Reference *ref = value_cast<const Reference *>(_lastValue)) { // if (const Reference *ref = value_cast<Reference>(_lastValue)) {
// _lastValue = _context->lookupReference(ref); // _lastValue = _context->lookupReference(ref);
// if (!_lastValue) // if (!_lastValue)
// error(ast->identifierToken, tr("could not resolve")); // error(ast->identifierToken, tr("could not resolve"));
@@ -1293,7 +1293,7 @@ const Value *Check::checkScopeObjectMember(const UiQualifiedId *id)
// member lookup // member lookup
const UiQualifiedId *idPart = id; const UiQualifiedId *idPart = id;
while (idPart->next) { while (idPart->next) {
const ObjectValue *objectValue = value_cast<const ObjectValue *>(value); const ObjectValue *objectValue = value_cast<ObjectValue>(value);
if (! objectValue) { if (! objectValue) {
addMessage(ErrDoesNotHaveMembers, idPart->identifierToken, propertyName); addMessage(ErrDoesNotHaveMembers, idPart->identifierToken, propertyName);
return 0; return 0;

View File

@@ -134,11 +134,11 @@ QString Context::defaultPropertyName(const ObjectValue *object) const
PrototypeIterator iter(object, this); PrototypeIterator iter(object, this);
while (iter.hasNext()) { while (iter.hasNext()) {
const ObjectValue *o = iter.next(); const ObjectValue *o = iter.next();
if (const ASTObjectValue *astObjValue = dynamic_cast<const ASTObjectValue *>(o)) { if (const ASTObjectValue *astObjValue = value_cast<ASTObjectValue>(o)) {
QString defaultProperty = astObjValue->defaultPropertyName(); QString defaultProperty = astObjValue->defaultPropertyName();
if (!defaultProperty.isEmpty()) if (!defaultProperty.isEmpty())
return defaultProperty; return defaultProperty;
} else if (const CppComponentValue *qmlValue = dynamic_cast<const CppComponentValue *>(o)) { } else if (const CppComponentValue *qmlValue = value_cast<CppComponentValue>(o)) {
return qmlValue->defaultPropertyName(); return qmlValue->defaultPropertyName();
} }
} }
@@ -151,7 +151,7 @@ ReferenceContext::ReferenceContext(const ContextPtr &context)
const Value *ReferenceContext::lookupReference(const Value *value) const Value *ReferenceContext::lookupReference(const Value *value)
{ {
const Reference *reference = value_cast<const Reference *>(value); const Reference *reference = value_cast<Reference>(value);
if (!reference) if (!reference)
return value; return value;

View File

@@ -62,7 +62,7 @@ const Value *Evaluate::value(AST::Node *ast)
{ {
const Value *result = reference(ast); const Value *result = reference(ast);
if (const Reference *ref = value_cast<const Reference *>(result)) { if (const Reference *ref = value_cast<Reference>(result)) {
if (_referenceContext) if (_referenceContext)
result = _referenceContext->lookupReference(ref); result = _referenceContext->lookupReference(ref);
else else
@@ -176,7 +176,7 @@ bool Evaluate::visit(AST::UiQualifiedId *ast)
_result = value; _result = value;
} else { } else {
const ObjectValue *base = value_cast<const ObjectValue *>(value); const ObjectValue *base = value_cast<ObjectValue>(value);
for (AST::UiQualifiedId *it = ast->next; base && it; it = it->next) { for (AST::UiQualifiedId *it = ast->next; base && it; it = it->next) {
const QString &name = it->name.toString(); const QString &name = it->name.toString();
@@ -187,7 +187,7 @@ bool Evaluate::visit(AST::UiQualifiedId *ast)
if (! it->next) if (! it->next)
_result = value; _result = value;
else else
base = value_cast<const ObjectValue *>(value); base = value_cast<ObjectValue>(value);
} }
} }
@@ -328,7 +328,7 @@ bool Evaluate::visit(AST::FieldMemberExpression *ast)
bool Evaluate::visit(AST::NewMemberExpression *ast) bool Evaluate::visit(AST::NewMemberExpression *ast)
{ {
if (const FunctionValue *ctor = value_cast<const FunctionValue *>(value(ast->base))) { if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->base))) {
_result = ctor->construct(); _result = ctor->construct();
} }
return false; return false;
@@ -336,7 +336,7 @@ bool Evaluate::visit(AST::NewMemberExpression *ast)
bool Evaluate::visit(AST::NewExpression *ast) bool Evaluate::visit(AST::NewExpression *ast)
{ {
if (const FunctionValue *ctor = value_cast<const FunctionValue *>(value(ast->expression))) { if (const FunctionValue *ctor = value_cast<FunctionValue>(value(ast->expression))) {
_result = ctor->construct(); _result = ctor->construct();
} }
return false; return false;

View File

@@ -193,6 +193,11 @@ static QString generatedSlotName(const QString &base)
return slotName; return slotName;
} }
const CppComponentValue *CppComponentValue::asCppComponentValue() const
{
return this;
}
void CppComponentValue::processMembers(MemberProcessor *processor) const void CppComponentValue::processMembers(MemberProcessor *processor) const
{ {
// process the meta enums // process the meta enums
@@ -337,7 +342,7 @@ const Value *CppComponentValue::valueForCppName(const QString &typeName) const
const CppComponentValue *CppComponentValue::prototype() const const CppComponentValue *CppComponentValue::prototype() const
{ {
Q_ASSERT(!_prototype || dynamic_cast<const CppComponentValue *>(_prototype)); Q_ASSERT(!_prototype || value_cast<CppComponentValue>(_prototype));
return static_cast<const CppComponentValue *>(_prototype); return static_cast<const CppComponentValue *>(_prototype);
} }
@@ -522,6 +527,11 @@ QmlEnumValue::~QmlEnumValue()
{ {
} }
const QmlEnumValue *QmlEnumValue::asQmlEnumValue() const
{
return this;
}
QString QmlEnumValue::name() const QString QmlEnumValue::name() const
{ {
return _owner->metaObject()->enumerator(_enumIndex).name(); return _owner->metaObject()->enumerator(_enumIndex).name();
@@ -669,6 +679,31 @@ const AnchorLineValue *Value::asAnchorLineValue() const
return 0; return 0;
} }
const CppComponentValue *Value::asCppComponentValue() const
{
return 0;
}
const ASTObjectValue *Value::asAstObjectValue() const
{
return 0;
}
const QmlEnumValue *Value::asQmlEnumValue() const
{
return 0;
}
const QmlPrototypeReference *Value::asQmlPrototypeReference() const
{
return 0;
}
const ASTPropertyReference *Value::asAstPropertyReference() const
{
return 0;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Values // Values
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -853,10 +888,10 @@ const Value *ObjectValue::prototype() const
const ObjectValue *ObjectValue::prototype(const Context *context) const const ObjectValue *ObjectValue::prototype(const Context *context) const
{ {
const ObjectValue *prototypeObject = value_cast<const ObjectValue *>(_prototype); const ObjectValue *prototypeObject = value_cast<ObjectValue>(_prototype);
if (! prototypeObject) { if (! prototypeObject) {
if (const Reference *prototypeReference = value_cast<const Reference *>(_prototype)) { if (const Reference *prototypeReference = value_cast<Reference>(_prototype)) {
prototypeObject = value_cast<const ObjectValue *>(context->lookupReference(prototypeReference)); prototypeObject = value_cast<ObjectValue>(context->lookupReference(prototypeReference));
} }
} }
return prototypeObject; return prototypeObject;
@@ -981,9 +1016,9 @@ bool PrototypeIterator::hasNext()
if (!proto) if (!proto)
return false; return false;
m_next = value_cast<const ObjectValue *>(proto); m_next = value_cast<ObjectValue>(proto);
if (! m_next) if (! m_next)
m_next = value_cast<const ObjectValue *>(m_context->lookupReference(proto)); m_next = value_cast<ObjectValue>(m_context->lookupReference(proto));
if (!m_next) { if (!m_next) {
m_error = ReferenceResolutionError; m_error = ReferenceResolutionError;
return false; return false;
@@ -1480,15 +1515,15 @@ void ConvertToNumber::visit(const StringValue *)
void ConvertToNumber::visit(const ObjectValue *object) void ConvertToNumber::visit(const ObjectValue *object)
{ {
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookupMember("valueOf", ContextPtr()))) { if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(object->lookupMember("valueOf", ContextPtr()))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number? _result = value_cast<NumberValue>(valueOfMember->call(object)); // ### invoke convert-to-number?
} }
} }
void ConvertToNumber::visit(const FunctionValue *object) void ConvertToNumber::visit(const FunctionValue *object)
{ {
if (const FunctionValue *valueOfMember = value_cast<const FunctionValue *>(object->lookupMember("valueOf", ContextPtr()))) { if (const FunctionValue *valueOfMember = value_cast<FunctionValue>(object->lookupMember("valueOf", ContextPtr()))) {
_result = value_cast<const NumberValue *>(valueOfMember->call(object)); // ### invoke convert-to-number? _result = value_cast<NumberValue>(valueOfMember->call(object)); // ### invoke convert-to-number?
} }
} }
@@ -1541,15 +1576,15 @@ void ConvertToString::visit(const StringValue *value)
void ConvertToString::visit(const ObjectValue *object) void ConvertToString::visit(const ObjectValue *object)
{ {
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookupMember("toString", ContextPtr()))) { if (const FunctionValue *toStringMember = value_cast<FunctionValue>(object->lookupMember("toString", ContextPtr()))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string? _result = value_cast<StringValue>(toStringMember->call(object)); // ### invoke convert-to-string?
} }
} }
void ConvertToString::visit(const FunctionValue *object) void ConvertToString::visit(const FunctionValue *object)
{ {
if (const FunctionValue *toStringMember = value_cast<const FunctionValue *>(object->lookupMember("toString", ContextPtr()))) { if (const FunctionValue *toStringMember = value_cast<FunctionValue>(object->lookupMember("toString", ContextPtr()))) {
_result = value_cast<const StringValue *>(toStringMember->call(object)); // ### invoke convert-to-string? _result = value_cast<StringValue>(toStringMember->call(object)); // ### invoke convert-to-string?
} }
} }
@@ -1705,6 +1740,11 @@ ASTObjectValue::~ASTObjectValue()
{ {
} }
const ASTObjectValue *ASTObjectValue::asAstObjectValue() const
{
return this;
}
bool ASTObjectValue::getSourceLocation(QString *fileName, int *line, int *column) const bool ASTObjectValue::getSourceLocation(QString *fileName, int *line, int *column) const
{ {
*fileName = _doc->fileName(); *fileName = _doc->fileName();
@@ -1856,6 +1896,11 @@ QmlPrototypeReference::~QmlPrototypeReference()
{ {
} }
const QmlPrototypeReference *QmlPrototypeReference::asQmlPrototypeReference() const
{
return this;
}
UiQualifiedId *QmlPrototypeReference::qmlTypeName() const UiQualifiedId *QmlPrototypeReference::qmlTypeName() const
{ {
return _qmlTypeName; return _qmlTypeName;
@@ -1878,6 +1923,11 @@ ASTPropertyReference::~ASTPropertyReference()
{ {
} }
const ASTPropertyReference *ASTPropertyReference::asAstPropertyReference() const
{
return this;
}
bool ASTPropertyReference::getSourceLocation(QString *fileName, int *line, int *column) const bool ASTPropertyReference::getSourceLocation(QString *fileName, int *line, int *column) const
{ {
*fileName = _doc->fileName(); *fileName = _doc->fileName();

View File

@@ -75,6 +75,11 @@ class JSImportScope;
class Context; class Context;
typedef QSharedPointer<const Context> ContextPtr; typedef QSharedPointer<const Context> ContextPtr;
class ReferenceContext; class ReferenceContext;
class CppComponentValue;
class ASTObjectValue;
class QmlEnumValue;
class QmlPrototypeReference;
class ASTPropertyReference;
typedef QList<const Value *> ValueList; typedef QList<const Value *> ValueList;
@@ -124,13 +129,18 @@ public:
virtual const Reference *asReference() const; virtual const Reference *asReference() const;
virtual const ColorValue *asColorValue() const; virtual const ColorValue *asColorValue() const;
virtual const AnchorLineValue *asAnchorLineValue() const; virtual const AnchorLineValue *asAnchorLineValue() const;
virtual const CppComponentValue *asCppComponentValue() const;
virtual const ASTObjectValue *asAstObjectValue() const;
virtual const QmlEnumValue *asQmlEnumValue() const;
virtual const QmlPrototypeReference *asQmlPrototypeReference() const;
virtual const ASTPropertyReference *asAstPropertyReference() const;
virtual void accept(ValueVisitor *) const = 0; virtual void accept(ValueVisitor *) const = 0;
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const; virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
}; };
template <typename _RetTy> _RetTy value_cast(const Value *v); template <typename _RetTy> const _RetTy *value_cast(const Value *v);
template <> Q_INLINE_TEMPLATE const NullValue *value_cast(const Value *v) template <> Q_INLINE_TEMPLATE const NullValue *value_cast(const Value *v)
{ {
@@ -210,6 +220,36 @@ template <> Q_INLINE_TEMPLATE const AnchorLineValue *value_cast(const Value *v)
else return 0; else return 0;
} }
template <> Q_INLINE_TEMPLATE const CppComponentValue *value_cast(const Value *v)
{
if (v) return v->asCppComponentValue();
else return 0;
}
template <> Q_INLINE_TEMPLATE const ASTObjectValue *value_cast(const Value *v)
{
if (v) return v->asAstObjectValue();
else return 0;
}
template <> Q_INLINE_TEMPLATE const QmlEnumValue *value_cast(const Value *v)
{
if (v) return v->asQmlEnumValue();
else return 0;
}
template <> Q_INLINE_TEMPLATE const QmlPrototypeReference *value_cast(const Value *v)
{
if (v) return v->asQmlPrototypeReference();
else return 0;
}
template <> Q_INLINE_TEMPLATE const ASTPropertyReference *value_cast(const Value *v)
{
if (v) return v->asAstPropertyReference();
else return 0;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Value nodes // Value nodes
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@@ -394,14 +434,14 @@ private:
Error m_error; Error m_error;
}; };
class CppComponentValue;
class QMLJS_EXPORT QmlEnumValue: public NumberValue class QMLJS_EXPORT QmlEnumValue: public NumberValue
{ {
public: public:
QmlEnumValue(const CppComponentValue *owner, int index); QmlEnumValue(const CppComponentValue *owner, int index);
virtual ~QmlEnumValue(); virtual ~QmlEnumValue();
virtual const QmlEnumValue *asQmlEnumValue() const;
QString name() const; QString name() const;
QStringList keys() const; QStringList keys() const;
const CppComponentValue *owner() const; const CppComponentValue *owner() const;
@@ -423,6 +463,8 @@ public:
ValueOwner *valueOwner); ValueOwner *valueOwner);
virtual ~CppComponentValue(); virtual ~CppComponentValue();
virtual const CppComponentValue *asCppComponentValue() const;
virtual void processMembers(MemberProcessor *processor) const; virtual void processMembers(MemberProcessor *processor) const;
const Value *valueForCppName(const QString &typeName) const; const Value *valueForCppName(const QString &typeName) const;
@@ -701,6 +743,8 @@ public:
QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, const Document *doc, ValueOwner *valueOwner); QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, const Document *doc, ValueOwner *valueOwner);
virtual ~QmlPrototypeReference(); virtual ~QmlPrototypeReference();
virtual const QmlPrototypeReference *asQmlPrototypeReference() const;
AST::UiQualifiedId *qmlTypeName() const; AST::UiQualifiedId *qmlTypeName() const;
private: private:
@@ -755,6 +799,8 @@ public:
ASTPropertyReference(AST::UiPublicMember *ast, const Document *doc, ValueOwner *valueOwner); ASTPropertyReference(AST::UiPublicMember *ast, const Document *doc, ValueOwner *valueOwner);
virtual ~ASTPropertyReference(); virtual ~ASTPropertyReference();
virtual const ASTPropertyReference *asAstPropertyReference() const;
AST::UiPublicMember *ast() const { return _ast; } AST::UiPublicMember *ast() const { return _ast; }
QString onChangedSlotName() const { return _onChangedSlotName; } QString onChangedSlotName() const { return _onChangedSlotName; }
@@ -804,6 +850,8 @@ public:
ValueOwner *valueOwner); ValueOwner *valueOwner);
virtual ~ASTObjectValue(); virtual ~ASTObjectValue();
virtual const ASTObjectValue *asAstObjectValue() const;
bool getSourceLocation(QString *fileName, int *line, int *column) const; bool getSourceLocation(QString *fileName, int *line, int *column) const;
virtual void processMembers(MemberProcessor *processor) const; virtual void processMembers(MemberProcessor *processor) const;

View File

@@ -185,7 +185,7 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
iter.next(); iter.next();
while (iter.hasNext()) { while (iter.hasNext()) {
const ObjectValue *prototype = iter.next(); const ObjectValue *prototype = iter.next();
if (const CppComponentValue *qmlMetaObject = dynamic_cast<const CppComponentValue *>(prototype)) { if (const CppComponentValue *qmlMetaObject = value_cast<CppComponentValue>(prototype)) {
if ((qmlMetaObject->className() == QLatin1String("ListElement") if ((qmlMetaObject->className() == QLatin1String("ListElement")
|| qmlMetaObject->className() == QLatin1String("Connections") || qmlMetaObject->className() == QLatin1String("Connections")
) && (qmlMetaObject->moduleName() == QLatin1String("Qt") ) && (qmlMetaObject->moduleName() == QLatin1String("Qt")
@@ -211,7 +211,7 @@ void ScopeBuilder::setQmlScopeObject(Node *node)
Evaluate evaluator(_scopeChain); Evaluate evaluator(_scopeChain);
const Value *targetValue = evaluator(scriptBinding->statement); const Value *targetValue = evaluator(scriptBinding->statement);
if (const ObjectValue *target = value_cast<const ObjectValue *>(targetValue)) { if (const ObjectValue *target = value_cast<ObjectValue>(targetValue)) {
qmlScopeObjects.prepend(target); qmlScopeObjects.prepend(target);
} else { } else {
qmlScopeObjects.clear(); qmlScopeObjects.clear();
@@ -259,7 +259,7 @@ const ObjectValue *ScopeBuilder::isPropertyChangesObject(const ContextPtr &conte
PrototypeIterator iter(object, context); PrototypeIterator iter(object, context);
while (iter.hasNext()) { while (iter.hasNext()) {
const ObjectValue *prototype = iter.next(); const ObjectValue *prototype = iter.next();
if (const CppComponentValue *qmlMetaObject = dynamic_cast<const CppComponentValue *>(prototype)) { if (const CppComponentValue *qmlMetaObject = value_cast<CppComponentValue>(prototype)) {
if (qmlMetaObject->className() == QLatin1String("PropertyChanges") if (qmlMetaObject->className() == QLatin1String("PropertyChanges")
&& (qmlMetaObject->moduleName() == QLatin1String("Qt") && (qmlMetaObject->moduleName() == QLatin1String("Qt")
|| qmlMetaObject->moduleName() == QLatin1String("QtQuick"))) || qmlMetaObject->moduleName() == QLatin1String("QtQuick")))

View File

@@ -96,14 +96,14 @@ class PropertyMemberProcessor : public MemberProcessor
public: public:
virtual bool processProperty(const QString &name, const Value *value) virtual bool processProperty(const QString &name, const Value *value)
{ {
const ASTPropertyReference *ref = dynamic_cast<const ASTPropertyReference*>(value); const ASTPropertyReference *ref = value_cast<ASTPropertyReference>(value);
if (ref) { if (ref) {
QString type = "unknown"; QString type = "unknown";
if (!ref->ast()->memberType.isEmpty()) if (!ref->ast()->memberType.isEmpty())
type = ref->ast()->memberType.toString(); type = ref->ast()->memberType.toString();
m_properties.append(qMakePair(name, type)); m_properties.append(qMakePair(name, type));
} else { } else {
if (const CppComponentValue * ov = dynamic_cast<const CppComponentValue *>(value)) { if (const CppComponentValue * ov = value_cast<CppComponentValue>(value)) {
QString qualifiedTypeName = ov->moduleName().isEmpty() ? ov->className() : ov->moduleName() + '.' + ov->className(); QString qualifiedTypeName = ov->moduleName().isEmpty() ? ov->className() : ov->moduleName() + '.' + ov->className();
m_properties.append(qMakePair(name, qualifiedTypeName)); m_properties.append(qMakePair(name, qualifiedTypeName));
} else { } else {
@@ -140,7 +140,7 @@ const CppComponentValue *findQmlPrototype(const ObjectValue *ov, const ContextPt
if (!ov) if (!ov)
return 0; return 0;
const CppComponentValue * qmlValue = dynamic_cast<const CppComponentValue *>(ov); const CppComponentValue * qmlValue = value_cast<CppComponentValue>(ov);
if (qmlValue) if (qmlValue)
return qmlValue; return qmlValue;
@@ -154,7 +154,7 @@ QStringList prototypes(const ObjectValue *ov, const ContextPtr &context, bool ve
return list; return list;
ov = ov->prototype(context); ov = ov->prototype(context);
while (ov) { while (ov) {
const CppComponentValue * qmlValue = dynamic_cast<const CppComponentValue *>(ov); const CppComponentValue * qmlValue = value_cast<CppComponentValue>(ov);
if (qmlValue) { if (qmlValue) {
if (versions) { if (versions) {
list << qmlValue->moduleName() + '.' + qmlValue->className() + list << qmlValue->moduleName() + '.' + qmlValue->className() +
@@ -192,7 +192,7 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *ov, const ContextPtr &c
QString name = property.first; QString name = property.first;
if (!ov->isWritable(name) && ov->isPointer(name)) { if (!ov->isWritable(name) && ov->isPointer(name)) {
//dot property //dot property
const CppComponentValue * qmlValue = dynamic_cast<const CppComponentValue *>(ov->lookupMember(name, context)); const CppComponentValue * qmlValue = value_cast<CppComponentValue>(ov->lookupMember(name, context));
if (qmlValue) { if (qmlValue) {
QList<PropertyInfo> dotProperties = getQmlTypes(qmlValue, context); QList<PropertyInfo> dotProperties = getQmlTypes(qmlValue, context);
foreach (const PropertyInfo &propertyInfo, dotProperties) { foreach (const PropertyInfo &propertyInfo, dotProperties) {
@@ -204,7 +204,7 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *ov, const ContextPtr &c
} }
} }
if (isValueType(ov->propertyType(name))) { if (isValueType(ov->propertyType(name))) {
const ObjectValue *dotObjectValue = dynamic_cast<const ObjectValue *>(ov->lookupMember(name, context)); const ObjectValue *dotObjectValue = value_cast<ObjectValue>(ov->lookupMember(name, context));
if (dotObjectValue) { if (dotObjectValue) {
QList<PropertyInfo> dotProperties = getObjectTypes(dotObjectValue, context); QList<PropertyInfo> dotProperties = getObjectTypes(dotObjectValue, context);
foreach (const PropertyInfo &propertyInfo, dotProperties) { foreach (const PropertyInfo &propertyInfo, dotProperties) {
@@ -224,7 +224,7 @@ QList<PropertyInfo> getQmlTypes(const CppComponentValue *ov, const ContextPtr &c
if (!local) { if (!local) {
const ObjectValue* prototype = ov->prototype(context); const ObjectValue* prototype = ov->prototype(context);
const CppComponentValue * qmlObjectValue = dynamic_cast<const CppComponentValue *>(prototype); const CppComponentValue * qmlObjectValue = value_cast<CppComponentValue>(prototype);
if (qmlObjectValue) { if (qmlObjectValue) {
list << getQmlTypes(qmlObjectValue, context); list << getQmlTypes(qmlObjectValue, context);
@@ -240,7 +240,7 @@ QList<PropertyInfo> getTypes(const ObjectValue *ov, const ContextPtr &context, b
{ {
QList<PropertyInfo> list; QList<PropertyInfo> list;
const CppComponentValue * qmlObjectValue = dynamic_cast<const CppComponentValue *>(ov); const CppComponentValue * qmlObjectValue = value_cast<CppComponentValue>(ov);
if (qmlObjectValue) { if (qmlObjectValue) {
list << getQmlTypes(qmlObjectValue, context, local); list << getQmlTypes(qmlObjectValue, context, local);
@@ -264,7 +264,7 @@ QList<PropertyInfo> getObjectTypes(const ObjectValue *ov, const ContextPtr &cont
if (!local) { if (!local) {
const ObjectValue* prototype = ov->prototype(context); const ObjectValue* prototype = ov->prototype(context);
const CppComponentValue * qmlObjectValue = dynamic_cast<const CppComponentValue *>(prototype); const CppComponentValue * qmlObjectValue = value_cast<CppComponentValue>(prototype);
if (qmlObjectValue) { if (qmlObjectValue) {
list << getQmlTypes(qmlObjectValue, context); list << getQmlTypes(qmlObjectValue, context);
@@ -434,7 +434,7 @@ NodeMetaInfoPrivate::NodeMetaInfoPrivate(Model *model, QString type, int maj, in
} else { } else {
const ObjectValue *objectValue = getObjectValue(); const ObjectValue *objectValue = getObjectValue();
if (objectValue) { if (objectValue) {
const CppComponentValue *qmlValue = dynamic_cast<const CppComponentValue *>(objectValue); const CppComponentValue *qmlValue = value_cast<CppComponentValue>(objectValue);
if (qmlValue) { if (qmlValue) {
m_majorVersion = qmlValue->componentVersion().majorVersion(); m_majorVersion = qmlValue->componentVersion().majorVersion();
m_minorVersion = qmlValue->componentVersion().minorVersion(); m_minorVersion = qmlValue->componentVersion().minorVersion();
@@ -476,7 +476,7 @@ const QmlJS::CppComponentValue *NodeMetaInfoPrivate::getCppComponentValue() cons
if (import.info.path() != module) if (import.info.path() != module)
continue; continue;
const Value *lookupResult = import.object->lookupMember(type, context()); const Value *lookupResult = import.object->lookupMember(type, context());
if ((value = dynamic_cast<const CppComponentValue *>(lookupResult))) if ((value = value_cast<CppComponentValue>(lookupResult)))
return value; return value;
} }
@@ -759,7 +759,7 @@ QString NodeMetaInfoPrivate::packageName() const
QString NodeMetaInfoPrivate::componentSource() const QString NodeMetaInfoPrivate::componentSource() const
{ {
if (isComponent()) { if (isComponent()) {
const ASTObjectValue * astObjectValue = dynamic_cast<const ASTObjectValue *>(getObjectValue()); const ASTObjectValue * astObjectValue = value_cast<ASTObjectValue>(getObjectValue());
if (astObjectValue) if (astObjectValue)
return astObjectValue->document()->source().mid(astObjectValue->typeName()->identifierToken.begin(), return astObjectValue->document()->source().mid(astObjectValue->typeName()->identifierToken.begin(),
astObjectValue->initializer()->rbraceToken.end()); astObjectValue->initializer()->rbraceToken.end());
@@ -770,7 +770,7 @@ QString NodeMetaInfoPrivate::componentSource() const
QString NodeMetaInfoPrivate::componentFileName() const QString NodeMetaInfoPrivate::componentFileName() const
{ {
if (isComponent()) { if (isComponent()) {
const ASTObjectValue * astObjectValue = dynamic_cast<const ASTObjectValue *>(getObjectValue()); const ASTObjectValue * astObjectValue = value_cast<ASTObjectValue>(getObjectValue());
if (astObjectValue) { if (astObjectValue) {
QString fileName; QString fileName;
int line; int line;
@@ -831,7 +831,7 @@ void NodeMetaInfoPrivate::setupPrototypes()
description.className = ov->className(); description.className = ov->className();
description.minorVersion = -1; description.minorVersion = -1;
description.majorVersion = -1; description.majorVersion = -1;
if (const CppComponentValue * qmlValue = dynamic_cast<const CppComponentValue *>(ov)) { if (const CppComponentValue * qmlValue = value_cast<CppComponentValue>(ov)) {
description.minorVersion = qmlValue->componentVersion().minorVersion(); description.minorVersion = qmlValue->componentVersion().minorVersion();
description.majorVersion = qmlValue->componentVersion().majorVersion(); description.majorVersion = qmlValue->componentVersion().majorVersion();
if (!qmlValue->moduleName().isEmpty()) if (!qmlValue->moduleName().isEmpty())

View File

@@ -344,7 +344,7 @@ public:
const ObjectValue *value = m_context->lookupType(m_doc.data(), astTypeNode); const ObjectValue *value = m_context->lookupType(m_doc.data(), astTypeNode);
defaultPropertyName = m_context->defaultPropertyName(value); defaultPropertyName = m_context->defaultPropertyName(value);
const CppComponentValue * qmlValue = dynamic_cast<const CppComponentValue *>(value); const CppComponentValue * qmlValue = value_cast<CppComponentValue>(value);
if (qmlValue) { if (qmlValue) {
typeName = fixUpPackeNameForQt(qmlValue->moduleName()) + QLatin1String(".") + qmlValue->className(); typeName = fixUpPackeNameForQt(qmlValue->moduleName()) + QLatin1String(".") + qmlValue->className();
@@ -452,7 +452,7 @@ public:
if (prefix.isEmpty()) if (prefix.isEmpty())
idPart = idPart->next; idPart = idPart->next;
for (; idPart; idPart = idPart->next) { for (; idPart; idPart = idPart->next) {
objectValue = value_cast<const ObjectValue *>(value); objectValue = value_cast<ObjectValue>(value);
if (! objectValue) { if (! objectValue) {
// if (idPart->name) // if (idPart->name)
// qDebug() << idPart->name->asString() << "has no property named" // qDebug() << idPart->name->asString() << "has no property named"
@@ -500,7 +500,7 @@ public:
const ObjectValue *proto = iter.next(); const ObjectValue *proto = iter.next();
if (proto->lookupMember(name, m_context) == m_context->valueOwner()->arrayPrototype()) if (proto->lookupMember(name, m_context) == m_context->valueOwner()->arrayPrototype())
return true; return true;
if (const CppComponentValue *qmlIter = dynamic_cast<const CppComponentValue *>(proto)) { if (const CppComponentValue *qmlIter = value_cast<CppComponentValue>(proto)) {
if (qmlIter->isListProperty(name)) if (qmlIter->isListProperty(name))
return true; return true;
} }
@@ -525,7 +525,7 @@ public:
if (containingObject) if (containingObject)
containingObject->lookupMember(name, m_context, &containingObject); containingObject->lookupMember(name, m_context, &containingObject);
if (const CppComponentValue * qmlObject = dynamic_cast<const CppComponentValue *>(containingObject)) { if (const CppComponentValue * qmlObject = value_cast<CppComponentValue>(containingObject)) {
const QString typeName = qmlObject->propertyType(name); const QString typeName = qmlObject->propertyType(name);
if (qmlObject->getEnum(typeName).isValid()) { if (qmlObject->getEnum(typeName).isValid()) {
return QVariant(cleanedValue); return QVariant(cleanedValue);
@@ -569,7 +569,7 @@ public:
if (containingObject) if (containingObject)
containingObject->lookupMember(name, m_context, &containingObject); containingObject->lookupMember(name, m_context, &containingObject);
const CppComponentValue * lhsCppComponent = dynamic_cast<const CppComponentValue *>(containingObject); const CppComponentValue * lhsCppComponent = value_cast<CppComponentValue>(containingObject);
if (!lhsCppComponent) if (!lhsCppComponent)
return QVariant(); return QVariant();
const QString lhsPropertyTypeName = lhsCppComponent->propertyType(name); const QString lhsPropertyTypeName = lhsCppComponent->propertyType(name);
@@ -593,7 +593,7 @@ public:
if (rhsValueObject) if (rhsValueObject)
rhsValueObject->lookupMember(rhsValueName, m_context, &rhsValueObject); rhsValueObject->lookupMember(rhsValueName, m_context, &rhsValueObject);
const CppComponentValue *rhsCppComponentValue = dynamic_cast<const CppComponentValue *>(rhsValueObject); const CppComponentValue *rhsCppComponentValue = value_cast<CppComponentValue>(rhsValueObject);
if (!rhsCppComponentValue) if (!rhsCppComponentValue)
return QVariant(); return QVariant();

View File

@@ -148,7 +148,7 @@ public:
virtual void operator ()(const Value *base, const QString &name, const Value *) virtual void operator ()(const Value *base, const QString &name, const Value *)
{ {
const CppComponentValue *qmlBase = dynamic_cast<const CppComponentValue *>(base); const CppComponentValue *qmlBase = value_cast<CppComponentValue>(base);
QString itemText = name; QString itemText = name;
QString postfix; QString postfix;
@@ -547,7 +547,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
} }
const Value *v = newScopeType->lookupMember(it->name.toString(), context); const Value *v = newScopeType->lookupMember(it->name.toString(), context);
v = context->lookupReference(v); v = context->lookupReference(v);
newScopeType = value_cast<const ObjectValue *>(v); newScopeType = value_cast<ObjectValue>(v);
} }
if (!newScopeType) if (!newScopeType)
break; break;
@@ -642,7 +642,7 @@ IAssistProposal *QmlJSCompletionAssistProcessor::perform(const IAssistInterface
const Value *value = const Value *value =
getPropertyValue(qmlScopeType, contextFinder.bindingPropertyName(), context); getPropertyValue(qmlScopeType, contextFinder.bindingPropertyName(), context);
if (const QmlEnumValue *enumValue = if (const QmlEnumValue *enumValue =
dynamic_cast<const QmlEnumValue *>(value)) { value_cast<QmlEnumValue>(value)) {
const QString &name = context->imports(document.data())->nameForImportedObject(enumValue->owner(), context.data()); const QString &name = context->imports(document.data())->nameForImportedObject(enumValue->owner(), context.data());
foreach (const QString &key, enumValue->keys()) { foreach (const QString &key, enumValue->keys()) {
QString completion; QString completion;

View File

@@ -525,7 +525,7 @@ protected:
if ((!_name.isEmpty()) && _name.at(0).isUpper()) { if ((!_name.isEmpty()) && _name.at(0).isUpper()) {
// a possible type // a possible type
_targetValue = _scopeChain->lookup(_name, &_scope); _targetValue = _scopeChain->lookup(_name, &_scope);
if (value_cast<const ObjectValue*>(_targetValue)) if (value_cast<ObjectValue>(_targetValue))
_typeKind = TypeKind; _typeKind = TypeKind;
} }
} }
@@ -851,7 +851,7 @@ static void find_helper(QFutureInterface<FindReferences::Usage> &future,
FindReferences::Usage searchStarting(replacement, name, 0, 0, 0); FindReferences::Usage searchStarting(replacement, name, 0, 0, 0);
if (findTarget.typeKind() == findTarget.TypeKind){ if (findTarget.typeKind() == findTarget.TypeKind){
const ObjectValue *typeValue = value_cast<const ObjectValue*>(findTarget.targetValue()); const ObjectValue *typeValue = value_cast<ObjectValue>(findTarget.targetValue());
if (!typeValue) if (!typeValue)
return; return;
future.reportResult(searchStarting); future.reportResult(searchStarting);

View File

@@ -300,7 +300,7 @@ void HoverHandler::prettyPrintTooltip(const QmlJS::Value *value,
} }
} }
} else if (const QmlEnumValue *enumValue = } else if (const QmlEnumValue *enumValue =
dynamic_cast<const QmlEnumValue *>(value)) { value_cast<QmlEnumValue>(value)) {
setToolTip(enumValue->name()); setToolTip(enumValue->name());
} }

View File

@@ -138,7 +138,7 @@ protected:
PrototypeIterator it(v, m_scopeChain.context()); PrototypeIterator it(v, m_scopeChain.context());
while (it.hasNext()) { while (it.hasNext()) {
const ObjectValue *proto = it.next(); const ObjectValue *proto = it.next();
const CppComponentValue *qmlProto = dynamic_cast<const CppComponentValue *>(proto); const CppComponentValue *qmlProto = value_cast<CppComponentValue>(proto);
if (!qmlProto) if (!qmlProto)
continue; continue;
if (qmlProto->metaObject() == m_statePrototype->metaObject()) if (qmlProto->metaObject() == m_statePrototype->metaObject())

View File

@@ -76,7 +76,7 @@ static inline const ObjectValue * getPropertyChangesTarget(Node *node, const Sco
&& ! scriptBinding->qualifiedId->next) { && ! scriptBinding->qualifiedId->next) {
Evaluate evaluator(&scopeChain); Evaluate evaluator(&scopeChain);
const Value *targetValue = evaluator(scriptBinding->statement); const Value *targetValue = evaluator(scriptBinding->statement);
if (const ObjectValue *targetObject = value_cast<const ObjectValue *>(targetValue)) { if (const ObjectValue *targetObject = value_cast<ObjectValue>(targetValue)) {
return targetObject; return targetObject;
} else { } else {
return 0; return 0;

View File

@@ -144,17 +144,17 @@ void tst_Basic::basicObjectTests()
QVERIFY(ovProperty); QVERIFY(ovProperty);
QCOMPARE(ovProperty->className(), QString("State")); QCOMPARE(ovProperty->className(), QString("State"));
const CppComponentValue * qmlItemValue = dynamic_cast<const CppComponentValue *>(ovItem); const CppComponentValue * qmlItemValue = value_cast<CppComponentValue>(ovItem);
QVERIFY(qmlItemValue); QVERIFY(qmlItemValue);
QCOMPARE(qmlItemValue->defaultPropertyName(), QString("data")); QCOMPARE(qmlItemValue->defaultPropertyName(), QString("data"));
QCOMPARE(qmlItemValue->propertyType("state"), QString("string")); QCOMPARE(qmlItemValue->propertyType("state"), QString("string"));
const ObjectValue *ovState = context->lookupType(doc.data(), QStringList() << "State"); const ObjectValue *ovState = context->lookupType(doc.data(), QStringList() << "State");
const CppComponentValue * qmlState2Value = dynamic_cast<const CppComponentValue *>(ovState); const CppComponentValue * qmlState2Value = value_cast<CppComponentValue>(ovState);
QCOMPARE(qmlState2Value->className(), QString("State")); QCOMPARE(qmlState2Value->className(), QString("State"));
const ObjectValue *ovImage = context->lookupType(doc.data(), QStringList() << "Image"); const ObjectValue *ovImage = context->lookupType(doc.data(), QStringList() << "Image");
const CppComponentValue * qmlImageValue = dynamic_cast<const CppComponentValue *>(ovImage); const CppComponentValue * qmlImageValue = value_cast<CppComponentValue>(ovImage);
QCOMPARE(qmlImageValue->className(), QString("Image")); QCOMPARE(qmlImageValue->className(), QString("Image"));
QCOMPARE(qmlImageValue->propertyType("source"), QString("QUrl")); QCOMPARE(qmlImageValue->propertyType("source"), QString("QUrl"));
} }