1 | // Copyright (C) 2021 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
3 | |
4 | #ifndef QMLVISITOR_H |
5 | #define QMLVISITOR_H |
6 | |
7 | #include "node.h" |
8 | #include "qmltypenode.h" |
9 | |
10 | #include <QtCore/qstring.h> |
11 | |
12 | #include <private/qqmljsastvisitor_p.h> |
13 | #include <private/qqmljsengine_p.h> |
14 | |
15 | QT_BEGIN_NAMESPACE |
16 | |
17 | class Aggregate; |
18 | |
19 | struct QmlPropArgs |
20 | { |
21 | QString m_type {}; |
22 | QString m_module {}; |
23 | QString m_component {}; |
24 | QString m_name; |
25 | |
26 | void clear() |
27 | { |
28 | m_type.clear(); |
29 | m_module.clear(); |
30 | m_component.clear(); |
31 | m_name.clear(); |
32 | } |
33 | }; |
34 | |
35 | class QmlDocVisitor : public QQmlJS::AST::Visitor |
36 | { |
37 | public: |
38 | QmlDocVisitor(const QString &filePath, const QString &code, QQmlJS::Engine *engine, |
39 | const QSet<QString> &commands, const QSet<QString> &topics); |
40 | ~QmlDocVisitor() override = default; |
41 | |
42 | bool visit(QQmlJS::AST::UiImport *import) override; |
43 | void endVisit(QQmlJS::AST::UiImport *definition) override; |
44 | |
45 | bool visit(QQmlJS::AST::UiObjectDefinition *definition) override; |
46 | void endVisit(QQmlJS::AST::UiObjectDefinition *definition) override; |
47 | |
48 | bool visit(QQmlJS::AST::UiPublicMember *member) override; |
49 | void endVisit(QQmlJS::AST::UiPublicMember *definition) override; |
50 | |
51 | bool visit(QQmlJS::AST::UiObjectBinding *) override; |
52 | void endVisit(QQmlJS::AST::UiObjectBinding *) override; |
53 | void endVisit(QQmlJS::AST::UiArrayBinding *) override; |
54 | bool visit(QQmlJS::AST::UiArrayBinding *) override; |
55 | |
56 | bool visit(QQmlJS::AST::IdentifierPropertyName *idproperty) override; |
57 | |
58 | bool visit(QQmlJS::AST::FunctionDeclaration *) override; |
59 | void endVisit(QQmlJS::AST::FunctionDeclaration *) override; |
60 | |
61 | bool visit(QQmlJS::AST::UiScriptBinding *) override; |
62 | void endVisit(QQmlJS::AST::UiScriptBinding *) override; |
63 | |
64 | bool visit(QQmlJS::AST::UiQualifiedId *) override; |
65 | void endVisit(QQmlJS::AST::UiQualifiedId *) override; |
66 | |
67 | void throwRecursionDepthError() final; |
68 | [[nodiscard]] bool hasError() const; |
69 | |
70 | private: |
71 | QString getFullyQualifiedId(QQmlJS::AST::UiQualifiedId *id); |
72 | [[nodiscard]] QQmlJS::SourceLocation precedingComment(quint32 offset) const; |
73 | bool applyDocumentation(QQmlJS::SourceLocation location, Node *node); |
74 | void applyMetacommands(QQmlJS::SourceLocation location, Node *node, Doc &doc); |
75 | bool splitQmlPropertyArg(const Doc &doc, const QString &arg, QmlPropArgs &qpa); |
76 | |
77 | QQmlJS::Engine *m_engine { nullptr }; |
78 | quint32 m_lastEndOffset {}; |
79 | quint32 m_nestingLevel {}; |
80 | QString m_filePath {}; |
81 | QString m_name {}; |
82 | QString m_document {}; |
83 | ImportList m_importList {}; |
84 | QSet<QString> m_commands {}; |
85 | QSet<QString> m_topics {}; |
86 | QSet<quint32> m_usedComments {}; |
87 | Aggregate *m_current { nullptr }; |
88 | bool hasRecursionDepthError { false }; |
89 | }; |
90 | |
91 | QT_END_NAMESPACE |
92 | |
93 | #endif |
94 |