Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v4 / qv4instruction_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 QtDeclarative 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 QV4INSTRUCTION_P_H
43 #define QV4INSTRUCTION_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 <QtCore/qbytearray.h>
58 #include <QtCore/qvector.h>
59 #include <QtCore/qvarlengtharray.h>
60
61 #include <private/qdeclarativepropertycache_p.h>
62
63 QT_BEGIN_HEADER
64
65 QT_BEGIN_NAMESPACE
66
67 #define FOR_EACH_V4_INSTR(F) \
68     F(Noop, common) \
69     F(BindingId, id) \
70     F(Subscribe, subscribeop) \
71     F(SubscribeId, subscribeop) \
72     F(FetchAndSubscribe, fetchAndSubscribe) \
73     F(LoadId, load) \
74     F(LoadScope, load) \
75     F(LoadRoot, load) \
76     F(LoadAttached, attached) \
77     F(UnaryNot, unaryop) \
78     F(UnaryMinusReal, unaryop) \
79     F(UnaryMinusInt, unaryop) \
80     F(UnaryPlusReal, unaryop) \
81     F(UnaryPlusInt, unaryop) \
82     F(ConvertBoolToInt, unaryop) \
83     F(ConvertBoolToReal, unaryop) \
84     F(ConvertBoolToString, unaryop) \
85     F(ConvertIntToBool, unaryop) \
86     F(ConvertIntToReal, unaryop) \
87     F(ConvertIntToString, unaryop) \
88     F(ConvertRealToBool, unaryop) \
89     F(ConvertRealToInt, unaryop) \
90     F(ConvertRealToString, unaryop) \
91     F(ConvertStringToBool, unaryop) \
92     F(ConvertStringToInt, unaryop) \
93     F(ConvertStringToReal, unaryop) \
94     F(ConvertStringToUrl, unaryop) \
95     F(ConvertUrlToBool, unaryop) \
96     F(ConvertUrlToString, unaryop) \
97     F(ResolveUrl, unaryop) \
98     F(MathSinReal, unaryop) \
99     F(MathCosReal, unaryop) \
100     F(MathRoundReal, unaryop) \
101     F(MathFloorReal, unaryop) \
102     F(MathPIReal, unaryop) \
103     F(LoadReal, real_value) \
104     F(LoadInt, int_value) \
105     F(LoadBool, bool_value) \
106     F(LoadString, string_value) \
107     F(EnableV4Test, string_value) \
108     F(TestV4Store, storetest) \
109     F(BitAndInt, binaryop) \
110     F(BitOrInt, binaryop) \
111     F(BitXorInt, binaryop) \
112     F(AddReal, binaryop) \
113     F(AddString, binaryop) \
114     F(SubReal, binaryop) \
115     F(MulReal, binaryop) \
116     F(DivReal, binaryop) \
117     F(ModReal, binaryop) \
118     F(LShiftInt, binaryop) \
119     F(RShiftInt, binaryop) \
120     F(URShiftInt, binaryop) \
121     F(GtReal, binaryop) \
122     F(LtReal, binaryop) \
123     F(GeReal, binaryop) \
124     F(LeReal, binaryop) \
125     F(EqualReal, binaryop) \
126     F(NotEqualReal, binaryop) \
127     F(StrictEqualReal, binaryop) \
128     F(StrictNotEqualReal, binaryop) \
129     F(GtString, binaryop) \
130     F(LtString, binaryop) \
131     F(GeString, binaryop) \
132     F(LeString, binaryop) \
133     F(EqualString, binaryop) \
134     F(NotEqualString, binaryop) \
135     F(StrictEqualString, binaryop) \
136     F(StrictNotEqualString, binaryop) \
137     F(NewString, construct) \
138     F(NewUrl, construct) \
139     F(CleanupRegister, cleanup) \
140     F(Copy, copy) \
141     F(Fetch, fetch) \
142     F(Store, store) \
143     F(Jump, jump) \
144     F(BranchTrue, branchop) \
145     F(BranchFalse, branchop) \
146     F(Branch, branchop) \
147     F(Block, blockop) \
148     /* Speculative property resolution */ \
149     F(InitString, initstring)
150
151 #if defined(Q_CC_GNU) && (!defined(Q_CC_INTEL) || __INTEL_COMPILER >= 1200)
152 #  define QML_THREADED_INTERPRETER
153 #endif
154
155 #ifdef Q_ALIGNOF
156 #  define QML_V4_INSTR_ALIGN_MASK (Q_ALIGNOF(V4Instr) - 1)
157 #else
158 #  define QML_V4_INSTR_ALIGN_MASK (sizeof(void *) - 1)
159 #endif
160
161 #define QML_V4_INSTR_ENUM(I, FMT) I,
162 #define QML_V4_INSTR_ADDR(I, FMT) &&op_##I,
163 #define QML_V4_INSTR_SIZE(I, FMT) ((sizeof(V4Instr::instr_##FMT) + QML_V4_INSTR_ALIGN_MASK) & ~QML_V4_INSTR_ALIGN_MASK)
164
165 #ifdef QML_THREADED_INTERPRETER
166 #  define QML_V4_BEGIN_INSTR(I,FMT) op_##I:
167 #  define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; goto *instr->common.code;
168 #  define QML_V4_INSTR_HEADER void *code;
169 #else
170 #  define QML_V4_BEGIN_INSTR(I,FMT) case V4Instr::I:
171 #  define QML_V4_END_INSTR(I,FMT) code += QML_V4_INSTR_SIZE(I, FMT); instr = (const V4Instr *) code; break;
172 #  define QML_V4_INSTR_HEADER quint8 type;
173 #endif
174
175 class QObject;
176 class QDeclarativeNotifier;
177
178 namespace QDeclarativeJS {
179
180 union V4Instr {
181     enum Type {
182         FOR_EACH_V4_INSTR(QML_V4_INSTR_ENUM)
183     };
184
185     static int size(Type type);
186
187     struct instr_common {
188         QML_V4_INSTR_HEADER
189     };
190
191     struct instr_id {
192         QML_V4_INSTR_HEADER
193         quint16 column;
194         quint32 line;
195     };
196
197     struct instr_init {
198         QML_V4_INSTR_HEADER
199         quint16 subscriptions;
200         quint16 identifiers;
201     };
202
203     struct instr_subscribeop {
204         QML_V4_INSTR_HEADER
205         qint8 reg;
206         quint16 offset;
207         quint32 index;
208     };
209
210     struct instr_load {
211         QML_V4_INSTR_HEADER
212         qint8 reg;
213         quint32 index;
214     };
215
216     struct instr_attached {
217         QML_V4_INSTR_HEADER
218         qint8 output;
219         qint8 reg;
220         quint8 exceptionId;
221         quint32 id;
222     };
223
224     struct instr_store {
225         QML_V4_INSTR_HEADER
226         qint8 output;
227         qint8 reg;
228         quint8 exceptionId;
229         quint32 index;
230     };
231
232     struct instr_storetest {
233         QML_V4_INSTR_HEADER
234         qint8 reg;
235         qint32 regType;
236     };
237
238     struct instr_fetchAndSubscribe {
239         QML_V4_INSTR_HEADER
240         qint8 reg;
241         quint8 exceptionId;
242         quint8 valueType;
243         quint16 subscription;
244         QDeclarativePropertyRawData property;
245     };
246
247     struct instr_fetch{
248         QML_V4_INSTR_HEADER
249         qint8 reg;
250         quint8 exceptionId;
251         quint8 valueType;
252         quint32 index;
253     };
254
255     struct instr_copy {
256         QML_V4_INSTR_HEADER
257         qint8 reg;
258         qint8 src;
259     };
260
261     struct instr_construct {
262         QML_V4_INSTR_HEADER
263         qint8 reg;
264     };
265
266     struct instr_real_value {
267         QML_V4_INSTR_HEADER
268         qint8 reg;
269         qreal value; // XXX Makes the instruction 12 bytes
270     };
271
272     struct instr_int_value {
273         QML_V4_INSTR_HEADER
274         qint8 reg;
275         int value;
276     };
277
278     struct instr_bool_value {
279         QML_V4_INSTR_HEADER
280         qint8 reg;
281         bool value;
282     };
283
284     struct instr_string_value {
285         QML_V4_INSTR_HEADER
286         qint8 reg;
287         quint16 length;
288         quint32 offset;
289     };
290
291     struct instr_binaryop {
292         QML_V4_INSTR_HEADER
293         qint8 output;
294         qint8 left;
295         qint8 right;
296     };
297
298     struct instr_unaryop {
299         QML_V4_INSTR_HEADER
300         qint8 output;
301         qint8 src;
302     };
303
304     struct instr_jump {
305         QML_V4_INSTR_HEADER
306         qint8 reg;
307         quint32 count;
308     };
309
310     struct instr_find {
311         QML_V4_INSTR_HEADER
312         qint8 reg;
313         qint8 src;
314         quint8 exceptionId;
315         quint16 name;
316         quint16 subscribeIndex;
317     };
318
319     struct instr_cleanup {
320         QML_V4_INSTR_HEADER
321         qint8 reg;
322     };
323
324     struct instr_initstring {
325         QML_V4_INSTR_HEADER
326         quint16 offset;
327         quint32 dataIdx;
328     };
329
330     struct instr_branchop {
331         QML_V4_INSTR_HEADER
332         quint8 reg;
333         qint16 offset;
334     };
335
336     struct instr_blockop {
337         QML_V4_INSTR_HEADER
338         quint32 block;
339     };
340
341     instr_common common;
342     instr_id id;
343     instr_init init;
344     instr_subscribeop subscribeop;
345     instr_load load;
346     instr_attached attached;
347     instr_store store;
348     instr_storetest storetest;
349     instr_fetchAndSubscribe fetchAndSubscribe;
350     instr_fetch fetch;
351     instr_copy copy;
352     instr_construct construct;
353     instr_real_value real_value;
354     instr_int_value int_value;
355     instr_bool_value bool_value;
356     instr_string_value string_value;
357     instr_binaryop binaryop;
358     instr_unaryop unaryop;
359     instr_jump jump;
360     instr_find find;
361     instr_cleanup cleanup;
362     instr_initstring initstring;
363     instr_branchop branchop;
364     instr_blockop blockop;
365 };
366
367 template<int N>
368 struct V4InstrMeta {
369 };
370
371 #define QML_V4_INSTR_META_TEMPLATE(I, FMT) \
372     template<> struct V4InstrMeta<(int)V4Instr::I> { \
373         enum { Size = QML_V4_INSTR_SIZE(I, FMT) }; \
374         typedef V4Instr::instr_##FMT DataType; \
375         static const DataType &data(const V4Instr &instr) { return instr.FMT; } \
376         static void setData(V4Instr &instr, const DataType &v) { instr.FMT = v; } \
377     };
378 FOR_EACH_V4_INSTR(QML_V4_INSTR_META_TEMPLATE);
379 #undef QML_V4_INSTR_META_TEMPLATE
380
381 template<int Instr>
382 class V4InstrData : public V4InstrMeta<Instr>::DataType
383 {
384 };
385
386 class Bytecode
387 {
388     Q_DISABLE_COPY(Bytecode)
389
390 public:
391     Bytecode();
392
393     const char *constData() const { return d.constData(); }
394     int size() const { return d.size(); }
395     int count() const { return d.count(); }
396     void clear() { d.clear(); }
397     bool isEmpty() const { return d.isEmpty(); }
398     V4Instr::Type instructionType(const V4Instr *instr) const;
399
400     template <int Instr>
401     void append(const V4InstrData<Instr> &data)
402     {
403         V4Instr genericInstr;
404         V4InstrMeta<Instr>::setData(genericInstr, data);
405         return append(static_cast<V4Instr::Type>(Instr), genericInstr);
406     }
407     void append(V4Instr::Type type, V4Instr &instr);
408
409     int remove(int index);
410
411     const V4Instr &operator[](int offset) const;
412     V4Instr &operator[](int offset);
413
414     void dump(const char *start, const char *end) const;
415
416 private:
417     void dump(const V4Instr *instr, int = -1) const;
418
419     QVarLengthArray<char, 4 * 1024> d;
420 #ifdef QML_THREADED_INTERPRETER
421     void **decodeInstr;
422 #endif
423 };
424
425 }
426
427 QT_END_NAMESPACE
428
429 QT_END_HEADER
430
431 #endif // QV4INSTRUCTION_P_H
432