Improve documentation.
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlinstruction_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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:1;
203         bool parentToSuper:1;
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:1;
248         bool isAlias:1;
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:1;
259         bool isAlias:1;
260         bool isFallback:1;
261         bool isSafe:1;
262         ushort line;
263         ushort column;
264     };
265     struct instr_fetch {
266         QML_INSTR_HEADER
267         int property;
268         ushort line;
269     };
270     struct instr_fetchValue {
271         QML_INSTR_HEADER
272         int property;
273         int type;
274         quint32 bindingSkipList;
275     };
276     struct instr_fetchQmlList {
277         QML_INSTR_HEADER
278         int property;
279         int type;
280     };
281     struct instr_begin {
282         QML_INSTR_HEADER
283         int castValue;
284     }; 
285     struct instr_storeFloat {
286         QML_INSTR_HEADER
287         int propertyIndex;
288         float value;
289     };
290     struct instr_storeDouble {
291         QML_INSTR_HEADER
292         int propertyIndex;
293         double value;
294     };
295     struct instr_storeInteger {
296         QML_INSTR_HEADER
297         int propertyIndex;
298         int value;
299     };
300     struct instr_storeBool {
301         QML_INSTR_HEADER
302         int propertyIndex;
303         bool value;
304     };
305     struct instr_storeString {
306         QML_INSTR_HEADER
307         int propertyIndex;
308         int value;
309     };
310     struct instr_storeTrString {
311         QML_INSTR_HEADER
312         int propertyIndex;
313         int context;
314         int text;
315         int comment;
316         int n;
317     };
318     struct instr_storeTrIdString {
319         QML_INSTR_HEADER
320         int propertyIndex;
321         int text;
322         int n;
323     };
324     struct instr_storeByteArray {
325         QML_INSTR_HEADER
326         int propertyIndex;
327         int value;
328     };
329     struct instr_storeScriptString {
330         QML_INSTR_HEADER
331         int propertyIndex;
332         int value;
333         int scope;
334         int bindingId;
335         ushort line;
336         ushort column;
337         double numberValue;
338         bool isStringLiteral:1;
339         bool isNumberLiteral:1;
340     }; 
341     struct instr_storeScript {
342         QML_INSTR_HEADER
343         int value;
344     };
345     struct instr_storeUrl {
346         QML_INSTR_HEADER
347         int propertyIndex;
348         int value;
349     };
350     struct instr_storeColor {
351         QML_INSTR_HEADER
352         int propertyIndex;
353         unsigned int value;
354     };
355     struct instr_storeDate {
356         QML_INSTR_HEADER
357         int propertyIndex;
358         int value;
359     };
360     struct instr_storeTime {
361         QML_INSTR_HEADER
362         int propertyIndex;
363         struct QTime {
364             int mds;
365 #if defined(Q_OS_WINCE)
366             int startTick;
367 #endif
368         } time;
369     };
370     struct instr_storeDateTime {
371         QML_INSTR_HEADER
372         int propertyIndex;
373         int date;
374         instr_storeTime::QTime time;
375     };
376     struct instr_storeRect {
377         QML_INSTR_HEADER
378         int propertyIndex;
379         struct QRect {
380             int x1;
381             int y1;
382             int x2;
383             int y2;
384         } rect;
385     };
386     struct instr_storeRectF {
387         QML_INSTR_HEADER
388         int propertyIndex;
389         struct QRectF {
390             qreal xp;
391             qreal yp;
392             qreal w;
393             qreal h;
394         } rect;
395     };
396     struct instr_storeObject {
397         QML_INSTR_HEADER
398         int propertyIndex;
399         ushort line;
400     };
401     struct instr_assignCustomType {
402         QML_INSTR_HEADER
403         int propertyIndex;
404         int primitive;
405         int type;
406         ushort line;
407     };
408     struct instr_storeSignal {
409         QML_INSTR_HEADER
410         int signalIndex;
411         int value;
412         int parameterCount;
413         short context;
414         ushort line;
415         ushort column;
416     };
417     struct instr_assignSignalObject {
418         QML_INSTR_HEADER
419         int signal;
420         ushort line; 
421     };
422     struct instr_createComponent {
423         QML_INSTR_HEADER
424         int count;
425         int endLine;
426         int metaObject;
427         ushort column;
428         ushort line;
429         bool isRoot;
430     };
431     struct instr_fetchAttached {
432         QML_INSTR_HEADER
433         int id;
434         ushort line;
435     };
436     struct instr_defer {
437         QML_INSTR_HEADER
438         int deferCount;
439     };
440     struct instr_assignObjectList {
441         QML_INSTR_HEADER
442         ushort line;
443     };
444     struct instr_storePoint {
445         QML_INSTR_HEADER
446         int propertyIndex;
447         struct QPoint {
448             int xp;
449             int yp;
450         } point;
451     };
452     struct instr_storePointF {
453         QML_INSTR_HEADER
454         int propertyIndex;
455         struct QPointF {
456             qreal xp;
457             qreal yp;
458         } point;
459     };
460     struct instr_storeSize {
461         QML_INSTR_HEADER
462         int propertyIndex;
463         struct QSize {
464             int wd;
465             int ht;
466         } size;
467     };
468     struct instr_storeSizeF {
469         QML_INSTR_HEADER
470         int propertyIndex;
471         struct QSizeF {
472             qreal wd;
473             qreal ht;
474         } size;
475     };
476     struct instr_storeVector3D {
477         QML_INSTR_HEADER
478         int propertyIndex;
479         struct QVector3D {
480             float xp;
481             float yp;
482             float zp;
483         } vector;
484     };
485     struct instr_storeVector4D {
486         QML_INSTR_HEADER
487         int propertyIndex;
488         struct QVector4D {
489             float xp;
490             float yp;
491             float zp;
492             float wp;
493         } vector;
494     };
495
496     instr_common common;
497     instr_init init;
498     instr_deferInit deferInit;
499     instr_create create;
500     instr_createQml createQml;
501     instr_completeQml completeQml;
502     instr_createSimple createSimple;
503     instr_storeMeta storeMeta;
504     instr_setId setId;
505     instr_assignValueSource assignValueSource;
506     instr_assignValueInterceptor assignValueInterceptor;
507     instr_initV8Bindings initV8Bindings;
508     instr_assignV4Binding assignV4Binding;
509     instr_assignBinding assignBinding;
510     instr_fetch fetch;
511     instr_fetchValue fetchValue;
512     instr_fetchQmlList fetchQmlList;
513     instr_begin begin;
514     instr_storeFloat storeFloat;
515     instr_storeDouble storeDouble;
516     instr_storeInteger storeInteger;
517     instr_storeBool storeBool;
518     instr_storeString storeString;
519     instr_storeTrString storeTrString;
520     instr_storeTrIdString storeTrIdString;
521     instr_storeByteArray storeByteArray;
522     instr_storeScriptString storeScriptString;
523     instr_storeScript storeScript;
524     instr_storeUrl storeUrl;
525     instr_storeColor storeColor;
526     instr_storeDate storeDate;
527     instr_storeTime storeTime;
528     instr_storeDateTime storeDateTime;
529     instr_storePoint storePoint;
530     instr_storePointF storePointF;
531     instr_storeSize storeSize;
532     instr_storeSizeF storeSizeF;
533     instr_storeRect storeRect;
534     instr_storeRectF storeRectF;
535     instr_storeVector3D storeVector3D;
536     instr_storeVector4D storeVector4D;
537     instr_storeObject storeObject;
538     instr_assignCustomType assignCustomType;
539     instr_storeSignal storeSignal;
540     instr_assignSignalObject assignSignalObject;
541     instr_createComponent createComponent;
542     instr_fetchAttached fetchAttached;
543     instr_defer defer;
544     instr_assignObjectList assignObjectList;
545
546     static int size(Type type);
547 };
548
549 template<int N>
550 struct QQmlInstructionMeta {
551 };
552
553 #define QML_INSTR_META_TEMPLATE(I, FMT) \
554     template<> struct QQmlInstructionMeta<(int)QQmlInstruction::I> { \
555         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
556         typedef QQmlInstruction::instr_##FMT DataType; \
557         static const DataType &data(const QQmlInstruction &instr) { return instr.FMT; } \
558         static void setData(QQmlInstruction &instr, const DataType &v) { instr.FMT = v; } \
559     }; 
560 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
561 #undef QML_INSTR_META_TEMPLATE
562
563 template<int Instr>
564 class QQmlInstructionData : public QQmlInstructionMeta<Instr>::DataType
565 {
566 };
567
568 QT_END_NAMESPACE
569
570 #endif // QQMLINSTRUCTION_P_H