2010-01-21 15:54:19 +01:00
|
|
|
/**************************************************************************
|
|
|
|
**
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2010-01-21 15:54:19 +01:00
|
|
|
**
|
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
|
|
**
|
|
|
|
** Commercial Usage
|
|
|
|
**
|
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Nokia.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
**
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** If you are unsure which license is appropriate for your use, please
|
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
|
|
|
**
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef QMLJS_INTERPRETER_H
|
|
|
|
#define QMLJS_INTERPRETER_H
|
|
|
|
|
2010-02-04 10:19:37 +01:00
|
|
|
#include <qmljs/qmljsdocument.h>
|
2010-01-26 14:50:52 +01:00
|
|
|
#include <qmljs/qmljs_global.h>
|
2010-02-03 14:31:03 +01:00
|
|
|
#include <qmljs/parser/qmljsastfwd_p.h>
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-03-01 13:01:05 +01:00
|
|
|
#include <QtCore/QFileInfoList>
|
2010-01-21 15:54:19 +01:00
|
|
|
#include <QtCore/QList>
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
#include <QtCore/QSet>
|
|
|
|
|
|
|
|
namespace QmlJS {
|
2010-02-03 14:31:03 +01:00
|
|
|
|
|
|
|
class NameId;
|
2010-02-04 09:44:43 +01:00
|
|
|
class Document;
|
2010-02-03 14:31:03 +01:00
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
namespace Interpreter {
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Forward declarations
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class Engine;
|
|
|
|
class Value;
|
|
|
|
class NullValue;
|
|
|
|
class UndefinedValue;
|
|
|
|
class NumberValue;
|
|
|
|
class BooleanValue;
|
|
|
|
class StringValue;
|
|
|
|
class ObjectValue;
|
|
|
|
class FunctionValue;
|
2010-02-03 10:24:25 +01:00
|
|
|
class Reference;
|
2010-02-19 15:10:39 +01:00
|
|
|
class EasingCurveNameValue;
|
2010-02-23 14:36:38 +01:00
|
|
|
class ColorValue;
|
2010-02-23 17:02:50 +01:00
|
|
|
class AnchorLineValue;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-24 11:10:01 +01:00
|
|
|
typedef QList<const Value *> ValueList;
|
|
|
|
|
2010-03-01 13:01:05 +01:00
|
|
|
class FakeMetaObject;
|
|
|
|
class FakeMetaMethod;
|
|
|
|
class FakeMetaProperty;
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Value visitor
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class QMLJS_EXPORT ValueVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ValueVisitor();
|
|
|
|
virtual ~ValueVisitor();
|
|
|
|
|
|
|
|
virtual void visit(const NullValue *);
|
|
|
|
virtual void visit(const UndefinedValue *);
|
|
|
|
virtual void visit(const NumberValue *);
|
|
|
|
virtual void visit(const BooleanValue *);
|
|
|
|
virtual void visit(const StringValue *);
|
|
|
|
virtual void visit(const ObjectValue *);
|
|
|
|
virtual void visit(const FunctionValue *);
|
2010-02-03 10:24:25 +01:00
|
|
|
virtual void visit(const Reference *);
|
2010-02-19 15:10:39 +01:00
|
|
|
virtual void visit(const EasingCurveNameValue *);
|
2010-02-23 14:36:38 +01:00
|
|
|
virtual void visit(const ColorValue *);
|
2010-02-23 17:02:50 +01:00
|
|
|
virtual void visit(const AnchorLineValue *);
|
2010-01-21 15:54:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// QML/JS value
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class QMLJS_EXPORT Value
|
|
|
|
{
|
|
|
|
Value(const Value &other);
|
|
|
|
void operator = (const Value &other);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Value();
|
|
|
|
virtual ~Value();
|
|
|
|
|
|
|
|
virtual const NullValue *asNullValue() const;
|
|
|
|
virtual const UndefinedValue *asUndefinedValue() const;
|
|
|
|
virtual const NumberValue *asNumberValue() const;
|
|
|
|
virtual const BooleanValue *asBooleanValue() const;
|
|
|
|
virtual const StringValue *asStringValue() const;
|
|
|
|
virtual const ObjectValue *asObjectValue() const;
|
|
|
|
virtual const FunctionValue *asFunctionValue() const;
|
2010-02-03 10:24:25 +01:00
|
|
|
virtual const Reference *asReference() const;
|
2010-02-19 15:10:39 +01:00
|
|
|
virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
|
2010-02-23 14:36:38 +01:00
|
|
|
virtual const ColorValue *asColorValue() const;
|
2010-02-23 17:02:50 +01:00
|
|
|
virtual const AnchorLineValue *asAnchorLineValue() const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
virtual void accept(ValueVisitor *) const = 0;
|
2010-02-08 12:50:10 +01:00
|
|
|
|
|
|
|
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename _RetTy> _RetTy value_cast(const Value *v);
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const NullValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asNullValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const UndefinedValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asUndefinedValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const NumberValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asNumberValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const BooleanValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asBooleanValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const StringValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asStringValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const ObjectValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asObjectValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <> Q_INLINE_TEMPLATE const FunctionValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asFunctionValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-03 10:24:25 +01:00
|
|
|
template <> Q_INLINE_TEMPLATE const Reference *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asReference();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-19 15:10:39 +01:00
|
|
|
template <> Q_INLINE_TEMPLATE const EasingCurveNameValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asEasingCurveNameValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-23 14:36:38 +01:00
|
|
|
template <> Q_INLINE_TEMPLATE const ColorValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asColorValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-23 17:02:50 +01:00
|
|
|
template <> Q_INLINE_TEMPLATE const AnchorLineValue *value_cast(const Value *v)
|
|
|
|
{
|
|
|
|
if (v) return v->asAnchorLineValue();
|
|
|
|
else return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Value nodes
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
class QMLJS_EXPORT NullValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const NullValue *asNullValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT UndefinedValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const UndefinedValue *asUndefinedValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT NumberValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const NumberValue *asNumberValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT BooleanValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const BooleanValue *asBooleanValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT StringValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const StringValue *asStringValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
2010-01-24 11:10:01 +01:00
|
|
|
class QMLJS_EXPORT MemberProcessor
|
|
|
|
{
|
|
|
|
MemberProcessor(const MemberProcessor &other);
|
|
|
|
void operator = (const MemberProcessor &other);
|
|
|
|
|
|
|
|
public:
|
2010-01-26 10:10:11 +01:00
|
|
|
MemberProcessor();
|
|
|
|
virtual ~MemberProcessor();
|
2010-01-24 11:10:01 +01:00
|
|
|
|
|
|
|
// Returns false to stop the processor.
|
2010-01-26 10:10:11 +01:00
|
|
|
virtual bool processProperty(const QString &name, const Value *value);
|
2010-01-28 15:50:58 +01:00
|
|
|
virtual bool processEnumerator(const QString &name, const Value *value);
|
2010-01-26 10:10:11 +01:00
|
|
|
virtual bool processSignal(const QString &name, const Value *value);
|
|
|
|
virtual bool processSlot(const QString &name, const Value *value);
|
2010-01-26 10:19:42 +01:00
|
|
|
virtual bool processGeneratedSlot(const QString &name, const Value *value);
|
2010-01-24 11:10:01 +01:00
|
|
|
};
|
|
|
|
|
2010-02-19 10:14:34 +01:00
|
|
|
class QMLJS_EXPORT ScopeChain
|
2010-02-03 10:24:25 +01:00
|
|
|
{
|
2010-02-03 14:31:03 +01:00
|
|
|
public:
|
2010-02-19 10:14:34 +01:00
|
|
|
ScopeChain();
|
|
|
|
|
|
|
|
struct QmlComponentChain
|
|
|
|
{
|
2010-02-22 11:21:03 +01:00
|
|
|
QmlComponentChain();
|
|
|
|
~QmlComponentChain();
|
2010-02-03 14:31:03 +01:00
|
|
|
|
2010-02-19 10:14:34 +01:00
|
|
|
QList<QmlComponentChain *> instantiatingComponents;
|
|
|
|
const ObjectValue *rootObject;
|
|
|
|
QList<const ObjectValue *> functionScopes;
|
|
|
|
const ObjectValue *ids;
|
|
|
|
|
|
|
|
void add(QList<const ObjectValue *> *list) const;
|
2010-02-22 11:21:03 +01:00
|
|
|
void clear();
|
2010-02-19 10:14:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const ObjectValue *globalScope;
|
|
|
|
QmlComponentChain qmlComponentScope;
|
|
|
|
QList<const ObjectValue *> qmlScopeObjects;
|
|
|
|
const ObjectValue *qmlTypes;
|
|
|
|
QList<const ObjectValue *> jsScopes;
|
|
|
|
|
|
|
|
// rebuilds the flat list of all scopes
|
|
|
|
void update();
|
2010-02-22 10:21:07 +01:00
|
|
|
QList<const ObjectValue *> all() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QList<const ObjectValue *> _all;
|
2010-02-19 10:14:34 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Context
|
|
|
|
{
|
|
|
|
public:
|
2010-02-03 14:31:03 +01:00
|
|
|
enum LookupMode {
|
|
|
|
JSLookup,
|
|
|
|
QmlLookup
|
|
|
|
};
|
|
|
|
|
2010-02-03 10:24:25 +01:00
|
|
|
public:
|
|
|
|
Context(Engine *engine);
|
2010-02-03 14:31:03 +01:00
|
|
|
~Context();
|
2010-02-03 10:24:25 +01:00
|
|
|
|
2010-03-16 16:34:33 +01:00
|
|
|
void build(const QList<AST::Node *> &astPath, const Document::Ptr doc,
|
|
|
|
const Snapshot &snapshot, const QStringList &importPaths);
|
2010-02-04 10:19:37 +01:00
|
|
|
|
2010-02-03 10:24:25 +01:00
|
|
|
Engine *engine() const;
|
2010-02-19 10:14:34 +01:00
|
|
|
const ScopeChain &scopeChain() const;
|
|
|
|
ScopeChain &scopeChain();
|
2010-02-03 14:31:03 +01:00
|
|
|
|
|
|
|
LookupMode lookupMode() const;
|
|
|
|
void setLookupMode(LookupMode lookupMode);
|
|
|
|
|
2010-02-04 09:44:43 +01:00
|
|
|
const ObjectValue *typeEnvironment(const Document *doc) const;
|
|
|
|
void setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment);
|
2010-02-03 15:39:57 +01:00
|
|
|
|
|
|
|
const Value *lookup(const QString &name);
|
2010-02-04 09:44:43 +01:00
|
|
|
const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName);
|
2010-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
const Value *property(const ObjectValue *object, const QString &name) const;
|
|
|
|
void setProperty(const ObjectValue *object, const QString &name, const Value *value);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef QHash<QString, const Value *> Properties;
|
|
|
|
|
|
|
|
Engine *_engine;
|
2010-02-03 14:31:03 +01:00
|
|
|
LookupMode _lookupMode;
|
2010-02-03 10:24:25 +01:00
|
|
|
QHash<const ObjectValue *, Properties> _properties;
|
2010-03-16 16:34:33 +01:00
|
|
|
QHash<QString, const ObjectValue *> _typeEnvironments;
|
2010-02-16 10:36:09 +01:00
|
|
|
ScopeChain _scopeChain;
|
|
|
|
int _qmlScopeObjectIndex;
|
|
|
|
bool _qmlScopeObjectSet;
|
2010-02-03 10:24:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Reference: public Value
|
|
|
|
{
|
|
|
|
public:
|
2010-02-03 14:31:03 +01:00
|
|
|
Reference(Engine *engine);
|
2010-02-03 10:24:25 +01:00
|
|
|
virtual ~Reference();
|
|
|
|
|
2010-02-03 14:31:03 +01:00
|
|
|
Engine *engine() const;
|
|
|
|
virtual const Value *value(Context *context) const;
|
2010-02-03 10:24:25 +01:00
|
|
|
|
|
|
|
// Value interface
|
|
|
|
virtual const Reference *asReference() const;
|
|
|
|
virtual void accept(ValueVisitor *) const;
|
2010-02-03 14:31:03 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Engine *_engine;
|
2010-02-03 10:24:25 +01:00
|
|
|
};
|
|
|
|
|
2010-02-19 15:10:39 +01:00
|
|
|
class QMLJS_EXPORT EasingCurveNameValue: public Value
|
|
|
|
{
|
|
|
|
static QSet<QString> _curveNames;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static QSet<QString> curveNames();
|
|
|
|
|
|
|
|
// Value interface
|
|
|
|
virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
|
|
|
|
virtual void accept(ValueVisitor *) const;
|
|
|
|
};
|
|
|
|
|
2010-02-23 14:36:38 +01:00
|
|
|
class QMLJS_EXPORT ColorValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Value interface
|
|
|
|
virtual const ColorValue *asColorValue() const;
|
|
|
|
virtual void accept(ValueVisitor *) const;
|
|
|
|
};
|
|
|
|
|
2010-02-23 17:02:50 +01:00
|
|
|
class QMLJS_EXPORT AnchorLineValue: public Value
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Value interface
|
|
|
|
virtual const AnchorLineValue *asAnchorLineValue() const;
|
|
|
|
virtual void accept(ValueVisitor *) const;
|
|
|
|
};
|
|
|
|
|
2010-02-03 10:59:52 +01:00
|
|
|
class QMLJS_EXPORT ObjectValue: public Value
|
2010-01-21 15:54:19 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ObjectValue(Engine *engine);
|
2010-01-24 11:10:01 +01:00
|
|
|
virtual ~ObjectValue();
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
Engine *engine() const;
|
|
|
|
|
|
|
|
QString className() const;
|
|
|
|
void setClassName(const QString &className);
|
|
|
|
|
2010-02-03 15:39:57 +01:00
|
|
|
const ObjectValue *prototype(Context *context) const;
|
|
|
|
void setPrototype(const Value *prototype);
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-24 11:10:01 +01:00
|
|
|
virtual void processMembers(MemberProcessor *processor) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-02-03 15:39:57 +01:00
|
|
|
virtual const Value *property(const QString &name, Context *context) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
virtual void setProperty(const QString &name, const Value *value);
|
|
|
|
virtual void removeProperty(const QString &name);
|
|
|
|
|
2010-04-06 11:44:55 +02:00
|
|
|
virtual const Value *lookupMember(const QString &name, Context *context, bool examinePrototypes = true) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
// Value interface
|
|
|
|
virtual const ObjectValue *asObjectValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
|
|
|
|
private:
|
2010-01-24 11:10:01 +01:00
|
|
|
bool checkPrototype(const ObjectValue *prototype, QSet<const ObjectValue *> *processed) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
Engine *_engine;
|
2010-02-03 15:39:57 +01:00
|
|
|
const Value *_prototype;
|
2010-01-21 15:54:19 +01:00
|
|
|
QHash<QString, const Value *> _members;
|
|
|
|
QString _className;
|
|
|
|
};
|
|
|
|
|
2010-03-16 13:10:18 +01:00
|
|
|
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
|
2010-01-26 14:50:52 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-03-01 13:01:05 +01:00
|
|
|
static const int NoVersion;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QmlObjectValue(const FakeMetaObject *metaObject, Engine *engine);
|
2010-01-26 14:50:52 +01:00
|
|
|
virtual ~QmlObjectValue();
|
|
|
|
|
|
|
|
virtual void processMembers(MemberProcessor *processor) const;
|
2010-03-01 13:01:05 +01:00
|
|
|
const Value *propertyValue(const FakeMetaProperty &prop) const;
|
2010-01-26 14:50:52 +01:00
|
|
|
|
2010-03-01 13:01:05 +01:00
|
|
|
QString packageName() const;
|
|
|
|
int majorVersion() const;
|
|
|
|
int minorVersion() const;
|
2010-03-31 14:18:57 +02:00
|
|
|
QString defaultPropertyName() const;
|
2010-04-06 11:44:55 +02:00
|
|
|
QString propertyType(const QString &propertyName) const;
|
2010-04-06 12:56:53 +02:00
|
|
|
bool isListProperty(const QString &name) const;
|
2010-04-06 11:44:55 +02:00
|
|
|
bool isEnum(const QString &typeName) const;
|
2010-04-06 15:40:47 +02:00
|
|
|
bool enumContainsKey(const QString &enumName, const QString &enumKeyName) const;
|
2010-01-26 14:50:52 +01:00
|
|
|
|
2010-02-01 13:54:44 +01:00
|
|
|
protected:
|
2010-03-01 13:01:05 +01:00
|
|
|
const Value *findOrCreateSignature(int index, const FakeMetaMethod &method, QString *methodName) const;
|
|
|
|
bool isDerivedFrom(const FakeMetaObject *base) const;
|
2010-02-01 13:54:44 +01:00
|
|
|
|
2010-01-26 14:50:52 +01:00
|
|
|
private:
|
2010-03-01 13:01:05 +01:00
|
|
|
const FakeMetaObject *_metaObject;
|
2010-02-01 13:54:44 +01:00
|
|
|
mutable QHash<int, const Value *> _metaSignature;
|
2010-01-26 14:50:52 +01:00
|
|
|
};
|
|
|
|
|
2010-01-28 14:11:56 +01:00
|
|
|
class QMLJS_EXPORT Activation
|
2010-01-24 11:35:11 +01:00
|
|
|
{
|
|
|
|
public:
|
2010-02-03 15:39:57 +01:00
|
|
|
explicit Activation(Context *parentContext = 0);
|
2010-01-24 11:35:11 +01:00
|
|
|
virtual ~Activation();
|
|
|
|
|
2010-02-03 15:39:57 +01:00
|
|
|
Context *context() const;
|
|
|
|
Context *parentContext() const;
|
|
|
|
|
2010-01-24 11:35:11 +01:00
|
|
|
bool calledAsConstructor() const;
|
|
|
|
void setCalledAsConstructor(bool calledAsConstructor);
|
|
|
|
|
|
|
|
bool calledAsFunction() const;
|
|
|
|
void setCalledAsFunction(bool calledAsFunction);
|
|
|
|
|
|
|
|
ObjectValue *thisObject() const;
|
|
|
|
void setThisObject(ObjectValue *thisObject);
|
|
|
|
|
|
|
|
ValueList arguments() const;
|
|
|
|
void setArguments(const ValueList &arguments);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ObjectValue *_thisObject;
|
|
|
|
ValueList _arguments;
|
|
|
|
bool _calledAsFunction;
|
2010-02-03 15:39:57 +01:00
|
|
|
Context *_parentContext;
|
2010-01-24 11:35:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
class QMLJS_EXPORT FunctionValue: public ObjectValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FunctionValue(Engine *engine);
|
2010-01-24 11:10:01 +01:00
|
|
|
virtual ~FunctionValue();
|
|
|
|
|
|
|
|
// [[construct]]
|
|
|
|
const Value *construct(const ValueList &actuals = ValueList()) const;
|
|
|
|
|
|
|
|
// [[call]]
|
|
|
|
const Value *call(const ValueList &actuals = ValueList()) const;
|
|
|
|
|
|
|
|
const Value *call(const ObjectValue *thisObject,
|
|
|
|
const ValueList &actuals = ValueList()) const;
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
virtual const Value *returnValue() const;
|
|
|
|
|
|
|
|
virtual int argumentCount() const;
|
2010-01-24 11:10:01 +01:00
|
|
|
virtual const Value *argument(int index) const;
|
2010-01-26 10:50:30 +01:00
|
|
|
virtual QString argumentName(int index) const;
|
|
|
|
virtual bool isVariadic() const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-24 11:35:11 +01:00
|
|
|
virtual const Value *invoke(const Activation *activation) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
// Value interface
|
|
|
|
virtual const FunctionValue *asFunctionValue() const;
|
|
|
|
virtual void accept(ValueVisitor *visitor) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Function: public FunctionValue
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Function(Engine *engine);
|
2010-01-24 11:35:11 +01:00
|
|
|
virtual ~Function();
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-29 22:49:55 +01:00
|
|
|
void addArgument(const Value *argument);
|
2010-01-21 15:54:19 +01:00
|
|
|
void setReturnValue(const Value *returnValue);
|
|
|
|
|
|
|
|
// ObjectValue interface
|
2010-02-03 15:39:57 +01:00
|
|
|
virtual const Value *property(const QString &name, Context *context) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
// FunctionValue interface
|
|
|
|
virtual const Value *returnValue() const;
|
|
|
|
virtual int argumentCount() const;
|
|
|
|
virtual const Value *argument(int index) const;
|
2010-01-24 11:35:11 +01:00
|
|
|
virtual const Value *invoke(const Activation *activation) const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
private:
|
2010-01-24 11:10:01 +01:00
|
|
|
ValueList _arguments;
|
2010-01-21 15:54:19 +01:00
|
|
|
const Value *_returnValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// typing environment
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-03-01 13:01:05 +01:00
|
|
|
class QMLJS_EXPORT MetaTypeSystem
|
|
|
|
{
|
|
|
|
static QList<const FakeMetaObject *> _metaObjects;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** \return an empty list when successful, error messages otherwise. */
|
|
|
|
static QStringList load(const QFileInfoList &xmlFiles);
|
|
|
|
|
|
|
|
void reload(Interpreter::Engine *interpreter);
|
|
|
|
|
|
|
|
QList<Interpreter::QmlObjectValue *> staticTypesForImport(const QString &prefix, int majorVersion, int minorVersion) const;
|
|
|
|
Interpreter::QmlObjectValue *staticTypeForImport(const QString &qualifiedName) const;
|
|
|
|
|
2010-03-16 16:34:33 +01:00
|
|
|
bool hasPackage(const QString &package) const;
|
|
|
|
|
2010-03-01 13:01:05 +01:00
|
|
|
private:
|
|
|
|
QHash<QString, QList<QmlObjectValue *> > _importedTypes;
|
|
|
|
};
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
class ConvertToNumber: protected ValueVisitor // ECMAScript ToInt()
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConvertToNumber(Engine *engine);
|
|
|
|
|
|
|
|
const Value *operator()(const Value *value);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const Value *switchResult(const Value *value);
|
|
|
|
|
|
|
|
virtual void visit(const NullValue *);
|
|
|
|
virtual void visit(const UndefinedValue *);
|
|
|
|
virtual void visit(const NumberValue *);
|
|
|
|
virtual void visit(const BooleanValue *);
|
|
|
|
virtual void visit(const StringValue *);
|
|
|
|
virtual void visit(const ObjectValue *);
|
|
|
|
virtual void visit(const FunctionValue *);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Engine *_engine;
|
|
|
|
const Value *_result;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConvertToString: protected ValueVisitor // ECMAScript ToString
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConvertToString(Engine *engine);
|
|
|
|
|
|
|
|
const Value *operator()(const Value *value);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const Value *switchResult(const Value *value);
|
|
|
|
|
|
|
|
virtual void visit(const NullValue *);
|
|
|
|
virtual void visit(const UndefinedValue *);
|
|
|
|
virtual void visit(const NumberValue *);
|
|
|
|
virtual void visit(const BooleanValue *);
|
|
|
|
virtual void visit(const StringValue *);
|
|
|
|
virtual void visit(const ObjectValue *);
|
|
|
|
virtual void visit(const FunctionValue *);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Engine *_engine;
|
|
|
|
const Value *_result;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConvertToObject: protected ValueVisitor // ECMAScript ToObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConvertToObject(Engine *engine);
|
|
|
|
|
|
|
|
const Value *operator()(const Value *value);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
const Value *switchResult(const Value *value);
|
|
|
|
|
|
|
|
virtual void visit(const NullValue *);
|
|
|
|
virtual void visit(const UndefinedValue *);
|
|
|
|
virtual void visit(const NumberValue *);
|
|
|
|
virtual void visit(const BooleanValue *);
|
|
|
|
virtual void visit(const StringValue *);
|
|
|
|
virtual void visit(const ObjectValue *);
|
|
|
|
virtual void visit(const FunctionValue *);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Engine *_engine;
|
|
|
|
const Value *_result;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TypeId: protected ValueVisitor
|
|
|
|
{
|
|
|
|
QString _result;
|
|
|
|
|
|
|
|
public:
|
|
|
|
QString operator()(const Value *value);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void visit(const NullValue *);
|
|
|
|
virtual void visit(const UndefinedValue *);
|
|
|
|
virtual void visit(const NumberValue *);
|
|
|
|
virtual void visit(const BooleanValue *);
|
|
|
|
virtual void visit(const StringValue *);
|
|
|
|
virtual void visit(const ObjectValue *object);
|
|
|
|
virtual void visit(const FunctionValue *object);
|
2010-02-23 17:02:50 +01:00
|
|
|
virtual void visit(const EasingCurveNameValue *);
|
|
|
|
virtual void visit(const ColorValue *);
|
|
|
|
virtual void visit(const AnchorLineValue *);
|
2010-01-21 15:54:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT Engine
|
|
|
|
{
|
|
|
|
Engine(const Engine &other);
|
|
|
|
void operator = (const Engine &other);
|
|
|
|
|
|
|
|
public:
|
|
|
|
Engine();
|
|
|
|
~Engine();
|
|
|
|
|
|
|
|
const NullValue *nullValue() const;
|
|
|
|
const UndefinedValue *undefinedValue() const;
|
|
|
|
const NumberValue *numberValue() const;
|
|
|
|
const BooleanValue *booleanValue() const;
|
|
|
|
const StringValue *stringValue() const;
|
2010-02-19 15:10:39 +01:00
|
|
|
const EasingCurveNameValue *easingCurveNameValue() const;
|
2010-02-23 14:36:38 +01:00
|
|
|
const ColorValue *colorValue() const;
|
2010-02-23 17:02:50 +01:00
|
|
|
const AnchorLineValue *anchorLineValue() const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-24 11:35:11 +01:00
|
|
|
ObjectValue *newObject(const ObjectValue *prototype);
|
2010-01-21 15:54:19 +01:00
|
|
|
ObjectValue *newObject();
|
|
|
|
Function *newFunction();
|
2010-01-24 11:35:11 +01:00
|
|
|
const Value *newArray(); // ### remove me
|
2010-01-21 15:54:19 +01:00
|
|
|
|
2010-01-24 13:29:46 +01:00
|
|
|
// QML objects
|
2010-01-26 11:06:28 +01:00
|
|
|
const ObjectValue *qmlKeysObject();
|
2010-01-26 11:15:21 +01:00
|
|
|
const Value *defaultValueForBuiltinType(const QString &typeName) const;
|
2010-01-24 13:29:46 +01:00
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
// global object
|
|
|
|
ObjectValue *globalObject() const;
|
|
|
|
const ObjectValue *mathObject() const;
|
2010-02-10 15:51:21 +01:00
|
|
|
const ObjectValue *qtObject() const;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
// prototypes
|
|
|
|
ObjectValue *objectPrototype() const;
|
|
|
|
ObjectValue *functionPrototype() const;
|
|
|
|
ObjectValue *numberPrototype() const;
|
|
|
|
ObjectValue *booleanPrototype() const;
|
|
|
|
ObjectValue *stringPrototype() const;
|
|
|
|
ObjectValue *arrayPrototype() const;
|
|
|
|
ObjectValue *datePrototype() const;
|
|
|
|
ObjectValue *regexpPrototype() const;
|
|
|
|
|
|
|
|
// ctors
|
|
|
|
const FunctionValue *objectCtor() const;
|
|
|
|
const FunctionValue *functionCtor() const;
|
|
|
|
const FunctionValue *arrayCtor() const;
|
|
|
|
const FunctionValue *stringCtor() const;
|
|
|
|
const FunctionValue *booleanCtor() const;
|
|
|
|
const FunctionValue *numberCtor() const;
|
|
|
|
const FunctionValue *dateCtor() const;
|
|
|
|
const FunctionValue *regexpCtor() const;
|
|
|
|
|
|
|
|
// operators
|
2010-01-24 11:35:11 +01:00
|
|
|
const Value *convertToBoolean(const Value *value);
|
2010-01-21 15:54:19 +01:00
|
|
|
const Value *convertToNumber(const Value *value);
|
|
|
|
const Value *convertToString(const Value *value);
|
|
|
|
const Value *convertToObject(const Value *value);
|
|
|
|
QString typeId(const Value *value);
|
|
|
|
|
2010-01-26 14:50:52 +01:00
|
|
|
// typing:
|
|
|
|
const MetaTypeSystem &metaTypeSystem() const
|
|
|
|
{ return _metaTypeSystem; }
|
|
|
|
|
2010-02-03 14:31:03 +01:00
|
|
|
void registerValue(Value *value); // internal
|
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
private:
|
|
|
|
void initializePrototypes();
|
|
|
|
|
|
|
|
void addFunction(ObjectValue *object, const QString &name, const Value *result, int argumentCount);
|
|
|
|
void addFunction(ObjectValue *object, const QString &name, int argumentCount);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ObjectValue *_objectPrototype;
|
|
|
|
ObjectValue *_functionPrototype;
|
|
|
|
ObjectValue *_numberPrototype;
|
|
|
|
ObjectValue *_booleanPrototype;
|
|
|
|
ObjectValue *_stringPrototype;
|
|
|
|
ObjectValue *_arrayPrototype;
|
|
|
|
ObjectValue *_datePrototype;
|
|
|
|
ObjectValue *_regexpPrototype;
|
|
|
|
|
|
|
|
Function *_objectCtor;
|
|
|
|
Function *_functionCtor;
|
|
|
|
Function *_arrayCtor;
|
|
|
|
Function *_stringCtor;
|
|
|
|
Function *_booleanCtor;
|
|
|
|
Function *_numberCtor;
|
|
|
|
Function *_dateCtor;
|
|
|
|
Function *_regexpCtor;
|
|
|
|
|
|
|
|
ObjectValue *_globalObject;
|
|
|
|
ObjectValue *_mathObject;
|
2010-02-10 15:51:21 +01:00
|
|
|
ObjectValue *_qtObject;
|
2010-01-26 11:06:28 +01:00
|
|
|
ObjectValue *_qmlKeysObject;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
NullValue _nullValue;
|
|
|
|
UndefinedValue _undefinedValue;
|
|
|
|
NumberValue _numberValue;
|
|
|
|
BooleanValue _booleanValue;
|
|
|
|
StringValue _stringValue;
|
2010-02-19 15:10:39 +01:00
|
|
|
EasingCurveNameValue _easingCurveNameValue;
|
2010-02-23 14:36:38 +01:00
|
|
|
ColorValue _colorValue;
|
2010-02-23 17:02:50 +01:00
|
|
|
AnchorLineValue _anchorLineValue;
|
2010-02-03 14:31:03 +01:00
|
|
|
QList<Value *> _registeredValues;
|
2010-01-21 15:54:19 +01:00
|
|
|
|
|
|
|
ConvertToNumber _convertToNumber;
|
|
|
|
ConvertToString _convertToString;
|
|
|
|
ConvertToObject _convertToObject;
|
|
|
|
TypeId _typeId;
|
2010-01-26 14:50:52 +01:00
|
|
|
|
|
|
|
MetaTypeSystem _metaTypeSystem;
|
2010-01-21 15:54:19 +01:00
|
|
|
};
|
|
|
|
|
2010-02-03 14:31:03 +01:00
|
|
|
|
|
|
|
// internal
|
2010-02-03 15:39:57 +01:00
|
|
|
class QMLJS_EXPORT QmlPrototypeReference: public Reference
|
|
|
|
{
|
|
|
|
public:
|
2010-02-04 09:44:43 +01:00
|
|
|
QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, const Document *doc, Engine *engine);
|
2010-02-03 15:39:57 +01:00
|
|
|
virtual ~QmlPrototypeReference();
|
|
|
|
|
|
|
|
AST::UiQualifiedId *qmlTypeName() const;
|
|
|
|
|
|
|
|
virtual const Value *value(Context *context) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
AST::UiQualifiedId *_qmlTypeName;
|
2010-02-04 09:44:43 +01:00
|
|
|
const Document *_doc;
|
2010-02-03 15:39:57 +01:00
|
|
|
};
|
|
|
|
|
2010-02-03 14:31:03 +01:00
|
|
|
class QMLJS_EXPORT ASTVariableReference: public Reference
|
|
|
|
{
|
|
|
|
AST::VariableDeclaration *_ast;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ASTVariableReference(AST::VariableDeclaration *ast, Engine *engine);
|
|
|
|
virtual ~ASTVariableReference();
|
|
|
|
|
|
|
|
virtual const Value *value(Context *context) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class QMLJS_EXPORT ASTFunctionValue: public FunctionValue
|
|
|
|
{
|
|
|
|
AST::FunctionDeclaration *_ast;
|
|
|
|
QList<NameId *> _argumentNames;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ASTFunctionValue(AST::FunctionDeclaration *ast, Engine *engine);
|
|
|
|
virtual ~ASTFunctionValue();
|
|
|
|
|
|
|
|
AST::FunctionDeclaration *ast() const;
|
|
|
|
|
|
|
|
virtual const Value *returnValue() const;
|
|
|
|
virtual int argumentCount() const;
|
|
|
|
virtual const Value *argument(int) const;
|
|
|
|
virtual QString argumentName(int index) const;
|
|
|
|
virtual bool isVariadic() const;
|
|
|
|
};
|
|
|
|
|
2010-02-08 12:50:10 +01:00
|
|
|
class QMLJS_EXPORT ASTPropertyReference: public Reference
|
|
|
|
{
|
|
|
|
AST::UiPublicMember *_ast;
|
|
|
|
const Document *_doc;
|
2010-02-17 09:16:28 +01:00
|
|
|
QString _onChangedSlotName;
|
2010-02-08 12:50:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
ASTPropertyReference(AST::UiPublicMember *ast, const Document *doc, Engine *engine);
|
|
|
|
virtual ~ASTPropertyReference();
|
2010-02-03 14:31:03 +01:00
|
|
|
|
2010-02-08 12:50:10 +01:00
|
|
|
AST::UiPublicMember *ast() const { return _ast; }
|
2010-02-17 09:16:28 +01:00
|
|
|
QString onChangedSlotName() const { return _onChangedSlotName; }
|
2010-02-08 12:50:10 +01:00
|
|
|
|
|
|
|
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
|
|
|
virtual const Value *value(Context *context) const;
|
|
|
|
};
|
|
|
|
|
2010-02-17 08:44:17 +01:00
|
|
|
class QMLJS_EXPORT ASTSignalReference: public Reference
|
|
|
|
{
|
|
|
|
AST::UiPublicMember *_ast;
|
|
|
|
const Document *_doc;
|
|
|
|
QString _slotName;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ASTSignalReference(AST::UiPublicMember *ast, const Document *doc, Engine *engine);
|
|
|
|
virtual ~ASTSignalReference();
|
|
|
|
|
|
|
|
AST::UiPublicMember *ast() const { return _ast; }
|
|
|
|
QString slotName() const { return _slotName; }
|
|
|
|
|
|
|
|
virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
|
|
|
virtual const Value *value(Context *context) const;
|
|
|
|
};
|
|
|
|
|
2010-02-08 12:50:10 +01:00
|
|
|
class QMLJS_EXPORT ASTObjectValue: public ObjectValue
|
|
|
|
{
|
|
|
|
AST::UiQualifiedId *_typeName;
|
|
|
|
AST::UiObjectInitializer *_initializer;
|
|
|
|
const Document *_doc;
|
|
|
|
QList<ASTPropertyReference *> _properties;
|
2010-02-17 08:44:17 +01:00
|
|
|
QList<ASTSignalReference *> _signals;
|
2010-02-08 12:50:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
ASTObjectValue(AST::UiQualifiedId *typeName,
|
|
|
|
AST::UiObjectInitializer *initializer,
|
|
|
|
const Document *doc,
|
|
|
|
Engine *engine);
|
|
|
|
virtual ~ASTObjectValue();
|
|
|
|
|
|
|
|
bool getSourceLocation(QString *fileName, int *line, int *column) const;
|
|
|
|
virtual void processMembers(MemberProcessor *processor) const;
|
|
|
|
};
|
2010-02-03 14:31:03 +01:00
|
|
|
|
2010-01-21 15:54:19 +01:00
|
|
|
} } // end of namespace QmlJS::Interpreter
|
|
|
|
|
|
|
|
#endif // QMLJS_INTERPRETER_H
|