| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/compiler/qv4compilercontext_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2017 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 QV4COMPILERCONTEXT_P_H | - | ||||||||||||
| 40 | #define QV4COMPILERCONTEXT_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/qv4global_p.h" | - | ||||||||||||
| 54 | #include <private/qqmljsast_p.h> | - | ||||||||||||
| 55 | #include <private/qv4compileddata_p.h> | - | ||||||||||||
| 56 | #include <QtCore/QStringList> | - | ||||||||||||
| 57 | #include <QtCore/QDateTime> | - | ||||||||||||
| 58 | #include <QtCore/QStack> | - | ||||||||||||
| 59 | #include <QtCore/QHash> | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 62 | - | |||||||||||||
| 63 | namespace QV4 { | - | ||||||||||||
| 64 | - | |||||||||||||
| 65 | namespace Compiler { | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | struct ControlFlow; | - | ||||||||||||
| 68 | - | |||||||||||||
| 69 | enum class ContextType { | - | ||||||||||||
| 70 | Global, | - | ||||||||||||
| 71 | Function, | - | ||||||||||||
| 72 | Eval, | - | ||||||||||||
| 73 | Binding, // This is almost the same as Eval, except: | - | ||||||||||||
| 74 | // * function declarations are moved to the return address when encountered | - | ||||||||||||
| 75 | // * return statements are allowed everywhere (like in FunctionCode) | - | ||||||||||||
| 76 | // * variable declarations are treated as true locals (like in FunctionCode) | - | ||||||||||||
| 77 | Block | - | ||||||||||||
| 78 | }; | - | ||||||||||||
| 79 | - | |||||||||||||
| 80 | struct Context; | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | struct Class { | - | ||||||||||||
| 83 | struct Method { | - | ||||||||||||
| 84 | enum Type { | - | ||||||||||||
| 85 | Regular, | - | ||||||||||||
| 86 | Getter, | - | ||||||||||||
| 87 | Setter | - | ||||||||||||
| 88 | }; | - | ||||||||||||
| 89 | uint nameIndex; | - | ||||||||||||
| 90 | Type type; | - | ||||||||||||
| 91 | uint functionIndex; | - | ||||||||||||
| 92 | }; | - | ||||||||||||
| 93 | - | |||||||||||||
| 94 | uint nameIndex; | - | ||||||||||||
| 95 | uint constructorIndex = UINT_MAX; | - | ||||||||||||
| 96 | QVector<Method> staticMethods; | - | ||||||||||||
| 97 | QVector<Method> methods; | - | ||||||||||||
| 98 | }; | - | ||||||||||||
| 99 | - | |||||||||||||
| 100 | struct Module { | - | ||||||||||||
| 101 | Module(bool debugMode) | - | ||||||||||||
| 102 | : debugMode(debugMode) | - | ||||||||||||
| 103 | {} executed 2818458 times by 31 tests: end of blockExecuted by:
| 2818458 | ||||||||||||
| 104 | ~Module() { | - | ||||||||||||
| 105 | qDeleteAll(contextMap); | - | ||||||||||||
| 106 | } executed 2867507 times by 147 tests: end of blockExecuted by:
| 2867507 | ||||||||||||
| 107 | - | |||||||||||||
| 108 | Context *newContext(QQmlJS::AST::Node *node, Context *parent, ContextType compilationMode); | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | QHash<QQmlJS::AST::Node *, Context *> contextMap; | - | ||||||||||||
| 111 | QList<Context *> functions; | - | ||||||||||||
| 112 | QList<Context *> blocks; | - | ||||||||||||
| 113 | QVector<Class> classes; | - | ||||||||||||
| 114 | Context *rootContext; | - | ||||||||||||
| 115 | QString fileName; | - | ||||||||||||
| 116 | QString finalUrl; | - | ||||||||||||
| 117 | QDateTime sourceTimeStamp; | - | ||||||||||||
| 118 | uint unitFlags = 0; // flags merged into CompiledData::Unit::flags | - | ||||||||||||
| 119 | bool debugMode = false; | - | ||||||||||||
| 120 | }; | - | ||||||||||||
| 121 | - | |||||||||||||
| 122 | - | |||||||||||||
| 123 | struct Context { | - | ||||||||||||
| 124 | Context *parent; | - | ||||||||||||
| 125 | QString name; | - | ||||||||||||
| 126 | int line = 0; | - | ||||||||||||
| 127 | int column = 0; | - | ||||||||||||
| 128 | int registerCountInFunction = 0; | - | ||||||||||||
| 129 | int functionIndex = -1; | - | ||||||||||||
| 130 | int blockIndex = -1; | - | ||||||||||||
| 131 | - | |||||||||||||
| 132 | enum MemberType { | - | ||||||||||||
| 133 | UndefinedMember, | - | ||||||||||||
| 134 | ThisFunctionName, | - | ||||||||||||
| 135 | VariableDefinition, | - | ||||||||||||
| 136 | VariableDeclaration, | - | ||||||||||||
| 137 | FunctionDefinition | - | ||||||||||||
| 138 | }; | - | ||||||||||||
| 139 | - | |||||||||||||
| 140 | struct Member { | - | ||||||||||||
| 141 | MemberType type = UndefinedMember; | - | ||||||||||||
| 142 | int index = -1; | - | ||||||||||||
| 143 | QQmlJS::AST::VariableScope scope = QQmlJS::AST::VariableScope::Var; | - | ||||||||||||
| 144 | mutable bool canEscape = false; | - | ||||||||||||
| 145 | QQmlJS::AST::FunctionExpression *function = nullptr; | - | ||||||||||||
| 146 | - | |||||||||||||
| 147 | bool isLexicallyScoped() const { return this->scope != QQmlJS::AST::VariableScope::Var; } executed 1050864 times by 20 tests: return this->scope != QQmlJS::AST::VariableScope::Var;Executed by:
| 1050864 | ||||||||||||
| 148 | }; | - | ||||||||||||
| 149 | typedef QMap<QString, Member> MemberMap; | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | MemberMap members; | - | ||||||||||||
| 152 | QSet<QString> usedVariables; | - | ||||||||||||
| 153 | QQmlJS::AST::FormalParameterList *formals = nullptr; | - | ||||||||||||
| 154 | QStringList arguments; | - | ||||||||||||
| 155 | QStringList locals; | - | ||||||||||||
| 156 | QVector<Context *> nestedContexts; | - | ||||||||||||
| 157 | - | |||||||||||||
| 158 | ControlFlow *controlFlow = nullptr; | - | ||||||||||||
| 159 | QByteArray code; | - | ||||||||||||
| 160 | QVector<CompiledData::CodeOffsetToLine> lineNumberMapping; | - | ||||||||||||
| 161 | - | |||||||||||||
| 162 | int nRegisters = 0; | - | ||||||||||||
| 163 | int registerOffset = -1; | - | ||||||||||||
| 164 | bool hasDirectEval = false; | - | ||||||||||||
| 165 | bool allVarsEscape = false; | - | ||||||||||||
| 166 | bool hasNestedFunctions = false; | - | ||||||||||||
| 167 | bool isStrict = false; | - | ||||||||||||
| 168 | bool isArrowFunction = false; | - | ||||||||||||
| 169 | bool isGenerator = false; | - | ||||||||||||
| 170 | bool usesThis = false; | - | ||||||||||||
| 171 | bool hasTry = false; | - | ||||||||||||
| 172 | bool returnsClosure = false; | - | ||||||||||||
| 173 | mutable bool argumentsCanEscape = false; | - | ||||||||||||
| 174 | bool requiresExecutionContext = false; | - | ||||||||||||
| 175 | bool isWithBlock = false; | - | ||||||||||||
| 176 | bool isCatchBlock = false; | - | ||||||||||||
| 177 | QString caughtVariable; | - | ||||||||||||
| 178 | - | |||||||||||||
| 179 | enum UsesArgumentsObject { | - | ||||||||||||
| 180 | ArgumentsObjectUnknown, | - | ||||||||||||
| 181 | ArgumentsObjectNotUsed, | - | ||||||||||||
| 182 | ArgumentsObjectUsed | - | ||||||||||||
| 183 | }; | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | UsesArgumentsObject usesArgumentsObject = ArgumentsObjectUnknown; | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | ContextType contextType; | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | template <typename T> | - | ||||||||||||
| 190 | class SmallSet: public QVarLengthArray<T, 8> | - | ||||||||||||
| 191 | { | - | ||||||||||||
| 192 | public: | - | ||||||||||||
| 193 | void insert(int value) | - | ||||||||||||
| 194 | { | - | ||||||||||||
| 195 | for (auto it : *this) { | - | ||||||||||||
| 196 | if (it == value)
| 0 | ||||||||||||
| 197 | return; never executed: return; | 0 | ||||||||||||
| 198 | } never executed: end of block | 0 | ||||||||||||
| 199 | this->append(value); | - | ||||||||||||
| 200 | } never executed: end of block | 0 | ||||||||||||
| 201 | }; | - | ||||||||||||
| 202 | - | |||||||||||||
| 203 | // Map from meta property index (existence implies dependency) to notify signal index | - | ||||||||||||
| 204 | struct KeyValuePair | - | ||||||||||||
| 205 | { | - | ||||||||||||
| 206 | quint32 _key = 0; | - | ||||||||||||
| 207 | quint32 _value = 0; | - | ||||||||||||
| 208 | - | |||||||||||||
| 209 | KeyValuePair() {} | - | ||||||||||||
| 210 | KeyValuePair(quint32 key, quint32 value): _key(key), _value(value) {} never executed: end of block | 0 | ||||||||||||
| 211 | - | |||||||||||||
| 212 | quint32 key() const { return _key; } never executed: return _key; | 0 | ||||||||||||
| 213 | quint32 value() const { return _value; } never executed: return _value; | 0 | ||||||||||||
| 214 | }; | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | class PropertyDependencyMap: public QVarLengthArray<KeyValuePair, 8> | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | public: | - | ||||||||||||
| 219 | void insert(quint32 key, quint32 value) | - | ||||||||||||
| 220 | { | - | ||||||||||||
| 221 | for (auto it = begin(), eit = end(); it != eit; ++it) {
| 0 | ||||||||||||
| 222 | if (it->_key == key) {
| 0 | ||||||||||||
| 223 | it->_value = value; | - | ||||||||||||
| 224 | return; never executed: return; | 0 | ||||||||||||
| 225 | } | - | ||||||||||||
| 226 | } never executed: end of block | 0 | ||||||||||||
| 227 | append(KeyValuePair(key, value)); | - | ||||||||||||
| 228 | } never executed: end of block | 0 | ||||||||||||
| 229 | }; | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | // Qml extension: | - | ||||||||||||
| 232 | SmallSet<int> idObjectDependencies; | - | ||||||||||||
| 233 | PropertyDependencyMap contextObjectPropertyDependencies; | - | ||||||||||||
| 234 | PropertyDependencyMap scopeObjectPropertyDependencies; | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | Context(Context *parent, ContextType type) | - | ||||||||||||
| 237 | : parent(parent) | - | ||||||||||||
| 238 | , contextType(type) | - | ||||||||||||
| 239 | { | - | ||||||||||||
| 240 | if (parent && parent->isStrict)
| 1394696-2906938 | ||||||||||||
| 241 | isStrict = true; executed 1394637 times by 3 tests: isStrict = true;Executed by:
| 1394637 | ||||||||||||
| 242 | } executed 5242758 times by 140 tests: end of blockExecuted by:
| 5242758 | ||||||||||||
| 243 | - | |||||||||||||
| 244 | int findArgument(const QString &name) | - | ||||||||||||
| 245 | { | - | ||||||||||||
| 246 | // search backwards to handle duplicate argument names correctly | - | ||||||||||||
| 247 | for (int i = arguments.size() - 1; i >= 0; --i) {
| 7153945-18472080 | ||||||||||||
| 248 | if (arguments.at(i) == name)
| 6944239-11543232 | ||||||||||||
| 249 | return i; executed 6922607 times by 58 tests: return i;Executed by:
| 6922607 | ||||||||||||
| 250 | } executed 11546476 times by 57 tests: end of blockExecuted by:
| 11546476 | ||||||||||||
| 251 | return -1; executed 7162698 times by 136 tests: return -1;Executed by:
| 7162698 | ||||||||||||
| 252 | } | - | ||||||||||||
| 253 | - | |||||||||||||
| 254 | Member findMember(const QString &name) const | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | MemberMap::const_iterator it = members.find(name); | - | ||||||||||||
| 257 | if (it == members.end())
| 4196572-16822718 | ||||||||||||
| 258 | return Member(); executed 16827897 times by 138 tests: return Member();Executed by:
| 16827897 | ||||||||||||
| 259 | Q_ASSERT(it->index != -1 || !parent); | - | ||||||||||||
| 260 | return (*it); executed 4197522 times by 52 tests: return (*it);Executed by:
| 4197522 | ||||||||||||
| 261 | } | - | ||||||||||||
| 262 | - | |||||||||||||
| 263 | bool memberInfo(const QString &name, const Member **m) const | - | ||||||||||||
| 264 | { | - | ||||||||||||
| 265 | Q_ASSERT(m); | - | ||||||||||||
| 266 | MemberMap::const_iterator it = members.find(name); | - | ||||||||||||
| 267 | if (it == members.end()) {
| 0 | ||||||||||||
| 268 | *m = nullptr; | - | ||||||||||||
| 269 | return false; never executed: return false; | 0 | ||||||||||||
| 270 | } | - | ||||||||||||
| 271 | *m = &(*it); | - | ||||||||||||
| 272 | return true; never executed: return true; | 0 | ||||||||||||
| 273 | } | - | ||||||||||||
| 274 | - | |||||||||||||
| 275 | bool requiresImplicitReturnValue() const { | - | ||||||||||||
| 276 | return contextType == ContextType::Binding || executed 3398543 times by 140 tests: return contextType == ContextType::Binding || contextType == ContextType::Eval || contextType == ContextType::Global;Executed by:
| 3398543 | ||||||||||||
| 277 | contextType == ContextType::Eval || executed 3398543 times by 140 tests: return contextType == ContextType::Binding || contextType == ContextType::Eval || contextType == ContextType::Global;Executed by:
| 3398543 | ||||||||||||
| 278 | contextType == ContextType::Global; executed 3398543 times by 140 tests: return contextType == ContextType::Binding || contextType == ContextType::Eval || contextType == ContextType::Global;Executed by:
| 3398543 | ||||||||||||
| 279 | } | - | ||||||||||||
| 280 | - | |||||||||||||
| 281 | void addUsedVariable(const QString &name) { | - | ||||||||||||
| 282 | usedVariables.insert(name); | - | ||||||||||||
| 283 | } never executed: end of block | 0 | ||||||||||||
| 284 | - | |||||||||||||
| 285 | bool addLocalVar(const QString &name, MemberType contextType, QQmlJS::AST::VariableScope scope, QQmlJS::AST::FunctionExpression *function = nullptr); | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | struct ResolvedName { | - | ||||||||||||
| 288 | enum Type { | - | ||||||||||||
| 289 | Unresolved, | - | ||||||||||||
| 290 | Global, | - | ||||||||||||
| 291 | Local, | - | ||||||||||||
| 292 | Stack | - | ||||||||||||
| 293 | }; | - | ||||||||||||
| 294 | Type type = Unresolved; | - | ||||||||||||
| 295 | bool isArgOrEval = false; | - | ||||||||||||
| 296 | bool isConst = false; | - | ||||||||||||
| 297 | int scope = -1; | - | ||||||||||||
| 298 | int index = -1; | - | ||||||||||||
| 299 | bool isValid() const { return type != Unresolved; } never executed: return type != Unresolved; | 0 | ||||||||||||
| 300 | }; | - | ||||||||||||
| 301 | ResolvedName resolveName(const QString &name); | - | ||||||||||||
| 302 | void emitBlockHeader(Compiler::Codegen *codegen); | - | ||||||||||||
| 303 | void emitBlockFooter(Compiler::Codegen *codegen); | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | void setupFunctionIndices(Moth::BytecodeGenerator *bytecodeGenerator); | - | ||||||||||||
| 306 | }; | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | - | |||||||||||||
| 309 | } } // namespace QV4::Compiler | - | ||||||||||||
| 310 | - | |||||||||||||
| 311 | QT_END_NAMESPACE | - | ||||||||||||
| 312 | - | |||||||||||||
| 313 | #endif // QV4CODEGEN_P_H | - | ||||||||||||
| Source code | Switch to Preprocessed file |