Support variable length instructions in QML bytecode
[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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
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, storeRealPair) \
85     F(StorePointF, storeRealPair) \
86     F(StoreSize, storeRealPair) \
87     F(StoreSizeF, storeRealPair) \
88     F(StoreRect, storeRect) \
89     F(StoreRectF, storeRect) \
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(StoreBinding, assignBinding) \
99     F(StoreBindingOnAlias, assignBinding) \
100     F(StoreCompiledBinding, assignBinding) \
101     F(StoreValueSource, assignValueSource) \
102     F(StoreValueInterceptor, assignValueInterceptor) \
103     F(StoreObjectQList, common) \
104     F(AssignObjectList, assignObjectList) \
105     F(StoreVariantObject, storeObject) \
106     F(StoreInterface, storeObject) \
107     F(FetchAttached, fetchAttached) \
108     F(FetchQList, fetchQmlList) \
109     F(FetchObject, fetch) \
110     F(PopQList, common) \
111     F(Defer, defer) \
112     F(PopFetchedObject, common) \
113     F(FetchValueType, fetchValue) \
114     F(PopValueType, fetchValue) 
115
116 #ifdef Q_ALIGNOF
117 #  define QML_INSTR_ALIGN_MASK (Q_ALIGNOF(QDeclarativeInstruction) - 1)
118 #else
119 #  define QML_INSTR_ALIGN_MASK (sizeof(void *) - 1)
120 #endif
121
122 #define QML_INSTR_HEADER quint8 instructionType;
123 #define QML_INSTR_ENUM(I, FMT)  I,
124 #define QML_INSTR_SIZE(I, FMT) ((sizeof(QDeclarativeInstruction::instr_##FMT) + QML_INSTR_ALIGN_MASK) & ~QML_INSTR_ALIGN_MASK)
125
126 class QDeclarativeCompiledData;
127 union QDeclarativeInstruction
128 {
129     enum Type { 
130         FOR_EACH_QML_INSTR(QML_INSTR_ENUM)
131     };
132
133     inline void setType(Type type) { common.instructionType = type; }
134     inline Type type() const { return (Type)common.instructionType; }
135
136     struct instr_common {
137         QML_INSTR_HEADER
138     };
139     struct instr_init {
140         QML_INSTR_HEADER
141         int bindingsSize;
142         int parserStatusSize;
143         int contextCache;
144         int compiledBinding;
145     };
146     struct instr_create {
147         QML_INSTR_HEADER
148         int type;
149         int data;
150         int bindingBits;
151         ushort column;
152         ushort line; 
153     };
154     struct instr_createSimple {
155         QML_INSTR_HEADER
156         void (*create)(void *);
157         int typeSize;
158         int type;
159         ushort column;
160         ushort line; 
161     };
162     struct instr_storeMeta {
163         QML_INSTR_HEADER
164         int data;
165         int aliasData;
166         int propertyCache;
167     };
168     struct instr_setId {
169         QML_INSTR_HEADER
170         int value;
171         int index;
172     };
173     struct instr_assignValueSource {
174         QML_INSTR_HEADER
175         int property;
176         int owner;
177         int castValue;
178     };
179     struct instr_assignValueInterceptor {
180         QML_INSTR_HEADER
181         int property;
182         int owner;
183         int castValue;
184     };
185     struct instr_assignBinding {
186         QML_INSTR_HEADER
187         unsigned int property;
188         int value;
189         short context;
190         short owner;
191         ushort line;
192     };
193     struct instr_fetch {
194         QML_INSTR_HEADER
195         int property;
196         ushort line;
197     };
198     struct instr_fetchValue {
199         QML_INSTR_HEADER
200         int property;
201         int type;
202         quint32 bindingSkipList;
203     };
204     struct instr_fetchQmlList {
205         QML_INSTR_HEADER
206         int property;
207         int type;
208     };
209     struct instr_begin {
210         QML_INSTR_HEADER
211         int castValue;
212     }; 
213     struct instr_storeFloat {
214         QML_INSTR_HEADER
215         int propertyIndex;
216         float value;
217     };
218     struct instr_storeDouble {
219         QML_INSTR_HEADER
220         int propertyIndex;
221         double value;
222     };
223     struct instr_storeInteger {
224         QML_INSTR_HEADER
225         int propertyIndex;
226         int value;
227     };
228     struct instr_storeBool {
229         QML_INSTR_HEADER
230         int propertyIndex;
231         bool value;
232     };
233     struct instr_storeString {
234         QML_INSTR_HEADER
235         int propertyIndex;
236         int value;
237     };
238     struct instr_storeByteArray {
239         QML_INSTR_HEADER
240         int propertyIndex;
241         int value;
242     };
243     struct instr_storeScriptString {
244         QML_INSTR_HEADER
245         int propertyIndex;
246         int value;
247         int scope;
248     }; 
249     struct instr_storeScript {
250         QML_INSTR_HEADER
251         int value;
252     };
253     struct instr_storeUrl {
254         QML_INSTR_HEADER
255         int propertyIndex;
256         int value;
257     };
258     struct instr_storeColor {
259         QML_INSTR_HEADER
260         int propertyIndex;
261         unsigned int value;
262     };
263     struct instr_storeDate {
264         QML_INSTR_HEADER
265         int propertyIndex;
266         int value;
267     };
268     struct instr_storeTime {
269         QML_INSTR_HEADER
270         int propertyIndex;
271         int valueIndex;
272     };
273     struct instr_storeDateTime {
274         QML_INSTR_HEADER
275         int propertyIndex;
276         int valueIndex;
277     };
278     struct instr_storeRealPair {
279         QML_INSTR_HEADER
280         int propertyIndex;
281         int valueIndex;
282     };
283     struct instr_storeRect {
284         QML_INSTR_HEADER
285         int propertyIndex;
286         int valueIndex;
287     };
288     struct instr_storeVector3D {
289         QML_INSTR_HEADER
290         int propertyIndex;
291         int valueIndex;
292     };
293     struct instr_storeObject {
294         QML_INSTR_HEADER
295         int propertyIndex;
296         ushort line;
297     };
298     struct instr_assignCustomType {
299         QML_INSTR_HEADER
300         int propertyIndex;
301         int valueIndex;
302         ushort line;
303     };
304     struct instr_storeSignal {
305         QML_INSTR_HEADER
306         int signalIndex;
307         int value;
308         short context;
309         int name;
310         ushort line;
311     };
312     struct instr_assignSignalObject {
313         QML_INSTR_HEADER
314         int signal;
315         ushort line; 
316     };
317     struct instr_createComponent {
318         QML_INSTR_HEADER
319         int count;
320         int endLine;
321         int metaObject;
322         ushort column;
323         ushort line;
324     };
325     struct instr_fetchAttached {
326         QML_INSTR_HEADER
327         int id;
328         ushort line;
329     };
330     struct instr_defer {
331         QML_INSTR_HEADER
332         int deferCount;
333     };
334     struct instr_assignObjectList {
335         QML_INSTR_HEADER
336         ushort line;
337     };
338
339     instr_common common;
340     instr_init init;
341     instr_create create;
342     instr_createSimple createSimple;
343     instr_storeMeta storeMeta;
344     instr_setId setId;
345     instr_assignValueSource assignValueSource;
346     instr_assignValueInterceptor assignValueInterceptor;
347     instr_assignBinding assignBinding;
348     instr_fetch fetch;
349     instr_fetchValue fetchValue;
350     instr_fetchQmlList fetchQmlList;
351     instr_begin begin;
352     instr_storeFloat storeFloat;
353     instr_storeDouble storeDouble;
354     instr_storeInteger storeInteger;
355     instr_storeBool storeBool;
356     instr_storeString storeString;
357     instr_storeByteArray storeByteArray;
358     instr_storeScriptString storeScriptString;
359     instr_storeScript storeScript;
360     instr_storeUrl storeUrl;
361     instr_storeColor storeColor;
362     instr_storeDate storeDate;
363     instr_storeTime storeTime;
364     instr_storeDateTime storeDateTime;
365     instr_storeRealPair storeRealPair;
366     instr_storeRect storeRect;
367     instr_storeVector3D storeVector3D;
368     instr_storeObject storeObject;
369     instr_assignCustomType assignCustomType;
370     instr_storeSignal storeSignal;
371     instr_assignSignalObject assignSignalObject;
372     instr_createComponent createComponent;
373     instr_fetchAttached fetchAttached;
374     instr_defer defer;
375     instr_assignObjectList assignObjectList;
376
377     int size() const;
378 };
379
380 template<int N>
381 struct QDeclarativeInstructionMeta {
382 };
383
384 #define QML_INSTR_META_TEMPLATE(I, FMT) \
385     template<> struct QDeclarativeInstructionMeta<(int)QDeclarativeInstruction::I> { \
386         enum { Size = QML_INSTR_SIZE(I, FMT) }; \
387         typedef QDeclarativeInstruction::instr_##FMT DataType; \
388         static const DataType &data(const QDeclarativeInstruction &instr) { return instr.FMT; } \
389     }; 
390 FOR_EACH_QML_INSTR(QML_INSTR_META_TEMPLATE);
391 #undef QML_INSTR_META_TEMPLATE
392
393 QT_END_NAMESPACE
394
395 #endif // QDECLARATIVEINSTRUCTION_P_H