aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmllint
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 /src/qmllint
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>
Diffstat (limited to 'src/qmllint')
-rw-r--r--src/qmllint/codegen.cpp12
-rw-r--r--src/qmllint/codegen_p.h5
-rw-r--r--src/qmllint/qqmllinter.cpp2
3 files changed, 9 insertions, 10 deletions
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