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 | #ifndef QV4GLOBAL_H |
41 | #define QV4GLOBAL_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtCore/qglobal.h> |
55 | #include <private/qv4compilerglobal_p.h> |
56 | #include <QString> |
57 | |
58 | #ifdef QT_NO_DEBUG |
59 | #define QML_NEARLY_ALWAYS_INLINE Q_ALWAYS_INLINE |
60 | #else |
61 | #define QML_NEARLY_ALWAYS_INLINE inline |
62 | #endif |
63 | |
64 | #include <qtqmlglobal.h> |
65 | #include <private/qtqmlglobal_p.h> |
66 | |
67 | #if defined(Q_CC_MSVC) |
68 | #include <float.h> |
69 | #include <math.h> |
70 | |
71 | namespace std { |
72 | |
73 | inline bool isinf(double d) { return !_finite(d) && !_isnan(d); } |
74 | inline bool isnan(double d) { return !!_isnan(d); } |
75 | inline bool isfinite(double d) { return _finite(d); } |
76 | |
77 | } // namespace std |
78 | |
79 | inline double trunc(double d) { return d > 0 ? floor(d) : ceil(d); } |
80 | #endif |
81 | |
82 | // Do certain things depending on whether the JIT is enabled or disabled |
83 | |
84 | #if QT_CONFIG(qml_jit) |
85 | #define ENABLE_YARR_JIT 1 |
86 | #define ENABLE_JIT 1 |
87 | #define ENABLE_ASSEMBLER 1 |
88 | #else |
89 | #define ENABLE_YARR_JIT 0 |
90 | #define ENABLE_ASSEMBLER 0 |
91 | #define ENABLE_JIT 0 |
92 | #endif |
93 | |
94 | #if defined(Q_OS_QNX) && defined(_CPPLIB_VER) |
95 | #include <math.h> |
96 | #undef isnan |
97 | #undef isfinite |
98 | #undef isinf |
99 | #undef signbit |
100 | #endif |
101 | |
102 | QT_BEGIN_NAMESPACE |
103 | |
104 | namespace QV4 { |
105 | |
106 | namespace Compiler { |
107 | struct Module; |
108 | struct Context; |
109 | struct JSUnitGenerator; |
110 | class Codegen; |
111 | } |
112 | |
113 | namespace Moth { |
114 | class BytecodeGenerator; |
115 | } |
116 | |
117 | namespace Heap { |
118 | struct Base; |
119 | struct MemberData; |
120 | struct ArrayData; |
121 | |
122 | struct StringOrSymbol; |
123 | struct String; |
124 | struct Symbol; |
125 | struct Object; |
126 | struct ObjectPrototype; |
127 | |
128 | struct ExecutionContext; |
129 | struct CallContext; |
130 | struct QmlContext; |
131 | struct ScriptFunction; |
132 | struct InternalClass; |
133 | |
134 | struct BooleanObject; |
135 | struct NumberObject; |
136 | struct StringObject; |
137 | struct ArrayObject; |
138 | struct DateObject; |
139 | struct FunctionObject; |
140 | struct ErrorObject; |
141 | struct ArgumentsObject; |
142 | struct QObjectWrapper; |
143 | struct RegExpObject; |
144 | struct RegExp; |
145 | struct EvalFunction; |
146 | |
147 | struct SharedArrayBuffer; |
148 | struct ArrayBuffer; |
149 | struct DataView; |
150 | struct TypedArray; |
151 | |
152 | struct MapObject; |
153 | struct SetObject; |
154 | |
155 | struct PromiseObject; |
156 | struct PromiseCapability; |
157 | |
158 | template <typename T, size_t> struct Pointer; |
159 | } |
160 | |
161 | struct CppStackFrame; |
162 | class MemoryManager; |
163 | class ExecutableAllocator; |
164 | struct PropertyKey; |
165 | struct StringOrSymbol; |
166 | struct String; |
167 | struct Symbol; |
168 | struct Object; |
169 | struct ObjectPrototype; |
170 | struct ObjectIterator; |
171 | struct ExecutionContext; |
172 | struct CallContext; |
173 | struct QmlContext; |
174 | struct ScriptFunction; |
175 | struct InternalClass; |
176 | struct Property; |
177 | struct Value; |
178 | template<size_t> struct HeapValue; |
179 | template<size_t> struct ValueArray; |
180 | struct Lookup; |
181 | struct ArrayData; |
182 | struct VTable; |
183 | struct Function; |
184 | |
185 | struct BooleanObject; |
186 | struct NumberObject; |
187 | struct StringObject; |
188 | struct ArrayObject; |
189 | struct DateObject; |
190 | struct FunctionObject; |
191 | struct ErrorObject; |
192 | struct ArgumentsObject; |
193 | struct Managed; |
194 | struct ExecutionEngine; |
195 | struct QObjectWrapper; |
196 | struct RegExpObject; |
197 | struct RegExp; |
198 | struct EvalFunction; |
199 | |
200 | struct SharedArrayBuffer; |
201 | struct ArrayBuffer; |
202 | struct DataView; |
203 | struct TypedArray; |
204 | |
205 | struct MapObject; |
206 | struct SetMapObject; |
207 | |
208 | struct PromiseObject; |
209 | struct PromiseCapability; |
210 | |
211 | struct CallData; |
212 | struct Scope; |
213 | struct ScopedValue; |
214 | template<typename T> struct Scoped; |
215 | typedef Scoped<String> ScopedString; |
216 | typedef Scoped<StringOrSymbol> ScopedStringOrSymbol; |
217 | typedef Scoped<Object> ScopedObject; |
218 | typedef Scoped<ArrayObject> ScopedArrayObject; |
219 | typedef Scoped<FunctionObject> ScopedFunctionObject; |
220 | typedef Scoped<ExecutionContext> ScopedContext; |
221 | |
222 | struct PersistentValueStorage; |
223 | class PersistentValue; |
224 | class WeakValue; |
225 | struct MarkStack; |
226 | |
227 | struct IdentifierTable; |
228 | class RegExpCache; |
229 | class MultiplyWrappedQObjectMap; |
230 | |
231 | enum PropertyFlag { |
232 | Attr_Data = 0, |
233 | Attr_Accessor = 0x1, |
234 | Attr_NotWritable = 0x2, |
235 | Attr_NotEnumerable = 0x4, |
236 | Attr_NotConfigurable = 0x8, |
237 | Attr_ReadOnly = Attr_NotWritable|Attr_NotEnumerable|Attr_NotConfigurable, |
238 | Attr_ReadOnly_ButConfigurable = Attr_NotWritable|Attr_NotEnumerable, |
239 | Attr_Invalid = 0xff |
240 | }; |
241 | |
242 | Q_DECLARE_FLAGS(PropertyFlags, PropertyFlag) |
243 | Q_DECLARE_OPERATORS_FOR_FLAGS(PropertyFlags) |
244 | |
245 | struct PropertyAttributes |
246 | { |
247 | union { |
248 | uchar m_all; |
249 | struct { |
250 | uchar m_flags : 4; |
251 | uchar m_mask : 4; |
252 | }; |
253 | struct { |
254 | uchar m_type : 1; |
255 | uchar m_writable : 1; |
256 | uchar m_enumerable : 1; |
257 | uchar m_configurable : 1; |
258 | uchar type_set : 1; |
259 | uchar writable_set : 1; |
260 | uchar enumerable_set : 1; |
261 | uchar configurable_set : 1; |
262 | }; |
263 | }; |
264 | |
265 | enum Type { |
266 | Data = 0, |
267 | Accessor = 1, |
268 | Generic = 2 |
269 | }; |
270 | |
271 | PropertyAttributes() : m_all(0) {} |
272 | PropertyAttributes(PropertyFlag f) : m_all(0) { |
273 | if (f != Attr_Invalid) { |
274 | setType(f & Attr_Accessor ? Accessor : Data); |
275 | if (!(f & Attr_Accessor)) |
276 | setWritable(!(f & Attr_NotWritable)); |
277 | setEnumerable(!(f & Attr_NotEnumerable)); |
278 | setConfigurable(!(f & Attr_NotConfigurable)); |
279 | } |
280 | } |
281 | PropertyAttributes(PropertyFlags f) : m_all(0) { |
282 | if (f != Attr_Invalid) { |
283 | setType(f & Attr_Accessor ? Accessor : Data); |
284 | if (!(f & Attr_Accessor)) |
285 | setWritable(!(f & Attr_NotWritable)); |
286 | setEnumerable(!(f & Attr_NotEnumerable)); |
287 | setConfigurable(!(f & Attr_NotConfigurable)); |
288 | } |
289 | } |
290 | |
291 | void setType(Type t) { m_type = t; type_set = true; } |
292 | Type type() const { return type_set ? (Type)m_type : Generic; } |
293 | |
294 | bool isData() const { return type() == PropertyAttributes::Data || writable_set; } |
295 | bool isAccessor() const { return type() == PropertyAttributes::Accessor; } |
296 | bool isGeneric() const { return type() == PropertyAttributes::Generic && !writable_set; } |
297 | |
298 | bool hasType() const { return type_set; } |
299 | bool hasWritable() const { return writable_set; } |
300 | bool hasConfigurable() const { return configurable_set; } |
301 | bool hasEnumerable() const { return enumerable_set; } |
302 | |
303 | void setWritable(bool b) { m_writable = b; writable_set = true; } |
304 | void setConfigurable(bool b) { m_configurable = b; configurable_set = true; } |
305 | void setEnumerable(bool b) { m_enumerable = b; enumerable_set = true; } |
306 | |
307 | void resolve() { m_mask = 0xf; if (m_type == Accessor) { m_writable = false; writable_set = false; } } |
308 | |
309 | bool isWritable() const { return m_type != Data || m_writable; } |
310 | bool isEnumerable() const { return m_enumerable; } |
311 | bool isConfigurable() const { return m_configurable; } |
312 | |
313 | void clearType() { m_type = Data; type_set = false; } |
314 | void clearWritable() { m_writable = false; writable_set = false; } |
315 | void clearEnumerable() { m_enumerable = false; enumerable_set = false; } |
316 | void clearConfigurable() { m_configurable = false; configurable_set = false; } |
317 | |
318 | void clear() { m_all = 0; } |
319 | bool isEmpty() const { return !m_all; } |
320 | |
321 | uint flags() const { return m_flags; } |
322 | uint all() const { return m_all; } |
323 | |
324 | bool operator==(PropertyAttributes other) { |
325 | return m_all == other.m_all; |
326 | } |
327 | bool operator!=(PropertyAttributes other) { |
328 | return m_all != other.m_all; |
329 | } |
330 | }; |
331 | |
332 | struct Q_QML_EXPORT StackFrame { |
333 | QString source; |
334 | QString function; |
335 | int line = -1; |
336 | int column = -1; |
337 | }; |
338 | typedef QVector<StackFrame> StackTrace; |
339 | |
340 | namespace JIT { |
341 | |
342 | enum class CallResultDestination { |
343 | Ignore, |
344 | InAccumulator, |
345 | }; |
346 | |
347 | } // JIT namespace |
348 | |
349 | } // QV4 namespace |
350 | |
351 | Q_DECLARE_TYPEINFO(QV4::PropertyAttributes, Q_PRIMITIVE_TYPE); |
352 | |
353 | QT_END_NAMESPACE |
354 | |
355 | #endif // QV4GLOBAL_H |
356 | |