OSDN Git Service

compilation fix with namespaces
[qt-creator-jp/qt-creator-jp.git] / src / libs / qmljs / qmljsdocument.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** Commercial Usage
10 **
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 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
27 **
28 **************************************************************************/
29 #ifndef QMLDOCUMENT_H
30 #define QMLDOCUMENT_H
31
32 #include <QtCore/QList>
33 #include <QtCore/QMap>
34 #include <QtCore/QPair>
35 #include <QtCore/QSharedPointer>
36 #include <QtCore/QString>
37
38 #include "parser/qmldirparser_p.h"
39 #include "parser/qmljsengine_p.h"
40 #include "qmljs_global.h"
41
42 QT_QML_BEGIN_NAMESPACE
43
44 namespace QmlJS {
45
46 class Bind;
47 class Snapshot;
48
49 namespace Interpreter {
50     class FakeMetaObject;
51 }
52
53 class QMLJS_EXPORT Document
54 {
55 public:
56     typedef QSharedPointer<Document> Ptr;
57
58 protected:
59     Document(const QString &fileName);
60
61 public:
62     ~Document();
63
64     static Document::Ptr create(const QString &fileName);
65
66     bool isQmlDocument() const;
67     bool isJSDocument() const;
68
69     AST::UiProgram *qmlProgram() const;
70     AST::Program *jsProgram() const;
71     AST::ExpressionNode *expression() const;
72     AST::Node *ast() const;
73
74     QList<DiagnosticMessage> diagnosticMessages() const;
75
76     QString source() const;
77     void setSource(const QString &source);
78
79     bool parse();
80     bool parseQml();
81     bool parseJavaScript();
82     bool parseExpression();
83
84     bool isParsedCorrectly() const
85     { return _parsedCorrectly; }
86
87     Bind *bind() const;
88
89     int editorRevision() const;
90     void setEditorRevision(int revision);
91
92     QString fileName() const;
93     QString path() const;
94     QString componentName() const;
95
96 private:
97     bool parse_helper(int kind);
98     static void extractPragmas(QString *source);
99
100 private:
101     QmlJS::Engine *_engine;
102     NodePool *_pool;
103     AST::Node *_ast;
104     Bind *_bind;
105     bool _isQmlDocument;
106     int _editorRevision;
107     bool _parsedCorrectly;
108     QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
109     QString _fileName;
110     QString _path;
111     QString _componentName;
112     QString _source;
113
114     // for documentFromSource
115     friend class Snapshot;
116 };
117
118 class QMLJS_EXPORT LibraryInfo
119 {
120     bool _valid;
121     QList<QmlDirParser::Component> _components;
122     QList<QmlDirParser::Plugin> _plugins;
123     typedef QList<const Interpreter::FakeMetaObject *> FakeMetaObjectList;
124     FakeMetaObjectList _metaObjects;
125
126 public:
127     LibraryInfo();
128     LibraryInfo(const QmlDirParser &parser);
129     ~LibraryInfo();
130
131     QList<QmlDirParser::Component> components() const
132     { return _components; }
133
134     QList<QmlDirParser::Plugin> plugins() const
135     { return _plugins; }
136
137     FakeMetaObjectList metaObjects() const
138     { return _metaObjects; }
139
140     void setMetaObjects(const FakeMetaObjectList &objects)
141     { _metaObjects = objects; }
142
143     bool isValid() const
144     { return _valid; }
145 };
146
147 class QMLJS_EXPORT Snapshot
148 {
149     typedef QHash<QString, Document::Ptr> _Base;
150     QHash<QString, Document::Ptr> _documents;
151     QHash<QString, QList<Document::Ptr> > _documentsByPath;
152     QHash<QString, LibraryInfo> _libraries;
153
154 public:
155     Snapshot();
156     ~Snapshot();
157
158     typedef _Base::iterator iterator;
159     typedef _Base::const_iterator const_iterator;
160
161     const_iterator begin() const { return _documents.begin(); }
162     const_iterator end() const { return _documents.end(); }
163
164     void insert(const Document::Ptr &document);
165     void insertLibraryInfo(const QString &path, const LibraryInfo &info);
166     void remove(const QString &fileName);
167
168     Document::Ptr document(const QString &fileName) const;
169     QList<Document::Ptr> documentsInDirectory(const QString &path) const;
170     LibraryInfo libraryInfo(const QString &path) const;
171
172     Document::Ptr documentFromSource(const QString &code,
173                                      const QString &fileName) const;
174 };
175
176 } // namespace QmlJS
177
178 QT_QML_END_NAMESPACE
179
180 #endif // QMLDOCUMENT_H