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
qqmljscompiler_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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
5#ifndef QQMLJSCOMPILER_P_H
6#define QQMLJSCOMPILER_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <qtqmlcompilerexports.h>
19
20#include <QtCore/qstring.h>
21#include <QtCore/qlist.h>
22#include <QtCore/qloggingcategory.h>
23
24#include <private/qqmlirbuilder_p.h>
25#include <private/qqmljscompilepass_p.h>
26#include <private/qqmljscompilerstats_p.h>
27#include <private/qqmljsdiagnosticmessage_p.h>
28#include <private/qqmljsimporter_p.h>
29#include <private/qqmljslogger_p.h>
30#include <private/qqmljstyperesolver_p.h>
31#include <private/qv4compileddata_p.h>
32
33#include <functional>
34
36
38
39struct Q_QMLCOMPILER_EXPORT QQmlJSCompileError
40{
41 QString message;
42 void print();
43 QQmlJSCompileError augment(const QString &contextErrorMessage) const;
44 void appendDiagnostics(const QString &inputFileName,
45 const QList<QQmlJS::DiagnosticMessage> &diagnostics);
46 void appendDiagnostic(const QString &inputFileName,
47 const QQmlJS::DiagnosticMessage &diagnostic);
48};
49
50struct Q_QMLCOMPILER_EXPORT QQmlJSAotFunction
51{
52 QStringList includes;
53 QString code;
54 QString signature;
55 std::optional<QString> skipReason;
56 int numArguments = 0;
57};
58
59class Q_QMLCOMPILER_EXPORT QQmlJSAotCompiler
60{
61public:
62 enum Flag {
63 NoFlags = 0x0,
64 ValidateBasicBlocks = 0x1,
65 IsLintCompiler = 0x2, // When we're linting and not compiling
66 };
67 Q_DECLARE_FLAGS(Flags, Flag)
68
69 QQmlJSAotCompiler(QQmlJSImporter *importer, const QString &resourcePath,
70 const QStringList &qmldirFiles, QQmlJSLogger *logger);
71
72 virtual ~QQmlJSAotCompiler() = default;
73
74 virtual void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document);
75 virtual void setScope(const QmlIR::Object *object, const QmlIR::Object *scope);
76 virtual std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>> compileBinding(
77 const QV4::Compiler::Context *context, const QmlIR::Binding &irBinding,
78 QQmlJS::AST::Node *astNode);
79 virtual std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>> compileFunction(
80 const QV4::Compiler::Context *context, const QString &name, QQmlJS::AST::Node *astNode);
81
82 virtual QQmlJSAotFunction globalCode() const;
83
84 bool isLintCompiler() const { return m_flags & IsLintCompiler; }
85
86 Flags m_flags;
87
88protected:
89 std::optional<QList<QQmlJS::DiagnosticMessage>> finalizeBindingOrFunction();
90
91 virtual QQmlJS::DiagnosticMessage diagnose(
92 const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location) const;
93
94 QQmlJSTypeResolver m_typeResolver;
95
96 const QString m_resourcePath;
97 const QStringList m_qmldirFiles;
98
99 const QmlIR::Document *m_document = nullptr;
100 const QmlIR::Object *m_currentObject = nullptr;
101 const QmlIR::Object *m_currentScope = nullptr;
102 const QV4::Compiler::JSUnitGenerator *m_unitGenerator = nullptr;
103
104 QQmlJSImporter *m_importer = nullptr;
105 QQmlJSLogger *m_logger = nullptr;
106
107private:
108 QQmlJSAotFunction doCompile(
109 const QV4::Compiler::Context *context, QQmlJSCompilePass::Function *function);
110 QQmlJSAotFunction doCompileAndRecordAotStats(
111 const QV4::Compiler::Context *context, QQmlJSCompilePass::Function *function,
112 const QString &name, QQmlJS::SourceLocation location);
113};
114
115Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlJSAotCompiler::Flags);
116
117using QQmlJSAotFunctionMap = QMap<int, QQmlJSAotFunction>;
119 = std::function<bool(const QV4::CompiledData::SaveableUnitPointer &,
120 const QQmlJSAotFunctionMap &, QString *)>;
121
122bool Q_QMLCOMPILER_EXPORT qCompileQmlFile(const QString &inputFileName,
123 const QQmlJSSaveFunction &saveFunction,
124 QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
125 bool storeSourceLocation = false,
126 QV4::Compiler::CodegenWarningInterface *wInterface =
127 QV4::Compiler::defaultCodegenWarningInterface(),
128 const QString *fileContents = nullptr);
129bool Q_QMLCOMPILER_EXPORT qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName,
130 const QQmlJSSaveFunction &saveFunction,
131 QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
132 bool storeSourceLocation = false,
133 QV4::Compiler::CodegenWarningInterface *wInterface =
134 QV4::Compiler::defaultCodegenWarningInterface(),
135 const QString *fileContents = nullptr);
136bool Q_QMLCOMPILER_EXPORT qCompileJSFile(const QString &inputFileName, const QString &inputFileUrl,
137 const QQmlJSSaveFunction &saveFunction,
138 QQmlJSCompileError *error);
139
140bool Q_QMLCOMPILER_EXPORT qSaveQmlJSUnitAsCpp(const QString &inputFileName,
141 const QString &outputFileName,
142 const QV4::CompiledData::SaveableUnitPointer &unit,
143 const QQmlJSAotFunctionMap &aotFunctions,
144 QString *errorString);
145
146QT_END_NAMESPACE
147
148#endif // QQMLJSCOMPILER_P_H
const QmlIR::Function * function() const
const QmlIR::Binding * binding() const
friend bool operator<(const BindingOrFunction &lhs, const BindingOrFunction &rhs)
BindingOrFunction(const QmlIR::Binding &b)
quint32 index() const
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
static bool isStrict(const QmlIR::Document *doc)
static const char * funcHeaderCode
static bool checkArgumentsObjectUseInSignalHandlers(const QmlIR::Document &doc, QQmlJSCompileError *error)
bool qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName, const QQmlJSSaveFunction &saveFunction, QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, bool storeSourceLocation, QV4::Compiler::CodegenWarningInterface *wInterface, const QString *fileContents)
static void annotateListElements(QmlIR::Document *document)
bool qCompileQmlFile(const QString &inputFileName, const QQmlJSSaveFunction &saveFunction, QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error, bool storeSourceLocation, QV4::Compiler::CodegenWarningInterface *wInterface, const QString *fileContents)
static QString diagnosticErrorMessage(const QString &fileName, const QQmlJS::DiagnosticMessage &m)
bool qSaveQmlJSUnitAsCpp(const QString &inputFileName, const QString &outputFileName, const QV4::CompiledData::SaveableUnitPointer &unit, const QQmlJSAotFunctionMap &aotFunctions, QString *errorString)
bool qCompileJSFile(const QString &inputFileName, const QString &inputFileUrl, const QQmlJSSaveFunction &saveFunction, QQmlJSCompileError *error)
static const int FileScopeCodeIndex
std::function< bool(const QV4::CompiledData::SaveableUnitPointer &, const QQmlJSAotFunctionMap &, QString *)> QQmlJSSaveFunction
QT_BEGIN_NAMESPACE QT_DECLARE_EXPORTED_QT_LOGGING_CATEGORY(lcAotCompiler, Q_QMLCOMPILER_EXPORT)