source: trunk/src/declarative/qml/qdeclarativecompiler_p.h@ 902

Last change on this file since 902 was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 13.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtDeclarative module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
71QT_BEGIN_NAMESPACE
72
73class QDeclarativeEngine;
74class QDeclarativeComponent;
75class QDeclarativeContext;
76class QDeclarativeContextData;
77
78class QScriptProgram;
79class Q_AUTOTEST_EXPORT QDeclarativeCompiledData : public QDeclarativeRefCount, public QDeclarativeCleanup
80{
81public:
82 QDeclarativeCompiledData(QDeclarativeEngine *engine);
83 virtual ~QDeclarativeCompiledData();
84
85 QString name;
86 QUrl url;
87 QDeclarativeTypeNameCache *importCache;
88
89 struct TypeReference
90 {
91 TypeReference()
92 : type(0), component(0) {}
93
94 QByteArray className;
95 QDeclarativeType *type;
96 QDeclarativeCompiledData *component;
97
98 QObject *createInstance(QDeclarativeContextData *, const QBitField &, QList<QDeclarativeError> *) const;
99 const QMetaObject *metaObject() const;
100 };
101 QList<TypeReference> types;
102 struct CustomTypeData
103 {
104 int index;
105 int type;
106 };
107
108 const QMetaObject *root;
109 QAbstractDynamicMetaObject rootData;
110 QDeclarativePropertyCache *rootPropertyCache;
111 QList<QString> primitives;
112 QList<float> floatData;
113 QList<int> intData;
114 QList<CustomTypeData> customTypeData;
115 QList<QByteArray> datas;
116 QList<QDeclarativeParser::Location> locations;
117 QList<QDeclarativeInstruction> bytecode;
118 QList<QScriptProgram *> cachedPrograms;
119 QList<QScriptValue *> cachedClosures;
120 QList<QDeclarativePropertyCache *> propertyCaches;
121 QList<QDeclarativeIntegerCache *> contextCaches;
122 QList<QDeclarativeParser::Object::ScriptBlock> scripts;
123 QList<QUrl> urls;
124
125 void dumpInstructions();
126
127protected:
128 virtual void clear(); // From QDeclarativeCleanup
129
130private:
131 void dump(QDeclarativeInstruction *, int idx = -1);
132 QDeclarativeCompiledData(const QDeclarativeCompiledData &other);
133 QDeclarativeCompiledData &operator=(const QDeclarativeCompiledData &other);
134 QByteArray packData;
135 friend class QDeclarativeCompiler;
136 int pack(const char *, size_t);
137
138 int indexForString(const QString &);
139 int indexForByteArray(const QByteArray &);
140 int indexForFloat(float *, int);
141 int indexForInt(int *, int);
142 int indexForLocation(const QDeclarativeParser::Location &);
143 int indexForLocation(const QDeclarativeParser::LocationSpan &);
144 int indexForUrl(const QUrl &);
145};
146
147class QMetaObjectBuilder;
148class Q_AUTOTEST_EXPORT QDeclarativeCompiler
149{
150 Q_DECLARE_TR_FUNCTIONS(QDeclarativeCompiler)
151public:
152 QDeclarativeCompiler();
153
154 bool compile(QDeclarativeEngine *, QDeclarativeTypeData *, QDeclarativeCompiledData *);
155
156 bool isError() const;
157 QList<QDeclarativeError> errors() const;
158
159 static bool isAttachedPropertyName(const QByteArray &);
160 static bool isSignalPropertyName(const QByteArray &);
161
162 int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum
163 const QMetaObject *resolveType(const QByteArray& name) const; // for QDeclarativeCustomParser::resolveType
164
165private:
166 static void reset(QDeclarativeCompiledData *);
167
168 struct BindingContext {
169 BindingContext()
170 : stack(0), owner(0), object(0) {}
171 BindingContext(QDeclarativeParser::Object *o)
172 : stack(0), owner(0), object(o) {}
173 BindingContext incr() const {
174 BindingContext rv(object);
175 rv.stack = stack + 1;
176 return rv;
177 }
178 bool isSubContext() const { return stack != 0; }
179 int stack;
180 int owner;
181 QDeclarativeParser::Object *object;
182 };
183
184 void compileTree(QDeclarativeParser::Object *tree);
185
186
187 bool buildObject(QDeclarativeParser::Object *obj, const BindingContext &);
188 bool buildComponent(QDeclarativeParser::Object *obj, const BindingContext &);
189 bool buildSubObject(QDeclarativeParser::Object *obj, const BindingContext &);
190 bool buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
191 const BindingContext &);
192 bool buildProperty(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj,
193 const BindingContext &);