extension_api_dump.cpp 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  1. /**************************************************************************/
  2. /* extension_api_dump.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. #include "extension_api_dump.h"
  31. #include "core/config/engine.h"
  32. #include "core/core_constants.h"
  33. #include "core/io/file_access.h"
  34. #include "core/io/json.h"
  35. #include "core/templates/pair.h"
  36. #include "core/version.h"
  37. #ifdef TOOLS_ENABLED
  38. static String get_builtin_or_variant_type_name(const Variant::Type p_type) {
  39. if (p_type == Variant::NIL) {
  40. return "Variant";
  41. } else {
  42. return Variant::get_type_name(p_type);
  43. }
  44. }
  45. static String get_property_info_type_name(const PropertyInfo &p_info) {
  46. if (p_info.type == Variant::INT && (p_info.hint == PROPERTY_HINT_INT_IS_POINTER)) {
  47. if (p_info.hint_string.is_empty()) {
  48. return "void*";
  49. } else {
  50. return p_info.hint_string + "*";
  51. }
  52. }
  53. if (p_info.type == Variant::ARRAY && (p_info.hint == PROPERTY_HINT_ARRAY_TYPE)) {
  54. return String("typedarray::") + p_info.hint_string;
  55. }
  56. if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_ENUM))) {
  57. return String("enum::") + String(p_info.class_name);
  58. }
  59. if (p_info.type == Variant::INT && (p_info.usage & (PROPERTY_USAGE_CLASS_IS_BITFIELD))) {
  60. return String("bitfield::") + String(p_info.class_name);
  61. }
  62. if (p_info.type == Variant::INT && (p_info.usage & PROPERTY_USAGE_ARRAY)) {
  63. return "int";
  64. }
  65. if (p_info.class_name != StringName()) {
  66. return p_info.class_name;
  67. }
  68. if (p_info.hint == PROPERTY_HINT_RESOURCE_TYPE) {
  69. return p_info.hint_string;
  70. }
  71. if (p_info.type == Variant::NIL && (p_info.usage & PROPERTY_USAGE_NIL_IS_VARIANT)) {
  72. return "Variant";
  73. }
  74. if (p_info.type == Variant::NIL) {
  75. return "void";
  76. }
  77. return get_builtin_or_variant_type_name(p_info.type);
  78. }
  79. static String get_type_meta_name(const GodotTypeInfo::Metadata metadata) {
  80. static const char *argmeta[11] = { "none", "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64", "float", "double" };
  81. return argmeta[metadata];
  82. }
  83. Dictionary GDExtensionAPIDump::generate_extension_api() {
  84. Dictionary api_dump;
  85. {
  86. //header
  87. Dictionary header;
  88. header["version_major"] = VERSION_MAJOR;
  89. header["version_minor"] = VERSION_MINOR;
  90. #if VERSION_PATCH
  91. header["version_patch"] = VERSION_PATCH;
  92. #else
  93. header["version_patch"] = 0;
  94. #endif
  95. header["version_status"] = VERSION_STATUS;
  96. header["version_build"] = VERSION_BUILD;
  97. header["version_full_name"] = VERSION_FULL_NAME;
  98. api_dump["header"] = header;
  99. }
  100. const uint32_t vec3_elems = 3;
  101. const uint32_t vec4_elems = 4;
  102. const uint32_t ptrsize_32 = 4;
  103. const uint32_t ptrsize_64 = 8;
  104. static const char *build_config_name[4] = { "float_32", "float_64", "double_32", "double_64" };
  105. {
  106. //type sizes
  107. constexpr struct {
  108. Variant::Type type;
  109. uint32_t size_32_bits_real_float;
  110. uint32_t size_64_bits_real_float;
  111. uint32_t size_32_bits_real_double;
  112. uint32_t size_64_bits_real_double;
  113. // For compile-time size check.
  114. constexpr uint32_t operator[](int index) const {
  115. switch (index) {
  116. #ifndef REAL_T_IS_DOUBLE
  117. case sizeof(uint32_t):
  118. return size_32_bits_real_float;
  119. case sizeof(uint64_t):
  120. return size_64_bits_real_float;
  121. #else // REAL_T_IS_DOUBLE
  122. case sizeof(uint32_t):
  123. return size_32_bits_real_double;
  124. case sizeof(uint64_t):
  125. return size_64_bits_real_double;
  126. #endif
  127. }
  128. return -1;
  129. }
  130. } type_size_array[Variant::VARIANT_MAX + 1] = {
  131. { Variant::NIL, 0, 0, 0, 0 },
  132. { Variant::BOOL, sizeof(uint8_t), sizeof(uint8_t), sizeof(uint8_t), sizeof(uint8_t) },
  133. { Variant::INT, sizeof(int64_t), sizeof(int64_t), sizeof(int64_t), sizeof(int64_t) },
  134. { Variant::FLOAT, sizeof(double), sizeof(double), sizeof(double), sizeof(double) },
  135. { Variant::STRING, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  136. { Variant::VECTOR2, 2 * sizeof(float), 2 * sizeof(float), 2 * sizeof(double), 2 * sizeof(double) },
  137. { Variant::VECTOR2I, 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t), 2 * sizeof(int32_t) },
  138. { Variant::RECT2, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  139. { Variant::RECT2I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) },
  140. { Variant::VECTOR3, vec3_elems * sizeof(float), vec3_elems * sizeof(float), vec3_elems * sizeof(double), vec3_elems * sizeof(double) },
  141. { Variant::VECTOR3I, 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t), 3 * sizeof(int32_t) },
  142. { Variant::TRANSFORM2D, 6 * sizeof(float), 6 * sizeof(float), 6 * sizeof(double), 6 * sizeof(double) },
  143. { Variant::VECTOR4, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  144. { Variant::VECTOR4I, 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t), 4 * sizeof(int32_t) },
  145. { Variant::PLANE, (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(float), (vec3_elems + 1) * sizeof(double), (vec3_elems + 1) * sizeof(double) },
  146. { Variant::QUATERNION, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(double), 4 * sizeof(double) },
  147. { Variant::AABB, (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(float), (vec3_elems * 2) * sizeof(double), (vec3_elems * 2) * sizeof(double) },
  148. { Variant::BASIS, (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(float), (vec3_elems * 3) * sizeof(double), (vec3_elems * 3) * sizeof(double) },
  149. { Variant::TRANSFORM3D, (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(float), (vec3_elems * 4) * sizeof(double), (vec3_elems * 4) * sizeof(double) },
  150. { Variant::PROJECTION, (vec4_elems * 4) * sizeof(float), (vec4_elems * 4) * sizeof(float), (vec4_elems * 4) * sizeof(double), (vec4_elems * 4) * sizeof(double) },
  151. { Variant::COLOR, 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float), 4 * sizeof(float) },
  152. { Variant::STRING_NAME, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  153. { Variant::NODE_PATH, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  154. { Variant::RID, sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t), sizeof(uint64_t) },
  155. { Variant::OBJECT, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  156. { Variant::CALLABLE, sizeof(Callable), sizeof(Callable), sizeof(Callable), sizeof(Callable) }, // Hardcoded align.
  157. { Variant::SIGNAL, sizeof(Signal), sizeof(Signal), sizeof(Signal), sizeof(Signal) }, // Hardcoded align.
  158. { Variant::DICTIONARY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  159. { Variant::ARRAY, ptrsize_32, ptrsize_64, ptrsize_32, ptrsize_64 },
  160. { Variant::PACKED_BYTE_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  161. { Variant::PACKED_INT32_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  162. { Variant::PACKED_INT64_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  163. { Variant::PACKED_FLOAT32_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  164. { Variant::PACKED_FLOAT64_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  165. { Variant::PACKED_STRING_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  166. { Variant::PACKED_VECTOR2_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  167. { Variant::PACKED_VECTOR3_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  168. { Variant::PACKED_COLOR_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
  169. { Variant::VARIANT_MAX, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(double) * 4, sizeof(uint64_t) + sizeof(double) * 4 },
  170. };
  171. // Validate sizes at compile time for the current build configuration.
  172. static_assert(type_size_array[Variant::BOOL][sizeof(void *)] == sizeof(GDExtensionBool), "Size of bool mismatch");
  173. static_assert(type_size_array[Variant::INT][sizeof(void *)] == sizeof(GDExtensionInt), "Size of int mismatch");
  174. static_assert(type_size_array[Variant::FLOAT][sizeof(void *)] == sizeof(double), "Size of float mismatch");
  175. static_assert(type_size_array[Variant::STRING][sizeof(void *)] == sizeof(String), "Size of String mismatch");
  176. static_assert(type_size_array[Variant::VECTOR2][sizeof(void *)] == sizeof(Vector2), "Size of Vector2 mismatch");
  177. static_assert(type_size_array[Variant::VECTOR2I][sizeof(void *)] == sizeof(Vector2i), "Size of Vector2i mismatch");
  178. static_assert(type_size_array[Variant::RECT2][sizeof(void *)] == sizeof(Rect2), "Size of Rect2 mismatch");
  179. static_assert(type_size_array[Variant::RECT2I][sizeof(void *)] == sizeof(Rect2i), "Size of Rect2i mismatch");
  180. static_assert(type_size_array[Variant::VECTOR3][sizeof(void *)] == sizeof(Vector3), "Size of Vector3 mismatch");
  181. static_assert(type_size_array[Variant::VECTOR3I][sizeof(void *)] == sizeof(Vector3i), "Size of Vector3i mismatch");
  182. static_assert(type_size_array[Variant::TRANSFORM2D][sizeof(void *)] == sizeof(Transform2D), "Size of Transform2D mismatch");
  183. static_assert(type_size_array[Variant::VECTOR4][sizeof(void *)] == sizeof(Vector4), "Size of Vector4 mismatch");
  184. static_assert(type_size_array[Variant::VECTOR4I][sizeof(void *)] == sizeof(Vector4i), "Size of Vector4i mismatch");
  185. static_assert(type_size_array[Variant::PLANE][sizeof(void *)] == sizeof(Plane), "Size of Plane mismatch");
  186. static_assert(type_size_array[Variant::QUATERNION][sizeof(void *)] == sizeof(Quaternion), "Size of Quaternion mismatch");
  187. static_assert(type_size_array[Variant::AABB][sizeof(void *)] == sizeof(AABB), "Size of AABB mismatch");
  188. static_assert(type_size_array[Variant::BASIS][sizeof(void *)] == sizeof(Basis), "Size of Basis mismatch");
  189. static_assert(type_size_array[Variant::TRANSFORM3D][sizeof(void *)] == sizeof(Transform3D), "Size of Transform3D mismatch");
  190. static_assert(type_size_array[Variant::PROJECTION][sizeof(void *)] == sizeof(Projection), "Size of Projection mismatch");
  191. static_assert(type_size_array[Variant::COLOR][sizeof(void *)] == sizeof(Color), "Size of Color mismatch");
  192. static_assert(type_size_array[Variant::STRING_NAME][sizeof(void *)] == sizeof(StringName), "Size of StringName mismatch");
  193. static_assert(type_size_array[Variant::NODE_PATH][sizeof(void *)] == sizeof(NodePath), "Size of NodePath mismatch");
  194. static_assert(type_size_array[Variant::RID][sizeof(void *)] == sizeof(RID), "Size of RID mismatch");
  195. static_assert(type_size_array[Variant::OBJECT][sizeof(void *)] == sizeof(Object *), "Size of Object mismatch");
  196. static_assert(type_size_array[Variant::CALLABLE][sizeof(void *)] == sizeof(Callable), "Size of Callable mismatch");
  197. static_assert(type_size_array[Variant::SIGNAL][sizeof(void *)] == sizeof(Signal), "Size of Signal mismatch");
  198. static_assert(type_size_array[Variant::DICTIONARY][sizeof(void *)] == sizeof(Dictionary), "Size of Dictionary mismatch");
  199. static_assert(type_size_array[Variant::ARRAY][sizeof(void *)] == sizeof(Array), "Size of Array mismatch");
  200. static_assert(type_size_array[Variant::PACKED_BYTE_ARRAY][sizeof(void *)] == sizeof(PackedByteArray), "Size of PackedByteArray mismatch");
  201. static_assert(type_size_array[Variant::PACKED_INT32_ARRAY][sizeof(void *)] == sizeof(PackedInt32Array), "Size of PackedInt32Array mismatch");
  202. static_assert(type_size_array[Variant::PACKED_INT64_ARRAY][sizeof(void *)] == sizeof(PackedInt64Array), "Size of PackedInt64Array mismatch");
  203. static_assert(type_size_array[Variant::PACKED_FLOAT32_ARRAY][sizeof(void *)] == sizeof(PackedFloat32Array), "Size of PackedFloat32Array mismatch");
  204. static_assert(type_size_array[Variant::PACKED_FLOAT64_ARRAY][sizeof(void *)] == sizeof(PackedFloat64Array), "Size of PackedFloat64Array mismatch");
  205. static_assert(type_size_array[Variant::PACKED_STRING_ARRAY][sizeof(void *)] == sizeof(PackedStringArray), "Size of PackedStringArray mismatch");
  206. static_assert(type_size_array[Variant::PACKED_VECTOR2_ARRAY][sizeof(void *)] == sizeof(PackedVector2Array), "Size of PackedVector2Array mismatch");
  207. static_assert(type_size_array[Variant::PACKED_VECTOR3_ARRAY][sizeof(void *)] == sizeof(PackedVector3Array), "Size of PackedVector3Array mismatch");
  208. static_assert(type_size_array[Variant::PACKED_COLOR_ARRAY][sizeof(void *)] == sizeof(PackedColorArray), "Size of PackedColorArray mismatch");
  209. static_assert(type_size_array[Variant::VARIANT_MAX][sizeof(void *)] == sizeof(Variant), "Size of Variant mismatch");
  210. Array core_type_sizes;
  211. for (int i = 0; i < 4; i++) {
  212. Dictionary d;
  213. d["build_configuration"] = build_config_name[i];
  214. Array sizes;
  215. for (int j = 0; j <= Variant::VARIANT_MAX; j++) {
  216. Variant::Type t = type_size_array[j].type;
  217. String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t);
  218. Dictionary d2;
  219. d2["name"] = name;
  220. uint32_t size = 0;
  221. switch (i) {
  222. case 0:
  223. size = type_size_array[j].size_32_bits_real_float;
  224. break;
  225. case 1:
  226. size = type_size_array[j].size_64_bits_real_float;
  227. break;
  228. case 2:
  229. size = type_size_array[j].size_32_bits_real_double;
  230. break;
  231. case 3:
  232. size = type_size_array[j].size_64_bits_real_double;
  233. break;
  234. }
  235. d2["size"] = size;
  236. sizes.push_back(d2);
  237. }
  238. d["sizes"] = sizes;
  239. core_type_sizes.push_back(d);
  240. }
  241. api_dump["builtin_class_sizes"] = core_type_sizes;
  242. }
  243. {
  244. // Member offsets, meta types and sizes.
  245. #define REAL_MEMBER_OFFSET(type, member) \
  246. { \
  247. type, \
  248. member, \
  249. "float", \
  250. sizeof(float), \
  251. "float", \
  252. sizeof(float), \
  253. "double", \
  254. sizeof(double), \
  255. "double", \
  256. sizeof(double), \
  257. }
  258. #define INT32_MEMBER_OFFSET(type, member) \
  259. { \
  260. type, \
  261. member, \
  262. "int32", \
  263. sizeof(int32_t), \
  264. "int32", \
  265. sizeof(int32_t), \
  266. "int32", \
  267. sizeof(int32_t), \
  268. "int32", \
  269. sizeof(int32_t), \
  270. }
  271. #define INT32_BASED_BUILTIN_MEMBER_OFFSET(type, member, member_type, member_elems) \
  272. { \
  273. type, \
  274. member, \
  275. member_type, \
  276. sizeof(int32_t) * member_elems, \
  277. member_type, \
  278. sizeof(int32_t) * member_elems, \
  279. member_type, \
  280. sizeof(int32_t) * member_elems, \
  281. member_type, \
  282. sizeof(int32_t) * member_elems, \
  283. }
  284. #define REAL_BASED_BUILTIN_MEMBER_OFFSET(type, member, member_type, member_elems) \
  285. { \
  286. type, \
  287. member, \
  288. member_type, \
  289. sizeof(float) * member_elems, \
  290. member_type, \
  291. sizeof(float) * member_elems, \
  292. member_type, \
  293. sizeof(double) * member_elems, \
  294. member_type, \
  295. sizeof(double) * member_elems, \
  296. }
  297. struct {
  298. Variant::Type type;
  299. const char *member;
  300. const char *member_meta_32_bits_real_float;
  301. const uint32_t member_size_32_bits_real_float;
  302. const char *member_meta_64_bits_real_float;
  303. const uint32_t member_size_64_bits_real_float;
  304. const char *member_meta_32_bits_real_double;
  305. const uint32_t member_size_32_bits_real_double;
  306. const char *member_meta_64_bits_real_double;
  307. const uint32_t member_size_64_bits_real_double;
  308. } member_offset_array[] = {
  309. // Vector2
  310. REAL_MEMBER_OFFSET(Variant::VECTOR2, "x"),
  311. REAL_MEMBER_OFFSET(Variant::VECTOR2, "y"),
  312. // Vector2i
  313. INT32_MEMBER_OFFSET(Variant::VECTOR2I, "x"),
  314. INT32_MEMBER_OFFSET(Variant::VECTOR2I, "y"),
  315. // Rect2
  316. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2, "position", "Vector2", 2),
  317. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2, "size", "Vector2", 2),
  318. // Rect2i
  319. INT32_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2I, "position", "Vector2i", 2),
  320. INT32_BASED_BUILTIN_MEMBER_OFFSET(Variant::RECT2I, "size", "Vector2i", 2),
  321. // Vector3
  322. REAL_MEMBER_OFFSET(Variant::VECTOR3, "x"),
  323. REAL_MEMBER_OFFSET(Variant::VECTOR3, "y"),
  324. REAL_MEMBER_OFFSET(Variant::VECTOR3, "z"),
  325. // Vector3i
  326. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "x"),
  327. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "y"),
  328. INT32_MEMBER_OFFSET(Variant::VECTOR3I, "z"),
  329. // Transform2D
  330. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "x", "Vector2", 2),
  331. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "y", "Vector2", 2),
  332. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM2D, "origin", "Vector2", 2),
  333. // Vector4
  334. REAL_MEMBER_OFFSET(Variant::VECTOR4, "x"),
  335. REAL_MEMBER_OFFSET(Variant::VECTOR4, "y"),
  336. REAL_MEMBER_OFFSET(Variant::VECTOR4, "z"),
  337. REAL_MEMBER_OFFSET(Variant::VECTOR4, "w"),
  338. // Vector4i
  339. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "x"),
  340. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "y"),
  341. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "z"),
  342. INT32_MEMBER_OFFSET(Variant::VECTOR4I, "w"),
  343. // Plane
  344. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PLANE, "normal", "Vector3", vec3_elems),
  345. REAL_MEMBER_OFFSET(Variant::PLANE, "d"),
  346. // Quaternion
  347. REAL_MEMBER_OFFSET(Variant::QUATERNION, "x"),
  348. REAL_MEMBER_OFFSET(Variant::QUATERNION, "y"),
  349. REAL_MEMBER_OFFSET(Variant::QUATERNION, "z"),
  350. REAL_MEMBER_OFFSET(Variant::QUATERNION, "w"),
  351. // AABB
  352. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::AABB, "position", "Vector3", vec3_elems),
  353. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::AABB, "size", "Vector3", vec3_elems),
  354. // Basis (remember that basis vectors are flipped!)
  355. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "x", "Vector3", vec3_elems),
  356. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "y", "Vector3", vec3_elems),
  357. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::BASIS, "z", "Vector3", vec3_elems),
  358. // Transform3D
  359. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM3D, "basis", "Basis", vec3_elems * 3),
  360. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::TRANSFORM3D, "origin", "Vector3", vec3_elems),
  361. // Projection
  362. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "x", "Vector4", vec4_elems),
  363. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "y", "Vector4", vec4_elems),
  364. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "z", "Vector4", vec4_elems),
  365. REAL_BASED_BUILTIN_MEMBER_OFFSET(Variant::PROJECTION, "w", "Vector4", vec4_elems),
  366. // Color (always composed of 4bytes floats)
  367. { Variant::COLOR, "r", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  368. { Variant::COLOR, "g", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  369. { Variant::COLOR, "b", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  370. { Variant::COLOR, "a", "float", sizeof(float), "float", sizeof(float), "float", sizeof(float), "float", sizeof(float) },
  371. // End marker, must stay last
  372. { Variant::NIL, nullptr, nullptr, 0, nullptr, 0, nullptr, 0, nullptr, 0 },
  373. };
  374. Array core_type_member_offsets;
  375. for (int i = 0; i < 4; i++) {
  376. Dictionary d;
  377. d["build_configuration"] = build_config_name[i];
  378. Array type_offsets;
  379. uint32_t idx = 0;
  380. Variant::Type previous_type = Variant::NIL;
  381. Dictionary d2;
  382. Array members;
  383. uint32_t offset = 0;
  384. while (true) {
  385. Variant::Type t = member_offset_array[idx].type;
  386. if (t != previous_type) {
  387. if (previous_type != Variant::NIL) {
  388. d2["members"] = members;
  389. type_offsets.push_back(d2);
  390. }
  391. if (t == Variant::NIL) {
  392. break;
  393. }
  394. String name = t == Variant::VARIANT_MAX ? String("Variant") : Variant::get_type_name(t);
  395. d2 = Dictionary();
  396. members = Array();
  397. offset = 0;
  398. d2["name"] = name;
  399. previous_type = t;
  400. }
  401. Dictionary d3;
  402. const char *member_meta = nullptr;
  403. uint32_t member_size = 0;
  404. switch (i) {
  405. case 0:
  406. member_meta = member_offset_array[idx].member_meta_32_bits_real_float;
  407. member_size = member_offset_array[idx].member_size_32_bits_real_float;
  408. break;
  409. case 1:
  410. member_meta = member_offset_array[idx].member_meta_64_bits_real_float;
  411. member_size = member_offset_array[idx].member_size_64_bits_real_float;
  412. break;
  413. case 2:
  414. member_meta = member_offset_array[idx].member_meta_32_bits_real_double;
  415. member_size = member_offset_array[idx].member_size_32_bits_real_double;
  416. break;
  417. case 3:
  418. member_meta = member_offset_array[idx].member_meta_64_bits_real_double;
  419. member_size = member_offset_array[idx].member_size_64_bits_real_double;
  420. break;
  421. }
  422. d3["member"] = member_offset_array[idx].member;
  423. d3["offset"] = offset;
  424. d3["meta"] = member_meta;
  425. offset += member_size;
  426. members.push_back(d3);
  427. idx++;
  428. }
  429. d["classes"] = type_offsets;
  430. core_type_member_offsets.push_back(d);
  431. }
  432. api_dump["builtin_class_member_offsets"] = core_type_member_offsets;
  433. }
  434. {
  435. // Global enums and constants.
  436. Array constants;
  437. HashMap<String, List<Pair<String, int64_t>>> enum_list;
  438. HashMap<String, bool> enum_is_bitfield;
  439. for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
  440. int64_t value = CoreConstants::get_global_constant_value(i);
  441. String enum_name = CoreConstants::get_global_constant_enum(i);
  442. String name = CoreConstants::get_global_constant_name(i);
  443. bool bitfield = CoreConstants::is_global_constant_bitfield(i);
  444. if (!enum_name.is_empty()) {
  445. enum_list[enum_name].push_back(Pair<String, int64_t>(name, value));
  446. enum_is_bitfield[enum_name] = bitfield;
  447. } else {
  448. Dictionary d;
  449. d["name"] = name;
  450. d["value"] = value;
  451. d["is_bitfield"] = bitfield;
  452. constants.push_back(d);
  453. }
  454. }
  455. api_dump["global_constants"] = constants;
  456. Array enums;
  457. for (const KeyValue<String, List<Pair<String, int64_t>>> &E : enum_list) {
  458. Dictionary d1;
  459. d1["name"] = E.key;
  460. d1["is_bitfield"] = enum_is_bitfield[E.key];
  461. Array values;
  462. for (const Pair<String, int64_t> &F : E.value) {
  463. Dictionary d2;
  464. d2["name"] = F.first;
  465. d2["value"] = F.second;
  466. values.push_back(d2);
  467. }
  468. d1["values"] = values;
  469. enums.push_back(d1);
  470. }
  471. api_dump["global_enums"] = enums;
  472. }
  473. {
  474. Array utility_funcs;
  475. List<StringName> utility_func_names;
  476. Variant::get_utility_function_list(&utility_func_names);
  477. for (const StringName &name : utility_func_names) {
  478. Dictionary func;
  479. func["name"] = String(name);
  480. if (Variant::has_utility_function_return_value(name)) {
  481. Variant::Type rt = Variant::get_utility_function_return_type(name);
  482. func["return_type"] = rt == Variant::NIL ? String("Variant") : Variant::get_type_name(rt);
  483. }
  484. switch (Variant::get_utility_function_type(name)) {
  485. case Variant::UTILITY_FUNC_TYPE_MATH:
  486. func["category"] = "math";
  487. break;
  488. case Variant::UTILITY_FUNC_TYPE_RANDOM:
  489. func["category"] = "random";
  490. break;
  491. case Variant::UTILITY_FUNC_TYPE_GENERAL:
  492. func["category"] = "general";
  493. break;
  494. }
  495. bool vararg = Variant::is_utility_function_vararg(name);
  496. func["is_vararg"] = Variant::is_utility_function_vararg(name);
  497. func["hash"] = Variant::get_utility_function_hash(name);
  498. Array arguments;
  499. int argcount = Variant::get_utility_function_argument_count(name);
  500. for (int i = 0; i < argcount; i++) {
  501. Dictionary arg;
  502. String argname = vararg ? "arg" + itos(i + 1) : Variant::get_utility_function_argument_name(name, i);
  503. arg["name"] = argname;
  504. arg["type"] = get_builtin_or_variant_type_name(Variant::get_utility_function_argument_type(name, i));
  505. //no default value support in utility functions
  506. arguments.push_back(arg);
  507. }
  508. if (arguments.size()) {
  509. func["arguments"] = arguments;
  510. }
  511. utility_funcs.push_back(func);
  512. }
  513. api_dump["utility_functions"] = utility_funcs;
  514. }
  515. {
  516. // builtin types
  517. Array builtins;
  518. for (int i = 0; i < Variant::VARIANT_MAX; i++) {
  519. if (i == Variant::OBJECT) {
  520. continue;
  521. }
  522. Variant::Type type = Variant::Type(i);
  523. Dictionary d;
  524. d["name"] = Variant::get_type_name(type);
  525. if (Variant::has_indexing(type)) {
  526. d["indexing_return_type"] = get_builtin_or_variant_type_name(Variant::get_indexed_element_type(type));
  527. }
  528. d["is_keyed"] = Variant::is_keyed(type);
  529. {
  530. //members
  531. Array members;
  532. List<StringName> member_names;
  533. Variant::get_member_list(type, &member_names);
  534. for (const StringName &member_name : member_names) {
  535. Dictionary d2;
  536. d2["name"] = String(member_name);
  537. d2["type"] = get_builtin_or_variant_type_name(Variant::get_member_type(type, member_name));
  538. members.push_back(d2);
  539. }
  540. if (members.size()) {
  541. d["members"] = members;
  542. }
  543. }
  544. {
  545. //constants
  546. Array constants;
  547. List<StringName> constant_names;
  548. Variant::get_constants_for_type(type, &constant_names);
  549. for (const StringName &constant_name : constant_names) {
  550. Dictionary d2;
  551. d2["name"] = String(constant_name);
  552. Variant constant = Variant::get_constant_value(type, constant_name);
  553. d2["type"] = get_builtin_or_variant_type_name(constant.get_type());
  554. d2["value"] = constant.get_construct_string();
  555. constants.push_back(d2);
  556. }
  557. if (constants.size()) {
  558. d["constants"] = constants;
  559. }
  560. }
  561. {
  562. //enums
  563. Array enums;
  564. List<StringName> enum_names;
  565. Variant::get_enums_for_type(type, &enum_names);
  566. for (const StringName &enum_name : enum_names) {
  567. Dictionary enum_dict;
  568. enum_dict["name"] = String(enum_name);
  569. List<StringName> enumeration_names;
  570. Variant::get_enumerations_for_enum(type, enum_name, &enumeration_names);
  571. Array values;
  572. for (const StringName &enumeration : enumeration_names) {
  573. Dictionary values_dict;
  574. values_dict["name"] = String(enumeration);
  575. values_dict["value"] = Variant::get_enum_value(type, enum_name, enumeration);
  576. values.push_back(values_dict);
  577. }
  578. if (values.size()) {
  579. enum_dict["values"] = values;
  580. }
  581. enums.push_back(enum_dict);
  582. }
  583. if (enums.size()) {
  584. d["enums"] = enums;
  585. }
  586. }
  587. {
  588. //operators
  589. Array operators;
  590. for (int j = 0; j < Variant::VARIANT_MAX; j++) {
  591. for (int k = 0; k < Variant::OP_MAX; k++) {
  592. Variant::Type rt = Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j));
  593. if (rt != Variant::NIL) {
  594. Dictionary d2;
  595. d2["name"] = Variant::get_operator_name(Variant::Operator(k));
  596. if (k != Variant::OP_NEGATE && k != Variant::OP_POSITIVE && k != Variant::OP_NOT && k != Variant::OP_BIT_NEGATE) {
  597. d2["right_type"] = get_builtin_or_variant_type_name(Variant::Type(j));
  598. }
  599. d2["return_type"] = get_builtin_or_variant_type_name(Variant::get_operator_return_type(Variant::Operator(k), type, Variant::Type(j)));
  600. operators.push_back(d2);
  601. }
  602. }
  603. }
  604. if (operators.size()) {
  605. d["operators"] = operators;
  606. }
  607. }
  608. {
  609. //methods
  610. Array methods;
  611. List<StringName> method_names;
  612. Variant::get_builtin_method_list(type, &method_names);
  613. for (const StringName &method_name : method_names) {
  614. Dictionary d2;
  615. d2["name"] = String(method_name);
  616. if (Variant::has_builtin_method_return_value(type, method_name)) {
  617. Variant::Type ret_type = Variant::get_builtin_method_return_type(type, method_name);
  618. d2["return_type"] = ret_type == Variant::NIL ? String("Variant") : Variant::get_type_name(ret_type);
  619. }
  620. d2["is_vararg"] = Variant::is_builtin_method_vararg(type, method_name);
  621. d2["is_const"] = Variant::is_builtin_method_const(type, method_name);
  622. d2["is_static"] = Variant::is_builtin_method_static(type, method_name);
  623. d2["hash"] = Variant::get_builtin_method_hash(type, method_name);
  624. Vector<Variant> default_args = Variant::get_builtin_method_default_arguments(type, method_name);
  625. Array arguments;
  626. int argcount = Variant::get_builtin_method_argument_count(type, method_name);
  627. for (int j = 0; j < argcount; j++) {
  628. Dictionary d3;
  629. d3["name"] = Variant::get_builtin_method_argument_name(type, method_name, j);
  630. d3["type"] = get_builtin_or_variant_type_name(Variant::get_builtin_method_argument_type(type, method_name, j));
  631. if (j >= (argcount - default_args.size())) {
  632. int dargidx = j - (argcount - default_args.size());
  633. d3["default_value"] = default_args[dargidx].get_construct_string();
  634. }
  635. arguments.push_back(d3);
  636. }
  637. if (arguments.size()) {
  638. d2["arguments"] = arguments;
  639. }
  640. methods.push_back(d2);
  641. }
  642. if (methods.size()) {
  643. d["methods"] = methods;
  644. }
  645. }
  646. {
  647. //constructors
  648. Array constructors;
  649. for (int j = 0; j < Variant::get_constructor_count(type); j++) {
  650. Dictionary d2;
  651. d2["index"] = j;
  652. Array arguments;
  653. int argcount = Variant::get_constructor_argument_count(type, j);
  654. for (int k = 0; k < argcount; k++) {
  655. Dictionary d3;
  656. d3["name"] = Variant::get_constructor_argument_name(type, j, k);
  657. d3["type"] = get_builtin_or_variant_type_name(Variant::get_constructor_argument_type(type, j, k));
  658. arguments.push_back(d3);
  659. }
  660. if (arguments.size()) {
  661. d2["arguments"] = arguments;
  662. }
  663. constructors.push_back(d2);
  664. }
  665. if (constructors.size()) {
  666. d["constructors"] = constructors;
  667. }
  668. }
  669. {
  670. //destructor
  671. d["has_destructor"] = Variant::has_destructor(type);
  672. }
  673. builtins.push_back(d);
  674. }
  675. api_dump["builtin_classes"] = builtins;
  676. }
  677. {
  678. // classes
  679. Array classes;
  680. List<StringName> class_list;
  681. ClassDB::get_class_list(&class_list);
  682. class_list.sort_custom<StringName::AlphCompare>();
  683. for (const StringName &class_name : class_list) {
  684. Dictionary d;
  685. d["name"] = String(class_name);
  686. d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted");
  687. d["is_instantiable"] = ClassDB::can_instantiate(class_name);
  688. StringName parent_class = ClassDB::get_parent_class(class_name);
  689. if (parent_class != StringName()) {
  690. d["inherits"] = String(parent_class);
  691. }
  692. {
  693. ClassDB::APIType api = ClassDB::get_api_type(class_name);
  694. static const char *api_type[5] = { "core", "editor", "extension", "editor_extension" };
  695. d["api_type"] = api_type[api];
  696. }
  697. {
  698. //constants
  699. Array constants;
  700. List<String> constant_list;
  701. ClassDB::get_integer_constant_list(class_name, &constant_list, true);
  702. for (const String &F : constant_list) {
  703. StringName enum_name = ClassDB::get_integer_constant_enum(class_name, F);
  704. if (enum_name != StringName()) {
  705. continue; //enums will be handled on their own
  706. }
  707. Dictionary d2;
  708. d2["name"] = String(F);
  709. d2["value"] = ClassDB::get_integer_constant(class_name, F);
  710. constants.push_back(d2);
  711. }
  712. if (constants.size()) {
  713. d["constants"] = constants;
  714. }
  715. }
  716. {
  717. //enum
  718. Array enums;
  719. List<StringName> enum_list;
  720. ClassDB::get_enum_list(class_name, &enum_list, true);
  721. for (const StringName &F : enum_list) {
  722. Dictionary d2;
  723. d2["name"] = String(F);
  724. d2["is_bitfield"] = ClassDB::is_enum_bitfield(class_name, F);
  725. Array values;
  726. List<StringName> enum_constant_list;
  727. ClassDB::get_enum_constants(class_name, F, &enum_constant_list, true);
  728. for (List<StringName>::Element *G = enum_constant_list.front(); G; G = G->next()) {
  729. Dictionary d3;
  730. d3["name"] = String(G->get());
  731. d3["value"] = ClassDB::get_integer_constant(class_name, G->get());
  732. values.push_back(d3);
  733. }
  734. d2["values"] = values;
  735. enums.push_back(d2);
  736. }
  737. if (enums.size()) {
  738. d["enums"] = enums;
  739. }
  740. }
  741. {
  742. //methods
  743. Array methods;
  744. List<MethodInfo> method_list;
  745. ClassDB::get_method_list(class_name, &method_list, true);
  746. for (const MethodInfo &F : method_list) {
  747. StringName method_name = F.name;
  748. if ((F.flags & METHOD_FLAG_VIRTUAL) && !(F.flags & METHOD_FLAG_OBJECT_CORE)) {
  749. //virtual method
  750. const MethodInfo &mi = F;
  751. Dictionary d2;
  752. d2["name"] = String(method_name);
  753. d2["is_const"] = (F.flags & METHOD_FLAG_CONST) ? true : false;
  754. d2["is_static"] = (F.flags & METHOD_FLAG_STATIC) ? true : false;
  755. d2["is_vararg"] = false;
  756. d2["is_virtual"] = true;
  757. // virtual functions have no hash since no MethodBind is involved
  758. bool has_return = mi.return_val.type != Variant::NIL || (mi.return_val.usage & PROPERTY_USAGE_NIL_IS_VARIANT);
  759. Array arguments;
  760. for (int i = (has_return ? -1 : 0); i < mi.arguments.size(); i++) {
  761. PropertyInfo pinfo = i == -1 ? mi.return_val : mi.arguments[i];
  762. Dictionary d3;
  763. if (i >= 0) {
  764. d3["name"] = pinfo.name;
  765. }
  766. d3["type"] = get_property_info_type_name(pinfo);
  767. if (mi.get_argument_meta(i) > 0) {
  768. d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)mi.get_argument_meta(i));
  769. }
  770. if (i == -1) {
  771. d2["return_value"] = d3;
  772. } else {
  773. arguments.push_back(d3);
  774. }
  775. }
  776. if (arguments.size()) {
  777. d2["arguments"] = arguments;
  778. }
  779. methods.push_back(d2);
  780. } else if (F.name.begins_with("_")) {
  781. //hidden method, ignore
  782. } else {
  783. Dictionary d2;
  784. d2["name"] = String(method_name);
  785. MethodBind *method = ClassDB::get_method(class_name, method_name);
  786. if (!method) {
  787. continue;
  788. }
  789. d2["is_const"] = method->is_const();
  790. d2["is_vararg"] = method->is_vararg();
  791. d2["is_static"] = method->is_static();
  792. d2["is_virtual"] = false;
  793. d2["hash"] = method->get_hash();
  794. Vector<Variant> default_args = method->get_default_arguments();
  795. Array arguments;
  796. for (int i = (method->has_return() ? -1 : 0); i < method->get_argument_count(); i++) {
  797. PropertyInfo pinfo = i == -1 ? method->get_return_info() : method->get_argument_info(i);
  798. Dictionary d3;
  799. if (i >= 0) {
  800. d3["name"] = pinfo.name;
  801. }
  802. d3["type"] = get_property_info_type_name(pinfo);
  803. if (method->get_argument_meta(i) > 0) {
  804. d3["meta"] = get_type_meta_name(method->get_argument_meta(i));
  805. }
  806. if (i >= 0 && i >= (method->get_argument_count() - default_args.size())) {
  807. int dargidx = i - (method->get_argument_count() - default_args.size());
  808. d3["default_value"] = default_args[dargidx].get_construct_string();
  809. }
  810. if (i == -1) {
  811. d2["return_value"] = d3;
  812. } else {
  813. arguments.push_back(d3);
  814. }
  815. }
  816. if (arguments.size()) {
  817. d2["arguments"] = arguments;
  818. }
  819. methods.push_back(d2);
  820. }
  821. }
  822. if (methods.size()) {
  823. d["methods"] = methods;
  824. }
  825. }
  826. {
  827. //signals
  828. Array signals;
  829. List<MethodInfo> signal_list;
  830. ClassDB::get_signal_list(class_name, &signal_list, true);
  831. for (const MethodInfo &F : signal_list) {
  832. StringName signal_name = F.name;
  833. Dictionary d2;
  834. d2["name"] = String(signal_name);
  835. Array arguments;
  836. for (int i = 0; i < F.arguments.size(); i++) {
  837. Dictionary d3;
  838. d3["name"] = F.arguments[i].name;
  839. d3["type"] = get_property_info_type_name(F.arguments[i]);
  840. if (F.get_argument_meta(i) > 0) {
  841. d3["meta"] = get_type_meta_name((GodotTypeInfo::Metadata)F.get_argument_meta(i));
  842. }
  843. arguments.push_back(d3);
  844. }
  845. if (arguments.size()) {
  846. d2["arguments"] = arguments;
  847. }
  848. signals.push_back(d2);
  849. }
  850. if (signals.size()) {
  851. d["signals"] = signals;
  852. }
  853. }
  854. {
  855. //properties
  856. Array properties;
  857. List<PropertyInfo> property_list;
  858. ClassDB::get_property_list(class_name, &property_list, true);
  859. for (const PropertyInfo &F : property_list) {
  860. if (F.usage & PROPERTY_USAGE_CATEGORY || F.usage & PROPERTY_USAGE_GROUP || F.usage & PROPERTY_USAGE_SUBGROUP || (F.type == Variant::NIL && F.usage & PROPERTY_USAGE_ARRAY)) {
  861. continue; //not real properties
  862. }
  863. if (F.name.begins_with("_")) {
  864. continue; //hidden property
  865. }
  866. if (F.name.find("/") >= 0) {
  867. // Ignore properties with '/' (slash) in the name. These are only meant for use in the inspector.
  868. continue;
  869. }
  870. StringName property_name = F.name;
  871. Dictionary d2;
  872. d2["type"] = get_property_info_type_name(F);
  873. d2["name"] = String(property_name);
  874. StringName setter = ClassDB::get_property_setter(class_name, F.name);
  875. if (!(setter == "")) {
  876. d2["setter"] = setter;
  877. }
  878. StringName getter = ClassDB::get_property_getter(class_name, F.name);
  879. if (!(getter == "")) {
  880. d2["getter"] = getter;
  881. }
  882. int index = ClassDB::get_property_index(class_name, F.name);
  883. if (index != -1) {
  884. d2["index"] = index;
  885. }
  886. properties.push_back(d2);
  887. }
  888. if (properties.size()) {
  889. d["properties"] = properties;
  890. }
  891. }
  892. classes.push_back(d);
  893. }
  894. api_dump["classes"] = classes;
  895. }
  896. {
  897. // singletons
  898. Array singletons;
  899. List<Engine::Singleton> singleton_list;
  900. Engine::get_singleton()->get_singletons(&singleton_list);
  901. for (const Engine::Singleton &s : singleton_list) {
  902. Dictionary d;
  903. d["name"] = s.name;
  904. if (s.class_name != StringName()) {
  905. d["type"] = String(s.class_name);
  906. } else {
  907. d["type"] = String(s.ptr->get_class());
  908. }
  909. singletons.push_back(d);
  910. }
  911. if (singletons.size()) {
  912. api_dump["singletons"] = singletons;
  913. }
  914. }
  915. {
  916. Array native_structures;
  917. List<StringName> native_structs;
  918. ClassDB::get_native_struct_list(&native_structs);
  919. native_structs.sort_custom<StringName::AlphCompare>();
  920. for (const StringName &E : native_structs) {
  921. String code = ClassDB::get_native_struct_code(E);
  922. Dictionary d;
  923. d["name"] = String(E);
  924. d["format"] = code;
  925. native_structures.push_back(d);
  926. }
  927. api_dump["native_structures"] = native_structures;
  928. }
  929. return api_dump;
  930. }
  931. void GDExtensionAPIDump::generate_extension_json_file(const String &p_path) {
  932. Dictionary api = generate_extension_api();
  933. Ref<JSON> json;
  934. json.instantiate();
  935. String text = json->stringify(api, "\t", false) + "\n";
  936. Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::WRITE);
  937. ERR_FAIL_COND_MSG(fa.is_null(), vformat("Cannot open file '%s' for writing.", p_path));
  938. fa->store_string(text);
  939. }
  940. #endif // TOOLS_ENABLED