Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqmljsengine_p.h
Go to the documentation of this file.
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
27
28namespace QQmlJS {
29
30class Lexer;
31class MemoryPool;
32
34public:
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);
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);
56 }
57};
58
59class Engine
60{
61 Lexer *_lexer = nullptr;
62 Directives *_directives = nullptr;
63 MemoryPool _pool;
64 QList<SourceLocation> _comments;
65 QStringList _extraCode;
66 QString _code;
67
68public:
69 void setCode(const QString &code) { _code = code; }
70 const QString &code() const { return _code; }
71
72 void addComment(int pos, int len, int line, int col)
73 {
74 Q_ASSERT(len >= 0);
75 _comments.append(QQmlJS::SourceLocation(pos, len, line, col));
76 }
77
78 QList<SourceLocation> comments() const { return _comments; }
79
80 Lexer *lexer() const { return _lexer; }
81 void setLexer(Lexer *lexer) { _lexer = lexer; }
82
83 Directives *directives() const { return _directives; }
85
86 MemoryPool *pool() { return &_pool; }
87 const MemoryPool *pool() const { return &_pool; }
88
90 {
91 return QStringView{_code}.mid(position, size);
92 }
93
95 {
96 _extraCode.append(text);
97 return QStringView{_extraCode.last()};
98 }
99
101 {
102 return newStringRef(QString(chars, size));
103 }
104};
105
106} // end of namespace QQmlJS
107
109
110#endif // QQMLJSENGINE_P_H
\inmodule QtCore
virtual void pragmaLibrary()
virtual void importFile(const QString &jsfile, const QString &module, int line, int column)
virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column)
QStringView newStringRef(const QChar *chars, int size)
const MemoryPool * pool() const
void addComment(int pos, int len, int line, int col)
MemoryPool * pool()
const QString & code() const
QStringView midRef(int position, int size)
QStringView newStringRef(const QString &text)
QList< SourceLocation > comments() const
void setCode(const QString &code)
void setLexer(Lexer *lexer)
void setDirectives(Directives *directives)
Directives * directives() const
Lexer * lexer() const
\inmodule QtCore
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
QString text
Combined button and popup list for selecting options.
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLenum GLsizei void GLsizei void * column
GLenum GLsizei len
#define QML_PARSER_EXPORT
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define Q_UNUSED(x)