cfc530df040b4e2a649b4cf4c6fdb4899ca632f1
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlinstruction_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQMLINSTRUCTION_P_H
43 #define QQMLINSTRUCTION_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/qqmlpropertycache_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(StoreStringList, storeString) \
83     F(StoreStringQList, storeString) \
84     F(StoreTrString, storeTrString) \
85     F(StoreTrIdString, storeTrIdString) \
86     F(StoreByteArray, storeByteArray) \
87     F(StoreUrl, storeUrl) \
88     F(StoreUrlQList, storeUrl) \
89     F(StoreFloat, storeFloat) \
90     F(StoreDouble, storeDouble) \
91     F(StoreDoubleQList, storeDouble) \
92     F(StoreBool, storeBool) \
93     F(StoreBoolQList, storeBool) \
94     F(StoreInteger, storeInteger) \
95     F(StoreIntegerQList, storeInteger) \
96     F(StoreColor, storeColor) \
97     F(StoreDate, storeDate) \
98     F(StoreTime, storeTime) \
99     F(StoreDateTime, storeDateTime) \
100     F(StorePoint, storePoint) \
101     F(StorePointF, storePointF) \
102     F(StoreSize, storeSize) \
103     F(StoreSizeF, storeSizeF) \
104     F(StoreRect, storeRect) \
105     F(StoreRectF, storeRectF) \
106     F(StoreVector3D, storeVector3D) \
107     F(StoreVector4D, storeVector4D) \
108     F(StoreObject, storeObject) \
109     F(AssignCustomType, assignCustomType) \
110     F(AssignSignalObject, assignSignalObject) \
111     F(StoreSignal, storeSignal) \
112     F(StoreImportedScript, storeScript) \
113     F(StoreScriptString, storeScriptString) \
114     F(BeginObject, begin) \
115     F(InitV8Bindings, initV8Bindings) \
116     F(StoreBinding, assignBinding) \
117     F(StoreV8Binding, assignBinding) \
118     F(StoreV4Binding, assignV4Binding) \
119     F(StoreValueSource, assignValueSource) \
120     F(StoreValueInterceptor, assignValueInterceptor) \
121     F(StoreObjectQList, common) \
122     F(AssignObjectList, assignObjectList) \
123     F(StoreVariantObject, storeObject) \
124     F(StoreVarObject, storeObject) \
125     F(StoreInterface, storeObject) \
126     F(FetchAttached, fetchAttached) \
127     F(FetchQList, fetchQmlList) \
128     F(FetchObject, fetch) \
129     F(PopQList, common) \
130     F(Defer, defer) \
131     F(PopFetchedObject, common) \
132     F(FetchValueType, fetchValue) \
133     F(PopValueType, fetchValue) 
134
135 #if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
136 #  define QML_THREADED_VME_INTERPRETER
137 #endif
138
139 #ifdef Q_ALIGNOF
140 #  define QML_INSTR_ALIGN_MASK (Q_ALIGNOF(QQmlInstruction) - 1)
141 #else
142 #  define QML_INSTR_ALIGN_MASK (sizeof(void *) - 1)
143 #endif
144
145 #ifdef QML_THREADED_VME_INTERPRETER
146 #  define QML_INSTR_HEADER void *code;
147 #else
148 #  define QML_INSTR_HEADER quint8 instructionType;
149 #endif
150
151 #define QML_INSTR_ENUM(I, FMT)  I,
152 #define QML_INSTR_SIZE(I, FMT) ((sizeof(QQmlInstruction::instr_##FMT) + QML_INSTR_ALIGN_MASK) & ~QML_INSTR_ALIGN_MASK)
153
154 class QQmlCompiledData;
155 union QQmlInstruction
156 {
157     enum Type { 
158         FOR_EACH_QML_INSTR(QML_INSTR_ENUM)
159     };
160
161     struct instr_common {
162         QML_INSTR_HEADER
163     };
164     struct instr_init {
165         QML_INSTR_HEADER
166         int bindingsSize;
167         int parserStatusSize;
168         int contextCache;
169         int compiledBinding;
170         int objectStackSize;
171         int listStackSize;
172     };
173     struct instr_deferInit {
174         QML_INSTR_HEADER
175         int bindingsSize;
176         int parserStatusSize;
177         int objectStackSize;
178         int listStackSize;
179     };
180     struct instr_createQml {
181         QML_INSTR_HEADER
182         int type;
183         int bindingBits;
184         bool isRoot;
185     };
186     struct instr_completeQml {
187         QML_INSTR_HEADER
188         ushort column;
189         ushort line; 
190         bool isRoot;
191     };
192     struct instr_create {
193         QML_INSTR_HEADER
194         int type;
195         int data;
196         ushort column;
197         ushort line; 
198         bool isRoot;
199     };
200     struct instr_createSimple {
201         QML_INSTR_HEADER
202         void (*create)(void *);
203         int typeSize;
204         int type;
205         ushort column;
206         ushort line; 
207     };
208     struct instr_storeMeta {
209         QML_INSTR_HEADER
210         int data;
211         int aliasData;
212         int propertyCache;
213     };
214     struct instr_setId {
215         QML_INSTR_HEADER
216         int value;
217         int index;
218     };
219     struct instr_assignValueSource {
220         QML_INSTR_HEADER
221         QQmlPropertyRawData property;
222         int owner;
223         int castValue;
224     };
225     struct instr_assignValueInterceptor {
226         QML_INSTR_HEADER
227         QQmlPropertyRawData property;
228         int owner;
229         int castValue;
230     };
231     struct instr_initV8Bindings {
232         QML_INSTR_HEADER
233         ushort programIndex;
234         ushort line;
235     };
236     struct instr_assignV4Binding {
237         QML_INSTR_HEADER
238         unsigned int property;
239         int value;
240         short context;
241         short owner;
242         bool isRoot;
243         ushort line;
244         ushort column;
245     };
246     struct instr_assignBinding {
247         QML_INSTR_HEADER
248         QQmlPropertyRawData property;
249         int value;
250         short context;
251         short owner;
252         bool isRoot;
253         bool isAlias;
254         ushort line;
255         ushort column;
256     };
257     struct instr_fetch {
258         QML_INSTR_HEADER
259         int property;
260         ushort line;
261     };
262     struct instr_fetchValue {
263         QML_INSTR_HEADER
264         int property;
265         int type;
266         quint32 bindingSkipList;
267     };
268     struct instr_fetchQmlList {
269         QML_INSTR_HEADER
270         int property;
271         int type;
272     };
273     struct instr_begin {
274         QML_INSTR_HEADER
275         int castValue;
276     }; 
277     struct instr_storeFloat {
278         QML_INSTR_HEADER
279         int propertyIndex;
280         float value;
281     };
282     struct instr_storeDouble {
283         QML_INSTR_HEADER
284         int propertyIndex;
285         double value;
286     };
287     struct instr_storeInteger {
288         QML_INSTR_HEADER
289         int propertyIndex;
290         int value;
291     };
292     struct instr_storeBool {
293         QML_INSTR_HEADER
294         int propertyIndex;
295         bool value;
296     };
297     struct instr_storeString {
298         QML_INSTR_HEADER
299         int propertyIndex;
300         int value;
301     };
302     struct instr_storeTrString {
303         QML_INSTR_HEADER
304         int propertyIndex;
305         int context;
306         int text;
307         int comment;
308         int n;
309     };
310     struct instr_storeTrIdString {
311         QML_INSTR_HEADER
312         int propertyIndex;
313         int text;
314         int n;
315     };
316     struct instr_storeByteArray {
317         QML_INSTR_HEADER
318         int propertyIndex;
319         int value;
320     };
321     struct instr_storeScriptString {
322         QML_INSTR_HEADER
323         int propertyIndex;
324         int value;
325         int scope;
326         int bindingId;
327         ushort line;
328         ushort column;
329     }; 
330     struct instr_storeScript {
331         QML_INSTR_HEADER
332         int value;
333     };
334     struct instr_storeUrl {
335         QML_INSTR_HEADER
336         int propertyIndex;
337         int value;
338     };
339     struct instr_storeColor {
340         QML_INSTR_HEADER
341         int propertyIndex;
342         unsigned int value;
343     };
344     struct instr_storeDate {
345         QML_INSTR_HEADER
346         int propertyIndex;
347         int value;
348     };
349     struct instr_storeTime {
350         QML_INSTR_HEADER
351         int propertyIndex;
352         struct QTime {
353             int mds;
354 #if defined(Q_OS_WINCE)
355             int startTick;
356 #endif
357         } time;
358     };
359     struct instr_storeDateTime {
360         QML_INSTR_HEADER
361         int propertyIndex;
362         int date;
363         instr_storeTime::QTime time;
364     };
365     struct instr_storeRect {
366         QML_INSTR_HEADER
367         int propertyIndex;
368         struct QRect {
369             int x1;
370             int y1;
371             int x2;
372             int y2;
373         } rect;
374     };
375     struct instr_storeRectF {
376         QML_INSTR_HEADER
377         int propertyIndex;
378         struct QRectF {
379             qreal xp;
380             qreal yp;
381             qreal w;
382             qreal h;
383         } rect;
384     };
385     struct instr_storeObject {
386         QML_INSTR_HEADER
387         int propertyIndex;
388         ushort line;
389     };
390     struct instr_assignCustomType {
391         QML_INSTR_HEADER
392         int propertyIndex;
393         int primitive;
394         int type;
395         ushort line;
396     };
397     struct instr_storeSignal {
398         QML_INSTR_HEADER
399         int signalIndex;
400         int value;
401         short context;
402         ushort line;
403         ushort column;
404     };
405     struct instr_assignSignalObject {
406         QML_INSTR_HEADER
407         int signal;
408         ushort line; 
409     };
410     struct instr_createComponent {
411         QML_INSTR_HEADER
412         int count;
413         int endLine;
414         int metaObject;
415         ushort column;
416         ushort line;
417         bool isRoot;
418     };
419     struct instr_fetchAttached {
420         QML_INSTR_HEADER
421         int id;
422         ushort line;
423     };
424     struct instr_defer {
425         QML_INSTR_HEADER
426         int deferCount;
427     };
428     struct instr_assignObjectList {
429         QML_INSTR_HEADER
430         ushort line;
431     };
432     struct instr_storePoint {
433         QML_INSTR_HEADER
434         int propertyIndex;
435         struct QPoint {
436             int xp;
437             int yp;
438         } point;
439     };
440     struct instr_storePointF {
441         QML_INSTR_HEADER
442         int propertyIndex;
443         struct QPointF {
444             qreal xp;
445             qreal yp;
446         } point;
447     };
448     struct instr_storeSize {
449         QML_INSTR_HEADER
450         int propertyIndex;
451         struct QSize {
452             int wd;
453             int ht;
454         } size;
455     };
456     struct instr_storeSizeF {
457         QML_INSTR_HEADER
458         int propertyIndex;
459         struct QSizeF {
460             qreal wd;
461             qreal ht;
462         } size;
463     };
464     struct instr_storeVector3D {
465         QML_INSTR_HEADER
466         int propertyIndex;
467         struct QVector3D {
468             float xp;
469             float yp;
470             float zp;
471         } vector;
472     };
473     struct instr_storeVector4D {
474         QML_INSTR_HEADER
475         int propertyIndex;
476         struct QVector4D {
477             float xp;
478             float yp;
479             float zp;
480             float wp;
481         } vector;
482     };
483
484     instr_common common;
485     instr_init init;
486     instr_deferInit deferInit;
487     instr_create create;
488     instr_createQml createQml;
489     instr_completeQml completeQml;
490     instr_createSimple createSimple;
491     instr_storeMeta storeMeta;
492     instr_setId setId;
493     instr_assignValueSource assignValueSource;
494     instr_assignValueInterceptor assignValueInterceptor;
495     instr_initV8Bindings initV8Bindings;
496     instr_assignV4Binding assignV4Binding;
497     instr_assignBinding assignBinding;
498     instr_fetch fetch;
499     instr_fetchValue fetchValue;
500     instr_fetchQmlList fetchQmlList;
501     instr_begin begin;
502     instr_storeFloat storeFloat;
503     instr_storeDouble storeDouble;
504     instr_storeInteger storeInteger;
505     instr_storeBool storeBool;
506     instr_storeString storeString;
507     instr_storeTrString storeTrString;
508     instr_storeTrIdString storeTrIdString;
509     instr_storeByteArray storeByteArray;
510     instr_storeScriptString storeScriptString;
511     instr_storeScript storeScript;
512     instr_storeUrl storeUrl;
513     instr_storeColor storeColor;
514     instr_storeDate storeDate;
515     instr_storeTime storeTime;
516     instr_storeDateTime storeDateTime;
517     instr_storePoint storePoint;
518     instr_storePointF storePointF;
519     instr_storeSize storeSize;
520     instr_storeSizeF storeSizeF;
521     instr_storeRect storeRect;
522     instr_storeRectF storeRectF;
523     instr_storeVector3D storeVector3D;
524     instr_storeVector4D storeVector4D;
525     instr_storeObject storeObject;
526     instr_assignCustomType assignCustomType;
527     instr_storeSignal storeSignal;
528     instr_assignSignalObject assignSignalObject;
529     instr_createComponent createComponent;
530     instr_fetchAttached fetchAttached;
531     instr_defer defer;
532     instr_assignObjectList assignObjectList;
533
534     static int size(Type type);
535 };
536
537 template<int N>
538 struct QQmlInstructionMeta {
539 };
540
541 #define QML_INSTR_META_TEMPLATE(I, FMT) \
542     template<> struct QQmlInstructionMeta<(int)QQmlInstruction::I> { \
543         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
544         typedef QQmlInstruction::instr_##FMT DataType; \
545         static const DataType &data(const QQmlInstruction &instr) { return instr.FMT; } \
546         static void setData(QQmlInstruction &instr, const DataType &v) { instr.FMT = v; } \
547     }; 
548 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
549 #undef QML_INSTR_META_TEMPLATE
550
551 template<int Instr>
552 class QQmlInstructionData : public QQmlInstructionMeta<Instr>::DataType
553 {
554 };
555
556 QT_END_NAMESPACE
557
558 #endif // QQMLINSTRUCTION_P_H