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>
70 #include <private/qfastmetabuilder_p.h>
76 QT_MODULE(Declarative)
78 class QDeclarativePropertyCache;
79 namespace QDeclarativeJS { namespace AST { class Node; class StringLiteral; } }
80 namespace QDeclarativeCompilerTypes { class BindingReference; class ComponentCompileState; }
85 These types are created (and owned) by the QDeclarativeScriptParser and consumed by the
86 QDeclarativeCompiler. During the compilation phase the compiler will update some of
87 the fields for its own use.
89 The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
90 reasons (there used to be more in this namespace) and will be cleaned up and
91 migrated into a more appropriate location eventually.
93 namespace QDeclarativeParser
97 Location() : line(-1), column(-1) {}
101 inline bool operator<(const Location &other) {
102 return line < other.line ||
103 (line == other.line && column < other.column);
109 LocationRange() : offset(0), length(0) {}
120 bool operator<(LocationSpan &o) const {
121 return (start.line < o.start.line) ||
122 (start.line == o.start.line && start.column < o.start.column);
128 class Q_DECLARATIVE_EXPORT Variant
140 Variant(const Variant &);
141 explicit Variant(bool);
142 explicit Variant(double, const QStringRef &asWritten = QStringRef());
143 explicit Variant(QDeclarativeJS::AST::StringLiteral *);
144 explicit Variant(const QStringRef &asWritten, QDeclarativeJS::AST::Node *);
145 Variant &operator=(const Variant &);
149 bool isBoolean() const { return type() == Boolean; }
150 bool isNumber() const { return type() == Number; }
151 bool isString() const { return type() == String; }
152 bool isScript() const { return type() == Script; }
153 bool isStringList() const;
155 bool asBoolean() const;
156 QString asString() const;
157 double asNumber() const;
158 QString asScript() const;
159 QDeclarativeJS::AST::Node *asAST() const;
160 QStringList asStringList() const;
167 QDeclarativeJS::AST::StringLiteral *l;
168 QDeclarativeJS::AST::Node *n;
170 QStringRef asWritten;
173 class Value : public QDeclarativePool::POD
179 // The type of this value assignment is not yet known
181 // This is used as a literal property assignment
183 // This is used as a property binding assignment
185 // This is used as a QDeclarativePropertyValueSource assignment
187 // This is used as a QDeclarativePropertyValueInterceptor assignment
189 // This is used as a property QObject assignment
191 // This is used as a signal object assignment
193 // This is used as a signal expression assignment
195 // This is used as an id assignment only
200 // ### Temporary (for id only)
201 QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
208 LocationSpan location;
211 QDeclarativeCompilerTypes::BindingReference *bindingReference;
212 int signalExpressionContextStack;
214 // Used in Property::ValueList lists
218 class Property : public QDeclarativePool::POD
223 // The Object to which this property is attached
226 Object *getValue(const LocationSpan &);
227 void addValue(Value *v);
228 void addOnValue(Value *v);
230 // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
233 // The metaobject index of this property, or -1 if unknown.
235 // The core data in the case of a regular property.
236 // XXX This has to be a value now as the synthCache may change during
237 // compilation which invalidates pointers. We should fix this.
238 QDeclarativePropertyCache::Data core;
240 // Returns true if this is an empty property - both value and values
242 bool isEmpty() const;
244 typedef QFieldList<Value, &Value::nextValue> ValueList;
245 // The list of values assigned to this property. Content in values
246 // and value are mutually exclusive
248 // The list of values assigned to this property using the "on" syntax
250 // The accessed property. This is used to represent dot properties.
251 // Content in value and values are mutually exclusive.
254 QStringRef name() const { return _name; }
255 void setName(const QString &n) { _name = QStringRef(pool()->NewString(n)); }
256 // True if this property was accessed as the default property.
258 // True if the setting of this property will be deferred. Set by the
259 // QDeclarativeCompiler
261 // True if this property is a value-type pseudo-property
262 bool isValueTypeSubProperty;
263 // True if this property is a property alias. Set by the
264 // QDeclarativeCompiler
267 // Used for scriptStringProperties
268 int scriptStringScope;
270 LocationSpan location;
271 LocationRange listValueRange;
273 // Used in Object::MainPropertyList
274 Property *nextMainProperty;
276 // Used in Object::PropertyList lists
277 Property *nextProperty;
284 class Object : public QDeclarativePool::Class
290 // Type of the object. The integer is an index into the
291 // QDeclarativeCompiledData::types array, or -1 if the object is a property
295 // The fully-qualified name of this type
297 // The id assigned to the object (if any). Set by the QDeclarativeCompiler
299 // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
301 // Custom parsed data
303 // Bit mask of the properties assigned bindings
304 QByteArray bindingBitmask;
305 void setBindingBit(int);
306 // Returns the metaobject for this type, or 0 if not available.
307 // Internally selectd between the metatype and extObject variables
308 const QMetaObject *metaObject() const;
310 // The compile time metaobject for this type
311 const QMetaObject *metatype;
312 // The synthesized metaobject, if QML added signals or properties to
313 // this type. Otherwise null
314 QAbstractDynamicMetaObject extObject;
315 QByteArray metadata; // Generated by compiler
316 QByteArray synthdata; // Generated by compiler
317 QDeclarativePropertyCache *synthCache; // Generated by compiler
319 Property *getDefaultProperty();
320 // name ptr must be guarenteed to remain valid
321 Property *getProperty(const QStringRef &name, bool create=true);
322 Property *getProperty(const QString &name, bool create=true);
324 Property *defaultProperty;
326 typedef QFieldList<Property, &Property::nextMainProperty> MainPropertyList;
327 MainPropertyList properties;
329 // Output of the compilation phase (these properties continue to exist
330 // in either the defaultProperty or properties members too)
331 void addValueProperty(Property *);
332 void addSignalProperty(Property *);
333 void addAttachedProperty(Property *);
334 void addGroupedProperty(Property *);
335 void addValueTypeProperty(Property *);
336 void addScriptStringProperty(Property *);
338 typedef QFieldList<Property, &Property::nextProperty> PropertyList;
339 PropertyList valueProperties;
340 PropertyList signalProperties;
341 PropertyList attachedProperties;
342 PropertyList groupedProperties;
343 PropertyList valueTypeProperties;
344 PropertyList scriptStringProperties;
346 // Script blocks that were nested under this object
352 Q_DECLARE_FLAGS(Pragmas, Pragma)
359 // The bytes to cast instances by to get to the QDeclarativeParserStatus
360 // interface. -1 indicates the type doesn't support this interface.
361 // Set by the QDeclarativeCompiler.
362 int parserStatusCast;
364 LocationSpan location;
366 struct DynamicProperty {
368 DynamicProperty(const DynamicProperty &);
370 enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
372 bool isDefaultProperty;
374 QByteArray customType;
376 QDeclarativeParser::Property *defaultValue;
377 LocationSpan location;
379 // Used by the compiler
380 QByteArray resolvedCustomTypeName;
381 QFastMetaBuilder::StringRef typeRef;
382 QFastMetaBuilder::StringRef nameRef;
383 QFastMetaBuilder::StringRef changedSignatureRef;
385 struct DynamicSignal {
387 DynamicSignal(const DynamicSignal &);
390 QList<QByteArray> parameterTypes;
391 QList<QByteArray> parameterNames;
393 int parameterTypesLength() const;
394 int parameterNamesLength() const;
396 // Used by the compiler
397 QFastMetaBuilder::StringRef signatureRef;
398 QFastMetaBuilder::StringRef parameterNamesRef;
402 DynamicSlot(const DynamicSlot &);
406 QList<QByteArray> parameterNames;
407 LocationSpan location;
409 int parameterNamesLength() const;
411 // Used by the compiler
412 QFastMetaBuilder::StringRef signatureRef;
413 QFastMetaBuilder::StringRef parameterNamesRef;
416 // The list of dynamic properties
417 QList<DynamicProperty> dynamicProperties;
418 // The list of dynamic signals
419 QList<DynamicSignal> dynamicSignals;
420 // The list of dynamic slots
421 QList<DynamicSlot> dynamicSlots;
424 QDeclarativeCompilerTypes::ComponentCompileState *componentCompileState;
426 // Used by ComponentCompileState::AliasingObjectsList
427 Object *nextAliasingObject;
428 // Used by ComponentComppileState::IdList
429 Object *nextIdObject;
434 Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
438 Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
442 #endif // QDECLARATIVEPARSER_P_H