Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljsstorageinitializer.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
6
8
9/*!
10 * \internal
11 * \class QQmlJSStorageInitializer
12 *
13 * The QQmlJSStorageInitializer is a compile pass that initializes the storage
14 * for all register contents.
15 *
16 * QQmlJSStorageInitializer does not have to use the byte code at all but
17 * operates only on the annotations and the function description.
18 */
19
20QQmlJSCompilePass::BlocksAndAnnotations QQmlJSStorageInitializer::run(Function *function)
21{
22 m_function = function;
23
24 if (QQmlJSRegisterContent &returnType = function->returnType; returnType.isValid()) {
25 if (const QQmlJSScope::ConstPtr stored
26 = m_typeResolver->storedType(returnType.containedType())) {
27 m_pool->storeType(returnType, stored);
28 } else {
29 addError(QStringLiteral("Cannot store the return type %1.")
30 .arg(returnType.containedType()->internalName()));
31 return {};
32 }
33 }
34
35 const auto storeRegister = [&](QQmlJSRegisterContent &content) {
36 if (!content.isValid() || !content.storage().isNull())
37 return;
38
39 const QQmlJSScope::ConstPtr original = m_typeResolver->originalContainedType(content);
40 if (const QQmlJSScope::ConstPtr originalStored = m_typeResolver->storedType(original)) {
41 m_pool->storeType(content, originalStored);
42 } else {
43 addError(QStringLiteral("Cannot store type %1.").arg(original->internalName()));
44 return;
45 }
46
47 const QQmlJSScope::ConstPtr contentContained = content.containedType();
48 const QQmlJSScope::ConstPtr adjustedStored = m_typeResolver->storedType(contentContained);
49 if (!adjustedStored) {
50 addError(QStringLiteral("Cannot store type %1.")
51 .arg(contentContained->internalName()));
52 return;
53 }
54
55 if (!m_typeResolver->adjustTrackedType(content.storage(), adjustedStored)) {
56 addError(QStringLiteral("Cannot adjust stored type for %1 to %2.")
57 .arg(contentContained->internalName(), adjustedStored->internalName()));
58 }
59 };
60
61 const auto storeRegisters = [&](VirtualRegisters &registers) {
62 for (auto j = registers.begin(), jEnd = registers.end(); j != jEnd; ++j)
63 storeRegister(j.value().content);
64 };
65
66 storeRegister(function->qmlScope);
67
68 for (QQmlJSRegisterContent &argument : function->argumentTypes) {
69 Q_ASSERT(argument.isValid());
70 storeRegister(argument);
71 }
72
73 for (QQmlJSRegisterContent &argument : function->registerTypes) {
74 Q_ASSERT(argument.isValid());
75 storeRegister(argument);
76 }
77
78 for (auto i = m_annotations.begin(), iEnd = m_annotations.end(); i != iEnd; ++i) {
79 storeRegister(i->second.changedRegister);
80 storeRegisters(i->second.typeConversions);
81 storeRegisters(i->second.readRegisters);
82 }
83
84 return { std::move(m_basicBlocks), std::move(m_annotations) };
85}
86
87QT_END_NAMESPACE