2013-08-06 14:41:28 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-08-06 14:41:28 +00:00
|
|
|
**
|
|
|
|
** This file is part of the tools applications of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
2013-08-06 14:41:28 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 09:38:36 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2013-08-06 14:41:28 +00:00
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2016-01-19 09:38:36 +00:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL3 included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 3 requirements
|
|
|
|
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
|
2013-08-06 14:41:28 +00:00
|
|
|
**
|
2016-01-19 09:38:36 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 2.0 or (at your option) the GNU General
|
|
|
|
** Public license version 3 or any later version approved by the KDE Free
|
|
|
|
** Qt Foundation. The licenses are as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
|
|
|
|
** https://www.gnu.org/licenses/gpl-3.0.html.
|
2013-08-06 14:41:28 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
2014-03-17 20:26:04 +00:00
|
|
|
#ifndef QQMLIRBUILDER_P_H
|
|
|
|
#define QQMLIRBUILDER_P_H
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2015-10-05 08:45:54 +00:00
|
|
|
//
|
|
|
|
// W A R N I N G
|
|
|
|
// -------------
|
|
|
|
//
|
|
|
|
// This file is not part of the Qt API. It exists purely as an
|
|
|
|
// implementation detail. This header file may change from version to
|
|
|
|
// version without notice, or even be removed.
|
|
|
|
//
|
|
|
|
// We mean it.
|
|
|
|
//
|
|
|
|
|
2013-08-06 14:41:28 +00:00
|
|
|
#include <private/qqmljsast_p.h>
|
|
|
|
#include <private/qqmljsengine_p.h>
|
|
|
|
#include <private/qv4compiler_p.h>
|
|
|
|
#include <private/qv4compileddata_p.h>
|
|
|
|
#include <private/qqmljsmemorypool_p.h>
|
|
|
|
#include <private/qv4codegen_p.h>
|
|
|
|
#include <private/qv4compiler_p.h>
|
2014-12-05 15:32:56 +00:00
|
|
|
#include <private/qqmljslexer_p.h>
|
2013-08-06 14:41:28 +00:00
|
|
|
#include <QTextStream>
|
2013-09-11 17:28:13 +00:00
|
|
|
#include <QCoreApplication>
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
#ifndef V4_BOOTSTRAP
|
|
|
|
#include <private/qqmlpropertycache_p.h>
|
|
|
|
#endif
|
|
|
|
|
2013-08-06 14:41:28 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
class QQmlPropertyCache;
|
2014-03-18 22:39:02 +00:00
|
|
|
class QQmlContextData;
|
2013-10-24 12:51:02 +00:00
|
|
|
class QQmlTypeNameCache;
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
namespace QmlIR {
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-03-27 16:07:06 +00:00
|
|
|
struct Document;
|
|
|
|
struct IRLoader;
|
|
|
|
|
2013-08-06 14:41:28 +00:00
|
|
|
template <typename T>
|
|
|
|
struct PoolList
|
|
|
|
{
|
|
|
|
PoolList()
|
|
|
|
: first(0)
|
|
|
|
, last(0)
|
|
|
|
, count(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
T *first;
|
|
|
|
T *last;
|
|
|
|
int count;
|
|
|
|
|
2014-01-31 13:00:53 +00:00
|
|
|
int append(T *item) {
|
2013-08-06 14:41:28 +00:00
|
|
|
item->next = 0;
|
|
|
|
if (last)
|
|
|
|
last->next = item;
|
|
|
|
else
|
|
|
|
first = item;
|
|
|
|
last = item;
|
2014-01-31 13:00:53 +00:00
|
|
|
return count++;
|
2013-08-06 14:41:28 +00:00
|
|
|
}
|
2014-02-03 09:29:04 +00:00
|
|
|
|
|
|
|
void prepend(T *item) {
|
|
|
|
item->next = first;
|
|
|
|
first = item;
|
|
|
|
if (!last)
|
|
|
|
last = first;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Sortable, typename Base, Sortable Base::*sortMember>
|
|
|
|
T *findSortedInsertionPoint(T *item) const
|
|
|
|
{
|
|
|
|
T *insertPos = 0;
|
|
|
|
|
|
|
|
for (T *it = first; it; it = it->next) {
|
2016-05-13 11:41:42 +00:00
|
|
|
if (!(it->*sortMember <= item->*sortMember))
|
2014-02-03 09:29:04 +00:00
|
|
|
break;
|
|
|
|
insertPos = it;
|
|
|
|
}
|
|
|
|
|
|
|
|
return insertPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void insertAfter(T *insertionPoint, T *item) {
|
|
|
|
if (!insertionPoint) {
|
|
|
|
prepend(item);
|
|
|
|
} else if (insertionPoint == last) {
|
|
|
|
append(item);
|
|
|
|
} else {
|
|
|
|
item->next = insertionPoint->next;
|
|
|
|
insertionPoint->next = item;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 15:36:41 +00:00
|
|
|
|
2014-03-04 14:26:18 +00:00
|
|
|
T *unlink(T *before, T *item) {
|
|
|
|
T * const newNext = item->next;
|
|
|
|
|
|
|
|
if (before)
|
|
|
|
before->next = newNext;
|
|
|
|
else
|
|
|
|
first = newNext;
|
|
|
|
|
|
|
|
if (item == last) {
|
|
|
|
if (newNext)
|
|
|
|
last = newNext;
|
|
|
|
else
|
|
|
|
last = first;
|
|
|
|
}
|
|
|
|
|
|
|
|
--count;
|
|
|
|
return newNext;
|
|
|
|
}
|
|
|
|
|
2014-02-25 15:36:41 +00:00
|
|
|
T *slowAt(int index) const
|
|
|
|
{
|
|
|
|
T *result = first;
|
|
|
|
while (index > 0 && result) {
|
|
|
|
result = result->next;
|
|
|
|
--index;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class FixedPoolArray
|
|
|
|
{
|
|
|
|
T *data;
|
|
|
|
public:
|
2014-03-06 15:19:42 +00:00
|
|
|
int count;
|
2014-02-25 15:36:41 +00:00
|
|
|
|
|
|
|
void init(QQmlJS::MemoryPool *pool, const QVector<T> &vector)
|
|
|
|
{
|
|
|
|
count = vector.count();
|
|
|
|
data = reinterpret_cast<T*>(pool->allocate(count * sizeof(T)));
|
|
|
|
|
|
|
|
if (QTypeInfo<T>::isComplex) {
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
new (data + i) T(vector.at(i));
|
|
|
|
} else {
|
|
|
|
memcpy(data, static_cast<const void*>(vector.constData()), count * sizeof(T));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const T &at(int index) const {
|
|
|
|
Q_ASSERT(index >= 0 && index < count);
|
|
|
|
return data[index];
|
|
|
|
}
|
|
|
|
|
2014-03-06 15:19:42 +00:00
|
|
|
T &operator[](int index) {
|
|
|
|
Q_ASSERT(index >= 0 && index < count);
|
|
|
|
return data[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-25 15:36:41 +00:00
|
|
|
int indexOf(const T &value) const {
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
if (data[i] == value)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
struct Object;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
|
|
|
struct SignalParameter : public QV4::CompiledData::Parameter
|
|
|
|
{
|
|
|
|
SignalParameter *next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Signal
|
|
|
|
{
|
|
|
|
int nameIndex;
|
2013-09-06 12:14:20 +00:00
|
|
|
QV4::CompiledData::Location location;
|
2013-08-06 14:41:28 +00:00
|
|
|
PoolList<SignalParameter> *parameters;
|
2013-09-13 13:03:51 +00:00
|
|
|
|
2014-03-27 16:07:06 +00:00
|
|
|
QStringList parameterStringList(const QV4::Compiler::StringTableGenerator *stringPool) const;
|
2013-09-13 13:03:51 +00:00
|
|
|
|
2013-08-06 14:41:28 +00:00
|
|
|
Signal *next;
|
|
|
|
};
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
struct Property : public QV4::CompiledData::Property
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2014-03-17 16:11:20 +00:00
|
|
|
Property *next;
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Binding : public QV4::CompiledData::Binding
|
|
|
|
{
|
2016-05-13 11:41:42 +00:00
|
|
|
// The offset in the source file where the binding appeared. This is used for sorting to ensure
|
|
|
|
// that assignments to list properties are done in the correct order. We use the offset here instead
|
|
|
|
// of Binding::location as the latter has limited precision.
|
|
|
|
quint32 offset;
|
2014-02-25 15:36:41 +00:00
|
|
|
// Binding's compiledScriptIndex is index in object's functionsAndExpressions
|
2013-08-06 14:41:28 +00:00
|
|
|
Binding *next;
|
|
|
|
};
|
|
|
|
|
2016-05-19 14:14:22 +00:00
|
|
|
struct Alias : public QV4::CompiledData::Alias
|
|
|
|
{
|
|
|
|
Alias *next;
|
|
|
|
};
|
|
|
|
|
2013-08-06 14:41:28 +00:00
|
|
|
struct Function
|
|
|
|
{
|
2014-02-14 12:58:40 +00:00
|
|
|
QQmlJS::AST::FunctionDeclaration *functionDeclaration;
|
2013-12-11 12:44:56 +00:00
|
|
|
QV4::CompiledData::Location location;
|
2014-01-31 13:00:53 +00:00
|
|
|
int nameIndex;
|
2014-02-25 15:36:41 +00:00
|
|
|
quint32 index; // index in parsedQML::functions
|
2013-08-06 14:41:28 +00:00
|
|
|
Function *next;
|
|
|
|
};
|
|
|
|
|
2014-04-28 11:41:34 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT CompiledFunctionOrExpression
|
2014-01-31 13:00:53 +00:00
|
|
|
{
|
|
|
|
CompiledFunctionOrExpression()
|
|
|
|
: node(0)
|
2014-02-25 15:36:41 +00:00
|
|
|
, nameIndex(0)
|
2014-01-31 13:00:53 +00:00
|
|
|
, disableAcceleratedLookups(false)
|
2014-02-25 15:36:41 +00:00
|
|
|
, next(0)
|
2014-01-31 13:00:53 +00:00
|
|
|
{}
|
2014-02-14 12:58:40 +00:00
|
|
|
CompiledFunctionOrExpression(QQmlJS::AST::Node *n)
|
2014-01-31 13:00:53 +00:00
|
|
|
: node(n)
|
2014-02-25 15:36:41 +00:00
|
|
|
, nameIndex(0)
|
2014-01-31 13:00:53 +00:00
|
|
|
, disableAcceleratedLookups(false)
|
2014-02-25 15:36:41 +00:00
|
|
|
, next(0)
|
2014-01-31 13:00:53 +00:00
|
|
|
{}
|
2014-02-14 12:58:40 +00:00
|
|
|
QQmlJS::AST::Node *node; // FunctionDeclaration, Statement or Expression
|
2014-02-25 15:36:41 +00:00
|
|
|
quint32 nameIndex;
|
2014-01-31 13:00:53 +00:00
|
|
|
bool disableAcceleratedLookups;
|
2014-02-25 15:36:41 +00:00
|
|
|
CompiledFunctionOrExpression *next;
|
2014-01-31 13:00:53 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT Object
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2014-03-17 16:11:20 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(Object)
|
2014-01-31 13:00:53 +00:00
|
|
|
public:
|
2014-02-03 12:30:06 +00:00
|
|
|
quint32 inheritedTypeNameIndex;
|
2014-01-31 14:23:30 +00:00
|
|
|
quint32 idIndex;
|
2016-05-19 14:14:22 +00:00
|
|
|
int indexOfDefaultPropertyOrAlias : 31;
|
|
|
|
int defaultPropertyIsAlias : 1;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2013-09-08 09:05:20 +00:00
|
|
|
QV4::CompiledData::Location location;
|
2013-09-17 15:27:07 +00:00
|
|
|
QV4::CompiledData::Location locationOfIdProperty;
|
2013-09-08 09:05:20 +00:00
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
const Property *firstProperty() const { return properties->first; }
|
2014-01-31 13:00:53 +00:00
|
|
|
int propertyCount() const { return properties->count; }
|
2016-05-23 08:38:33 +00:00
|
|
|
Alias *firstAlias() const { return aliases->first; }
|
2016-05-19 14:14:22 +00:00
|
|
|
int aliasCount() const { return aliases->count; }
|
2014-01-31 13:00:53 +00:00
|
|
|
const Signal *firstSignal() const { return qmlSignals->first; }
|
|
|
|
int signalCount() const { return qmlSignals->count; }
|
|
|
|
Binding *firstBinding() const { return bindings->first; }
|
|
|
|
int bindingCount() const { return bindings->count; }
|
|
|
|
const Function *firstFunction() const { return functions->first; }
|
|
|
|
int functionCount() const { return functions->count; }
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-01-28 09:41:58 +00:00
|
|
|
// If set, then declarations for this object (and init bindings for these) should go into the
|
|
|
|
// specified object. Used for declarations inside group properties.
|
2014-03-17 16:11:20 +00:00
|
|
|
Object *declarationsOverride;
|
2014-01-28 09:41:58 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
void init(QQmlJS::MemoryPool *pool, int typeNameIndex, int id, const QQmlJS::AST::SourceLocation &location = QQmlJS::AST::SourceLocation());
|
2014-01-07 14:35:20 +00:00
|
|
|
|
2014-02-25 15:36:41 +00:00
|
|
|
QString sanityCheckFunctionNames(const QSet<QString> &illegalNames, QQmlJS::AST::SourceLocation *errorLocation);
|
2014-01-31 13:00:53 +00:00
|
|
|
|
|
|
|
QString appendSignal(Signal *signal);
|
2014-03-17 16:11:20 +00:00
|
|
|
QString appendProperty(Property *prop, const QString &propertyName, bool isDefaultProperty, const QQmlJS::AST::SourceLocation &defaultToken, QQmlJS::AST::SourceLocation *errorLocation);
|
2016-05-19 14:14:22 +00:00
|
|
|
QString appendAlias(Alias *prop, const QString &aliasName, bool isDefaultProperty, const QQmlJS::AST::SourceLocation &defaultToken, QQmlJS::AST::SourceLocation *errorLocation);
|
2014-03-17 16:11:20 +00:00
|
|
|
void appendFunction(QmlIR::Function *f);
|
2014-01-31 13:00:53 +00:00
|
|
|
|
2014-02-03 12:30:06 +00:00
|
|
|
QString appendBinding(Binding *b, bool isListBinding);
|
2014-02-20 12:48:24 +00:00
|
|
|
Binding *findBinding(quint32 nameIndex) const;
|
2014-03-04 14:26:18 +00:00
|
|
|
Binding *unlinkBinding(Binding *before, Binding *binding) { return bindings->unlink(before, binding); }
|
|
|
|
void insertSorted(Binding *b);
|
2014-04-01 09:00:27 +00:00
|
|
|
QString bindingAsString(Document *doc, int scriptIndex) const;
|
2014-01-31 13:00:53 +00:00
|
|
|
|
2014-02-25 15:36:41 +00:00
|
|
|
PoolList<CompiledFunctionOrExpression> *functionsAndExpressions;
|
|
|
|
FixedPoolArray<int> *runtimeFunctionIndices;
|
|
|
|
|
2014-01-31 13:00:53 +00:00
|
|
|
private:
|
2014-03-27 16:07:06 +00:00
|
|
|
friend struct IRLoader;
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
PoolList<Property> *properties;
|
2016-05-19 14:14:22 +00:00
|
|
|
PoolList<Alias> *aliases;
|
2014-01-31 13:00:53 +00:00
|
|
|
PoolList<Signal> *qmlSignals;
|
|
|
|
PoolList<Binding> *bindings;
|
|
|
|
PoolList<Function> *functions;
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT Pragma
|
2013-09-24 19:49:10 +00:00
|
|
|
{
|
|
|
|
enum PragmaType {
|
|
|
|
PragmaSingleton = 0x1
|
|
|
|
};
|
|
|
|
quint32 type;
|
|
|
|
|
|
|
|
QV4::CompiledData::Location location;
|
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT Document
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2014-03-27 16:07:06 +00:00
|
|
|
Document(bool debugMode);
|
2013-08-06 14:41:28 +00:00
|
|
|
QString code;
|
|
|
|
QQmlJS::Engine jsParserEngine;
|
2014-02-14 12:58:40 +00:00
|
|
|
QV4::IR::Module jsModule;
|
2014-03-27 16:07:06 +00:00
|
|
|
QList<const QV4::CompiledData::Import *> imports;
|
2013-09-24 19:49:10 +00:00
|
|
|
QList<Pragma*> pragmas;
|
2014-02-14 12:58:40 +00:00
|
|
|
QQmlJS::AST::UiProgram *program;
|
2013-08-06 14:41:28 +00:00
|
|
|
int indexOfRootObject;
|
2014-03-17 16:11:20 +00:00
|
|
|
QList<Object*> objects;
|
2013-08-06 14:41:28 +00:00
|
|
|
QV4::Compiler::JSUnitGenerator jsGenerator;
|
2014-03-18 17:21:18 +00:00
|
|
|
quint32 unitFlags;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-10-04 15:18:15 +00:00
|
|
|
QQmlRefPointer<QV4::CompiledData::CompilationUnit> javaScriptCompilationUnit;
|
2014-03-27 16:07:06 +00:00
|
|
|
QHash<int, QStringList> extraSignalParameters;
|
|
|
|
|
2013-09-12 08:53:20 +00:00
|
|
|
QV4::CompiledData::TypeReferenceMap typeReferences;
|
2014-03-27 16:07:06 +00:00
|
|
|
void collectTypeReferences();
|
2013-09-12 08:53:20 +00:00
|
|
|
|
2014-03-18 17:21:18 +00:00
|
|
|
int registerString(const QString &str) { return jsGenerator.registerString(str); }
|
2014-03-27 16:07:06 +00:00
|
|
|
QString stringAt(int index) const { return jsGenerator.stringForIndex(index); }
|
2014-03-18 17:21:18 +00:00
|
|
|
|
2014-03-18 22:39:02 +00:00
|
|
|
static void removeScriptPragmas(QString &script);
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
2014-12-05 15:32:56 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT ScriptDirectivesCollector : public QQmlJS::Directives
|
|
|
|
{
|
|
|
|
ScriptDirectivesCollector(QQmlJS::Engine *engine, QV4::Compiler::JSUnitGenerator *unitGenerator);
|
|
|
|
|
|
|
|
QQmlJS::Engine *engine;
|
|
|
|
QV4::Compiler::JSUnitGenerator *jsGenerator;
|
|
|
|
QList<const QV4::CompiledData::Import *> imports;
|
|
|
|
bool hasPragmaLibrary;
|
|
|
|
|
|
|
|
virtual void pragmaLibrary();
|
|
|
|
virtual void importFile(const QString &jsfile, const QString &module, int lineNumber, int column);
|
|
|
|
virtual void importModule(const QString &uri, const QString &version, const QString &module, int lineNumber, int column);
|
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT IRBuilder : public QQmlJS::AST::Visitor
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2013-09-11 17:28:13 +00:00
|
|
|
Q_DECLARE_TR_FUNCTIONS(QQmlCodeGenerator)
|
|
|
|
public:
|
2014-03-17 20:26:04 +00:00
|
|
|
IRBuilder(const QSet<QString> &illegalNames);
|
2014-06-04 15:32:31 +00:00
|
|
|
bool generateFromQml(const QString &code, const QString &url, Document *output);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2013-09-13 13:03:51 +00:00
|
|
|
static bool isSignalPropertyName(const QString &name);
|
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
using QQmlJS::AST::Visitor::visit;
|
|
|
|
using QQmlJS::AST::Visitor::endVisit;
|
|
|
|
|
|
|
|
virtual bool visit(QQmlJS::AST::UiArrayMemberList *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiImport *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiPragma *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiHeaderItemList *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiObjectInitializer *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiObjectMemberList *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiParameterList *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiProgram *);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiQualifiedId *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiArrayBinding *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiObjectBinding *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiObjectDefinition *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiPublicMember *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiScriptBinding *ast);
|
|
|
|
virtual bool visit(QQmlJS::AST::UiSourceElement *ast);
|
|
|
|
|
|
|
|
void accept(QQmlJS::AST::Node *node);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
|
|
|
// returns index in _objects
|
2014-03-17 16:11:20 +00:00
|
|
|
bool defineQMLObject(int *objectIndex, QQmlJS::AST::UiQualifiedId *qualifiedTypeNameId, const QQmlJS::AST::SourceLocation &location, QQmlJS::AST::UiObjectInitializer *initializer, Object *declarationsOverride = 0);
|
|
|
|
bool defineQMLObject(int *objectIndex, QQmlJS::AST::UiObjectDefinition *node, Object *declarationsOverride = 0)
|
2014-02-19 14:55:11 +00:00
|
|
|
{ return defineQMLObject(objectIndex, node->qualifiedTypeNameId, node->qualifiedTypeNameId->firstSourceLocation(), node->initializer, declarationsOverride); }
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
static QString asString(QQmlJS::AST::UiQualifiedId *node);
|
|
|
|
QStringRef asStringRef(QQmlJS::AST::Node *node);
|
2013-08-06 14:41:28 +00:00
|
|
|
static void extractVersion(QStringRef string, int *maj, int *min);
|
2014-02-14 12:58:40 +00:00
|
|
|
QStringRef textRefAt(const QQmlJS::AST::SourceLocation &loc) const
|
2013-08-06 14:41:28 +00:00
|
|
|
{ return QStringRef(&sourceCode, loc.offset, loc.length); }
|
2014-02-14 12:58:40 +00:00
|
|
|
QStringRef textRefAt(const QQmlJS::AST::SourceLocation &first,
|
|
|
|
const QQmlJS::AST::SourceLocation &last) const;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
void setBindingValue(QV4::CompiledData::Binding *binding, QQmlJS::AST::Statement *statement);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
void appendBinding(QQmlJS::AST::UiQualifiedId *name, QQmlJS::AST::Statement *value);
|
|
|
|
void appendBinding(QQmlJS::AST::UiQualifiedId *name, int objectIndex, bool isOnAssignment = false);
|
2014-02-20 12:48:24 +00:00
|
|
|
void appendBinding(const QQmlJS::AST::SourceLocation &qualifiedNameLocation, const QQmlJS::AST::SourceLocation &nameLocation, quint32 propertyNameIndex, QQmlJS::AST::Statement *value);
|
|
|
|
void appendBinding(const QQmlJS::AST::SourceLocation &qualifiedNameLocation, const QQmlJS::AST::SourceLocation &nameLocation, quint32 propertyNameIndex, int objectIndex, bool isListItem = false, bool isOnAssignment = false);
|
2013-09-11 17:28:13 +00:00
|
|
|
|
2016-05-19 14:14:22 +00:00
|
|
|
bool appendAlias(QQmlJS::AST::UiPublicMember *node);
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
Object *bindingsTarget() const;
|
2014-01-28 09:41:58 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
bool setId(const QQmlJS::AST::SourceLocation &idLocation, QQmlJS::AST::Statement *value);
|
2013-09-12 14:53:32 +00:00
|
|
|
|
2013-09-12 12:43:56 +00:00
|
|
|
// resolves qualified name (font.pixelSize for example) and returns the last name along
|
|
|
|
// with the object any right-hand-side of a binding should apply to.
|
2014-03-17 16:11:20 +00:00
|
|
|
bool resolveQualifiedId(QQmlJS::AST::UiQualifiedId **nameToResolve, Object **object, bool onAssignment = false);
|
2013-09-12 12:43:56 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
void recordError(const QQmlJS::AST::SourceLocation &location, const QString &description);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-02-03 12:30:06 +00:00
|
|
|
quint32 registerString(const QString &str) const { return jsGenerator->registerString(str); }
|
2014-01-07 14:35:20 +00:00
|
|
|
template <typename _Tp> _Tp *New() { return pool->New<_Tp>(); }
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2014-03-27 16:07:06 +00:00
|
|
|
QString stringAt(int index) const { return jsGenerator->stringForIndex(index); }
|
2013-09-12 12:43:56 +00:00
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
static bool isStatementNodeScript(QQmlJS::AST::Statement *statement);
|
2013-09-30 07:41:35 +00:00
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
QList<QQmlJS::DiagnosticMessage> errors;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2013-12-06 10:29:43 +00:00
|
|
|
QSet<QString> illegalNames;
|
|
|
|
|
2014-03-27 16:07:06 +00:00
|
|
|
QList<const QV4::CompiledData::Import *> _imports;
|
2013-09-24 19:49:10 +00:00
|
|
|
QList<Pragma*> _pragmas;
|
2014-03-17 16:11:20 +00:00
|
|
|
QList<Object*> _objects;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2013-09-12 08:53:20 +00:00
|
|
|
QV4::CompiledData::TypeReferenceMap _typeReferences;
|
|
|
|
|
2014-03-17 16:11:20 +00:00
|
|
|
Object *_object;
|
|
|
|
Property *_propertyDeclaration;
|
2013-08-06 14:41:28 +00:00
|
|
|
|
|
|
|
QQmlJS::MemoryPool *pool;
|
|
|
|
QString sourceCode;
|
|
|
|
QV4::Compiler::JSUnitGenerator *jsGenerator;
|
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT QmlUnitGenerator
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2014-08-06 12:59:34 +00:00
|
|
|
QV4::CompiledData::Unit *generate(Document &output);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
|
|
|
private:
|
2014-02-03 09:29:04 +00:00
|
|
|
typedef bool (Binding::*BindingFilter)() const;
|
2014-03-17 16:11:20 +00:00
|
|
|
char *writeBindings(char *bindingPtr, Object *o, BindingFilter filter) const;
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
#ifndef V4_BOOTSTRAP
|
2014-03-17 20:26:04 +00:00
|
|
|
struct Q_QML_EXPORT PropertyResolver
|
2013-09-13 13:03:51 +00:00
|
|
|
{
|
|
|
|
PropertyResolver(QQmlPropertyCache *cache)
|
|
|
|
: cache(cache)
|
|
|
|
{}
|
|
|
|
|
|
|
|
QQmlPropertyData *property(int index)
|
|
|
|
{
|
|
|
|
return cache->property(index);
|
|
|
|
}
|
|
|
|
|
2016-01-19 14:37:26 +00:00
|
|
|
enum RevisionCheck {
|
|
|
|
CheckRevision,
|
|
|
|
IgnoreRevision
|
|
|
|
};
|
|
|
|
|
|
|
|
QQmlPropertyData *property(const QString &name, bool *notInRevision = 0, RevisionCheck check = CheckRevision);
|
2013-09-13 13:03:51 +00:00
|
|
|
|
|
|
|
// This code must match the semantics of QQmlPropertyPrivate::findSignalByName
|
2016-01-19 14:37:26 +00:00
|
|
|
QQmlPropertyData *signal(const QString &name, bool *notInRevision);
|
2013-09-13 13:03:51 +00:00
|
|
|
|
|
|
|
QQmlPropertyCache *cache;
|
|
|
|
};
|
2014-03-12 15:55:06 +00:00
|
|
|
#endif
|
2013-09-13 13:03:51 +00:00
|
|
|
|
2014-03-12 15:55:06 +00:00
|
|
|
struct Q_QML_PRIVATE_EXPORT JSCodeGen : public QQmlJS::Codegen
|
2013-08-06 14:41:28 +00:00
|
|
|
{
|
2014-03-17 16:11:20 +00:00
|
|
|
JSCodeGen(const QString &fileName, const QString &sourceCode, QV4::IR::Module *jsModule,
|
2014-02-25 15:36:41 +00:00
|
|
|
QQmlJS::Engine *jsEngine, QQmlJS::AST::UiProgram *qmlRoot, QQmlTypeNameCache *imports,
|
2014-03-27 16:07:06 +00:00
|
|
|
const QV4::Compiler::StringTableGenerator *stringPool);
|
2013-08-06 14:41:28 +00:00
|
|
|
|
2013-10-23 14:24:58 +00:00
|
|
|
struct IdMapping
|
|
|
|
{
|
|
|
|
QString name;
|
|
|
|
int idIndex;
|
2013-10-25 12:23:39 +00:00
|
|
|
QQmlPropertyCache *type;
|
2013-10-23 14:24:58 +00:00
|
|
|
};
|
|
|
|
typedef QVector<IdMapping> ObjectIdMapping;
|
|
|
|
|
2013-10-24 12:51:02 +00:00
|
|
|
void beginContextScope(const ObjectIdMapping &objectIds, QQmlPropertyCache *contextObject);
|
|
|
|
void beginObjectScope(QQmlPropertyCache *scopeObject);
|
|
|
|
|
2014-02-14 12:58:40 +00:00
|
|
|
// Returns mapping from input functions to index in IR::Module::functions / compiledData->runtimeFunctions
|
2013-12-10 14:25:22 +00:00
|
|
|
QVector<int> generateJSCodeForFunctionsAndBindings(const QList<CompiledFunctionOrExpression> &functions);
|
2013-09-13 11:43:15 +00:00
|
|
|
|
2013-10-23 14:24:58 +00:00
|
|
|
protected:
|
2013-10-29 12:02:48 +00:00
|
|
|
virtual void beginFunctionBodyHook();
|
2014-03-17 16:11:20 +00:00
|
|
|
virtual QV4::IR::Expr *fallbackNameLookup(const QString &name, int line, int col);
|
2013-09-13 11:43:15 +00:00
|
|
|
|
2013-10-23 14:24:58 +00:00
|
|
|
private:
|
2013-11-25 14:58:36 +00:00
|
|
|
QQmlPropertyData *lookupQmlCompliantProperty(QQmlPropertyCache *cache, const QString &name, bool *propertyExistsButForceNameLookup = 0);
|
|
|
|
|
2013-10-24 08:38:29 +00:00
|
|
|
QString sourceCode;
|
|
|
|
QQmlJS::Engine *jsEngine; // needed for memory pool
|
2014-02-14 12:58:40 +00:00
|
|
|
QQmlJS::AST::UiProgram *qmlRoot;
|
2013-10-24 12:51:02 +00:00
|
|
|
QQmlTypeNameCache *imports;
|
2014-03-27 16:07:06 +00:00
|
|
|
const QV4::Compiler::StringTableGenerator *stringPool;
|
2013-10-24 08:38:29 +00:00
|
|
|
|
2013-12-10 14:25:22 +00:00
|
|
|
bool _disableAcceleratedLookups;
|
2013-10-24 12:51:02 +00:00
|
|
|
ObjectIdMapping _idObjects;
|
|
|
|
QQmlPropertyCache *_contextObject;
|
|
|
|
QQmlPropertyCache *_scopeObject;
|
2015-06-18 11:12:31 +00:00
|
|
|
int _qmlContextTemp;
|
2013-10-29 12:02:48 +00:00
|
|
|
int _importedScriptsTemp;
|
2013-08-06 14:41:28 +00:00
|
|
|
};
|
|
|
|
|
2014-03-17 20:26:04 +00:00
|
|
|
} // namespace QmlIR
|
2013-08-06 14:41:28 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2014-03-17 20:26:04 +00:00
|
|
|
#endif // QQMLIRBUILDER_P_H
|