aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-11-18 14:24:12 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-11-26 11:57:57 +0100
commit17bfd9c69467f2e7e426674d8d9fc4b9112e852d (patch)
treebca2edde54abcae6a5719d7fe814c42e09016f6a
parentcb3ec010fff39a9b5b35b1afb3af478cf118c3ca (diff)
QmlCompiler: Tighten the constness of various method parameters
The compile passes shouldn't need to change the document, AST, or IR. At least not accidentally. We might add interfaces to explicitly modify things later. As a side effect, you can now use one instance of QQmlJSTypeResolver for multiple documents by re-init()'ing it. Change-Id: Ic3544b3ddedd30d7f8d00b1df9cee3e6292ca7de Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljscompiler_p.h2
-rw-r--r--src/qmlcompiler/qqmljsshadowcheck_p.h2
-rw-r--r--src/qmlcompiler/qqmljstypepropagator.cpp2
-rw-r--r--src/qmlcompiler/qqmljstypepropagator_p.h2
-rw-r--r--src/qmlcompiler/qqmljstyperesolver.cpp10
-rw-r--r--src/qmlcompiler/qqmljstyperesolver_p.h2
-rw-r--r--src/qmllint/codegen.cpp12
-rw-r--r--src/qmllint/codegen_p.h5
-rw-r--r--src/qmllint/qqmllinter.cpp2
-rw-r--r--tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp2
-rw-r--r--tools/qmltc/main.cpp3
-rw-r--r--tools/qmltc/qmltctyperesolver.h5
12 files changed, 26 insertions, 23 deletions
diff --git a/src/qmlcompiler/qqmljscompiler_p.h b/src/qmlcompiler/qqmljscompiler_p.h
index f2b80f272b..59cbcd6c9c 100644
--- a/src/qmlcompiler/qqmljscompiler_p.h
+++ b/src/qmlcompiler/qqmljscompiler_p.h
@@ -74,7 +74,7 @@ class QQmlJSAotCompiler
public:
virtual ~QQmlJSAotCompiler() = default;
- virtual void setDocument(QmlIR::JSCodeGen *codegen, QmlIR::Document *document) = 0;
+ virtual void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document) = 0;
virtual void setScope(const QmlIR::Object *object, const QmlIR::Object *scope) = 0;
virtual std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> compileBinding(
const QV4::Compiler::Context *context,
diff --git a/src/qmlcompiler/qqmljsshadowcheck_p.h b/src/qmlcompiler/qqmljsshadowcheck_p.h
index bb98ca311b..0a6a566e46 100644
--- a/src/qmlcompiler/qqmljsshadowcheck_p.h
+++ b/src/qmlcompiler/qqmljsshadowcheck_p.h
@@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE
class QQmlJSShadowCheck : public QQmlJSCompilePass
{
public:
- QQmlJSShadowCheck(QV4::Compiler::JSUnitGenerator *jsUnitGenerator,
+ QQmlJSShadowCheck(const QV4::Compiler::JSUnitGenerator *jsUnitGenerator,
QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger)
: QQmlJSCompilePass(jsUnitGenerator, typeResolver, logger)
{}
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp
index 9e49cb3cb5..430762cbe1 100644
--- a/src/qmlcompiler/qqmljstypepropagator.cpp
+++ b/src/qmlcompiler/qqmljstypepropagator.cpp
@@ -31,7 +31,7 @@
QT_BEGIN_NAMESPACE
-QQmlJSTypePropagator::QQmlJSTypePropagator(QV4::Compiler::JSUnitGenerator *unitGenerator,
+QQmlJSTypePropagator::QQmlJSTypePropagator(const QV4::Compiler::JSUnitGenerator *unitGenerator,
QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger,
QQmlJSTypeInfo *typeInfo)
: QQmlJSCompilePass(unitGenerator, typeResolver, logger), m_typeInfo(typeInfo)
diff --git a/src/qmlcompiler/qqmljstypepropagator_p.h b/src/qmlcompiler/qqmljstypepropagator_p.h
index 25194c83f9..c864702cf9 100644
--- a/src/qmlcompiler/qqmljstypepropagator_p.h
+++ b/src/qmlcompiler/qqmljstypepropagator_p.h
@@ -48,7 +48,7 @@ QT_BEGIN_NAMESPACE
struct QQmlJSTypePropagator : public QQmlJSCompilePass
{
- QQmlJSTypePropagator(QV4::Compiler::JSUnitGenerator *unitGenerator,
+ QQmlJSTypePropagator(const QV4::Compiler::JSUnitGenerator *unitGenerator,
QQmlJSTypeResolver *typeResolver, QQmlJSLogger *logger,
QQmlJSTypeInfo *typeInfo = nullptr);
diff --git a/src/qmlcompiler/qqmljstyperesolver.cpp b/src/qmlcompiler/qqmljstyperesolver.cpp
index 60cb757adc..2595275dd5 100644
--- a/src/qmlcompiler/qqmljstyperesolver.cpp
+++ b/src/qmlcompiler/qqmljstyperesolver.cpp
@@ -63,8 +63,7 @@ static bool searchBaseAndExtensionTypes(const QQmlJSScope::ConstPtr type, const
return false;
}
-QQmlJSTypeResolver::QQmlJSTypeResolver(QQmlJSImporter *importer, QQmlJSLogger *logger)
- : m_logger(logger)
+QQmlJSTypeResolver::QQmlJSTypeResolver(QQmlJSImporter *importer)
{
const QHash<QString, QQmlJSScope::ConstPtr> builtinTypes = importer->builtinInternalNames();
m_voidType = builtinTypes[u"void"_qs];
@@ -114,6 +113,13 @@ QQmlJSTypeResolver::QQmlJSTypeResolver(QQmlJSImporter *importer, QQmlJSLogger *l
*/
void QQmlJSTypeResolver::init(QQmlJSImportVisitor *visitor, QQmlJS::AST::Node *program)
{
+ m_logger = visitor->logger();
+
+ m_objectsById.clear();
+ m_objectsByLocation.clear();
+ m_imports.clear();
+ m_signalHandlers.clear();
+
program->accept(visitor);
m_objectsById = visitor->addressableScopes();
diff --git a/src/qmlcompiler/qqmljstyperesolver_p.h b/src/qmlcompiler/qqmljstyperesolver_p.h
index 31bdeb5da1..ab5d607b8f 100644
--- a/src/qmlcompiler/qqmljstyperesolver_p.h
+++ b/src/qmlcompiler/qqmljstyperesolver_p.h
@@ -62,7 +62,7 @@ public:
QString setter;
};
- QQmlJSTypeResolver(QQmlJSImporter *importer, QQmlJSLogger *logger);
+ QQmlJSTypeResolver(QQmlJSImporter *importer);
// Note: must be called after the construction to read the QML program
void init(QQmlJSImportVisitor *visitor, QQmlJS::AST::Node *program);
diff --git a/src/qmllint/codegen.cpp b/src/qmllint/codegen.cpp
index dc961f85e0..229fc44655 100644
--- a/src/qmllint/codegen.cpp
+++ b/src/qmllint/codegen.cpp
@@ -47,11 +47,10 @@ Codegen::Codegen(const QString &fileName, const QStringList &qmltypesFiles, QQml
{
}
-void Codegen::setDocument(QmlIR::JSCodeGen *codegen, QmlIR::Document *document)
+void Codegen::setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document)
{
Q_UNUSED(codegen);
m_document = document;
- m_pool = document->jsParserEngine.pool();
m_unitGenerator = &document->jsGenerator;
m_entireSourceCodeLines = document->code.split(u'\n');
}
@@ -164,19 +163,20 @@ Codegen::compileBinding(const QV4::Compiler::Context *context, const QmlIR::Bind
m_currentObject->functionsAndExpressions->slowAt(irBinding.value.compiledScriptIndex)
->node;
auto ast = astNode->asFunctionDefinition();
+ QQmlJS::MemoryPool pool;
if (!ast) {
QQmlJS::AST::Statement *stmt = astNode->statementCast();
if (!stmt) {
Q_ASSERT(astNode->expressionCast());
QQmlJS::AST::ExpressionNode *expr = astNode->expressionCast();
- stmt = new (m_pool) QQmlJS::AST::ExpressionStatement(expr);
+ stmt = new (&pool) QQmlJS::AST::ExpressionStatement(expr);
}
- auto body = new (m_pool) QQmlJS::AST::StatementList(stmt);
+ auto body = new (&pool) QQmlJS::AST::StatementList(stmt);
body = body->finish();
QString name = u"binding for "_qs; // ####
- ast = new (m_pool) QQmlJS::AST::FunctionDeclaration(m_pool->newString(name),
- /*formals*/ nullptr, body);
+ ast = new (&pool) QQmlJS::AST::FunctionDeclaration(
+ pool.newString(name), /*formals*/ nullptr, body);
ast->lbraceToken = astNode->firstSourceLocation();
ast->functionToken = ast->lbraceToken;
ast->rbraceToken = astNode->lastSourceLocation();
diff --git a/src/qmllint/codegen_p.h b/src/qmllint/codegen_p.h
index b59a97da2e..a2d65e5b09 100644
--- a/src/qmllint/codegen_p.h
+++ b/src/qmllint/codegen_p.h
@@ -62,7 +62,7 @@ public:
Codegen(const QString &fileName, const QStringList &qmltypesFiles,
QQmlJSLogger *logger, QQmlJSTypeInfo *typeInfo, const QString &m_code);
- void setDocument(QmlIR::JSCodeGen *codegen, QmlIR::Document *document) override;
+ void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document) override;
void setScope(const QmlIR::Object *object, const QmlIR::Object *scope) override;
std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage>
compileBinding(const QV4::Compiler::Context *context, const QmlIR::Binding &irBinding) override;
@@ -85,11 +85,10 @@ private:
const QStringList m_resourceFiles;
const QStringList m_qmltypesFiles;
- QQmlJS::MemoryPool *m_pool = nullptr;
const QmlIR::Object *m_currentObject = nullptr;
QQmlJSScope::ConstPtr m_scopeType;
QQmlJSScope::ConstPtr m_objectType;
- QV4::Compiler::JSUnitGenerator *m_unitGenerator = nullptr;
+ const QV4::Compiler::JSUnitGenerator *m_unitGenerator = nullptr;
QStringList m_entireSourceCodeLines;
QQmlJSLogger *m_logger;
QQmlJSTypeInfo *m_typeInfo;
diff --git a/src/qmllint/qqmllinter.cpp b/src/qmllint/qqmllinter.cpp
index c8b5d09735..30115457ad 100644
--- a/src/qmllint/qqmllinter.cpp
+++ b/src/qmllint/qqmllinter.cpp
@@ -185,7 +185,7 @@ bool QQmlLinter::lintFile(const QString &filename, const QString *fileContents,
}
std::unique_ptr<QQmlJSTypeResolver> typeResolver
- = std::make_unique<QQmlJSTypeResolver>(&m_importer, m_logger.get());
+ = std::make_unique<QQmlJSTypeResolver>(&m_importer);
// Type resolving is using document parent mode here so that it produces fewer false positives
// on the "parent" property of QQuickItem. It does produce a few false negatives this way
diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
index 0f0c76ad43..6ad07ace1d 100644
--- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
+++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp
@@ -85,7 +85,7 @@ class tst_qqmljsscope : public QQmlDataTest
QQmlJSImporter importer { importPaths, /* resource file mapper */ nullptr };
QQmlJSLogger logger(url, sourceCode, /* silent */ true);
QQmlJSImportVisitor visitor(&importer, &logger, dataDirectory());
- QQmlJSTypeResolver typeResolver { &importer, &logger };
+ QQmlJSTypeResolver typeResolver { &importer };
typeResolver.init(&visitor, document.program);
return visitor.result();
}
diff --git a/tools/qmltc/main.cpp b/tools/qmltc/main.cpp
index d749b91c35..941685fb5d 100644
--- a/tools/qmltc/main.cpp
+++ b/tools/qmltc/main.cpp
@@ -173,8 +173,9 @@ int main(int argc, char **argv)
QQmlJSLogger logger(url, sourceCode, /* silent */ false);
setupLogger(logger);
QmltcVisitor visitor(&importer, &logger, implicitImportDirectory, qmltypesFiles);
- QmltcTypeResolver typeResolver { &importer, &logger };
+ QmltcTypeResolver typeResolver { &importer };
typeResolver.init(&visitor, document.program);
+
if (logger.hasWarnings() || logger.hasErrors())
return EXIT_FAILURE;
diff --git a/tools/qmltc/qmltctyperesolver.h b/tools/qmltc/qmltctyperesolver.h
index 2be59d9087..495f78b81d 100644
--- a/tools/qmltc/qmltctyperesolver.h
+++ b/tools/qmltc/qmltctyperesolver.h
@@ -39,10 +39,7 @@ QT_BEGIN_NAMESPACE
class QmltcTypeResolver : public QQmlJSTypeResolver
{
public:
- QmltcTypeResolver(QQmlJSImporter *importer, QQmlJSLogger *logger)
- : QQmlJSTypeResolver(importer, logger)
- {
- }
+ QmltcTypeResolver(QQmlJSImporter *importer) : QQmlJSTypeResolver(importer) {}
};
QT_END_NAMESPACE