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 };
66 Q_DECLARE_FLAGS(Flags, Flag)
67
68 QQmlJSAotCompiler(QQmlJSImporter *importer, const QString &resourcePath,
69 const QStringList &qmldirFiles, QQmlJSLogger *logger);
70
71 virtual ~QQmlJSAotCompiler() = default;
72
73 virtual void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document);
74 virtual void setScope(const QmlIR::Object *object, const QmlIR::Object *scope);
75 virtual std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>> compileBinding(
76 const QV4::Compiler::Context *context, const QmlIR::Binding &irBinding,
77 QQmlJS::AST::Node *astNode);
78 virtual std::variant<QQmlJSAotFunction, QList<QQmlJS::DiagnosticMessage>> compileFunction(
79 const QV4::Compiler::Context *context, const QString &name, QQmlJS::AST::Node *astNode);
80
81 virtual QQmlJSAotFunction globalCode() const;
82
83 Flags m_flags;
84
85protected:
86 std::optional<QList<QQmlJS::DiagnosticMessage>> finalizeBindingOrFunction();
87
88 virtual QQmlJS::DiagnosticMessage diagnose(
89 const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location) const;
90
91 QQmlJSTypeResolver m_typeResolver;
92
93 const QString m_resourcePath;
94 const QStringList m_qmldirFiles;
95
96 const QmlIR::Document *m_document = nullptr;
97 const QmlIR::Object *m_currentObject = nullptr;
98 const QmlIR::Object *m_currentScope = nullptr;
99 const QV4::Compiler::JSUnitGenerator *m_unitGenerator = nullptr;
100
101 QQmlJSImporter *m_importer = nullptr;
102 QQmlJSLogger *m_logger = nullptr;
103
104private:
105 QQmlJSAotFunction doCompile(
106 const QV4::Compiler::Context *context, QQmlJSCompilePass::Function *function);
107 QQmlJSAotFunction doCompileAndRecordAotStats(
108 const QV4::Compiler::Context *context, QQmlJSCompilePass::Function *function,
109 const QString &name, QQmlJS::SourceLocation location);
110};
111
112Q_DECLARE_OPERATORS_FOR_FLAGS(QQmlJSAotCompiler::Flags);
113
114using QQmlJSAotFunctionMap = QMap<int, QQmlJSAotFunction>;
116 = std::function<bool(const QV4::CompiledData::SaveableUnitPointer &,
117 const QQmlJSAotFunctionMap &, QString *)>;
118
119bool Q_QMLCOMPILER_EXPORT qCompileQmlFile(const QString &inputFileName,
120 const QQmlJSSaveFunction &saveFunction,
121 QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
122 bool storeSourceLocation = false,
123 QV4::Compiler::CodegenWarningInterface *wInterface =
124 QV4::Compiler::defaultCodegenWarningInterface(),
125 const QString *fileContents = nullptr);
126bool Q_QMLCOMPILER_EXPORT qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName,
127 const QQmlJSSaveFunction &saveFunction,
128 QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
129 bool storeSourceLocation = false,
130 QV4::Compiler::CodegenWarningInterface *wInterface =
131 QV4::Compiler::defaultCodegenWarningInterface(),
132 const QString *fileContents = nullptr);
133bool Q_QMLCOMPILER_EXPORT qCompileJSFile(const QString &inputFileName, const QString &inputFileUrl,
134 const QQmlJSSaveFunction &saveFunction,
135 QQmlJSCompileError *error);
136
137bool Q_QMLCOMPILER_EXPORT qSaveQmlJSUnitAsCpp(const QString &inputFileName,
138 const QString &outputFileName,
139 const QV4::CompiledData::SaveableUnitPointer &unit,
140 const QQmlJSAotFunctionMap &aotFunctions,
141 QString *errorString);
142
143QT_END_NAMESPACE
144
145#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)