OpenCoverage

qv4util_p.h

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/qml/jsruntime/qv4util_p.h
Source codeSwitch to Preprocessed file
LineSourceCount
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#ifndef QV4UTIL_H-
40#define QV4UTIL_H-
41-
42//-
43// W A R N I N G-
44// --------------
45//-
46// This file is not part of the Qt API. It exists purely as an-
47// implementation detail. This header file may change from version to-
48// version without notice, or even be removed.-
49//-
50// We mean it.-
51//-
52-
53#include "qv4global_p.h"-
54#include <QtCore/QBitArray>-
55#include <algorithm>-
56#include <vector>-
57-
58QT_BEGIN_NAMESPACE-
59-
60namespace QV4 {-
61-
62template <typename T>-
63struct TemporaryAssignment-
64{-
65 TemporaryAssignment(T &var, const T& temporaryValue)-
66 : variable(var)-
67 , savedValue(var)-
68 {-
69 variable = temporaryValue;-
70 }
executed 119771 times by 14 tests: end of block
Executed by:
  • tst_ecmascripttests
  • tst_examples
  • tst_qjsengine
  • tst_qjsonbinding
  • tst_qjsvalue
  • tst_qjsvalueiterator
  • tst_qmlcachegen
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmllistmodelworkerscript
  • tst_qqmlxmlhttprequest
  • tst_qquickworkerscript
  • tst_qv4assembler
  • tst_qv4debugger
119771
71 ~TemporaryAssignment()-
72 {-
73 variable = savedValue;-
74 }
executed 119680 times by 14 tests: end of block
Executed by:
  • tst_ecmascripttests
  • tst_examples
  • tst_qjsengine
  • tst_qjsonbinding
  • tst_qjsvalue
  • tst_qjsvalueiterator
  • tst_qmlcachegen
  • tst_qqmldebugjs
  • tst_qqmlecmascript
  • tst_qqmllistmodelworkerscript
  • tst_qqmlxmlhttprequest
  • tst_qquickworkerscript
  • tst_qv4assembler
  • tst_qv4debugger
119680
75 T &variable;-
76 T savedValue;-
77private:-
78 TemporaryAssignment(const TemporaryAssignment<T>&);-
79 TemporaryAssignment operator=(const TemporaryAssignment<T>&);-
80};-
81-
82#if !defined(BROKEN_STD_VECTOR_BOOL_OR_BROKEN_STD_FIND)-
83// Sanity:-
84class BitVector-
85{-
86 std::vector<bool> bits;-
87-
88public:-
89 BitVector(int size = 0, bool value = false)-
90 : bits(size, value)-
91 {}
executed 260 times by 24 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
260
92-
93 void clear()-
94 { bits = std::vector<bool>(bits.size(), false); }
never executed: end of block
0
95-
96 void reserve(int size)-
97 { bits.reserve(size); }
never executed: end of block
0
98-
99 int size() const-
100 {-
101 Q_ASSERT(bits.size() < INT_MAX);-
102 return static_cast<int>(bits.size());
executed 163328 times by 24 tests: return static_cast<int>(bits.size());
Executed by:
  • tst_examples
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
163328
103 }-
104-
105 void resize(int newSize)-
106 { bits.resize(newSize); }
never executed: end of block
0
107-
108 void resize(int newSize, bool newValue)-
109 { bits.resize(newSize, newValue); }
executed 470 times by 24 tests: end of block
Executed by:
  • tst_examples
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
470
110-
111 void assign(int newSize, bool value)-
112 { bits.assign(newSize, value); }
never executed: end of block
0
113-
114 int findNext(int start, bool value, bool wrapAround) const-
115 {-
116 // The ++operator of std::vector<bool>::iterator in libc++ has a bug when using it on an-
117 // iterator pointing to the last element. It will not be set to ::end(), but beyond-
118 // that. (It will be set to the first multiple of the native word size that is bigger-
119 // than size().)-
120 //-
121 // See http://llvm.org/bugs/show_bug.cgi?id=19663-
122 //-
123 // The work-around is to calculate the distance, and compare it to the size() to see if it's-
124 // beyond the end, or take the minimum of the distance and the size.-
125-
126 size_t pos = std::distance(bits.begin(),-
127 std::find(bits.begin() + start, bits.end(), value));-
128 if (wrapAround && pos >= static_cast<size_t>(size()))
wrapAroundDescription
TRUEnever evaluated
FALSEevaluated 54286 times by 23 tests
Evaluated by:
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
pos >= static_...ize_t>(size())Description
TRUEnever evaluated
FALSEnever evaluated
0-54286
129 pos = std::distance(bits.begin(),
never executed: pos = std::distance(bits.begin(), std::find(bits.begin(), bits.begin() + start, value));
0
130 std::find(bits.begin(), bits.begin() + start, value));
never executed: pos = std::distance(bits.begin(), std::find(bits.begin(), bits.begin() + start, value));
0
131-
132 pos = qMin(pos, static_cast<size_t>(size()));-
133-
134 Q_ASSERT(pos <= static_cast<size_t>(size()));-
135 Q_ASSERT(pos < INT_MAX);-
136-
137 return static_cast<int>(pos);
executed 54286 times by 23 tests: return static_cast<int>(pos);
Executed by:
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
54286
138 }-
139-
140 bool at(int idx) const-
141 { return bits.at(idx); }
never executed: return bits.at(idx);
0
142-
143 void setBit(int idx)-
144 { bits[idx] = true; }
executed 14020 times by 23 tests: end of block
Executed by:
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
14020
145-
146 void clearBit(int idx)-
147 { bits[idx] = false; }
executed 54286 times by 23 tests: end of block
Executed by:
  • tst_qquickage
  • tst_qquickangleddirection
  • tst_qquickcumulativedirection
  • tst_qquickcustomaffector
  • tst_qquickcustomparticle
  • tst_qquickellipseextruder
  • tst_qquickfriction
  • tst_qquickgravity
  • tst_qquickgroupgoal
  • tst_qquickimageparticle
  • tst_qquickitemparticle
  • tst_qquicklineextruder
  • tst_qquickmaskextruder
  • tst_qquickparticlegroup
  • tst_qquickparticlesystem
  • tst_qquickpointattractor
  • tst_qquickpointdirection
  • tst_qquickrectangleextruder
  • tst_qquickspritegoal
  • tst_qquicktargetdirection
  • tst_qquicktrailemitter
  • tst_qquickturbulence
  • tst_qquickwander
54286
148};-
149#else // Insanity:-
150class BitVector-
151{-
152 QBitArray bits;-
153-
154public:-
155 BitVector(int size = 0, bool value = false)-
156 : bits(size, value)-
157 {}-
158-
159 void clear()-
160 { bits = QBitArray(bits.size(), false); }-
161-
162 void reserve(int size)-
163 { Q_UNUSED(size); }-
164-
165 int size() const-
166 { return bits.size(); }-
167-
168 void resize(int newSize)-
169 { bits.resize(newSize); }-
170-
171 void resize(int newSize, bool newValue)-
172 {-
173 int oldSize = bits.size();-
174 bits.resize(newSize);-
175 bits.fill(newValue, oldSize, bits.size());-
176 }-
177-
178 void assign(int newSize, bool value)-
179 {-
180 bits.resize(newSize);-
181 bits.fill(value);-
182 }-
183-
184 int findNext(int start, bool value, bool wrapAround) const-
185 {-
186 for (int i = start, ei = size(); i < ei; ++i) {-
187 if (at(i) == value)-
188 return i;-
189 }-
190-
191 if (wrapAround) {-
192 for (int i = 0, ei = start; i < ei; ++i) {-
193 if (at(i) == value)-
194 return i;-
195 }-
196 }-
197-
198 return size();-
199 }-
200-
201 bool at(int idx) const-
202 { return bits.at(idx); }-
203-
204 void setBit(int idx)-
205 { bits[idx] = true; }-
206-
207 void clearBit(int idx)-
208 { bits[idx] = false; }-
209};-
210#endif-
211-
212}-
213-
214QT_END_NAMESPACE-
215-
216#endif // QV4UTIL_H-
Source codeSwitch to Preprocessed file

Generated by Squish Coco 4.2.0