Qt 4.8
qdeclarativecompiler_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QDECLARATIVECOMPILER_P_H
43 #define QDECLARATIVECOMPILER_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 "qdeclarative.h"
57 #include "qdeclarativeerror.h"
58 #include "private/qdeclarativeinstruction_p.h"
59 #include "private/qdeclarativeparser_p.h"
60 #include "private/qdeclarativeengine_p.h"
61 #include "private/qbitfield_p.h"
62 #include "private/qdeclarativepropertycache_p.h"
63 #include "private/qdeclarativeintegercache_p.h"
64 #include "private/qdeclarativetypenamecache_p.h"
65 #include "private/qdeclarativetypeloader_p.h"
66 
67 #include <QtCore/qbytearray.h>
68 #include <QtCore/qset.h>
69 #include <QtCore/QCoreApplication>
70 
72 
73 class QDeclarativeEngine;
77 
78 class QScriptProgram;
80 {
81 public:
83  virtual ~QDeclarativeCompiledData();
84 
88 
89  struct TypeReference
90  {
92  : type(0), typePropertyCache(0), component(0) {}
93 
98 
99  QObject *createInstance(QDeclarativeContextData *, const QBitField &, QList<QDeclarativeError> *) const;
100  const QMetaObject *metaObject() const;
101  QDeclarativePropertyCache *propertyCache() const;
102  QDeclarativePropertyCache *createPropertyCache(QDeclarativeEngine *);
103  };
106  {
107  int index;
108  int type;
109  };
110 
127 
128  void dumpInstructions();
129 
130 protected:
131  virtual void clear(); // From QDeclarativeCleanup
132 
133 private:
134  void dump(QDeclarativeInstruction *, int idx = -1);
136  QDeclarativeCompiledData &operator=(const QDeclarativeCompiledData &other);
138  friend class QDeclarativeCompiler;
139  int pack(const char *, size_t);
140 
141  int indexForString(const QString &);
142  int indexForByteArray(const QByteArray &);
143  int indexForFloat(float *, int);
144  int indexForInt(int *, int);
145  int indexForLocation(const QDeclarativeParser::Location &);
146  int indexForLocation(const QDeclarativeParser::LocationSpan &);
147  int indexForUrl(const QUrl &);
148 };
149 
150 class QMetaObjectBuilder;
152 {
154 public:
156 
158 
159  bool isError() const;
160  QList<QDeclarativeError> errors() const;
161 
162  static bool isAttachedPropertyName(const QByteArray &);
163  static bool isSignalPropertyName(const QByteArray &);
164 
165  int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
166  const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType
167  int rewriteBinding(const QString& expression, const QByteArray& name); // for QDeclarativeCustomParser::rewriteBinding
168 
169 private:
170  static void reset(QDeclarativeCompiledData *);
171 
172  struct BindingContext {
174  : stack(0), owner(0), object(0) {}
176  : stack(0), owner(0), object(o) {}
178  BindingContext rv(object);
179  rv.stack = stack + 1;
180  return rv;
181  }
182  bool isSubContext() const { return stack != 0; }
183  int stack;
184  int owner;
186  };
187 
188  void compileTree(QDeclarativeParser::Object *tree);
189 
190 
191  bool buildObject(QDeclarativeParser::Object *obj, const BindingContext &);
192  bool buildComponent(QDeclarativeParser::Object *obj, const BindingContext &);
193  bool buildSubObject(QDeclarativeParser::Object *obj, const BindingContext &);
194  bool buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
195  const BindingContext &);
196  bool buildProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
197  const BindingContext &);
198  bool buildPropertyInNamespace(QDeclarativeImportedNamespace *ns,
201  const BindingContext &);
202  bool buildIdProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
203  bool buildAttachedProperty(QDeclarativeParser::Property *prop,
205  const BindingContext &ctxt);
206  bool buildGroupedProperty(QDeclarativeParser::Property *prop,
208  const BindingContext &ctxt);
209  bool buildValueTypeProperty(QObject *type,
212  const BindingContext &ctxt);
213  bool buildListProperty(QDeclarativeParser::Property *prop,
215  const BindingContext &ctxt);
216  bool buildScriptStringProperty(QDeclarativeParser::Property *prop,
218  const BindingContext &ctxt);
219  bool buildPropertyAssignment(QDeclarativeParser::Property *prop,
221  const BindingContext &ctxt);
222  bool buildPropertyObjectAssignment(QDeclarativeParser::Property *prop,
225  const BindingContext &ctxt);
226  bool buildPropertyOnAssignment(QDeclarativeParser::Property *prop,
230  const BindingContext &ctxt);
231  bool buildPropertyLiteralAssignment(QDeclarativeParser::Property *prop,
234  const BindingContext &ctxt);
235  bool doesPropertyExist(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
236  bool testLiteralAssignment(const QMetaProperty &prop,
238  bool testQualifiedEnumAssignment(const QMetaProperty &prop,
241  bool *isAssignment);
242  enum DynamicMetaMode { IgnoreAliases, ResolveAliases, ForceCreation };
243  bool mergeDynamicMetaProperties(QDeclarativeParser::Object *obj);
244  bool buildDynamicMeta(QDeclarativeParser::Object *obj, DynamicMetaMode mode);
245  bool checkDynamicMeta(QDeclarativeParser::Object *obj);
246  bool buildBinding(QDeclarativeParser::Value *, QDeclarativeParser::Property *prop,
247  const BindingContext &ctxt);
248  bool buildComponentFromRoot(QDeclarativeParser::Object *obj, const BindingContext &);
249  bool compileAlias(QMetaObjectBuilder &,
250  QByteArray &data,
253  bool completeComponentBuild();
254  bool checkValidId(QDeclarativeParser::Value *, const QString &);
255 
256 
257  void genObject(QDeclarativeParser::Object *obj);
258  void genObjectBody(QDeclarativeParser::Object *obj);
259  void genValueTypeProperty(QDeclarativeParser::Object *obj,QDeclarativeParser::Property *);
260  void genComponent(QDeclarativeParser::Object *obj);
261  void genValueProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
262  void genListProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj);
263  void genPropertyAssignment(QDeclarativeParser::Property *prop,
265  QDeclarativeParser::Property *valueTypeProperty = 0);
266  void genLiteralAssignment(const QMetaProperty &prop,
268  void genBindingAssignment(QDeclarativeParser::Value *binding,
271  QDeclarativeParser::Property *valueTypeProperty = 0);
272  int genContextCache();
273 
274  int genValueTypeData(QDeclarativeParser::Property *prop, QDeclarativeParser::Property *valueTypeProp);
275  int genPropertyData(QDeclarativeParser::Property *prop);
276 
277  int componentTypeRef();
278 
279  static QDeclarativeType *toQmlType(QDeclarativeParser::Object *from);
280  bool canCoerce(int to, QDeclarativeParser::Object *from);
281 
282  QStringList deferredProperties(QDeclarativeParser::Object *);
283  int indexOfProperty(QDeclarativeParser::Object *, const QByteArray &, bool *notInRevision = 0);
284  int indexOfSignal(QDeclarativeParser::Object *, const QByteArray &, bool *notInRevision = 0);
285 
286  void addId(const QString &, QDeclarativeParser::Object *);
287 
288  void dumpStats();
289 
294 
295  enum DataType { QtScript, Experimental };
297 
299 
302  };
303  void addBindingReference(const BindingReference &);
304 
306  {
308  : parserStatusCount(0), pushedProperties(0), root(0) {}
313 
315 
320  };
322 
324  {
325  ComponentStat() : ids(0), objects(0) {}
326 
328 
329  int ids;
332  int objects;
333  };
335 
336  void saveComponentState();
337 
341 
348 };
350 
351 #endif // QDECLARATIVECOMPILER_P_H
QHash< QDeclarativeParser::Value *, BindingContext > signalExpressions
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
QList< QDeclarativeParser::Location > locations
QList< QDeclarativeError > exceptions
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT QTextStream & reset(QTextStream &s)
QDeclarativePropertyCache * typePropertyCache
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
QList< QDeclarativeParser::Object::ScriptBlock > scripts
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QWidget * owner
The QHash class is a template class that provides a hash-table-based dictionary.
Definition: qdatastream.h:66
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
QDeclarativeParser::Property * property
QList< QDeclarativeParser::LocationSpan > optimizedBindings
QDeclarativeEngine * engine
ComponentCompileState compileState
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QDeclarativeComponent class encapsulates a QML component definition.
QList< ComponentStat > savedComponentStats
const char * name
BindingContext(QDeclarativeParser::Object *o)
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QDeclarativeCompiledData * output
static const char * data(const QByteArray &arr)
QList< QScriptProgram * > cachedPrograms
QDeclarativeParser::Object * unitRoot
QList< QDeclarativeParser::LocationSpan > scriptBindings
QList< QDeclarativePropertyCache * > propertyCaches
static qreal component(const QPointF &point, unsigned int i)
Q_CORE_EXPORT int QT_FASTCALL script(uint ucs4)
QList< QScriptValue * > cachedClosures
QList< QDeclarativeIntegerCache * > contextCaches
QDeclarativeTypeData * unit
QDeclarativePropertyCache * rootPropertyCache
The QDeclarativeEngine class provides an environment for instantiating QML components.
QHash< QString, QDeclarativeParser::Object * > ids
QList< QDeclarativeParser::Object * > aliasingObjects
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
QAbstractDynamicMetaObject rootData
static QString dump(const QByteArray &)
The QDeclarativeContext class defines a context within a QML engine.
QList< CustomTypeData > customTypeData
QHash< QDeclarativeParser::Value *, BindingReference > bindings
The QScriptProgram class encapsulates a Qt Script program.
static bool isSignalPropertyName(const QString &signalName)
The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. ...
QHash< int, QDeclarativeParser::Object * > idIndexes
QDeclarativeTypeNameCache * importCache
The QMetaProperty class provides meta-data about a property.
Definition: qmetaobject.h:176
QDeclarativeEnginePrivate * enginePrivate
#define Q_DECLARE_TR_FUNCTIONS(context)
The Q_DECLARE_TR_FUNCTIONS() macro declares and implements two translation functions, tr() and trUtf8(), with these signatures:
QList< TypeReference > types
QList< QDeclarativeInstruction > bytecode
QHash< QDeclarativeParser::Object *, ComponentCompileState > savedCompileStates