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
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// Qt-Security score:significant
4
5#ifndef QQMLJSENGINE_P_H
6#define QQMLJSENGINE_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
19#include "qqmljsglobal_p.h"
20#include <private/qqmljssourcelocation_p.h>
21
22#include <private/qqmljsmemorypool_p.h>
23
24#include <QtCore/qstring.h>
25#include <QtCore/qset.h>
26
28
29namespace QQmlJS {
30
31class Lexer;
32class MemoryPool;
33
35public:
36 virtual ~Directives() {}
37
38 virtual void pragmaLibrary()
39 {
40 }
41
42 virtual void importFile(const QString &jsfile, const QString &module, int line, int column)
43 {
48 }
49
50 virtual void importModule(const QString &uri, const QString &version, const QString &module, int line, int column)
51 {
57 }
58};
59
60class Engine
61{
62 Lexer *_lexer = nullptr;
63 Directives *_directives = nullptr;
64 MemoryPool _pool;
65 QList<SourceLocation> _comments;
66 QStringList _extraCode;
67 QString _code;
68
69public:
70 void setCode(const QString &code) { _code = code; }
71 const QString &code() const { return _code; }
72
73 void addComment(int pos, int len, int line, int col)
74 {
75 Q_ASSERT(len >= 0);
76 _comments.append(QQmlJS::SourceLocation(pos, len, line, col));
77 }
78
79 QList<SourceLocation> comments() const { return _comments; }
80
81 Lexer *lexer() const { return _lexer; }
82 void setLexer(Lexer *lexer) { _lexer = lexer; }
83
84 Directives *directives() const { return _directives; }
85 void setDirectives(Directives *directives) { _directives = directives; }
86
87 MemoryPool *pool() { return &_pool; }
88 const MemoryPool *pool() const { return &_pool; }
89
90 QStringView midRef(int position, int size)
91 {
92 return QStringView{_code}.mid(position, size);
93 }
94
95 QStringView newStringRef(const QString &text)
96 {
97 _extraCode.append(text);
98 return QStringView{_extraCode.last()};
99 }
100
101 QStringView newStringRef(const QChar *chars, int size)
102 {
103 return newStringRef(QString(chars, size));
104 }
105};
106
107} // end of namespace QQmlJS
108
109QT_END_NAMESPACE
110
111#endif // QQMLJSENGINE_P_H
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
#define QML_PARSER_EXPORT
static int regExpFlagFromChar(const QChar &ch)
static bool isIdentifierPart(uint ch)
static QChar convertHex(QChar c1, QChar c2)
static const int uriTokens[]
static bool isUriToken(int token)
static unsigned char convertHex(ushort c)
static bool isIdentifierStart(uint ch)