1/****************************************************************************
2**
3** Copyright (C) 2019 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#ifndef TYPEDESCRIPTIONREADER_H
30#define TYPEDESCRIPTIONREADER_H
31
32//
33// W A R N I N G
34// -------------
35//
36// This file is not part of the Qt API. It exists purely as an
37// implementation detail. This header file may change from version to
38// version without notice, or even be removed.
39//
40// We mean it.
41
42#include "scopetree.h"
43
44#include <QtQml/private/qqmljsastfwd_p.h>
45
46// for Q_DECLARE_TR_FUNCTIONS
47#include <QtCore/qcoreapplication.h>
48
49struct ModuleApiInfo
50{
51 QString uri;
52 ComponentVersion version;
53 QString cppName;
54};
55
56class TypeDescriptionReader
57{
58 Q_DECLARE_TR_FUNCTIONS(TypeDescriptionReader)
59public:
60 TypeDescriptionReader() = default;
61 explicit TypeDescriptionReader(QString fileName, QString data)
62 : m_fileName(std::move(fileName)), m_source(std::move(data)) {}
63
64 bool operator()(
65 QHash<QString, ScopeTree::ConstPtr> *objects,
66 QList<ModuleApiInfo> *moduleApis,
67 QStringList *dependencies);
68
69 QString errorMessage() const { return m_errorMessage; }
70 QString warningMessage() const { return m_warningMessage; }
71
72private:
73 void readDocument(QQmlJS::AST::UiProgram *ast);
74 void readModule(QQmlJS::AST::UiObjectDefinition *ast);
75 void readDependencies(QQmlJS::AST::UiScriptBinding *ast);
76 void readComponent(QQmlJS::AST::UiObjectDefinition *ast);
77 void readModuleApi(QQmlJS::AST::UiObjectDefinition *ast);
78 void readSignalOrMethod(QQmlJS::AST::UiObjectDefinition *ast, bool isMethod,
79 const ScopeTree::Ptr &scope);
80 void readProperty(QQmlJS::AST::UiObjectDefinition *ast, const ScopeTree::Ptr &scope);
81 void readEnum(QQmlJS::AST::UiObjectDefinition *ast, const ScopeTree::Ptr &scope);
82 void readParameter(QQmlJS::AST::UiObjectDefinition *ast, MetaMethod *metaMethod);
83
84 QString readStringBinding(QQmlJS::AST::UiScriptBinding *ast);
85 bool readBoolBinding(QQmlJS::AST::UiScriptBinding *ast);
86 double readNumericBinding(QQmlJS::AST::UiScriptBinding *ast);
87 ComponentVersion readNumericVersionBinding(QQmlJS::AST::UiScriptBinding *ast);
88 int readIntBinding(QQmlJS::AST::UiScriptBinding *ast);
89 void readExports(QQmlJS::AST::UiScriptBinding *ast, const ScopeTree::Ptr &scope);
90 void readMetaObjectRevisions(QQmlJS::AST::UiScriptBinding *ast, const ScopeTree::Ptr &scope);
91 void readEnumValues(QQmlJS::AST::UiScriptBinding *ast, MetaEnum *metaEnum);
92
93 void addError(const QQmlJS::SourceLocation &loc, const QString &message);
94 void addWarning(const QQmlJS::SourceLocation &loc, const QString &message);
95
96 QString m_fileName;
97 QString m_source;
98 QString m_errorMessage;
99 QString m_warningMessage;
100 QHash<QString, ScopeTree::ConstPtr> *m_objects = nullptr;
101 QList<ModuleApiInfo> *m_moduleApis = nullptr;
102 QStringList *m_dependencies = nullptr;
103};
104
105#endif // TYPEDESCRIPTIONREADER_H
106

source code of qtdeclarative/tools/qmllint/typedescriptionreader.h