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
qv4regexp_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#ifndef QV4REGEXP_H
5#define QV4REGEXP_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// Yarr.h is not self-contained. Make sure it sees uint8_t
19#include <cstdint>
20
21#include <yarr/Yarr.h>
22#include <yarr/YarrInterpreter.h>
23#include <yarr/YarrJIT.h>
24
25#include <private/qv4compileddata_p.h>
26#include <private/qv4managed_p.h>
27
28#include <QtCore/qstring.h>
29#include <QtCore/qvector.h>
30
31QT_BEGIN_NAMESPACE
32
33namespace QV4 {
34
35struct ExecutionEngine;
36struct RegExpCacheKey;
37
38namespace Heap {
39
40struct RegExp : Base {
41 void init(ExecutionEngine *engine, const QString& pattern, uint flags);
42 void destroy();
43
46#if ENABLE(YARR_JIT)
48#endif
49 bool hasValidJITCode() const {
50#if ENABLE(YARR_JIT)
51 return jitCode && !jitCode->failureReason().has_value() && jitCode->has16BitCode();
52#else
53 return false;
54#endif
55 }
56
57 bool ignoreCase() const { return flags & CompiledData::RegExp::RegExp_IgnoreCase; }
58 bool multiLine() const { return flags & CompiledData::RegExp::RegExp_Multiline; }
59 bool global() const { return flags & CompiledData::RegExp::RegExp_Global; }
60 bool unicode() const { return flags & CompiledData::RegExp::RegExp_Unicode; }
61 bool sticky() const { return flags & CompiledData::RegExp::RegExp_Sticky; }
62
65
66#if ENABLE(YARR_JIT)
67 bool isJittable() const { return !jitFailed; }
69 bool jitFailed;
70#endif
71
73 bool valid;
74
75 int captureCount() const { return subPatternCount + 1; }
76};
78
79}
80
81struct RegExp : public Managed
82{
83 V4_MANAGED(RegExp, Managed)
87
88 QString pattern() const { return *d()->pattern; }
90#if ENABLE(YARR_JIT)
91 JSC::Yarr::YarrCodeBlock *jitCode() const { return d()->jitCode; }
92#endif
93 RegExpCache *cache() const { return d()->cache; }
94 int subPatternCount() const { return d()->subPatternCount; }
95 bool ignoreCase() const { return d()->ignoreCase(); }
96 bool multiLine() const { return d()->multiLine(); }
97 bool global() const { return d()->global(); }
98 bool unicode() const { return d()->unicode(); }
99 bool sticky() const { return d()->sticky(); }
100
101 static Heap::RegExp *create(
104
105 bool isValid() const { return d()->valid; }
106
107 uint match(const QString& string, int start, uint *matchOffsets);
108
109 int captureCount() const { return subPatternCount() + 1; }
110
111 static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement);
112
113 friend class RegExpCache;
114};
115
117{
118 RegExpCacheKey(const QString &pattern, uint flags)
120 { }
121 explicit inline RegExpCacheKey(const RegExp::Data *re);
122
123 bool operator==(const RegExpCacheKey &other) const
124 { return pattern == other.pattern && flags == other.flags;; }
125 bool operator!=(const RegExpCacheKey &other) const
126 { return !operator==(other); }
127
130};
131
132inline RegExpCacheKey::RegExpCacheKey(const RegExp::Data *re)
133 : pattern(*re->pattern)
134 , flags(re->flags)
135{}
136
137inline size_t qHash(const RegExpCacheKey& key, size_t seed = 0) noexcept
138{ return qHashMulti(seed, key.pattern, key.flags); }
139
141{
142public:
143 ~RegExpCache();
144};
145
146
147
148}
149
150QT_END_NAMESPACE
151
152#endif // QV4REGEXP_H
Q_STATIC_ASSERT(std::is_trivial_v< ArrayData >)
Definition qjsvalue.h:23
size_t qHash(const RegExpCacheKey &key, size_t seed=0) noexcept
DEFINE_MANAGED_VTABLE(RegExp)
static JSC::RegExpFlags jscFlags(quint8 flags)
Definition qv4regexp.cpp:19
bool global() const
Definition qv4regexp_p.h:59
bool sticky() const
Definition qv4regexp_p.h:61
bool ignoreCase() const
Definition qv4regexp_p.h:57
bool multiLine() const
Definition qv4regexp_p.h:58
bool unicode() const
Definition qv4regexp_p.h:60
bool hasValidJITCode() const
Definition qv4regexp_p.h:49
RegExpCache * cache
Definition qv4regexp_p.h:63
void init(ExecutionEngine *engine, const QString &pattern, uint flags)
JSC::Yarr::BytecodePattern * byteCode
Definition qv4regexp_p.h:45
QString * pattern
Definition qv4regexp_p.h:44
int captureCount() const
Definition qv4regexp_p.h:75
RegExpCacheKey(const QString &pattern, uint flags)
bool operator!=(const RegExpCacheKey &other) const
bool operator==(const RegExpCacheKey &other) const
RegExpCacheKey(const RegExp::Data *re)
static QString getSubstitution(const QString &matched, const QString &str, int position, const Value *captures, int nCaptures, const QString &replacement)
bool isValid() const
int captureCount() const
uint match(const QString &string, int start, uint *matchOffsets)
Definition qv4regexp.cpp:45