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 QMLVISITOR_H 30 #define QMLVISITOR_H 31 32 #include "node.h" 33 34 #include <QtCore/qstring.h> 35 36 #ifndef QT_NO_DECLARATIVE 37 # include <private/qqmljsastvisitor_p.h> 38 # include <private/qqmljsengine_p.h> 39 #endif 40 41 QT_BEGIN_NAMESPACE 42 43 #ifndef QT_NO_DECLARATIVE 44 # include <private/qqmlapiversion_p.h> 45 # if Q_QML_PRIVATE_API_VERSION < 8 46 namespace QQmlJS { 47 using SourceLocation = AST::SourceLocation; 48 } 49 # endif 50 #endif 51 52 struct QmlPropArgs 53 { 54 QString type_; 55 QString module_; 56 QString component_; 57 QString name_; 58 clearQmlPropArgs59 void clear() 60 { 61 type_.clear(); 62 module_.clear(); 63 component_.clear(); 64 name_.clear(); 65 } 66 }; 67 68 #ifndef QT_NO_DECLARATIVE 69 class QmlDocVisitor : public QQmlJS::AST::Visitor 70 { 71 Q_DECLARE_TR_FUNCTIONS(QDoc::QmlDocVisitor) 72 73 public: 74 QmlDocVisitor(const QString &filePath, const QString &code, QQmlJS::Engine *engine, 75 const QSet<QString> &commands, const QSet<QString> &topics); 76 ~QmlDocVisitor() override; 77 78 bool visit(QQmlJS::AST::UiImport *import) override; 79 void endVisit(QQmlJS::AST::UiImport *definition) override; 80 81 bool visit(QQmlJS::AST::UiObjectDefinition *definition) override; 82 void endVisit(QQmlJS::AST::UiObjectDefinition *definition) override; 83 84 bool visit(QQmlJS::AST::UiPublicMember *member) override; 85 void endVisit(QQmlJS::AST::UiPublicMember *definition) override; 86 87 bool visit(QQmlJS::AST::UiObjectBinding *) override; 88 void endVisit(QQmlJS::AST::UiObjectBinding *) override; 89 void endVisit(QQmlJS::AST::UiArrayBinding *) override; 90 bool visit(QQmlJS::AST::UiArrayBinding *) override; 91 92 bool visit(QQmlJS::AST::IdentifierPropertyName *idproperty) override; 93 94 bool visit(QQmlJS::AST::FunctionDeclaration *) override; 95 void endVisit(QQmlJS::AST::FunctionDeclaration *) override; 96 97 bool visit(QQmlJS::AST::UiScriptBinding *) override; 98 void endVisit(QQmlJS::AST::UiScriptBinding *) override; 99 100 bool visit(QQmlJS::AST::UiQualifiedId *) override; 101 void endVisit(QQmlJS::AST::UiQualifiedId *) override; 102 103 void throwRecursionDepthError() final; 104 bool hasError() const; 105 106 private: 107 QString getFullyQualifiedId(QQmlJS::AST::UiQualifiedId *id); 108 QQmlJS::SourceLocation precedingComment(quint32 offset) const; 109 bool applyDocumentation(QQmlJS::SourceLocation location, Node *node); 110 void applyMetacommands(QQmlJS::SourceLocation location, Node *node, Doc &doc); 111 bool splitQmlPropertyArg(const Doc &doc, const QString &arg, QmlPropArgs &qpa); 112 113 QQmlJS::Engine *engine; 114 quint32 lastEndOffset; 115 quint32 nestingLevel; 116 QString filePath_; 117 QString name; 118 QString document; 119 ImportList importList; 120 QSet<QString> commands_; 121 QSet<QString> topics_; 122 QSet<quint32> usedComments; 123 Aggregate *current; 124 bool hasRecursionDepthError = false; 125 }; 126 #endif 127 128 QT_END_NAMESPACE 129 130 #endif 131