| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#ifdef DEBUG_ENABLED |
| 34 |
|
| 35 |
#include "core/doc_data.h" |
| 36 |
#include "core/object/class_db.h" |
| 37 |
#include "core/string/string_builder.h" |
| 38 |
#include "core/string/ustring.h" |
| 39 |
#include "core/typedefs.h" |
| 40 |
#include "editor/doc/doc_tools.h" |
| 41 |
#include "editor/doc/editor_help.h" |
| 42 |
|
| 43 |
class BindingsGenerator { |
| 44 |
struct ConstantInterface { |
| 45 |
String name; |
| 46 |
String proxy_name; |
| 47 |
int64_t value = 0; |
| 48 |
const DocData::ConstantDoc *const_doc = nullptr; |
| 49 |
|
| 50 |
bool is_deprecated = false; |
| 51 |
String deprecation_message; |
| 52 |
|
| 53 |
ConstantInterface() {} |
| 54 |
|
| 55 |
ConstantInterface(const String &p_name, const String &p_proxy_name, int64_t p_value) { |
| 56 |
name = p_name; |
| 57 |
proxy_name = p_proxy_name; |
| 58 |
value = p_value; |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
struct EnumInterface { |
| 63 |
StringName cname; |
| 64 |
String proxy_name; |
| 65 |
List<ConstantInterface> constants; |
| 66 |
bool is_flags = false; |
| 67 |
|
| 68 |
_FORCE_INLINE_ bool operator==(const EnumInterface &p_ienum) const { |
| 69 |
return p_ienum.cname == cname; |
| 70 |
} |
| 71 |
|
| 72 |
EnumInterface() {} |
| 73 |
|
| 74 |
EnumInterface(const StringName &p_cname, const String &p_proxy_name, bool p_is_flags) { |
| 75 |
cname = p_cname; |
| 76 |
proxy_name = p_proxy_name; |
| 77 |
is_flags = p_is_flags; |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
struct PropertyInterface { |
| 82 |
StringName cname; |
| 83 |
String proxy_name; |
| 84 |
int index = 0; |
| 85 |
|
| 86 |
StringName setter; |
| 87 |
StringName getter; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
bool is_hidden = false; |
| 96 |
|
| 97 |
const DocData::PropertyDoc *prop_doc; |
| 98 |
|
| 99 |
bool is_deprecated = false; |
| 100 |
String deprecation_message; |
| 101 |
}; |
| 102 |
|
| 103 |
struct TypeReference { |
| 104 |
StringName cname; |
| 105 |
bool is_enum = false; |
| 106 |
|
| 107 |
List<TypeReference> generic_type_parameters; |
| 108 |
|
| 109 |
TypeReference() {} |
| 110 |
|
| 111 |
TypeReference(const StringName &p_cname) : |
| 112 |
cname(p_cname) {} |
| 113 |
}; |
| 114 |
|
| 115 |
struct ArgumentInterface { |
| 116 |
enum DefaultParamMode { |
| 117 |
CONSTANT, |
| 118 |
NULLABLE_VAL, |
| 119 |
NULLABLE_REF |
| 120 |
}; |
| 121 |
|
| 122 |
TypeReference type; |
| 123 |
|
| 124 |
String name; |
| 125 |
|
| 126 |
Variant def_param_value; |
| 127 |
DefaultParamMode def_param_mode = CONSTANT; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
String default_argument; |
| 135 |
|
| 136 |
ArgumentInterface() {} |
| 137 |
}; |
| 138 |
|
| 139 |
struct MethodInterface { |
| 140 |
String name; |
| 141 |
StringName cname; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
String proxy_name; |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
uint64_t hash = 0; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
TypeReference return_type; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
bool is_vararg = false; |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
bool is_static = false; |
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
bool is_virtual = false; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
bool requires_object_call = false; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
bool is_internal = false; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
bool is_hidden = false; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
bool is_compat = false; |
| 201 |
|
| 202 |
List<ArgumentInterface> arguments; |
| 203 |
|
| 204 |
const DocData::MethodDoc *method_doc = nullptr; |
| 205 |
|
| 206 |
bool is_deprecated = false; |
| 207 |
String deprecation_message; |
| 208 |
|
| 209 |
void add_argument(const ArgumentInterface &argument) { |
| 210 |
arguments.push_back(argument); |
| 211 |
} |
| 212 |
|
| 213 |
MethodInterface() {} |
| 214 |
}; |
| 215 |
|
| 216 |
struct SignalInterface { |
| 217 |
String name; |
| 218 |
StringName cname; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
String proxy_name; |
| 224 |
|
| 225 |
List<ArgumentInterface> arguments; |
| 226 |
|
| 227 |
const DocData::MethodDoc *method_doc = nullptr; |
| 228 |
|
| 229 |
bool is_deprecated = false; |
| 230 |
String deprecation_message; |
| 231 |
|
| 232 |
void add_argument(const ArgumentInterface &argument) { |
| 233 |
arguments.push_back(argument); |
| 234 |
} |
| 235 |
|
| 236 |
SignalInterface() {} |
| 237 |
}; |
| 238 |
|
| 239 |
struct TypeInterface { |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
String name; |
| 245 |
StringName cname; |
| 246 |
|
| 247 |
int type_parameter_count = 0; |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
StringName base_name; |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
String proxy_name; |
| 258 |
|
| 259 |
ClassDB::APIType api_type = ClassDB::API_NONE; |
| 260 |
|
| 261 |
bool is_enum = false; |
| 262 |
bool is_object_type = false; |
| 263 |
bool is_singleton = false; |
| 264 |
bool is_singleton_instance = false; |
| 265 |
bool is_ref_counted = false; |
| 266 |
bool is_span_compatible = false; |
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
bool is_compat_singleton = false; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
bool c_type_is_disposable_struct = false; |
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
bool c_ret_needs_default_initialization = false; |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
bool is_instantiable = false; |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
bool memory_own = false; |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
String c_in; |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
String c_in_vararg; |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
String c_arg_in = "%s"; |
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
String c_out; |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
String c_type; |
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
String c_type_in; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
String c_type_out; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
String cs_in_expr; |
| 400 |
bool cs_in_expr_is_unsafe = false; |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
String cs_in; |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
String cs_out; |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
String cs_type; |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
String cs_variant_to_managed; |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
String cs_managed_to_variant; |
| 448 |
|
| 449 |
const DocData::ClassDoc *class_doc = nullptr; |
| 450 |
|
| 451 |
bool is_deprecated = false; |
| 452 |
String deprecation_message; |
| 453 |
|
| 454 |
List<ConstantInterface> constants; |
| 455 |
List<EnumInterface> enums; |
| 456 |
List<PropertyInterface> properties; |
| 457 |
List<MethodInterface> methods; |
| 458 |
List<SignalInterface> signals_; |
| 459 |
HashSet<String> ignored_members; |
| 460 |
|
| 461 |
bool has_virtual_methods = false; |
| 462 |
|
| 463 |
const MethodInterface *find_method_by_name(const StringName &p_cname) const { |
| 464 |
for (const MethodInterface &E : methods) { |
| 465 |
if (E.cname == p_cname) { |
| 466 |
return &E; |
| 467 |
} |
| 468 |
} |
| 469 |
|
| 470 |
return nullptr; |
| 471 |
} |
| 472 |
|
| 473 |
const MethodInterface *find_method_by_proxy_name(const String &p_proxy_name) const { |
| 474 |
for (const MethodInterface &E : methods) { |
| 475 |
if (E.proxy_name == p_proxy_name) { |
| 476 |
return &E; |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
return nullptr; |
| 481 |
} |
| 482 |
|
| 483 |
const PropertyInterface *find_property_by_name(const StringName &p_cname) const { |
| 484 |
for (const PropertyInterface &E : properties) { |
| 485 |
if (E.cname == p_cname) { |
| 486 |
return &E; |
| 487 |
} |
| 488 |
} |
| 489 |
|
| 490 |
return nullptr; |
| 491 |
} |
| 492 |
|
| 493 |
const PropertyInterface *find_property_by_proxy_name(const String &p_proxy_name) const { |
| 494 |
for (const PropertyInterface &E : properties) { |
| 495 |
if (E.proxy_name == p_proxy_name) { |
| 496 |
return &E; |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
return nullptr; |
| 501 |
} |
| 502 |
|
| 503 |
const SignalInterface *find_signal_by_name(const StringName &p_cname) const { |
| 504 |
for (const SignalInterface &E : signals_) { |
| 505 |
if (E.cname == p_cname) { |
| 506 |
return &E; |
| 507 |
} |
| 508 |
} |
| 509 |
|
| 510 |
return nullptr; |
| 511 |
} |
| 512 |
|
| 513 |
const SignalInterface *find_signal_by_proxy_name(const String &p_proxy_name) const { |
| 514 |
for (const SignalInterface &E : signals_) { |
| 515 |
if (E.proxy_name == p_proxy_name) { |
| 516 |
return &E; |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
return nullptr; |
| 521 |
} |
| 522 |
|
| 523 |
bool is_intentionally_ignored(const String &p_name) const { |
| 524 |
return ignored_members.has(p_name); |
| 525 |
} |
| 526 |
|
| 527 |
private: |
| 528 |
static DocData::ClassDoc *_get_type_doc(TypeInterface &itype) { |
| 529 |
String doc_name = itype.name.begins_with("_") ? itype.name.substr(1) : itype.name; |
| 530 |
return &EditorHelp::get_doc_data()->class_list[doc_name]; |
| 531 |
} |
| 532 |
|
| 533 |
static void _init_value_type(TypeInterface &itype) { |
| 534 |
if (itype.proxy_name.is_empty()) { |
| 535 |
itype.proxy_name = itype.name; |
| 536 |
} |
| 537 |
|
| 538 |
itype.cs_type = itype.proxy_name; |
| 539 |
itype.c_type = itype.cs_type; |
| 540 |
itype.c_type_in = itype.cs_type + "*"; |
| 541 |
itype.c_type_out = itype.cs_type; |
| 542 |
|
| 543 |
itype.class_doc = _get_type_doc(itype); |
| 544 |
} |
| 545 |
|
| 546 |
static void _init_object_type(TypeInterface &itype, ClassDB::APIType p_api_type) { |
| 547 |
if (itype.proxy_name.is_empty()) { |
| 548 |
itype.proxy_name = itype.name; |
| 549 |
} |
| 550 |
|
| 551 |
if (itype.proxy_name.begins_with("_")) { |
| 552 |
itype.proxy_name = itype.proxy_name.substr(1); |
| 553 |
} |
| 554 |
|
| 555 |
itype.api_type = p_api_type; |
| 556 |
itype.is_object_type = true; |
| 557 |
|
| 558 |
itype.class_doc = _get_type_doc(itype); |
| 559 |
} |
| 560 |
|
| 561 |
public: |
| 562 |
static TypeInterface create_value_type(const String &p_name, const String &p_proxy_name) { |
| 563 |
TypeInterface itype; |
| 564 |
itype.name = p_name; |
| 565 |
itype.cname = p_name; |
| 566 |
itype.proxy_name = p_proxy_name; |
| 567 |
_init_value_type(itype); |
| 568 |
return itype; |
| 569 |
} |
| 570 |
|
| 571 |
static TypeInterface create_value_type(const StringName &p_cname, const String &p_proxy_name) { |
| 572 |
TypeInterface itype; |
| 573 |
itype.name = p_cname; |
| 574 |
itype.cname = p_cname; |
| 575 |
itype.proxy_name = p_proxy_name; |
| 576 |
_init_value_type(itype); |
| 577 |
return itype; |
| 578 |
} |
| 579 |
|
| 580 |
static TypeInterface create_value_type(const String &p_name) { |
| 581 |
TypeInterface itype; |
| 582 |
itype.name = p_name; |
| 583 |
itype.cname = p_name; |
| 584 |
_init_value_type(itype); |
| 585 |
return itype; |
| 586 |
} |
| 587 |
|
| 588 |
static TypeInterface create_value_type(const StringName &p_cname) { |
| 589 |
TypeInterface itype; |
| 590 |
itype.name = p_cname; |
| 591 |
itype.cname = p_cname; |
| 592 |
_init_value_type(itype); |
| 593 |
return itype; |
| 594 |
} |
| 595 |
|
| 596 |
static TypeInterface create_object_type(const StringName &p_cname, const String &p_proxy_name, ClassDB::APIType p_api_type) { |
| 597 |
TypeInterface itype; |
| 598 |
itype.name = p_cname; |
| 599 |
itype.cname = p_cname; |
| 600 |
itype.proxy_name = p_proxy_name; |
| 601 |
_init_object_type(itype, p_api_type); |
| 602 |
return itype; |
| 603 |
} |
| 604 |
|
| 605 |
static TypeInterface create_object_type(const StringName &p_cname, ClassDB::APIType p_api_type) { |
| 606 |
TypeInterface itype; |
| 607 |
itype.name = p_cname; |
| 608 |
itype.cname = p_cname; |
| 609 |
_init_object_type(itype, p_api_type); |
| 610 |
return itype; |
| 611 |
} |
| 612 |
|
| 613 |
static void postsetup_enum_type(TypeInterface &r_enum_itype); |
| 614 |
|
| 615 |
TypeInterface() { |
| 616 |
static String default_cs_variant_to_managed = "VariantUtils.ConvertTo<%1>(%0)"; |
| 617 |
static String default_cs_managed_to_variant = "VariantUtils.CreateFrom<%1>(%0)"; |
| 618 |
cs_variant_to_managed = default_cs_variant_to_managed; |
| 619 |
cs_managed_to_variant = default_cs_managed_to_variant; |
| 620 |
} |
| 621 |
}; |
| 622 |
|
| 623 |
struct InternalCall { |
| 624 |
String name; |
| 625 |
String unique_sig; |
| 626 |
bool editor_only = false; |
| 627 |
|
| 628 |
bool is_vararg = false; |
| 629 |
bool is_static = false; |
| 630 |
TypeReference return_type; |
| 631 |
List<TypeReference> argument_types; |
| 632 |
|
| 633 |
_FORCE_INLINE_ int get_arguments_count() const { return argument_types.size(); } |
| 634 |
|
| 635 |
InternalCall() {} |
| 636 |
|
| 637 |
InternalCall(ClassDB::APIType api_type, const String &p_name, const String &p_unique_sig = String()) { |
| 638 |
name = p_name; |
| 639 |
unique_sig = p_unique_sig; |
| 640 |
editor_only = api_type == ClassDB::API_EDITOR; |
| 641 |
} |
| 642 |
|
| 643 |
inline bool operator==(const InternalCall &p_a) const { |
| 644 |
return p_a.unique_sig == unique_sig; |
| 645 |
} |
| 646 |
}; |
| 647 |
|
| 648 |
bool log_print_enabled = true; |
| 649 |
bool initialized = false; |
| 650 |
|
| 651 |
HashMap<StringName, TypeInterface> obj_types; |
| 652 |
|
| 653 |
HashMap<StringName, TypeInterface> builtin_types; |
| 654 |
HashMap<StringName, TypeInterface> enum_types; |
| 655 |
|
| 656 |
List<EnumInterface> global_enums; |
| 657 |
List<ConstantInterface> global_constants; |
| 658 |
|
| 659 |
List<InternalCall> method_icalls; |
| 660 |
|
| 661 |
HashMap<const MethodInterface *, const InternalCall *> method_icalls_map; |
| 662 |
|
| 663 |
HashMap<StringName, List<StringName>> blacklisted_methods; |
| 664 |
HashSet<StringName> compat_singletons; |
| 665 |
|
| 666 |
void _initialize_blacklisted_methods(); |
| 667 |
void _initialize_compat_singletons(); |
| 668 |
|
| 669 |
struct NameCache { |
| 670 |
StringName type_void = "void"; |
| 671 |
StringName type_Variant = "Variant"; |
| 672 |
StringName type_VarArg = "VarArg"; |
| 673 |
StringName type_Object = "Object"; |
| 674 |
StringName type_RefCounted = "RefCounted"; |
| 675 |
StringName type_RID = "RID"; |
| 676 |
StringName type_Callable = "Callable"; |
| 677 |
StringName type_Signal = "Signal"; |
| 678 |
StringName type_String = "String"; |
| 679 |
StringName type_StringName = "StringName"; |
| 680 |
StringName type_NodePath = "NodePath"; |
| 681 |
StringName type_Array_generic = "Array_@generic"; |
| 682 |
StringName type_Dictionary_generic = "Dictionary_@generic"; |
| 683 |
StringName type_at_GlobalScope = "@GlobalScope"; |
| 684 |
StringName enum_Error = "Error"; |
| 685 |
|
| 686 |
StringName type_sbyte = "sbyte"; |
| 687 |
StringName type_short = "short"; |
| 688 |
StringName type_int = "int"; |
| 689 |
StringName type_byte = "byte"; |
| 690 |
StringName type_ushort = "ushort"; |
| 691 |
StringName type_uint = "uint"; |
| 692 |
StringName type_long = "long"; |
| 693 |
StringName type_ulong = "ulong"; |
| 694 |
|
| 695 |
StringName type_bool = "bool"; |
| 696 |
StringName type_float = "float"; |
| 697 |
StringName type_double = "double"; |
| 698 |
|
| 699 |
StringName type_Vector2 = "Vector2"; |
| 700 |
StringName type_Rect2 = "Rect2"; |
| 701 |
StringName type_Vector3 = "Vector3"; |
| 702 |
StringName type_Vector3i = "Vector3i"; |
| 703 |
StringName type_Vector4 = "Vector4"; |
| 704 |
StringName type_Vector4i = "Vector4i"; |
| 705 |
|
| 706 |
|
| 707 |
static constexpr int nullable_types_count = 19; |
| 708 |
StringName nullable_types[nullable_types_count] = { |
| 709 |
type_String, |
| 710 |
type_StringName, |
| 711 |
type_NodePath, |
| 712 |
|
| 713 |
type_Array_generic, |
| 714 |
type_Dictionary_generic, |
| 715 |
StringName(_STR(Array)), |
| 716 |
StringName(_STR(Dictionary)), |
| 717 |
StringName(_STR(Callable)), |
| 718 |
StringName(_STR(Signal)), |
| 719 |
|
| 720 |
StringName(_STR(PackedByteArray)), |
| 721 |
StringName(_STR(PackedInt32Array)), |
| 722 |
StringName(_STR(PackedInt64Array)), |
| 723 |
StringName(_STR(PackedFloat32Array)), |
| 724 |
StringName(_STR(PackedFloat64Array)), |
| 725 |
StringName(_STR(PackedStringArray)), |
| 726 |
StringName(_STR(PackedVector2Array)), |
| 727 |
StringName(_STR(PackedVector3Array)), |
| 728 |
StringName(_STR(PackedColorArray)), |
| 729 |
StringName(_STR(PackedVector4Array)), |
| 730 |
}; |
| 731 |
|
| 732 |
bool is_nullable_type(const StringName &p_type) const { |
| 733 |
for (int i = 0; i < nullable_types_count; i++) { |
| 734 |
if (p_type == nullable_types[i]) { |
| 735 |
return true; |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
return false; |
| 740 |
} |
| 741 |
|
| 742 |
NameCache() {} |
| 743 |
|
| 744 |
private: |
| 745 |
NameCache(const NameCache &); |
| 746 |
void operator=(const NameCache &); |
| 747 |
}; |
| 748 |
|
| 749 |
NameCache name_cache; |
| 750 |
|
| 751 |
const ConstantInterface *find_constant_by_name(const String &p_name, const List<ConstantInterface> &p_constants) const { |
| 752 |
for (const ConstantInterface &E : p_constants) { |
| 753 |
if (E.name == p_name) { |
| 754 |
return &E; |
| 755 |
} |
| 756 |
} |
| 757 |
|
| 758 |
return nullptr; |
| 759 |
} |
| 760 |
|
| 761 |
inline String get_arg_unique_sig(const TypeInterface &p_type) { |
| 762 |
|
| 763 |
if (p_type.is_object_type) { |
| 764 |
return "Obj"; |
| 765 |
} else if (p_type.is_enum) { |
| 766 |
return "int"; |
| 767 |
} else if (p_type.cname == name_cache.type_Array_generic) { |
| 768 |
return "Array"; |
| 769 |
} else if (p_type.cname == name_cache.type_Dictionary_generic) { |
| 770 |
return "Dictionary"; |
| 771 |
} |
| 772 |
|
| 773 |
return p_type.name; |
| 774 |
} |
| 775 |
|
| 776 |
inline String get_ret_unique_sig(const TypeInterface *p_type) { |
| 777 |
|
| 778 |
if (p_type->is_ref_counted) { |
| 779 |
return "Ref"; |
| 780 |
} else if (p_type->is_object_type) { |
| 781 |
return "Obj"; |
| 782 |
} else if (p_type->is_enum) { |
| 783 |
return "int"; |
| 784 |
} else if (p_type->cname == name_cache.type_Array_generic) { |
| 785 |
return "Array"; |
| 786 |
} else if (p_type->cname == name_cache.type_Dictionary_generic) { |
| 787 |
return "Dictionary"; |
| 788 |
} |
| 789 |
|
| 790 |
return p_type->name; |
| 791 |
} |
| 792 |
|
| 793 |
String bbcode_to_text(const String &p_bbcode, const TypeInterface *p_itype); |
| 794 |
String bbcode_to_xml(const String &p_bbcode, const TypeInterface *p_itype, bool p_is_signal = false); |
| 795 |
|
| 796 |
void _append_text_method(StringBuilder &p_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts); |
| 797 |
void _append_text_member(StringBuilder &p_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts); |
| 798 |
void _append_text_signal(StringBuilder &p_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts); |
| 799 |
void _append_text_enum(StringBuilder &p_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts); |
| 800 |
void _append_text_constant(StringBuilder &p_output, const TypeInterface *p_target_itype, const StringName &p_target_cname, const String &p_link_target, const Vector<String> &p_link_target_parts); |
| 801 |
void _append_text_constant_in_global_scope(StringBuilder &p_output, const String &p_target_cname, const String &p_link_target); |
| 802 |
void _append_text_param(StringBuilder &p_output, const String &p_link_target); |
| 803 |
void _append_text_undeclared(StringBuilder &p_output, const String &p_link_target); |
| 804 |
|
| 805 |
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, const TypeInterface *p_source_itype); |
| 806 |
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, const TypeInterface *p_source_itype); |
| 807 |
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, const TypeInterface *p_source_itype); |
| 808 |
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, const TypeInterface *p_source_itype); |
| 809 |
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); |
| 810 |
void _append_xml_constant_in_global_scope(StringBuilder &p_xml_output, const String &p_target_cname, const String &p_link_target); |
| 811 |
void _append_xml_param(StringBuilder &p_xml_output, const String &p_link_target, bool p_is_signal); |
| 812 |
void _append_xml_undeclared(StringBuilder &p_xml_output, const String &p_link_target); |
| 813 |
|
| 814 |
bool _validate_api_type(const TypeInterface *p_target_itype, const TypeInterface *p_source_itype); |
| 815 |
|
| 816 |
int _determine_enum_prefix(const EnumInterface &p_ienum); |
| 817 |
void _apply_prefix_to_enum_constants(EnumInterface &p_ienum, int p_prefix_length); |
| 818 |
|
| 819 |
Error _populate_method_icalls_table(const TypeInterface &p_itype); |
| 820 |
|
| 821 |
const TypeInterface *_get_type_or_null(const TypeReference &p_typeref); |
| 822 |
const TypeInterface *_get_type_or_singleton_or_null(const TypeReference &p_typeref); |
| 823 |
|
| 824 |
const String _get_generic_type_parameters(const TypeInterface &p_itype, const List<TypeReference> &p_generic_type_parameters); |
| 825 |
|
| 826 |
StringName _get_type_name_from_meta(Variant::Type p_type, GodotTypeInfo::Metadata p_meta); |
| 827 |
StringName _get_int_type_name_from_meta(GodotTypeInfo::Metadata p_meta); |
| 828 |
StringName _get_float_type_name_from_meta(GodotTypeInfo::Metadata p_meta); |
| 829 |
|
| 830 |
bool _arg_default_value_from_variant(const Variant &p_val, ArgumentInterface &r_iarg); |
| 831 |
bool _arg_default_value_is_assignable_to_type(const Variant &p_val, const TypeInterface &p_arg_type); |
| 832 |
|
| 833 |
bool _populate_object_type_interfaces(); |
| 834 |
void _populate_builtin_type_interfaces(); |
| 835 |
|
| 836 |
void _populate_global_constants(); |
| 837 |
|
| 838 |
bool _method_has_conflicting_signature(const MethodInterface &p_imethod, const TypeInterface &p_itype); |
| 839 |
bool _method_has_conflicting_signature(const MethodInterface &p_imethod_left, const MethodInterface &p_imethod_right); |
| 840 |
|
| 841 |
Error _generate_cs_type(const TypeInterface &itype, const String &p_output_file); |
| 842 |
|
| 843 |
Error _generate_cs_property(const TypeInterface &p_itype, const PropertyInterface &p_iprop, StringBuilder &p_output); |
| 844 |
Error _generate_cs_method(const TypeInterface &p_itype, const MethodInterface &p_imethod, int &p_method_bind_count, StringBuilder &p_output, bool p_use_span); |
| 845 |
Error _generate_cs_signal(const BindingsGenerator::TypeInterface &p_itype, const BindingsGenerator::SignalInterface &p_isignal, StringBuilder &p_output); |
| 846 |
|
| 847 |
Error _generate_cs_native_calls(const InternalCall &p_icall, StringBuilder &r_output); |
| 848 |
|
| 849 |
void _generate_array_extensions(StringBuilder &p_output); |
| 850 |
void _generate_global_constants(StringBuilder &p_output); |
| 851 |
|
| 852 |
Error _save_file(const String &p_path, const StringBuilder &p_content); |
| 853 |
|
| 854 |
void _log(const char *p_format, ...) _PRINTF_FORMAT_ATTRIBUTE_2_3; |
| 855 |
|
| 856 |
void _initialize(); |
| 857 |
|
| 858 |
public: |
| 859 |
Error generate_cs_core_project(const String &p_proj_dir); |
| 860 |
Error generate_cs_editor_project(const String &p_proj_dir); |
| 861 |
Error generate_cs_api(const String &p_output_dir); |
| 862 |
|
| 863 |
_FORCE_INLINE_ bool is_log_print_enabled() { return log_print_enabled; } |
| 864 |
_FORCE_INLINE_ void set_log_print_enabled(bool p_enabled) { log_print_enabled = p_enabled; } |
| 865 |
|
| 866 |
_FORCE_INLINE_ bool is_initialized() { return initialized; } |
| 867 |
|
| 868 |
static void handle_cmdline_args(const List<String> &p_cmdline_args); |
| 869 |
|
| 870 |
BindingsGenerator() { |
| 871 |
_initialize(); |
| 872 |
} |
| 873 |
}; |
| 874 |
|
| 875 |
#endif |