| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/compiler/qqmltypecompiler_p.h |
| Source code | Switch to Preprocessed file |
| Line | Source | Count |
|---|---|---|
| 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 tools applications 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 QQMLTYPECOMPILER_P_H | - |
| 40 | #define QQMLTYPECOMPILER_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 <qglobal.h> | - |
| 54 | #include <qqmlerror.h> | - |
| 55 | #include <qhash.h> | - |
| 56 | #include <private/qqmltypeloader_p.h> | - |
| 57 | #include <private/qqmlirbuilder_p.h> | - |
| 58 | #include <private/qqmlpropertycachecreator_p.h> | - |
| 59 | - | |
| 60 | QT_BEGIN_NAMESPACE | - |
| 61 | - | |
| 62 | class QQmlEnginePrivate; | - |
| 63 | class QQmlError; | - |
| 64 | class QQmlTypeData; | - |
| 65 | class QQmlImports; | - |
| 66 | - | |
| 67 | namespace QmlIR { | - |
| 68 | struct Document; | - |
| 69 | } | - |
| 70 | - | |
| 71 | namespace QV4 { | - |
| 72 | namespace CompiledData { | - |
| 73 | struct QmlUnit; | - |
| 74 | struct Location; | - |
| 75 | } | - |
| 76 | } | - |
| 77 | - | |
| 78 | struct QQmlTypeCompiler | - |
| 79 | { | - |
| 80 | Q_DECLARE_TR_FUNCTIONS(QQmlTypeCompiler) | - |
| 81 | public: | - |
| 82 | QQmlTypeCompiler(QQmlEnginePrivate *engine, QQmlTypeData *typeData, QmlIR::Document *document, const QQmlRefPointer<QQmlTypeNameCache> &typeNameCache, const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypeCache, | - |
| 83 | const QV4::CompiledData::DependentTypesHasher &dependencyHasher); | - |
| 84 | - | |
| 85 | // --- interface used by QQmlPropertyCacheCreator | - |
| 86 | typedef QmlIR::Object CompiledObject; | - |
| 87 | const QmlIR::Object *objectAt(int index) const { return document->objects.at(index); } executed 71753 times by 141 tests: return document->objects.at(index);Executed by:
| 71753 |
| 88 | int objectCount() const { return document->objects.count(); } executed 48461 times by 141 tests: return document->objects.count();Executed by:
| 48461 |
| 89 | QString stringAt(int idx) const; | - |
| 90 | QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsBegin(const QmlIR::Object *object) const { return object->functionsBegin(); } executed 4594 times by 101 tests: return object->functionsBegin();Executed by:
| 4594 |
| 91 | QmlIR::PoolList<QmlIR::Function>::Iterator objectFunctionsEnd(const QmlIR::Object *object) const { return object->functionsEnd(); } executed 4594 times by 101 tests: return object->functionsEnd();Executed by:
| 4594 |
| 92 | QV4::CompiledData::ResolvedTypeReferenceMap resolvedTypes; | - |
| 93 | // --- | - |
| 94 | - | |
| 95 | QQmlRefPointer<QV4::CompiledData::CompilationUnit> compile(); | - |
| 96 | - | |
| 97 | QList<QQmlError> compilationErrors() const { return errors; } executed 8 times by 2 tests: return errors;Executed by:
| 8 |
| 98 | void recordError(QQmlError error); | - |
| 99 | void recordError(const QV4::CompiledData::Location &location, const QString &description); | - |
| 100 | void recordError(const QQmlCompileError &error); | - |
| 101 | - | |
| 102 | int registerString(const QString &str); | - |
| 103 | - | |
| 104 | const QV4::CompiledData::Unit *qmlUnit() const; | - |
| 105 | - | |
| 106 | QUrl url() const { return typeData->finalUrl(); } executed 3835 times by 95 tests: return typeData->finalUrl();Executed by:
| 3835 |
| 107 | QQmlEnginePrivate *enginePrivate() const { return engine; } executed 146726 times by 141 tests: return engine;Executed by:
| 146726 |
| 108 | const QQmlImports *imports() const; | - |
| 109 | QVector<QmlIR::Object *> *qmlObjects() const; | - |
| 110 | void setPropertyCaches(QQmlPropertyCacheVector &&caches); | - |
| 111 | const QQmlPropertyCacheVector *propertyCaches() const; | - |
| 112 | QQmlPropertyCacheVector &&takePropertyCaches(); | - |
| 113 | void setComponentRoots(const QVector<quint32> &roots) { m_componentRoots = roots; } executed 48455 times by 141 tests: end of blockExecuted by:
| 48455 |
| 114 | const QVector<quint32> &componentRoots() const { return m_componentRoots; } executed 48431 times by 140 tests: return m_componentRoots;Executed by:
| 48431 |
| 115 | QQmlJS::MemoryPool *memoryPool(); | - |
| 116 | QStringRef newStringRef(const QString &string); | - |
| 117 | const QV4::Compiler::StringTableGenerator *stringPool() const; | - |
| 118 | void setBindingPropertyDataPerObject(const QVector<QV4::CompiledData::BindingPropertyData> &propertyData); | - |
| 119 | - | |
| 120 | const QHash<int, QQmlCustomParser*> &customParserCache() const { return customParsers; } executed 193800 times by 141 tests: return customParsers;Executed by:
| 193800 |
| 121 | - | |
| 122 | QString bindingAsString(const QmlIR::Object *object, int scriptIndex) const; | - |
| 123 | - | |
| 124 | void addImport(const QString &module, const QString &qualifier, int majorVersion, int minorVersion); | - |
| 125 | - | |
| 126 | private: | - |
| 127 | QList<QQmlError> errors; | - |
| 128 | QQmlEnginePrivate *engine; | - |
| 129 | QQmlTypeData *typeData; | - |
| 130 | const QV4::CompiledData::DependentTypesHasher &dependencyHasher; | - |
| 131 | QQmlRefPointer<QQmlTypeNameCache> typeNameCache; | - |
| 132 | QmlIR::Document *document; | - |
| 133 | // index is string index of type name (use obj->inheritedTypeNameIndex) | - |
| 134 | QHash<int, QQmlCustomParser*> customParsers; | - |
| 135 | - | |
| 136 | // index in first hash is component index, vector inside contains object indices of objects with id property | - |
| 137 | QVector<quint32> m_componentRoots; | - |
| 138 | QQmlPropertyCacheVector m_propertyCaches; | - |
| 139 | }; | - |
| 140 | - | |
| 141 | struct QQmlCompilePass | - |
| 142 | { | - |
| 143 | QQmlCompilePass(QQmlTypeCompiler *typeCompiler); | - |
| 144 | - | |
| 145 | QString stringAt(int idx) const { return compiler->stringAt(idx); } executed 628669 times by 141 tests: return compiler->stringAt(idx);Executed by:
| 628669 |
| 146 | protected: | - |
| 147 | void recordError(const QV4::CompiledData::Location &location, const QString &description) const | - |
| 148 | { compiler->recordError(location, description); } executed 4 times by 1 test: end of blockExecuted by:
| 4 |
| 149 | void recordError(const QQmlCompileError &error) | - |
| 150 | { compiler->recordError(error); } never executed: end of block | 0 |
| 151 | - | |
| 152 | QQmlTypeCompiler *compiler; | - |
| 153 | }; | - |
| 154 | - | |
| 155 | // "Converts" signal expressions to full-fleged function declarations with | - |
| 156 | // parameters taken from the signal declarations | - |
| 157 | // It also updates the QV4::CompiledData::Binding objects to set the property name | - |
| 158 | // to the final signal name (onTextChanged -> textChanged) and sets the IsSignalExpression flag. | - |
| 159 | struct SignalHandlerConverter : public QQmlCompilePass | - |
| 160 | { | - |
| 161 | Q_DECLARE_TR_FUNCTIONS(SignalHandlerConverter) | - |
| 162 | public: | - |
| 163 | SignalHandlerConverter(QQmlTypeCompiler *typeCompiler); | - |
| 164 | - | |
| 165 | bool convertSignalHandlerExpressionsToFunctionDeclarations(); | - |
| 166 | - | |
| 167 | private: | - |
| 168 | bool convertSignalHandlerExpressionsToFunctionDeclarations(const QmlIR::Object *obj, const QString &typeName, QQmlPropertyCache *propertyCache); | - |
| 169 | - | |
| 170 | QQmlEnginePrivate *enginePrivate; | - |
| 171 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 172 | const QQmlImports *imports; | - |
| 173 | const QHash<int, QQmlCustomParser*> &customParsers; | - |
| 174 | const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypes; | - |
| 175 | const QSet<QString> &illegalNames; | - |
| 176 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 177 | }; | - |
| 178 | - | |
| 179 | // ### This will go away when the codegen resolves all enums to constant expressions | - |
| 180 | // and we replace the constant expression with a literal binding instead of using | - |
| 181 | // a script. | - |
| 182 | class QQmlEnumTypeResolver : public QQmlCompilePass | - |
| 183 | { | - |
| 184 | Q_DECLARE_TR_FUNCTIONS(QQmlEnumTypeResolver) | - |
| 185 | public: | - |
| 186 | QQmlEnumTypeResolver(QQmlTypeCompiler *typeCompiler); | - |
| 187 | - | |
| 188 | bool resolveEnumBindings(); | - |
| 189 | - | |
| 190 | private: | - |
| 191 | bool assignEnumToBinding(QmlIR::Binding *binding, const QStringRef &enumName, int enumValue, bool isQtObject); | - |
| 192 | bool assignEnumToBinding(QmlIR::Binding *binding, const QString &enumName, int enumValue, bool isQtObject) | - |
| 193 | { | - |
| 194 | return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject); never executed: return assignEnumToBinding(binding, QStringRef(&enumName), enumValue, isQtObject); | 0 |
| 195 | } | - |
| 196 | bool tryQualifiedEnumAssignment(const QmlIR::Object *obj, const QQmlPropertyCache *propertyCache, | - |
| 197 | const QQmlPropertyData *prop, | - |
| 198 | QmlIR::Binding *binding); | - |
| 199 | int evaluateEnum(const QString &scope, const QStringRef &enumName, const QStringRef &enumValue, bool *ok) const; | - |
| 200 | - | |
| 201 | - | |
| 202 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 203 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 204 | const QQmlImports *imports; | - |
| 205 | QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypes; | - |
| 206 | }; | - |
| 207 | - | |
| 208 | class QQmlCustomParserScriptIndexer: public QQmlCompilePass | - |
| 209 | { | - |
| 210 | public: | - |
| 211 | QQmlCustomParserScriptIndexer(QQmlTypeCompiler *typeCompiler); | - |
| 212 | - | |
| 213 | void annotateBindingsWithScriptStrings(); | - |
| 214 | - | |
| 215 | private: | - |
| 216 | void scanObjectRecursively(int objectIndex, bool annotateScriptBindings = false); | - |
| 217 | - | |
| 218 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 219 | const QHash<int, QQmlCustomParser*> &customParsers; | - |
| 220 | }; | - |
| 221 | - | |
| 222 | // Annotate properties bound to aliases with a flag | - |
| 223 | class QQmlAliasAnnotator : public QQmlCompilePass | - |
| 224 | { | - |
| 225 | public: | - |
| 226 | QQmlAliasAnnotator(QQmlTypeCompiler *typeCompiler); | - |
| 227 | - | |
| 228 | void annotateBindingsToAliases(); | - |
| 229 | private: | - |
| 230 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 231 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 232 | }; | - |
| 233 | - | |
| 234 | class QQmlScriptStringScanner : public QQmlCompilePass | - |
| 235 | { | - |
| 236 | public: | - |
| 237 | QQmlScriptStringScanner(QQmlTypeCompiler *typeCompiler); | - |
| 238 | - | |
| 239 | void scan(); | - |
| 240 | - | |
| 241 | private: | - |
| 242 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 243 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 244 | }; | - |
| 245 | - | |
| 246 | class QQmlComponentAndAliasResolver : public QQmlCompilePass | - |
| 247 | { | - |
| 248 | Q_DECLARE_TR_FUNCTIONS(QQmlAnonymousComponentResolver) | - |
| 249 | public: | - |
| 250 | QQmlComponentAndAliasResolver(QQmlTypeCompiler *typeCompiler); | - |
| 251 | - | |
| 252 | bool resolve(); | - |
| 253 | - | |
| 254 | protected: | - |
| 255 | void findAndRegisterImplicitComponents(const QmlIR::Object *obj, QQmlPropertyCache *propertyCache); | - |
| 256 | bool collectIdsAndAliases(int objectIndex); | - |
| 257 | bool resolveAliases(int componentIndex); | - |
| 258 | void propertyDataForAlias(QmlIR::Alias *alias, int *type, quint32 *propertyFlags); | - |
| 259 | - | |
| 260 | enum AliasResolutionResult { | - |
| 261 | NoAliasResolved, | - |
| 262 | SomeAliasesResolved, | - |
| 263 | AllAliasesResolved | - |
| 264 | }; | - |
| 265 | - | |
| 266 | AliasResolutionResult resolveAliasesInObject(int objectIndex, QQmlCompileError *error); | - |
| 267 | - | |
| 268 | QQmlEnginePrivate *enginePrivate; | - |
| 269 | QQmlJS::MemoryPool *pool; | - |
| 270 | - | |
| 271 | QVector<QmlIR::Object*> *qmlObjects; | - |
| 272 | - | |
| 273 | // indices of the objects that are actually Component {} | - |
| 274 | QVector<quint32> componentRoots; | - |
| 275 | - | |
| 276 | // Deliberate choice of map over hash here to ensure stable generated output. | - |
| 277 | QMap<int, int> _idToObjectIndex; | - |
| 278 | QVector<int> _objectsWithAliases; | - |
| 279 | - | |
| 280 | QV4::CompiledData::ResolvedTypeReferenceMap *resolvedTypes; | - |
| 281 | QQmlPropertyCacheVector propertyCaches; | - |
| 282 | }; | - |
| 283 | - | |
| 284 | class QQmlDeferredAndCustomParserBindingScanner : public QQmlCompilePass | - |
| 285 | { | - |
| 286 | public: | - |
| 287 | QQmlDeferredAndCustomParserBindingScanner(QQmlTypeCompiler *typeCompiler); | - |
| 288 | - | |
| 289 | bool scanObject(); | - |
| 290 | - | |
| 291 | private: | - |
| 292 | bool scanObject(int objectIndex); | - |
| 293 | - | |
| 294 | QVector<QmlIR::Object*> *qmlObjects; | - |
| 295 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 296 | const QHash<int, QQmlCustomParser*> &customParsers; | - |
| 297 | - | |
| 298 | bool _seenObjectWithId; | - |
| 299 | }; | - |
| 300 | - | |
| 301 | // ### merge with QtQml::JSCodeGen and operate directly on object->functionsAndExpressions once old compiler is gone. | - |
| 302 | class QQmlJSCodeGenerator : public QQmlCompilePass | - |
| 303 | { | - |
| 304 | public: | - |
| 305 | QQmlJSCodeGenerator(QQmlTypeCompiler *typeCompiler, QmlIR::JSCodeGen *v4CodeGen); | - |
| 306 | - | |
| 307 | bool generateCodeForComponents(); | - |
| 308 | - | |
| 309 | private: | - |
| 310 | bool compileComponent(int componentRoot); | - |
| 311 | bool compileJavaScriptCodeInObjectsRecursively(int objectIndex, int scopeObjectIndex); | - |
| 312 | - | |
| 313 | const QV4::CompiledData::ResolvedTypeReferenceMap &resolvedTypes; | - |
| 314 | const QHash<int, QQmlCustomParser*> &customParsers; | - |
| 315 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 316 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 317 | QmlIR::JSCodeGen * const v4CodeGen; | - |
| 318 | }; | - |
| 319 | - | |
| 320 | class QQmlDefaultPropertyMerger : public QQmlCompilePass | - |
| 321 | { | - |
| 322 | public: | - |
| 323 | QQmlDefaultPropertyMerger(QQmlTypeCompiler *typeCompiler); | - |
| 324 | - | |
| 325 | void mergeDefaultProperties(); | - |
| 326 | - | |
| 327 | private: | - |
| 328 | void mergeDefaultProperties(int objectIndex); | - |
| 329 | - | |
| 330 | const QVector<QmlIR::Object*> &qmlObjects; | - |
| 331 | const QQmlPropertyCacheVector * const propertyCaches; | - |
| 332 | }; | - |
| 333 | - | |
| 334 | QT_END_NAMESPACE | - |
| 335 | - | |
| 336 | #endif // QQMLTYPECOMPILER_P_H | - |
| Source code | Switch to Preprocessed file |