Evaluate all shared bindings together using a shared context
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativeinstruction_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEINSTRUCTION_P_H
43 #define QDECLARATIVEINSTRUCTION_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
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.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qglobal.h>
57
58 QT_BEGIN_NAMESPACE
59
60 #define FOR_EACH_QML_INSTR(F) \
61     F(Init, init) \
62     F(Done, common) \
63     F(CreateObject, create) \
64     F(CreateSimpleObject, createSimple) \
65     F(SetId, setId) \
66     F(SetDefault, common) \
67     F(CreateComponent, createComponent) \
68     F(StoreMetaObject, storeMeta) \
69     F(StoreVariant, storeString) \
70     F(StoreVariantInteger, storeInteger) \
71     F(StoreVariantDouble, storeDouble) \
72     F(StoreVariantBool, storeBool) \
73     F(StoreString, storeString) \
74     F(StoreByteArray, storeByteArray) \
75     F(StoreUrl, storeUrl) \
76     F(StoreFloat, storeFloat) \
77     F(StoreDouble, storeDouble) \
78     F(StoreBool, storeBool) \
79     F(StoreInteger, storeInteger) \
80     F(StoreColor, storeColor) \
81     F(StoreDate, storeDate) \
82     F(StoreTime, storeTime) \
83     F(StoreDateTime, storeDateTime) \
84     F(StorePoint, storePoint) \
85     F(StorePointF, storePointF) \
86     F(StoreSize, storeSize) \
87     F(StoreSizeF, storeSizeF) \
88     F(StoreRect, storeRect) \
89     F(StoreRectF, storeRectF) \
90     F(StoreVector3D, storeVector3D) \
91     F(StoreObject, storeObject) \
92     F(AssignCustomType, assignCustomType) \
93     F(AssignSignalObject, assignSignalObject) \
94     F(StoreSignal, storeSignal) \
95     F(StoreImportedScript, storeScript) \
96     F(StoreScriptString, storeScriptString) \
97     F(BeginObject, begin) \
98     F(InitV8Bindings, initV8Bindings) \
99     F(StoreBinding, assignBinding) \
100     F(StoreBindingOnAlias, assignBinding) \
101     F(StoreV4Binding, assignBinding) \
102     F(StoreV8Binding, assignBinding) \
103     F(StoreValueSource, assignValueSource) \
104     F(StoreValueInterceptor, assignValueInterceptor) \
105     F(StoreObjectQList, common) \
106     F(AssignObjectList, assignObjectList) \
107     F(StoreVariantObject, storeObject) \
108     F(StoreInterface, storeObject) \
109     F(FetchAttached, fetchAttached) \
110     F(FetchQList, fetchQmlList) \
111     F(FetchObject, fetch) \
112     F(PopQList, common) \
113     F(Defer, defer) \
114     F(PopFetchedObject, common) \
115     F(FetchValueType, fetchValue) \
116     F(PopValueType, fetchValue) 
117
118 #ifdef Q_ALIGNOF
119 #  define QML_INSTR_ALIGN_MASK (Q_ALIGNOF(QDeclarativeInstruction) - 1)
120 #else
121 #  define QML_INSTR_ALIGN_MASK (sizeof(void *) - 1)
122 #endif
123
124 #define QML_INSTR_HEADER quint8 instructionType;
125 #define QML_INSTR_ENUM(I, FMT)  I,
126 #define QML_INSTR_SIZE(I, FMT) ((sizeof(QDeclarativeInstruction::instr_##FMT) + QML_INSTR_ALIGN_MASK) & ~QML_INSTR_ALIGN_MASK)
127
128 class QDeclarativeCompiledData;
129 union QDeclarativeInstruction
130 {
131     enum Type { 
132         FOR_EACH_QML_INSTR(QML_INSTR_ENUM)
133     };
134
135     inline void setType(Type type) { common.instructionType = type; }
136     inline Type type() const { return (Type)common.instructionType; }
137
138     struct instr_common {
139         QML_INSTR_HEADER
140     };
141     struct instr_init {
142         QML_INSTR_HEADER
143         int bindingsSize;
144         int parserStatusSize;
145         int contextCache;
146         int compiledBinding;
147     };
148     struct instr_create {
149         QML_INSTR_HEADER
150         int type;
151         int data;
152         int bindingBits;
153         ushort column;
154         ushort line; 
155     };
156     struct instr_createSimple {
157         QML_INSTR_HEADER
158         void (*create)(void *);
159         int typeSize;
160         int type;
161         ushort column;
162         ushort line; 
163     };
164     struct instr_storeMeta {
165         QML_INSTR_HEADER
166         int data;
167         int aliasData;
168         int propertyCache;
169     };
170     struct instr_setId {
171         QML_INSTR_HEADER
172         int value;
173         int index;
174     };
175     struct instr_assignValueSource {
176         QML_INSTR_HEADER
177         int property;
178         int owner;
179         int castValue;
180     };
181     struct instr_assignValueInterceptor {
182         QML_INSTR_HEADER
183         int property;
184         int owner;
185         int castValue;
186     };
187     struct instr_initV8Bindings {
188         QML_INSTR_HEADER
189         int program;
190         int line;
191     };
192     struct instr_assignBinding {
193         QML_INSTR_HEADER
194         unsigned int property;
195         int value;
196         short context;
197         short owner;
198         ushort line;
199     };
200     struct instr_fetch {
201         QML_INSTR_HEADER
202         int property;
203         ushort line;
204     };
205     struct instr_fetchValue {
206         QML_INSTR_HEADER
207         int property;
208         int type;
209         quint32 bindingSkipList;
210     };
211     struct instr_fetchQmlList {
212         QML_INSTR_HEADER
213         int property;
214         int type;
215     };
216     struct instr_begin {
217         QML_INSTR_HEADER
218         int castValue;
219     }; 
220     struct instr_storeFloat {
221         QML_INSTR_HEADER
222         int propertyIndex;
223         float value;
224     };
225     struct instr_storeDouble {
226         QML_INSTR_HEADER
227         int propertyIndex;
228         double value;
229     };
230     struct instr_storeInteger {
231         QML_INSTR_HEADER
232         int propertyIndex;
233         int value;
234     };
235     struct instr_storeBool {
236         QML_INSTR_HEADER
237         int propertyIndex;
238         bool value;
239     };
240     struct instr_storeString {
241         QML_INSTR_HEADER
242         int propertyIndex;
243         int value;
244     };
245     struct instr_storeByteArray {
246         QML_INSTR_HEADER
247         int propertyIndex;
248         int value;
249     };
250     struct instr_storeScriptString {
251         QML_INSTR_HEADER
252         int propertyIndex;
253         int value;
254         int scope;
255         int bindingId;
256         ushort line;
257     }; 
258     struct instr_storeScript {
259         QML_INSTR_HEADER
260         int value;
261     };
262     struct instr_storeUrl {
263         QML_INSTR_HEADER
264         int propertyIndex;
265         int value;
266     };
267     struct instr_storeColor {
268         QML_INSTR_HEADER
269         int propertyIndex;
270         unsigned int value;
271     };
272     struct instr_storeDate {
273         QML_INSTR_HEADER
274         int propertyIndex;
275         int value;
276     };
277     struct instr_storeTime {
278         QML_INSTR_HEADER
279         int propertyIndex;
280         struct QTime {
281             int mds;
282 #if defined(Q_OS_WINCE)
283             int startTick;
284 #endif
285         } time;
286     };
287     struct instr_storeDateTime {
288         QML_INSTR_HEADER
289         int propertyIndex;
290         int date;
291         instr_storeTime::QTime time;
292     };
293     struct instr_storeRect {
294         QML_INSTR_HEADER
295         int propertyIndex;
296         struct QRect {
297 #if defined(Q_OS_MAC)
298             int y1;
299             int x1;
300             int y2;
301             int x2;
302 #else
303             int x1;
304             int y1;
305             int x2;
306             int y2;
307 #endif
308         } rect;
309     };
310     struct instr_storeRectF {
311         QML_INSTR_HEADER
312         int propertyIndex;
313         struct QRectF {
314             qreal xp;
315             qreal yp;
316             qreal w;
317             qreal h;
318         } rect;
319     };
320     struct instr_storeObject {
321         QML_INSTR_HEADER
322         int propertyIndex;
323         ushort line;
324     };
325     struct instr_assignCustomType {
326         QML_INSTR_HEADER
327         int propertyIndex;
328         int primitive;
329         int type;
330         ushort line;
331     };
332     struct instr_storeSignal {
333         QML_INSTR_HEADER
334         int signalIndex;
335         int value;
336         short context;
337         int name;
338         ushort line;
339     };
340     struct instr_assignSignalObject {
341         QML_INSTR_HEADER
342         int signal;
343         ushort line; 
344     };
345     struct instr_createComponent {
346         QML_INSTR_HEADER
347         int count;
348         int endLine;
349         int metaObject;
350         ushort column;
351         ushort line;
352     };
353     struct instr_fetchAttached {
354         QML_INSTR_HEADER
355         int id;
356         ushort line;
357     };
358     struct instr_defer {
359         QML_INSTR_HEADER
360         int deferCount;
361     };
362     struct instr_assignObjectList {
363         QML_INSTR_HEADER
364         ushort line;
365     };
366     struct instr_storePoint {
367         QML_INSTR_HEADER
368         int propertyIndex;
369         struct QPoint {
370 #if defined(Q_OS_MAC)
371             int yp;
372             int xp;
373 #else
374             int xp;
375             int yp;
376 #endif
377         } point;
378     };
379     struct instr_storePointF {
380         QML_INSTR_HEADER
381         int propertyIndex;
382         struct QPointF {
383             qreal xp;
384             qreal yp;
385         } point;
386     };
387     struct instr_storeSize {
388         QML_INSTR_HEADER
389         int propertyIndex;
390         struct QSize {
391             int wd;
392             int ht;
393         } size;
394     };
395     struct instr_storeSizeF {
396         QML_INSTR_HEADER
397         int propertyIndex;
398         struct QSizeF {
399             qreal wd;
400             qreal ht;
401         } size;
402     };
403     struct instr_storeVector3D {
404         QML_INSTR_HEADER
405         int propertyIndex;
406         struct QVector3D {
407             float xp;
408             float yp;
409             float zp;
410         } vector;
411     };
412
413     instr_common common;
414     instr_init init;
415     instr_create create;
416     instr_createSimple createSimple;
417     instr_storeMeta storeMeta;
418     instr_setId setId;
419     instr_assignValueSource assignValueSource;
420     instr_assignValueInterceptor assignValueInterceptor;
421     instr_initV8Bindings initV8Bindings;
422     instr_assignBinding assignBinding;
423     instr_fetch fetch;
424     instr_fetchValue fetchValue;
425     instr_fetchQmlList fetchQmlList;
426     instr_begin begin;
427     instr_storeFloat storeFloat;
428     instr_storeDouble storeDouble;
429     instr_storeInteger storeInteger;
430     instr_storeBool storeBool;
431     instr_storeString storeString;
432     instr_storeByteArray storeByteArray;
433     instr_storeScriptString storeScriptString;
434     instr_storeScript storeScript;
435     instr_storeUrl storeUrl;
436     instr_storeColor storeColor;
437     instr_storeDate storeDate;
438     instr_storeTime storeTime;
439     instr_storeDateTime storeDateTime;
440     instr_storePoint storePoint;
441     instr_storePointF storePointF;
442     instr_storeSize storeSize;
443     instr_storeSizeF storeSizeF;
444     instr_storeRect storeRect;
445     instr_storeRectF storeRectF;
446     instr_storeVector3D storeVector3D;
447     instr_storeObject storeObject;
448     instr_assignCustomType assignCustomType;
449     instr_storeSignal storeSignal;
450     instr_assignSignalObject assignSignalObject;
451     instr_createComponent createComponent;
452     instr_fetchAttached fetchAttached;
453     instr_defer defer;
454     instr_assignObjectList assignObjectList;
455
456     int size() const;
457 };
458
459 template<int N>
460 struct QDeclarativeInstructionMeta {
461 };
462
463 #define QML_INSTR_META_TEMPLATE(I, FMT) \
464     template<> struct QDeclarativeInstructionMeta<(int)QDeclarativeInstruction::I> { \
465         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
466         typedef QDeclarativeInstruction::instr_##FMT DataType; \
467         static const DataType &data(const QDeclarativeInstruction &instr) { return instr.FMT; } \
468     }; 
469 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
470 #undef QML_INSTR_META_TEMPLATE
471
472 QT_END_NAMESPACE
473
474 #endif // QDECLARATIVEINSTRUCTION_P_H