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;
210 int signalExpressionContextStack;
212 // Used in Property::ValueList lists
216 class Property : public QDeclarativePool::POD
221 // The Object to which this property is attached
224 Object *getValue(const LocationSpan &);
225 void addValue(Value *v);
226 void addOnValue(Value *v);
228 // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
231 // The metaobject index of this property, or -1 if unknown.
234 // Returns true if this is an empty property - both value and values
236 bool isEmpty() const;
238 typedef QFieldList<Value, &Value::nextValue> ValueList;
239 // The list of values assigned to this property. Content in values
240 // and value are mutually exclusive
242 // The list of values assigned to this property using the "on" syntax
244 // The accessed property. This is used to represent dot properties.
245 // Content in value and values are mutually exclusive.
248 QString name() const { return _name?*_name:QString(); }
249 void setName(const QString &n) { _name = pool()->NewString(n); }
250 // True if this property was accessed as the default property.
252 // True if the setting of this property will be deferred. Set by the
253 // QDeclarativeCompiler
255 // True if this property is a value-type pseudo-property
256 bool isValueTypeSubProperty;
257 // True if this property is a property alias. Set by the
258 // QDeclarativeCompiler
261 // Used for scriptStringProperties
262 int scriptStringScope;
264 LocationSpan location;
265 LocationRange listValueRange;
267 // Used in Object::MainPropertyList
268 Property *nextMainProperty;
270 // Used in Object::PropertyList lists
271 Property *nextProperty;
278 class Object : public QDeclarativePool::Class
284 // Type of the object. The integer is an index into the
285 // QDeclarativeCompiledData::types array, or -1 if the object is a property
289 // The fully-qualified name of this type
291 // The id assigned to the object (if any). Set by the QDeclarativeCompiler
293 // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
295 // Custom parsed data
297 // Bit mask of the properties assigned bindings
298 QByteArray bindingBitmask;
299 void setBindingBit(int);
300 // Returns the metaobject for this type, or 0 if not available.
301 // Internally selectd between the metatype and extObject variables
302 const QMetaObject *metaObject() const;
304 // The compile time metaobject for this type
305 const QMetaObject *metatype;
306 // The synthesized metaobject, if QML added signals or properties to
307 // this type. Otherwise null
308 QAbstractDynamicMetaObject extObject;
309 QByteArray metadata; // Generated by compiler
310 QByteArray synthdata; // Generated by compiler
311 QDeclarativePropertyCache *synthCache; // Generated by compiler
313 Property *getDefaultProperty();
314 // name ptr must be guarenteed to remain valid
315 Property *getProperty(const QString *name, bool create=true);
316 Property *getProperty(const QString &name, bool create=true);
318 Property *defaultProperty;
320 typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
321 MainPropertyList properties;
323 // Output of the compilation phase (these properties continue to exist
324 // in either the defaultProperty or properties members too)
325 void addValueProperty(Property *);
326 void addSignalProperty(Property *);
327 void addAttachedProperty(Property *);
328 void addGroupedProperty(Property *);
329 void addValueTypeProperty(Property *);
330 void addScriptStringProperty(Property *);
332 typedef QFieldList<Property, &Property::nextProperty> PropertyList;
333 PropertyList valueProperties;
334 PropertyList signalProperties;
335 PropertyList attachedProperties;
336 PropertyList groupedProperties;
337 PropertyList valueTypeProperties;
338 PropertyList scriptStringProperties;
340 // Script blocks that were nested under this object
346 Q_DECLARE_FLAGS(Pragmas, Pragma)
353 // The bytes to cast instances by to get to the QDeclarativeParserStatus
354 // interface. -1 indicates the type doesn't support this interface.
355 // Set by the QDeclarativeCompiler.
356 int parserStatusCast;
358 LocationSpan location;
360 struct DynamicProperty {
362 DynamicProperty(const DynamicProperty &);
364 enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
366 bool isDefaultProperty;
368 QByteArray customType;
370 QDeclarativeParser::Property *defaultValue;
371 LocationSpan location;
373 struct DynamicSignal {
375 DynamicSignal(const DynamicSignal &);
378 QList<QByteArray> parameterTypes;
379 QList<QByteArray> parameterNames;
383 DynamicSlot(const DynamicSlot &);
387 QList<QByteArray> parameterNames;
388 LocationSpan location;
391 // The list of dynamic properties
392 QList<DynamicProperty> dynamicProperties;
393 // The list of dynamic signals
394 QList<DynamicSignal> dynamicSignals;
395 // The list of dynamic slots
396 QList<DynamicSlot> dynamicSlots;
399 QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
401 // Used by ComponentCompileState::AliasingObjectsList
402 Object *nextAliasingObject;
403 // Used by ComponentComppileState::IdList
404 Object *nextIdObject;
409 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
413 Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
417 #endif // QDECLARATIVEPARSER_P_H