|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "private/qdeclarativecompiler_p.h" |
|
43 #include "qdeclarativeengine.h" |
|
44 #include "qdeclarativecomponent.h" |
|
45 #include "private/qdeclarativecomponent_p.h" |
|
46 #include "qdeclarativecontext.h" |
|
47 #include "private/qdeclarativecontext_p.h" |
|
48 |
|
49 #include <QtCore/qdebug.h> |
|
50 |
|
51 #include <private/qobject_p.h> |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 int QDeclarativeCompiledData::pack(const char *data, size_t size) |
|
56 { |
|
57 const char *p = packData.constData(); |
|
58 unsigned int ps = packData.size(); |
|
59 |
|
60 for (unsigned int ii = 0; (ii + size) <= ps; ii += sizeof(int)) { |
|
61 if (0 == ::memcmp(p + ii, data, size)) |
|
62 return ii; |
|
63 } |
|
64 |
|
65 int rv = packData.size(); |
|
66 packData.append(data, size); |
|
67 return rv; |
|
68 } |
|
69 |
|
70 int QDeclarativeCompiledData::indexForString(const QString &data) |
|
71 { |
|
72 int idx = primitives.indexOf(data); |
|
73 if (idx == -1) { |
|
74 idx = primitives.count(); |
|
75 primitives << data; |
|
76 } |
|
77 return idx; |
|
78 } |
|
79 |
|
80 int QDeclarativeCompiledData::indexForByteArray(const QByteArray &data) |
|
81 { |
|
82 int idx = datas.indexOf(data); |
|
83 if (idx == -1) { |
|
84 idx = datas.count(); |
|
85 datas << data; |
|
86 } |
|
87 return idx; |
|
88 } |
|
89 |
|
90 int QDeclarativeCompiledData::indexForUrl(const QUrl &data) |
|
91 { |
|
92 int idx = urls.indexOf(data); |
|
93 if (idx == -1) { |
|
94 idx = urls.count(); |
|
95 urls << data; |
|
96 } |
|
97 return idx; |
|
98 } |
|
99 |
|
100 int QDeclarativeCompiledData::indexForFloat(float *data, int count) |
|
101 { |
|
102 Q_ASSERT(count > 0); |
|
103 |
|
104 for (int ii = 0; ii <= floatData.count() - count; ++ii) { |
|
105 bool found = true; |
|
106 for (int jj = 0; jj < count; ++jj) { |
|
107 if (floatData.at(ii + jj) != data[jj]) { |
|
108 found = false; |
|
109 break; |
|
110 } |
|
111 } |
|
112 |
|
113 if (found) |
|
114 return ii; |
|
115 } |
|
116 |
|
117 int idx = floatData.count(); |
|
118 for (int ii = 0; ii < count; ++ii) |
|
119 floatData << data[ii]; |
|
120 |
|
121 return idx; |
|
122 } |
|
123 |
|
124 int QDeclarativeCompiledData::indexForInt(int *data, int count) |
|
125 { |
|
126 Q_ASSERT(count > 0); |
|
127 |
|
128 for (int ii = 0; ii <= intData.count() - count; ++ii) { |
|
129 bool found = true; |
|
130 for (int jj = 0; jj < count; ++jj) { |
|
131 if (intData.at(ii + jj) != data[jj]) { |
|
132 found = false; |
|
133 break; |
|
134 } |
|
135 } |
|
136 |
|
137 if (found) |
|
138 return ii; |
|
139 } |
|
140 |
|
141 int idx = intData.count(); |
|
142 for (int ii = 0; ii < count; ++ii) |
|
143 intData << data[ii]; |
|
144 |
|
145 return idx; |
|
146 } |
|
147 |
|
148 int QDeclarativeCompiledData::indexForLocation(const QDeclarativeParser::Location &l) |
|
149 { |
|
150 // ### FIXME |
|
151 int rv = locations.count(); |
|
152 locations << l; |
|
153 return rv; |
|
154 } |
|
155 |
|
156 int QDeclarativeCompiledData::indexForLocation(const QDeclarativeParser::LocationSpan &l) |
|
157 { |
|
158 // ### FIXME |
|
159 int rv = locations.count(); |
|
160 locations << l.start << l.end; |
|
161 return rv; |
|
162 } |
|
163 |
|
164 QDeclarativeCompiledData::QDeclarativeCompiledData(QDeclarativeEngine *engine) |
|
165 : QDeclarativeCleanup(engine), importCache(0), root(0), rootPropertyCache(0) |
|
166 { |
|
167 } |
|
168 |
|
169 QDeclarativeCompiledData::~QDeclarativeCompiledData() |
|
170 { |
|
171 for (int ii = 0; ii < types.count(); ++ii) { |
|
172 if (types.at(ii).ref) |
|
173 types.at(ii).ref->release(); |
|
174 } |
|
175 |
|
176 for (int ii = 0; ii < propertyCaches.count(); ++ii) |
|
177 propertyCaches.at(ii)->release(); |
|
178 |
|
179 for (int ii = 0; ii < contextCaches.count(); ++ii) |
|
180 contextCaches.at(ii)->release(); |
|
181 |
|
182 if (importCache) |
|
183 importCache->release(); |
|
184 |
|
185 if (rootPropertyCache) |
|
186 rootPropertyCache->release(); |
|
187 |
|
188 qDeleteAll(cachedPrograms); |
|
189 qDeleteAll(cachedClosures); |
|
190 } |
|
191 |
|
192 void QDeclarativeCompiledData::clear() |
|
193 { |
|
194 qDeleteAll(cachedPrograms); |
|
195 qDeleteAll(cachedClosures); |
|
196 for (int ii = 0; ii < cachedClosures.count(); ++ii) |
|
197 cachedClosures[ii] = 0; |
|
198 for (int ii = 0; ii < cachedPrograms.count(); ++ii) |
|
199 cachedPrograms[ii] = 0; |
|
200 } |
|
201 |
|
202 const QMetaObject *QDeclarativeCompiledData::TypeReference::metaObject() const |
|
203 { |
|
204 if (type) { |
|
205 return type->metaObject(); |
|
206 } else { |
|
207 Q_ASSERT(component); |
|
208 return static_cast<QDeclarativeComponentPrivate *>(QObjectPrivate::get(component))->cc->root; |
|
209 } |
|
210 } |
|
211 |
|
212 void QDeclarativeCompiledData::dumpInstructions() |
|
213 { |
|
214 if (!name.isEmpty()) |
|
215 qWarning() << name; |
|
216 qWarning().nospace() << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments"; |
|
217 qWarning().nospace() << "-------------------------------------------------------------------------------"; |
|
218 for (int ii = 0; ii < bytecode.count(); ++ii) { |
|
219 dump(&bytecode[ii], ii); |
|
220 } |
|
221 qWarning().nospace() << "-------------------------------------------------------------------------------"; |
|
222 } |
|
223 |
|
224 |
|
225 QT_END_NAMESPACE |