forked from qt-creator/qt-creator
QmlJS: Convert more dynamic_casts to value_casts.
And introduce a good error message for the case when someone forgets the specialization of the value_cast template. Change-Id: Iec55a839e8f5eef5872b1dab8601f66e0e0c88de Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
This commit is contained in:
@@ -704,6 +704,11 @@ const ASTPropertyReference *Value::asAstPropertyReference() const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const ASTSignal *Value::asAstSignal() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Values
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -1982,6 +1987,11 @@ ASTSignal::~ASTSignal()
|
||||
{
|
||||
}
|
||||
|
||||
const ASTSignal *ASTSignal::asAstSignal() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
int ASTSignal::argumentCount() const
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
@@ -80,6 +80,7 @@ class ASTObjectValue;
|
||||
class QmlEnumValue;
|
||||
class QmlPrototypeReference;
|
||||
class ASTPropertyReference;
|
||||
class ASTSignal;
|
||||
|
||||
typedef QList<const Value *> ValueList;
|
||||
|
||||
@@ -134,13 +135,19 @@ public:
|
||||
virtual const QmlEnumValue *asQmlEnumValue() const;
|
||||
virtual const QmlPrototypeReference *asQmlPrototypeReference() const;
|
||||
virtual const ASTPropertyReference *asAstPropertyReference() const;
|
||||
virtual const ASTSignal *asAstSignal() const;
|
||||
|
||||
virtual void accept(ValueVisitor *) const = 0;
|
||||
|
||||
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
||||
};
|
||||
|
||||
template <typename _RetTy> const _RetTy *value_cast(const Value *v);
|
||||
template <typename _RetTy> const _RetTy *value_cast(const Value *)
|
||||
{
|
||||
// Produce a good error message if a specialization is missing.
|
||||
_RetTy::ERROR_MissingValueCastSpecialization();
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <> Q_INLINE_TEMPLATE const NullValue *value_cast(const Value *v)
|
||||
{
|
||||
@@ -250,6 +257,12 @@ template <> Q_INLINE_TEMPLATE const ASTPropertyReference *value_cast(const Value
|
||||
else return 0;
|
||||
}
|
||||
|
||||
template <> Q_INLINE_TEMPLATE const ASTSignal *value_cast(const Value *v)
|
||||
{
|
||||
if (v) return v->asAstSignal();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Value nodes
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -821,6 +834,8 @@ public:
|
||||
ASTSignal(AST::UiPublicMember *ast, const Document *doc, ValueOwner *valueOwner);
|
||||
virtual ~ASTSignal();
|
||||
|
||||
virtual const ASTSignal *asAstSignal() const;
|
||||
|
||||
AST::UiPublicMember *ast() const { return _ast; }
|
||||
QString slotName() const { return _slotName; }
|
||||
const ObjectValue *bodyScope() const { return _bodyScope; }
|
||||
|
||||
@@ -84,11 +84,11 @@ void ScopeBuilder::push(AST::Node *node)
|
||||
break;
|
||||
}
|
||||
// signals defined in QML
|
||||
if (const ASTSignal *astsig = dynamic_cast<const ASTSignal *>(value)) {
|
||||
if (const ASTSignal *astsig = value_cast<ASTSignal>(value)) {
|
||||
_scopeChain->appendJsScope(astsig->bodyScope());
|
||||
}
|
||||
// signals defined in C++
|
||||
else if (const CppComponentValue *qmlObject = dynamic_cast<const CppComponentValue *>(owner)) {
|
||||
else if (const CppComponentValue *qmlObject = value_cast<CppComponentValue>(owner)) {
|
||||
if (const ObjectValue *scope = qmlObject->signalScope(name)) {
|
||||
_scopeChain->appendJsScope(scope);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user