qmljsinterpreter.cpp 64 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11 12 13 14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17 18 19 20 21 22 23 24 25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26 27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
29 30

#include "qmljsinterpreter.h"
31
#include "qmljsevaluate.h"
32
#include "qmljsscopebuilder.h"
33
#include "qmljsscopechain.h"
34
#include "qmljsscopeastpath.h"
35
#include "qmljstypedescriptionreader.h"
36
#include "qmljsvalueowner.h"
37
#include "qmljscontext.h"
Fawzi Mohamed's avatar
Fawzi Mohamed committed
38
#include "qmljsmodelmanagerinterface.h"
39
#include "parser/qmljsast_p.h"
40

41
#include <utils/qtcassert.h>
42

43
#include <QApplication>
44 45 46 47 48
#include <QFile>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QDebug>
49

50
using namespace LanguageUtils;
51
using namespace QmlJS;
52
using namespace QmlJS::AST;
53

54 55
/*!
    \class QmlJS::Value
56 57
    \brief The Value class is an abstract base class for the result of a
    JS expression.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    \sa Evaluate ValueOwner ValueVisitor

    A Value represents a category of JavaScript values, such as number
    (NumberValue), string (StringValue) or functions with a
    specific signature (FunctionValue). It can also represent internal
    categories such as "a QML component instantiation defined in a file"
    (ASTObjectValue), "a QML component defined in C++"
    (CppComponentValue) or "no specific information is available"
    (UnknownValue).

    The Value class itself provides accept() for admitting
    \l{ValueVisitor}s and a do-nothing getSourceLocation().

    Value instances should be cast to a derived type either through the
    asXXX() helper functions such as asNumberValue() or via the
    value_cast() template function.

    Values are the result of many operations in the QmlJS code model:
    \list
77 78 79 80
    \li \l{Evaluate}
    \li Context::lookupType() and Context::lookupReference()
    \li ScopeChain::lookup()
    \li ObjectValue::lookupMember()
81 82 83
    \endlist
*/

Roberto Raggi's avatar
Roberto Raggi committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
namespace {

class LookupMember: public MemberProcessor
{
    QString _name;
    const Value *_value;

    bool process(const QString &name, const Value *value)
    {
        if (_value)
            return false;

        if (name == _name) {
            _value = value;
            return false;
        }

        return true;
    }

public:
    LookupMember(const QString &name)
        : _name(name), _value(0) {}

    const Value *value() const { return _value; }

    virtual bool processProperty(const QString &name, const Value *value)
    {
        return process(name, value);
    }

    virtual bool processEnumerator(const QString &name, const Value *value)
    {
        return process(name, value);
    }

    virtual bool processSignal(const QString &name, const Value *value)
    {
        return process(name, value);
    }

    virtual bool processSlot(const QString &name, const Value *value)
    {
        return process(name, value);
    }

    virtual bool processGeneratedSlot(const QString &name, const Value *value)
    {
        return process(name, value);
    }
};

136 137
class MetaFunction: public FunctionValue
{
138
    FakeMetaMethod _method;
139 140

public:
141 142
    MetaFunction(const FakeMetaMethod &method, ValueOwner *valueOwner)
        : FunctionValue(valueOwner), _method(method)
143 144 145
    {
    }

146
    virtual int namedArgumentCount() const
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    {
        return _method.parameterNames().size();
    }

    virtual QString argumentName(int index) const
    {
        if (index < _method.parameterNames().size())
            return _method.parameterNames().at(index);

        return FunctionValue::argumentName(index);
    }

    virtual bool isVariadic() const
    {
        return false;
    }
};

Roberto Raggi's avatar
Roberto Raggi committed
165 166
} // end of anonymous namespace

167
CppComponentValue::CppComponentValue(FakeMetaObject::ConstPtr metaObject, const QString &className,
168
                               const QString &packageName, const ComponentVersion &componentVersion,
169 170
                               const ComponentVersion &importVersion, int metaObjectRevision,
                               ValueOwner *valueOwner)
171
    : ObjectValue(valueOwner),
172
      _metaObject(metaObject),
173 174
      _moduleName(packageName),
      _componentVersion(componentVersion),
175 176
      _importVersion(importVersion),
      _metaObjectRevision(metaObjectRevision)
177
{
178
    setClassName(className);
179 180 181
    int nEnums = metaObject->enumeratorCount();
    for (int i = 0; i < nEnums; ++i) {
        FakeMetaEnum fEnum = metaObject->enumerator(i);
182
        _enums[fEnum.name()] = new QmlEnumValue(this, i);
183
    }
184
}
Roberto Raggi's avatar
Roberto Raggi committed
185

186
CppComponentValue::~CppComponentValue()
187
{
188 189 190 191
#if QT_VERSION >= 0x050000
    delete _metaSignatures.load();
    delete _signalScopes.load();
#else
192 193
    delete _metaSignatures;
    delete _signalScopes;
194
#endif
195 196 197 198 199 200 201 202 203
}

static QString generatedSlotName(const QString &base)
{
    QString slotName = QLatin1String("on");
    slotName += base.at(0).toUpper();
    slotName += base.midRef(1);
    return slotName;
}
Roberto Raggi's avatar
Roberto Raggi committed
204

Christian Kamm's avatar
Christian Kamm committed
205 206 207 208 209
const CppComponentValue *CppComponentValue::asCppComponentValue() const
{
    return this;
}

210
void CppComponentValue::processMembers(MemberProcessor *processor) const
211
{
Roberto Raggi's avatar
Roberto Raggi committed
212
    // process the meta enums
213 214
    for (int index = _metaObject->enumeratorOffset(); index < _metaObject->enumeratorCount(); ++index) {
        FakeMetaEnum e = _metaObject->enumerator(index);
215 216

        for (int i = 0; i < e.keyCount(); ++i) {
217
            processor->processEnumerator(e.key(i), valueOwner()->numberValue());
218 219 220
        }
    }

221 222
    // all explicitly defined signal names
    QSet<QString> explicitSignals;
223

224
    // make MetaFunction instances lazily when first needed
225 226 227
#if QT_VERSION >= 0x050000
    QList<const Value *> *signatures = _metaSignatures.load();
#else
228
    QList<const Value *> *signatures = _metaSignatures;
229
#endif
230 231 232 233 234 235 236
    if (!signatures) {
        signatures = new QList<const Value *>;
        signatures->reserve(_metaObject->methodCount());
        for (int index = 0; index < _metaObject->methodCount(); ++index)
            signatures->append(new MetaFunction(_metaObject->method(index), valueOwner()));
        if (!_metaSignatures.testAndSetOrdered(0, signatures)) {
            delete signatures;
237 238 239
#if QT_VERSION >= 0x050000
            signatures = _metaSignatures.load();
#else
240
            signatures = _metaSignatures;
241
#endif
242 243 244
        }
    }

Roberto Raggi's avatar
Roberto Raggi committed
245 246
    // process the meta methods
    for (int index = 0; index < _metaObject->methodCount(); ++index) {
247
        const FakeMetaMethod method = _metaObject->method(index);
248
        if (_metaObjectRevision < method.revision())
249 250
            continue;

Christian Kamm's avatar
Christian Kamm committed
251
        const QString &methodName = _metaObject->method(index).methodName();
252
        const Value *signature = signatures->at(index);
253

254
        if (method.methodType() == FakeMetaMethod::Slot && method.access() == FakeMetaMethod::Public) {
Roberto Raggi's avatar
Roberto Raggi committed
255
            processor->processSlot(methodName, signature);
256

257
        } else if (method.methodType() == FakeMetaMethod::Signal && method.access() != FakeMetaMethod::Private) {
258
            // process the signal
Roberto Raggi's avatar
Roberto Raggi committed
259
            processor->processSignal(methodName, signature);
260
            explicitSignals.insert(methodName);
261

262
            // process the generated slot
263
            const QString &slotName = generatedSlotName(methodName);
Roberto Raggi's avatar
Roberto Raggi committed
264
            processor->processGeneratedSlot(slotName, signature);
265
        }
Roberto Raggi's avatar
Roberto Raggi committed
266 267
    }

268 269
    // process the meta properties
    for (int index = 0; index < _metaObject->propertyCount(); ++index) {
270
        const FakeMetaProperty prop = _metaObject->property(index);
271
        if (_metaObjectRevision < prop.revision())
272
            continue;
273 274

        const QString propertyName = prop.name();
275
        processor->processProperty(propertyName, valueForCppName(prop.typeName()));
276 277 278 279 280 281 282

        // every property always has a onXyzChanged slot, even if the NOTIFY
        // signal has a different name
        QString signalName = propertyName;
        signalName += QLatin1String("Changed");
        if (!explicitSignals.contains(signalName)) {
            // process the generated slot
283
            const QString &slotName = generatedSlotName(signalName);
284
            processor->processGeneratedSlot(slotName, valueOwner()->unknownValue());
285 286 287
        }
    }

288 289 290
    // look into attached types
    const QString &attachedTypeName = _metaObject->attachedTypeName();
    if (!attachedTypeName.isEmpty()) {
291
        const CppComponentValue *attachedType = valueOwner()->cppQmlTypes().objectByCppName(attachedTypeName);
292
        if (attachedType && attachedType != this) // ### only weak protection against infinite loops
293 294
            attachedType->processMembers(processor);
    }
295

296 297 298
    ObjectValue::processMembers(processor);
}

299
const Value *CppComponentValue::valueForCppName(const QString &typeName) const
300
{
301
    const CppQmlTypes &cppTypes = valueOwner()->cppQmlTypes();
Roberto Raggi's avatar
Roberto Raggi committed
302

303
    // check in the same package/version first
304
    const CppComponentValue *objectValue = cppTypes.objectByQualifiedName(
305 306 307 308 309 310 311
                _moduleName, typeName, _importVersion);
    if (objectValue)
        return objectValue;

    // fallback to plain cpp name
    objectValue = cppTypes.objectByCppName(typeName);
    if (objectValue)
312
        return objectValue;
Roberto Raggi's avatar
Roberto Raggi committed
313

314 315 316 317 318 319 320
    // try qml builtin type names
    if (const Value *v = valueOwner()->defaultValueForBuiltinType(typeName)) {
        if (!v->asUndefinedValue())
            return v;
    }

    // map other C++ types
321
    if (typeName == QLatin1String("QByteArray")
Christian Kamm's avatar
Christian Kamm committed
322
            || typeName == QLatin1String("QString")) {
Christian Kamm's avatar
Christian Kamm committed
323
        return valueOwner()->stringValue();
Christian Kamm's avatar
Christian Kamm committed
324
    } else if (typeName == QLatin1String("QUrl")) {
Christian Kamm's avatar
Christian Kamm committed
325
        return valueOwner()->urlValue();
326
    } else if (typeName == QLatin1String("long")) {
Christian Kamm's avatar
Christian Kamm committed
327
        return valueOwner()->intValue();
328 329
    }  else if (typeName == QLatin1String("float")
                || typeName == QLatin1String("qreal")) {
Christian Kamm's avatar
Christian Kamm committed
330
        return valueOwner()->realValue();
331
    } else if (typeName == QLatin1String("QFont")) {
Christian Kamm's avatar
Christian Kamm committed
332
        return valueOwner()->qmlFontObject();
333 334 335
    } else if (typeName == QLatin1String("QPoint")
            || typeName == QLatin1String("QPointF")
            || typeName == QLatin1String("QVector2D")) {
Christian Kamm's avatar
Christian Kamm committed
336
        return valueOwner()->qmlPointObject();
337 338
    } else if (typeName == QLatin1String("QSize")
            || typeName == QLatin1String("QSizeF")) {
Christian Kamm's avatar
Christian Kamm committed
339
        return valueOwner()->qmlSizeObject();
340 341
    } else if (typeName == QLatin1String("QRect")
            || typeName == QLatin1String("QRectF")) {
Christian Kamm's avatar
Christian Kamm committed
342
        return valueOwner()->qmlRectObject();
343
    } else if (typeName == QLatin1String("QVector3D")) {
Christian Kamm's avatar
Christian Kamm committed
344
        return valueOwner()->qmlVector3DObject();
345
    } else if (typeName == QLatin1String("QColor")) {
Christian Kamm's avatar
Christian Kamm committed
346
        return valueOwner()->colorValue();
347
    } else if (typeName == QLatin1String("QDeclarativeAnchorLine")) {
Christian Kamm's avatar
Christian Kamm committed
348
        return valueOwner()->anchorLineValue();
349 350
    }

Christian Kamm's avatar
Christian Kamm committed
351
    // might be an enum
352
    const CppComponentValue *base = this;
353
    const QStringList components = typeName.split(QLatin1String("::"));
354
    if (components.size() == 2)
355
        base = valueOwner()->cppQmlTypes().objectByCppName(components.first());
356
    if (base) {
357
        if (const QmlEnumValue *value = base->getEnumValue(components.last()))
Christian Kamm's avatar
Christian Kamm committed
358
            return value;
Christian Kamm's avatar
Christian Kamm committed
359 360
    }

361 362
    // may still be a cpp based value
    return valueOwner()->unknownValue();
363
}
364

365
const CppComponentValue *CppComponentValue::prototype() const
366
{
Christian Kamm's avatar
Christian Kamm committed
367
    Q_ASSERT(!_prototype || value_cast<CppComponentValue>(_prototype));
368
    return static_cast<const CppComponentValue *>(_prototype);
369 370
}

371
/*!
Leena Miettinen's avatar
Leena Miettinen committed
372
  Returns a list started by this object and followed by all its prototypes.
373

Leena Miettinen's avatar
Leena Miettinen committed
374 375
  Use this function rather than calling prototype() in a loop, as it avoids
  cycles.
376
*/
377
QList<const CppComponentValue *> CppComponentValue::prototypes() const
378
{
379 380
    QList<const CppComponentValue *> protos;
    for (const CppComponentValue *it = this; it; it = it->prototype()) {
381 382 383 384 385 386 387
        if (protos.contains(it))
            break;
        protos += it;
    }
    return protos;
}

388
FakeMetaObject::ConstPtr CppComponentValue::metaObject() const
389
{
390
    return _metaObject;
391 392
}

393
QString CppComponentValue::moduleName() const
394
{ return _moduleName; }
395

396
ComponentVersion CppComponentValue::componentVersion() const
397
{ return _componentVersion; }
398

399
ComponentVersion CppComponentValue::importVersion() const
400 401
{ return _importVersion; }

402
QString CppComponentValue::defaultPropertyName() const
403 404
{ return _metaObject->defaultPropertyName(); }

405
QString CppComponentValue::propertyType(const QString &propertyName) const
406
{
407
    foreach (const CppComponentValue *it, prototypes()) {
408
        FakeMetaObject::ConstPtr iter = it->_metaObject;
409
        int propIdx = iter->propertyIndex(propertyName);
410
        if (propIdx != -1)
411
            return iter->property(propIdx).typeName();
412 413 414 415
    }
    return QString();
}

416
bool CppComponentValue::isListProperty(const QString &propertyName) const
417
{
418
    foreach (const CppComponentValue *it, prototypes()) {
419
        FakeMetaObject::ConstPtr iter = it->_metaObject;
420
        int propIdx = iter->propertyIndex(propertyName);
421
        if (propIdx != -1)
422 423 424
            return iter->property(propIdx).isList();
    }
    return false;
425 426
}

427
FakeMetaEnum CppComponentValue::getEnum(const QString &typeName, const CppComponentValue **foundInScope) const
428
{
429
    foreach (const CppComponentValue *it, prototypes()) {
Christian Kamm's avatar
Christian Kamm committed
430 431 432 433 434 435 436 437 438 439 440
        FakeMetaObject::ConstPtr iter = it->_metaObject;
        const int index = iter->enumeratorIndex(typeName);
        if (index != -1) {
            if (foundInScope)
                *foundInScope = it;
            return iter->enumerator(index);
        }
    }
    if (foundInScope)
        *foundInScope = 0;
    return FakeMetaEnum();
441 442
}

443
const QmlEnumValue *CppComponentValue::getEnumValue(const QString &typeName, const CppComponentValue **foundInScope) const
444
{
445
    foreach (const CppComponentValue *it, prototypes()) {
Christian Kamm's avatar
Christian Kamm committed
446 447 448 449 450 451 452 453 454
        if (const QmlEnumValue *e = it->_enums.value(typeName)) {
            if (foundInScope)
                *foundInScope = it;
            return e;
        }
    }
    if (foundInScope)
        *foundInScope = 0;
    return 0;
455 456
}

457
const ObjectValue *CppComponentValue::signalScope(const QString &signalName) const
458
{
459 460 461
#if QT_VERSION >= 0x050000
    QHash<QString, const ObjectValue *> *scopes = _signalScopes.load();
#else
462
    QHash<QString, const ObjectValue *> *scopes = _signalScopes;
463
#endif
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
    if (!scopes) {
        scopes = new QHash<QString, const ObjectValue *>;
        // usually not all methods are signals
        scopes->reserve(_metaObject->methodCount() / 2);
        for (int index = 0; index < _metaObject->methodCount(); ++index) {
            const FakeMetaMethod &method = _metaObject->method(index);
            if (method.methodType() != FakeMetaMethod::Signal || method.access() == FakeMetaMethod::Private)
                continue;

            const QStringList &parameterNames = method.parameterNames();
            const QStringList &parameterTypes = method.parameterTypes();
            QTC_ASSERT(parameterNames.size() == parameterTypes.size(), continue);

            ObjectValue *scope = valueOwner()->newObject(/*prototype=*/0);
            for (int i = 0; i < parameterNames.size(); ++i) {
                const QString &name = parameterNames.at(i);
                const QString &type = parameterTypes.at(i);
                if (name.isEmpty())
                    continue;
                scope->setMember(name, valueForCppName(type));
            }
            scopes->insert(generatedSlotName(method.methodName()), scope);
        }
        if (!_signalScopes.testAndSetOrdered(0, scopes)) {
488
            delete scopes;
489 490 491
#if QT_VERSION >= 0x050000
            scopes = _signalScopes.load();
#else
492
            scopes = _signalScopes;
493
#endif
494 495 496 497 498 499
        }
    }

    return scopes->value(signalName);
}

500
bool CppComponentValue::isWritable(const QString &propertyName) const
501
{
502
    foreach (const CppComponentValue *it, prototypes()) {
503
        FakeMetaObject::ConstPtr iter = it->_metaObject;
504
        int propIdx = iter->propertyIndex(propertyName);
505
        if (propIdx != -1)
506 507 508 509 510
            return iter->property(propIdx).isWritable();
    }
    return false;
}

511
bool CppComponentValue::isPointer(const QString &propertyName) const
512
{
513
    foreach (const CppComponentValue *it, prototypes()) {
514
        FakeMetaObject::ConstPtr iter = it->_metaObject;
515
        int propIdx = iter->propertyIndex(propertyName);
516
        if (propIdx != -1)
517 518 519 520 521
            return iter->property(propIdx).isPointer();
    }
    return false;
}

522
bool CppComponentValue::hasLocalProperty(const QString &typeName) const
523 524 525 526 527 528 529
{
    int idx = _metaObject->propertyIndex(typeName);
    if (idx == -1)
        return false;
    return true;
}

530
bool CppComponentValue::hasProperty(const QString &propertyName) const
531
{
532
    foreach (const CppComponentValue *it, prototypes()) {
533
        FakeMetaObject::ConstPtr iter = it->_metaObject;
534
        int propIdx = iter->propertyIndex(propertyName);
535
        if (propIdx != -1)
536 537 538 539 540
            return true;
    }
    return false;
}

541
bool CppComponentValue::isDerivedFrom(FakeMetaObject::ConstPtr base) const
542
{
543
    foreach (const CppComponentValue *it, prototypes()) {
544
        FakeMetaObject::ConstPtr iter = it->_metaObject;
545 546 547 548 549 550
        if (iter == base)
            return true;
    }
    return false;
}

551
QmlEnumValue::QmlEnumValue(const CppComponentValue *owner, int enumIndex)
552 553
    : _owner(owner)
    , _enumIndex(enumIndex)
Christian Kamm's avatar
Christian Kamm committed
554
{
555
    owner->valueOwner()->registerValue(this);
Christian Kamm's avatar
Christian Kamm committed
556 557 558 559 560 561
}

QmlEnumValue::~QmlEnumValue()
{
}

Christian Kamm's avatar
Christian Kamm committed
562 563 564 565 566
const QmlEnumValue *QmlEnumValue::asQmlEnumValue() const
{
    return this;
}

Christian Kamm's avatar
Christian Kamm committed
567 568
QString QmlEnumValue::name() const
{
569
    return _owner->metaObject()->enumerator(_enumIndex).name();
Christian Kamm's avatar
Christian Kamm committed
570 571 572 573
}

QStringList QmlEnumValue::keys() const
{
574 575 576
    return _owner->metaObject()->enumerator(_enumIndex).keys();
}

577
const CppComponentValue *QmlEnumValue::owner() const
578 579
{
    return _owner;
Christian Kamm's avatar
Christian Kamm committed
580 581
}

582 583 584
////////////////////////////////////////////////////////////////////////////////
// ValueVisitor
////////////////////////////////////////////////////////////////////////////////
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
ValueVisitor::ValueVisitor()
{
}

ValueVisitor::~ValueVisitor()
{
}

void ValueVisitor::visit(const NullValue *)
{
}

void ValueVisitor::visit(const UndefinedValue *)
{
}

601 602 603 604
void ValueVisitor::visit(const UnknownValue *)
{
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
void ValueVisitor::visit(const NumberValue *)
{
}

void ValueVisitor::visit(const BooleanValue *)
{
}

void ValueVisitor::visit(const StringValue *)
{
}

void ValueVisitor::visit(const ObjectValue *)
{
}

void ValueVisitor::visit(const FunctionValue *)
{
}
624

Roberto Raggi's avatar
Roberto Raggi committed
625 626 627
void ValueVisitor::visit(const Reference *)
{
}
628

629 630 631 632
void ValueVisitor::visit(const ColorValue *)
{
}

633 634 635 636
void ValueVisitor::visit(const AnchorLineValue *)
{
}

637 638 639
////////////////////////////////////////////////////////////////////////////////
// Value
////////////////////////////////////////////////////////////////////////////////
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
640 641 642 643 644 645 646 647
Value::Value()
{
}

Value::~Value()
{
}

648 649 650 651 652
bool Value::getSourceLocation(QString *, int *, int *) const
{
    return false;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
653 654 655 656 657 658 659 660 661 662
const NullValue *Value::asNullValue() const
{
    return 0;
}

const UndefinedValue *Value::asUndefinedValue() const
{
    return 0;
}

663 664 665 666 667
const UnknownValue *Value::asUnknownValue() const
{
    return 0;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
668 669 670 671 672
const NumberValue *Value::asNumberValue() const
{
    return 0;
}

673 674 675 676 677 678 679 680 681 682
const IntValue *Value::asIntValue() const
{
    return 0;
}

const RealValue *Value::asRealValue() const
{
    return 0;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
683 684 685 686 687 688 689 690 691 692
const BooleanValue *Value::asBooleanValue() const
{
    return 0;
}

const StringValue *Value::asStringValue() const
{
    return 0;
}

Christian Kamm's avatar
Christian Kamm committed
693 694 695 696 697
const UrlValue *Value::asUrlValue() const
{
    return 0;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
698 699 700 701 702 703 704 705 706
const ObjectValue *Value::asObjectValue() const
{
    return 0;
}

const FunctionValue *Value::asFunctionValue() const
{
    return 0;
}
707

Roberto Raggi's avatar
Roberto Raggi committed
708 709 710 711 712
const Reference *Value::asReference() const
{
    return 0;
}

713 714 715 716 717
const ColorValue *Value::asColorValue() const
{
    return 0;
}

718 719 720 721 722
const AnchorLineValue *Value::asAnchorLineValue() const
{
    return 0;
}

Christian Kamm's avatar
Christian Kamm committed
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
const CppComponentValue *Value::asCppComponentValue() const
{
    return 0;
}

const ASTObjectValue *Value::asAstObjectValue() const
{
    return 0;
}

const QmlEnumValue *Value::asQmlEnumValue() const
{
    return 0;
}

const QmlPrototypeReference *Value::asQmlPrototypeReference() const
{
    return 0;
}

const ASTPropertyReference *Value::asAstPropertyReference() const
{
    return 0;
}

748 749 750 751 752
const ASTSignal *Value::asAstSignal() const
{
    return 0;
}

753 754 755
////////////////////////////////////////////////////////////////////////////////
// Values
////////////////////////////////////////////////////////////////////////////////
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770
const NullValue *NullValue::asNullValue() const
{
    return this;
}

void NullValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

const UndefinedValue *UndefinedValue::asUndefinedValue() const
{
    return this;
}

771
void UnknownValue::accept(ValueVisitor *visitor) const
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
772 773 774
{
    visitor->visit(this);
}
775

776 777 778 779 780 781 782 783 784
const UnknownValue *UnknownValue::asUnknownValue() const
{
    return this;
}

void UndefinedValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
785 786 787 788 789
const NumberValue *NumberValue::asNumberValue() const
{
    return this;
}

790 791 792 793 794 795 796 797 798 799
const RealValue *RealValue::asRealValue() const
{
    return this;
}

const IntValue *IntValue::asIntValue() const
{
    return this;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819
void NumberValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

const BooleanValue *BooleanValue::asBooleanValue() const
{
    return this;
}

void BooleanValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

const StringValue *StringValue::asStringValue() const
{
    return this;
}

Christian Kamm's avatar
Christian Kamm committed
820 821 822 823 824
const UrlValue *UrlValue::asUrlValue() const
{
    return this;
}

Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
825 826 827 828 829
void StringValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

830 831
Reference::Reference(ValueOwner *valueOwner)
    : _valueOwner(valueOwner)
Roberto Raggi's avatar
Roberto Raggi committed
832
{
833
    _valueOwner->registerValue(this);
Roberto Raggi's avatar
Roberto Raggi committed
834 835 836 837 838 839
}

Reference::~Reference()
{
}

840
ValueOwner *Reference::valueOwner() const
841
{
842
    return _valueOwner;
843 844
}

Roberto Raggi's avatar
Roberto Raggi committed
845 846 847 848 849 850 851 852 853 854
const Reference *Reference::asReference() const
{
    return this;
}

void Reference::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

855
const Value *Reference::value(ReferenceContext *) const
856
{
857
    return _valueOwner->undefinedValue();
858
}
Roberto Raggi's avatar
Roberto Raggi committed
859

860 861 862 863 864 865 866 867 868 869
void ColorValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

const ColorValue *ColorValue::asColorValue() const
{
    return this;
}

870 871 872 873 874 875 876 877 878 879
void AnchorLineValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

const AnchorLineValue *AnchorLineValue::asAnchorLineValue() const
{
    return this;
}

880 881 882 883 884 885 886 887 888 889 890 891 892
MemberProcessor::MemberProcessor()
{
}

MemberProcessor::~MemberProcessor()
{
}

bool MemberProcessor::processProperty(const QString &, const Value *)
{
    return true;
}

893 894 895 896 897
bool MemberProcessor::processEnumerator(const QString &, const Value *)
{
    return true;
}

898 899 900 901 902 903 904 905 906 907
bool MemberProcessor::processSignal(const QString &, const Value *)
{
    return true;
}

bool MemberProcessor::processSlot(const QString &, const Value *)
{
    return true;
}

908 909 910 911 912
bool MemberProcessor::processGeneratedSlot(const QString &, const Value *)
{
    return true;
}

913 914
ObjectValue::ObjectValue(ValueOwner *valueOwner)
    : _valueOwner(valueOwner),
915
      _prototype(0)
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
916
{
917
    valueOwner->registerValue(this);
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
918 919 920 921 922 923
}

ObjectValue::~ObjectValue()
{
}

924
ValueOwner *ObjectValue::valueOwner() const
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
925
{
926
    return _valueOwner;
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
927 928 929 930 931 932 933 934 935 936 937 938
}

QString ObjectValue::className() const
{
    return _className;
}

void ObjectValue::setClassName(const QString &className)
{
    _className = className;
}

939 940 941 942 943
const Value *ObjectValue::prototype() const
{
    return _prototype;
}

944
const ObjectValue *ObjectValue::prototype(const Context *context) const
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
945
{
Christian Kamm's avatar
Christian Kamm committed
946
    const ObjectValue *prototypeObject = value_cast<ObjectValue>(_prototype);
947
    if (! prototypeObject) {
948
        if (const Reference *prototypeReference = value_cast<Reference>(_prototype))
Christian Kamm's avatar
Christian Kamm committed
949
            prototypeObject = value_cast<ObjectValue>(context->lookupReference(prototypeReference));
950 951 952 953 954 955 956
    }
    return prototypeObject;
}

void ObjectValue::setPrototype(const Value *prototype)
{
    _prototype = prototype;
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
957 958
}

959
void ObjectValue::setMember(const QString &name, const Value *value)
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
960 961 962 963
{
    _members[name] = value;
}

964
void ObjectValue::removeMember(const QString &name)
Roberto Raggi's avatar
Cleanup  
Roberto Raggi committed
965 966 967 968 969 970 971 972 973 974 975 976 977 978
{
    _members.remove(name);
}

const ObjectValue *ObjectValue::asObjectValue() const
{
    return this;
}

void ObjectValue::accept(ValueVisitor *visitor) const
{
    visitor->visit(this);
}

979
bool ObjectValue::checkPrototype(const ObjectValue *, QSet<const ObjectValue *> *) const