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