1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#ifndef QQMLJSCOMPILER_P_H
#define QQMLJSCOMPILER_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
#include <private/qtqmlcompilerexports_p.h>
#include <QtCore/qstring.h>
#include <QtCore/qlist.h>
#include <QtCore/qloggingcategory.h>
#include <private/qqmlirbuilder_p.h>
#include <private/qqmljscompilepass_p.h>
#include <private/qqmljsdiagnosticmessage_p.h>
#include <private/qqmljsimporter_p.h>
#include <private/qqmljslogger_p.h>
#include <private/qqmljstyperesolver_p.h>
#include <private/qv4compileddata_p.h>
#include <functional>
QT_BEGIN_NAMESPACE
Q_QMLCOMPILER_PRIVATE_EXPORT Q_DECLARE_LOGGING_CATEGORY(lcAotCompiler);
struct Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSCompileError
{
QString message;
void print();
QQmlJSCompileError augment(const QString &contextErrorMessage) const;
void appendDiagnostics(const QString &inputFileName,
const QList<QQmlJS::DiagnosticMessage> &diagnostics);
void appendDiagnostic(const QString &inputFileName,
const QQmlJS::DiagnosticMessage &diagnostic);
};
struct Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSAotFunction
{
QStringList includes;
QStringList argumentTypes;
QString code;
QString returnType;
};
class Q_QMLCOMPILER_PRIVATE_EXPORT QQmlJSAotCompiler
{
public:
QQmlJSAotCompiler(QQmlJSImporter *importer, const QString &resourcePath,
const QStringList &qmldirFiles, QQmlJSLogger *logger);
virtual ~QQmlJSAotCompiler() = default;
virtual void setDocument(const QmlIR::JSCodeGen *codegen, const QmlIR::Document *document);
virtual void setScope(const QmlIR::Object *object, const QmlIR::Object *scope);
virtual std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> compileBinding(
const QV4::Compiler::Context *context, const QmlIR::Binding &irBinding);
virtual std::variant<QQmlJSAotFunction, QQmlJS::DiagnosticMessage> compileFunction(
const QV4::Compiler::Context *context, const QmlIR::Function &irFunction);
virtual QQmlJSAotFunction globalCode() const;
protected:
virtual QQmlJS::DiagnosticMessage diagnose(
const QString &message, QtMsgType type, const QQmlJS::SourceLocation &location) const;
QQmlJSTypeResolver m_typeResolver;
QStringList m_entireSourceCodeLines;
const QString m_resourcePath;
const QStringList m_qmldirFiles;
const QmlIR::Document *m_document = nullptr;
const QmlIR::Object *m_currentObject = nullptr;
const QmlIR::Object *m_currentScope = nullptr;
const QV4::Compiler::JSUnitGenerator *m_unitGenerator = nullptr;
QQmlJSImporter *m_importer = nullptr;
QQmlJSLogger *m_logger = nullptr;
private:
QQmlJSAotFunction doCompile(
const QV4::Compiler::Context *context, QQmlJSCompilePass::Function *function,
QQmlJS::DiagnosticMessage *error);
};
using QQmlJSAotFunctionMap = QMap<int, QQmlJSAotFunction>;
using QQmlJSSaveFunction
= std::function<bool(const QV4::CompiledData::SaveableUnitPointer &,
const QQmlJSAotFunctionMap &, QString *)>;
bool Q_QMLCOMPILER_PRIVATE_EXPORT qCompileQmlFile(const QString &inputFileName,
QQmlJSSaveFunction saveFunction,
QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
bool storeSourceLocation = false,
QV4::Compiler::CodegenWarningInterface *interface =
QV4::Compiler::defaultCodegenWarningInterface(),
const QString *fileContents = nullptr);
bool Q_QMLCOMPILER_PRIVATE_EXPORT qCompileQmlFile(QmlIR::Document &irDocument, const QString &inputFileName,
QQmlJSSaveFunction saveFunction,
QQmlJSAotCompiler *aotCompiler, QQmlJSCompileError *error,
bool storeSourceLocation = false,
QV4::Compiler::CodegenWarningInterface *interface =
QV4::Compiler::defaultCodegenWarningInterface(),
const QString *fileContents = nullptr);
bool Q_QMLCOMPILER_PRIVATE_EXPORT qCompileJSFile(const QString &inputFileName, const QString &inputFileUrl,
QQmlJSSaveFunction saveFunction,
QQmlJSCompileError *error);
bool Q_QMLCOMPILER_PRIVATE_EXPORT qSaveQmlJSUnitAsCpp(const QString &inputFileName,
const QString &outputFileName,
const QV4::CompiledData::SaveableUnitPointer &unit,
const QQmlJSAotFunctionMap &aotFunctions,
QString *errorString);
QT_END_NAMESPACE
#endif // QQMLJSCOMPILER_P_H
|