| 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 FINDUNQUALIFIED_H |
| 30 | #define FINDUNQUALIFIED_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 "typedescriptionreader.h" |
| 43 | #include "scopetree.h" |
| 44 | #include "qcoloroutput.h" |
| 45 | |
| 46 | #include <QtQml/private/qqmljsastvisitor_p.h> |
| 47 | #include <QtQml/private/qqmljsast_p.h> |
| 48 | |
| 49 | #include <QtCore/qscopedpointer.h> |
| 50 | |
| 51 | class FindUnqualifiedIDVisitor : public QQmlJS::AST::Visitor |
| 52 | { |
| 53 | Q_DISABLE_COPY_MOVE(FindUnqualifiedIDVisitor) |
| 54 | public: |
| 55 | explicit FindUnqualifiedIDVisitor(QStringList qmltypeDirs, QStringList qmltypeFiles, QString code, |
| 56 | QString fileName, bool silent); |
| 57 | ~FindUnqualifiedIDVisitor() override = default; |
| 58 | bool check(); |
| 59 | |
| 60 | private: |
| 61 | struct Import { |
| 62 | QHash<QString, ScopeTree::ConstPtr> objects; |
| 63 | QList<ModuleApiInfo> moduleApis; |
| 64 | QStringList dependencies; |
| 65 | }; |
| 66 | |
| 67 | QScopedPointer<ScopeTree> m_rootScope; |
| 68 | ScopeTree *m_currentScope; |
| 69 | QQmlJS::AST::ExpressionNode *m_fieldMemberBase = nullptr; |
| 70 | QHash<QString, ScopeTree::ConstPtr> m_types; |
| 71 | QHash<QString, ScopeTree::ConstPtr> m_exportedName2Scope; |
| 72 | QStringList m_qmltypeDirs; |
| 73 | QStringList m_qmltypeFiles; |
| 74 | QString m_code; |
| 75 | QHash<QString, const ScopeTree *> m_qmlid2scope; |
| 76 | QString m_rootId; |
| 77 | QString m_filePath; |
| 78 | QSet<QPair<QString, QString>> m_alreadySeenImports; |
| 79 | QSet<QString> m_unknownImports; |
| 80 | ColorOutput m_colorOut; |
| 81 | bool m_visitFailed = false; |
| 82 | |
| 83 | struct OutstandingConnection |
| 84 | { |
| 85 | QString targetName; |
| 86 | ScopeTree *scope; |
| 87 | QQmlJS::AST::UiObjectDefinition *uiod; |
| 88 | }; |
| 89 | |
| 90 | QVarLengthArray<OutstandingConnection, 3> m_outstandingConnections; // Connections whose target we have not encountered |
| 91 | |
| 92 | void enterEnvironment(ScopeType type, const QString &name); |
| 93 | void leaveEnvironment(); |
| 94 | void importHelper(const QString &module, const QString &prefix = QString(), |
| 95 | int major = -1, int minor = -1); |
| 96 | |
| 97 | void readQmltypes(const QString &filename, Import &result); |
| 98 | Import readQmldir(const QString &dirname); |
| 99 | void processImport(const QString &prefix, const Import &import); |
| 100 | |
| 101 | ScopeTree *localFile2ScopeTree(const QString &filePath); |
| 102 | |
| 103 | void importFileOrDirectory(const QString &directory, const QString &prefix); |
| 104 | void importExportedNames(const QStringRef &prefix, QString name); |
| 105 | |
| 106 | void (QQmlJS::AST::UiHeaderItemList *); |
| 107 | ScopeTree *parseProgram(QQmlJS::AST::Program *program, const QString &name); |
| 108 | |
| 109 | void throwRecursionDepthError() override; |
| 110 | |
| 111 | // start block/scope handling |
| 112 | bool visit(QQmlJS::AST::UiProgram *ast) override; |
| 113 | void endVisit(QQmlJS::AST::UiProgram *ast) override; |
| 114 | |
| 115 | bool visit(QQmlJS::AST::ClassExpression *ast) override; |
| 116 | void endVisit(QQmlJS::AST::ClassExpression *ast) override; |
| 117 | |
| 118 | bool visit(QQmlJS::AST::ClassDeclaration *ast) override; |
| 119 | void endVisit(QQmlJS::AST::ClassDeclaration *ast) override; |
| 120 | |
| 121 | bool visit(QQmlJS::AST::ForStatement *ast) override; |
| 122 | void endVisit(QQmlJS::AST::ForStatement *ast) override; |
| 123 | |
| 124 | bool visit(QQmlJS::AST::ForEachStatement *ast) override; |
| 125 | void endVisit(QQmlJS::AST::ForEachStatement *ast) override; |
| 126 | |
| 127 | bool visit(QQmlJS::AST::Block *ast) override; |
| 128 | void endVisit(QQmlJS::AST::Block *ast) override; |
| 129 | |
| 130 | bool visit(QQmlJS::AST::CaseBlock *ast) override; |
| 131 | void endVisit(QQmlJS::AST::CaseBlock *ast) override; |
| 132 | |
| 133 | bool visit(QQmlJS::AST::Catch *ast) override; |
| 134 | void endVisit(QQmlJS::AST::Catch *ast) override; |
| 135 | |
| 136 | bool visit(QQmlJS::AST::WithStatement *withStatement) override; |
| 137 | void endVisit(QQmlJS::AST::WithStatement *ast) override; |
| 138 | |
| 139 | void visitFunctionExpressionHelper(QQmlJS::AST::FunctionExpression *fexpr); |
| 140 | bool visit(QQmlJS::AST::FunctionExpression *fexpr) override; |
| 141 | void endVisit(QQmlJS::AST::FunctionExpression *fexpr) override; |
| 142 | |
| 143 | bool visit(QQmlJS::AST::FunctionDeclaration *fdecl) override; |
| 144 | void endVisit(QQmlJS::AST::FunctionDeclaration *fdecl) override; |
| 145 | /* --- end block handling --- */ |
| 146 | |
| 147 | bool visit(QQmlJS::AST::VariableDeclarationList *vdl) override; |
| 148 | bool visit(QQmlJS::AST::FormalParameterList *fpl) override; |
| 149 | |
| 150 | bool visit(QQmlJS::AST::UiImport *import) override; |
| 151 | bool visit(QQmlJS::AST::UiEnumDeclaration *uied) override; |
| 152 | bool visit(QQmlJS::AST::UiObjectBinding *uiob) override; |
| 153 | void endVisit(QQmlJS::AST::UiObjectBinding *uiob) override; |
| 154 | bool visit(QQmlJS::AST::UiObjectDefinition *uiod) override; |
| 155 | void endVisit(QQmlJS::AST::UiObjectDefinition *) override; |
| 156 | bool visit(QQmlJS::AST::UiScriptBinding *uisb) override; |
| 157 | bool visit(QQmlJS::AST::UiPublicMember *uipm) override; |
| 158 | |
| 159 | // expression handling |
| 160 | bool visit(QQmlJS::AST::IdentifierExpression *idexp) override; |
| 161 | |
| 162 | bool visit(QQmlJS::AST::PatternElement *) override; |
| 163 | bool visit(QQmlJS::AST::FieldMemberExpression *idprop) override; |
| 164 | void endVisit(QQmlJS::AST::FieldMemberExpression *) override; |
| 165 | |
| 166 | bool visit(QQmlJS::AST::BinaryExpression *) override; |
| 167 | void endVisit(QQmlJS::AST::BinaryExpression *) override; |
| 168 | }; |
| 169 | |
| 170 | #endif // FINDUNQUALIFIED_H |
| 171 | |