| 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 | class QmlDocVisitor : public QQmlJS::AST::Visitor |
| 20 | { |
| 21 | public: |
| 22 | QmlDocVisitor(const QString &filePath, const QString &code, QQmlJS::Engine *engine, |
| 23 | const QSet<QString> &commands, const QSet<QString> &topics); |
| 24 | ~QmlDocVisitor() override = default; |
| 25 | |
| 26 | bool visit(QQmlJS::AST::UiImport *import) override; |
| 27 | void endVisit(QQmlJS::AST::UiImport *definition) override; |
| 28 | |
| 29 | bool visit(QQmlJS::AST::UiObjectDefinition *definition) override; |
| 30 | void endVisit(QQmlJS::AST::UiObjectDefinition *definition) override; |
| 31 | |
| 32 | bool visit(QQmlJS::AST::UiPublicMember *member) override; |
| 33 | void endVisit(QQmlJS::AST::UiPublicMember *definition) override; |
| 34 | |
| 35 | bool visit(QQmlJS::AST::UiObjectBinding *) override; |
| 36 | void endVisit(QQmlJS::AST::UiObjectBinding *) override; |
| 37 | void endVisit(QQmlJS::AST::UiArrayBinding *) override; |
| 38 | bool visit(QQmlJS::AST::UiArrayBinding *) override; |
| 39 | |
| 40 | bool visit(QQmlJS::AST::IdentifierPropertyName *idproperty) override; |
| 41 | |
| 42 | bool visit(QQmlJS::AST::FunctionDeclaration *) override; |
| 43 | void endVisit(QQmlJS::AST::FunctionDeclaration *) override; |
| 44 | |
| 45 | bool visit(QQmlJS::AST::UiScriptBinding *) override; |
| 46 | void endVisit(QQmlJS::AST::UiScriptBinding *) override; |
| 47 | |
| 48 | bool visit(QQmlJS::AST::UiQualifiedId *) override; |
| 49 | void endVisit(QQmlJS::AST::UiQualifiedId *) override; |
| 50 | |
| 51 | void throwRecursionDepthError() final; |
| 52 | [[nodiscard]] bool hasError() const; |
| 53 | |
| 54 | private: |
| 55 | QString getFullyQualifiedId(QQmlJS::AST::UiQualifiedId *id); |
| 56 | [[nodiscard]] QQmlJS::SourceLocation precedingComment(quint32 offset) const; |
| 57 | Node *applyDocumentation(QQmlJS::SourceLocation location, Node *node); |
| 58 | void applyMetacommands(QQmlJS::SourceLocation location, Node *node, Doc &doc); |
| 59 | |
| 60 | QQmlJS::Engine *m_engine { nullptr }; |
| 61 | quint32 m_lastEndOffset {}; |
| 62 | quint32 m_nestingLevel {}; |
| 63 | QString m_filePath {}; |
| 64 | QString m_name {}; |
| 65 | QString m_document {}; |
| 66 | ImportList m_importList {}; |
| 67 | QSet<QString> m_commands {}; |
| 68 | QSet<QString> m_topics {}; |
| 69 | QSet<quint32> m_usedComments {}; |
| 70 | Aggregate *m_current { nullptr }; |
| 71 | bool hasRecursionDepthError { false }; |
| 72 | }; |
| 73 | |
| 74 | QT_END_NAMESPACE |
| 75 | |
| 76 | #endif |
| 77 |
