Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtdeclarative
[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(StoreBinding, assignBinding) \
99     F(StoreBindingOnAlias, assignBinding) \
100     F(StoreCompiledBinding, assignBinding) \
101     F(StoreValueSource, assignValueSource) \
102     F(StoreValueInterceptor, assignValueInterceptor) \
103     F(StoreObjectQList, common) \
104     F(AssignObjectList, assignObjectList) \
105     F(StoreVariantObject, storeObject) \
106     F(StoreInterface, storeObject) \
107     F(FetchAttached, fetchAttached) \
108     F(FetchQList, fetchQmlList) \
109     F(FetchObject, fetch) \
110     F(PopQList, common) \
111     F(Defer, defer) \
112     F(PopFetchedObject, common) \
113     F(FetchValueType, fetchValue) \
114     F(PopValueType, fetchValue) 
115
116 #ifdef Q_ALIGNOF
117 #  define QML_INSTR_ALIGN_MASK (Q_ALIGNOF(QDeclarativeInstruction) - 1)
118 #else
119 #  define QML_INSTR_ALIGN_MASK (sizeof(void *) - 1)
120 #endif
121
122 #define QML_INSTR_HEADER quint8 instructionType;
123 #define QML_INSTR_ENUM(I, FMT)  I,
124 #define QML_INSTR_SIZE(I, FMT) ((sizeof(QDeclarativeInstruction::instr_##FMT) + QML_INSTR_ALIGN_MASK) & ~QML_INSTR_ALIGN_MASK)
125
126 class QDeclarativeCompiledData;
127 union QDeclarativeInstruction
128 {
129     enum Type { 
130         FOR_EACH_QML_INSTR(QML_INSTR_ENUM)
131     };
132
133     inline void setType(Type type) { common.instructionType = type; }
134     inline Type type() const { return (Type)common.instructionType; }
135
136     struct instr_common {
137         QML_INSTR_HEADER
138     };
139     struct instr_init {
140         QML_INSTR_HEADER
141         int bindingsSize;
142         int parserStatusSize;
143         int contextCache;
144         int compiledBinding;
145     };
146     struct instr_create {
147         QML_INSTR_HEADER
148         int type;
149         int data;
150         int bindingBits;
151         ushort column;
152         ushort line; 
153     };
154     struct instr_createSimple {
155         QML_INSTR_HEADER
156         void (*create)(void *);
157         int typeSize;
158         int type;
159         ushort column;
160         ushort line; 
161     };
162     struct instr_storeMeta {
163         QML_INSTR_HEADER
164         int data;
165         int aliasData;
166         int propertyCache;
167     };
168     struct instr_setId {
169         QML_INSTR_HEADER
170         int value;
171         int index;
172     };
173     struct instr_assignValueSource {
174         QML_INSTR_HEADER
175         int property;
176         int owner;
177         int castValue;
178     };
179     struct instr_assignValueInterceptor {
180         QML_INSTR_HEADER
181         int property;
182         int owner;
183         int castValue;
184     };
185     struct instr_assignBinding {
186         QML_INSTR_HEADER
187         unsigned int property;
188         int value;
189         short context;
190         short owner;
191         ushort line;
192     };
193     struct instr_fetch {
194         QML_INSTR_HEADER
195         int property;
196         ushort line;
197     };
198     struct instr_fetchValue {
199         QML_INSTR_HEADER
200         int property;
201         int type;
202         quint32 bindingSkipList;
203     };
204     struct instr_fetchQmlList {
205         QML_INSTR_HEADER
206         int property;
207         int type;
208     };
209     struct instr_begin {
210         QML_INSTR_HEADER
211         int castValue;
212     }; 
213     struct instr_storeFloat {
214         QML_INSTR_HEADER
215         int propertyIndex;
216         float value;
217     };
218     struct instr_storeDouble {
219         QML_INSTR_HEADER
220         int propertyIndex;
221         double value;
222     };
223     struct instr_storeInteger {
224         QML_INSTR_HEADER
225         int propertyIndex;
226         int value;
227     };
228     struct instr_storeBool {
229         QML_INSTR_HEADER
230         int propertyIndex;
231         bool value;
232     };
233     struct instr_storeString {
234         QML_INSTR_HEADER
235         int propertyIndex;
236         int value;
237     };
238     struct instr_storeByteArray {
239         QML_INSTR_HEADER
240         int propertyIndex;
241         int value;
242     };
243     struct instr_storeScriptString {
244         QML_INSTR_HEADER
245         int propertyIndex;
246         int value;
247         int scope;
248     }; 
249     struct instr_storeScript {
250         QML_INSTR_HEADER
251         int value;
252     };
253     struct instr_storeUrl {
254         QML_INSTR_HEADER
255         int propertyIndex;
256         int value;
257     };
258     struct instr_storeColor {
259         QML_INSTR_HEADER
260         int propertyIndex;
261         unsigned int value;
262     };
263     struct instr_storeDate {
264         QML_INSTR_HEADER
265         int propertyIndex;
266         int value;
267     };
268     struct instr_storeTime {
269         QML_INSTR_HEADER
270         int propertyIndex;
271         struct QTime {
272             int mds;
273 #if defined(Q_OS_WINCE)
274             int startTick;
275 #endif
276         } time;
277     };
278     struct instr_storeDateTime {
279         QML_INSTR_HEADER
280         int propertyIndex;
281         int date;
282         instr_storeTime::QTime time;
283     };
284     struct instr_storeRect {
285         QML_INSTR_HEADER
286         int propertyIndex;
287         struct QRect {
288 #if defined(Q_OS_MAC)
289             int y1;
290             int x1;
291             int y2;
292             int x2;
293 #else
294             int x1;
295             int y1;
296             int x2;
297             int y2;
298 #endif
299         } rect;
300     };
301     struct instr_storeRectF {
302         QML_INSTR_HEADER
303         int propertyIndex;
304         struct QRectF {
305             qreal xp;
306             qreal yp;
307             qreal w;
308             qreal h;
309         } rect;
310     };
311     struct instr_storeObject {
312         QML_INSTR_HEADER
313         int propertyIndex;
314         ushort line;
315     };
316     struct instr_assignCustomType {
317         QML_INSTR_HEADER
318         int propertyIndex;
319         int primitive;
320         int type;
321         ushort line;
322     };
323     struct instr_storeSignal {
324         QML_INSTR_HEADER
325         int signalIndex;
326         int value;
327         short context;
328         int name;
329         ushort line;
330     };
331     struct instr_assignSignalObject {
332         QML_INSTR_HEADER
333         int signal;
334         ushort line; 
335     };
336     struct instr_createComponent {
337         QML_INSTR_HEADER
338         int count;
339         int endLine;
340         int metaObject;
341         ushort column;
342         ushort line;
343     };
344     struct instr_fetchAttached {
345         QML_INSTR_HEADER
346         int id;
347         ushort line;
348     };
349     struct instr_defer {
350         QML_INSTR_HEADER
351         int deferCount;
352     };
353     struct instr_assignObjectList {
354         QML_INSTR_HEADER
355         ushort line;
356     };
357     struct instr_storePoint {
358         QML_INSTR_HEADER
359         int propertyIndex;
360         struct QPoint {
361 #if defined(Q_OS_MAC)
362             int yp;
363             int xp;
364 #else
365             int xp;
366             int yp;
367 #endif
368         } point;
369     };
370     struct instr_storePointF {
371         QML_INSTR_HEADER
372         int propertyIndex;
373         struct QPointF {
374             qreal xp;
375             qreal yp;
376         } point;
377     };
378     struct instr_storeSize {
379         QML_INSTR_HEADER
380         int propertyIndex;
381         struct QSize {
382             int wd;
383             int ht;
384         } size;
385     };
386     struct instr_storeSizeF {
387         QML_INSTR_HEADER
388         int propertyIndex;
389         struct QSizeF {
390             qreal wd;
391             qreal ht;
392         } size;
393     };
394     struct instr_storeVector3D {
395         QML_INSTR_HEADER
396         int propertyIndex;
397         struct QVector3D {
398             float xp;
399             float yp;
400             float zp;
401         } vector;
402     };
403
404     instr_common common;
405     instr_init init;
406     instr_create create;
407     instr_createSimple createSimple;
408     instr_storeMeta storeMeta;
409     instr_setId setId;
410     instr_assignValueSource assignValueSource;
411     instr_assignValueInterceptor assignValueInterceptor;
412     instr_assignBinding assignBinding;
413     instr_fetch fetch;
414     instr_fetchValue fetchValue;
415     instr_fetchQmlList fetchQmlList;
416     instr_begin begin;
417     instr_storeFloat storeFloat;
418     instr_storeDouble storeDouble;
419     instr_storeInteger storeInteger;
420     instr_storeBool storeBool;
421     instr_storeString storeString;
422     instr_storeByteArray storeByteArray;
423     instr_storeScriptString storeScriptString;
424     instr_storeScript storeScript;
425     instr_storeUrl storeUrl;
426     instr_storeColor storeColor;
427     instr_storeDate storeDate;
428     instr_storeTime storeTime;
429     instr_storeDateTime storeDateTime;
430     instr_storePoint storePoint;
431     instr_storePointF storePointF;
432     instr_storeSize storeSize;
433     instr_storeSizeF storeSizeF;
434     instr_storeRect storeRect;
435     instr_storeRectF storeRectF;
436     instr_storeVector3D storeVector3D;
437     instr_storeObject storeObject;
438     instr_assignCustomType assignCustomType;
439     instr_storeSignal storeSignal;
440     instr_assignSignalObject assignSignalObject;
441     instr_createComponent createComponent;
442     instr_fetchAttached fetchAttached;
443     instr_defer defer;
444     instr_assignObjectList assignObjectList;
445
446     int size() const;
447 };
448
449 template<int N>
450 struct QDeclarativeInstructionMeta {
451 };
452
453 #define QML_INSTR_META_TEMPLATE(I, FMT) \
454     template<> struct QDeclarativeInstructionMeta<(int)QDeclarativeInstruction::I> { \
455         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
456         typedef QDeclarativeInstruction::instr_##FMT DataType; \
457         static const DataType &data(const QDeclarativeInstruction &instr) { return instr.FMT; } \
458     }; 
459 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
460 #undef QML_INSTR_META_TEMPLATE
461
462 QT_END_NAMESPACE
463
464 #endif // QDECLARATIVEINSTRUCTION_P_H