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>
69 #include <private/qdeclarativepropertycache_p.h>
75 QT_MODULE(Declarative)
77 class QDeclarativePropertyCache;
78 namespace QDeclarativeJS { namespace AST { class Node; class StringLiteral; } }
79 namespace QDeclarativeCompilerTypes { class BindingReference; class ComponentCompileState; }
84 These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
85 QDeclarativeCompiler. During the compilation phase the compiler will update some of
86 the fields for its own use.
88 The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
89 reasons (there used to be more in this namespace) and will be cleaned up and
90 migrated into a more appropriate location eventually.
92 namespace QDeclarativeParser
96 Location() : line(-1), column(-1) {}
100 inline bool operator<(const Location &other) {
101 return line < other.line ||
102 (line == other.line && column < other.column);
108 LocationRange() : offset(0), length(0) {}
119 bool operator<(LocationSpan &o) const {
120 return (start.line < o.start.line) ||
121 (start.line == o.start.line && start.column < o.start.column);
127 class Q_DECLARATIVE_EXPORT Variant
139 Variant(const Variant &);
140 explicit Variant(bool);
141 explicit Variant(double, const QStringRef &asWritten = QStringRef());
142 explicit Variant(QDeclarativeJS::AST::StringLiteral *);
143 explicit Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *);
144 Variant &operator=(const Variant &);
148 bool isBoolean() const { return type() == Boolean; }
149 bool isNumber() const { return type() == Number; }
150 bool isString() const { return type() == String; }
151 bool isScript() const { return type() == Script; }
152 bool isStringList() const;
154 bool asBoolean() const;
155 QString asString() const;
156 double asNumber() const;
157 QString asScript() const;
158 QDeclarativeJS::AST::Node *asAST() const;
159 QStringList asStringList() const;
166 QDeclarativeJS::AST::StringLiteral *l;
167 QDeclarativeJS::AST::Node *n;
169 QStringRef asWritten;
172 class Value : public QDeclarativePool::POD
178 // The type of this value assignment is not yet known
180 // This is used as a literal property assignment
182 // This is used as a property binding assignment
184 // This is used as a QDeclarativePropertyValueSource assignment
186 // This is used as a QDeclarativePropertyValueInterceptor assignment
188 // This is used as a property QObject assignment
190 // This is used as a signal object assignment
192 // This is used as a signal expression assignment
194 // This is used as an id assignment only
199 // ### Temporary (for id only)
200 QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
207 LocationSpan location;
210 QDeclarativeCompilerTypes::BindingReference *bindingReference;
211 int signalExpressionContextStack;
213 // Used in Property::ValueList lists
217 class Property : public QDeclarativePool::POD
222 // The Object to which this property is attached
225 Object *getValue(const LocationSpan &);
226 void addValue(Value *v);
227 void addOnValue(Value *v);
229 // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
232 // The metaobject index of this property, or -1 if unknown.
234 // The core data in the case of a regular property.
235 // XXX This has to be a value now as the synthCache may change during
236 // compilation which invalidates pointers. We should fix this.
237 QDeclarativePropertyCache::Data core;
239 // Returns true if this is an empty property - both value and values
241 bool isEmpty() const;
243 typedef QFieldList<Value, &Value::nextValue> ValueList;
244 // The list of values assigned to this property. Content in values
245 // and value are mutually exclusive
247 // The list of values assigned to this property using the "on" syntax
249 // The accessed property. This is used to represent dot properties.
250 // Content in value and values are mutually exclusive.
253 QStringRef name() const { return _name; }
254 void setName(const QString &n) { _name = QStringRef(pool()->NewString(n)); }
255 // True if this property was accessed as the default property.
257 // True if the setting of this property will be deferred. Set by the
258 // QDeclarativeCompiler
260 // True if this property is a value-type pseudo-property
261 bool isValueTypeSubProperty;
262 // True if this property is a property alias. Set by the
263 // QDeclarativeCompiler
266 // Used for scriptStringProperties
267 int scriptStringScope;
269 LocationSpan location;
270 LocationRange listValueRange;
272 // Used in Object::MainPropertyList
273 Property *nextMainProperty;
275 // Used in Object::PropertyList lists
276 Property *nextProperty;
283 class Object : public QDeclarativePool::Class
289 // Type of the object. The integer is an index into the
290 // QDeclarativeCompiledData::types array, or -1 if the object is a property
294 // The fully-qualified name of this type
296 // The id assigned to the object (if any). Set by the QDeclarativeCompiler
298 // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
300 // Custom parsed data
302 // Bit mask of the properties assigned bindings
303 QByteArray bindingBitmask;
304 void setBindingBit(int);
305 // Returns the metaobject for this type, or 0 if not available.
306 // Internally selectd between the metatype and extObject variables
307 const QMetaObject *metaObject() const;
309 // The compile time metaobject for this type
310 const QMetaObject *metatype;
311 // The synthesized metaobject, if QML added signals or properties to
312 // this type. Otherwise null
313 QAbstractDynamicMetaObject extObject;
314 QByteArray metadata; // Generated by compiler
315 QByteArray synthdata; // Generated by compiler
316 QDeclarativePropertyCache *synthCache; // Generated by compiler
318 Property *getDefaultProperty();
319 // name ptr must be guarenteed to remain valid
320 Property *getProperty(const QStringRef &name, bool create=true);
321 Property *getProperty(const QString &name, bool create=true);
323 Property *defaultProperty;
325 typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
326 MainPropertyList properties;
328 // Output of the compilation phase (these properties continue to exist
329 // in either the defaultProperty or properties members too)
330 void addValueProperty(Property *);
331 void addSignalProperty(Property *);
332 void addAttachedProperty(Property *);
333 void addGroupedProperty(Property *);
334 void addValueTypeProperty(Property *);
335 void addScriptStringProperty(Property *);
337 typedef QFieldList<Property, &Property::nextProperty> PropertyList;
338 PropertyList valueProperties;
339 PropertyList signalProperties;
340 PropertyList attachedProperties;
341 PropertyList groupedProperties;
342 PropertyList valueTypeProperties;
343 PropertyList scriptStringProperties;
345 // Script blocks that were nested under this object
351 Q_DECLARE_FLAGS(Pragmas, Pragma)
358 // The bytes to cast instances by to get to the QDeclarativeParserStatus
359 // interface. -1 indicates the type doesn't support this interface.
360 // Set by the QDeclarativeCompiler.
361 int parserStatusCast;
363 LocationSpan location;
365 struct DynamicProperty {
367 DynamicProperty(const DynamicProperty &);
369 enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
371 bool isDefaultProperty;
373 QByteArray customType;
375 QDeclarativeParser::Property *defaultValue;
376 LocationSpan location;
378 struct DynamicSignal {
380 DynamicSignal(const DynamicSignal &);
383 QList<QByteArray> parameterTypes;
384 QList<QByteArray> parameterNames;
388 DynamicSlot(const DynamicSlot &);
392 QList<QByteArray> parameterNames;
393 LocationSpan location;
396 // The list of dynamic properties
397 QList<DynamicProperty> dynamicProperties;
398 // The list of dynamic signals
399 QList<DynamicSignal> dynamicSignals;
400 // The list of dynamic slots
401 QList<DynamicSlot> dynamicSlots;
404 QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
406 // Used by ComponentCompileState::AliasingObjectsList
407 Object *nextAliasingObject;
408 // Used by ComponentComppileState::IdList
409 Object *nextIdObject;
414 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
418 Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
422 #endif // QDECLARATIVEPARSER_P_H