binder_common.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. /*************************************************************************/
  2. /* binder_common.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef BINDER_COMMON_H
  31. #define BINDER_COMMON_H
  32. #include "core/input/input_enums.h"
  33. #include "core/object/object.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/templates/list.h"
  36. #include "core/templates/simple_type.h"
  37. #include "core/typedefs.h"
  38. #include "core/variant/method_ptrcall.h"
  39. #include "core/variant/type_info.h"
  40. #include "core/variant/variant.h"
  41. #include "core/variant/variant_internal.h"
  42. #include <stdio.h>
  43. // Variant cannot define an implicit cast operator for every Object subclass, so the
  44. // casting is done here, to allow binding methods with parameters more specific than Object *
  45. template <class T>
  46. struct VariantCaster {
  47. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  48. using TStripped = std::remove_pointer_t<T>;
  49. if constexpr (std::is_base_of<Object, TStripped>::value) {
  50. return Object::cast_to<TStripped>(p_variant);
  51. } else {
  52. return p_variant;
  53. }
  54. }
  55. };
  56. template <class T>
  57. struct VariantCaster<T &> {
  58. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  59. using TStripped = std::remove_pointer_t<T>;
  60. if constexpr (std::is_base_of<Object, TStripped>::value) {
  61. return Object::cast_to<TStripped>(p_variant);
  62. } else {
  63. return p_variant;
  64. }
  65. }
  66. };
  67. template <class T>
  68. struct VariantCaster<const T &> {
  69. static _FORCE_INLINE_ T cast(const Variant &p_variant) {
  70. using TStripped = std::remove_pointer_t<T>;
  71. if constexpr (std::is_base_of<Object, TStripped>::value) {
  72. return Object::cast_to<TStripped>(p_variant);
  73. } else {
  74. return p_variant;
  75. }
  76. }
  77. };
  78. #define VARIANT_ENUM_CAST(m_enum) \
  79. MAKE_ENUM_TYPE_INFO(m_enum) \
  80. template <> \
  81. struct VariantCaster<m_enum> { \
  82. static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
  83. return (m_enum)p_variant.operator int64_t(); \
  84. } \
  85. }; \
  86. template <> \
  87. struct PtrToArg<m_enum> { \
  88. _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \
  89. return m_enum(*reinterpret_cast<const int64_t *>(p_ptr)); \
  90. } \
  91. typedef int64_t EncodeT; \
  92. _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \
  93. *(int64_t *)p_ptr = (int64_t)p_val; \
  94. } \
  95. }; \
  96. template <> \
  97. struct ZeroInitializer<m_enum> { \
  98. static void initialize(m_enum &value) { value = (m_enum)0; } \
  99. };
  100. #define VARIANT_BITFIELD_CAST(m_enum) \
  101. MAKE_BITFIELD_TYPE_INFO(m_enum) \
  102. template <> \
  103. struct VariantCaster<BitField<m_enum>> { \
  104. static _FORCE_INLINE_ BitField<m_enum> cast(const Variant &p_variant) { \
  105. return BitField<m_enum>(p_variant.operator int64_t()); \
  106. } \
  107. }; \
  108. template <> \
  109. struct PtrToArg<BitField<m_enum>> { \
  110. _FORCE_INLINE_ static BitField<m_enum> convert(const void *p_ptr) { \
  111. return BitField<m_enum>(*reinterpret_cast<const int64_t *>(p_ptr)); \
  112. } \
  113. typedef int64_t EncodeT; \
  114. _FORCE_INLINE_ static void encode(BitField<m_enum> p_val, const void *p_ptr) { \
  115. *(int64_t *)p_ptr = p_val; \
  116. } \
  117. }; \
  118. template <> \
  119. struct ZeroInitializer<BitField<m_enum>> { \
  120. static void initialize(BitField<m_enum> &value) { value = 0; } \
  121. };
  122. // Object enum casts must go here
  123. VARIANT_ENUM_CAST(Object::ConnectFlags);
  124. VARIANT_ENUM_CAST(Vector2::Axis);
  125. VARIANT_ENUM_CAST(Vector2i::Axis);
  126. VARIANT_ENUM_CAST(Vector3::Axis);
  127. VARIANT_ENUM_CAST(Vector3i::Axis);
  128. VARIANT_ENUM_CAST(Vector4::Axis);
  129. VARIANT_ENUM_CAST(Vector4i::Axis);
  130. VARIANT_ENUM_CAST(Basis::EulerOrder);
  131. VARIANT_ENUM_CAST(Projection::Planes);
  132. VARIANT_ENUM_CAST(Error);
  133. VARIANT_ENUM_CAST(Side);
  134. VARIANT_ENUM_CAST(ClockDirection);
  135. VARIANT_ENUM_CAST(Corner);
  136. VARIANT_ENUM_CAST(HatDir);
  137. VARIANT_ENUM_CAST(HatMask);
  138. VARIANT_ENUM_CAST(JoyAxis);
  139. VARIANT_ENUM_CAST(JoyButton);
  140. VARIANT_ENUM_CAST(Key);
  141. VARIANT_ENUM_CAST(KeyModifierMask);
  142. VARIANT_ENUM_CAST(MIDIMessage);
  143. VARIANT_ENUM_CAST(MouseButton);
  144. VARIANT_ENUM_CAST(Orientation);
  145. VARIANT_ENUM_CAST(HorizontalAlignment);
  146. VARIANT_ENUM_CAST(VerticalAlignment);
  147. VARIANT_ENUM_CAST(InlineAlignment);
  148. VARIANT_ENUM_CAST(PropertyHint);
  149. VARIANT_ENUM_CAST(PropertyUsageFlags);
  150. VARIANT_ENUM_CAST(Variant::Type);
  151. VARIANT_ENUM_CAST(Variant::Operator);
  152. template <>
  153. struct VariantCaster<char32_t> {
  154. static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) {
  155. return (char32_t)p_variant.operator int();
  156. }
  157. };
  158. template <>
  159. struct PtrToArg<char32_t> {
  160. _FORCE_INLINE_ static char32_t convert(const void *p_ptr) {
  161. return char32_t(*reinterpret_cast<const int *>(p_ptr));
  162. }
  163. typedef int64_t EncodeT;
  164. _FORCE_INLINE_ static void encode(char32_t p_val, const void *p_ptr) {
  165. *(int *)p_ptr = p_val;
  166. }
  167. };
  168. template <typename T>
  169. struct VariantObjectClassChecker {
  170. static _FORCE_INLINE_ bool check(const Variant &p_variant) {
  171. using TStripped = std::remove_pointer_t<T>;
  172. if constexpr (std::is_base_of<Object, TStripped>::value) {
  173. Object *obj = p_variant;
  174. return Object::cast_to<TStripped>(p_variant) || !obj;
  175. } else {
  176. return true;
  177. }
  178. }
  179. };
  180. template <typename T>
  181. class Ref;
  182. template <typename T>
  183. struct VariantObjectClassChecker<const Ref<T> &> {
  184. static _FORCE_INLINE_ bool check(const Variant &p_variant) {
  185. Object *obj = p_variant;
  186. const Ref<T> node = p_variant;
  187. return node.ptr() || !obj;
  188. }
  189. };
  190. #ifdef DEBUG_METHODS_ENABLED
  191. template <class T>
  192. struct VariantCasterAndValidate {
  193. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  194. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  195. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  196. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  197. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  198. r_error.argument = p_arg_idx;
  199. r_error.expected = argtype;
  200. }
  201. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  202. }
  203. };
  204. template <class T>
  205. struct VariantCasterAndValidate<T &> {
  206. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  207. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  208. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  209. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  210. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  211. r_error.argument = p_arg_idx;
  212. r_error.expected = argtype;
  213. }
  214. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  215. }
  216. };
  217. template <class T>
  218. struct VariantCasterAndValidate<const T &> {
  219. static _FORCE_INLINE_ T cast(const Variant **p_args, uint32_t p_arg_idx, Callable::CallError &r_error) {
  220. Variant::Type argtype = GetTypeInfo<T>::VARIANT_TYPE;
  221. if (!Variant::can_convert_strict(p_args[p_arg_idx]->get_type(), argtype) ||
  222. !VariantObjectClassChecker<T>::check(*p_args[p_arg_idx])) {
  223. r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  224. r_error.argument = p_arg_idx;
  225. r_error.expected = argtype;
  226. }
  227. return VariantCaster<T>::cast(*p_args[p_arg_idx]);
  228. }
  229. };
  230. #endif // DEBUG_METHODS_ENABLED
  231. template <class T, class... P, size_t... Is>
  232. void call_with_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  233. r_error.error = Callable::CallError::CALL_OK;
  234. #ifdef DEBUG_METHODS_ENABLED
  235. (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  236. #else
  237. (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  238. #endif
  239. (void)(p_args); //avoid warning
  240. }
  241. template <class T, class... P, size_t... Is>
  242. void call_with_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  243. r_error.error = Callable::CallError::CALL_OK;
  244. #ifdef DEBUG_METHODS_ENABLED
  245. (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  246. #else
  247. (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  248. #endif
  249. (void)(p_args); //avoid warning
  250. }
  251. template <class T, class... P, size_t... Is>
  252. void call_with_ptr_args_helper(T *p_instance, void (T::*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
  253. (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
  254. }
  255. template <class T, class... P, size_t... Is>
  256. void call_with_ptr_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const void **p_args, IndexSequence<Is...>) {
  257. (p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...);
  258. }
  259. template <class T, class R, class... P, size_t... Is>
  260. void call_with_ptr_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  261. PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  262. }
  263. template <class T, class R, class... P, size_t... Is>
  264. void call_with_ptr_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret, IndexSequence<Is...>) {
  265. PtrToArg<R>::encode((p_instance->*p_method)(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  266. }
  267. template <class T, class... P, size_t... Is>
  268. void call_with_ptr_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const void **p_args, IndexSequence<Is...>) {
  269. p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...);
  270. }
  271. template <class T, class R, class... P, size_t... Is>
  272. void call_with_ptr_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  273. PtrToArg<R>::encode(p_method(p_instance, PtrToArg<P>::convert(p_args[Is])...), r_ret);
  274. }
  275. template <class R, class... P, size_t... Is>
  276. void call_with_ptr_args_static_method_ret_helper(R (*p_method)(P...), const void **p_args, void *r_ret, IndexSequence<Is...>) {
  277. PtrToArg<R>::encode(p_method(PtrToArg<P>::convert(p_args[Is])...), r_ret);
  278. }
  279. template <class... P, size_t... Is>
  280. void call_with_ptr_args_static_method_helper(void (*p_method)(P...), const void **p_args, IndexSequence<Is...>) {
  281. p_method(PtrToArg<P>::convert(p_args[Is])...);
  282. }
  283. template <class T, class... P, size_t... Is>
  284. void call_with_validated_variant_args_helper(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
  285. (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
  286. }
  287. template <class T, class... P, size_t... Is>
  288. void call_with_validated_variant_argsc_helper(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, IndexSequence<Is...>) {
  289. (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
  290. }
  291. template <class T, class R, class... P, size_t... Is>
  292. void call_with_validated_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  293. VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
  294. }
  295. template <class T, class R, class... P, size_t... Is>
  296. void call_with_validated_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  297. VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, (p_instance->*p_method)((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
  298. }
  299. template <class T, class R, class... P, size_t... Is>
  300. void call_with_validated_variant_args_static_retc_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  301. VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
  302. }
  303. template <class T, class... P, size_t... Is>
  304. void call_with_validated_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, IndexSequence<Is...>) {
  305. p_method(p_instance, (VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
  306. }
  307. template <class R, class... P, size_t... Is>
  308. void call_with_validated_variant_args_static_method_ret_helper(R (*p_method)(P...), const Variant **p_args, Variant *r_ret, IndexSequence<Is...>) {
  309. VariantInternalAccessor<typename GetSimpleTypeT<R>::type_t>::set(r_ret, p_method((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...));
  310. }
  311. template <class... P, size_t... Is>
  312. void call_with_validated_variant_args_static_method_helper(void (*p_method)(P...), const Variant **p_args, IndexSequence<Is...>) {
  313. p_method((VariantInternalAccessor<typename GetSimpleTypeT<P>::type_t>::get(p_args[Is]))...);
  314. }
  315. template <class T, class... P>
  316. void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
  317. #ifdef DEBUG_METHODS_ENABLED
  318. if ((size_t)p_argcount > sizeof...(P)) {
  319. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  320. r_error.argument = sizeof...(P);
  321. return;
  322. }
  323. if ((size_t)p_argcount < sizeof...(P)) {
  324. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  325. r_error.argument = sizeof...(P);
  326. return;
  327. }
  328. #endif
  329. call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  330. }
  331. template <class T, class... P>
  332. void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  333. #ifdef DEBUG_ENABLED
  334. if ((size_t)p_argcount > sizeof...(P)) {
  335. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  336. r_error.argument = sizeof...(P);
  337. return;
  338. }
  339. #endif
  340. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  341. int32_t dvs = default_values.size();
  342. #ifdef DEBUG_ENABLED
  343. if (missing > dvs) {
  344. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  345. r_error.argument = sizeof...(P);
  346. return;
  347. }
  348. #endif
  349. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  350. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  351. if (i < p_argcount) {
  352. args[i] = p_args[i];
  353. } else {
  354. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  355. }
  356. }
  357. call_with_variant_args_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  358. }
  359. template <class T, class... P>
  360. void call_with_variant_argsc(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
  361. #ifdef DEBUG_METHODS_ENABLED
  362. if ((size_t)p_argcount > sizeof...(P)) {
  363. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  364. r_error.argument = sizeof...(P);
  365. return;
  366. }
  367. if ((size_t)p_argcount < sizeof...(P)) {
  368. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  369. r_error.argument = sizeof...(P);
  370. return;
  371. }
  372. #endif
  373. call_with_variant_args_helper<T, P...>(p_instance, p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  374. }
  375. template <class T, class... P>
  376. void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  377. #ifdef DEBUG_ENABLED
  378. if ((size_t)p_argcount > sizeof...(P)) {
  379. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  380. r_error.argument = sizeof...(P);
  381. return;
  382. }
  383. #endif
  384. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  385. int32_t dvs = default_values.size();
  386. #ifdef DEBUG_ENABLED
  387. if (missing > dvs) {
  388. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  389. r_error.argument = sizeof...(P);
  390. return;
  391. }
  392. #endif
  393. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  394. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  395. if (i < p_argcount) {
  396. args[i] = p_args[i];
  397. } else {
  398. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  399. }
  400. }
  401. call_with_variant_argsc_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  402. }
  403. template <class T, class R, class... P>
  404. void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  405. #ifdef DEBUG_ENABLED
  406. if ((size_t)p_argcount > sizeof...(P)) {
  407. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  408. r_error.argument = sizeof...(P);
  409. return;
  410. }
  411. #endif
  412. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  413. int32_t dvs = default_values.size();
  414. #ifdef DEBUG_ENABLED
  415. if (missing > dvs) {
  416. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  417. r_error.argument = sizeof...(P);
  418. return;
  419. }
  420. #endif
  421. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  422. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  423. if (i < p_argcount) {
  424. args[i] = p_args[i];
  425. } else {
  426. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  427. }
  428. }
  429. call_with_variant_args_ret_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  430. }
  431. template <class T, class R, class... P>
  432. void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  433. #ifdef DEBUG_ENABLED
  434. if ((size_t)p_argcount > sizeof...(P)) {
  435. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  436. r_error.argument = sizeof...(P);
  437. return;
  438. }
  439. #endif
  440. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  441. int32_t dvs = default_values.size();
  442. #ifdef DEBUG_ENABLED
  443. if (missing > dvs) {
  444. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  445. r_error.argument = sizeof...(P);
  446. return;
  447. }
  448. #endif
  449. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  450. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  451. if (i < p_argcount) {
  452. args[i] = p_args[i];
  453. } else {
  454. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  455. }
  456. }
  457. call_with_variant_args_retc_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  458. }
  459. template <class T, class... P>
  460. void call_with_ptr_args(T *p_instance, void (T::*p_method)(P...), const void **p_args) {
  461. call_with_ptr_args_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  462. }
  463. template <class T, class... P>
  464. void call_with_ptr_argsc(T *p_instance, void (T::*p_method)(P...) const, const void **p_args) {
  465. call_with_ptr_argsc_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  466. }
  467. template <class T, class R, class... P>
  468. void call_with_ptr_args_ret(T *p_instance, R (T::*p_method)(P...), const void **p_args, void *r_ret) {
  469. call_with_ptr_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  470. }
  471. template <class T, class R, class... P>
  472. void call_with_ptr_args_retc(T *p_instance, R (T::*p_method)(P...) const, const void **p_args, void *r_ret) {
  473. call_with_ptr_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  474. }
  475. template <class T, class... P>
  476. void call_with_ptr_args_static(T *p_instance, void (*p_method)(T *, P...), const void **p_args) {
  477. call_with_ptr_args_static_helper<T, P...>(p_instance, p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  478. }
  479. template <class T, class R, class... P>
  480. void call_with_ptr_args_static_retc(T *p_instance, R (*p_method)(T *, P...), const void **p_args, void *r_ret) {
  481. call_with_ptr_args_static_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  482. }
  483. template <class R, class... P>
  484. void call_with_ptr_args_static_method_ret(R (*p_method)(P...), const void **p_args, void *r_ret) {
  485. call_with_ptr_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  486. }
  487. template <class... P>
  488. void call_with_ptr_args_static_method(void (*p_method)(P...), const void **p_args) {
  489. call_with_ptr_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  490. }
  491. template <class T, class... P>
  492. void call_with_validated_variant_args(Variant *base, void (T::*p_method)(P...), const Variant **p_args) {
  493. call_with_validated_variant_args_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  494. }
  495. template <class T, class R, class... P>
  496. void call_with_validated_variant_args_ret(Variant *base, R (T::*p_method)(P...), const Variant **p_args, Variant *r_ret) {
  497. call_with_validated_variant_args_ret_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  498. }
  499. template <class T, class R, class... P>
  500. void call_with_validated_variant_args_retc(Variant *base, R (T::*p_method)(P...) const, const Variant **p_args, Variant *r_ret) {
  501. call_with_validated_variant_args_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  502. }
  503. template <class T, class... P>
  504. void call_with_validated_variant_args_static(Variant *base, void (*p_method)(T *, P...), const Variant **p_args) {
  505. call_with_validated_variant_args_static_helper<T, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  506. }
  507. template <class T, class R, class... P>
  508. void call_with_validated_variant_args_static_retc(Variant *base, R (*p_method)(T *, P...), const Variant **p_args, Variant *r_ret) {
  509. call_with_validated_variant_args_static_retc_helper<T, R, P...>(VariantGetInternalPtr<T>::get_ptr(base), p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  510. }
  511. template <class... P>
  512. void call_with_validated_variant_args_static_method(void (*p_method)(P...), const Variant **p_args) {
  513. call_with_validated_variant_args_static_method_helper<P...>(p_method, p_args, BuildIndexSequence<sizeof...(P)>{});
  514. }
  515. template <class R, class... P>
  516. void call_with_validated_variant_args_static_method_ret(R (*p_method)(P...), const Variant **p_args, Variant *r_ret) {
  517. call_with_validated_variant_args_static_method_ret_helper<R, P...>(p_method, p_args, r_ret, BuildIndexSequence<sizeof...(P)>{});
  518. }
  519. // GCC raises "parameter 'p_args' set but not used" when P = {},
  520. // it's not clever enough to treat other P values as making this branch valid.
  521. #if defined(__GNUC__) && !defined(__clang__)
  522. #pragma GCC diagnostic push
  523. #pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
  524. #endif
  525. template <class Q>
  526. void call_get_argument_type_helper(int p_arg, int &index, Variant::Type &type) {
  527. if (p_arg == index) {
  528. type = GetTypeInfo<Q>::VARIANT_TYPE;
  529. }
  530. index++;
  531. }
  532. template <class... P>
  533. Variant::Type call_get_argument_type(int p_arg) {
  534. Variant::Type type = Variant::NIL;
  535. int index = 0;
  536. // I think rocket science is simpler than modern C++.
  537. using expand_type = int[];
  538. expand_type a{ 0, (call_get_argument_type_helper<P>(p_arg, index, type), 0)... };
  539. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  540. (void)index; // Suppress GCC warning.
  541. return type;
  542. }
  543. template <class Q>
  544. void call_get_argument_type_info_helper(int p_arg, int &index, PropertyInfo &info) {
  545. if (p_arg == index) {
  546. info = GetTypeInfo<Q>::get_class_info();
  547. }
  548. index++;
  549. }
  550. template <class... P>
  551. void call_get_argument_type_info(int p_arg, PropertyInfo &info) {
  552. int index = 0;
  553. // I think rocket science is simpler than modern C++.
  554. using expand_type = int[];
  555. expand_type a{ 0, (call_get_argument_type_info_helper<P>(p_arg, index, info), 0)... };
  556. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  557. (void)index; // Suppress GCC warning.
  558. }
  559. #ifdef DEBUG_METHODS_ENABLED
  560. template <class Q>
  561. void call_get_argument_metadata_helper(int p_arg, int &index, GodotTypeInfo::Metadata &md) {
  562. if (p_arg == index) {
  563. md = GetTypeInfo<Q>::METADATA;
  564. }
  565. index++;
  566. }
  567. template <class... P>
  568. GodotTypeInfo::Metadata call_get_argument_metadata(int p_arg) {
  569. GodotTypeInfo::Metadata md = GodotTypeInfo::METADATA_NONE;
  570. int index = 0;
  571. // I think rocket science is simpler than modern C++.
  572. using expand_type = int[];
  573. expand_type a{ 0, (call_get_argument_metadata_helper<P>(p_arg, index, md), 0)... };
  574. (void)a; // Suppress (valid, but unavoidable) -Wunused-variable warning.
  575. (void)index;
  576. return md;
  577. }
  578. #endif // DEBUG_METHODS_ENABLED
  579. //////////////////////
  580. template <class T, class R, class... P, size_t... Is>
  581. void call_with_variant_args_ret_helper(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  582. r_error.error = Callable::CallError::CALL_OK;
  583. #ifdef DEBUG_METHODS_ENABLED
  584. r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  585. #else
  586. r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  587. #endif
  588. }
  589. template <class R, class... P, size_t... Is>
  590. void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  591. r_error.error = Callable::CallError::CALL_OK;
  592. #ifdef DEBUG_METHODS_ENABLED
  593. r_ret = (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  594. #else
  595. r_ret = (p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  596. #endif
  597. }
  598. template <class... P, size_t... Is>
  599. void call_with_variant_args_static(void (*p_method)(P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  600. r_error.error = Callable::CallError::CALL_OK;
  601. #ifdef DEBUG_METHODS_ENABLED
  602. (p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  603. #else
  604. (p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  605. #endif
  606. }
  607. template <class T, class R, class... P>
  608. void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  609. #ifdef DEBUG_METHODS_ENABLED
  610. if ((size_t)p_argcount > sizeof...(P)) {
  611. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  612. r_error.argument = sizeof...(P);
  613. return;
  614. }
  615. if ((size_t)p_argcount < sizeof...(P)) {
  616. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  617. r_error.argument = sizeof...(P);
  618. return;
  619. }
  620. #endif
  621. call_with_variant_args_ret_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  622. }
  623. template <class T, class R, class... P, size_t... Is>
  624. void call_with_variant_args_retc_helper(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  625. r_error.error = Callable::CallError::CALL_OK;
  626. #ifdef DEBUG_METHODS_ENABLED
  627. r_ret = (p_instance->*p_method)(VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  628. #else
  629. r_ret = (p_instance->*p_method)(VariantCaster<P>::cast(*p_args[Is])...);
  630. #endif
  631. (void)p_args;
  632. }
  633. template <class R, class... P>
  634. void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  635. #ifdef DEBUG_METHODS_ENABLED
  636. if ((size_t)p_argcount > sizeof...(P)) {
  637. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  638. r_error.argument = sizeof...(P);
  639. return;
  640. }
  641. if ((size_t)p_argcount < sizeof...(P)) {
  642. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  643. r_error.argument = sizeof...(P);
  644. return;
  645. }
  646. #endif
  647. call_with_variant_args_static_ret<R, P...>(p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  648. }
  649. template <class... P>
  650. void call_with_variant_args_static_ret(void (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  651. #ifdef DEBUG_METHODS_ENABLED
  652. if ((size_t)p_argcount > sizeof...(P)) {
  653. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  654. r_error.argument = sizeof...(P);
  655. return;
  656. }
  657. if ((size_t)p_argcount < sizeof...(P)) {
  658. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  659. r_error.argument = sizeof...(P);
  660. return;
  661. }
  662. #endif
  663. call_with_variant_args_static<P...>(p_method, p_args, r_error, BuildIndexSequence<sizeof...(P)>{});
  664. }
  665. template <class T, class R, class... P>
  666. void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error) {
  667. #ifdef DEBUG_METHODS_ENABLED
  668. if ((size_t)p_argcount > sizeof...(P)) {
  669. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  670. r_error.argument = sizeof...(P);
  671. return;
  672. }
  673. if ((size_t)p_argcount < sizeof...(P)) {
  674. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  675. r_error.argument = sizeof...(P);
  676. return;
  677. }
  678. #endif
  679. call_with_variant_args_retc_helper<T, R, P...>(p_instance, p_method, p_args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  680. }
  681. template <class T, class R, class... P, size_t... Is>
  682. void call_with_variant_args_retc_static_helper(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, Variant &r_ret, Callable::CallError &r_error, IndexSequence<Is...>) {
  683. r_error.error = Callable::CallError::CALL_OK;
  684. #ifdef DEBUG_METHODS_ENABLED
  685. r_ret = (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  686. #else
  687. r_ret = (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...);
  688. #endif
  689. (void)p_args;
  690. }
  691. template <class T, class R, class... P>
  692. void call_with_variant_args_retc_static_helper_dv(T *p_instance, R (*p_method)(T *, P...), const Variant **p_args, int p_argcount, Variant &r_ret, const Vector<Variant> &default_values, Callable::CallError &r_error) {
  693. #ifdef DEBUG_ENABLED
  694. if ((size_t)p_argcount > sizeof...(P)) {
  695. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  696. r_error.argument = sizeof...(P);
  697. return;
  698. }
  699. #endif
  700. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  701. int32_t dvs = default_values.size();
  702. #ifdef DEBUG_ENABLED
  703. if (missing > dvs) {
  704. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  705. r_error.argument = sizeof...(P);
  706. return;
  707. }
  708. #endif
  709. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  710. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  711. if (i < p_argcount) {
  712. args[i] = p_args[i];
  713. } else {
  714. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  715. }
  716. }
  717. call_with_variant_args_retc_static_helper(p_instance, p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  718. }
  719. template <class T, class... P, size_t... Is>
  720. void call_with_variant_args_static_helper(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, Callable::CallError &r_error, IndexSequence<Is...>) {
  721. r_error.error = Callable::CallError::CALL_OK;
  722. #ifdef DEBUG_METHODS_ENABLED
  723. (p_method)(p_instance, VariantCasterAndValidate<P>::cast(p_args, Is, r_error)...);
  724. #else
  725. (p_method)(p_instance, VariantCaster<P>::cast(*p_args[Is])...);
  726. #endif
  727. (void)p_args;
  728. }
  729. template <class T, class... P>
  730. void call_with_variant_args_static_helper_dv(T *p_instance, void (*p_method)(T *, P...), const Variant **p_args, int p_argcount, const Vector<Variant> &default_values, Callable::CallError &r_error) {
  731. #ifdef DEBUG_ENABLED
  732. if ((size_t)p_argcount > sizeof...(P)) {
  733. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  734. r_error.argument = sizeof...(P);
  735. return;
  736. }
  737. #endif
  738. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  739. int32_t dvs = default_values.size();
  740. #ifdef DEBUG_ENABLED
  741. if (missing > dvs) {
  742. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  743. r_error.argument = sizeof...(P);
  744. return;
  745. }
  746. #endif
  747. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  748. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  749. if (i < p_argcount) {
  750. args[i] = p_args[i];
  751. } else {
  752. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  753. }
  754. }
  755. call_with_variant_args_static_helper(p_instance, p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  756. }
  757. template <class R, class... P>
  758. void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const Variant **p_args, int p_argcount, Variant &r_ret, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  759. #ifdef DEBUG_ENABLED
  760. if ((size_t)p_argcount > sizeof...(P)) {
  761. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  762. r_error.argument = sizeof...(P);
  763. return;
  764. }
  765. #endif
  766. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  767. int32_t dvs = default_values.size();
  768. #ifdef DEBUG_ENABLED
  769. if (missing > dvs) {
  770. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  771. r_error.argument = sizeof...(P);
  772. return;
  773. }
  774. #endif
  775. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  776. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  777. if (i < p_argcount) {
  778. args[i] = p_args[i];
  779. } else {
  780. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  781. }
  782. }
  783. call_with_variant_args_static_ret(p_method, args, r_ret, r_error, BuildIndexSequence<sizeof...(P)>{});
  784. }
  785. template <class... P>
  786. void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_args, int p_argcount, Callable::CallError &r_error, const Vector<Variant> &default_values) {
  787. #ifdef DEBUG_ENABLED
  788. if ((size_t)p_argcount > sizeof...(P)) {
  789. r_error.error = Callable::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS;
  790. r_error.argument = sizeof...(P);
  791. return;
  792. }
  793. #endif
  794. int32_t missing = (int32_t)sizeof...(P) - (int32_t)p_argcount;
  795. int32_t dvs = default_values.size();
  796. #ifdef DEBUG_ENABLED
  797. if (missing > dvs) {
  798. r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  799. r_error.argument = sizeof...(P);
  800. return;
  801. }
  802. #endif
  803. const Variant *args[sizeof...(P) == 0 ? 1 : sizeof...(P)]; //avoid zero sized array
  804. for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) {
  805. if (i < p_argcount) {
  806. args[i] = p_args[i];
  807. } else {
  808. args[i] = &default_values[i - p_argcount + (dvs - missing)];
  809. }
  810. }
  811. call_with_variant_args_static(p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
  812. }
  813. #if defined(__GNUC__) && !defined(__clang__)
  814. #pragma GCC diagnostic pop
  815. #endif
  816. #endif // BINDER_COMMON_H