1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
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.
16 ** GNU Lesser General Public License Usage
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.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
32 #include <QtCore/QList>
33 #include <QtCore/QMap>
34 #include <QtCore/QPair>
35 #include <QtCore/QSharedPointer>
36 #include <QtCore/QString>
38 #include "parser/qmldirparser_p.h"
39 #include "parser/qmljsengine_p.h"
40 #include "qmljs_global.h"
47 namespace Interpreter {
51 class QMLJS_EXPORT Document
54 typedef QSharedPointer<Document> Ptr;
57 Document(const QString &fileName);
62 static Document::Ptr create(const QString &fileName);
64 bool isQmlDocument() const;
65 bool isJSDocument() const;
67 AST::UiProgram *qmlProgram() const;
68 AST::Program *jsProgram() const;
69 AST::ExpressionNode *expression() const;
70 AST::Node *ast() const;
72 QList<DiagnosticMessage> diagnosticMessages() const;
74 QString source() const;
75 void setSource(const QString &source);
79 bool parseJavaScript();
80 bool parseExpression();
82 bool isParsedCorrectly() const
83 { return _parsedCorrectly; }
87 int documentRevision() const;
88 void setDocumentRevision(int documentRevision);
90 QString fileName() const;
92 QString componentName() const;
95 bool parse_helper(int kind);
96 static void extractPragmas(QString *source);
99 QmlJS::Engine *_engine;
104 int _documentRevision;
105 bool _parsedCorrectly;
106 QList<QmlJS::DiagnosticMessage> _diagnosticMessages;
109 QString _componentName;
112 // for documentFromSource
113 friend class Snapshot;
116 class QMLJS_EXPORT LibraryInfo
119 QList<QmlDirParser::Component> _components;
120 QList<QmlDirParser::Plugin> _plugins;
121 typedef QList<const Interpreter::FakeMetaObject *> FakeMetaObjectList;
122 FakeMetaObjectList _metaObjects;
126 LibraryInfo(const QmlDirParser &parser);
129 QList<QmlDirParser::Component> components() const
130 { return _components; }
132 QList<QmlDirParser::Plugin> plugins() const
135 FakeMetaObjectList metaObjects() const
136 { return _metaObjects; }
138 void setMetaObjects(const FakeMetaObjectList &objects)
139 { _metaObjects = objects; }
145 class QMLJS_EXPORT Snapshot
147 typedef QHash<QString, Document::Ptr> _Base;
148 QHash<QString, Document::Ptr> _documents;
149 QMultiHash<QString, Document::Ptr> _documentsByPath;
150 QHash<QString, LibraryInfo> _libraries;
156 typedef _Base::iterator iterator;
157 typedef _Base::const_iterator const_iterator;
159 const_iterator begin() const { return _documents.begin(); }
160 const_iterator end() const { return _documents.end(); }
162 void insert(const Document::Ptr &document);
163 void insertLibraryInfo(const QString &path, const LibraryInfo &info);
164 void remove(const QString &fileName);
166 Document::Ptr document(const QString &fileName) const;
167 QList<Document::Ptr> documentsInDirectory(const QString &path) const;
168 LibraryInfo libraryInfo(const QString &path) const;
170 Document::Ptr documentFromSource(const QString &code,
171 const QString &fileName) const;
174 } // end of namespace Qml
176 #endif // QMLDOCUMENT_H