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