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 QDECLARATIVEPARSER_P_H
43 #define QDECLARATIVEPARSER_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 "qdeclarative.h"
58 #include <QtCore/qbytearray.h>
59 #include <QtCore/qlist.h>
60 #include <QtCore/qurl.h>
61 #include <QtCore/qstring.h>
62 #include <QtCore/qstringlist.h>
64 #include <private/qobject_p.h>
65 #include <private/qdeclarativerefcount_p.h>
66 #include <private/qdeclarativeglobal_p.h>
72 QT_MODULE(Declarative)
74 class QDeclarativePropertyCache;
75 namespace QDeclarativeJS { namespace AST { class Node; } }
80 These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
81 QDeclarativeCompiler. During the compilation phase the compiler will update some of
82 the fields for its own use.
84 The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
85 reasons (there used to be more in this namespace) and will be cleaned up and
86 migrated into a more appropriate location eventually.
88 namespace QDeclarativeParser
92 Location() : line(-1), column(-1) {}
99 LocationRange() : offset(0), length(0) {}
110 bool operator<(LocationSpan &o) const {
111 return (start.line < o.start.line) ||
112 (start.line == o.start.line && start.column < o.start.column);
117 class Object : public QDeclarativeRefCount
123 // Type of the object. The integer is an index into the
124 // QDeclarativeCompiledData::types array, or -1 if the object is a property
128 // The fully-qualified name of this type
130 // The id assigned to the object (if any). Set by the QDeclarativeCompiler
132 // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
134 // Custom parsed data
136 // Bit mask of the properties assigned bindings
137 QByteArray bindingBitmask;
138 void setBindingBit(int);
139 // Returns the metaobject for this type, or 0 if not available.
140 // Internally selectd between the metatype and extObject variables
141 const QMetaObject *metaObject() const;
143 // The compile time metaobject for this type
144 const QMetaObject *metatype;
145 // The synthesized metaobject, if QML added signals or properties to
146 // this type. Otherwise null
147 QAbstractDynamicMetaObject extObject;
148 QByteArray metadata; // Generated by compiler
149 QByteArray synthdata; // Generated by compiler
150 QDeclarativePropertyCache *synthCache; // Generated by compiler
152 Property *getDefaultProperty();
153 Property *getProperty(const QString &name, bool create=true);
155 Property *defaultProperty;
156 QHash<QString, Property *> properties;
158 // Output of the compilation phase (these properties continue to exist
159 // in either the defaultProperty or properties members too)
160 void addValueProperty(Property *);
161 void addSignalProperty(Property *);
162 void addAttachedProperty(Property *);
163 void addGroupedProperty(Property *);
164 void addValueTypeProperty(Property *);
165 void addScriptStringProperty(Property *, int = 0);
166 QList<Property *> valueProperties;
167 QList<Property *> signalProperties;
168 QList<Property *> attachedProperties;
169 QList<Property *> groupedProperties;
170 QList<Property *> valueTypeProperties;
171 QList<QPair<Property *, int> > scriptStringProperties;
173 // Script blocks that were nested under this object
179 Q_DECLARE_FLAGS(Pragmas, Pragma)
186 // The bytes to cast instances by to get to the QDeclarativeParserStatus
187 // interface. -1 indicates the type doesn't support this interface.
188 // Set by the QDeclarativeCompiler.
189 int parserStatusCast;
191 LocationSpan location;
193 struct DynamicProperty {
195 DynamicProperty(const DynamicProperty &);
197 enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
199 bool isDefaultProperty;
201 QByteArray customType;
203 QDeclarativeParser::Property *defaultValue;
204 LocationSpan location;
206 struct DynamicSignal {
208 DynamicSignal(const DynamicSignal &);
211 QList<QByteArray> parameterTypes;
212 QList<QByteArray> parameterNames;
213 LocationSpan location;
217 DynamicSlot(const DynamicSlot &);
221 QList<QByteArray> parameterNames;
222 LocationSpan location;
225 // The list of dynamic properties
226 QList<DynamicProperty> dynamicProperties;
227 // The list of dynamic signals
228 QList<DynamicSignal> dynamicSignals;
229 // The list of dynamic slots
230 QList<DynamicSlot> dynamicSlots;
233 class Q_DECLARATIVE_EXPORT Variant
245 Variant(const Variant &);
247 Variant(double, const QString &asWritten=QString());
248 Variant(const QString &);
249 Variant(const QString &, QDeclarativeJS::AST::Node *);
250 Variant &operator=(const Variant &);
254 bool isBoolean() const { return type() == Boolean; }
255 bool isNumber() const { return type() == Number; }
256 bool isString() const { return type() == String; }
257 bool isScript() const { return type() == Script; }
258 bool isStringList() const;
260 bool asBoolean() const;
261 QString asString() const;
262 double asNumber() const;
263 QString asScript() const;
264 QDeclarativeJS::AST::Node *asAST() const;
265 QStringList asStringList() const;
272 QDeclarativeJS::AST::Node *n;
277 class Value : public QDeclarativeRefCount
284 // The type of this value assignment is not yet known
286 // This is used as a literal property assignment
288 // This is used as a property binding assignment
290 // This is used as a QDeclarativePropertyValueSource assignment
292 // This is used as a QDeclarativePropertyValueInterceptor assignment
294 // This is used as a property QObject assignment
296 // This is used as a signal object assignment
298 // This is used as a signal expression assignment
300 // This is used as an id assignment only
305 // ### Temporary (for id only)
306 QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
313 LocationSpan location;
316 class Property : public QDeclarativeRefCount
320 Property(const QString &n);
323 // The Object to which this property is attached
326 Object *getValue(const LocationSpan &);
327 void addValue(Value *v);
328 void addOnValue(Value *v);
330 // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
333 // The metaobject index of this property, or -1 if unknown.
336 // Returns true if this is an empty property - both value and values
338 bool isEmpty() const;
339 // The list of values assigned to this property. Content in values
340 // and value are mutually exclusive
341 QList<Value *> values;
342 // The list of values assigned to this property using the "on" syntax
343 QList<Value *> onValues;
344 // The accessed property. This is used to represent dot properties.
345 // Content in value and values are mutually exclusive.
349 // True if this property was accessed as the default property.
351 // True if the setting of this property will be deferred. Set by the
352 // QDeclarativeCompiler
354 // True if this property is a value-type pseudo-property
355 bool isValueTypeSubProperty;
356 // True if this property is a property alias. Set by the
357 // QDeclarativeCompiler
360 LocationSpan location;
361 LocationRange listValueRange;
365 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
369 Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
373 #endif // QDECLARATIVEPARSER_P_H