| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtDeclarative module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #ifndef QDECLARATIVEPARSER_P_H
|
|---|
| 43 | #define QDECLARATIVEPARSER_P_H
|
|---|
| 44 |
|
|---|
| 45 | //
|
|---|
| 46 | // W A R N I N G
|
|---|
| 47 | // -------------
|
|---|
| 48 | //
|
|---|
| 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.
|
|---|
| 52 | //
|
|---|
| 53 | // We mean it.
|
|---|
| 54 | //
|
|---|
| 55 |
|
|---|
| 56 | #include "qdeclarative.h"
|
|---|
| 57 |
|
|---|
| 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>
|
|---|
| 63 |
|
|---|
| 64 | #include <private/qobject_p.h>
|
|---|
| 65 | #include <private/qdeclarativerefcount_p.h>
|
|---|
| 66 | #include <private/qdeclarativeglobal_p.h>
|
|---|
| 67 |
|
|---|
| 68 | QT_BEGIN_HEADER
|
|---|
| 69 |
|
|---|
| 70 | QT_BEGIN_NAMESPACE
|
|---|
| 71 |
|
|---|
| 72 | QT_MODULE(Declarative)
|
|---|
| 73 |
|
|---|
| 74 | namespace QDeclarativeJS { namespace AST { class Node; } }
|
|---|
| 75 |
|
|---|
| 76 | /*
|
|---|
| 77 | XXX
|
|---|
| 78 |
|
|---|
| 79 | These types are created (and owned) by the QDeclarativeXmlParser and consumed by the
|
|---|
| 80 | QDeclarativeCompiler. During the compilation phase the compiler will update some of
|
|---|
| 81 | the fields for both its own use and for the use of the upcoming QDeclarativeDom API.
|
|---|
| 82 |
|
|---|
| 83 | The types are part of the generic sounding "QDeclarativeParser" namespace for legacy
|
|---|
| 84 | reasons (there used to be more in this namespace) and will be cleaned up and
|
|---|
| 85 | migrated into a more appropriate location shortly.
|
|---|
| 86 | */
|
|---|
| 87 | namespace QDeclarativeParser
|
|---|
| 88 | {
|
|---|
| 89 | struct Location
|
|---|
| 90 | {
|
|---|
| 91 | Location() : line(-1), column(-1) {}
|
|---|
| 92 | int line;
|
|---|
| 93 | int column;
|
|---|
| 94 | };
|
|---|
| 95 |
|
|---|
| 96 | struct LocationRange
|
|---|
| 97 | {
|
|---|
| 98 | LocationRange() : offset(0), length(0) {}
|
|---|
| 99 | quint32 offset;
|
|---|
| 100 | quint32 length;
|
|---|
| 101 | };
|
|---|
| 102 |
|
|---|
| 103 | struct LocationSpan
|
|---|
| 104 | {
|
|---|
| 105 | Location start;
|
|---|
| 106 | Location end;
|
|---|
| 107 | LocationRange range;
|
|---|
| 108 |
|
|---|
| 109 | bool operator<(LocationSpan &o) const {
|
|---|
| 110 | return (start.line < o.start.line) ||
|
|---|
| 111 | (start.line == o.start.line && start.column < o.start.column);
|
|---|
| 112 | }
|
|---|
| 113 | };
|
|---|
| 114 |
|
|---|
| 115 | class Property;
|
|---|
| 116 | class Object : public QDeclarativeRefCount
|
|---|
| 117 | {
|
|---|
| 118 | public:
|
|---|
| 119 | Object();
|
|---|
| 120 | virtual ~Object();
|
|---|
| 121 |
|
|---|
| 122 | // Type of the object. The integer is an index into the
|
|---|
| 123 | // QDeclarativeCompiledData::types array, or -1 if the object is a property
|
|---|
| 124 | // group.
|
|---|
| 125 | int type;
|
|---|
| 126 | // The url of this object if it is an external type. Used by the DOM
|
|---|
| 127 | QUrl url;
|
|---|
| 128 |
|
|---|
| 129 | // version information if type is defined in library or C++
|
|---|
| 130 | int majorVersion;
|
|---|
| 131 | int minorVersion;
|
|---|
| 132 |
|
|---|
| 133 | // The fully-qualified name of this type
|
|---|
| 134 | QByteArray typeName;
|
|---|
| 135 | // The class name
|
|---|
| 136 | QByteArray className;
|
|---|
| 137 | // The id assigned to the object (if any). Set by the QDeclarativeCompiler
|
|---|
| 138 | QString id;
|
|---|
| 139 | // The id index assigned to the object (if any). Set by the QDeclarativeCompiler
|
|---|
| 140 | int idIndex;
|
|---|
| 141 | // Custom parsed data
|
|---|
| 142 | QByteArray custom;
|
|---|
| 143 | // Bit mask of the properties assigned bindings
|
|---|
| 144 | QByteArray bindingBitmask;
|
|---|
| 145 | void setBindingBit(int);
|
|---|
| 146 | // Returns the metaobject for this type, or 0 if not available.
|
|---|
| 147 | // Internally selectd between the metatype and extObject variables
|
|---|
| 148 | const QMetaObject *metaObject() const;
|
|---|
| 149 |
|
|---|
| 150 | // The compile time metaobject for this type
|
|---|
| 151 | const QMetaObject *metatype;
|
|---|
| 152 | // The synthesized metaobject, if QML added signals or properties to
|
|---|
| 153 | // this type. Otherwise null
|
|---|
| 154 | QAbstractDynamicMetaObject extObject;
|
|---|
| 155 | QByteArray metadata; // Generated by compiler
|
|---|
| 156 | QByteArray synthdata; // Generated by compiler
|
|---|
| 157 |
|
|---|
| 158 | Property *getDefaultProperty();
|
|---|
| 159 | Property *getProperty(const QByteArray &name, bool create=true);
|
|---|
| 160 |
|
|---|
| 161 | Property *defaultProperty;
|
|---|
| 162 | QHash<QByteArray, Property *> properties;
|
|---|
| 163 |
|
|---|
| 164 | // Output of the compilation phase (these properties continue to exist
|
|---|
| 165 | // in either the defaultProperty or properties members too)
|
|---|
| 166 | void addValueProperty(Property *);
|
|---|
| 167 | void addSignalProperty(Property *);
|
|---|
| 168 | void addAttachedProperty(Property *);
|
|---|
| 169 | void addGroupedProperty(Property *);
|
|---|
| 170 | void addValueTypeProperty(Property *);
|
|---|
| 171 | void addScriptStringProperty(Property *, int = 0);
|
|---|
| 172 | QList<Property *> valueProperties;
|
|---|
| 173 | QList<Property *> signalProperties;
|
|---|
| 174 | QList<Property *> attachedProperties;
|
|---|
| 175 | QList<Property *> groupedProperties;
|
|---|
| 176 | QList<Property *> valueTypeProperties;
|
|---|
| 177 | QList<QPair<Property *, int> > scriptStringProperties;
|
|---|
| 178 |
|
|---|
| 179 | // Script blocks that were nested under this object
|
|---|
| 180 | struct ScriptBlock {
|
|---|
| 181 | enum Pragma {
|
|---|
| 182 | None = 0x00000000,
|
|---|
| 183 | Shared = 0x00000001
|
|---|
| 184 | };
|
|---|
| 185 | Q_DECLARE_FLAGS(Pragmas, Pragma)
|
|---|
| 186 |
|
|---|
| 187 | QString code;
|
|---|
| 188 | QString file;
|
|---|
| 189 | Pragmas pragmas;
|
|---|
| 190 | };
|
|---|
| 191 |
|
|---|
| 192 | // The bytes to cast instances by to get to the QDeclarativeParserStatus
|
|---|
| 193 | // interface. -1 indicates the type doesn't support this interface.
|
|---|
| 194 | // Set by the QDeclarativeCompiler.
|
|---|
| 195 | int parserStatusCast;
|
|---|
| 196 |
|
|---|
| 197 | LocationSpan location;
|
|---|
| 198 |
|
|---|
| 199 | struct DynamicProperty {
|
|---|
| 200 | DynamicProperty();
|
|---|
| 201 | DynamicProperty(const DynamicProperty &);
|
|---|
| 202 |
|
|---|
| 203 | enum Type { Variant, Int, Bool, Real, String, Url, Color, Time, Date, DateTime, Alias, Custom, CustomList };
|
|---|
| 204 |
|
|---|
| 205 | bool isDefaultProperty;
|
|---|
| 206 | Type type;
|
|---|
| 207 | QByteArray customType;
|
|---|
| 208 | QByteArray name;
|
|---|
| 209 | QDeclarativeParser::Property *defaultValue;
|
|---|
| 210 | LocationSpan location;
|
|---|
| 211 | };
|
|---|
| 212 | struct DynamicSignal {
|
|---|
| 213 | DynamicSignal();
|
|---|
| 214 | DynamicSignal(const DynamicSignal &);
|
|---|
| 215 |
|
|---|
| 216 | QByteArray name;
|
|---|
| 217 | QList<QByteArray> parameterTypes;
|
|---|
| 218 | QList<QByteArray> parameterNames;
|
|---|
| 219 | };
|
|---|
| 220 | struct DynamicSlot {
|
|---|
| 221 | DynamicSlot();
|
|---|
| 222 | DynamicSlot(const DynamicSlot &);
|
|---|
| 223 |
|
|---|
| 224 | QByteArray name;
|
|---|
| 225 | QString body;
|
|---|
| 226 | QList<QByteArray> parameterNames;
|
|---|
| 227 | LocationSpan location;
|
|---|
| 228 | };
|
|---|
| 229 |
|
|---|
| 230 | // The list of dynamic properties
|
|---|
| 231 | QList<DynamicProperty> dynamicProperties;
|
|---|
| 232 | // The list of dynamic signals
|
|---|
| 233 | QList<DynamicSignal> dynamicSignals;
|
|---|
| 234 | // The list of dynamic slots
|
|---|
| 235 | QList<DynamicSlot> dynamicSlots;
|
|---|
| 236 | };
|
|---|
| 237 |
|
|---|
| 238 | class Q_DECLARATIVE_EXPORT Variant
|
|---|
| 239 | {
|
|---|
| 240 | public:
|
|---|
| 241 | enum Type {
|
|---|
| 242 | Invalid,
|
|---|
| 243 | Boolean,
|
|---|
| 244 | Number,
|
|---|
| 245 | String,
|
|---|
| 246 | Script
|
|---|
| 247 | };
|
|---|
| 248 |
|
|---|
| 249 | Variant();
|
|---|
| 250 | Variant(const Variant &);
|
|---|
| 251 | Variant(bool);
|
|---|
| 252 | Variant(double, const QString &asWritten=QString());
|
|---|
| 253 | Variant(const QString &);
|
|---|
| 254 | Variant(const QString &, QDeclarativeJS::AST::Node *);
|
|---|
| 255 | Variant &operator=(const Variant &);
|
|---|
| 256 |
|
|---|
| 257 | Type type() const;
|
|---|
| 258 |
|
|---|
| 259 | bool isBoolean() const { return type() == Boolean; }
|
|---|
| 260 | bool isNumber() const { return type() == Number; }
|
|---|
| 261 | bool isString() const { return type() == String; }
|
|---|
| 262 | bool isScript() const { return type() == Script; }
|
|---|
| 263 | bool isStringList() const;
|
|---|
| 264 |
|
|---|
| 265 | bool asBoolean() const;
|
|---|
| 266 | QString asString() const;
|
|---|
| 267 | double asNumber() const;
|
|---|
| 268 | QString asScript() const;
|
|---|
| 269 | QDeclarativeJS::AST::Node *asAST() const;
|
|---|
| 270 | QStringList asStringList() const;
|
|---|
| 271 |
|
|---|
| 272 | private:
|
|---|
| 273 | Type t;
|
|---|
| 274 | union {
|
|---|
| 275 | bool b;
|
|---|
| 276 | double d;
|
|---|
| 277 | QDeclarativeJS::AST::Node *n;
|
|---|
| 278 | };
|
|---|
| 279 | QString s;
|
|---|
| 280 | };
|
|---|
| 281 |
|
|---|
| 282 | class Value : public QDeclarativeRefCount
|
|---|
| 283 | {
|
|---|
| 284 | public:
|
|---|
| 285 | Value();
|
|---|
| 286 | virtual ~Value();
|
|---|
| 287 |
|
|---|
| 288 | enum Type {
|
|---|
| 289 | // The type of this value assignment is not yet known
|
|---|
| 290 | Unknown,
|
|---|
| 291 | // This is used as a literal property assignment
|
|---|
| 292 | Literal,
|
|---|
| 293 | // This is used as a property binding assignment
|
|---|
| 294 | PropertyBinding,
|
|---|
| 295 | // This is used as a QDeclarativePropertyValueSource assignment
|
|---|
| 296 | ValueSource,
|
|---|
| 297 | // This is used as a QDeclarativePropertyValueInterceptor assignment
|
|---|
| 298 | ValueInterceptor,
|
|---|
| 299 | // This is used as a property QObject assignment
|
|---|
| 300 | CreatedObject,
|
|---|
| 301 | // This is used as a signal object assignment
|
|---|
| 302 | SignalObject,
|
|---|
| 303 | // This is used as a signal expression assignment
|
|---|
| 304 | SignalExpression,
|
|---|
| 305 | // This is used as an id assignment only
|
|---|
| 306 | Id
|
|---|
| 307 | };
|
|---|
| 308 | Type type;
|
|---|
| 309 |
|
|---|
| 310 | // ### Temporary (for id only)
|
|---|
| 311 | QString primitive() const { return value.isString() ? value.asString() : value.asScript(); }
|
|---|
| 312 |
|
|---|
| 313 | // Primitive value
|
|---|
| 314 | Variant value;
|
|---|
| 315 | // Object value
|
|---|
| 316 | Object *object;
|
|---|
| 317 |
|
|---|
| 318 | LocationSpan location;
|
|---|
| 319 | };
|
|---|
| 320 |
|
|---|
| 321 | class Property : public QDeclarativeRefCount
|
|---|
| 322 | {
|
|---|
| 323 | public:
|
|---|
| 324 | Property();
|
|---|
| 325 | Property(const QByteArray &n);
|
|---|
| 326 | virtual ~Property();
|
|---|
| 327 |
|
|---|
| 328 | // The Object to which this property is attached
|
|---|
| 329 | Object *parent;
|
|---|
| 330 |
|
|---|
| 331 | Object *getValue(const LocationSpan &);
|
|---|
| 332 | void addValue(Value *v);
|
|---|
| 333 | void addOnValue(Value *v);
|
|---|
| 334 |
|
|---|
| 335 | // The QVariant::Type of the property, or 0 (QVariant::Invalid) if
|
|---|
| 336 | // unknown.
|
|---|
| 337 | int type;
|
|---|
| 338 | // The metaobject index of this property, or -1 if unknown.
|
|---|
| 339 | int index;
|
|---|
| 340 |
|
|---|
| 341 | // Returns true if this is an empty property - both value and values
|
|---|
| 342 | // are unset.
|
|---|
| 343 | bool isEmpty() const;
|
|---|
| 344 | // The list of values assigned to this property. Content in values
|
|---|
| 345 | // and value are mutually exclusive
|
|---|
| 346 | QList<Value *> values;
|
|---|
| 347 | // The list of values assigned to this property using the "on" syntax
|
|---|
| 348 | QList<Value *> onValues;
|
|---|
| 349 | // The accessed property. This is used to represent dot properties.
|
|---|
| 350 | // Content in value and values are mutually exclusive.
|
|---|
| 351 | Object *value;
|
|---|
| 352 | // The property name
|
|---|
| 353 | QByteArray name;
|
|---|
| 354 | // True if this property was accessed as the default property.
|
|---|
| 355 | bool isDefault;
|
|---|
| 356 | // True if the setting of this property will be deferred. Set by the
|
|---|
| 357 | // QDeclarativeCompiler
|
|---|
| 358 | bool isDeferred;
|
|---|
| 359 | // True if this property is a value-type pseudo-property
|
|---|
| 360 | bool isValueTypeSubProperty;
|
|---|
| 361 | // True if this property is a property alias. Set by the
|
|---|
| 362 | // QDeclarativeCompiler
|
|---|
| 363 | bool isAlias;
|
|---|
| 364 |
|
|---|
| 365 | LocationSpan location;
|
|---|
| 366 | LocationRange listValueRange;
|
|---|
| 367 | QList<int> listCommaPositions;
|
|---|
| 368 | };
|
|---|
| 369 | }
|
|---|
| 370 |
|
|---|
| 371 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativeParser::Object::ScriptBlock::Pragmas);
|
|---|
| 372 |
|
|---|
| 373 | QT_END_NAMESPACE
|
|---|
| 374 |
|
|---|
| 375 | Q_DECLARE_METATYPE(QDeclarativeParser::Variant)
|
|---|
| 376 |
|
|---|
| 377 | QT_END_HEADER
|
|---|
| 378 |
|
|---|
| 379 | #endif // QDECLARATIVEPARSER_P_H
|
|---|