qmljsinterpreter.h 22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/

#ifndef QMLJS_INTERPRETER_H
#define QMLJS_INTERPRETER_H

33
#include <qmljs/qmljsdocument.h>
34
35
#include <qmljs/qmljs_global.h>
#include <qmljs/qmljsmetatypesystem.h>
36
#include <qmljs/parser/qmljsastfwd_p.h>
37
38
39
40
41
42
43

#include <QtCore/QList>
#include <QtCore/QString>
#include <QtCore/QHash>
#include <QtCore/QSet>

namespace QmlJS {
44
45

class NameId;
46
class Document;
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
namespace Interpreter {

////////////////////////////////////////////////////////////////////////////////
// Forward declarations
////////////////////////////////////////////////////////////////////////////////
class Engine;
class Value;
class NullValue;
class UndefinedValue;
class NumberValue;
class BooleanValue;
class StringValue;
class ObjectValue;
class FunctionValue;
Roberto Raggi's avatar
Roberto Raggi committed
62
class Reference;
63
class EasingCurveNameValue;
64

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
65
66
typedef QList<const Value *> ValueList;

67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
////////////////////////////////////////////////////////////////////////////////
// Value visitor
////////////////////////////////////////////////////////////////////////////////
class QMLJS_EXPORT ValueVisitor
{
public:
    ValueVisitor();
    virtual ~ValueVisitor();

    virtual void visit(const NullValue *);
    virtual void visit(const UndefinedValue *);
    virtual void visit(const NumberValue *);
    virtual void visit(const BooleanValue *);
    virtual void visit(const StringValue *);
    virtual void visit(const ObjectValue *);
    virtual void visit(const FunctionValue *);
Roberto Raggi's avatar
Roberto Raggi committed
83
    virtual void visit(const Reference *);
84
    virtual void visit(const EasingCurveNameValue *);
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
};

////////////////////////////////////////////////////////////////////////////////
// QML/JS value
////////////////////////////////////////////////////////////////////////////////
class QMLJS_EXPORT Value
{
    Value(const Value &other);
    void operator = (const Value &other);

public:
    Value();
    virtual ~Value();

    virtual const NullValue *asNullValue() const;
    virtual const UndefinedValue *asUndefinedValue() const;
    virtual const NumberValue *asNumberValue() const;
    virtual const BooleanValue *asBooleanValue() const;
    virtual const StringValue *asStringValue() const;
    virtual const ObjectValue *asObjectValue() const;
    virtual const FunctionValue *asFunctionValue() const;
Roberto Raggi's avatar
Roberto Raggi committed
106
    virtual const Reference *asReference() const;
107
    virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
108
109

    virtual void accept(ValueVisitor *) const = 0;
110
111

    virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
};

template <typename _RetTy> _RetTy value_cast(const Value *v);

template <> Q_INLINE_TEMPLATE const NullValue *value_cast(const Value *v)
{
    if (v) return v->asNullValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const UndefinedValue *value_cast(const Value *v)
{
    if (v) return v->asUndefinedValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const NumberValue *value_cast(const Value *v)
{
    if (v) return v->asNumberValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const BooleanValue *value_cast(const Value *v)
{
    if (v) return v->asBooleanValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const StringValue *value_cast(const Value *v)
{
    if (v) return v->asStringValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const ObjectValue *value_cast(const Value *v)
{
    if (v) return v->asObjectValue();
    else   return 0;
}

template <> Q_INLINE_TEMPLATE const FunctionValue *value_cast(const Value *v)
{
    if (v) return v->asFunctionValue();
    else   return 0;
}

Roberto Raggi's avatar
Roberto Raggi committed
158
159
160
161
162
163
template <> Q_INLINE_TEMPLATE const Reference *value_cast(const Value *v)
{
    if (v) return v->asReference();
    else   return 0;
}

164
165
166
167
168
169
template <> Q_INLINE_TEMPLATE const EasingCurveNameValue *value_cast(const Value *v)
{
    if (v) return v->asEasingCurveNameValue();
    else   return 0;
}

170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
////////////////////////////////////////////////////////////////////////////////
// Value nodes
////////////////////////////////////////////////////////////////////////////////
class QMLJS_EXPORT NullValue: public Value
{
public:
    virtual const NullValue *asNullValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

class QMLJS_EXPORT UndefinedValue: public Value
{
public:
    virtual const UndefinedValue *asUndefinedValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

class QMLJS_EXPORT NumberValue: public Value
{
public:
    virtual const NumberValue *asNumberValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

class QMLJS_EXPORT BooleanValue: public Value
{
public:
    virtual const BooleanValue *asBooleanValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

class QMLJS_EXPORT StringValue: public Value
{
public:
    virtual const StringValue *asStringValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
208
209
210
211
212
213
class QMLJS_EXPORT MemberProcessor
{
    MemberProcessor(const MemberProcessor &other);
    void operator = (const MemberProcessor &other);

public:
214
215
    MemberProcessor();
    virtual ~MemberProcessor();
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
216
217

    // Returns false to stop the processor.
218
    virtual bool processProperty(const QString &name, const Value *value);
219
    virtual bool processEnumerator(const QString &name, const Value *value);
220
221
    virtual bool processSignal(const QString &name, const Value *value);
    virtual bool processSlot(const QString &name, const Value *value);
222
    virtual bool processGeneratedSlot(const QString &name, const Value *value);
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
223
224
};

225
class QMLJS_EXPORT ScopeChain
Roberto Raggi's avatar
Roberto Raggi committed
226
{
227
public:
228
229
230
231
    ScopeChain();

    struct QmlComponentChain
    {
232
233
        QmlComponentChain();
        ~QmlComponentChain();
234

235
236
237
238
239
240
        QList<QmlComponentChain *> instantiatingComponents;
        const ObjectValue *rootObject;
        QList<const ObjectValue *> functionScopes;
        const ObjectValue *ids;

        void add(QList<const ObjectValue *> *list) const;
241
        void clear();
242
243
244
245
246
247
248
249
250
251
    };

    const ObjectValue *globalScope;
    QmlComponentChain qmlComponentScope;
    QList<const ObjectValue *> qmlScopeObjects;
    const ObjectValue *qmlTypes;
    QList<const ObjectValue *> jsScopes;

    // rebuilds the flat list of all scopes
    void update();
252
253
254
255
    QList<const ObjectValue *> all() const;

private:
    QList<const ObjectValue *> _all;
256
257
258
259
260
};

class QMLJS_EXPORT Context
{
public:
261
262
263
264
265
    enum LookupMode {
        JSLookup,
        QmlLookup
    };

Roberto Raggi's avatar
Roberto Raggi committed
266
267
public:
    Context(Engine *engine);
268
    ~Context();
Roberto Raggi's avatar
Roberto Raggi committed
269

270
    void build(const QList<AST::Node *> &astPath, const Document::Ptr doc, const Snapshot &snapshot);
271

Roberto Raggi's avatar
Roberto Raggi committed
272
    Engine *engine() const;
273
274
    const ScopeChain &scopeChain() const;
    ScopeChain &scopeChain();
275
276
277
278

    LookupMode lookupMode() const;
    void setLookupMode(LookupMode lookupMode);

279
280
    const ObjectValue *typeEnvironment(const Document *doc) const;
    void setTypeEnvironment(const Document *doc, const ObjectValue *typeEnvironment);
281
282

    const Value *lookup(const QString &name);
283
    const ObjectValue *lookupType(const Document *doc, AST::UiQualifiedId *qmlTypeName);
Roberto Raggi's avatar
Roberto Raggi committed
284
285
286
287
288
289
290
291

    const Value *property(const ObjectValue *object, const QString &name) const;
    void setProperty(const ObjectValue *object, const QString &name, const Value *value);

private:
    typedef QHash<QString, const Value *> Properties;

    Engine *_engine;
292
    LookupMode _lookupMode;
Roberto Raggi's avatar
Roberto Raggi committed
293
    QHash<const ObjectValue *, Properties> _properties;
294
    QHash<const Document *, const ObjectValue *> _typeEnvironments;
Christian Kamm's avatar
Christian Kamm committed
295
296
297
    ScopeChain _scopeChain;
    int _qmlScopeObjectIndex;
    bool _qmlScopeObjectSet;
Roberto Raggi's avatar
Roberto Raggi committed
298
299
300
301
302
};

class QMLJS_EXPORT Reference: public Value
{
public:
303
    Reference(Engine *engine);
Roberto Raggi's avatar
Roberto Raggi committed
304
305
    virtual ~Reference();

306
307
    Engine *engine() const;
    virtual const Value *value(Context *context) const;
Roberto Raggi's avatar
Roberto Raggi committed
308
309
310
311

    // Value interface
    virtual const Reference *asReference() const;
    virtual void accept(ValueVisitor *) const;
312
313
314

private:
    Engine *_engine;
Roberto Raggi's avatar
Roberto Raggi committed
315
316
};

317
318
319
320
321
322
323
324
325
326
327
328
class QMLJS_EXPORT EasingCurveNameValue: public Value
{
    static QSet<QString> _curveNames;

public:
    static QSet<QString> curveNames();

    // Value interface
    virtual const EasingCurveNameValue *asEasingCurveNameValue() const;
    virtual void accept(ValueVisitor *) const;
};

329
class QMLJS_EXPORT ObjectValue: public Value
330
331
332
{
public:
    ObjectValue(Engine *engine);
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
333
    virtual ~ObjectValue();
334
335
336
337
338
339

    Engine *engine() const;

    QString className() const;
    void setClassName(const QString &className);

340
341
    const ObjectValue *prototype(Context *context) const;
    void setPrototype(const Value *prototype);
342

Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
343
    virtual void processMembers(MemberProcessor *processor) const;
344

345
    virtual const Value *property(const QString &name, Context *context) const;
346
347
348
    virtual void setProperty(const QString &name, const Value *value);
    virtual void removeProperty(const QString &name);

349
    virtual const Value *lookupMember(const QString &name, Context *context) const;
350
351
352
353
354
355

    // Value interface
    virtual const ObjectValue *asObjectValue() const;
    virtual void accept(ValueVisitor *visitor) const;

private:
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
356
    bool checkPrototype(const ObjectValue *prototype, QSet<const ObjectValue *> *processed) const;
357
358
359

private:
    Engine *_engine;
360
    const Value *_prototype;
361
362
363
364
    QHash<QString, const Value *> _members;
    QString _className;
};

365
366
367
368
369
370
371
372
#ifndef NO_DECLARATIVE_BACKEND

class QmlObjectValue: public ObjectValue
{
public:
    QmlObjectValue(const QMetaObject *metaObject, const QString &qmlTypeName, int majorVersion, int minorVersion, Engine *engine);
    virtual ~QmlObjectValue();

373
    virtual const Value *lookupMember(const QString &name, Context *context) const;
374
375
376
377
378
379
380
381
382
383
384
385
    virtual void processMembers(MemberProcessor *processor) const;
    const Value *propertyValue(const QMetaProperty &prop) const;

    QString qmlTypeName() const
    { return _qmlTypeName; }

    int majorVersion() const
    { return _majorVersion; }

    int minorVersion() const
    { return _minorVersion; }

Roberto Raggi's avatar
Roberto Raggi committed
386
387
protected:
    const Value *findOrCreateSignature(int index, const QMetaMethod &method, QString *methodName) const;
388
    bool isDerivedFrom(const QMetaObject *base) const;
Roberto Raggi's avatar
Roberto Raggi committed
389

390
391
392
393
394
private:
    const QMetaObject *_metaObject;
    QString _qmlTypeName;
    int _majorVersion;
    int _minorVersion;
Roberto Raggi's avatar
Roberto Raggi committed
395
    mutable QHash<int, const Value *> _metaSignature;
396
397
398
399
};

#endif // !NO_DECLARATIVE_BACKEND

400
class QMLJS_EXPORT Activation
Roberto Raggi's avatar
Roberto Raggi committed
401
402
{
public:
403
    explicit Activation(Context *parentContext = 0);
Roberto Raggi's avatar
Roberto Raggi committed
404
405
    virtual ~Activation();

406
407
408
    Context *context() const;
    Context *parentContext() const;

Roberto Raggi's avatar
Roberto Raggi committed
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
    bool calledAsConstructor() const;
    void setCalledAsConstructor(bool calledAsConstructor);

    bool calledAsFunction() const;
    void setCalledAsFunction(bool calledAsFunction);

    ObjectValue *thisObject() const;
    void setThisObject(ObjectValue *thisObject);

    ValueList arguments() const;
    void setArguments(const ValueList &arguments);

private:
    ObjectValue *_thisObject;
    ValueList _arguments;
    bool _calledAsFunction;
425
    Context *_parentContext;
Roberto Raggi's avatar
Roberto Raggi committed
426
427
428
};


429
430
431
432
class QMLJS_EXPORT FunctionValue: public ObjectValue
{
public:
    FunctionValue(Engine *engine);
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
433
434
435
436
437
438
439
440
441
442
443
    virtual ~FunctionValue();

    // [[construct]]
    const Value *construct(const ValueList &actuals = ValueList()) const;

    // [[call]]
    const Value *call(const ValueList &actuals = ValueList()) const;

    const Value *call(const ObjectValue *thisObject,
                      const ValueList &actuals = ValueList()) const;

444
445
446
447

    virtual const Value *returnValue() const;

    virtual int argumentCount() const;
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
448
    virtual const Value *argument(int index) const;
449
450
    virtual QString argumentName(int index) const;
    virtual bool isVariadic() const;
451

Roberto Raggi's avatar
Roberto Raggi committed
452
    virtual const Value *invoke(const Activation *activation) const;
453
454
455
456
457
458
459
460
461
462

    // Value interface
    virtual const FunctionValue *asFunctionValue() const;
    virtual void accept(ValueVisitor *visitor) const;
};

class QMLJS_EXPORT Function: public FunctionValue
{
public:
    Function(Engine *engine);
Roberto Raggi's avatar
Roberto Raggi committed
463
    virtual ~Function();
464

465
    void addArgument(const Value *argument);
466
467
468
    void setReturnValue(const Value *returnValue);

    // ObjectValue interface
469
    virtual const Value *property(const QString &name, Context *context) const;
470
471
472
473
474

    // FunctionValue interface
    virtual const Value *returnValue() const;
    virtual int argumentCount() const;
    virtual const Value *argument(int index) const;
Roberto Raggi's avatar
Roberto Raggi committed
475
    virtual const Value *invoke(const Activation *activation) const;
476
477

private:
Roberto Raggi's avatar
Cleanup    
Roberto Raggi committed
478
    ValueList _arguments;
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
    const Value *_returnValue;
};


////////////////////////////////////////////////////////////////////////////////
// typing environment
////////////////////////////////////////////////////////////////////////////////

class ConvertToNumber: protected ValueVisitor // ECMAScript ToInt()
{
public:
    ConvertToNumber(Engine *engine);

    const Value *operator()(const Value *value);

protected:
    const Value *switchResult(const Value *value);

    virtual void visit(const NullValue *);
    virtual void visit(const UndefinedValue *);
    virtual void visit(const NumberValue *);
    virtual void visit(const BooleanValue *);
    virtual void visit(const StringValue *);
    virtual void visit(const ObjectValue *);
    virtual void visit(const FunctionValue *);

private:
    Engine *_engine;
    const Value *_result;
};

class ConvertToString: protected ValueVisitor // ECMAScript ToString
{
public:
    ConvertToString(Engine *engine);

    const Value *operator()(const Value *value);

protected:
    const Value *switchResult(const Value *value);

    virtual void visit(const NullValue *);
    virtual void visit(const UndefinedValue *);
    virtual void visit(const NumberValue *);
    virtual void visit(const BooleanValue *);
    virtual void visit(const StringValue *);
    virtual void visit(const ObjectValue *);
    virtual void visit(const FunctionValue *);

private:
    Engine *_engine;
    const Value *_result;
};

class ConvertToObject: protected ValueVisitor // ECMAScript ToObject
{
public:
    ConvertToObject(Engine *engine);

    const Value *operator()(const Value *value);

protected:
    const Value *switchResult(const Value *value);

    virtual void visit(const NullValue *);
    virtual void visit(const UndefinedValue *);
    virtual void visit(const NumberValue *);
    virtual void visit(const BooleanValue *);
    virtual void visit(const StringValue *);
    virtual void visit(const ObjectValue *);
    virtual void visit(const FunctionValue *);

private:
    Engine *_engine;
    const Value *_result;
};

class TypeId: protected ValueVisitor
{
    QString _result;

public:
    QString operator()(const Value *value);

protected:
    virtual void visit(const NullValue *);
    virtual void visit(const UndefinedValue *);
    virtual void visit(const NumberValue *);
    virtual void visit(const BooleanValue *);
    virtual void visit(const StringValue *);
    virtual void visit(const ObjectValue *object);
    virtual void visit(const FunctionValue *object);
};

class QMLJS_EXPORT Engine
{
    Engine(const Engine &other);
    void operator = (const Engine &other);

public:
    Engine();
    ~Engine();

    const NullValue *nullValue() const;
    const UndefinedValue *undefinedValue() const;
    const NumberValue *numberValue() const;
    const BooleanValue *booleanValue() const;
    const StringValue *stringValue() const;
587
    const EasingCurveNameValue *easingCurveNameValue() const;
588

Roberto Raggi's avatar
Roberto Raggi committed
589
    ObjectValue *newObject(const ObjectValue *prototype);
590
591
    ObjectValue *newObject();
    Function *newFunction();
Roberto Raggi's avatar
Roberto Raggi committed
592
    const Value *newArray(); // ### remove me
593

Roberto Raggi's avatar
Roberto Raggi committed
594
    // QML objects
595
    const ObjectValue *qmlKeysObject();
596
    const Value *defaultValueForBuiltinType(const QString &typeName) const;
597
598
599
#ifndef NO_DECLARATIVE_BACKEND
    QmlObjectValue *newQmlObject(const QString &name, const QString &prefix, int majorVersion, int minorVersion);
#endif
Roberto Raggi's avatar
Roberto Raggi committed
600

601
602
603
    // global object
    ObjectValue *globalObject() const;
    const ObjectValue *mathObject() const;
604
    const ObjectValue *qtObject() const;
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

    // prototypes
    ObjectValue *objectPrototype() const;
    ObjectValue *functionPrototype() const;
    ObjectValue *numberPrototype() const;
    ObjectValue *booleanPrototype() const;
    ObjectValue *stringPrototype() const;
    ObjectValue *arrayPrototype() const;
    ObjectValue *datePrototype() const;
    ObjectValue *regexpPrototype() const;

    // ctors
    const FunctionValue *objectCtor() const;
    const FunctionValue *functionCtor() const;
    const FunctionValue *arrayCtor() const;
    const FunctionValue *stringCtor() const;
    const FunctionValue *booleanCtor() const;
    const FunctionValue *numberCtor() const;
    const FunctionValue *dateCtor() const;
    const FunctionValue *regexpCtor() const;

    // operators
Roberto Raggi's avatar
Roberto Raggi committed
627
    const Value *convertToBoolean(const Value *value);
628
629
630
631
632
    const Value *convertToNumber(const Value *value);
    const Value *convertToString(const Value *value);
    const Value *convertToObject(const Value *value);
    QString typeId(const Value *value);

633
634
635
636
    // typing:
    const MetaTypeSystem &metaTypeSystem() const
    { return _metaTypeSystem; }

637
638
    void registerValue(Value *value); // internal

639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
private:
    void initializePrototypes();

    void addFunction(ObjectValue *object, const QString &name, const Value *result, int argumentCount);
    void addFunction(ObjectValue *object, const QString &name, int argumentCount);

private:
    ObjectValue *_objectPrototype;
    ObjectValue *_functionPrototype;
    ObjectValue *_numberPrototype;
    ObjectValue *_booleanPrototype;
    ObjectValue *_stringPrototype;
    ObjectValue *_arrayPrototype;
    ObjectValue *_datePrototype;
    ObjectValue *_regexpPrototype;

    Function *_objectCtor;
    Function *_functionCtor;
    Function *_arrayCtor;
    Function *_stringCtor;
    Function *_booleanCtor;
    Function *_numberCtor;
    Function *_dateCtor;
    Function *_regexpCtor;

    ObjectValue *_globalObject;
    ObjectValue *_mathObject;
666
    ObjectValue *_qtObject;
667
#ifndef NO_DECLARATIVE_BACKEND
668
    ObjectValue *_qmlKeysObject;
669
#endif
670
671
672
673
674
675

    NullValue _nullValue;
    UndefinedValue _undefinedValue;
    NumberValue _numberValue;
    BooleanValue _booleanValue;
    StringValue _stringValue;
676
    EasingCurveNameValue _easingCurveNameValue;
677
    QList<Value *> _registeredValues;
678
679
680
681
682

    ConvertToNumber _convertToNumber;
    ConvertToString _convertToString;
    ConvertToObject _convertToObject;
    TypeId _typeId;
683
684

    MetaTypeSystem _metaTypeSystem;
685
686
};

687
688

// internal
689
690
691
class QMLJS_EXPORT QmlPrototypeReference: public Reference
{
public:
692
    QmlPrototypeReference(AST::UiQualifiedId *qmlTypeName, const Document *doc, Engine *engine);
693
694
695
696
697
698
699
700
    virtual ~QmlPrototypeReference();

    AST::UiQualifiedId *qmlTypeName() const;

    virtual const Value *value(Context *context) const;

private:
    AST::UiQualifiedId *_qmlTypeName;
701
    const Document *_doc;
702
703
};

704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
class QMLJS_EXPORT ASTVariableReference: public Reference
{
    AST::VariableDeclaration *_ast;

public:
    ASTVariableReference(AST::VariableDeclaration *ast, Engine *engine);
    virtual ~ASTVariableReference();

    virtual const Value *value(Context *context) const;
};

class QMLJS_EXPORT ASTFunctionValue: public FunctionValue
{
    AST::FunctionDeclaration *_ast;
    QList<NameId *> _argumentNames;

public:
    ASTFunctionValue(AST::FunctionDeclaration *ast, Engine *engine);
    virtual ~ASTFunctionValue();

    AST::FunctionDeclaration *ast() const;

    virtual const Value *returnValue() const;
    virtual int argumentCount() const;
    virtual const Value *argument(int) const;
    virtual QString argumentName(int index) const;
    virtual bool isVariadic() const;
};

733
734
735
736
class QMLJS_EXPORT ASTPropertyReference: public Reference
{
    AST::UiPublicMember *_ast;
    const Document *_doc;
737
    QString _onChangedSlotName;
738
739
740
741

public:
    ASTPropertyReference(AST::UiPublicMember *ast, const Document *doc, Engine *engine);
    virtual ~ASTPropertyReference();
742

743
    AST::UiPublicMember *ast() const { return _ast; }
744
    QString onChangedSlotName() const { return _onChangedSlotName; }
745
746
747
748
749

    virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
    virtual const Value *value(Context *context) const;
};

750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
class QMLJS_EXPORT ASTSignalReference: public Reference
{
    AST::UiPublicMember *_ast;
    const Document *_doc;
    QString _slotName;

public:
    ASTSignalReference(AST::UiPublicMember *ast, const Document *doc, Engine *engine);
    virtual ~ASTSignalReference();

    AST::UiPublicMember *ast() const { return _ast; }
    QString slotName() const { return _slotName; }

    virtual bool getSourceLocation(QString *fileName, int *line, int *column) const;
    virtual const Value *value(Context *context) const;
};

767
768
769
770
771
772
class QMLJS_EXPORT ASTObjectValue: public ObjectValue
{
    AST::UiQualifiedId *_typeName;
    AST::UiObjectInitializer *_initializer;
    const Document *_doc;
    QList<ASTPropertyReference *> _properties;
773
    QList<ASTSignalReference *> _signals;
774
775
776
777
778
779
780
781
782
783
784

public:
    ASTObjectValue(AST::UiQualifiedId *typeName,
                   AST::UiObjectInitializer *initializer,
                   const Document *doc,
                   Engine *engine);
    virtual ~ASTObjectValue();

    bool getSourceLocation(QString *fileName, int *line, int *column) const;
    virtual void processMembers(MemberProcessor *processor) const;
};
785

786
787
788
} } // end of namespace QmlJS::Interpreter

#endif // QMLJS_INTERPRETER_H