1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEVME_P_H
43 #define QDECLARATIVEVME_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include "qdeclarativeerror.h"
57 #include <private/qbitfield_p.h>
58 #include "qdeclarativeinstruction_p.h"
59 #include <private/qrecursionwatcher_p.h>
61 #include <QtCore/QStack>
62 #include <QtCore/QString>
63 #include <QtCore/qelapsedtimer.h>
64 #include <QtCore/qcoreapplication.h>
66 #include <private/qv8_p.h>
67 #include <private/qdeclarativeengine_p.h>
68 #include <private/qfinitestack_p.h>
70 #include <private/qdeclarativetrace_p.h>
76 class QDeclarativeScriptData;
77 class QDeclarativeCompiledData;
78 class QDeclarativeCompiledData;
79 class QDeclarativeContextData;
81 namespace QDeclarativeVMETypes {
85 List(int t) : type(t) {}
88 QDeclarativeListProperty<void> qListProperty;
91 Q_DECLARE_TYPEINFO(QDeclarativeVMETypes::List, Q_PRIMITIVE_TYPE | Q_MOVABLE_TYPE);
95 Q_DECLARE_TR_FUNCTIONS(QDeclarativeVME)
100 inline Interrupt(bool *runWhile);
101 inline Interrupt(int nsecs);
104 inline bool shouldInterrupt() const;
106 enum Mode { None, Time, Flag };
117 QDeclarativeVME() : data(0), componentAttached(0) {}
118 QDeclarativeVME(void *data) : data(data), componentAttached(0) {}
121 QDeclarativeComponentAttached *componentAttached;
122 QList<QDeclarativeEnginePrivate::FinalizeCallback> finalizeCallbacks;
124 void init(QDeclarativeContextData *, QDeclarativeCompiledData *, int start,
125 QDeclarativeContextData * = 0);
126 bool initDeferred(QObject *);
129 QObject *execute(QList<QDeclarativeError> *errors, const Interrupt & = Interrupt());
130 QDeclarativeContextData *complete(const Interrupt & = Interrupt());
133 friend class QDeclarativeVMEGuard;
135 QObject *run(QList<QDeclarativeError> *errors, const Interrupt &
136 #ifdef QML_THREADED_VME_INTERPRETER
137 , void ***storeJumpTable = 0
140 v8::Persistent<v8::Object> run(QDeclarativeContextData *, QDeclarativeScriptData *);
142 #ifdef QML_THREADED_VME_INTERPRETER
143 static void **instructionJumpTable();
144 friend class QDeclarativeCompiledData;
147 QDeclarativeEngine *engine;
148 QRecursionNode recursion;
150 #ifdef QML_ENABLE_TRACE
151 QDeclarativeCompiledData *rootComponent;
154 QFiniteStack<QObject *> objects;
155 QFiniteStack<QDeclarativeVMETypes::List> lists;
157 QFiniteStack<QDeclarativeAbstractBinding *> bindValues;
158 QFiniteStack<QDeclarativeParserStatus *> parserStatus;
159 #ifdef QML_ENABLE_TRACE
160 QFiniteStack<QDeclarativeData *> parserStatusData;
163 QDeclarativeGuardedContextData rootContext;
164 QDeclarativeGuardedContextData creationContext;
167 enum Flag { Deferred = 0x00000001 };
169 State() : flags(0), context(0), compiledData(0), instructionStream(0) {}
171 QDeclarativeContextData *context;
172 QDeclarativeCompiledData *compiledData;
173 const char *instructionStream;
174 QBitField bindingSkipList;
177 QStack<State> states;
179 static void blank(QFiniteStack<QDeclarativeParserStatus *> &);
180 static void blank(QFiniteStack<QDeclarativeAbstractBinding *> &);
183 // Used to check that a QDeclarativeVME that is interrupted mid-execution
184 // is still valid. Checks all the objects and contexts have not been
186 class QDeclarativeVMEGuard
189 QDeclarativeVMEGuard();
190 ~QDeclarativeVMEGuard();
192 void guard(QDeclarativeVME *);
199 QDeclarativeGuard<QObject> *m_objects;
201 QDeclarativeGuardedContextData *m_contexts;
204 QDeclarativeVME::Interrupt::Interrupt()
209 QDeclarativeVME::Interrupt::Interrupt(bool *runWhile)
210 : mode(Flag), runWhile(runWhile)
214 QDeclarativeVME::Interrupt::Interrupt(int nsecs)
215 : mode(Time), nsecs(nsecs)
219 void QDeclarativeVME::Interrupt::reset()
225 bool QDeclarativeVME::Interrupt::shouldInterrupt() const
229 } else if (mode == Time) {
230 return timer.nsecsElapsed() > nsecs;
231 } else if (mode == Flag) {
240 #endif // QDECLARATIVEVME_P_H