extension_api_dump.cpp 40 KB

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