Qt 4.8
qdeclarativecompileddata.cpp
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 #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 
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 
71 {
72  int idx = primitives.indexOf(data);
73  if (idx == -1) {
74  idx = primitives.count();
75  primitives << data;
76  }
77  return idx;
78 }
79 
81 {
82  int idx = datas.indexOf(data);
83  if (idx == -1) {
84  idx = datas.count();
85  datas << data;
86  }
87  return idx;
88 }
89 
91 {
92  int idx = urls.indexOf(data);
93  if (idx == -1) {
94  idx = urls.count();
95  urls << data;
96  }
97  return idx;
98 }
99 
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 
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 
149 {
150  // ### FIXME
151  int rv = locations.count();
152  locations << l;
153  return rv;
154 }
155 
157 {
158  // ### FIXME
159  int rv = locations.count();
160  locations << l.start << l.end;
161  return rv;
162 }
163 
166 {
167 }
168 
170 {
171  for (int ii = 0; ii < types.count(); ++ii) {
172  if (types.at(ii).component)
173  types.at(ii).component->release();
174  if (types.at(ii).typePropertyCache)
175  types.at(ii).typePropertyCache->release();
176  }
177 
178  for (int ii = 0; ii < propertyCaches.count(); ++ii)
179  propertyCaches.at(ii)->release();
180 
181  for (int ii = 0; ii < contextCaches.count(); ++ii)
182  contextCaches.at(ii)->release();
183 
184  if (importCache)
185  importCache->release();
186 
187  if (rootPropertyCache)
189 
192 }
193 
195 {
198  for (int ii = 0; ii < cachedClosures.count(); ++ii)
199  cachedClosures[ii] = 0;
200  for (int ii = 0; ii < cachedPrograms.count(); ++ii)
201  cachedPrograms[ii] = 0;
202 }
203 
205 {
206  if (type) {
207  return type->metaObject();
208  } else {
210  return component->root;
211  }
212 }
213 
218 {
219  if (type)
220  return typePropertyCache;
221  else
222  return component->rootPropertyCache;
223 }
224 
229 {
230  if (typePropertyCache) {
231  return typePropertyCache;
232  } else if (type) {
233  typePropertyCache = QDeclarativeEnginePrivate::get(engine)->cache(type->metaObject());
234  typePropertyCache->addref();
235  return typePropertyCache;
236  } else {
237  return component->rootPropertyCache;
238  }
239 }
240 
241 
243 {
244  if (!name.isEmpty())
245  qWarning() << name;
246  qWarning().nospace() << "Index\tLine\tOperation\t\tData1\tData2\tData3\tComments";
247  qWarning().nospace() << "-------------------------------------------------------------------------------";
248  for (int ii = 0; ii < bytecode.count(); ++ii) {
249  dump(&bytecode[ii], ii);
250  }
251  qWarning().nospace() << "-------------------------------------------------------------------------------";
252 }
253 
254 
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
int type
Definition: qmetatype.cpp:239
QList< QDeclarativeParser::Location > locations
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int indexForByteArray(const QByteArray &)
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QDeclarativePropertyCache * cache(QObject *obj)
Returns a QDeclarativePropertyCache for obj if one is available.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
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
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
static QDeclarativeEnginePrivate * get(QDeclarativeEngine *e)
QDeclarativePropertyCache * createPropertyCache(QDeclarativeEngine *)
Returns the property cache, creating one if it doesn&#39;t already exist.
int indexForLocation(const QDeclarativeParser::Location &)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QList< QScriptProgram * > cachedPrograms
QList< QDeclarativePropertyCache * > propertyCaches
static qreal component(const QPointF &point, unsigned int i)
QList< QScriptValue * > cachedClosures
QList< QDeclarativeIntegerCache * > contextCaches
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QDeclarativePropertyCache * rootPropertyCache
void dump(QDeclarativeInstruction *, int idx=-1)
int indexOf(const T &t, int from=0) const
Returns the index position of the first occurrence of value in the list, searching forward from index...
Definition: qlist.h:847
The QDeclarativeEngine class provides an environment for instantiating QML components.
QDeclarativePropertyCache * propertyCache() const
Returns the property cache, if one alread exists.
QFactoryLoader * l
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QDeclarativeCleanup provides a callback when a QDeclarativeEngine is deleted. ...
QDeclarativeTypeNameCache * importCache
Q_OUTOFLINE_TEMPLATE void qDeleteAll(ForwardIterator begin, ForwardIterator end)
Definition: qalgorithms.h:319
int pack(const char *, size_t)
QDeclarativeCompiledData(QDeclarativeEngine *engine)
QList< TypeReference > types
QList< QDeclarativeInstruction > bytecode