summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlbasicscript_p.h
blob: 43c0d36c809c59519a50dd33d356e72f0f282c9c (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the $MODULE$ of the Qt Toolkit.
**
** $TROLLTECH_DUAL_LICENSE$
**
****************************************************************************/

#ifndef QMLBASICSCRIPT_P_H
#define QMLBASICSCRIPT_P_H

#include <QtCore/QList>
#include <QtCore/QByteArray>
#include <QtCore/QVariant>
#include <private/qmlparser_p.h>

QT_BEGIN_HEADER

QT_BEGIN_NAMESPACE

class QmlRefCount;
class QmlContext;
class QmlBasicScriptPrivate;
class QmlBasicScriptNodeCache;
class QmlBasicScript
{
public:
    QmlBasicScript();
    QmlBasicScript(const char *, QmlRefCount * = 0);
    ~QmlBasicScript();

    // Always 4-byte aligned
    const char *compileData() const;
    unsigned int compileDataSize() const;

    QByteArray expression() const;

    struct Expression
    {
        QmlParser::Object *component;
        QmlParser::Object *context;
        QmlParser::Property *property;
        QmlParser::Variant expression;
        QHash<QString, QPair<QmlParser::Object *, int> > ids;
    };

    bool compile(const Expression &);
    bool isValid() const;

    void clear();

    void dump();
    void *newScriptState();
    void deleteScriptState(void *);

    enum CacheState { NoChange, Incremental, Reset };
    QVariant run(QmlContext *, void *, CacheState *);

    // Optimization opportunities
    bool isSingleLoad() const;
    QByteArray singleLoadTarget() const;

private:
    int flags;
    QmlBasicScriptPrivate *d;
    QmlRefCount *rc;

    void clearCache(void *);
    void guard(QmlBasicScriptNodeCache &);
    bool valid(QmlBasicScriptNodeCache &, QObject *);
};

class QmlContextPrivate;
class QDebug;
class QmlBasicScriptNodeCache
{
public:
    QObject *object;
    const QMetaObject *metaObject;
    enum { Invalid,
           Core, 
           Attached, 
           Signal,
           SignalProperty, 
           Variant
    } type;
    union {
        int core;
        QObject *attached;
        QmlContextPrivate *context;
    };
    int coreType;
    int contextIndex;

    bool isValid() const { return type != Invalid; }
    bool isCore() const { return type == Core; }
    bool isVariant() const { return type == Variant; }
    void clear();
    QVariant value(const char *) const;
};

QDebug operator<<(QDebug, const QmlBasicScriptNodeCache &);

QT_END_NAMESPACE

QT_END_HEADER

#endif // QMLBASICSCRIPT_P_H