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>
67 #include <private/qdeclarativepool_p.h>
68 #include <private/qfieldlist_p.h>
74 QT_MODULE(Declarative)
76 class QDeclarativePropertyCache;
77 namespace QDeclarativeJS { namespace AST { class Node; class StringLiteral; } }
78 namespace QDeclarativeCompilerTypes { class BindingReference; class ComponentCompileState; }
83 These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
84 QDeclarativeCompiler. During the compilation phase the compiler will update some of
85 the fields for its own use.
87 The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
88 reasons (there used to be more in this namespace) and will be cleaned up and
89 migrated into a more appropriate location eventually.
91 namespace QDeclarativeParser
95 Location() : line(-1), column(-1) {}
99 inline bool operator<(const Location &other) {
100 return line < other.line ||
101 (line == other.line && column < other.column);
107 LocationRange() : offset(0), length(0) {}
118 bool operator<(LocationSpan &o) const {
119 return (start.line < o.start.line) ||
120 (start.line == o.start.line && start.column < o.start.column);
126 class Q_DECLARATIVE_EXPORT Variant
138 Variant(const Variant &);
139 explicit Variant(bool);
140 explicit Variant(double, const QStringRef &asWritten = QStringRef());
141 explicit Variant(QDeclarativeJS::AST::StringLiteral *);
142 explicit Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *);
143 Variant &operator=(const Variant &);
147 bool isBoolean() const { return type() == Boolean; }
148 bool isNumber() const { return type() == Number; }
149 bool isString() const { return type() == String; }
150 bool isScript() const { return type() == Script; }
151 bool isStringList() const;
153 bool asBoolean() const;
154 QString asString() const;
155 double asNumber() const;
156 QString asScript() const;
157 QDeclarativeJS::AST::Node *asAST() const;
158 QStringList asStringList() const;
165 QDeclarativeJS::AST::StringLiteral *l;
166 QDeclarativeJS::AST::Node *n;
168 QStringRef asWritten;
171 class Value : public QDeclarativePool::POD
177 // The type of this value assignment is not yet known
179 // This is used as a literal property assignment
181 // This is used as a property binding assignment
183 // This is used as a QDeclarativePropertyValueSource assignment
185 // This is used as a QDeclarativePropertyValueInterceptor assignment
187 // This is used as a property QObject assignment
189 // This is used as a signal object assignment
191 // This is used as a signal expression assignment
193 // This is used as an id assignment only
198 // ### Temporary (for id only)
199 QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
206 LocationSpan location;
209 QDeclarativeCompilerTypes::BindingReference *bindingReference;
211 // Used in Property::ValueList lists
215 class Property : public QDeclarativePool::POD
220 // The Object to which this property is attached
223 Object *getValue(const LocationSpan &);
224 void addValue(Value *v);
225 void addOnValue(Value *v);
227 // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
230 // The metaobject index of this property, or -1 if unknown.
233 // Returns true if this is an empty property - both value and values
235 bool isEmpty() const;
237 typedef QFieldList<Value, &Value::nextValue> ValueList;
238 // The list of values assigned to this property. Content in values
239 // and value are mutually exclusive
241 // The list of values assigned to this property using the "on" syntax
243 // The accessed property. This is used to represent dot properties.
244 // Content in value and values are mutually exclusive.
247 QString name() const { return _name?*_name:QString(); }
248 void setName(const QString &n) { _name = pool()->NewString(n); }
249 // True if this property was accessed as the default property.
251 // True if the setting of this property will be deferred. Set by the
252 // QDeclarativeCompiler
254 // True if this property is a value-type pseudo-property
255 bool isValueTypeSubProperty;
256 // True if this property is a property alias. Set by the
257 // QDeclarativeCompiler
260 // Used for scriptStringProperties
261 int scriptStringScope;
263 LocationSpan location;
264 LocationRange listValueRange;
266 // Used in Object::MainPropertyList
267 Property *nextMainProperty;
269 // Used in Object::PropertyList lists
270 Property *nextProperty;
277 class Object : public QDeclarativePool::Class
283 // Type of the object. The integer is an index into the
284 // QDeclarativeCompiledData::types array, or -1 if the object is a property
288 // The fully-qualified name of this type
290 // The id assigned to the object (if any). Set by the QDeclarativeCompiler
292 // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
294 // Custom parsed data
296 // Bit mask of the properties assigned bindings
297 QByteArray bindingBitmask;
298 void setBindingBit(int);
299 // Returns the metaobject for this type, or 0 if not available.
300 // Internally selectd between the metatype and extObject variables
301 const QMetaObject *metaObject() const;
303 // The compile time metaobject for this type
304 const QMetaObject *metatype;
305 // The synthesized metaobject, if QML added signals or properties to
306 // this type. Otherwise null
307 QAbstractDynamicMetaObject extObject;
308 QByteArray metadata; // Generated by compiler
309 QByteArray synthdata; // Generated by compiler
310 QDeclarativePropertyCache *synthCache; // Generated by compiler
312 Property *getDefaultProperty();
313 // name ptr must be guarenteed to remain valid
314 Property *getProperty(const QString *name, bool create=true);
315 Property *getProperty(const QString &name, bool create=true);
317 Property *defaultProperty;
319 typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
320 MainPropertyList properties;
322 // Output of the compilation phase (these properties continue to exist
323 // in either the defaultProperty or properties members too)
324 void addValueProperty(Property *);
325 void addSignalProperty(Property *);
326 void addAttachedProperty(Property *);
327 void addGroupedProperty(Property *);
328 void addValueTypeProperty(Property *);
329 void addScriptStringProperty(Property *);
331 typedef QFieldList<Property, &Property::nextProperty> PropertyList;
332 PropertyList valueProperties;
333 PropertyList signalProperties;
334 PropertyList attachedProperties;
335 PropertyList groupedProperties;
336 PropertyList valueTypeProperties;
337 PropertyList scriptStringProperties;
339 // Script blocks that were nested under this object
345 Q_DECLARE_FLAGS(Pragmas, Pragma)
352 // The bytes to cast instances by to get to the QDeclarativeParserStatus
353 // interface. -1 indicates the type doesn't support this interface.
354 // Set by the QDeclarativeCompiler.
355 int parserStatusCast;
357 LocationSpan location;
359 struct DynamicProperty {
361 DynamicProperty(const DynamicProperty &);
363 enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
365 bool isDefaultProperty;
367 QByteArray customType;
369 QDeclarativeParser::Property *defaultValue;
370 LocationSpan location;
372 struct DynamicSignal {
374 DynamicSignal(const DynamicSignal &);
377 QList<QByteArray> parameterTypes;
378 QList<QByteArray> parameterNames;
382 DynamicSlot(const DynamicSlot &);
386 QList<QByteArray> parameterNames;
387 LocationSpan location;
390 // The list of dynamic properties
391 QList<DynamicProperty> dynamicProperties;
392 // The list of dynamic signals
393 QList<DynamicSignal> dynamicSignals;
394 // The list of dynamic slots
395 QList<DynamicSlot> dynamicSlots;
398 QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
403 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
407 Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
411 #endif // QDECLARATIVEPARSER_P_H