1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEV4COMPILER_P_P_H
43 #define QDECLARATIVEV4COMPILER_P_P_H
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.
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>
66 // NOTE: This is a copy of QDeclarative1AnchorLine: src/qtquick1/graphicsitems/qdeclarativeanchors_p_p.h
67 class QGraphicsObject;
68 class QDeclarative1AnchorLine
71 QDeclarative1AnchorLine() : item(0), anchorLine(Invalid) {}
82 Horizontal_Mask = Left | Right | HCenter,
83 Vertical_Mask = Top | Bottom | VCenter | Baseline
86 QGraphicsObject *item;
87 AnchorLine anchorLine;
90 inline bool operator==(const QDeclarative1AnchorLine& a, const QDeclarative1AnchorLine& b)
92 return a.item == b.item && a.anchorLine == b.anchorLine;
96 class QDeclarativeV4CompilerPrivate: protected QDeclarativeJS::IR::ExprVisitor,
97 protected QDeclarativeJS::IR::StmtVisitor
100 QDeclarativeV4CompilerPrivate();
102 void resetInstanceState();
105 const QDeclarativeV4Compiler::Expression *expression;
106 QDeclarativeEnginePrivate *engine;
108 QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((quintptr)expression->context, 16); }
110 bool compile(QDeclarativeJS::AST::Node *);
112 QHash<int, QPair<int, int> > registerCleanups;
114 int registerLiteralString(quint8 reg, const QString &);
115 int registerString(const QString &);
116 QHash<QString, QPair<int, int> > registeredStrings;
119 bool blockNeedsSubscription(const QStringList &);
120 int subscriptionIndex(const QStringList &);
121 quint32 subscriptionBlockMask(const QStringList &);
123 quint8 exceptionId(quint32 line, quint32 column);
124 quint8 exceptionId(QDeclarativeJS::AST::ExpressionNode *);
125 QVector<quint64> exceptions;
127 QHash<int, quint32> usedSubscriptionIds;
129 QHash<QString, int> subscriptionIds;
130 QDeclarativeJS::Bytecode bytecode;
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) {}
139 QVector<Patch> patches;
141 // Committed binding data
144 QList<QHash<int, quint32> > dependencies;
146 //QDeclarativeJS::Bytecode bytecode;
149 QHash<QString, int> subscriptionIds;
150 QVector<quint64> exceptions;
152 QHash<QString, QPair<int, int> > registeredStrings;
154 int count() const { return offsets.count(); }
157 QByteArray buildSignalTable() const;
158 QByteArray buildExceptionData() const;
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);
170 void trace(int line, int column);
171 void trace(QVector<QDeclarativeJS::IR::BasicBlock *> *blocks);
172 void traceExpression(QDeclarativeJS::IR::Expr *e, quint8 r);
174 inline void gen(const QDeclarativeJS::Instr &i) { bytecode.append(i); }
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);
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);
197 QStringList _subscribeName;
198 QDeclarativeJS::IR::Function *_function;
199 QDeclarativeJS::IR::BasicBlock *_block;
200 void discard() { _discarded = true; }
204 bool usedSubscriptionIdsChanged;
205 quint32 currentBlockMask;
211 Q_DECLARE_METATYPE(QDeclarative1AnchorLine)
215 #endif // QDECLARATIVEV4COMPILER_P_P_H