1 | /**************************************************************************/ |
2 | /* variant_call.cpp */ |
3 | /**************************************************************************/ |
4 | /* This file is part of: */ |
5 | /* GODOT ENGINE */ |
6 | /* https://godotengine.org */ |
7 | /**************************************************************************/ |
8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
10 | /* */ |
11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
12 | /* a copy of this software and associated documentation files (the */ |
13 | /* "Software"), to deal in the Software without restriction, including */ |
14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
17 | /* the following conditions: */ |
18 | /* */ |
19 | /* The above copyright notice and this permission notice shall be */ |
20 | /* included in all copies or substantial portions of the Software. */ |
21 | /* */ |
22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
29 | /**************************************************************************/ |
30 | |
31 | #include "variant.h" |
32 | |
33 | #include "core/core_string_names.h" |
34 | #include "core/crypto/crypto_core.h" |
35 | #include "core/debugger/engine_debugger.h" |
36 | #include "core/io/compression.h" |
37 | #include "core/io/marshalls.h" |
38 | #include "core/object/class_db.h" |
39 | #include "core/os/os.h" |
40 | #include "core/templates/local_vector.h" |
41 | #include "core/templates/oa_hash_map.h" |
42 | |
43 | typedef void (*VariantFunc)(Variant &r_ret, Variant &p_self, const Variant **p_args); |
44 | typedef void (*VariantConstructFunc)(Variant &r_ret, const Variant **p_args); |
45 | |
46 | template <class R, class... P> |
47 | static _FORCE_INLINE_ void vc_static_method_call(R (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
48 | call_with_variant_args_static_ret_dv(method, p_args, p_argcount, r_ret, r_error, p_defvals); |
49 | } |
50 | |
51 | template <class... P> |
52 | static _FORCE_INLINE_ void vc_static_method_call(void (*method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
53 | call_with_variant_args_static_dv(method, p_args, p_argcount, r_error, p_defvals); |
54 | } |
55 | |
56 | template <class R, class T, class... P> |
57 | static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
58 | call_with_variant_args_ret_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); |
59 | } |
60 | |
61 | template <class R, class T, class... P> |
62 | static _FORCE_INLINE_ void vc_method_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
63 | call_with_variant_args_retc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, r_error, p_defvals); |
64 | } |
65 | |
66 | template <class T, class... P> |
67 | static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
68 | VariantInternal::clear(&r_ret); |
69 | call_with_variant_args_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); |
70 | } |
71 | |
72 | template <class T, class... P> |
73 | static _FORCE_INLINE_ void vc_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
74 | VariantInternal::clear(&r_ret); |
75 | call_with_variant_argsc_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_error, p_defvals); |
76 | } |
77 | |
78 | template <class From, class R, class T, class... P> |
79 | static _FORCE_INLINE_ void vc_convert_method_call(R (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
80 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
81 | call_with_variant_args_ret_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals); |
82 | } |
83 | |
84 | template <class From, class R, class T, class... P> |
85 | static _FORCE_INLINE_ void vc_convert_method_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
86 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
87 | call_with_variant_args_retc_dv(&converted, method, p_args, p_argcount, r_ret, r_error, p_defvals); |
88 | } |
89 | |
90 | template <class From, class T, class... P> |
91 | static _FORCE_INLINE_ void vc_convert_method_call(void (T::*method)(P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
92 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
93 | call_with_variant_args_dv(&converted, method, p_args, p_argcount, r_error, p_defvals); |
94 | } |
95 | |
96 | template <class From, class T, class... P> |
97 | static _FORCE_INLINE_ void vc_convert_method_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
98 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
99 | call_with_variant_argsc_dv(&converted, method, p_args, p_argcount, r_error, p_defvals); |
100 | } |
101 | |
102 | template <class R, class T, class... P> |
103 | static _FORCE_INLINE_ void vc_method_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
104 | call_with_variant_args_retc_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, r_ret, p_defvals, r_error); |
105 | } |
106 | |
107 | template <class T, class... P> |
108 | static _FORCE_INLINE_ void vc_method_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &p_defvals, Callable::CallError &r_error) { |
109 | call_with_variant_args_static_helper_dv(VariantGetInternalPtr<T>::get_ptr(base), method, p_args, p_argcount, p_defvals, r_error); |
110 | } |
111 | |
112 | template <class R, class T, class... P> |
113 | static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
114 | call_with_validated_variant_args_ret(base, method, p_args, r_ret); |
115 | } |
116 | |
117 | template <class R, class T, class... P> |
118 | static _FORCE_INLINE_ void vc_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { |
119 | call_with_validated_variant_args_retc(base, method, p_args, r_ret); |
120 | } |
121 | template <class T, class... P> |
122 | static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
123 | call_with_validated_variant_args(base, method, p_args); |
124 | } |
125 | |
126 | template <class T, class... P> |
127 | static _FORCE_INLINE_ void vc_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { |
128 | call_with_validated_variant_argsc(base, method, p_args); |
129 | } |
130 | |
131 | template <class From, class R, class T, class... P> |
132 | static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
133 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
134 | call_with_validated_variant_args_ret_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); |
135 | } |
136 | |
137 | template <class From, class R, class T, class... P> |
138 | static _FORCE_INLINE_ void vc_convert_validated_call(R (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { |
139 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
140 | call_with_validated_variant_args_retc_helper<T, R, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); |
141 | } |
142 | template <class From, class T, class... P> |
143 | static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
144 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
145 | call_with_validated_variant_args_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); |
146 | } |
147 | |
148 | template <class From, class T, class... P> |
149 | static _FORCE_INLINE_ void vc_convert_validated_call(void (T::*method)(P...) const, Variant *base, const Variant **p_args, Variant *r_ret) { |
150 | T converted(static_cast<T>(*VariantGetInternalPtr<From>::get_ptr(base))); |
151 | call_with_validated_variant_argsc_helper<T, P...>(&converted, method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{}); |
152 | } |
153 | |
154 | template <class R, class T, class... P> |
155 | static _FORCE_INLINE_ void vc_validated_call_static(R (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
156 | call_with_validated_variant_args_static_retc(base, method, p_args, r_ret); |
157 | } |
158 | |
159 | template <class T, class... P> |
160 | static _FORCE_INLINE_ void vc_validated_call_static(void (*method)(T *, P...), Variant *base, const Variant **p_args, Variant *r_ret) { |
161 | call_with_validated_variant_args_static(base, method, p_args); |
162 | } |
163 | |
164 | template <class R, class... P> |
165 | static _FORCE_INLINE_ void vc_validated_static_call(R (*method)(P...), const Variant **p_args, Variant *r_ret) { |
166 | call_with_validated_variant_args_static_method_ret(method, p_args, r_ret); |
167 | } |
168 | |
169 | template <class... P> |
170 | static _FORCE_INLINE_ void vc_validated_static_call(void (*method)(P...), const Variant **p_args, Variant *r_ret) { |
171 | call_with_validated_variant_args_static_method(method, p_args); |
172 | } |
173 | |
174 | template <class R, class T, class... P> |
175 | static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { |
176 | call_with_ptr_args_ret(reinterpret_cast<T *>(p_base), method, p_args, r_ret); |
177 | } |
178 | |
179 | template <class R, class T, class... P> |
180 | static _FORCE_INLINE_ void vc_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { |
181 | call_with_ptr_args_retc(reinterpret_cast<T *>(p_base), method, p_args, r_ret); |
182 | } |
183 | |
184 | template <class T, class... P> |
185 | static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { |
186 | call_with_ptr_args(reinterpret_cast<T *>(p_base), method, p_args); |
187 | } |
188 | |
189 | template <class T, class... P> |
190 | static _FORCE_INLINE_ void vc_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { |
191 | call_with_ptr_argsc(reinterpret_cast<T *>(p_base), method, p_args); |
192 | } |
193 | |
194 | template <class From, class R, class T, class... P> |
195 | static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { |
196 | T converted(*reinterpret_cast<From *>(p_base)); |
197 | call_with_ptr_args_ret(&converted, method, p_args, r_ret); |
198 | } |
199 | |
200 | template <class From, class R, class T, class... P> |
201 | static _FORCE_INLINE_ void vc_convert_ptrcall(R (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { |
202 | T converted(*reinterpret_cast<From *>(p_base)); |
203 | call_with_ptr_args_retc(&converted, method, p_args, r_ret); |
204 | } |
205 | |
206 | template <class From, class T, class... P> |
207 | static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...), void *p_base, const void **p_args, void *r_ret) { |
208 | T converted(*reinterpret_cast<From *>(p_base)); |
209 | call_with_ptr_args(&converted, method, p_args); |
210 | } |
211 | |
212 | template <class From, class T, class... P> |
213 | static _FORCE_INLINE_ void vc_convert_ptrcall(void (T::*method)(P...) const, void *p_base, const void **p_args, void *r_ret) { |
214 | T converted(*reinterpret_cast<From *>(p_base)); |
215 | call_with_ptr_argsc(&converted, method, p_args); |
216 | } |
217 | |
218 | template <class R, class T, class... P> |
219 | static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...)) { |
220 | return sizeof...(P); |
221 | } |
222 | template <class R, class T, class... P> |
223 | static _FORCE_INLINE_ int vc_get_argument_count(R (T::*method)(P...) const) { |
224 | return sizeof...(P); |
225 | } |
226 | |
227 | template <class T, class... P> |
228 | static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...)) { |
229 | return sizeof...(P); |
230 | } |
231 | |
232 | template <class T, class... P> |
233 | static _FORCE_INLINE_ int vc_get_argument_count(void (T::*method)(P...) const) { |
234 | return sizeof...(P); |
235 | } |
236 | |
237 | template <class R, class T, class... P> |
238 | static _FORCE_INLINE_ int vc_get_argument_count(R (*method)(T *, P...)) { |
239 | return sizeof...(P); |
240 | } |
241 | |
242 | template <class R, class... P> |
243 | static _FORCE_INLINE_ int vc_get_argument_count_static(R (*method)(P...)) { |
244 | return sizeof...(P); |
245 | } |
246 | |
247 | template <class R, class T, class... P> |
248 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...), int p_arg) { |
249 | return call_get_argument_type<P...>(p_arg); |
250 | } |
251 | template <class R, class T, class... P> |
252 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (T::*method)(P...) const, int p_arg) { |
253 | return call_get_argument_type<P...>(p_arg); |
254 | } |
255 | |
256 | template <class T, class... P> |
257 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...), int p_arg) { |
258 | return call_get_argument_type<P...>(p_arg); |
259 | } |
260 | |
261 | template <class T, class... P> |
262 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type(void (T::*method)(P...) const, int p_arg) { |
263 | return call_get_argument_type<P...>(p_arg); |
264 | } |
265 | |
266 | template <class R, class T, class... P> |
267 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type(R (*method)(T *, P...), int p_arg) { |
268 | return call_get_argument_type<P...>(p_arg); |
269 | } |
270 | |
271 | template <class R, class... P> |
272 | static _FORCE_INLINE_ Variant::Type vc_get_argument_type_static(R (*method)(P...), int p_arg) { |
273 | return call_get_argument_type<P...>(p_arg); |
274 | } |
275 | |
276 | template <class R, class T, class... P> |
277 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...)) { |
278 | return GetTypeInfo<R>::VARIANT_TYPE; |
279 | } |
280 | |
281 | template <class R, class T, class... P> |
282 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (T::*method)(P...) const) { |
283 | return GetTypeInfo<R>::VARIANT_TYPE; |
284 | } |
285 | |
286 | template <class T, class... P> |
287 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...)) { |
288 | return Variant::NIL; |
289 | } |
290 | |
291 | template <class T, class... P> |
292 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (T::*method)(P...) const) { |
293 | return Variant::NIL; |
294 | } |
295 | |
296 | template <class R, class... P> |
297 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(R (*method)(P...)) { |
298 | return GetTypeInfo<R>::VARIANT_TYPE; |
299 | } |
300 | |
301 | template <class... P> |
302 | static _FORCE_INLINE_ Variant::Type vc_get_return_type(void (*method)(P...)) { |
303 | return Variant::NIL; |
304 | } |
305 | |
306 | template <class R, class T, class... P> |
307 | static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...)) { |
308 | return true; |
309 | } |
310 | template <class R, class T, class... P> |
311 | static _FORCE_INLINE_ bool vc_has_return_type(R (T::*method)(P...) const) { |
312 | return true; |
313 | } |
314 | |
315 | template <class T, class... P> |
316 | static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...)) { |
317 | return false; |
318 | } |
319 | |
320 | template <class T, class... P> |
321 | static _FORCE_INLINE_ bool vc_has_return_type(void (T::*method)(P...) const) { |
322 | return false; |
323 | } |
324 | |
325 | template <class... P> |
326 | static _FORCE_INLINE_ bool vc_has_return_type_static(void (*method)(P...)) { |
327 | return false; |
328 | } |
329 | |
330 | template <class R, class... P> |
331 | static _FORCE_INLINE_ bool vc_has_return_type_static(R (*method)(P...)) { |
332 | return true; |
333 | } |
334 | |
335 | template <class R, class T, class... P> |
336 | static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...)) { |
337 | return false; |
338 | } |
339 | template <class R, class T, class... P> |
340 | static _FORCE_INLINE_ bool vc_is_const(R (T::*method)(P...) const) { |
341 | return true; |
342 | } |
343 | |
344 | template <class T, class... P> |
345 | static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...)) { |
346 | return false; |
347 | } |
348 | |
349 | template <class T, class... P> |
350 | static _FORCE_INLINE_ bool vc_is_const(void (T::*method)(P...) const) { |
351 | return true; |
352 | } |
353 | |
354 | template <class R, class T, class... P> |
355 | static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...)) { |
356 | return GetTypeInfo<T>::VARIANT_TYPE; |
357 | } |
358 | template <class R, class T, class... P> |
359 | static _FORCE_INLINE_ Variant::Type vc_get_base_type(R (T::*method)(P...) const) { |
360 | return GetTypeInfo<T>::VARIANT_TYPE; |
361 | } |
362 | |
363 | template <class T, class... P> |
364 | static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...)) { |
365 | return GetTypeInfo<T>::VARIANT_TYPE; |
366 | } |
367 | |
368 | template <class T, class... P> |
369 | static _FORCE_INLINE_ Variant::Type vc_get_base_type(void (T::*method)(P...) const) { |
370 | return GetTypeInfo<T>::VARIANT_TYPE; |
371 | } |
372 | |
373 | #define METHOD_CLASS(m_class, m_method_name, m_method_ptr) \ |
374 | struct Method_##m_class##_##m_method_name { \ |
375 | static void |
---|