1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QQMLJSENGINE_P_H |
5 | #define QQMLJSENGINE_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qqmljsglobal_p.h" |
19 | #include <private/qqmljssourcelocation_p.h> |
20 | |
21 | #include <private/qqmljsmemorypool_p.h> |
22 | |
23 | #include <QtCore/qstring.h> |
24 | #include <QtCore/qset.h> |
25 | |
26 | QT_BEGIN_NAMESPACE |
27 | |
28 | namespace QQmlJS { |
29 | |
30 | class Lexer; |
31 | class MemoryPool; |
32 | |
33 | class QML_PARSER_EXPORT Directives { |
34 | public: |
35 | virtual ~Directives() {} |
36 | |
37 | virtual void pragmaLibrary() |
38 | { |
39 | } |
40 | |
41 | virtual void importFile(const QString &jsfile, const QString &module, int line, int column) |
42 | { |
43 | Q_UNUSED(jsfile); |
44 | Q_UNUSED(module); |
45 | Q_UNUSED(line); |
46 | Q_UNUSED(column); |
47 | } |
48 | |
49 | virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column) |
50 | { |
51 | Q_UNUSED(uri); |
52 | Q_UNUSED(version); |
53 | Q_UNUSED(module); |
54 | Q_UNUSED(line); |
55 | Q_UNUSED(column); |
56 | } |
57 | }; |
58 | |
59 | class Engine |
60 | { |
61 | Lexer *_lexer = nullptr; |
62 | Directives *_directives = nullptr; |
63 | MemoryPool _pool; |
64 | QList<SourceLocation> ; |
65 | QStringList ; |
66 | QString _code; |
67 | |
68 | public: |
69 | void setCode(const QString &code) { _code = code; } |
70 | const QString &code() const { return _code; } |
71 | |
72 | void (int pos, int len, int line, int col) |
73 | { |
74 | Q_ASSERT(len >= 0); |
75 | _comments.append(t: QQmlJS::SourceLocation(pos, len, line, col)); |
76 | } |
77 | |
78 | QList<SourceLocation> () const { return _comments; } |
79 | |
80 | Lexer *lexer() const { return _lexer; } |
81 | void setLexer(Lexer *lexer) { _lexer = lexer; } |
82 | |
83 | Directives *directives() const { return _directives; } |
84 | void setDirectives(Directives *directives) { _directives = directives; } |
85 | |
86 | MemoryPool *pool() { return &_pool; } |
87 | const MemoryPool *pool() const { return &_pool; } |
88 | |
89 | QStringView midRef(int position, int size) |
90 | { |
91 | return QStringView{_code}.mid(pos: position, n: size); |
92 | } |
93 | |
94 | QStringView newStringRef(const QString &text) |
95 | { |
96 | _extraCode.append(t: text); |
97 | return QStringView{_extraCode.last()}; |
98 | } |
99 | |
100 | QStringView newStringRef(const QChar *chars, int size) |
101 | { |
102 | return newStringRef(text: QString(chars, size)); |
103 | } |
104 | }; |
105 | |
106 | } // end of namespace QQmlJS |
107 | |
108 | QT_END_NAMESPACE |
109 | |
110 | #endif // QQMLJSENGINE_P_H |
111 | |