1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtQml module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 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 Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 #ifndef QV4COMPILERSCANFUNCTIONS_P_H 40 #define QV4COMPILERSCANFUNCTIONS_P_H 41 42 // 43 // W A R N I N G 44 // ------------- 45 // 46 // This file is not part of the Qt API. It exists purely as an 47 // implementation detail. This header file may change from version to 48 // version without notice, or even be removed. 49 // 50 // We mean it. 51 // 52 53 #include <private/qtqmlcompilerglobal_p.h> 54 #include <private/qqmljsastvisitor_p.h> 55 #include <private/qqmljsast_p.h> 56 #include <private/qqmljsengine_p.h> 57 #include <private/qv4compilercontext_p.h> 58 #include <private/qv4util_p.h> 59 #include <QtCore/QStringList> 60 #include <QStack> 61 #include <QScopedValueRollback> 62 63 QT_BEGIN_NAMESPACE 64 65 namespace QV4 { 66 67 namespace Moth { 68 struct Instruction; 69 } 70 71 namespace CompiledData { 72 struct CompilationUnit; 73 } 74 75 namespace Compiler { 76 77 class Codegen; 78 79 class ScanFunctions: protected QQmlJS::AST::Visitor 80 { 81 typedef QScopedValueRollback<bool> TemporaryBoolAssignment; 82 public: 83 ScanFunctions(Codegen *cg, const QString &sourceCode, ContextType defaultProgramType); 84 void operator()(QQmlJS::AST::Node *node); 85 86 void enterGlobalEnvironment(ContextType compilationMode); 87 void enterEnvironment(QQmlJS::AST::Node *node, ContextType compilationMode, 88 const QString &name); 89 void leaveEnvironment(); 90 enterQmlFunction(QQmlJS::AST::FunctionExpression * ast)91 void enterQmlFunction(QQmlJS::AST::FunctionExpression *ast) 92 { enterFunction(ast, false); } 93 94 protected: 95 using Visitor::visit; 96 using Visitor::endVisit; 97 98 void checkDirectivePrologue(QQmlJS::AST::StatementList *ast); 99 100 void checkName(const QStringRef &name, const QQmlJS::SourceLocation &loc); 101 102 bool visit(QQmlJS::AST::Program *ast) override; 103 void endVisit(QQmlJS::AST::Program *) override; 104 105 bool visit(QQmlJS::AST::ESModule *ast) override; 106 void endVisit(QQmlJS::AST::ESModule *) override; 107 108 bool visit(QQmlJS::AST::ExportDeclaration *declaration) override; 109 bool visit(QQmlJS::AST::ImportDeclaration *declaration) override; 110 111 bool visit(QQmlJS::AST::CallExpression *ast) override; 112 bool visit(QQmlJS::AST::PatternElement *ast) override; 113 bool visit(QQmlJS::AST::IdentifierExpression *ast) override; 114 bool visit(QQmlJS::AST::ExpressionStatement *ast) override; 115 bool visit(QQmlJS::AST::FunctionExpression *ast) override; 116 bool visit(QQmlJS::AST::TemplateLiteral *ast) override; 117 bool visit(QQmlJS::AST::SuperLiteral *) override; 118 bool visit(QQmlJS::AST::FieldMemberExpression *) override; 119 bool visit(QQmlJS::AST::ArrayPattern *) override; 120 121 bool enterFunction(QQmlJS::AST::FunctionExpression *ast, bool enterName); 122 123 void endVisit(QQmlJS::AST::FunctionExpression *) override; 124 125 bool visit(QQmlJS::AST::ObjectPattern *ast) override; 126 127 bool visit(QQmlJS::AST::PatternProperty *ast) override; 128 void endVisit(QQmlJS::AST::PatternProperty *) override; 129 130 bool visit(QQmlJS::AST::FunctionDeclaration *ast) override; 131 void endVisit(QQmlJS::AST::FunctionDeclaration *) override; 132 133 bool visit(QQmlJS::AST::ClassExpression *ast) override; 134 void endVisit(QQmlJS::AST::ClassExpression *) override; 135 136 bool visit(QQmlJS::AST::ClassDeclaration *ast) override; 137 void endVisit(QQmlJS::AST::ClassDeclaration *) override; 138 139 bool visit(QQmlJS::AST::DoWhileStatement *ast) override; 140 bool visit(QQmlJS::AST::ForStatement *ast) override; 141 void endVisit(QQmlJS::AST::ForStatement *) override; 142 bool visit(QQmlJS::AST::ForEachStatement *ast) override; 143 void endVisit(QQmlJS::AST::ForEachStatement *) override; 144 145 bool visit(QQmlJS::AST::ThisExpression *ast) override; 146 147 bool visit(QQmlJS::AST::Block *ast) override; 148 void endVisit(QQmlJS::AST::Block *ast) override; 149 150 bool visit(QQmlJS::AST::CaseBlock *ast) override; 151 void endVisit(QQmlJS::AST::CaseBlock *ast) override; 152 153 bool visit(QQmlJS::AST::Catch *ast) override; 154 void endVisit(QQmlJS::AST::Catch *ast) override; 155 156 bool visit(QQmlJS::AST::WithStatement *ast) override; 157 void endVisit(QQmlJS::AST::WithStatement *ast) override; 158 159 void throwRecursionDepthError() override; 160 161 protected: 162 bool enterFunction(QQmlJS::AST::Node *ast, const QString &name, 163 QQmlJS::AST::FormalParameterList *formals, 164 QQmlJS::AST::StatementList *body, bool enterName); 165 166 void calcEscapingVariables(); 167 // fields: 168 Codegen *_cg; 169 const QString _sourceCode; 170 Context *_context; 171 QStack<Context *> _contextStack; 172 173 bool _allowFuncDecls; 174 ContextType defaultProgramType; 175 176 private: 177 static constexpr QQmlJS::AST::Node *astNodeForGlobalEnvironment = nullptr; 178 }; 179 180 } 181 182 } 183 184 QT_END_NAMESPACE 185 186 #endif // QV4CODEGEN_P_H 187