From 5f3e8f33083be7bd7b858c8880f52a99952e0b75 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:36:06 +1000 Subject: doc --- doc/src/declarative/examples.qdoc | 6 + doc/src/examples/qml-folderlistmodel.qdoc | 142 +++++++++++++++++++++ doc/src/images/declarative-folderlistmodel.png | Bin 0 -> 17764 bytes doc/src/snippets/declarative/folderlistmodel.qml | 17 +++ src/imports/folderlistmodel/plugin.cpp | 4 + .../qdeclarativefolderlistmodel.cpp | 9 ++ .../folderlistmodel/qdeclarativefolderlistmodel.h | 31 ++++- 7 files changed, 204 insertions(+), 5 deletions(-) create mode 100644 doc/src/examples/qml-folderlistmodel.qdoc create mode 100644 doc/src/images/declarative-folderlistmodel.png create mode 100644 doc/src/snippets/declarative/folderlistmodel.qml diff --git a/doc/src/declarative/examples.qdoc b/doc/src/declarative/examples.qdoc index cdc308a..94f27e9 100644 --- a/doc/src/declarative/examples.qdoc +++ b/doc/src/declarative/examples.qdoc @@ -168,5 +168,11 @@ For example, from your build directory, run: \o \l{demos/declarative/snake}{Snake} \endlist +\section1 Labs + +\list +\o \l{src/imports/folderlistmodel}{Folder List Model} - a C++ model plugin +\endlist + */ diff --git a/doc/src/examples/qml-folderlistmodel.qdoc b/doc/src/examples/qml-folderlistmodel.qdoc new file mode 100644 index 0000000..6e5f493 --- /dev/null +++ b/doc/src/examples/qml-folderlistmodel.qdoc @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + +\title FolderListModel - a C++ model plugin +\example src/imports/folderlistmodel + +This plugin shows how to make a C++ model available to QML. It presents +a simple file list for a single folder (directory) and allows the presented +folder to be changed. + +\image declarative-folderlistmodel.png The FolderListModel used to choose a QML file + +We do not explain the model implementation in detail, but rather focus on the mechanics of +making the model available to QML. + +\section1 Usage from QML + +The type we are creating can be used from QML like this: + +\snippet doc/src/snippets/declarative/folderlistmodel.qml 0 + +\section1 Defining the Model + +We are subclassing QAbstractListModel which will allow us to give data to QML and +send notifications when the data changes: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class begin + +As you see, we also inherit the QDeclarativeParserStatus interface, so that we +can delay initial processing until we have all properties set (via componentComplete() below). + +The first thing to do when devising a new type for QML is to define the properties +you want the type to have: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class props + +The purposes of each of these should be pretty obvious - in QML we will set the folder +to display (a file: URL), and the kinds of files we want to show in the view of the model. + +Next are the constructor, destructor, and standard QAbstractListModel subclassing requirements: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h abslistmodel + +The data() function is where we provide model values. The rowCount() function +is also a standard part of the QAbstractListModel interface, but we also want to provide +a simpler count property: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h count + +Then we have the functions for the remaining properties which we defined above: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h prop funcs + +Imperative actions upon the model are made available to QML via a Q_INVOKABLE tag on +a normal member function. The isFolder(index) function says whether the value at \e index +is a folder: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h isfolder + +Then we have the QDeclarativeParserStatus interface: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h parserstatus + +Then the NOTIFY function for the folders property. The implementation will emit this +when the folder property is changed. + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h notifier + +The class ends with some implementation details: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h class end + +Lastly, the boilerplare to declare the type for QML use: + +\snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h qml decl + +To make this class available to QML, we only need to make a simple subclass of QDeclarativeExtensionPlugin: + +\snippet src/imports/folderlistmodel/plugin.cpp class decl + +and then use the standard Qt plugin export macro: + +\snippet src/imports/folderlistmodel/plugin.cpp plugin export decl + +Finally, in order for QML to connect the "import" statement to our plugin, we list it in the qmldir file: + +\l{src/imports/folderlistmodel/qmldir} + +This qmldir file and the compiled plugin will be installed in \c $QTDIR/imports/Qt/labs/folderlistmodel/ where +the QML engine will find it (since \c $QTDIR/imports is the value of QLibraryInf::libraryPath()). + +\section1 Implementing the Model + +We'll not discuss the model implementation in detail, as it is not specific to QML - any Qt C++ model +can be interfaced to QML. +This implementation is basically just takes the krufty old QDirModel, +which is a tree with lots of detailed roles and re-presents it as a simpler list model where +each item is just a fileName and a filePath (as a file: URL rather than a plain file, since QML +works with URLs for all content). + +\l{src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp} +*/ diff --git a/doc/src/images/declarative-folderlistmodel.png b/doc/src/images/declarative-folderlistmodel.png new file mode 100644 index 0000000..a469f96 Binary files /dev/null and b/doc/src/images/declarative-folderlistmodel.png differ diff --git a/doc/src/snippets/declarative/folderlistmodel.qml b/doc/src/snippets/declarative/folderlistmodel.qml new file mode 100644 index 0000000..e90f9fd --- /dev/null +++ b/doc/src/snippets/declarative/folderlistmodel.qml @@ -0,0 +1,17 @@ +//![0] +import Qt 4.7 +import Qt.labs.folderlistmodel 1.0 + +ListView { + FolderListModel { + id: foldermodel + nameFilters: ["*.qml"] + } + Component { + id: filedelegate + Text { text: fileName } + } + model: foldermodel + delegate: filedelegate +} +//![0] diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index b94efb0..d4569f7 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -46,6 +46,7 @@ QT_BEGIN_NAMESPACE +//![class decl] class QmlFolderListModelPlugin : public QDeclarativeExtensionPlugin { Q_OBJECT @@ -56,10 +57,13 @@ public: qmlRegisterType(uri,1,0,"FolderListModel"); } }; +//![class decl] QT_END_NAMESPACE #include "plugin.moc" +//![plugin export decl] Q_EXPORT_PLUGIN2(qmlfolderlistmodelplugin, QT_PREPEND_NAMESPACE(QmlFolderListModelPlugin)); +//![plugin export decl] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index a16f0c6..0a75edf 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -39,6 +39,7 @@ ** ****************************************************************************/ +//![code] #include "qdeclarativefolderlistmodel.h" #include #include @@ -99,6 +100,12 @@ public: separator, Qt will translate your paths to conform to the underlying operating system. + This type is made available by importing the \c Qt.labs.folderlistmodel module. + \e {Elements in the Qt.labs module are not guaranteed to remain compatible + in future versions.} + + \bold{import Qt.labs.folderlistmodel 1.0} + The roles available are: \list \o fileName @@ -387,3 +394,5 @@ void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) else d->model.setFilter(d->model.filter() & ~QDir::Readable); } + +//![code] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h index e610a14..87141c5 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -51,11 +51,15 @@ class QDeclarativeContext; class QModelIndex; class QDeclarativeFolderListModelPrivate; + +//![class begin] class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarativeParserStatus { Q_OBJECT Q_INTERFACES(QDeclarativeParserStatus) +//![class begin] +//![class props] Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged) Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged) Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters) @@ -65,7 +69,9 @@ class QDeclarativeFolderListModel : public QAbstractListModel, public QDeclarati Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot) Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable) Q_PROPERTY(int count READ count) +//![class props] +//![abslistmodel] public: QDeclarativeFolderListModel(QObject *parent = 0); ~QDeclarativeFolderListModel(); @@ -74,9 +80,13 @@ public: int rowCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role) const; +//![abslistmodel] +//![count] int count() const { return rowCount(QModelIndex()); } +//![count] +//![prop funcs] QUrl folder() const; void setFolder(const QUrl &folder); @@ -85,11 +95,6 @@ public: QStringList nameFilters() const; void setNameFilters(const QStringList &filters); - virtual void classBegin(); - virtual void componentComplete(); - - Q_INVOKABLE bool isFolder(int index) const; - enum SortField { Unsorted, Name, Time, Size, Type }; SortField sortField() const; void setSortField(SortField field); @@ -104,10 +109,23 @@ public: void setShowDotAndDotDot(bool); bool showOnlyReadable() const; void setShowOnlyReadable(bool); +//![prop funcs] + +//![isfolder] + Q_INVOKABLE bool isFolder(int index) const; +//![isfolder] + +//![parserstatus] + virtual void classBegin(); + virtual void componentComplete(); +//![parserstatus] +//![notifier] Q_SIGNALS: void folderChanged(); +//![notifier] +//![class end] private Q_SLOTS: void refresh(); void inserted(const QModelIndex &index, int start, int end); @@ -118,7 +136,10 @@ private: Q_DISABLE_COPY(QDeclarativeFolderListModel) QDeclarativeFolderListModelPrivate *d; }; +//![class end] +//![qml decl] QML_DECLARE_TYPE(QDeclarativeFolderListModel) +//![qml decl] #endif // QDECLARATIVEFOLDERLISTMODEL_H -- cgit v0.12 From cd707a865625c7ee0ec836d2a1bdcda847ab0517 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:41:50 +1000 Subject: doc --- doc/src/examples/qml-folderlistmodel.qdoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/src/examples/qml-folderlistmodel.qdoc b/doc/src/examples/qml-folderlistmodel.qdoc index 6e5f493..b820528 100644 --- a/doc/src/examples/qml-folderlistmodel.qdoc +++ b/doc/src/examples/qml-folderlistmodel.qdoc @@ -114,6 +114,8 @@ Lastly, the boilerplare to declare the type for QML use: \snippet src/imports/folderlistmodel/qdeclarativefolderlistmodel.h qml decl +\section1 Connecting the Model to QML + To make this class available to QML, we only need to make a simple subclass of QDeclarativeExtensionPlugin: \snippet src/imports/folderlistmodel/plugin.cpp class decl -- cgit v0.12 From 36c51fe5229580ddaef7b7feb23822ecb775bffc Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Wed, 19 May 2010 12:54:59 +1000 Subject: Bug moved. --- .../qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp index 831e318..4173a44 100644 --- a/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp +++ b/tests/auto/declarative/qdeclarativexmllistmodel/tst_qdeclarativexmllistmodel.cpp @@ -238,7 +238,7 @@ void tst_qdeclarativexmllistmodel::roleErrors() QCOMPARE(data.value(Qt::UserRole+1), QVariant()); QCOMPARE(data.value(Qt::UserRole+2), QVariant()); - QEXPECT_FAIL("", "QT-2456", Continue); + QEXPECT_FAIL("", "QTBUG-10797", Continue); QCOMPARE(data.value(Qt::UserRole+3), QVariant()); delete model; -- cgit v0.12 From 90faa4aafc32adcf8fc3415fa0aa36d765b51087 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Wed, 19 May 2010 13:17:00 +1000 Subject: Introduce a threaded interpreter for QML binding bytecode Reviewed-by: Roberto Raggi --- .../qml/qdeclarativecompiledbindings.cpp | 389 ++++++++++++--------- 1 file changed, 233 insertions(+), 156 deletions(-) diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp index 7ddc735..ad05e80 100644 --- a/src/declarative/qml/qdeclarativecompiledbindings.cpp +++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp @@ -64,6 +64,73 @@ DEFINE_BOOL_CONFIG_OPTION(bindingsDump, QML_BINDINGS_DUMP); Q_GLOBAL_STATIC(QDeclarativeFastProperties, fastProperties); +#ifdef __GNUC__ +# define QML_THREADED_INTERPRETER +#endif + +#define FOR_EACH_QML_INSTR(F) \ + F(Noop) /* Nop */ \ + F(BindingId) /* id */ \ + F(Subscribe) /* subscribe */ \ + F(SubscribeId) /* subscribe */ \ + F(FetchAndSubscribe) /* fetchAndSubscribe */ \ + F(LoadId) /* load */ \ + F(LoadScope) /* load */ \ + F(LoadRoot) /* load */ \ + F(LoadAttached) /* attached */ \ + F(ConvertIntToReal) /* unaryop */ \ + F(ConvertRealToInt) /* unaryop */ \ + F(Real) /* real_value */ \ + F(Int) /* int_value */ \ + F(Bool) /* bool_value */ \ + F(String) /* string_value */ \ + F(AddReal) /* binaryop */ \ + F(AddInt) /* binaryop */ \ + F(AddString) /* binaryop */ \ + F(MinusReal) /* binaryop */ \ + F(MinusInt) /* binaryop */ \ + F(CompareReal) /* binaryop */ \ + F(CompareString) /* binaryop */ \ + F(NotCompareReal) /* binaryop */ \ + F(NotCompareString) /* binaryop */ \ + F(GreaterThanReal) /* binaryop */ \ + F(MaxReal) /* binaryop */ \ + F(MinReal) /* binaryop */ \ + F(NewString) /* construct */ \ + F(NewUrl) /* construct */ \ + F(CleanupUrl) /* cleanup */ \ + F(CleanupString) /* cleanup */ \ + F(Copy) /* copy */ \ + F(Fetch) /* fetch */ \ + F(Store) /* store */ \ + F(Skip) /* skip */ \ + F(Done) /* done */ \ + /* Speculative property resolution */ \ + F(InitString) /* initstring */ \ + F(FindGeneric) /* find */ \ + F(FindGenericTerminal) /* find */ \ + F(FindProperty) /* find */ \ + F(FindPropertyTerminal) /* find */ \ + F(CleanupGeneric) /* cleanup */ \ + F(ConvertGenericToReal) /* unaryop */ \ + F(ConvertGenericToBool) /* unaryop */ \ + F(ConvertGenericToString) /* unaryop */ \ + F(ConvertGenericToUrl) /* unaryop */ + +#define QML_INSTR_ENUM(I) I, +#define QML_INSTR_ADDR(I) &&op_##I, + +#ifdef QML_THREADED_INTERPRETER +# define QML_BEGIN_INSTR(I) op_##I: +# define QML_END_INSTR(I) ++instr; goto *instr->common.code; +# define QML_INSTR_HEADER void *code; +#else +# define QML_BEGIN_INSTR(I) case Instr::I: +# define QML_END_INSTR(I) break; +# define QML_INSTR_HEADER +#endif + + using namespace QDeclarativeJS; namespace { @@ -328,101 +395,45 @@ namespace { // This structure is exactly 8-bytes in size struct Instr { enum { - Noop, - BindingId, // id - - Subscribe, // subscribe - SubscribeId, // subscribe - - FetchAndSubscribe, // fetchAndSubscribe - - LoadId, // load - LoadScope, // load - LoadRoot, // load - LoadAttached, // attached - - ConvertIntToReal, // unaryop - ConvertRealToInt, // unaryop - - Real, // real_value - Int, // int_value - Bool, // bool_value - String, // string_value - - AddReal, // binaryop - AddInt, // binaryop - AddString, // binaryop - - MinusReal, // binaryop - MinusInt, // binaryop - - CompareReal, // binaryop - CompareString, // binaryop - - NotCompareReal, // binaryop - NotCompareString, // binaryop - - GreaterThanReal, // binaryop - MaxReal, // binaryop - MinReal, // binaryop - - NewString, // construct - NewUrl, // construct - - CleanupUrl, // cleanup - CleanupString, // cleanup - - Copy, // copy - Fetch, // fetch - Store, // store - - Skip, // skip - - Done, - - // Speculative property resolution - InitString, // initstring - FindGeneric, // find - FindGenericTerminal, // find - FindProperty, // find - FindPropertyTerminal, // find - CleanupGeneric, // cleanup - ConvertGenericToReal, // unaryop - ConvertGenericToBool, // unaryop - ConvertGenericToString, // unaryop - ConvertGenericToUrl, // unaryop + FOR_EACH_QML_INSTR(QML_INSTR_ENUM) }; union { struct { + QML_INSTR_HEADER quint8 type; quint8 packing[7]; } common; struct { + QML_INSTR_HEADER quint8 type; quint8 packing; quint16 column; quint32 line; } id; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[3]; quint16 subscriptions; quint16 identifiers; } init; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 offset; quint32 index; } subscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 index; } load; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -430,6 +441,7 @@ struct Instr { quint32 index; } attached; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 reg; @@ -437,6 +449,7 @@ struct Instr { quint32 index; } store; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -445,6 +458,7 @@ struct Instr { quint16 function; } fetchAndSubscribe; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 objectReg; @@ -452,41 +466,48 @@ struct Instr { quint32 index; } fetch; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; quint8 packing[5]; } copy; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } construct; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; float value; } real_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; int value; } int_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; bool value; quint8 packing[5]; } bool_value; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint16 length; quint32 offset; } string_value; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src1; @@ -494,18 +515,21 @@ struct Instr { quint8 packing[4]; } binaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 output; qint8 src; quint8 packing[5]; } unaryop; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[2]; quint32 count; } skip; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; qint8 src; @@ -514,11 +538,13 @@ struct Instr { quint16 subscribeIndex; } find; struct { + QML_INSTR_HEADER quint8 type; qint8 reg; quint8 packing[6]; } cleanup; struct { + QML_INSTR_HEADER quint8 type; quint8 packing[1]; quint16 offset; @@ -535,7 +561,7 @@ struct Program { quint16 subscriptions; quint16 identifiers; quint16 instructionCount; - quint16 dummy; + quint16 compiled; const char *data() const { return ((const char *)this) + sizeof(Program); } const Instr *instructions() const { return (const Instr *)(data() + dataLength); } @@ -1097,35 +1123,57 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr += instrIndex; const char *data = program->data(); +#ifdef QML_THREADED_INTERPRETER + static void *decode_instr[] = { + FOR_EACH_QML_INSTR(QML_INSTR_ADDR) + }; + + if (!program->compiled) { + program->compiled = true; + const Instr *inop = program->instructions(); + for (int i = 0; i < program->instructionCount; ++i) { + Instr *op = (Instr *) inop++; + op->common.code = decode_instr[op->common.type]; + } + } + + goto *instr->common.code; +#else // return; + #ifdef COMPILEDBINDINGS_DEBUG qWarning().nospace() << "Begin binding run"; #endif while (instr) { + switch (instr->common.type) { + #ifdef COMPILEDBINDINGS_DEBUG dumpInstruction(instr); #endif - switch (instr->common.type) { - case Instr::Noop: - case Instr::BindingId: - break; +#endif - case Instr::SubscribeId: + QML_BEGIN_INSTR(Noop) + QML_END_INSTR(Noop) + + QML_BEGIN_INSTR(BindingId) + QML_END_INSTR(BindingId) + + QML_BEGIN_INSTR(SubscribeId) subscribeId(context, instr->subscribe.index, instr->subscribe.offset); - break; + QML_END_INSTR(SubscribeId) - case Instr::Subscribe: + QML_BEGIN_INSTR(Subscribe) { QObject *o = 0; const Register &object = registers[instr->subscribe.reg]; if (!object.isUndefined()) o = object.getQObject(); subscribe(o, instr->subscribe.index, instr->subscribe.offset); } - break; + QML_END_INSTR(Subscribe) - case Instr::FetchAndSubscribe: + QML_BEGIN_INSTR(FetchAndSubscribe) { const Register &input = registers[instr->fetchAndSubscribe.objectReg]; Register &output = registers[instr->fetchAndSubscribe.output]; @@ -1149,21 +1197,21 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, fastProperties()->accessor(instr->fetchAndSubscribe.function)(object, output.typeDataPtr(), sub); } } - break; + QML_END_INSTR(FetchAndSubscribe) - case Instr::LoadId: + QML_BEGIN_INSTR(LoadId) registers[instr->load.reg].setQObject(context->idValues[instr->load.index].data()); - break; + QML_END_INSTR(LoadId) - case Instr::LoadScope: + QML_BEGIN_INSTR(LoadScope) registers[instr->load.reg].setQObject(scope); - break; + QML_END_INSTR(LoadScope) - case Instr::LoadRoot: + QML_BEGIN_INSTR(LoadRoot) registers[instr->load.reg].setQObject(context->contextObject); - break; + QML_END_INSTR(LoadRoot) - case Instr::LoadAttached: + QML_BEGIN_INSTR(LoadAttached) { const Register &input = registers[instr->attached.reg]; Register &output = registers[instr->attached.output]; @@ -1184,48 +1232,48 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setQObject(attached); } } - break; + QML_END_INSTR(LoadAttached) - case Instr::ConvertIntToReal: + QML_BEGIN_INSTR(ConvertIntToReal) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); else output.setqreal(qreal(input.getint())); } - break; + QML_END_INSTR(ConvertIntToReal) - case Instr::ConvertRealToInt: + QML_BEGIN_INSTR(ConvertRealToInt) { const Register &input = registers[instr->unaryop.src]; Register &output = registers[instr->unaryop.output]; if (input.isUndefined()) output.setUndefined(); else output.setint(qRound(input.getqreal())); } - break; + QML_END_INSTR(ConvertRealToInt) - case Instr::Real: + QML_BEGIN_INSTR(Real) registers[instr->real_value.reg].setqreal(instr->real_value.value); - break; + QML_END_INSTR(Real) - case Instr::Int: + QML_BEGIN_INSTR(Int) registers[instr->int_value.reg].setint(instr->int_value.value); - break; + QML_END_INSTR(Int) - case Instr::Bool: + QML_BEGIN_INSTR(Bool) registers[instr->bool_value.reg].setbool(instr->bool_value.value); - break; + QML_END_INSTR(Bool) - case Instr::String: + QML_BEGIN_INSTR(String) { Register &output = registers[instr->string_value.reg]; new (output.getstringptr()) QString((QChar *)(data + instr->string_value.offset), instr->string_value.length); output.settype(QMetaType::QString); } - break; + QML_END_INSTR(String) - case Instr::AddReal: + QML_BEGIN_INSTR(AddReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1233,9 +1281,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() + rhs.getqreal()); } - break; + QML_END_INSTR(AddReal) - case Instr::AddInt: + QML_BEGIN_INSTR(AddInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1243,9 +1291,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() + rhs.getint()); } - break; + QML_END_INSTR(AddInt) - case Instr::AddString: + QML_BEGIN_INSTR(AddString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1265,9 +1313,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.settype(QMetaType::QString); } } - break; + QML_END_INSTR(AddString) - case Instr::MinusReal: + QML_BEGIN_INSTR(MinusReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1275,9 +1323,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(lhs.getqreal() - rhs.getqreal()); } - break; + QML_END_INSTR(MinusReal) - case Instr::MinusInt: + QML_BEGIN_INSTR(MinusInt) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1285,9 +1333,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setint(lhs.getint() - rhs.getint()); } - break; + QML_END_INSTR(MinusInt) - case Instr::CompareReal: + QML_BEGIN_INSTR(CompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1295,9 +1343,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(lhs.getqreal() == rhs.getqreal()); } - break; + QML_END_INSTR(CompareReal) - case Instr::CompareString: + QML_BEGIN_INSTR(CompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1305,9 +1353,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() == rhs.isUndefined()); else output.setbool(*lhs.getstringptr() == *rhs.getstringptr()); } - break; + QML_END_INSTR(CompareString) - case Instr::NotCompareReal: + QML_BEGIN_INSTR(NotCompareReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1315,9 +1363,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(lhs.getqreal() != rhs.getqreal()); } - break; + QML_END_INSTR(NotCompareReal) - case Instr::NotCompareString: + QML_BEGIN_INSTR(NotCompareString) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1325,9 +1373,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(lhs.isUndefined() != rhs.isUndefined()); else output.setbool(*lhs.getstringptr() != *rhs.getstringptr()); } - break; + QML_END_INSTR(NotCompareString) - case Instr::GreaterThanReal: + QML_BEGIN_INSTR(GreaterThanReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1335,9 +1383,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setbool(false); else output.setbool(lhs.getqreal() > rhs.getqreal()); } - break; + QML_END_INSTR(GreaterThanReal) - case Instr::MaxReal: + QML_BEGIN_INSTR(MaxReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1345,9 +1393,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMax(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MaxReal) - case Instr::MinReal: + QML_BEGIN_INSTR(MinReal) { const Register &lhs = registers[instr->binaryop.src1]; const Register &rhs = registers[instr->binaryop.src2]; @@ -1355,33 +1403,33 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (lhs.isUndefined() || rhs.isUndefined()) output.setNaN(); else output.setqreal(qMin(lhs.getqreal(), rhs.getqreal())); } - break; + QML_END_INSTR(MinReal) - case Instr::NewString: + QML_BEGIN_INSTR(NewString) { Register &output = registers[instr->construct.reg]; new (output.getstringptr()) QString; output.settype(QMetaType::QString); } - break; + QML_END_INSTR(NewString) - case Instr::NewUrl: + QML_BEGIN_INSTR(NewUrl) { Register &output = registers[instr->construct.reg]; new (output.geturlptr()) QUrl; output.settype(QMetaType::QUrl); } - break; + QML_END_INSTR(NewUrl) - case Instr::CleanupString: + QML_BEGIN_INSTR(CleanupString) registers[instr->cleanup.reg].getstringptr()->~QString(); - break; + QML_END_INSTR(CleanupString) - case Instr::CleanupUrl: + QML_BEGIN_INSTR(CleanupUrl) registers[instr->cleanup.reg].geturlptr()->~QUrl(); - break; + QML_END_INSTR(CleanupUrl) - case Instr::Fetch: + QML_BEGIN_INSTR(Fetch) { const Register &input = registers[instr->fetch.objectReg]; Register &output = registers[instr->fetch.output]; @@ -1399,9 +1447,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(object, QMetaObject::ReadProperty, instr->fetch.index, argv); } } - break; + QML_END_INSTR(Fetch) - case Instr::Store: + QML_BEGIN_INSTR(Store) { Register &data = registers[instr->store.reg]; if (data.isUndefined()) { @@ -1415,21 +1463,22 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, QMetaObject::metacall(output, QMetaObject::WriteProperty, instr->store.index, argv); } - break; + QML_END_INSTR(Store) - case Instr::Copy: + QML_BEGIN_INSTR(Copy) registers[instr->copy.reg] = registers[instr->copy.src]; - break; + QML_END_INSTR(Copy) - case Instr::Skip: + QML_BEGIN_INSTR(Skip) if (instr->skip.reg == -1 || !registers[instr->skip.reg].getbool()) instr += instr->skip.count; - break; + QML_END_INSTR(Skip) - case Instr::Done: + QML_BEGIN_INSTR(Done) return; + QML_END_INSTR(Done) - case Instr::InitString: + QML_BEGIN_INSTR(InitString) if (!identifiers[instr->initstring.offset].identifier) { quint32 len = *(quint32 *)(data + instr->initstring.dataIdx); QChar *strdata = (QChar *)(data + instr->initstring.dataIdx + sizeof(quint32)); @@ -1438,10 +1487,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, identifiers[instr->initstring.offset] = engine->objectClass->createPersistentIdentifier(str); } - break; + QML_END_INSTR(InitString) - case Instr::FindGenericTerminal: - case Instr::FindGeneric: + QML_BEGIN_INSTR(FindGenericTerminal) // We start the search in the parent context, as we know that the // name is not present in the current context or it would have been // found during the static compile @@ -1449,10 +1497,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, context->parent, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindGenericTerminal); - break; + QML_END_INSTR(FindGenericTerminal) - case Instr::FindPropertyTerminal: - case Instr::FindProperty: + QML_BEGIN_INSTR(FindGeneric) + // We start the search in the parent context, as we know that the + // name is not present in the current context or it would have been + // found during the static compile + findgeneric(registers + instr->find.reg, instr->find.subscribeIndex, + context->parent, + identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindGenericTerminal); + QML_END_INSTR(FindGeneric) + + QML_BEGIN_INSTR(FindPropertyTerminal) { const Register &object = registers[instr->find.src]; if (object.isUndefined()) { @@ -1465,9 +1522,24 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, instr->find.subscribeIndex, identifiers[instr->find.name].identifier, instr->common.type == Instr::FindPropertyTerminal); } - break; + QML_END_INSTR(FindPropertyTerminal) - case Instr::CleanupGeneric: + QML_BEGIN_INSTR(FindProperty) + { + const Register &object = registers[instr->find.src]; + if (object.isUndefined()) { + throwException(instr->find.exceptionId, error, program, context); + return; + } + + findproperty(object.getQObject(), registers + instr->find.reg, + QDeclarativeEnginePrivate::get(context->engine), + instr->find.subscribeIndex, identifiers[instr->find.name].identifier, + instr->common.type == Instr::FindPropertyTerminal); + } + QML_END_INSTR(FindProperty) + + QML_BEGIN_INSTR(CleanupGeneric) { int type = registers[instr->cleanup.reg].gettype(); if (type == qMetaTypeId()) { @@ -1478,9 +1550,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, registers[instr->cleanup.reg].geturlptr()->~QUrl(); } } - break; + QML_END_INSTR(CleanupGeneric) - case Instr::ConvertGenericToReal: + QML_BEGIN_INSTR(ConvertGenericToReal) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1488,9 +1560,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setqreal(toReal(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToReal) - case Instr::ConvertGenericToBool: + QML_BEGIN_INSTR(ConvertGenericToBool) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1498,9 +1570,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, output.setbool(toBool(&input, input.gettype(), &ok)); if (!ok) output.setUndefined(); } - break; + QML_END_INSTR(ConvertGenericToBool) - case Instr::ConvertGenericToString: + QML_BEGIN_INSTR(ConvertGenericToString) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1509,9 +1581,9 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.getstringptr()) QString(str); output.settype(QMetaType::QString); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToString) - case Instr::ConvertGenericToUrl: + QML_BEGIN_INSTR(ConvertGenericToUrl) { Register &output = registers[instr->unaryop.output]; Register &input = registers[instr->unaryop.src]; @@ -1520,15 +1592,19 @@ void QDeclarativeCompiledBindingsPrivate::run(int instrIndex, if (ok) { new (output.geturlptr()) QUrl(url); output.settype(QMetaType::QUrl); } else { output.setUndefined(); } } - break; + QML_END_INSTR(ConvertGenericToUrl) +#ifdef QML_THREADED_INTERPRETER + // nothing to do +#else default: qFatal("EEK"); break; - } + } // switch - instr++; - } + ++instr; + } // while +#endif } void QDeclarativeBindingCompiler::dump(const QByteArray &programData) @@ -2781,6 +2857,7 @@ QByteArray QDeclarativeBindingCompiler::program() const prog.subscriptions = d->committed.subscriptionIds.count(); prog.identifiers = d->committed.registeredStrings.count(); prog.instructionCount = bytecode.count(); + prog.compiled = false; int size = sizeof(Program) + bytecode.count() * sizeof(Instr); size += prog.dataLength; -- cgit v0.12