qmljsdocument.h 3.42 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
33
34
35
36
37
38
/**************************************************************************
**
** 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 QMLDOCUMENT_H
#define QMLDOCUMENT_H

#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
#include <QtCore/QString>

#include "parser/qmljsengine_p.h"
39
#include "qmljs_global.h"
40

41
namespace QmlJS {
42

43
44
class Bind;

45
class QMLJS_EXPORT Document
46
47
{
public:
48
    typedef QSharedPointer<Document> Ptr;
49
50

protected:
51
    Document(const QString &fileName);
52
53

public:
54
    ~Document();
55

56
    static Document::Ptr create(const QString &fileName);
57

Roberto Raggi's avatar
Roberto Raggi committed
58
59
60
61
    AST::UiProgram *qmlProgram() const;
    AST::Program *jsProgram() const;
    AST::ExpressionNode *expression() const;
    AST::Node *ast() const;
62

Roberto Raggi's avatar
Roberto Raggi committed
63
    QList<DiagnosticMessage> diagnosticMessages() const;
64
65
66
67
68
69

    QString source() const;
    void setSource(const QString &source);

    bool parseQml();
    bool parseJavaScript();
70
    bool parseExpression();
71
72
73
74

    bool isParsedCorrectly() const
    { return _parsedCorrectly; }

Roberto Raggi's avatar
Roberto Raggi committed
75
    Bind *bind() const;
76

77
78
79
    int documentRevision() const;
    void setDocumentRevision(int documentRevision);

80
81
82
    QString fileName() const;
    QString path() const;
    QString componentName() const;
83

84
85
86
private:
    bool parse_helper(int kind);

87
88
private:
    QmlJS::Engine *_engine;
Roberto Raggi's avatar
Roberto Raggi committed
89
90
91
    NodePool *_pool;
    AST::Node *_ast;
    Bind *_bind;
92
93
    int _documentRevision;
    bool _parsedCorrectly;
94
95
96
97
98
99
100
    QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
    QString _fileName;
    QString _path;
    QString _componentName;
    QString _source;
};

101
class QMLJS_EXPORT Snapshot
102
{
103
104
105
    typedef QMap<QString, Document::Ptr> _Base;
    QMap<QString, Document::Ptr> _documents;

106
107
108
109
public:
    Snapshot();
    ~Snapshot();

110
111
112
113
114
115
    typedef _Base::iterator iterator;
    typedef _Base::const_iterator const_iterator;

    const_iterator begin() const { return _documents.begin(); }
    const_iterator end() const { return _documents.end(); }

116
    void insert(const Document::Ptr &document);
117

118
    Document::Ptr document(const QString &fileName) const
119
    { return _documents.value(fileName); }
120

Roberto Raggi's avatar
Roberto Raggi committed
121
    QList<Document::Ptr> importedDocuments(const Document::Ptr &doc, const QString &importPath) const;
122
    QMap<QString, Document::Ptr> componentsDefinedByImportedDocuments(const Document::Ptr &doc, const QString &importPath) const;
123
124
125
126
127
};

} // end of namespace Qml

#endif // QMLDOCUMENT_H