Extract all QtQuick 1 elements into a separate library/plugin.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / v4 / qdeclarativev4compiler_p_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 QDECLARATIVEV4COMPILER_P_P_H
43 #define QDECLARATIVEV4COMPILER_P_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 "qdeclarativev4instruction_p.h"
57 #include "qdeclarativev4ir_p.h"
58 #include <private/qdeclarativeparser_p.h>
59 #include <private/qdeclarativeimport_p.h>
60 #include <private/qdeclarativeengine_p.h>
61
62 QT_BEGIN_HEADER
63
64 QT_BEGIN_NAMESPACE
65
66 // NOTE: This is a copy of QDeclarative1AnchorLine: src/qtquick1/graphicsitems/qdeclarativeanchors_p_p.h
67 class QGraphicsObject;
68 class QDeclarative1AnchorLine
69 {
70 public:
71     QDeclarative1AnchorLine() : item(0), anchorLine(Invalid) {}
72
73     enum AnchorLine {
74         Invalid = 0x0,
75         Left = 0x01,
76         Right = 0x02,
77         Top = 0x04,
78         Bottom = 0x08,
79         HCenter = 0x10,
80         VCenter = 0x20,
81         Baseline = 0x40,
82         Horizontal_Mask = Left | Right | HCenter,
83         Vertical_Mask = Top | Bottom | VCenter | Baseline
84     };
85
86     QGraphicsObject *item;
87     AnchorLine anchorLine;
88 };
89
90 inline bool operator==(const QDeclarative1AnchorLine& a, const QDeclarative1AnchorLine& b)
91 {
92     return a.item == b.item && a.anchorLine == b.anchorLine;
93 }
94
95
96 class QDeclarativeV4CompilerPrivate: protected QDeclarativeJS::IR::ExprVisitor, 
97                                      protected QDeclarativeJS::IR::StmtVisitor
98 {
99 public:
100     QDeclarativeV4CompilerPrivate();
101
102     void resetInstanceState();
103     int commitCompile();
104
105     const QDeclarativeV4Compiler::Expression *expression;
106     QDeclarativeEnginePrivate *engine;
107
108     QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((quintptr)expression->context, 16); }
109
110     bool compile(QDeclarativeJS::AST::Node *);
111
112     QHash<int, QPair<int, int> > registerCleanups;
113
114     int registerLiteralString(quint8 reg, const QString &);
115     int registerString(const QString &);
116     QHash<QString, QPair<int, int> > registeredStrings;
117     QByteArray data;
118
119     bool blockNeedsSubscription(const QStringList &);
120     int subscriptionIndex(const QStringList &);
121     quint32 subscriptionBlockMask(const QStringList &);
122
123     quint8 exceptionId(quint32 line, quint32 column);
124     quint8 exceptionId(QDeclarativeJS::AST::ExpressionNode *);
125     QVector<quint64> exceptions;
126
127     QHash<int, quint32> usedSubscriptionIds;
128
129     QHash<QString, int> subscriptionIds;
130     QDeclarativeJS::Bytecode bytecode;
131
132     // back patching
133     struct Patch {
134         QDeclarativeJS::IR::BasicBlock *block; // the basic block
135         int offset; // the index of the instruction to patch
136         Patch(QDeclarativeJS::IR::BasicBlock *block = 0, int index = -1)
137             : block(block), offset(index) {}
138     };
139     QVector<Patch> patches;
140
141     // Committed binding data
142     struct {
143         QList<int> offsets;
144         QList<QHash<int, quint32> > dependencies;
145
146         //QDeclarativeJS::Bytecode bytecode;
147         QByteArray bytecode;
148         QByteArray data;
149         QHash<QString, int> subscriptionIds;
150         QVector<quint64> exceptions;
151
152         QHash<QString, QPair<int, int> > registeredStrings;
153
154         int count() const { return offsets.count(); }
155     } committed;
156
157     QByteArray buildSignalTable() const;
158     QByteArray buildExceptionData() const;
159
160     void convertToReal(QDeclarativeJS::IR::Expr *expr, int reg);    
161     void convertToInt(QDeclarativeJS::IR::Expr *expr, int reg);
162     void convertToBool(QDeclarativeJS::IR::Expr *expr, int reg);
163     quint8 instructionOpcode(QDeclarativeJS::IR::Binop *e);
164
165 protected:
166
167     //
168     // tracing
169     //
170     void trace(int line, int column);
171     void trace(QVector<QDeclarativeJS::IR::BasicBlock *> *blocks);
172     void traceExpression(QDeclarativeJS::IR::Expr *e, quint8 r);
173
174     inline void gen(const QDeclarativeJS::Instr &i) { bytecode.append(i); }
175
176     //
177     // expressions
178     //
179     virtual void visitConst(QDeclarativeJS::IR::Const *e);
180     virtual void visitString(QDeclarativeJS::IR::String *e);
181     virtual void visitName(QDeclarativeJS::IR::Name *e);
182     virtual void visitTemp(QDeclarativeJS::IR::Temp *e);
183     virtual void visitUnop(QDeclarativeJS::IR::Unop *e);
184     virtual void visitBinop(QDeclarativeJS::IR::Binop *e);
185     virtual void visitCall(QDeclarativeJS::IR::Call *e);
186
187     //
188     // statements
189     //
190     virtual void visitExp(QDeclarativeJS::IR::Exp *s);
191     virtual void visitMove(QDeclarativeJS::IR::Move *s);
192     virtual void visitJump(QDeclarativeJS::IR::Jump *s);
193     virtual void visitCJump(QDeclarativeJS::IR::CJump *s);
194     virtual void visitRet(QDeclarativeJS::IR::Ret *s);
195
196 private:
197     QStringList _subscribeName;
198     QDeclarativeJS::IR::Function *_function;
199     QDeclarativeJS::IR::BasicBlock *_block;
200     void discard() { _discarded = true; }
201     bool _discarded;
202     quint8 currentReg;
203
204     bool usedSubscriptionIdsChanged;
205     quint32 currentBlockMask;
206 };
207
208
209 QT_END_NAMESPACE
210
211 Q_DECLARE_METATYPE(QDeclarative1AnchorLine)
212
213 QT_END_HEADER
214
215 #endif // QDECLARATIVEV4COMPILER_P_P_H
216