7#include <QtQmlCompiler/private/qqmljsimportvisitor_p.h>
8#include <QtQmlCompiler/private/qqmljsshadowcheck_p.h>
9#include <QtQmlCompiler/private/qqmljsstoragegeneralizer_p.h>
10#include <QtQmlCompiler/private/qqmljsstorageinitializer_p.h>
11#include <QtQmlCompiler/private/qqmljsfunctioninitializer_p.h>
12#include <QtQmlCompiler/private/qqmljsbasicblocks_p.h>
18using namespace Qt::StringLiterals;
21 const QStringList &qmldirFiles, QQmlJSLogger *logger,
22 const ContextPropertyInfo &contextPropertyInfo)
29 const QmlIR::Document *document)
32 m_document = document;
33 m_unitGenerator = &document->jsGenerator;
36std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>>
37QQmlJSLinterCodegen::compileBinding(
const QV4::Compiler::Context *context,
38 const QmlIR::Binding &irBinding, QQmlJS::AST::Node *astNode)
40 const QString name = m_document->stringAt(irBinding.propertyNameIndex);
41 m_logger->setCompileErrorPrefix(
42 u"Could not determine signature of binding for %1: "_s.arg(name));
44 QQmlJSFunctionInitializer initializer(
45 &m_typeResolver, m_currentObject->location, m_currentScope->location, m_logger);
46 QQmlJSCompilePass::Function function = initializer.run(context, name, astNode, irBinding);
48 m_logger->iterateCurrentFunctionMessages([
this](
const Message &error) {
49 diagnose(error.message, error.type, error.loc);
52 m_logger->setCompileErrorPrefix(u"Could not compile binding for %1: "_s.arg(name));
53 m_logger->setCompileSkipPrefix(u"Compilation of binding for %1 was skipped: "_s.arg(name));
55 analyzeFunction(context, &function);
56 if (
const auto errors = finalizeBindingOrFunction())
59 return QQmlJSAotFunction {};
62std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>>
63QQmlJSLinterCodegen::compileFunction(
const QV4::Compiler::Context *context,
64 const QString &name, QQmlJS::AST::Node *astNode)
66 m_logger->setCompileErrorPrefix(u"Could not determine signature of function %1: "_s.arg(name));
68 QQmlJSFunctionInitializer initializer(
69 &m_typeResolver, m_currentObject->location, m_currentScope->location, m_logger);
70 QQmlJSCompilePass::Function function = initializer.run(context, name, astNode);
72 m_logger->iterateCurrentFunctionMessages([
this](
const Message &error) {
73 diagnose(error.message, error.type, error.loc);
76 m_logger->setCompileErrorPrefix(u"Could not compile function %1: "_s.arg(name));
77 m_logger->setCompileSkipPrefix(u"Compilation of function %1 was skipped: "_s.arg(name));
78 analyzeFunction(context, &function);
80 if (
const auto errors = finalizeBindingOrFunction())
83 return QQmlJSAotFunction {};
88 m_passManager = passManager;
89 auto managerPriv = QQmlSA::PassManagerPrivate::get(passManager);
90 managerPriv->m_typeResolver = typeResolver();
94 QQmlJSCompilePass::Function *function)
97 QQmlJSCompilePass::BlocksAndAnnotations blocksAndAnnotations =
98 QQmlJSBasicBlocks(context, m_unitGenerator, &m_typeResolver, m_logger)
99 .run(function, ValidateBasicBlocks, dummy);
101 blocksAndAnnotations =
102 QQmlJSTypePropagator(m_unitGenerator, &m_typeResolver, m_logger,
103 blocksAndAnnotations.basicBlocks, blocksAndAnnotations.annotations,
104 m_passManager, m_contextPropertyInfo)
107 if (m_logger->isCategoryIgnored(qmlCompiler))
110 if (!m_logger->currentFunctionHasCompileError()) {
111 blocksAndAnnotations = QQmlJSShadowCheck(m_unitGenerator, &m_typeResolver, m_logger,
112 blocksAndAnnotations.basicBlocks,
113 blocksAndAnnotations.annotations)
117 if (!m_logger->currentFunctionHasCompileError()) {
118 blocksAndAnnotations = QQmlJSStorageInitializer(m_unitGenerator, &m_typeResolver, m_logger,
119 blocksAndAnnotations.basicBlocks,
120 blocksAndAnnotations.annotations)
124 if (!m_logger->currentFunctionHasCompileError()) {
125 blocksAndAnnotations = QQmlJSStorageGeneralizer(m_unitGenerator, &m_typeResolver, m_logger,
126 blocksAndAnnotations.basicBlocks,
127 blocksAndAnnotations.annotations)
QQmlJSLinterCodegen(QQmlJSImporter *importer, const QString &fileName, const QStringList &qmldirFiles, QQmlJSLogger *logger, const ContextPropertyInfo &contextPropertyInfo)
void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document) override
void setPassManager(QQmlSA::PassManager *passManager)