7#include <QRegularExpression>
77 symbol += fi.baseName();
79 symbol += fi.completeSuffix();
100 stream <<
"#include <QtQml/qqmlprivate.h>\n";
101 stream <<
"#include <QtCore/qdir.h>\n";
102 stream <<
"#include <QtCore/qurl.h>\n";
103 stream <<
"#include <QtCore/qhash.h>\n";
104 stream <<
"#include <QtCore/qstring.h>\n";
107 stream <<
"namespace QmlCacheGeneratedCode {\n";
108 for (
int i = 0;
i < compiledFiles.size(); ++
i) {
109 const QString compiledFile = compiledFiles.
at(
i);
111 stream <<
"namespace " <<
ns <<
" { \n";
112 stream <<
" extern const unsigned char qmlData[];\n";
113 stream <<
" extern const QQmlPrivate::AOTCompiledFunction aotBuiltFunctions[];\n";
114 stream <<
" const QQmlPrivate::CachedQmlUnit unit = {\n";
115 stream <<
" reinterpret_cast<const QV4::CompiledData::Unit*>(&qmlData), &aotBuiltFunctions[0], nullptr\n";
121 stream <<
"namespace {\n";
123 stream <<
"struct Registry {\n";
124 stream <<
" Registry();\n";
125 stream <<
" ~Registry();\n";
126 stream <<
" QHash<QString, const QQmlPrivate::CachedQmlUnit*> resourcePathToCachedUnit;\n";
127 stream <<
" static const QQmlPrivate::CachedQmlUnit *lookupCachedUnit(const QUrl &url);\n";
129 stream <<
"Q_GLOBAL_STATIC(Registry, unitRegistry)\n";
132 stream <<
"Registry::Registry() {\n";
134 for (
int i = 0;
i < compiledFiles.size(); ++
i) {
137 stream <<
" resourcePathToCachedUnit.insert(QStringLiteral(\"" << qrcFile <<
"\"), &QmlCacheGeneratedCode::" <<
ns <<
"::unit);\n";
140 stream <<
" QQmlPrivate::RegisterQmlUnitCacheHook registration;\n";
141 stream <<
" registration.structVersion = 0;\n";
142 stream <<
" registration.lookupCachedQmlUnit = &lookupCachedUnit;\n";
143 stream <<
" QQmlPrivate::qmlregister(QQmlPrivate::QmlUnitCacheHookRegistration, ®istration);\n";
146 stream <<
"Registry::~Registry() {\n";
147 stream <<
" QQmlPrivate::qmlunregister(QQmlPrivate::QmlUnitCacheHookRegistration, quintptr(&lookupCachedUnit));\n";
150 stream <<
"const QQmlPrivate::CachedQmlUnit *Registry::lookupCachedUnit(const QUrl &url) {\n";
151 stream <<
" if (url.scheme() != QLatin1String(\"qrc\"))\n";
152 stream <<
" return nullptr;\n";
153 stream <<
" QString resourcePath = QDir::cleanPath(url.path());\n";
154 stream <<
" if (resourcePath.isEmpty())\n";
155 stream <<
" return nullptr;\n";
156 stream <<
" if (!resourcePath.startsWith(QLatin1Char('/')))\n";
157 stream <<
" resourcePath.prepend(QLatin1Char('/'));\n";
158 stream <<
" return unitRegistry()->resourcePathToCachedUnit.value(resourcePath, nullptr);\n";
166 if (mappingSplit != -1) {
167 newResourceFile = originalResourceFile.mid(mappingSplit + 1);
168 originalResourceFile.truncate(mappingSplit);
175 stream <<
" ::unitRegistry();\n";
176 if (!newResourceFile.isEmpty())
180 stream <<
"Q_CONSTRUCTOR_FUNCTION(QT_MANGLE_NAMESPACE(" << initFunction <<
"))\n";
184 if (!newResourceFile.isEmpty())
191#if QT_CONFIG(temporaryfile)
192 QSaveFile
f(outputFileName);
197 *errorString =
f.errorString();
201 if (
f.write(generatedLoaderCode) != generatedLoaderCode.size()) {
202 *errorString =
f.errorString();
206#if QT_CONFIG(temporaryfile)
208 *errorString =
f.errorString();
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
qsizetype indexOf(QLatin1StringView s, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QString & replace(qsizetype i, qsizetype len, QChar after)
void reserve(qsizetype size)
Ensures the string has space for at least size characters.
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const noexcept
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Combined button and popup list for selecting options.
GLenum GLenum GLenum GLenum mapping
static QString qtResourceNameForFile(const QString &fileName)
bool qQmlJSGenerateLoader(const QStringList &compiledFiles, const QString &outputFileName, const QStringList &resourceFileMappings, QString *errorString)
QT_BEGIN_NAMESPACE QString mangledIdentifier(const QString &str)
QString qQmlJSSymbolNamespaceForPath(const QString &relativePath)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
\inmodule QtCore \reentrant