2
0

bindings_generator.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*************************************************************************/
  2. /* bindings_generator.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 BINDINGS_GENERATOR_H
  31. #define BINDINGS_GENERATOR_H
  32. #include "core/doc_data.h"
  33. #include "core/object/class_db.h"
  34. #include "core/string/string_builder.h"
  35. #include "editor/doc_tools.h"
  36. #include "editor/editor_help.h"
  37. #if defined(DEBUG_METHODS_ENABLED) && defined(TOOLS_ENABLED)
  38. #include "core/string/ustring.h"
  39. class BindingsGenerator {
  40. struct ConstantInterface {
  41. String name;
  42. String proxy_name;
  43. int64_t value = 0;
  44. const DocData::ConstantDoc *const_doc;
  45. ConstantInterface() {}
  46. ConstantInterface(const String &p_name, const String &p_proxy_name, int64_t p_value) {
  47. name = p_name;
  48. proxy_name = p_proxy_name;
  49. value = p_value;
  50. }
  51. };
  52. struct EnumInterface {
  53. StringName cname;
  54. List<ConstantInterface> constants;
  55. bool is_flags = false;
  56. _FORCE_INLINE_ bool operator==(const EnumInterface &p_ienum) const {
  57. return p_ienum.cname == cname;
  58. }
  59. EnumInterface() {}
  60. EnumInterface(const StringName &p_cname) {
  61. cname = p_cname;
  62. }
  63. };
  64. struct PropertyInterface {
  65. StringName cname;
  66. String proxy_name;
  67. int index = 0;
  68. StringName setter;
  69. StringName getter;
  70. const DocData::PropertyDoc *prop_doc;
  71. };
  72. struct TypeReference {
  73. StringName cname;
  74. bool is_enum = false;
  75. List<TypeReference> generic_type_parameters;
  76. TypeReference() {}
  77. TypeReference(const StringName &p_cname) :
  78. cname(p_cname) {}
  79. };
  80. struct ArgumentInterface {
  81. enum DefaultParamMode {
  82. CONSTANT,
  83. NULLABLE_VAL,
  84. NULLABLE_REF
  85. };
  86. TypeReference type;
  87. String name;
  88. Variant def_param_value;
  89. DefaultParamMode def_param_mode = CONSTANT;
  90. /**
  91. * Determines the expression for the parameter default value.
  92. * Formatting elements:
  93. * %0 or %s: [cs_type] of the argument type
  94. */
  95. String default_argument;
  96. ArgumentInterface() {}
  97. };
  98. struct MethodInterface {
  99. String name;
  100. StringName cname;
  101. /**
  102. * Name of the C# method
  103. */
  104. String proxy_name;
  105. /**
  106. * [TypeInterface::name] of the return type
  107. */
  108. TypeReference return_type;
  109. /**
  110. * Determines if the method has a variable number of arguments (VarArg)
  111. */
  112. bool is_vararg = false;
  113. /**
  114. * Determines if the method is static.
  115. */
  116. bool is_static = false;
  117. /**
  118. * Virtual methods ("virtual" as defined by the Godot API) are methods that by default do nothing,
  119. * but can be overridden by the user to add custom functionality.
  120. * e.g.: _ready, _process, etc.
  121. */
  122. bool is_virtual = false;
  123. /**
  124. * Determines if the call should fallback to Godot's object.Call(string, params) in C#.
  125. */
  126. bool requires_object_call = false;
  127. /**
  128. * Determines if the method visibility is 'internal' (visible only to files in the same assembly).
  129. * Currently, we only use this for methods that are not meant to be exposed,
  130. * but are required by properties as getters or setters.
  131. * Methods that are not meant to be exposed are those that begin with underscore and are not virtual.
  132. */
  133. bool is_internal = false;
  134. List<ArgumentInterface> arguments;
  135. const DocData::MethodDoc *method_doc = nullptr;
  136. bool is_deprecated = false;
  137. String deprecation_message;
  138. void add_argument(const ArgumentInterface &argument) {
  139. arguments.push_back(argument);
  140. }
  141. MethodInterface() {}
  142. };
  143. struct SignalInterface {
  144. String name;
  145. StringName cname;
  146. /**
  147. * Name of the C# method
  148. */
  149. String proxy_name;
  150. List<ArgumentInterface> arguments;
  151. const DocData::MethodDoc *method_doc = nullptr;
  152. bool is_deprecated = false;
  153. String deprecation_message;
  154. void add_argument(const ArgumentInterface &argument) {
  155. arguments.push_back(argument);
  156. }
  157. SignalInterface() {}
  158. };
  159. struct TypeInterface {
  160. /**
  161. * Identifier name for this type.
  162. * Also used to format [c_out].
  163. */
  164. String name;
  165. StringName cname;
  166. int type_parameter_count;
  167. /**
  168. * Identifier name of the base class.
  169. */
  170. StringName base_name;
  171. /**
  172. * Name of the C# class
  173. */
  174. String proxy_name;
  175. ClassDB::APIType api_type = ClassDB::API_NONE;
  176. bool is_enum = false;
  177. bool is_object_type = false;
  178. bool is_singleton = false;
  179. bool is_ref_counted = false;
  180. /**
  181. * Used only by Object-derived types.
  182. * Determines if this type is not abstract (incomplete).
  183. * e.g.: CanvasItem cannot be instantiated.
  184. */
  185. bool is_instantiable = false;
  186. /**
  187. * Used only by Object-derived types.
  188. * Determines if the C# class owns the native handle and must free it somehow when disposed.
  189. * e.g.: RefCounted types must notify when the C# instance is disposed, for proper refcounting.
  190. */
  191. bool memory_own = false;
  192. /**
  193. * This must be set to true for any struct bigger than 32-bits. Those cannot be passed/returned by value
  194. * with internal calls, so we must use pointers instead. Returns must be replace with out parameters.
  195. * In this case, [c_out] and [cs_out] must have a different format, explained below.
  196. * The Mono IL interpreter icall trampolines don't support passing structs bigger than 32-bits by value (at least not on WASM).
  197. */
  198. bool ret_as_byref_arg = false;
  199. // !! The comments of the following fields make reference to other fields via square brackets, e.g.: [field_name]
  200. // !! When renaming those fields, make sure to rename their references in the comments
  201. // --- C INTERFACE ---
  202. static const char *DEFAULT_VARARG_C_IN;
  203. /**
  204. * One or more statements that manipulate the parameter before being passed as argument of a ptrcall.
  205. * If the statement adds a local that must be passed as the argument instead of the parameter,
  206. * the name of that local must be specified with [c_arg_in].
  207. * For variadic methods, this field is required and, if empty, [DEFAULT_VARARG_C_IN] is used instead.
  208. * Formatting elements:
  209. * %0: [c_type] of the parameter
  210. * %1: name of the parameter
  211. */
  212. String c_in;
  213. /**
  214. * Determines the expression that will be passed as argument to ptrcall.
  215. * By default the value equals the name of the parameter,
  216. * this varies for types that require special manipulation via [c_in].
  217. * Formatting elements:
  218. * %0 or %s: name of the parameter
  219. */
  220. String c_arg_in = "%s";
  221. /**
  222. * One or more statements that determine how a variable of this type is returned from a function.
  223. * It must contain the return statement(s).
  224. * Formatting elements:
  225. * %0: [c_type_out] of the return type
  226. * %1: name of the variable to be returned
  227. * %2: [name] of the return type
  228. * ---------------------------------------
  229. * If [ret_as_byref_arg] is true, the format is different. Instead of using a return statement,
  230. * the value must be assigned to a parameter. This type of this parameter is a pointer to [c_type_out].
  231. * Formatting elements:
  232. * %0: [c_type_out] of the return type
  233. * %1: name of the variable to be returned
  234. * %2: [name] of the return type
  235. * %3: name of the parameter that must be assigned the return value
  236. */
  237. String c_out;
  238. /**
  239. * The actual expected type, as seen (in most cases) in Variant copy constructors
  240. * Used for the type of the return variable and to format [c_in].
  241. * The value must be the following depending of the type:
  242. * Object-derived types: Object*
  243. * Other types: [name]
  244. * -- Exceptions --
  245. * VarArg (fictitious type to represent variable arguments): Array
  246. * float: double (because ptrcall only supports double)
  247. * int: int64_t (because ptrcall only supports int64_t and uint64_t)
  248. * RefCounted types override this for the type of the return variable: Ref<RefCounted>
  249. */
  250. String c_type;
  251. /**
  252. * Determines the type used for parameters in function signatures.
  253. */
  254. String c_type_in;
  255. /**
  256. * Determines the return type used for function signatures.
  257. * Also used to construct a default value to return in case of errors,
  258. * and to format [c_out].
  259. */
  260. String c_type_out;
  261. // --- C# INTERFACE ---
  262. /**
  263. * An expression that overrides the way the parameter is passed to the internal call.
  264. * If empty, the parameter is passed as is.
  265. * Formatting elements:
  266. * %0 or %s: name of the parameter
  267. */
  268. String cs_in;
  269. /**
  270. * One or more statements that determine how a variable of this type is returned from a method.
  271. * It must contain the return statement(s).
  272. * Formatting elements:
  273. * %0: internal method name
  274. * %1: internal method call arguments without surrounding parenthesis
  275. * %2: [cs_type] of the return type
  276. * %3: [im_type_out] of the return type
  277. */
  278. String cs_out;
  279. /**
  280. * Type used for method signatures, both for parameters and the return type.
  281. * Same as [proxy_name] except for variable arguments (VarArg) and collections (which include the namespace).
  282. */
  283. String cs_type;
  284. /**
  285. * Type used for parameters of internal call methods.
  286. */
  287. String im_type_in;
  288. /**
  289. * Type used for the return type of internal call methods.
  290. */
  291. String im_type_out;
  292. const DocData::ClassDoc *class_doc = nullptr;
  293. List<ConstantInterface> constants;
  294. List<EnumInterface> enums;
  295. List<PropertyInterface> properties;
  296. List<MethodInterface> methods;
  297. List<SignalInterface> signals_;
  298. const MethodInterface *find_method_by_name(const StringName &p_cname) const {
  299. for (const MethodInterface &E : methods) {
  300. if (E.cname == p_cname) {
  301. return &E;
  302. }
  303. }
  304. return nullptr;
  305. }
  306. const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const {
  307. for (const MethodInterface &E : methods) {
  308. if (E.proxy_name == p_proxy_name) {
  309. return &E;
  310. }
  311. }
  312. return nullptr;
  313. }
  314. const PropertyInterface *find_property_by_name(const StringName &p_cname) const {
  315. for (const PropertyInterface &E : properties) {
  316. if (E.cname == p_cname) {
  317. return &E;
  318. }
  319. }
  320. return nullptr;
  321. }
  322. const PropertyInterface *find_property_by_proxy_name(const String &p_proxy_name) const {
  323. for (const PropertyInterface &E : properties) {
  324. if (E.proxy_name == p_proxy_name) {
  325. return &E;
  326. }
  327. }
  328. return nullptr;
  329. }
  330. const SignalInterface *find_signal_by_name(const StringName &p_cname) const {
  331. for (const SignalInterface &E : signals_) {
  332. if (E.cname == p_cname) {
  333. return &E;
  334. }
  335. }
  336. return nullptr;
  337. }
  338. const SignalInterface *find_signal_by_proxy_name(const String &p_proxy_name) const {
  339. for (const SignalInterface &E : signals_) {
  340. if (E.proxy_name == p_proxy_name) {
  341. return &E;
  342. }
  343. }
  344. return nullptr;
  345. }
  346. private:
  347. static void _init_value_type(TypeInterface &itype) {
  348. itype.proxy_name = itype.name;
  349. itype.c_type = itype.name;
  350. itype.cs_type = itype.proxy_name;
  351. itype.im_type_in = "ref " + itype.proxy_name;
  352. itype.im_type_out = itype.proxy_name;
  353. itype.class_doc = &EditorHelp::get_doc_data()->class_list[itype.proxy_name];
  354. }
  355. public:
  356. static TypeInterface create_value_type(const String &p_name) {
  357. TypeInterface itype;
  358. itype.name = p_name;
  359. itype.cname = StringName(p_name);
  360. _init_value_type(itype);
  361. return itype;
  362. }
  363. static TypeInterface create_value_type(const StringName &p_name) {
  364. TypeInterface itype;
  365. itype.name = p_name.operator String();
  366. itype.cname = p_name;
  367. _init_value_type(itype);
  368. return itype;
  369. }
  370. static TypeInterface create_object_type(const StringName &p_cname, ClassDB::APIType p_api_type) {
  371. TypeInterface itype;
  372. itype.name = p_cname;
  373. itype.cname = p_cname;
  374. itype.proxy_name = itype.name.begins_with("_") ? itype.name.substr(1, itype.name.length()) : itype.name;
  375. itype.api_type = p_api_type;
  376. itype.is_object_type = true;
  377. itype.class_doc = &EditorHelp::get_doc_data()->class_list[itype.proxy_name];
  378. return itype;
  379. }
  380. static void create_placeholder_type(TypeInterface &r_itype, const StringName &p_cname) {
  381. r_itype.name = p_cname;
  382. r_itype.cname = p_cname;
  383. r_itype.proxy_name = r_itype.name;
  384. r_itype.c_type = r_itype.name;
  385. r_itype.c_type_in = "MonoObject*";
  386. r_itype.c_type_out = "MonoObject*";
  387. r_itype.cs_type = r_itype.proxy_name;
  388. r_itype.im_type_in = r_itype.proxy_name;
  389. r_itype.im_type_out = r_itype.proxy_name;
  390. }
  391. static void postsetup_enum_type(TypeInterface &r_enum_itype) {
  392. // C interface for enums is the same as that of 'uint32_t'. Remember to apply
  393. // any of the changes done here to the 'uint32_t' type interface as well.
  394. r_enum_itype.c_arg_in = "&%s_in";
  395. {
  396. // The expected types for parameters and return value in ptrcall are 'int64_t' or 'uint64_t'.
  397. r_enum_itype.c_in = "\t%0 %1_in = (%0)%1;\n";
  398. r_enum_itype.c_out = "\treturn (%0)%1;\n";
  399. r_enum_itype.c_type = "int64_t";
  400. }
  401. r_enum_itype.c_type_in = "int32_t";
  402. r_enum_itype.c_type_out = r_enum_itype.c_type_in;
  403. r_enum_itype.cs_type = r_enum_itype.proxy_name;
  404. r_enum_itype.cs_in = "(int)%s";
  405. r_enum_itype.cs_out = "return (%2)%0(%1);";
  406. r_enum_itype.im_type_in = "int";
  407. r_enum_itype.im_type_out = "int";
  408. r_enum_itype.class_doc = &EditorHelp::get_doc_data()->class_list[r_enum_itype.proxy_name];
  409. }
  410. TypeInterface() {}
  411. };
  412. struct InternalCall {
  413. String name;
  414. String im_type_out; // Return type for the C# method declaration. Also used as companion of [unique_siq]
  415. String im_sig; // Signature for the C# method declaration
  416. String unique_sig; // Unique signature to avoid duplicates in containers
  417. bool editor_only = false;
  418. InternalCall() {}
  419. InternalCall(const String &p_name, const String &p_im_type_out, const String &p_im_sig = String(), const String &p_unique_sig = String()) {
  420. name = p_name;
  421. im_type_out = p_im_type_out;
  422. im_sig = p_im_sig;
  423. unique_sig = p_unique_sig;
  424. editor_only = false;
  425. }
  426. InternalCall(ClassDB::APIType api_type, const String &p_name, const String &p_im_type_out, const String &p_im_sig = String(), const String &p_unique_sig = String()) {
  427. name = p_name;
  428. im_type_out = p_im_type_out;
  429. im_sig = p_im_sig;
  430. unique_sig = p_unique_sig;
  431. editor_only = api_type == ClassDB::API_EDITOR;
  432. }
  433. inline bool operator==(const InternalCall &p_a) const {
  434. return p_a.unique_sig == unique_sig;
  435. }
  436. };
  437. bool log_print_enabled = true;
  438. bool initialized = false;
  439. HashMap<StringName, TypeInterface> obj_types;
  440. HashMap<StringName, TypeInterface> placeholder_types;
  441. HashMap<StringName, TypeInterface> builtin_types;
  442. HashMap<StringName, TypeInterface> enum_types;
  443. List<EnumInterface> global_enums;
  444. List<ConstantInterface> global_constants;
  445. List<InternalCall> method_icalls;
  446. HashMap<const MethodInterface *, const InternalCall *> method_icalls_map;
  447. List<const InternalCall *> generated_icall_funcs;
  448. List<InternalCall> core_custom_icalls;
  449. List<InternalCall> editor_custom_icalls;
  450. HashMap<StringName, List<StringName>> blacklisted_methods;
  451. void _initialize_blacklisted_methods();
  452. struct NameCache {
  453. StringName type_void = StaticCString::create("void");
  454. StringName type_Variant = StaticCString::create("Variant");
  455. StringName type_VarArg = StaticCString::create("VarArg");
  456. StringName type_Object = StaticCString::create("Object");
  457. StringName type_RefCounted = StaticCString::create("RefCounted");
  458. StringName type_RID = StaticCString::create("RID");
  459. StringName type_Callable = StaticCString::create("Callable");
  460. StringName type_Signal = StaticCString::create("Signal");
  461. StringName type_String = StaticCString::create("String");
  462. StringName type_StringName = StaticCString::create("StringName");
  463. StringName type_NodePath = StaticCString::create("NodePath");
  464. StringName type_at_GlobalScope = StaticCString::create("@GlobalScope");
  465. StringName enum_Error = StaticCString::create("Error");
  466. StringName type_sbyte = StaticCString::create("sbyte");
  467. StringName type_short = StaticCString::create("short");
  468. StringName type_int = StaticCString::create("int");
  469. StringName type_byte = StaticCString::create("byte");
  470. StringName type_ushort = StaticCString::create("ushort");
  471. StringName type_uint = StaticCString::create("uint");
  472. StringName type_long = StaticCString::create("long");
  473. StringName type_ulong = StaticCString::create("ulong");
  474. StringName type_bool = StaticCString::create("bool");
  475. StringName type_float = StaticCString::create("float");
  476. StringName type_double = StaticCString::create("double");
  477. StringName type_Vector2 = StaticCString::create("Vector2");
  478. StringName type_Rect2 = StaticCString::create("Rect2");
  479. StringName type_Vector3 = StaticCString::create("Vector3");
  480. StringName type_Vector3i = StaticCString::create("Vector3i");
  481. StringName type_Vector4 = StaticCString::create("Vector4");
  482. StringName type_Vector4i = StaticCString::create("Vector4i");
  483. // Object not included as it must be checked for all derived classes
  484. static constexpr int nullable_types_count = 17;
  485. StringName nullable_types[nullable_types_count] = {
  486. type_String,
  487. type_StringName,
  488. type_NodePath,
  489. StaticCString::create(_STR(Array)),
  490. StaticCString::create(_STR(Dictionary)),
  491. StaticCString::create(_STR(Callable)),
  492. StaticCString::create(_STR(Signal)),
  493. StaticCString::create(_STR(PackedByteArray)),
  494. StaticCString::create(_STR(PackedInt32Array)),
  495. StaticCString::create(_STR(PackedInt64Array)),
  496. StaticCString::create(_STR(PackedFloat32Array)),
  497. StaticCString::create(_STR(PackedFloat64Array)),
  498. StaticCString::create(_STR(PackedStringArray)),
  499. StaticCString::create(_STR(PackedVector2Array)),
  500. StaticCString::create(_STR(PackedVector3Array)),
  501. StaticCString::create(_STR(PackedColorArray)),
  502. };
  503. bool is_nullable_type(const StringName &p_type) const {
  504. for (int i = 0; i < nullable_types_count; i++) {
  505. if (p_type == nullable_types[i]) {
  506. return true;
  507. }
  508. }
  509. return false;
  510. }
  511. NameCache() {}
  512. private:
  513. NameCache(const NameCache &);
  514. void operator=(const NameCache &);
  515. };
  516. NameCache name_cache;
  517. const List<InternalCall>::Element *find_icall_by_name(const String &p_name, const List<InternalCall> &p_list) {
  518. const List<InternalCall>::Element *it = p_list.front();
  519. while (it) {
  520. if (it->get().name == p_name) {
  521. return it;
  522. }
  523. it = it->next();
  524. }
  525. return nullptr;
  526. }
  527. const ConstantInterface *find_constant_by_name(const String &p_name, const List<ConstantInterface> &p_constants) const {
  528. for (const ConstantInterface &E : p_constants) {
  529. if (E.name == p_name) {
  530. return &E;
  531. }
  532. }
  533. return nullptr;
  534. }
  535. inline String get_unique_sig(const TypeInterface &p_type) {
  536. if (p_type.is_ref_counted) {
  537. return "Ref";
  538. } else if (p_type.is_object_type) {
  539. return "Obj";
  540. } else if (p_type.is_enum) {
  541. return "int";
  542. }
  543. return p_type.name;
  544. }
  545. String bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype);
  546. void _append_xml_method(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
  547. void _append_xml_member(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
  548. void _append_xml_signal(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
  549. void _append_xml_enum(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
  550. void _append_xml_constant(StringBuilder &p_xml_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts);
  551. void _append_xml_constant_in_global_scope(StringBuilder &p_xml_output, const String &p_target_cname, const String &p_link_target);
  552. void _append_xml_undeclared(StringBuilder &p_xml_output, const String &p_link_target);
  553. int _determine_enum_prefix(const EnumInterface &p_ienum);
  554. void _apply_prefix_to_enum_constants(EnumInterface &p_ienum, int p_prefix_length);
  555. void _generate_method_icalls(const TypeInterface &p_itype);
  556. const TypeInterface *_get_type_or_null(const TypeReference &p_typeref);
  557. const TypeInterface *_get_type_or_placeholder(const TypeReference &p_typeref);
  558. const String _get_generic_type_parameters(const TypeInterface &p_itype, const List<TypeReference> &p_generic_type_parameters);
  559. StringName _get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta);
  560. StringName _get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta);
  561. bool _arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg);
  562. bool _arg_default_value_is_assignable_to_type(const Variant &p_val, const TypeInterface &p_arg_type);
  563. bool _populate_object_type_interfaces();
  564. void _populate_builtin_type_interfaces();
  565. void _populate_global_constants();
  566. Error _generate_cs_type(const TypeInterface &itype, const String &p_output_file);
  567. Error _generate_cs_property(const TypeInterface &p_itype, const PropertyInterface &p_iprop, StringBuilder &p_output);
  568. Error _generate_cs_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, int &p_method_bind_count, StringBuilder &p_output);
  569. Error _generate_cs_signal(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::SignalInterface &p_isignal, StringBuilder &p_output);
  570. void _generate_array_extensions(StringBuilder &p_output);
  571. void _generate_global_constants(StringBuilder &p_output);
  572. Error _generate_glue_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, StringBuilder &p_output);
  573. Error _save_file(const String &p_path, const StringBuilder &p_content);
  574. void _log(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3;
  575. void _initialize();
  576. public:
  577. Error generate_cs_core_project(const String &p_proj_dir);
  578. Error generate_cs_editor_project(const String &p_proj_dir);
  579. Error generate_cs_api(const String &p_output_dir);
  580. Error generate_glue(const String &p_output_dir);
  581. _FORCE_INLINE_ bool is_log_print_enabled() { return log_print_enabled; }
  582. _FORCE_INLINE_ void set_log_print_enabled(bool p_enabled) { log_print_enabled = p_enabled; }
  583. _FORCE_INLINE_ bool is_initialized() { return initialized; }
  584. static uint32_t get_version();
  585. static void handle_cmdline_args(const List<String> &p_cmdline_args);
  586. BindingsGenerator() {
  587. _initialize();
  588. }
  589. };
  590. #endif
  591. #endif // BINDINGS_GENERATOR_H