7b36c9a87e8da3242e0315c38c2b4a8194f0cd21
[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 #include <private/qdeclarativepropertycache_p.h>
58
59 QT_BEGIN_NAMESPACE
60
61 #define FOR_EACH_QML_INSTR(F) \
62     F(Init, init) \
63     F(DeferInit, deferInit) \
64     F(Done, common) \
65     F(CreateCppObject, create) \
66     F(CreateQMLObject, createQml) \
67     F(CompleteQMLObject, completeQml) \
68     F(CreateSimpleObject, createSimple) \
69     F(SetId, setId) \
70     F(SetDefault, common) \
71     F(CreateComponent, createComponent) \
72     F(StoreMetaObject, storeMeta) \
73     F(StoreVariant, storeString) \
74     F(StoreVariantInteger, storeInteger) \
75     F(StoreVariantDouble, storeDouble) \
76     F(StoreVariantBool, storeBool) \
77     F(StoreVar, storeString) \
78     F(StoreVarInteger, storeInteger) \
79     F(StoreVarDouble, storeDouble) \
80     F(StoreVarBool, storeBool) \
81     F(StoreString, storeString) \
82     F(StoreByteArray, storeByteArray) \
83     F(StoreUrl, storeUrl) \
84     F(StoreFloat, storeFloat) \
85     F(StoreDouble, storeDouble) \
86     F(StoreBool, storeBool) \
87     F(StoreInteger, storeInteger) \
88     F(StoreColor, storeColor) \
89     F(StoreDate, storeDate) \
90     F(StoreTime, storeTime) \
91     F(StoreDateTime, storeDateTime) \
92     F(StorePoint, storePoint) \
93     F(StorePointF, storePointF) \
94     F(StoreSize, storeSize) \
95     F(StoreSizeF, storeSizeF) \
96     F(StoreRect, storeRect) \
97     F(StoreRectF, storeRectF) \
98     F(StoreVector3D, storeVector3D) \
99     F(StoreVector4D, storeVector4D) \
100     F(StoreObject, storeObject) \
101     F(AssignCustomType, assignCustomType) \
102     F(AssignSignalObject, assignSignalObject) \
103     F(StoreSignal, storeSignal) \
104     F(StoreImportedScript, storeScript) \
105     F(StoreScriptString, storeScriptString) \
106     F(BeginObject, begin) \
107     F(InitV8Bindings, initV8Bindings) \
108     F(StoreBinding, assignBinding) \
109     F(StoreBindingOnAlias, assignBinding) \
110     F(StoreV8Binding, assignBinding) \
111     F(StoreV4Binding, assignV4Binding) \
112     F(StoreValueSource, assignValueSource) \
113     F(StoreValueInterceptor, assignValueInterceptor) \
114     F(StoreObjectQList, common) \
115     F(AssignObjectList, assignObjectList) \
116     F(StoreVariantObject, storeObject) \
117     F(StoreVarObject, storeObject) \
118     F(StoreInterface, storeObject) \
119     F(FetchAttached, fetchAttached) \
120     F(FetchQList, fetchQmlList) \
121     F(FetchObject, fetch) \
122     F(PopQList, common) \
123     F(Defer, defer) \
124     F(PopFetchedObject, common) \
125     F(FetchValueType, fetchValue) \
126     F(PopValueType, fetchValue) 
127
128 #if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
129 #  define QML_THREADED_VME_INTERPRETER
130 #endif
131
132 #ifdef Q_ALIGNOF
133 #  define QML_INSTR_ALIGN_MASK (Q_ALIGNOF(QDeclarativeInstruction) - 1)
134 #else
135 #  define QML_INSTR_ALIGN_MASK (sizeof(void *) - 1)
136 #endif
137
138 #ifdef QML_THREADED_VME_INTERPRETER
139 #  define QML_INSTR_HEADER void *code;
140 #else
141 #  define QML_INSTR_HEADER quint8 instructionType;
142 #endif
143
144 #define QML_INSTR_ENUM(I, FMT)  I,
145 #define QML_INSTR_SIZE(I, FMT) ((sizeof(QDeclarativeInstruction::instr_##FMT) + QML_INSTR_ALIGN_MASK) & ~QML_INSTR_ALIGN_MASK)
146
147 class QDeclarativeCompiledData;
148 union QDeclarativeInstruction
149 {
150     enum Type { 
151         FOR_EACH_QML_INSTR(QML_INSTR_ENUM)
152     };
153
154     struct instr_common {
155         QML_INSTR_HEADER
156     };
157     struct instr_init {
158         QML_INSTR_HEADER
159         int bindingsSize;
160         int parserStatusSize;
161         int contextCache;
162         int compiledBinding;
163         int objectStackSize;
164         int listStackSize;
165     };
166     struct instr_deferInit {
167         QML_INSTR_HEADER
168         int bindingsSize;
169         int parserStatusSize;
170         int objectStackSize;
171         int listStackSize;
172     };
173     struct instr_createQml {
174         QML_INSTR_HEADER
175         int type;
176         int bindingBits;
177         bool isRoot;
178     };
179     struct instr_completeQml {
180         QML_INSTR_HEADER
181         ushort column;
182         ushort line; 
183         bool isRoot;
184     };
185     struct instr_create {
186         QML_INSTR_HEADER
187         int type;
188         int data;
189         ushort column;
190         ushort line; 
191         bool isRoot;
192     };
193     struct instr_createSimple {
194         QML_INSTR_HEADER
195         void (*create)(void *);
196         int typeSize;
197         int type;
198         ushort column;
199         ushort line; 
200     };
201     struct instr_storeMeta {
202         QML_INSTR_HEADER
203         int data;
204         int aliasData;
205         int propertyCache;
206     };
207     struct instr_setId {
208         QML_INSTR_HEADER
209         int value;
210         int index;
211     };
212     struct instr_assignValueSource {
213         QML_INSTR_HEADER
214         QDeclarativePropertyCache::RawData property;
215         int owner;
216         int castValue;
217     };
218     struct instr_assignValueInterceptor {
219         QML_INSTR_HEADER
220         QDeclarativePropertyCache::RawData property;
221         int owner;
222         int castValue;
223     };
224     struct instr_initV8Bindings {
225         QML_INSTR_HEADER
226         int program;
227         ushort programIndex;
228         ushort line;
229     };
230     struct instr_assignV4Binding {
231         QML_INSTR_HEADER
232         unsigned int property;
233         int value;
234         short context;
235         short owner;
236         bool isRoot;
237         ushort line;
238     };
239     struct instr_assignBinding {
240         QML_INSTR_HEADER
241         QDeclarativePropertyCache::RawData property;
242         int value;
243         short context;
244         short owner;
245         bool isRoot;
246         ushort line;
247     };
248     struct instr_fetch {
249         QML_INSTR_HEADER
250         int property;
251         ushort line;
252     };
253     struct instr_fetchValue {
254         QML_INSTR_HEADER
255         int property;
256         int type;
257         quint32 bindingSkipList;
258     };
259     struct instr_fetchQmlList {
260         QML_INSTR_HEADER
261         int property;
262         int type;
263     };
264     struct instr_begin {
265         QML_INSTR_HEADER
266         int castValue;
267     }; 
268     struct instr_storeFloat {
269         QML_INSTR_HEADER
270         int propertyIndex;
271         float value;
272     };
273     struct instr_storeDouble {
274         QML_INSTR_HEADER
275         int propertyIndex;
276         double value;
277     };
278     struct instr_storeInteger {
279         QML_INSTR_HEADER
280         int propertyIndex;
281         int value;
282     };
283     struct instr_storeBool {
284         QML_INSTR_HEADER
285         int propertyIndex;
286         bool value;
287     };
288     struct instr_storeString {
289         QML_INSTR_HEADER
290         int propertyIndex;
291         int value;
292     };
293     struct instr_storeByteArray {
294         QML_INSTR_HEADER
295         int propertyIndex;
296         int value;
297     };
298     struct instr_storeScriptString {
299         QML_INSTR_HEADER
300         int propertyIndex;
301         int value;
302         int scope;
303         int bindingId;
304         ushort line;
305     }; 
306     struct instr_storeScript {
307         QML_INSTR_HEADER
308         int value;
309     };
310     struct instr_storeUrl {
311         QML_INSTR_HEADER
312         int propertyIndex;
313         int value;
314     };
315     struct instr_storeColor {
316         QML_INSTR_HEADER
317         int propertyIndex;
318         unsigned int value;
319     };
320     struct instr_storeDate {
321         QML_INSTR_HEADER
322         int propertyIndex;
323         int value;
324     };
325     struct instr_storeTime {
326         QML_INSTR_HEADER
327         int propertyIndex;
328         struct QTime {
329             int mds;
330 #if defined(Q_OS_WINCE)
331             int startTick;
332 #endif
333         } time;
334     };
335     struct instr_storeDateTime {
336         QML_INSTR_HEADER
337         int propertyIndex;
338         int date;
339         instr_storeTime::QTime time;
340     };
341     struct instr_storeRect {
342         QML_INSTR_HEADER
343         int propertyIndex;
344         struct QRect {
345 #if defined(Q_OS_MAC)
346             int y1;
347             int x1;
348             int y2;
349             int x2;
350 #else
351             int x1;
352             int y1;
353             int x2;
354             int y2;
355 #endif
356         } rect;
357     };
358     struct instr_storeRectF {
359         QML_INSTR_HEADER
360         int propertyIndex;
361         struct QRectF {
362             qreal xp;
363             qreal yp;
364             qreal w;
365             qreal h;
366         } rect;
367     };
368     struct instr_storeObject {
369         QML_INSTR_HEADER
370         int propertyIndex;
371         ushort line;
372     };
373     struct instr_assignCustomType {
374         QML_INSTR_HEADER
375         int propertyIndex;
376         int primitive;
377         int type;
378         ushort line;
379     };
380     struct instr_storeSignal {
381         QML_INSTR_HEADER
382         int signalIndex;
383         int value;
384         short context;
385         int name;
386         ushort line;
387     };
388     struct instr_assignSignalObject {
389         QML_INSTR_HEADER
390         int signal;
391         ushort line; 
392     };
393     struct instr_createComponent {
394         QML_INSTR_HEADER
395         int count;
396         int endLine;
397         int metaObject;
398         ushort column;
399         ushort line;
400         bool isRoot;
401     };
402     struct instr_fetchAttached {
403         QML_INSTR_HEADER
404         int id;
405         ushort line;
406     };
407     struct instr_defer {
408         QML_INSTR_HEADER
409         int deferCount;
410     };
411     struct instr_assignObjectList {
412         QML_INSTR_HEADER
413         ushort line;
414     };
415     struct instr_storePoint {
416         QML_INSTR_HEADER
417         int propertyIndex;
418         struct QPoint {
419             int xp;
420             int yp;
421         } point;
422     };
423     struct instr_storePointF {
424         QML_INSTR_HEADER
425         int propertyIndex;
426         struct QPointF {
427             qreal xp;
428             qreal yp;
429         } point;
430     };
431     struct instr_storeSize {
432         QML_INSTR_HEADER
433         int propertyIndex;
434         struct QSize {
435             int wd;
436             int ht;
437         } size;
438     };
439     struct instr_storeSizeF {
440         QML_INSTR_HEADER
441         int propertyIndex;
442         struct QSizeF {
443             qreal wd;
444             qreal ht;
445         } size;
446     };
447     struct instr_storeVector3D {
448         QML_INSTR_HEADER
449         int propertyIndex;
450         struct QVector3D {
451             float xp;
452             float yp;
453             float zp;
454         } vector;
455     };
456     struct instr_storeVector4D {
457         QML_INSTR_HEADER
458         int propertyIndex;
459         struct QVector4D {
460             float xp;
461             float yp;
462             float zp;
463             float wp;
464         } vector;
465     };
466
467     instr_common common;
468     instr_init init;
469     instr_deferInit deferInit;
470     instr_create create;
471     instr_createQml createQml;
472     instr_completeQml completeQml;
473     instr_createSimple createSimple;
474     instr_storeMeta storeMeta;
475     instr_setId setId;
476     instr_assignValueSource assignValueSource;
477     instr_assignValueInterceptor assignValueInterceptor;
478     instr_initV8Bindings initV8Bindings;
479     instr_assignV4Binding assignV4Binding;
480     instr_assignBinding assignBinding;
481     instr_fetch fetch;
482     instr_fetchValue fetchValue;
483     instr_fetchQmlList fetchQmlList;
484     instr_begin begin;
485     instr_storeFloat storeFloat;
486     instr_storeDouble storeDouble;
487     instr_storeInteger storeInteger;
488     instr_storeBool storeBool;
489     instr_storeString storeString;
490     instr_storeByteArray storeByteArray;
491     instr_storeScriptString storeScriptString;
492     instr_storeScript storeScript;
493     instr_storeUrl storeUrl;
494     instr_storeColor storeColor;
495     instr_storeDate storeDate;
496     instr_storeTime storeTime;
497     instr_storeDateTime storeDateTime;
498     instr_storePoint storePoint;
499     instr_storePointF storePointF;
500     instr_storeSize storeSize;
501     instr_storeSizeF storeSizeF;
502     instr_storeRect storeRect;
503     instr_storeRectF storeRectF;
504     instr_storeVector3D storeVector3D;
505     instr_storeVector4D storeVector4D;
506     instr_storeObject storeObject;
507     instr_assignCustomType assignCustomType;
508     instr_storeSignal storeSignal;
509     instr_assignSignalObject assignSignalObject;
510     instr_createComponent createComponent;
511     instr_fetchAttached fetchAttached;
512     instr_defer defer;
513     instr_assignObjectList assignObjectList;
514
515     static int size(Type type);
516 };
517
518 template<int N>
519 struct QDeclarativeInstructionMeta {
520 };
521
522 #define QML_INSTR_META_TEMPLATE(I, FMT) \
523     template<> struct QDeclarativeInstructionMeta<(int)QDeclarativeInstruction::I> { \
524         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
525         typedef QDeclarativeInstruction::instr_##FMT DataType; \
526         static const DataType &data(const QDeclarativeInstruction &instr) { return instr.FMT; } \
527         static void setData(QDeclarativeInstruction &instr, const DataType &v) { instr.FMT = v; } \
528     }; 
529 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
530 #undef QML_INSTR_META_TEMPLATE
531
532 template<int Instr>
533 class QDeclarativeInstructionData : public QDeclarativeInstructionMeta<Instr>::DataType
534 {
535 };
536
537 QT_END_NAMESPACE
538
539 #endif // QDECLARATIVEINSTRUCTION_P_H