Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4regexp.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtQml module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qv4regexp_p.h" | - | ||||||||||||
41 | #include "qv4engine_p.h" | - | ||||||||||||
42 | #include "qv4scopedvalue_p.h" | - | ||||||||||||
43 | #include <private/qv4mm_p.h> | - | ||||||||||||
44 | - | |||||||||||||
45 | using namespace QV4; | - | ||||||||||||
46 | - | |||||||||||||
47 | RegExpCache::~RegExpCache() | - | ||||||||||||
48 | { | - | ||||||||||||
49 | for (RegExpCache::Iterator it = begin(), e = end(); it != e; ++it) {
| 0-99193 | ||||||||||||
50 | if (RegExp *re = it.value().as<RegExp>())
| 0 | ||||||||||||
51 | re->d()->cache = nullptr; never executed: re->d()->cache = nullptr; | 0 | ||||||||||||
52 | } never executed: end of block | 0 | ||||||||||||
53 | } executed 99193 times by 153 tests: end of block Executed by:
| 99193 | ||||||||||||
54 | - | |||||||||||||
55 | DEFINE_MANAGED_VTABLE(RegExp); | - | ||||||||||||
56 | - | |||||||||||||
57 | uint RegExp::match(const QString &string, int start, uint *matchOffsets) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | if (!isValid())
| 0-11437 | ||||||||||||
60 | return JSC::Yarr::offsetNoMatch; never executed: return JSC::Yarr::offsetNoMatch; | 0 | ||||||||||||
61 | - | |||||||||||||
62 | WTF::String s(string); | - | ||||||||||||
63 | - | |||||||||||||
64 | #if ENABLE(YARR_JIT) | - | ||||||||||||
65 | if (d()->hasValidJITCode())
| 216-11231 | ||||||||||||
66 | return uint(jitCode()->execute(s.characters16(), start, s.length(), (int*)matchOffsets).start); executed 11227 times by 3 tests: return uint(jitCode()->execute(s.characters16(), start, s.length(), (int*)matchOffsets).start); Executed by:
| 11227 | ||||||||||||
67 | #endif | - | ||||||||||||
68 | - | |||||||||||||
69 | return JSC::Yarr::interpret(byteCode(), s.characters16(), string.length(), start, matchOffsets); executed 215 times by 1 test: return JSC::Yarr::interpret(byteCode(), s.characters16(), string.length(), start, matchOffsets); Executed by:
| 215 | ||||||||||||
70 | } | - | ||||||||||||
71 | - | |||||||||||||
72 | Heap::RegExp *RegExp::create(ExecutionEngine* engine, const QString& pattern, bool ignoreCase, bool multiline, bool global) | - | ||||||||||||
73 | { | - | ||||||||||||
74 | RegExpCacheKey key(pattern, ignoreCase, multiline, global); | - | ||||||||||||
75 | - | |||||||||||||
76 | RegExpCache *cache = engine->regExpCache; | - | ||||||||||||
77 | if (!cache)
| 98566-1054009 | ||||||||||||
78 | cache = engine->regExpCache = new RegExpCache; executed 98567 times by 153 tests: cache = engine->regExpCache = new RegExpCache; Executed by:
| 98567 | ||||||||||||
79 | - | |||||||||||||
80 | QV4::WeakValue &cachedValue = (*cache)[key]; | - | ||||||||||||
81 | if (QV4::RegExp *result = cachedValue.as<RegExp>())
| 3060-1149478 | ||||||||||||
82 | return result->d(); executed 3060 times by 5 tests: return result->d(); Executed by:
| 3060 | ||||||||||||
83 | - | |||||||||||||
84 | Scope scope(engine); | - | ||||||||||||
85 | Scoped<RegExp> result(scope, engine->memoryManager->alloc<RegExp>(engine, pattern, ignoreCase, multiline, global)); | - | ||||||||||||
86 | - | |||||||||||||
87 | result->d()->cache = cache; | - | ||||||||||||
88 | cachedValue.set(engine, result); | - | ||||||||||||
89 | - | |||||||||||||
90 | return result->d(); executed 1151821 times by 153 tests: return result->d(); Executed by:
| 1151821 | ||||||||||||
91 | } | - | ||||||||||||
92 | - | |||||||||||||
93 | void Heap::RegExp::init(ExecutionEngine *engine, const QString &pattern, bool ignoreCase, bool multiline, bool global) | - | ||||||||||||
94 | { | - | ||||||||||||
95 | Base::init(); | - | ||||||||||||
96 | this->pattern = new QString(pattern); | - | ||||||||||||
97 | this->ignoreCase = ignoreCase; | - | ||||||||||||
98 | this->multiLine = multiline; | - | ||||||||||||
99 | this->global = global; | - | ||||||||||||
100 | - | |||||||||||||
101 | valid = false; | - | ||||||||||||
102 | - | |||||||||||||
103 | const char* error = nullptr; | - | ||||||||||||
104 | JSC::Yarr::YarrPattern yarrPattern(WTF::String(pattern), ignoreCase, multiLine, &error); | - | ||||||||||||
105 | if (error)
| 252-1150190 | ||||||||||||
106 | return; executed 252 times by 1 test: return; Executed by:
| 252 | ||||||||||||
107 | subPatternCount = yarrPattern.m_numSubpatterns; | - | ||||||||||||
108 | #if ENABLE(YARR_JIT) | - | ||||||||||||
109 | if (!yarrPattern.m_containsBackreferences && engine->canJIT()) {
| 0-1149679 | ||||||||||||
110 | jitCode = new JSC::Yarr::YarrCodeBlock; | - | ||||||||||||
111 | JSC::JSGlobalData dummy(internalClass->engine->regExpAllocator); | - | ||||||||||||
112 | JSC::Yarr::jitCompile(yarrPattern, JSC::Yarr::Char16, &dummy, *jitCode); | - | ||||||||||||
113 | } executed 1151507 times by 153 tests: end of block Executed by:
| 1151507 | ||||||||||||
114 | #else | - | ||||||||||||
115 | Q_UNUSED(engine) | - | ||||||||||||
116 | #endif | - | ||||||||||||
117 | if (hasValidJITCode()) {
| 208-1151403 | ||||||||||||
118 | valid = true; | - | ||||||||||||
119 | return; executed 1151399 times by 153 tests: return; Executed by:
| 1151399 | ||||||||||||
120 | } | - | ||||||||||||
121 | OwnPtr<JSC::Yarr::BytecodePattern> p = JSC::Yarr::byteCompile(yarrPattern, internalClass->engine->bumperPointerAllocator); | - | ||||||||||||
122 | byteCode = p.take(); | - | ||||||||||||
123 | if (byteCode)
| 0-208 | ||||||||||||
124 | valid = true; executed 208 times by 1 test: valid = true; Executed by:
| 208 | ||||||||||||
125 | } executed 208 times by 1 test: end of block Executed by:
| 208 | ||||||||||||
126 | - | |||||||||||||
127 | void Heap::RegExp::destroy() | - | ||||||||||||
128 | { | - | ||||||||||||
129 | if (cache) {
| 0-1150980 | ||||||||||||
130 | RegExpCacheKey key(this); | - | ||||||||||||
131 | cache->remove(key); | - | ||||||||||||
132 | } executed 1151789 times by 153 tests: end of block Executed by:
| 1151789 | ||||||||||||
133 | #if ENABLE(YARR_JIT) | - | ||||||||||||
134 | delete jitCode; | - | ||||||||||||
135 | #endif | - | ||||||||||||
136 | delete byteCode; | - | ||||||||||||
137 | delete pattern; | - | ||||||||||||
138 | Base::destroy(); | - | ||||||||||||
139 | } executed 1151797 times by 153 tests: end of block Executed by:
| 1151797 | ||||||||||||
Source code | Switch to Preprocessed file |