Blender V5.3
makesrna.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <cerrno>
11#include <cfloat>
12#include <cinttypes>
13#include <climits>
14#include <cmath>
15#include <cstdio>
16#include <cstdlib>
17#include <cstring>
18#include <limits>
19#include <sstream>
20
21#include "MEM_guardedalloc.h"
22
23#include "BLI_listbase.hh"
24#include "BLI_string.hh"
25#include "BLI_system.hh" /* For #BLI_system_backtrace stub. */
26#include "BLI_utildefines.hh"
27#include "BLI_vector_set.hh"
28
29#include "RNA_define.hh"
30#include "RNA_enum_types.hh"
31#include "RNA_types.hh"
32
33#include "dna_parse.h"
34
35#include "makesrna_utils.hh"
36#include "rna_internal.hh"
37
38#include "CLG_log.h"
39
40namespace blender {
41
42static CLG_LogRef LOG = {"makesrna"};
43
50static int debugSRNA = 0;
51
52/* stub for BLI_abort() */
53#ifndef NDEBUG
54void BLI_system_backtrace(FILE *fp)
55{
56 (void)fp;
57}
58#endif /* !NDEBUG */
59
60/* Replace if different */
61#define TMP_EXT ".tmp"
62
63/* copied from BLI_file_older */
64#include <sys/stat.h>
65static bool file_older(const char *file1, const char *file2)
66{
67 struct stat st1, st2;
68 if (debugSRNA > 0) {
69 printf("compare: %s %s\n", file1, file2);
70 }
71
72 if (stat(file1, &st1)) {
73 return false;
74 }
75 if (stat(file2, &st2)) {
76 return false;
77 }
78
79 return (st1.st_mtime < st2.st_mtime);
80}
81static const char *makesrna_path = nullptr;
82
83static const char *path_basename(const char *path)
84{
85 const char *lfslash, *lbslash;
86
87 lfslash = strrchr(path, '/');
88 lbslash = strrchr(path, '\\');
89 if (lbslash) {
90 lbslash++;
91 }
92 if (lfslash) {
93 lfslash++;
94 }
95
96 return std::max({path, lfslash, lbslash});
97}
98
99/* forward declarations */
101 StructRNA *srna,
102 FunctionDefRNA *dfunc,
103 const char *name_override,
104 int close_prototype);
105
106/* helpers */
107#define WRITE_COMMA \
108 { \
109 if (!first) { \
110 fprintf(f, ", "); \
111 } \
112 first = 0; \
113 } \
114 (void)0
115
116#define WRITE_PARAM(param) \
117 { \
118 WRITE_COMMA; \
119 fprintf(f, param); \
120 } \
121 (void)0
122
126static int replace_if_different(const char *tmpfile, const char *dep_files[])
127{
128
129#ifdef USE_MAKEFILE_WORKAROUND
130 const bool use_makefile_workaround = true;
131#else
132 const bool use_makefile_workaround = false;
133#endif
134
135 /* Use for testing hand edited `rna_*_gen.c` files. */
136 // return 0;
137
138#define REN_IF_DIFF \
139 { \
140 FILE *file_test = fopen(orgfile, "rb"); \
141 if (file_test) { \
142 fclose(file_test); \
143 if (fp_org) { \
144 fclose(fp_org); \
145 } \
146 if (fp_new) { \
147 fclose(fp_new); \
148 } \
149 if (remove(orgfile) != 0) { \
150 CLOG_ERROR(&LOG, "remove error (%s): \"%s\"", strerror(errno), orgfile); \
151 return -1; \
152 } \
153 } \
154 } \
155 if (rename(tmpfile, orgfile) != 0) { \
156 CLOG_ERROR(&LOG, "rename error (%s): \"%s\" -> \"%s\"", strerror(errno), tmpfile, orgfile); \
157 return -1; \
158 } \
159 remove(tmpfile); \
160 return 1; \
161 ((void)0)
162 /* End `REN_IF_DIFF`. */
163
164 FILE *fp_new = nullptr, *fp_org = nullptr;
165 int len_new, len_org;
166 char *arr_new, *arr_org;
167 int cmp;
168
169 const char *makesrna_source_filepath = __FILE__;
170 const char *makesrna_source_filename = path_basename(makesrna_source_filepath);
171
172 char orgfile[4096];
173
174 const size_t orgfile_len = STRNCPY_RLEN(orgfile, tmpfile);
175 orgfile[orgfile_len - strlen(TMP_EXT)] = '\0'; /* Strip `.tmp`. */
176
177 fp_org = fopen(orgfile, "rb");
178
179 if (fp_org == nullptr) {
181 }
182
183 /* NOTE(@ideasman42): trick to work around dependency problem.
184 * The issue is as follows: When `makesrna.cc` or any of the `rna_*.c` files being newer than
185 * their generated output, the build-system detects that the `rna_*_gen.c` file is out-dated and
186 * requests the `rna_*_gen.c` files are re-generated (even if this function always returns 0).
187 * It happens *every* rebuild, slowing incremental builds which isn't practical for development.
188 *
189 * This is only an issue for `Unix Makefiles`, `Ninja` generator doesn't have this problem.
190 *
191 * CMake will set `use_makefile_workaround` to 0 or 1 depending on the generator used. */
192
193 if (use_makefile_workaround) {
194 /* First check if `makesrna.cc` is newer than generated files.
195 * For development on `makesrna.cc` you may want to disable this. */
196 if (file_older(orgfile, makesrna_source_filepath)) {
198 }
199
200 if (file_older(orgfile, makesrna_path)) {
202 }
203
204 /* Now check if any files we depend on are newer than any generated files. */
205 if (dep_files) {
206 int pass;
207 for (pass = 0; dep_files[pass]; pass++) {
208 char from_path[4096];
209 /* Only the directory (base-name). */
210 SNPRINTF(from_path,
211 "%.*s%s",
212 int(makesrna_source_filename - makesrna_source_filepath),
213 makesrna_source_filepath,
214 dep_files[pass]);
215 /* Account for build dependencies, if `makesrna.cc` (this file) is newer. */
216 if (file_older(orgfile, from_path)) {
218 }
219 }
220 }
221 }
222 /* XXX end dep trick */
223
224 fp_new = fopen(tmpfile, "rb");
225
226 if (fp_new == nullptr) {
227 /* Shouldn't happen, just to be safe. */
228 CLOG_ERROR(&LOG, "open error: \"%s\"", tmpfile);
229 fclose(fp_org);
230 return -1;
231 }
232
233 fseek(fp_new, 0L, SEEK_END);
234 len_new = ftell(fp_new);
235 fseek(fp_new, 0L, SEEK_SET);
236 fseek(fp_org, 0L, SEEK_END);
237 len_org = ftell(fp_org);
238 fseek(fp_org, 0L, SEEK_SET);
239
240 if (len_new != len_org) {
241 fclose(fp_new);
242 fp_new = nullptr;
243 fclose(fp_org);
244 fp_org = nullptr;
246 }
247
248 /* Now compare the files: */
249 arr_new = MEM_new_array_uninitialized<char>(size_t(len_new), "rna_cmp_file_new");
250 arr_org = MEM_new_array_uninitialized<char>(size_t(len_org), "rna_cmp_file_org");
251
252 if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new) {
253 CLOG_ERROR(&LOG, "unable to read file %s for comparison.", tmpfile);
254 }
255 if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org) {
256 CLOG_ERROR(&LOG, "unable to read file %s for comparison.", orgfile);
257 }
258
259 fclose(fp_new);
260 fp_new = nullptr;
261 fclose(fp_org);
262 fp_org = nullptr;
263
264 cmp = memcmp(arr_new, arr_org, len_new);
265
266 MEM_delete(arr_new);
267 MEM_delete(arr_org);
268
269 if (cmp) {
271 }
272 remove(tmpfile);
273 return 0;
274
275#undef REN_IF_DIFF
276}
277
278/* Helper to solve keyword problems with C/C++. */
279
280static const char *rna_safe_id(const UString id)
281{
282 if (id == "default") {
283 return "default_value";
284 }
285 if (id == "operator") {
286 return "operator_value";
287 }
288 if (id == "new") {
289 return "create";
290 }
291 if (id == "co_return") {
292 /* MSVC2015, C++ uses for coroutines */
293 return "coord_return";
294 }
295
296 return id.c_str();
297}
298
299/* Preprocessing */
300
301static void rna_print_c_string(FILE *f, const char *str)
302{
303 static const char *escape[] = {
304 "\''", "\"\"", "\??", "\\\\", "\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", nullptr};
305 int i, j;
306
307 if (!str) {
308 fprintf(f, "nullptr");
309 return;
310 }
311
312 fprintf(f, "\"");
313 for (i = 0; str[i]; i++) {
314 for (j = 0; escape[j]; j++) {
315 if (str[i] == escape[j][0]) {
316 break;
317 }
318 }
319
320 if (escape[j]) {
321 fprintf(f, "\\%c", escape[j][1]);
322 }
323 else {
324 fprintf(f, "%c", str[i]);
325 }
326 }
327 fprintf(f, "\"");
328}
329
330static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
331{
333 fprintf(f,
334 " %s *data = (%s *)(((%s *)ptr->data)->%s);\n",
335 dp->dnastructname.c_str(),
336 dp->dnastructname.c_str(),
339 }
340 else {
341 fprintf(f,
342 " %s *data = (%s *)(ptr->data);\n",
343 dp->dnastructname.c_str(),
344 dp->dnastructname.c_str());
345 }
346}
347
348static void rna_print_id_get(FILE *f, PropertyDefRNA * /*dp*/)
349{
350 fprintf(f, " ID *id = ptr->owner_id;\n");
351}
352
354 char *buffer, int size, const char *structname, const char *propname, const char *type)
355{
356 BLI_snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
357}
358
360 char *buffer, int size, const char *structname, const char *propname, const char *type)
361{
362 if (type == nullptr || type[0] == '\0') {
363 BLI_snprintf(buffer, size, "%s_%s", structname, propname);
364 }
365 else {
366 BLI_snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
367 }
368}
369
370void *rna_alloc_from_buffer(const char *buffer, int buffer_size)
371{
372 AllocDefRNA *alloc = MEM_new_zeroed<AllocDefRNA>("AllocDefRNA");
373 alloc->mem = MEM_new_uninitialized(buffer_size, __func__);
374 memcpy(alloc->mem, buffer, buffer_size);
375 rna_addtail(&DefRNA.allocs, alloc);
376 return alloc->mem;
377}
378
379void *rna_calloc(int buffer_size)
380{
381 AllocDefRNA *alloc = MEM_new_zeroed<AllocDefRNA>("AllocDefRNA");
382 alloc->mem = MEM_new_zeroed(buffer_size, __func__);
383 rna_addtail(&DefRNA.allocs, alloc);
384 return alloc->mem;
385}
386
387static char *rna_alloc_function_name(const char *structname,
388 const char *propname,
389 const char *type)
390{
391 char buffer[2048];
392 rna_construct_function_name(buffer, sizeof(buffer), structname, propname, type);
393 return static_cast<char *>(rna_alloc_from_buffer(buffer, strlen(buffer) + 1));
394}
395
396static StructRNA *rna_find_struct(const char *identifier)
397{
398 StructDefRNA *ds;
399
400 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
401 if (ds->srna->identifier == identifier) {
402 return ds->srna;
403 }
404 }
405
406 return nullptr;
407}
408
409static const char *rna_find_type(const StringRef type)
410{
411 StructDefRNA *ds;
412
413 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
414 if (ds->dnaname == type) {
415 return ds->srna->identifier.c_str();
416 }
417 }
418
419 return nullptr;
420}
421
422static const char *rna_find_dna_type(const char *type)
423{
424 StructDefRNA *ds;
425
426 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
427 if (ds->srna->identifier == type) {
428 return ds->dnaname.c_str();
429 }
430 }
431
432 return nullptr;
433}
434
435static const char *rna_type_type_name(PropertyRNA *prop)
436{
437 switch (prop->type) {
438 case PROP_BOOLEAN:
439 return "bool";
440 case PROP_INT:
441 return "int";
442 case PROP_ENUM: {
443 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
444 if (eprop->native_enum_type) {
445 return eprop->native_enum_type;
446 }
447 return "int";
448 }
449 case PROP_FLOAT:
450 return "float";
451 case PROP_STRING:
452 if (prop->flag & PROP_THICK_WRAP) {
453 return "char *";
454 }
455 else {
456 return "const char *";
457 }
458 default:
459 return nullptr;
460 }
461}
462
463static const char *rna_type_type(PropertyRNA *prop)
464{
465 const char *type;
466
467 type = rna_type_type_name(prop);
468
469 if (type) {
470 return type;
471 }
472
473 return "PointerRNA";
474}
475
476static const char *rna_parameter_type_name(PropertyRNA *parm)
477{
478 const char *type;
479
480 type = rna_type_type_name(parm);
481
482 if (type) {
483 return type;
484 }
485
486 switch (parm->type) {
487 case PROP_POINTER: {
488 PointerPropertyRNA *pparm = reinterpret_cast<PointerPropertyRNA *>(parm);
489
490 if (parm->flag_parameter & PARM_RNAPTR) {
491 return "PointerRNA";
492 }
493 return rna_find_dna_type(reinterpret_cast<const char *>(pparm->pointer_type));
494 }
495 case PROP_COLLECTION: {
496 return "CollectionVector";
497 }
498 default:
499 return "<error, no type specified>";
500 }
501}
502
504{
505 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
506 int a, mask = 0;
507
508 if (eprop->item) {
509 for (a = 0; a < eprop->totitem; a++) {
510 if (eprop->item[a].identifier[0]) {
511 mask |= eprop->item[a].value;
512 }
513 }
514 }
515
516 return mask;
517}
518
519static bool rna_parameter_is_const(const PropertyDefRNA *dparm)
520{
521 return (dparm->prop->arraydimension) && ((dparm->prop->flag_parameter & PARM_OUTPUT) == 0);
522}
523
525{
526 return ((prop->type == PROP_FLOAT) && ELEM(prop->subtype, PROP_COLOR, PROP_COLOR_GAMMA) &&
528}
529
535static const char *rna_enum_id_from_pointer(const EnumPropertyItem *item)
536{
537#define RNA_MAKESRNA
538#define DEF_ENUM(id) \
539 if (item == id) { \
540 return STRINGIFY(id); \
541 }
542#include "RNA_enum_items.hh"
543#undef RNA_MAKESRNA
544 return nullptr;
545}
546
547template<typename T> static const char *rna_function_string(T *func)
548{
549 return (func) ? reinterpret_cast<const char *>(func) : "nullptr";
550}
551
552static void rna_float_print(FILE *f, float num)
553{
554 if (num == -FLT_MAX) {
555 fprintf(f, "-FLT_MAX");
556 }
557 else if (num == FLT_MAX) {
558 fprintf(f, "FLT_MAX");
559 }
560 else if ((fabsf(num) < float(INT64_MAX)) && (int64_t(num) == num)) {
561 fprintf(f, "%.1ff", num);
562 }
563 else if (num == std::numeric_limits<float>::infinity()) {
564 fprintf(f, "std::numeric_limits<float>::infinity()");
565 }
566 else if (num == -std::numeric_limits<float>::infinity()) {
567 fprintf(f, "-std::numeric_limits<float>::infinity()");
568 }
569 else {
570 fprintf(f, "%.10ff", num);
571 }
572}
573
574static const char *rna_ui_scale_type_string(const PropertyScaleType type)
575{
576 switch (type) {
578 return "PROP_SCALE_LINEAR";
579 case PROP_SCALE_LOG:
580 return "PROP_SCALE_LOG";
581 case PROP_SCALE_CUBIC:
582 return "PROP_SCALE_CUBIC";
583 }
585 return "";
586}
587
588static void rna_int_print(FILE *f, int64_t num)
589{
590 if (num == INT_MIN) {
591 fprintf(f, "INT_MIN");
592 }
593 else if (num == INT_MAX) {
594 fprintf(f, "INT_MAX");
595 }
596 else if (num == INT64_MIN) {
597 fprintf(f, "INT64_MIN");
598 }
599 else if (num == INT64_MAX) {
600 fprintf(f, "INT64_MAX");
601 }
603 fprintf(f, "%" PRId64 "LL", num);
604 }
605 else {
606 fprintf(f, "%d", int(num));
607 }
608}
609
611 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
612{
613 char *func;
614
615 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
616 return nullptr;
617 }
618
619 if (!manualfunc) {
620 if (dp->dnastructname.is_empty() || dp->dnaname.is_empty()) {
622 "%s.%s has no valid dna info.",
623 srna->identifier.c_str(),
624 prop->identifier.c_str());
625 DefRNA.error = true;
626 return nullptr;
627 }
628
629 /* Type check. */
630 if (!dp->dnatype.is_empty()) {
631
632 if (prop->type == PROP_FLOAT) {
634 /* Colors are an exception. these get translated. */
635 if (prop->subtype != PROP_COLOR_GAMMA) {
637 "%s.%s is a '%s' but wrapped as type '%s'.",
638 srna->identifier.c_str(),
639 prop->identifier.c_str(),
640 dp->dnatype.c_str(),
642 DefRNA.error = true;
643 return nullptr;
644 }
645 }
646 }
647 else if (prop->type == PROP_BOOLEAN) {
650 "%s.%s is a '%s' but wrapped as type '%s'.",
651 srna->identifier.c_str(),
652 prop->identifier.c_str(),
653 dp->dnatype.c_str(),
655 DefRNA.error = true;
656 return nullptr;
657 }
658 }
659 else if (ELEM(prop->type, PROP_INT, PROP_ENUM)) {
660 if (!is_dnatype_int_compat(dp->dnatype)) {
662 "%s.%s is a '%s' but wrapped as type '%s'.",
663 srna->identifier.c_str(),
664 prop->identifier.c_str(),
665 dp->dnatype.c_str(),
667 DefRNA.error = true;
668 return nullptr;
669 }
670 }
671 }
672
673 /* Check log scale sliders for negative range. */
674 if (prop->type == PROP_FLOAT) {
675 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
676 /* NOTE: ButtonType::NumSlider can't have a softmin of zero. */
677 if ((fprop->ui_scale_type == PROP_SCALE_LOG) && (fprop->hardmin < 0 || fprop->softmin < 0)) {
679 "\"%s.%s\", range for log scale < 0.",
680 srna->identifier.c_str(),
681 prop->identifier.c_str());
682 DefRNA.error = true;
683 return nullptr;
684 }
685 }
686 if (prop->type == PROP_INT) {
687 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
688 /* Only ButtonType::NumSlider is implemented and that one can't have a softmin of zero. */
689 if ((iprop->ui_scale_type == PROP_SCALE_LOG) && (iprop->hardmin <= 0 || iprop->softmin <= 0))
690 {
692 "\"%s.%s\", range for log scale <= 0.",
693 srna->identifier.c_str(),
694 prop->identifier.c_str());
695 DefRNA.error = true;
696 return nullptr;
697 }
698 }
699 }
700
701 func = rna_alloc_function_name(srna->identifier.c_str(), rna_safe_id(prop->identifier), "get");
702
703 switch (prop->type) {
704 case PROP_STRING: {
705 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop);
706 UNUSED_VARS_NDEBUG(sprop);
707 fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
708 fprintf(f, "{\n");
709 if (manualfunc) {
710 fprintf(f, " PropStringGetFunc fn = %s;\n", manualfunc);
711 fprintf(f, " fn(ptr, value);\n");
712 }
713 else {
714 rna_print_data_get(f, dp);
715
716 if (dp->dnapointerlevel == 1) {
717 /* Handle allocated char pointer properties. */
718 fprintf(f, " if (data->%s == nullptr) {\n", dp->dnaname.c_str());
719 fprintf(f, " *value = '\\0';\n");
720 fprintf(f, " return;\n");
721 fprintf(f, " }\n");
722 fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname.c_str());
723 }
724 else {
725 /* Handle char array properties. */
726
727#ifndef NDEBUG /* Assert lengths never exceed their maximum expected value. */
728 if (sprop->maxlength) {
729 fprintf(f,
730 " BLI_assert(strlen(data->%s) < %d);\n",
731 dp->dnaname.c_str(),
732 sprop->maxlength);
733 }
734 else {
735 fprintf(f,
736 " BLI_assert(strlen(data->%s) < sizeof(data->%s));\n",
737 dp->dnaname.c_str(),
738 dp->dnaname.c_str());
739 }
740#endif
741
742 fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname.c_str());
743 }
744 }
745 fprintf(f, "}\n\n");
746 break;
747 }
748 case PROP_POINTER: {
749 fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
750 fprintf(f, "{\n");
751 if (manualfunc) {
752 fprintf(f, " PropPointerGetFunc fn = %s;\n", manualfunc);
753 fprintf(f, " return fn(ptr);\n");
754 }
755 else {
756 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
757 rna_print_data_get(f, dp);
758 if (dp->dnapointerlevel == 0) {
759 fprintf(f,
760 " return RNA_pointer_create_with_parent(*ptr, RNA_%s, &data->%s);\n",
761 reinterpret_cast<const char *>(pprop->pointer_type),
762 dp->dnaname.c_str());
763 }
764 else {
765 fprintf(f,
766 " return RNA_pointer_create_with_parent(*ptr, RNA_%s, data->%s);\n",
767 reinterpret_cast<const char *>(pprop->pointer_type),
768 dp->dnaname.c_str());
769 }
770 }
771 fprintf(f, "}\n\n");
772 break;
773 }
774 case PROP_COLLECTION: {
775 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
776
777 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
778 fprintf(f, "{\n");
779 if (manualfunc) {
780 if (STR_ELEM(manualfunc,
781 "rna_iterator_listbase_get",
782 "rna_iterator_array_get",
783 "rna_iterator_array_dereference_get"))
784 {
785 fprintf(f,
786 " return RNA_pointer_create_with_parent(iter->parent, RNA_%s, %s(iter));\n",
787 (cprop->item_type) ? reinterpret_cast<const char *>(cprop->item_type) :
788 "UnknownType",
789 manualfunc);
790 }
791 else {
792 fprintf(f, " PropCollectionGetFunc fn = %s;\n", manualfunc);
793 fprintf(f, " return fn(iter);\n");
794 }
795 }
796 fprintf(f, "}\n\n");
797 break;
798 }
799 default:
800 if (prop->arraydimension) {
801 if (prop->flag & PROP_DYNAMIC) {
802 fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
803 }
804 else {
805 fprintf(f,
806 "void %s(PointerRNA *ptr, %s values[%u])\n",
807 func,
808 rna_type_type(prop),
809 prop->totarraylength);
810 }
811 fprintf(f, "{\n");
812
813 if (manualfunc) {
814 /* Assign `fn` to ensure function signatures match. */
815 if (prop->type == PROP_BOOLEAN) {
816 fprintf(f, " PropBooleanArrayGetFunc fn = %s;\n", manualfunc);
817 fprintf(f, " fn(ptr, values);\n");
818 }
819 else if (prop->type == PROP_INT) {
820 fprintf(f, " PropIntArrayGetFunc fn = %s;\n", manualfunc);
821 fprintf(f, " fn(ptr, values);\n");
822 }
823 else if (prop->type == PROP_FLOAT) {
824 fprintf(f, " PropFloatArrayGetFunc fn = %s;\n", manualfunc);
825 fprintf(f, " fn(ptr, values);\n");
826 }
827 else {
828 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
829 fprintf(f, " %s(ptr, values);\n", manualfunc);
830 }
831 }
832 else {
833 rna_print_data_get(f, dp);
834 fprintf(f, " uint64_t i;\n");
835
836 if (prop->flag & PROP_DYNAMIC) {
837 char *lenfunc = rna_alloc_function_name(
838 srna->identifier.c_str(), rna_safe_id(prop->identifier), "get_length");
839 fprintf(f, " unsigned int arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
840 fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
841 fprintf(f, " for (i = 0; i < len; i++) {\n");
842 MEM_delete(lenfunc);
843 }
844 else {
845 fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
846 }
847
848 if (dp->dnaarraylength == 1) {
849 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
850 fprintf(f,
851 " values[i] = %s((uint64_t(data->%s) & (uint64_t(",
852 (dp->booleannegative) ? "!" : "",
853 dp->dnaname.c_str());
855 fprintf(f, ") << i)) != 0);\n");
856 }
857 else {
858 fprintf(f,
859 " values[i] = (%s)%s((&data->%s)[i]);\n",
860 rna_type_type(prop),
861 (dp->booleannegative) ? "!" : "",
862 dp->dnaname.c_str());
863 }
864 }
865 else {
866 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
867 fprintf(f,
868 " values[i] = %s((uint64_t(data->%s[i]) & ",
869 (dp->booleannegative) ? "!" : "",
870 dp->dnaname.c_str());
872 fprintf(f, ") != 0);\n");
873 }
874 else if (rna_color_quantize(prop, dp)) {
875 fprintf(f,
876 " values[i] = (%s)(data->%s[i] * (1.0f / 255.0f));\n",
877 rna_type_type(prop),
878 dp->dnaname.c_str());
879 }
880 else if (!dp->dnatype.is_empty()) {
881 fprintf(f,
882 " values[i] = (%s)%s(((%s *)data->%s)[i]);\n",
883 rna_type_type(prop),
884 (dp->booleannegative) ? "!" : "",
885 dp->dnatype.c_str(),
886 dp->dnaname.c_str());
887 }
888 else {
889 fprintf(f,
890 " values[i] = (%s)%s((data->%s)[i]);\n",
891 rna_type_type(prop),
892 (dp->booleannegative) ? "!" : "",
893 dp->dnaname.c_str());
894 }
895 }
896 fprintf(f, " }\n");
897 }
898 fprintf(f, "}\n\n");
899 }
900 else {
901 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
902 fprintf(f, "{\n");
903
904 if (manualfunc) {
905 /* Assign `fn` to ensure function signatures match. */
906 if (prop->type == PROP_BOOLEAN) {
907 fprintf(f, " PropBooleanGetFunc fn = %s;\n", manualfunc);
908 fprintf(f, " return fn(ptr);\n");
909 }
910 else if (prop->type == PROP_INT) {
911 fprintf(f, " PropIntGetFunc fn = %s;\n", manualfunc);
912 fprintf(f, " return fn(ptr);\n");
913 }
914 else if (prop->type == PROP_FLOAT) {
915 fprintf(f, " PropFloatGetFunc fn = %s;\n", manualfunc);
916 fprintf(f, " return fn(ptr);\n");
917 }
918 else if (prop->type == PROP_ENUM) {
919 fprintf(f, " PropEnumGetFunc fn = %s;\n", manualfunc);
920 fprintf(f, " return fn(ptr);\n");
921 }
922 else {
923 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
924 fprintf(f, " return %s(ptr);\n", manualfunc);
925 }
926 }
927 else {
928 rna_print_data_get(f, dp);
929 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
930 fprintf(f,
931 " return %s((uint64_t(data->%s) & ",
932 (dp->booleannegative) ? "!" : "",
933 dp->dnaname.c_str());
935 fprintf(f, ") != 0);\n");
936 }
937 else if (prop->type == PROP_ENUM && dp->enumbitflags) {
938 fprintf(f, " return (uint64_t(data->%s) & ", dp->dnaname.c_str());
940 fprintf(f, ");\n");
941 }
942 else {
943 fprintf(f,
944 " return (%s)%s(data->%s);\n",
945 rna_type_type(prop),
946 (dp->booleannegative) ? "!" : "",
947 dp->dnaname.c_str());
948 }
949 }
950
951 fprintf(f, "}\n\n");
952 }
953 break;
954 }
955
956 return func;
957}
958
959/* defined min/max variables to be used by rna_clamp_value() */
960static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
961{
962 if (prop->type == PROP_FLOAT) {
963 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
964 if (fprop->range) {
965 fprintf(f,
966 " float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, "
967 "prop_soft_max;\n");
968 fprintf(f,
969 " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
970 rna_function_string(fprop->range));
971 }
972 }
973 else if (prop->type == PROP_INT) {
974 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
975 if (iprop->range) {
976 fprintf(f,
977 " int prop_clamp_min = INT_MIN, prop_clamp_max = INT_MAX, prop_soft_min, "
978 "prop_soft_max;\n");
979 fprintf(f,
980 " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
981 rna_function_string(iprop->range));
982 }
983 }
984}
985
986#ifdef USE_RNA_RANGE_CHECK
987static void rna_clamp_value_range_check(FILE *f,
988 PropertyRNA *prop,
989 const char *dnaname_prefix,
990 const char *dnaname)
991{
992 if (prop->type == PROP_INT) {
993 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
994 fprintf(f, " {\n");
995 fprintf(f, " using T = decltype(%s%s);\n", dnaname_prefix, dnaname);
996 fprintf(f,
997 " static_assert(std::numeric_limits<std::decay_t<T>>::max() >= %d);\n",
998 iprop->hardmax);
999 fprintf(f,
1000 " static_assert(std::numeric_limits<std::decay_t<T>>::min() <= %d);\n",
1001 iprop->hardmin);
1002 fprintf(f, " }\n");
1003 }
1004}
1005#endif /* USE_RNA_RANGE_CHECK */
1006
1007static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
1008{
1009 if (prop->type == PROP_INT) {
1010 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
1011
1012 if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX || iprop->range) {
1013 if (array) {
1014 fprintf(f, "std::clamp(values[i], ");
1015 }
1016 else {
1017 fprintf(f, "std::clamp(value, ");
1018 }
1019 if (iprop->range) {
1020 fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
1021 }
1022 else {
1023 rna_int_print(f, iprop->hardmin);
1024 fprintf(f, ", ");
1025 rna_int_print(f, iprop->hardmax);
1026 fprintf(f, ");\n");
1027 }
1028 return;
1029 }
1030 }
1031 else if (prop->type == PROP_FLOAT) {
1032 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
1033
1034 if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX || fprop->range) {
1035 if (array) {
1036 fprintf(f, "std::clamp(values[i], ");
1037 }
1038 else {
1039 fprintf(f, "std::clamp(value, ");
1040 }
1041 if (fprop->range) {
1042 fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
1043 }
1044 else {
1045 rna_float_print(f, fprop->hardmin);
1046 fprintf(f, ", ");
1047 rna_float_print(f, fprop->hardmax);
1048 fprintf(f, ");\n");
1049 }
1050 return;
1051 }
1052 }
1053
1054 if (array) {
1055 fprintf(f, "values[i];\n");
1056 }
1057 else {
1058 fprintf(f, "value;\n");
1059 }
1060}
1061
1063 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1064{
1065 char *func;
1066
1067 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1068 return nullptr;
1069 }
1070 if (!manualfunc) {
1071 return nullptr;
1072 }
1073
1075 srna->identifier.c_str(), rna_safe_id(prop->identifier), "search");
1076
1077 fprintf(f,
1078 "void %s("
1079 "const bContext *C, "
1080 "PointerRNA *ptr, "
1081 "PropertyRNA *prop, "
1082 "const char *edit_text, "
1083 "FunctionRef<void(StringPropertySearchVisitParams)> visit_fn)\n",
1084 func);
1085 fprintf(f, "{\n");
1086 fprintf(f, "\n StringPropertySearchFunc fn = %s;\n", manualfunc);
1087 fprintf(f, "\n fn(C, ptr, prop, edit_text, visit_fn);\n");
1088 fprintf(f, "}\n\n");
1089 return func;
1090}
1091
1093 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1094{
1095 char *func;
1096
1097 if (!(prop->flag & PROP_EDITABLE)) {
1098 return nullptr;
1099 }
1100 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1101 return nullptr;
1102 }
1103
1104 if (!manualfunc) {
1105 if (dp->dnastructname.is_empty() || dp->dnaname.is_empty()) {
1106 if (prop->flag & PROP_EDITABLE) {
1107 CLOG_ERROR(&LOG,
1108 "%s.%s has no valid dna info.",
1109 srna->identifier.c_str(),
1110 prop->identifier.c_str());
1111 DefRNA.error = true;
1112 }
1113 return nullptr;
1114 }
1115 }
1116
1117 func = rna_alloc_function_name(srna->identifier.c_str(), rna_safe_id(prop->identifier), "set");
1118
1119 switch (prop->type) {
1120 case PROP_STRING: {
1121 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop);
1122 fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
1123 fprintf(f, "{\n");
1124 if (manualfunc) {
1125 fprintf(f, " PropStringSetFunc fn = %s;\n", manualfunc);
1126 fprintf(f, " fn(ptr, value);\n");
1127 }
1128 else {
1129 const PropertySubType subtype = prop->subtype;
1130 rna_print_data_get(f, dp);
1131
1132 if (dp->dnapointerlevel == 1) {
1133 /* Handle allocated char pointer properties. */
1134 fprintf(f,
1135 " if (data->%s != nullptr) { MEM_delete(data->%s); }\n",
1136 dp->dnaname.c_str(),
1137 dp->dnaname.c_str());
1138 fprintf(f, " const size_t length = strlen(value);\n");
1139 fprintf(f, " if (length > 0) {\n");
1140 fprintf(f,
1141 " data->%s = MEM_new_array_uninitialized<char>(length + 1, __func__);\n",
1142 dp->dnaname.c_str());
1143 fprintf(f, " memcpy(data->%s, value, length + 1);\n", dp->dnaname.c_str());
1144 fprintf(f, " } else { data->%s = nullptr; }\n", dp->dnaname.c_str());
1145 }
1146 else {
1147 const char *string_copy_func =
1149 "BLI_strncpy" :
1150 "BLI_strncpy_utf8";
1151 /* Handle char array properties. */
1152 if (sprop->maxlength) {
1153 fprintf(f,
1154 " %s(data->%s, value, %d);\n",
1155 string_copy_func,
1156 dp->dnaname.c_str(),
1157 sprop->maxlength);
1158 }
1159 else {
1160 fprintf(f,
1161 " %s(data->%s, value, sizeof(data->%s));\n",
1162 string_copy_func,
1163 dp->dnaname.c_str(),
1164 dp->dnaname.c_str());
1165 }
1166 }
1167 }
1168 fprintf(f, "}\n\n");
1169 break;
1170 }
1171 case PROP_POINTER: {
1172 fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value, ReportList *reports)\n", func);
1173 fprintf(f, "{\n");
1174 if (manualfunc) {
1175 fprintf(f, " PropPointerSetFunc fn = %s;\n", manualfunc);
1176 fprintf(f, " fn(ptr, value, reports);\n");
1177 }
1178 else {
1179 rna_print_data_get(f, dp);
1180
1181 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(dp->prop);
1182 StructRNA *type = (pprop->pointer_type) ? rna_find_struct(reinterpret_cast<const char *>(
1183 pprop->pointer_type)) :
1184 nullptr;
1185
1186 if (prop->flag & PROP_ID_SELF_CHECK) {
1187 /* No pointers to self allowed. */
1188 rna_print_id_get(f, dp);
1189 fprintf(f, " if (id == value.data) {\n");
1190 fprintf(f, " return;\n");
1191 fprintf(f, " }\n");
1192 }
1193
1194 if (type && (type->flag & STRUCT_ID)) {
1195 /* Check if pointers between datablocks are allowed. */
1196 fprintf(f,
1197 " if (value && ptr->has_owner_id() && value.has_owner_id() && "
1198 "!BKE_id_can_use_id(*ptr->owner_id, *value.owner_id)) {\n");
1199 fprintf(f, " return;\n");
1200 fprintf(f, " }\n");
1201 }
1202
1203 if (prop->flag & PROP_ID_REFCOUNT) {
1204 /* Perform reference counting. */
1205 fprintf(f, "\n if (data->%s) {\n", dp->dnaname.c_str());
1206 fprintf(f, " id_us_min((ID *)data->%s);\n", dp->dnaname.c_str());
1207 fprintf(f, " }\n");
1208 fprintf(f, " if (value) {\n");
1209 fprintf(f, " id_us_plus((ID *)value.data);\n");
1210 fprintf(f, " }\n");
1211 }
1212 else if (type && (type->flag & STRUCT_ID)) {
1213 /* Still mark linked data as used if not reference counting. */
1214 fprintf(f, " if (value) {\n");
1215 fprintf(f, " id_lib_extern((ID *)value.data);\n");
1216 fprintf(f, " }\n");
1217 }
1218
1219 fprintf(f, " *(void **)&data->%s = value.data;\n", dp->dnaname.c_str());
1220 }
1221 fprintf(f, "}\n\n");
1222 break;
1223 }
1224 default:
1225 if (prop->arraydimension) {
1226 if (prop->flag & PROP_DYNAMIC) {
1227 fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
1228 }
1229 else {
1230 fprintf(f,
1231 "void %s(PointerRNA *ptr, const %s values[%u])\n",
1232 func,
1233 rna_type_type(prop),
1234 prop->totarraylength);
1235 }
1236 fprintf(f, "{\n");
1237
1238 if (manualfunc) {
1239 /* Assign `fn` to ensure function signatures match. */
1240 if (prop->type == PROP_BOOLEAN) {
1241 fprintf(f, " PropBooleanArraySetFunc fn = %s;\n", manualfunc);
1242 fprintf(f, " fn(ptr, values);\n");
1243 }
1244 else if (prop->type == PROP_INT) {
1245 fprintf(f, " PropIntArraySetFunc fn = %s;\n", manualfunc);
1246 fprintf(f, " fn(ptr, values);\n");
1247 }
1248 else if (prop->type == PROP_FLOAT) {
1249 fprintf(f, " PropFloatArraySetFunc fn = %s;\n", manualfunc);
1250 fprintf(f, " fn(ptr, values);\n");
1251 }
1252 else {
1253 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
1254 fprintf(f, " %s(ptr, values);\n", manualfunc);
1255 }
1256 }
1257 else {
1258 rna_print_data_get(f, dp);
1259 fprintf(f, " uint64_t i;\n");
1260
1261 if (prop->flag & PROP_DYNAMIC) {
1262 char *lenfunc = rna_alloc_function_name(
1263 srna->identifier.c_str(), rna_safe_id(prop->identifier), "set_length");
1264 fprintf(f, " unsigned int arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
1265 fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
1266 rna_clamp_value_range(f, prop);
1267 fprintf(f, " for (i = 0; i < len; i++) {\n");
1268 MEM_delete(lenfunc);
1269 }
1270 else {
1271 rna_clamp_value_range(f, prop);
1272 fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
1273 }
1274
1275 if (dp->dnaarraylength == 1) {
1276 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1277 /* Cast to avoid issues when the field is an enum type. */
1278 fprintf(f,
1279 " if (%svalues[i]) { data->%s = "
1280 "std::remove_reference_t<decltype(data->%s)>"
1281 "(uint64_t(data->%s) | (uint64_t(",
1282 (dp->booleannegative) ? "!" : "",
1283 dp->dnaname.c_str(),
1284 dp->dnaname.c_str(),
1285 dp->dnaname.c_str());
1286 rna_int_print(f, dp->booleanbit);
1287 fprintf(f, ") << i)); }\n");
1288 fprintf(f,
1289 " else { data->%s = "
1290 "std::remove_reference_t<decltype(data->%s)>"
1291 "(uint64_t(data->%s) & ~(uint64_t(",
1292 dp->dnaname.c_str(),
1293 dp->dnaname.c_str(),
1294 dp->dnaname.c_str());
1295 rna_int_print(f, dp->booleanbit);
1296 fprintf(f, ") << i)); }\n");
1297 }
1298 else {
1299 fprintf(f,
1300 " (&data->%s)[i] = %s",
1301 dp->dnaname.c_str(),
1302 (dp->booleannegative) ? "!" : "");
1303 rna_clamp_value(f, prop, 1);
1304 }
1305 }
1306 else {
1307 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1308 /* Cast to avoid issues when the field is an enum type. */
1309 fprintf(f,
1310 " if (%svalues[i]) { data->%s[i] = "
1311 "std::remove_reference_t<decltype(data->%s[i])>"
1312 "(uint64_t(data->%s[i]) | ",
1313 (dp->booleannegative) ? "!" : "",
1314 dp->dnaname.c_str(),
1315 dp->dnaname.c_str(),
1316 dp->dnaname.c_str());
1317 rna_int_print(f, dp->booleanbit);
1318 fprintf(f, "); }\n");
1319 fprintf(f,
1320 " else { data->%s[i] = "
1321 "std::remove_reference_t<decltype(data->%s[i])>"
1322 "(uint64_t(data->%s[i]) & ~uint64_t(",
1323 dp->dnaname.c_str(),
1324 dp->dnaname.c_str(),
1325 dp->dnaname.c_str());
1326 rna_int_print(f, dp->booleanbit);
1327 fprintf(f, ")); }\n");
1328 }
1329 else if (rna_color_quantize(prop, dp)) {
1330 fprintf(f,
1331 " data->%s[i] = unit_float_to_uchar_clamp(values[i]);\n",
1332 dp->dnaname.c_str());
1333 }
1334 else {
1335 if (!dp->dnatype.is_empty()) {
1336 fprintf(f,
1337 " ((%s *)data->%s)[i] = %s",
1338 dp->dnatype.c_str(),
1339 dp->dnaname.c_str(),
1340 (dp->booleannegative) ? "!" : "");
1341 }
1342 else {
1343 fprintf(f,
1344 " (data->%s)[i] = %s",
1345 dp->dnaname.c_str(),
1346 (dp->booleannegative) ? "!" : "");
1347 }
1348 rna_clamp_value(f, prop, 1);
1349 }
1350 }
1351 fprintf(f, " }\n");
1352 }
1353
1354#ifdef USE_RNA_RANGE_CHECK
1355 if (!dp->dnaname.is_empty() && manualfunc == nullptr) {
1356 if (dp->dnaarraylength == 1) {
1357 rna_clamp_value_range_check(f, prop, "data->", dp->dnaname.c_str());
1358 }
1359 else {
1360 rna_clamp_value_range_check(f, prop, "*data->", dp->dnaname.c_str());
1361 }
1362 }
1363#endif
1364
1365 fprintf(f, "}\n\n");
1366 }
1367 else {
1368 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
1369 fprintf(f, "{\n");
1370
1371 if (manualfunc) {
1372 /* Assign `fn` to ensure function signatures match. */
1373 if (prop->type == PROP_BOOLEAN) {
1374 fprintf(f, " PropBooleanSetFunc fn = %s;\n", manualfunc);
1375 fprintf(f, " fn(ptr, value);\n");
1376 }
1377 else if (prop->type == PROP_INT) {
1378 fprintf(f, " PropIntSetFunc fn = %s;\n", manualfunc);
1379 fprintf(f, " fn(ptr, value);\n");
1380 }
1381 else if (prop->type == PROP_FLOAT) {
1382 fprintf(f, " PropFloatSetFunc fn = %s;\n", manualfunc);
1383 fprintf(f, " fn(ptr, value);\n");
1384 }
1385 else if (prop->type == PROP_ENUM) {
1386 fprintf(f, " PropEnumSetFunc fn = %s;\n", manualfunc);
1387 fprintf(f, " fn(ptr, value);\n");
1388 }
1389 else {
1390 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
1391 fprintf(f, " %s(ptr, value);\n", manualfunc);
1392 }
1393 }
1394 else {
1395 rna_print_data_get(f, dp);
1396 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1397 /* Cast to avoid issues when the field is an enum type. */
1398 fprintf(f,
1399 " if (%svalue) { data->%s = "
1400 "std::remove_reference_t<decltype(data->%s)>"
1401 "(uint64_t(data->%s) | ",
1402 (dp->booleannegative) ? "!" : "",
1403 dp->dnaname.c_str(),
1404 dp->dnaname.c_str(),
1405 dp->dnaname.c_str());
1406 rna_int_print(f, dp->booleanbit);
1407 fprintf(f, "); }\n");
1408 fprintf(f,
1409 " else { data->%s = "
1410 "std::remove_reference_t<decltype(data->%s)>"
1411 "(uint64_t(data->%s) & ~uint64_t(",
1412 dp->dnaname.c_str(),
1413 dp->dnaname.c_str(),
1414 dp->dnaname.c_str());
1415 rna_int_print(f, dp->booleanbit);
1416 fprintf(f, ")); }\n");
1417 }
1418 else if (prop->type == PROP_ENUM && dp->enumbitflags) {
1419 /* Cast to avoid issues when the field is an enum type. */
1420 fprintf(f,
1421 " data->%s = std::remove_reference_t<decltype(data->%s)>"
1422 "(uint64_t(data->%s) & ~uint64_t(",
1423 dp->dnaname.c_str(),
1424 dp->dnaname.c_str(),
1425 dp->dnaname.c_str());
1427 fprintf(f, "));\n");
1428 fprintf(f,
1429 " data->%s = std::remove_reference_t<decltype(data->%s)>"
1430 "(uint64_t(data->%s) | uint64_t(value));\n",
1431 dp->dnaname.c_str(),
1432 dp->dnaname.c_str(),
1433 dp->dnaname.c_str());
1434 }
1435 else {
1436 /* Cast to avoid issues when the field is an enum type.
1437 * If #rna_clamp_value() adds an expression like `std::clamp(...)`
1438 * (instead of an `lvalue`), #decltype() yields a reference,
1439 * so that has to be removed. */
1440 rna_clamp_value_range(f, prop);
1441 fprintf(f,
1442 " data->%s = %s(std::remove_reference_t<decltype(data->%s)>)",
1443 dp->dnaname.c_str(),
1444 (dp->booleannegative) ? "!" : "",
1445 dp->dnaname.c_str());
1446 rna_clamp_value(f, prop, 0);
1447 }
1448 }
1449
1450#ifdef USE_RNA_RANGE_CHECK
1451 if (!dp->dnaname.is_empty() && manualfunc == nullptr) {
1452 rna_clamp_value_range_check(f, prop, "data->", dp->dnaname.c_str());
1453 }
1454#endif
1455
1456 fprintf(f, "}\n\n");
1457 }
1458 break;
1459 }
1460
1461 return func;
1462}
1463
1465 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1466{
1467 char *func = nullptr;
1468
1469 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1470 return nullptr;
1471 }
1472
1473 if (prop->type == PROP_STRING) {
1474 if (!manualfunc) {
1475 if (dp->dnastructname.is_empty() || dp->dnaname.is_empty()) {
1476 CLOG_ERROR(&LOG,
1477 "%s.%s has no valid dna info.",
1478 srna->identifier.c_str(),
1479 prop->identifier.c_str());
1480 DefRNA.error = true;
1481 return nullptr;
1482 }
1483 }
1484
1486 srna->identifier.c_str(), rna_safe_id(prop->identifier), "length");
1487
1488 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
1489 fprintf(f, "{\n");
1490 if (manualfunc) {
1491 fprintf(f, " PropStringLengthFunc fn = %s;\n", manualfunc);
1492 fprintf(f, " return fn(ptr);\n");
1493 }
1494 else {
1495 rna_print_data_get(f, dp);
1496 if (dp->dnapointerlevel == 1) {
1497 /* Handle allocated char pointer properties. */
1498 fprintf(f,
1499 " return (data->%s == nullptr) ? 0 : strlen(data->%s);\n",
1500 dp->dnaname.c_str(),
1501 dp->dnaname.c_str());
1502 }
1503 else {
1504 /* Handle char array properties. */
1505 fprintf(f, " return strlen(data->%s);\n", dp->dnaname.c_str());
1506 }
1507 }
1508 fprintf(f, "}\n\n");
1509 }
1510 else if (prop->type == PROP_COLLECTION) {
1511 if (!manualfunc) {
1512 if (prop->type == PROP_COLLECTION &&
1513 ((dp->dnalengthname.is_empty() && !dp->dnalengthfixed) || dp->dnaname.is_empty()))
1514 {
1515 CLOG_ERROR(&LOG,
1516 "%s.%s has no valid dna info.",
1517 srna->identifier.c_str(),
1518 prop->identifier.c_str());
1519 DefRNA.error = true;
1520 return nullptr;
1521 }
1522 }
1523
1525 srna->identifier.c_str(), rna_safe_id(prop->identifier), "length");
1526
1527 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
1528 fprintf(f, "{\n");
1529 if (manualfunc) {
1530 fprintf(f, " PropCollectionLengthFunc fn = %s;\n", manualfunc);
1531 fprintf(f, " return fn(ptr);\n");
1532 }
1533 else {
1534 if (dp->dnaarraylength <= 1 || !dp->dnalengthname.is_empty()) {
1535 rna_print_data_get(f, dp);
1536 }
1537
1538 if (dp->dnaarraylength > 1) {
1539 fprintf(f, " return ");
1540 }
1541 else {
1542 fprintf(f, " return (data->%s == nullptr) ? 0 : ", dp->dnaname.c_str());
1543 }
1544
1545 if (!dp->dnalengthname.is_empty()) {
1546 fprintf(f, "data->%s;\n", dp->dnalengthname.c_str());
1547 }
1548 else {
1549 fprintf(f, "%d;\n", dp->dnalengthfixed);
1550 }
1551 }
1552 fprintf(f, "}\n\n");
1553 }
1554
1555 return func;
1556}
1557
1559 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1560{
1561 char *func, *getfunc;
1562
1563 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1564 return nullptr;
1565 }
1566
1567 if (!manualfunc) {
1568 if (dp->dnastructname.is_empty() || dp->dnaname.is_empty()) {
1569 CLOG_ERROR(&LOG,
1570 "%s.%s has no valid dna info.",
1571 srna->identifier.c_str(),
1572 prop->identifier.c_str());
1573 DefRNA.error = true;
1574 return nullptr;
1575 }
1576 }
1577
1578 func = rna_alloc_function_name(srna->identifier.c_str(), rna_safe_id(prop->identifier), "begin");
1579
1580 fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
1581 fprintf(f, "{\n");
1582
1583 if (!manualfunc) {
1584 rna_print_data_get(f, dp);
1585 }
1586
1587 fprintf(f, "\n *iter = {};\n");
1588 fprintf(f, " iter->parent = *ptr;\n");
1589 fprintf(f, " iter->prop = &rna_%s_%s;\n", srna->identifier.c_str(), prop->identifier.c_str());
1590
1591 if (!dp->dnalengthname.is_empty() || dp->dnalengthfixed) {
1592 if (manualfunc) {
1593 fprintf(f, "\n PropCollectionBeginFunc fn = %s;\n", manualfunc);
1594 fprintf(f, " fn(iter, ptr);\n");
1595 }
1596 else {
1597 if (!dp->dnalengthname.is_empty()) {
1598 fprintf(f,
1599 "\n rna_iterator_array_begin(iter, ptr, data->%s, sizeof(data->%s[0]), "
1600 "data->%s, 0, nullptr);\n",
1601 dp->dnaname.c_str(),
1602 dp->dnaname.c_str(),
1603 dp->dnalengthname.c_str());
1604 }
1605 else {
1606 fprintf(f,
1607 "\n rna_iterator_array_begin(iter, ptr, data->%s, sizeof(data->%s[0]), %d, 0, "
1608 "nullptr);\n",
1609 dp->dnaname.c_str(),
1610 dp->dnaname.c_str(),
1611 dp->dnalengthfixed);
1612 }
1613 }
1614 }
1615 else {
1616 if (manualfunc) {
1617 fprintf(f, "\n PropCollectionBeginFunc fn = %s;\n", manualfunc);
1618 fprintf(f, " fn(iter, ptr);\n");
1619 }
1620 else if (dp->dnapointerlevel == 0) {
1621 fprintf(f,
1622 "\n rna_iterator_listbase_begin(iter, ptr, &data->%s, nullptr);\n",
1623 dp->dnaname.c_str());
1624 }
1625 else {
1626 fprintf(f,
1627 "\n rna_iterator_listbase_begin(iter, ptr, data->%s, nullptr);\n",
1628 dp->dnaname.c_str());
1629 }
1630 }
1631
1632 getfunc = rna_alloc_function_name(
1633 srna->identifier.c_str(), rna_safe_id(prop->identifier), "get");
1634
1635 fprintf(f, "\n if (iter->valid) {\n");
1636 fprintf(f, " iter->ptr = %s(iter);", getfunc);
1637 fprintf(f, "\n }\n");
1638
1639 fprintf(f, "}\n\n");
1640
1641 return func;
1642}
1643
1645 FILE *f, StructRNA *srna, PropertyRNA *prop, const char *manualfunc, const char *nextfunc)
1646{
1647 /* note on indices, this is for external functions and ignores skipped values.
1648 * so the index can only be checked against the length when there is no 'skip' function. */
1649 char *func;
1650
1651 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1652 return nullptr;
1653 }
1654
1655 if (!manualfunc) {
1656 /* only supported in case of standard next functions */
1657 if (STREQ(nextfunc, "rna_iterator_array_next")) {
1658 }
1659 else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {
1660 }
1661 else {
1662 return nullptr;
1663 }
1664 }
1665
1667 srna->identifier.c_str(), rna_safe_id(prop->identifier), "lookup_int");
1668
1669 fprintf(f, "bool %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
1670 fprintf(f, "{\n");
1671
1672 if (manualfunc) {
1673 fprintf(f, "\n PropCollectionLookupIntFunc fn = %s;\n", manualfunc);
1674 fprintf(f, " return fn(ptr, index, r_ptr);\n");
1675 fprintf(f, "}\n\n");
1676 return func;
1677 }
1678
1679 fprintf(f, " bool found = false;\n");
1680 fprintf(f, " CollectionPropertyIterator iter;\n\n");
1681
1682 fprintf(f,
1683 " %s_%s_begin(&iter, ptr);\n\n",
1684 srna->identifier.c_str(),
1685 rna_safe_id(prop->identifier));
1686 fprintf(f, " if (iter.valid) {\n");
1687
1688 if (STREQ(nextfunc, "rna_iterator_array_next")) {
1689 fprintf(f, " ArrayIterator *internal = &iter.internal.array;\n");
1690 fprintf(f, " if (index < 0 || index >= internal->length) {\n");
1691 fprintf(f, "#ifdef __GNUC__\n");
1692 fprintf(f,
1693 " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, "
1694 "index);\n");
1695 fprintf(f, "#else\n");
1696 fprintf(f, " printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
1697 fprintf(f, "#endif\n");
1698 fprintf(f, " }\n");
1699 fprintf(f, " else if (internal->skip) {\n");
1700 fprintf(f, " while (index-- > 0 && iter.valid) {\n");
1701 fprintf(f, " rna_iterator_array_next(&iter);\n");
1702 fprintf(f, " }\n");
1703 fprintf(f, " found = (index == -1 && iter.valid);\n");
1704 fprintf(f, " }\n");
1705 fprintf(f, " else {\n");
1706 fprintf(f, " internal->ptr += internal->itemsize * index;\n");
1707 fprintf(f, " found = 1;\n");
1708 fprintf(f, " }\n");
1709 }
1710 else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {
1711 fprintf(f, " ListBaseIterator *internal = &iter.internal.listbase;\n");
1712 fprintf(f, " if (internal->skip) {\n");
1713 fprintf(f, " while (index-- > 0 && iter.valid) {\n");
1714 fprintf(f, " rna_iterator_listbase_next(&iter);\n");
1715 fprintf(f, " }\n");
1716 fprintf(f, " found = (index == -1 && iter.valid);\n");
1717 fprintf(f, " }\n");
1718 fprintf(f, " else {\n");
1719 fprintf(f, " while (index-- > 0 && internal->link) {\n");
1720 fprintf(f, " internal->link = internal->link->next;\n");
1721 fprintf(f, " }\n");
1722 fprintf(f, " found = (index == -1 && internal->link);\n");
1723 fprintf(f, " }\n");
1724 }
1725
1726 fprintf(f,
1727 " if (found) { *r_ptr = %s_%s_get(&iter); }\n",
1728 srna->identifier.c_str(),
1729 rna_safe_id(prop->identifier));
1730 fprintf(f, " }\n\n");
1731 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier.c_str(), rna_safe_id(prop->identifier));
1732
1733 fprintf(f, " return found;\n");
1734
1735 fprintf(f, "}\n\n");
1736
1737 return func;
1738}
1739
1741 StructRNA *srna,
1742 PropertyRNA *prop,
1743 PropertyDefRNA *dp,
1744 const char *manualfunc,
1745 const char *item_type)
1746{
1747 char *func;
1748 StructRNA *item_srna, *item_name_base;
1749 PropertyRNA *item_name_prop;
1750 const int namebuflen = 1024;
1751
1752 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1753 return nullptr;
1754 }
1755
1756 if (!manualfunc) {
1757 if (dp->dnastructname.is_empty() || dp->dnaname.is_empty()) {
1758 return nullptr;
1759 }
1760
1761 /* only supported for collection items with name properties */
1762 item_srna = rna_find_struct(item_type);
1763 if (item_srna && item_srna->nameproperty) {
1764 item_name_prop = item_srna->nameproperty;
1765 item_name_base = item_srna;
1766 while (item_name_base->base && item_name_base->base->nameproperty == item_name_prop) {
1767 item_name_base = item_name_base->base;
1768 }
1769 }
1770 else {
1771 return nullptr;
1772 }
1773 }
1774
1776 srna->identifier.c_str(), rna_safe_id(prop->identifier), "lookup_string");
1777
1778 if (!manualfunc) {
1779 fprintf(f,
1780 "int %s_%s_length(PointerRNA *);\n",
1781 item_name_base->identifier.c_str(),
1782 rna_safe_id(item_name_prop->identifier));
1783 fprintf(f,
1784 "void %s_%s_get(PointerRNA *, char *);\n\n",
1785 item_name_base->identifier.c_str(),
1786 rna_safe_id(item_name_prop->identifier));
1787 }
1788
1789 fprintf(f, "bool %s(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)\n", func);
1790 fprintf(f, "{\n");
1791
1792 if (manualfunc) {
1793 fprintf(f, " PropCollectionLookupStringFunc fn = %s;\n", manualfunc);
1794 fprintf(f, " return fn(ptr, key, r_ptr);\n");
1795 fprintf(f, "}\n\n");
1796 return func;
1797 }
1798
1799 fprintf(f, " bool found = false;\n");
1800 fprintf(f, " CollectionPropertyIterator iter;\n");
1801 fprintf(f, " char namebuf[%d];\n", namebuflen);
1802 fprintf(f, " char *name;\n\n");
1803
1804 fprintf(f,
1805 " %s_%s_begin(&iter, ptr);\n\n",
1806 srna->identifier.c_str(),
1807 rna_safe_id(prop->identifier));
1808
1809 fprintf(f, " while (iter.valid) {\n");
1810 fprintf(f, " if (iter.ptr) {\n");
1811 fprintf(f,
1812 " int namelen = %s_%s_length(&iter.ptr);\n",
1813 item_name_base->identifier.c_str(),
1814 rna_safe_id(item_name_prop->identifier));
1815 fprintf(f, " if (namelen < %d) {\n", namebuflen);
1816 fprintf(f,
1817 " %s_%s_get(&iter.ptr, namebuf);\n",
1818 item_name_base->identifier.c_str(),
1819 rna_safe_id(item_name_prop->identifier));
1820 fprintf(f, " if (strcmp(namebuf, key) == 0) {\n");
1821 fprintf(f, " found = true;\n");
1822 fprintf(f, " *r_ptr = iter.ptr;\n");
1823 fprintf(f, " break;\n");
1824 fprintf(f, " }\n");
1825 fprintf(f, " }\n");
1826 fprintf(f, " else {\n");
1827 fprintf(f, " name = MEM_new_array_uninitialized<char>(size_t(namelen) + 1,\n");
1828 fprintf(f, " \"name string\");\n");
1829 fprintf(f,
1830 " %s_%s_get(&iter.ptr, name);\n",
1831 item_name_base->identifier.c_str(),
1832 rna_safe_id(item_name_prop->identifier));
1833 fprintf(f, " if (strcmp(name, key) == 0) {\n");
1834 fprintf(f, " MEM_delete(name);\n\n");
1835 fprintf(f, " found = true;\n");
1836 fprintf(f, " *r_ptr = iter.ptr;\n");
1837 fprintf(f, " break;\n");
1838 fprintf(f, " }\n");
1839 fprintf(f, " else {\n");
1840 fprintf(f, " MEM_delete(name);\n");
1841 fprintf(f, " }\n");
1842 fprintf(f, " }\n");
1843 fprintf(f, " }\n");
1844 fprintf(
1845 f, " %s_%s_next(&iter);\n", srna->identifier.c_str(), rna_safe_id(prop->identifier));
1846 fprintf(f, " }\n");
1847 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier.c_str(), rna_safe_id(prop->identifier));
1848
1849 fprintf(f, " return found;\n");
1850 fprintf(f, "}\n\n");
1851
1852 return func;
1853}
1854
1856 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1857{
1858 char *func, *getfunc;
1859
1860 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1861 return nullptr;
1862 }
1863
1864 if (!manualfunc) {
1865 return nullptr;
1866 }
1867
1868 func = rna_alloc_function_name(srna->identifier.c_str(), rna_safe_id(prop->identifier), "next");
1869
1870 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1871 fprintf(f, "{\n");
1872 fprintf(f, " PropCollectionNextFunc fn = %s;\n", manualfunc);
1873 fprintf(f, " fn(iter);\n");
1874
1875 getfunc = rna_alloc_function_name(
1876 srna->identifier.c_str(), rna_safe_id(prop->identifier), "get");
1877
1878 fprintf(f, "\n if (iter->valid) {\n");
1879 fprintf(f, " iter->ptr = %s(iter);", getfunc);
1880 fprintf(f, "\n }\n");
1881
1882 fprintf(f, "}\n\n");
1883
1884 return func;
1885}
1886
1888 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1889{
1890 char *func;
1891
1892 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1893 return nullptr;
1894 }
1895
1896 func = rna_alloc_function_name(srna->identifier.c_str(), rna_safe_id(prop->identifier), "end");
1897
1898 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
1899 fprintf(f, "{\n");
1900 if (manualfunc) {
1901 fprintf(f, " PropCollectionEndFunc fn = %s;\n", manualfunc);
1902 fprintf(f, " fn(iter);\n");
1903 }
1904 fprintf(f, "}\n\n");
1905
1906 return func;
1907}
1908
1910{
1911 if (dp->dnapointerlevel != 0) {
1912 return;
1913 }
1914 if (dp->dnatype.is_empty() || dp->dnaname.is_empty() || dp->dnastructname.is_empty()) {
1915 return;
1916 }
1917
1918 if (dp->dnatype == "char") {
1921 }
1922 else if (dp->dnatype == "int8_t") {
1925 }
1926 else if (dp->dnatype == "uchar") {
1929 }
1930 else if (dp->dnatype == "short") {
1931 prop->rawtype = PROP_RAW_SHORT;
1933 }
1934 else if (dp->dnatype == "ushort") {
1935 prop->rawtype = PROP_RAW_UINT16;
1937 }
1938 else if (dp->dnatype == "int") {
1939 prop->rawtype = PROP_RAW_INT;
1941 }
1942 else if (dp->dnatype == "float") {
1943 prop->rawtype = PROP_RAW_FLOAT;
1945 }
1946 else if (dp->dnatype == "double") {
1947 prop->rawtype = PROP_RAW_DOUBLE;
1949 }
1950 else if (dp->dnatype == "int64_t") {
1951 prop->rawtype = PROP_RAW_INT64;
1953 }
1954 else if (dp->dnatype == "uint64_t") {
1955 prop->rawtype = PROP_RAW_UINT64;
1957 }
1958}
1959
1960static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
1961{
1963
1964 fprintf(f,
1965 "\toffsetof(%s, %s), RawPropertyType(%d)",
1966 dp->dnastructname.c_str(),
1967 dp->dnaname.c_str(),
1968 prop->rawtype);
1969}
1970
1971static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1972{
1973 PropertyRNA *prop;
1974
1975 prop = dp->prop;
1976
1977 switch (prop->type) {
1978 case PROP_BOOLEAN: {
1979 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop);
1980
1981 if (!(prop->flag & PROP_EDITABLE) &&
1982 (bprop->set || bprop->set_ex || bprop->set_transform || bprop->setarray ||
1983 bprop->setarray_ex || bprop->setarray_transform))
1984 {
1985 CLOG_ERROR(&LOG,
1986 "%s.%s, is read-only but has defines a \"set\" callback.",
1987 srna->identifier.c_str(),
1988 prop->identifier.c_str());
1989 DefRNA.error = true;
1990 }
1991
1992 if (!prop->arraydimension &&
1993 (bprop->getarray || bprop->getarray_ex || bprop->getarray_transform || bprop->setarray ||
1994 bprop->setarray_ex || bprop->setarray_transform))
1995 {
1996 CLOG_ERROR(&LOG,
1997 "%s.%s, is not an array but defines an array callback.",
1998 srna->identifier.c_str(),
1999 prop->identifier.c_str());
2000 DefRNA.error = true;
2001 }
2002
2003 if (!prop->arraydimension) {
2004 if (!bprop->get && !bprop->set && !dp->booleanbit) {
2005 rna_set_raw_property(dp, prop);
2006 }
2007
2008 bprop->get = reinterpret_cast<PropBooleanGetFunc>(rna_def_property_get_func(
2009 f, srna, prop, dp, reinterpret_cast<const char *>(bprop->get)));
2010 bprop->set = reinterpret_cast<PropBooleanSetFunc>(rna_def_property_set_func(
2011 f, srna, prop, dp, reinterpret_cast<const char *>(bprop->set)));
2012 }
2013 else {
2015 f, srna, prop, dp, reinterpret_cast<const char *>(bprop->getarray)));
2017 f, srna, prop, dp, reinterpret_cast<const char *>(bprop->setarray)));
2018 }
2019 break;
2020 }
2021 case PROP_INT: {
2022 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
2023
2024 if (!(prop->flag & PROP_EDITABLE) &&
2025 (iprop->set || iprop->set_ex || iprop->set_transform || iprop->setarray ||
2026 iprop->setarray_ex || iprop->setarray_transform))
2027 {
2028 CLOG_ERROR(&LOG,
2029 "%s.%s, is read-only but has defines a \"set\" callback.",
2030 srna->identifier.c_str(),
2031 prop->identifier.c_str());
2032 DefRNA.error = true;
2033 }
2034
2035 if (!prop->arraydimension &&
2036 (iprop->getarray || iprop->getarray_ex || iprop->getarray_transform || iprop->setarray ||
2037 iprop->setarray_ex || iprop->setarray_transform))
2038 {
2039 CLOG_ERROR(&LOG,
2040 "%s.%s, is not an array but defines an array callback.",
2041 srna->identifier.c_str(),
2042 prop->identifier.c_str());
2043 DefRNA.error = true;
2044 }
2045
2046 if (!prop->arraydimension) {
2047 if (!iprop->get && !iprop->set) {
2048 rna_set_raw_property(dp, prop);
2049 }
2050
2051 iprop->get = reinterpret_cast<PropIntGetFunc>(rna_def_property_get_func(
2052 f, srna, prop, dp, reinterpret_cast<const char *>(iprop->get)));
2053 iprop->set = reinterpret_cast<PropIntSetFunc>(rna_def_property_set_func(
2054 f, srna, prop, dp, reinterpret_cast<const char *>(iprop->set)));
2055 }
2056 else {
2057 if (!iprop->getarray && !iprop->setarray) {
2058 rna_set_raw_property(dp, prop);
2059 }
2060
2061 iprop->getarray = reinterpret_cast<PropIntArrayGetFunc>(rna_def_property_get_func(
2062 f, srna, prop, dp, reinterpret_cast<const char *>(iprop->getarray)));
2063 iprop->setarray = reinterpret_cast<PropIntArraySetFunc>(rna_def_property_set_func(
2064 f, srna, prop, dp, reinterpret_cast<const char *>(iprop->setarray)));
2065 }
2066 break;
2067 }
2068 case PROP_FLOAT: {
2069 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
2070
2071 if (!(prop->flag & PROP_EDITABLE) &&
2072 (fprop->set || fprop->set_ex || fprop->set_transform || fprop->setarray ||
2073 fprop->setarray_ex || fprop->setarray_transform))
2074 {
2075 CLOG_ERROR(&LOG,
2076 "%s.%s, is read-only but has defines a \"set\" callback.",
2077 srna->identifier.c_str(),
2078 prop->identifier.c_str());
2079 DefRNA.error = true;
2080 }
2081
2082 if (!prop->arraydimension &&
2083 (fprop->getarray || fprop->getarray_ex || fprop->getarray_transform || fprop->setarray ||
2084 fprop->setarray_ex || fprop->setarray_transform))
2085 {
2086 CLOG_ERROR(&LOG,
2087 "%s.%s, is not an array but defines an array callback.",
2088 srna->identifier.c_str(),
2089 prop->identifier.c_str());
2090 DefRNA.error = true;
2091 }
2092
2093 if (!prop->arraydimension) {
2094 if (!fprop->get && !fprop->set) {
2095 rna_set_raw_property(dp, prop);
2096 }
2097
2098 fprop->get = reinterpret_cast<PropFloatGetFunc>(rna_def_property_get_func(
2099 f, srna, prop, dp, reinterpret_cast<const char *>(fprop->get)));
2100 fprop->set = reinterpret_cast<PropFloatSetFunc>(rna_def_property_set_func(
2101 f, srna, prop, dp, reinterpret_cast<const char *>(fprop->set)));
2102 }
2103 else {
2104 if (!fprop->getarray && !fprop->setarray) {
2105 rna_set_raw_property(dp, prop);
2106 }
2107
2108 fprop->getarray = reinterpret_cast<PropFloatArrayGetFunc>(rna_def_property_get_func(
2109 f, srna, prop, dp, reinterpret_cast<const char *>(fprop->getarray)));
2110 fprop->setarray = reinterpret_cast<PropFloatArraySetFunc>(rna_def_property_set_func(
2111 f, srna, prop, dp, reinterpret_cast<const char *>(fprop->setarray)));
2112 }
2113 break;
2114 }
2115 case PROP_ENUM: {
2116 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
2117
2118 if (dp->enumbitflags && eprop->item_fn &&
2119 !(eprop->item != rna_enum_dummy_NULL_items || eprop->set || eprop->set_ex ||
2120 eprop->set_transform))
2121 {
2122 CLOG_ERROR(&LOG,
2123 "%s.%s, bitflag enum should not define an `item` callback function, unless "
2124 "they also define a static list of items, or a custom `set` callback.",
2125 srna->identifier.c_str(),
2126 prop->identifier.c_str());
2127 DefRNA.error = true;
2128 }
2129
2130 if (!(prop->flag & PROP_EDITABLE) && (eprop->set || eprop->set_ex || eprop->set_transform)) {
2131 CLOG_ERROR(&LOG,
2132 "%s.%s, is read-only but has defines a \"set\" callback.",
2133 srna->identifier.c_str(),
2134 prop->identifier.c_str());
2135 DefRNA.error = true;
2136 }
2137
2138 if (!eprop->get && !eprop->set) {
2139 rna_set_raw_property(dp, prop);
2140 }
2141
2142 eprop->get = reinterpret_cast<PropEnumGetFunc>(rna_def_property_get_func(
2143 f, srna, prop, dp, reinterpret_cast<const char *>(eprop->get)));
2144 eprop->set = reinterpret_cast<PropEnumSetFunc>(rna_def_property_set_func(
2145 f, srna, prop, dp, reinterpret_cast<const char *>(eprop->set)));
2146 break;
2147 }
2148 case PROP_STRING: {
2149 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop);
2150
2151 if (!(prop->flag & PROP_EDITABLE) && (sprop->set || sprop->set_ex || sprop->set_transform)) {
2152 CLOG_ERROR(&LOG,
2153 "%s.%s, is read-only but has defines a \"set\" callback.",
2154 srna->identifier.c_str(),
2155 prop->identifier.c_str());
2156 DefRNA.error = true;
2157 }
2158
2159 sprop->get = reinterpret_cast<PropStringGetFunc>(rna_def_property_get_func(
2160 f, srna, prop, dp, reinterpret_cast<const char *>(sprop->get)));
2161 sprop->length = reinterpret_cast<PropStringLengthFunc>(rna_def_property_length_func(
2162 f, srna, prop, dp, reinterpret_cast<const char *>(sprop->length)));
2163 sprop->set = reinterpret_cast<PropStringSetFunc>(rna_def_property_set_func(
2164 f, srna, prop, dp, reinterpret_cast<const char *>(sprop->set)));
2166 f, srna, prop, dp, reinterpret_cast<const char *>(sprop->search)));
2167 break;
2168 }
2169 case PROP_POINTER: {
2170 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
2171
2172 if (!(prop->flag & PROP_EDITABLE) && pprop->set) {
2173 CLOG_ERROR(&LOG,
2174 "%s.%s, is read-only but has defines a \"set\" callback.",
2175 srna->identifier.c_str(),
2176 prop->identifier.c_str());
2177 DefRNA.error = true;
2178 }
2179
2180 pprop->get = reinterpret_cast<PropPointerGetFunc>(rna_def_property_get_func(
2181 f, srna, prop, dp, reinterpret_cast<const char *>(pprop->get)));
2182 pprop->set = reinterpret_cast<PropPointerSetFunc>(rna_def_property_set_func(
2183 f, srna, prop, dp, reinterpret_cast<const char *>(pprop->set)));
2184 if (!pprop->pointer_type) {
2185 CLOG_ERROR(&LOG,
2186 "%s.%s, pointer must have a struct type.",
2187 srna->identifier.c_str(),
2188 prop->identifier.c_str());
2189 DefRNA.error = true;
2190 }
2191 break;
2192 }
2193 case PROP_COLLECTION: {
2194 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
2195 const char *nextfunc = reinterpret_cast<const char *>(cprop->next);
2196 const char *item_type = reinterpret_cast<const char *>(cprop->item_type);
2197
2198 if (cprop->length) {
2199 /* always generate if we have a manual implementation */
2201 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->length)));
2202 }
2203 else if (dp->dnatype == "ListBase") {
2204 /* pass */
2205 }
2206 else if (!dp->dnalengthname.is_empty() || dp->dnalengthfixed) {
2208 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->length)));
2209 }
2210
2211 /* test if we can allow raw array access, if it is using our standard
2212 * array get/next function, we can be sure it is an actual array */
2213 if (cprop->next && cprop->get) {
2214 if (STREQ((const char *)cprop->next, "rna_iterator_array_next") &&
2215 STREQ((const char *)cprop->get, "rna_iterator_array_get"))
2216 {
2218 }
2219 }
2220
2221 cprop->get = reinterpret_cast<PropCollectionGetFunc>(rna_def_property_get_func(
2222 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->get)));
2224 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->begin)));
2225 cprop->next = reinterpret_cast<PropCollectionNextFunc>(rna_def_property_next_func(
2226 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->next)));
2227 cprop->end = reinterpret_cast<PropCollectionEndFunc>(rna_def_property_end_func(
2228 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->end)));
2229 cprop->lookupint = reinterpret_cast<PropCollectionLookupIntFunc>(
2231 f, srna, prop, reinterpret_cast<const char *>(cprop->lookupint), nextfunc));
2232 cprop->lookupstring = reinterpret_cast<PropCollectionLookupStringFunc>(
2234 f, srna, prop, dp, reinterpret_cast<const char *>(cprop->lookupstring), item_type));
2235
2236 if (!(prop->flag & PROP_IDPROPERTY)) {
2237 if (!cprop->begin) {
2238 CLOG_ERROR(&LOG,
2239 "%s.%s, collection must have a begin function.",
2240 srna->identifier.c_str(),
2241 prop->identifier.c_str());
2242 DefRNA.error = true;
2243 }
2244 if (!cprop->next) {
2245 CLOG_ERROR(&LOG,
2246 "%s.%s, collection must have a next function.",
2247 srna->identifier.c_str(),
2248 prop->identifier.c_str());
2249 DefRNA.error = true;
2250 }
2251 if (!cprop->get) {
2252 CLOG_ERROR(&LOG,
2253 "%s.%s, collection must have a get function.",
2254 srna->identifier.c_str(),
2255 prop->identifier.c_str());
2256 DefRNA.error = true;
2257 }
2258 }
2259 if (!cprop->item_type) {
2260 CLOG_ERROR(&LOG,
2261 "%s.%s, collection must have a struct type.",
2262 srna->identifier.c_str(),
2263 prop->identifier.c_str());
2264 DefRNA.error = true;
2265 }
2266 break;
2267 }
2268 }
2269}
2270
2272{
2273 if (dp->prop->getlength) {
2274 char funcname[2048];
2276 sizeof(funcname),
2277 dsrna->srna->identifier.c_str(),
2278 dp->prop->identifier.c_str(),
2279 "get_length");
2280 fprintf(f, "int %s(PointerRNA *ptr, int *arraylen)\n", funcname);
2281 fprintf(f, "{\n");
2282 fprintf(f, "\treturn %s(ptr, arraylen);\n", rna_function_string(dp->prop->getlength));
2283 fprintf(f, "}\n\n");
2284 }
2285}
2286
2288{
2289 StructRNA *srna = dsrna->srna;
2290 FunctionRNA *func = dfunc->func;
2291 PropertyDefRNA *dparm;
2292
2293 int first;
2294 char funcname[2048];
2295
2296 if (!dfunc->call) {
2297 return;
2298 }
2299
2301 funcname, sizeof(funcname), srna->identifier.c_str(), func->identifier.c_str(), "func");
2302
2303 rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 0);
2304
2305 fprintf(f, "\n{\n");
2306
2307 if (func->c_ret) {
2308 fprintf(f, "\treturn %s(", dfunc->call);
2309 }
2310 else {
2311 fprintf(f, "\t%s(", dfunc->call);
2312 }
2313
2314 first = 1;
2315
2316 if (func->flag & FUNC_USE_SELF_ID) {
2317 WRITE_PARAM("_selfid");
2318 }
2319
2320 if ((func->flag & FUNC_NO_SELF) == 0) {
2321 WRITE_PARAM("_self");
2322 }
2323 else if (func->flag & FUNC_USE_SELF_TYPE) {
2324 WRITE_PARAM("_type");
2325 }
2326
2327 if (func->flag & FUNC_USE_MAIN) {
2328 WRITE_PARAM("bmain");
2329 }
2330
2331 if (func->flag & FUNC_USE_CONTEXT) {
2332 WRITE_PARAM("C");
2333 }
2334
2335 if (func->flag & FUNC_USE_REPORTS) {
2336 WRITE_PARAM("reports");
2337 }
2338
2339 dparm = dfunc->cont.properties.first();
2340 for (; dparm; dparm = dparm->next) {
2341 if (dparm->prop == func->c_ret) {
2342 continue;
2343 }
2344
2346
2347 if (dparm->prop->flag & PROP_DYNAMIC) {
2348 fprintf(f, "%s, %s_num", dparm->prop->identifier.c_str(), dparm->prop->identifier.c_str());
2349 }
2350 else {
2351 fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
2352 }
2353 }
2354
2355 fprintf(f, ");\n");
2356 fprintf(f, "}\n\n");
2357}
2358
2359static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
2360{
2361 StructRNA *srna;
2362 FunctionRNA *func;
2363 PropertyDefRNA *dparm;
2364 PropertyType type;
2365 const char *funcname, *valstr;
2366 const char *ptrstr;
2367 const bool has_data = (dfunc->cont.properties.first() != nullptr);
2368 int flag, flag_parameter, pout, cptr, first;
2369
2370 srna = dsrna->srna;
2371 func = dfunc->func;
2372
2373 if (!dfunc->call) {
2374 return;
2375 }
2376
2377 funcname = rna_alloc_function_name(srna->identifier.c_str(), func->identifier.c_str(), "call");
2378
2379 /* function definition */
2380 fprintf(
2381 f,
2382 "static void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)",
2383 funcname);
2384 fprintf(f, "\n{\n");
2385
2386 /* variable definitions */
2387
2388 if (func->flag & FUNC_USE_SELF_ID) {
2389 fprintf(f, "\tID *_selfid;\n");
2390 }
2391
2392 if ((func->flag & FUNC_NO_SELF) == 0) {
2393 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
2394 fprintf(f, "\tPointerRNA _self;\n");
2395 }
2396 else if (!dsrna->dnafromprop.is_empty()) {
2397 fprintf(f, "\t%s *_self;\n", dsrna->dnafromname.c_str());
2398 }
2399 else if (!dsrna->dnaname.is_empty()) {
2400 fprintf(f, "\t%s *_self;\n", dsrna->dnaname.c_str());
2401 }
2402 else {
2403 fprintf(f, "\t%s *_self;\n", srna->identifier.c_str());
2404 }
2405 }
2406 else if (func->flag & FUNC_USE_SELF_TYPE) {
2407 fprintf(f, "\tStructRNA *_type;\n");
2408 }
2409
2410 dparm = dfunc->cont.properties.first();
2411 for (; dparm; dparm = dparm->next) {
2412 type = dparm->prop->type;
2413 flag = dparm->prop->flag;
2414 flag_parameter = dparm->prop->flag_parameter;
2415 pout = (flag_parameter & PARM_OUTPUT);
2416 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
2417
2418 if (dparm->prop == func->c_ret) {
2419 ptrstr = cptr || dparm->prop->arraydimension ? "*" : "";
2420 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
2421 }
2422 else if (cptr || (flag & PROP_DYNAMIC)) {
2423 if (type == PROP_STRING) {
2424 ptrstr = pout ? "*" : "";
2425 }
2426 else {
2427 ptrstr = pout ? "**" : "*";
2428 }
2429 /* Fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack,
2430 * pass a pointer to it. */
2431 }
2432 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
2433 ptrstr = "*";
2434 }
2435 else if ((type == PROP_POINTER) && (flag_parameter & PARM_RNAPTR) && !(flag & PROP_THICK_WRAP))
2436 {
2437 ptrstr = "*";
2438 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
2439 * but type name for string props is already (char *), so leave empty */
2440 }
2441 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
2442 ptrstr = "";
2443 }
2444 else {
2445 ptrstr = pout ? "*" : "";
2446 }
2447
2448 /* for dynamic parameters we pass an additional int for the length of the parameter */
2449 if (flag & PROP_DYNAMIC) {
2450 fprintf(f, "\tint %s%s_num;\n", pout ? "*" : "", dparm->prop->identifier.c_str());
2451 }
2452
2453 fprintf(f,
2454 "\t%s%s %s%s;\n",
2455 rna_parameter_is_const(dparm) ? "const " : "",
2457 ptrstr,
2458 rna_safe_id(dparm->prop->identifier));
2459 }
2460
2461 if (has_data) {
2462 fprintf(f, "\tchar *_data");
2463 if (func->c_ret) {
2464 fprintf(f, ", *_retdata");
2465 }
2466 fprintf(f, ";\n");
2467 fprintf(f, "\t\n");
2468 }
2469
2470 /* assign self */
2471 if (func->flag & FUNC_USE_SELF_ID) {
2472 fprintf(f, "\t_selfid = (ID *)_ptr->owner_id;\n");
2473 }
2474
2475 if ((func->flag & FUNC_NO_SELF) == 0) {
2476 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
2477 fprintf(f, "\t_self = *_ptr;\n");
2478 }
2479 else if (!dsrna->dnafromprop.is_empty()) {
2480 fprintf(f, "\t_self = (%s *)_ptr->data;\n", dsrna->dnafromname.c_str());
2481 }
2482 else if (!dsrna->dnaname.is_empty()) {
2483 fprintf(f, "\t_self = (%s *)_ptr->data;\n", dsrna->dnaname.c_str());
2484 }
2485 else {
2486 fprintf(f, "\t_self = (%s *)_ptr->data;\n", srna->identifier.c_str());
2487 }
2488 }
2489 else if (func->flag & FUNC_USE_SELF_TYPE) {
2490 fprintf(f, "\t_type = _ptr->type;\n");
2491 }
2492
2493 if (has_data) {
2494 fprintf(f, "\t_data = (char *)_parms->data;\n");
2495 }
2496
2497 dparm = dfunc->cont.properties.first();
2498 for (; dparm; dparm = dparm->next) {
2499 type = dparm->prop->type;
2500 flag = dparm->prop->flag;
2501 flag_parameter = dparm->prop->flag_parameter;
2502 pout = (flag_parameter & PARM_OUTPUT);
2503 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
2504
2505 if (dparm->prop == func->c_ret) {
2506 fprintf(f, "\t_retdata = _data;\n");
2507 }
2508 else {
2509 const char *data_str;
2510 if (cptr || (flag & PROP_DYNAMIC)) {
2511 if (type == PROP_STRING) {
2512 ptrstr = "*";
2513 valstr = "";
2514 }
2515 else {
2516 ptrstr = "**";
2517 valstr = "*";
2518 }
2519 }
2520 else if ((type == PROP_POINTER) && !(flag & PROP_THICK_WRAP)) {
2521 ptrstr = "**";
2522 valstr = "*";
2523 }
2524 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
2525 ptrstr = "*";
2526 valstr = "";
2527 }
2528 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
2529 ptrstr = "";
2530 valstr = "";
2531 }
2532 else {
2533 ptrstr = "*";
2534 valstr = "*";
2535 }
2536
2537 /* This must be kept in sync with RNA_parameter_dynamic_length_get_data and
2538 * RNA_parameter_get, we could just call the function directly, but this is faster. */
2539 if (flag & PROP_DYNAMIC) {
2540 fprintf(f,
2541 "\t%s_num = %s((ParameterDynAlloc *)_data)->array_tot;\n",
2542 rna_safe_id(dparm->prop->identifier),
2543 pout ? "(int *)&" : "(int)");
2544 data_str = "(&(((ParameterDynAlloc *)_data)->array))";
2545 }
2546 else {
2547 data_str = "_data";
2548 }
2549 fprintf(f, "\t%s = ", rna_safe_id(dparm->prop->identifier));
2550
2551 if (!pout) {
2552 fprintf(f, "%s", valstr);
2553 }
2554
2555 fprintf(f,
2556 "((%s%s %s)%s);\n",
2557 rna_parameter_is_const(dparm) ? "const " : "",
2559 ptrstr,
2560 data_str);
2561 }
2562
2563 if (dparm->next) {
2564 fprintf(f, "\t_data += %d;\n", rna_parameter_size_pad(rna_parameter_size(dparm->prop)));
2565 }
2566 }
2567
2568 if (dfunc->call) {
2569 fprintf(f, "\t\n");
2570 fprintf(f, "\t");
2571 if (func->c_ret) {
2572 fprintf(f, "%s = ", func->c_ret->identifier.c_str());
2573 }
2574 fprintf(f, "%s(", dfunc->call);
2575
2576 first = 1;
2577
2578 if (func->flag & FUNC_USE_SELF_ID) {
2579 fprintf(f, "_selfid");
2580 first = 0;
2581 }
2582
2583 if ((func->flag & FUNC_NO_SELF) == 0) {
2584 if (!first) {
2585 fprintf(f, ", ");
2586 }
2587 fprintf(f, "_self");
2588 first = 0;
2589 }
2590 else if (func->flag & FUNC_USE_SELF_TYPE) {
2591 if (!first) {
2592 fprintf(f, ", ");
2593 }
2594 fprintf(f, "_type");
2595 first = 0;
2596 }
2597
2598 if (func->flag & FUNC_USE_MAIN) {
2599 if (!first) {
2600 fprintf(f, ", ");
2601 }
2602 first = 0;
2603 fprintf(f, "CTX_data_main(C)"); /* may have direct access later */
2604 }
2605
2606 if (func->flag & FUNC_USE_CONTEXT) {
2607 if (!first) {
2608 fprintf(f, ", ");
2609 }
2610 first = 0;
2611 fprintf(f, "C");
2612 }
2613
2614 if (func->flag & FUNC_USE_REPORTS) {
2615 if (!first) {
2616 fprintf(f, ", ");
2617 }
2618 first = 0;
2619 fprintf(f, "reports");
2620 }
2621
2622 dparm = dfunc->cont.properties.first();
2623 for (; dparm; dparm = dparm->next) {
2624 if (dparm->prop == func->c_ret) {
2625 continue;
2626 }
2627
2628 if (!first) {
2629 fprintf(f, ", ");
2630 }
2631 first = 0;
2632
2633 if (dparm->prop->flag & PROP_DYNAMIC) {
2634 fprintf(f,
2635 "%s, %s_num",
2636 rna_safe_id(dparm->prop->identifier),
2637 rna_safe_id(dparm->prop->identifier));
2638 }
2639 else {
2640 fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
2641 }
2642 }
2643
2644 fprintf(f, ");\n");
2645
2646 if (func->c_ret) {
2647 dparm = rna_find_parameter_def(func->c_ret);
2648 if ((dparm->prop->type == PROP_POINTER) && (dparm->prop->flag_parameter & PARM_RNAPTR) &&
2649 (dparm->prop->flag & PROP_THICK_WRAP))
2650 {
2651 const char *parameter_type_name = rna_parameter_type_name(dparm->prop);
2652 fprintf(f,
2653 "\t*reinterpret_cast<%s *>(_retdata) = %s;\n",
2654 parameter_type_name,
2655 func->c_ret->identifier.c_str());
2656 }
2657 else {
2658 ptrstr = (((dparm->prop->type == PROP_POINTER) &&
2659 !(dparm->prop->flag_parameter & PARM_RNAPTR)) ||
2660 (dparm->prop->arraydimension)) ?
2661 "*" :
2662 "";
2663 if (dparm->prop->type == PROP_COLLECTION) {
2664 /* Placement new is necessary because #ParameterList::data is not initialized. */
2665 fprintf(f,
2666 "\tnew ((CollectionVector *)_retdata) CollectionVector(std::move(%s));\n",
2667 func->c_ret->identifier.c_str());
2668 }
2669 else {
2670 fprintf(f,
2671 "\t*((%s %s*)_retdata) = %s;\n",
2673 ptrstr,
2674 func->c_ret->identifier.c_str());
2675 }
2676 }
2677 }
2678 }
2679
2680 fprintf(f, "}\n\n");
2681
2682 dfunc->gencall = funcname;
2683}
2684
2685static void rna_sanity_checks()
2686{
2687 /* Ensure RNA enum definitions follow naming convention. */
2688 {
2689#define DEF_ENUM(id) #id,
2690 const char *rna_enum_id_array[] = {
2691#include "RNA_enum_items.hh"
2692 };
2693 for (int i = 0; i < ARRAY_SIZE(rna_enum_id_array); i++) {
2694 if (!(BLI_str_startswith(rna_enum_id_array[i], "rna_enum_") &&
2695 BLI_str_endswith(rna_enum_id_array[i], "_items")))
2696 {
2697 fprintf(stderr,
2698 "Error: enum defined in \"RNA_enum_items.hh\" "
2699 "doesn't confirm to \"rna_enum_*_items\" convention!\n");
2700 DefRNA.error = true;
2701 }
2702 }
2703 }
2704}
2705
2706static void rna_auto_types()
2707{
2708 StructDefRNA *ds;
2709
2710 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
2711 /* DNA name for Screen is patched in 2.5, we do the reverse here. */
2712 if (!ds->dnaname.is_empty()) {
2713 if (ds->dnaname == "Screen") {
2714 ds->dnaname = "bScreen";
2715 }
2716 if (ds->dnaname == "Group") {
2717 ds->dnaname = "Collection";
2718 }
2719 if (ds->dnaname == "GroupObject") {
2720 ds->dnaname = "CollectionObject";
2721 }
2722 }
2723
2724 for (PropertyDefRNA &dp : ds->cont.properties) {
2725 if (!dp.dnastructname.is_empty()) {
2726 if (dp.dnastructname == "Screen") {
2727 dp.dnastructname = "bScreen";
2728 }
2729 if (dp.dnastructname == "Group") {
2730 dp.dnastructname = "Collection";
2731 }
2732 if (dp.dnastructname == "GroupObject") {
2733 dp.dnastructname = "CollectionObject";
2734 }
2735 }
2736
2737 if (!dp.dnatype.is_empty()) {
2738 if (dp.prop->type == PROP_POINTER) {
2739 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(dp.prop);
2740 StructRNA *type;
2741
2742 if (!pprop->pointer_type && !pprop->get) {
2743 pprop->pointer_type = reinterpret_cast<StructRNA *>(
2744 const_cast<char *>(rna_find_type(dp.dnatype.c_str())));
2745 }
2746
2747 /* Only automatically define `PROP_ID_REFCOUNT` if it was not already explicitly set or
2748 * cleared by calls to `RNA_def_property_flag` or `RNA_def_property_clear_flag`. */
2750 pprop->pointer_type)
2751 {
2752 type = rna_find_struct(reinterpret_cast<const char *>(pprop->pointer_type));
2753 if (type && (type->flag & STRUCT_ID_REFCOUNT)) {
2754 pprop->flag |= PROP_ID_REFCOUNT;
2755 }
2756 }
2757 }
2758 else if (dp.prop->type == PROP_COLLECTION) {
2759 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(dp.prop);
2760
2761 if (!cprop->item_type && !cprop->get && dp.dnatype == "ListBase") {
2762 cprop->item_type = reinterpret_cast<StructRNA *>(
2763 const_cast<char *>(rna_find_type(dp.dnatype.c_str())));
2764 }
2765 }
2766 }
2767 }
2768 }
2769}
2770
2772{
2773 switch (type) {
2774 case PROP_BOOLEAN:
2775 return "BoolPropertyRNA";
2776 case PROP_INT:
2777 return "IntPropertyRNA";
2778 case PROP_FLOAT:
2779 return "FloatPropertyRNA";
2780 case PROP_STRING:
2781 return "StringPropertyRNA";
2782 case PROP_ENUM:
2783 return "EnumPropertyRNA";
2784 case PROP_POINTER:
2785 return "PointerPropertyRNA";
2786 case PROP_COLLECTION:
2787 return "CollectionPropertyRNA";
2788 default:
2789 return "UnknownPropertyRNA";
2790 }
2791}
2792
2794{
2795 switch (type) {
2796 case PROP_NONE:
2797 return "PROP_NONE";
2798 case PROP_FILEPATH:
2799 return "PROP_FILEPATH";
2800 case PROP_FILENAME:
2801 return "PROP_FILENAME";
2802 case PROP_DIRPATH:
2803 return "PROP_DIRPATH";
2804 case PROP_PIXEL:
2805 return "PROP_PIXEL";
2807 return "PROP_PIXEL_DIAMETER";
2808 case PROP_BYTESTRING:
2809 return "PROP_BYTESTRING";
2810 case PROP_UNSIGNED:
2811 return "PROP_UNSIGNED";
2812 case PROP_PERCENTAGE:
2813 return "PROP_PERCENTAGE";
2814 case PROP_FACTOR:
2815 return "PROP_FACTOR";
2816 case PROP_MASS:
2817 return "PROP_MASS";
2818 case PROP_ANGLE:
2819 return "PROP_ANGLE";
2820 case PROP_TIME:
2821 return "PROP_TIME";
2822 case PROP_TIME_ABSOLUTE:
2823 return "PROP_TIME_ABSOLUTE";
2824 case PROP_DISTANCE:
2825 return "PROP_DISTANCE";
2827 return "PROP_DISTANCE_DIAMETER";
2829 return "PROP_DISTANCE_CAMERA";
2830 case PROP_COLOR:
2831 return "PROP_COLOR";
2832 case PROP_TRANSLATION:
2833 return "PROP_TRANSLATION";
2834 case PROP_DIRECTION:
2835 return "PROP_DIRECTION";
2836 case PROP_MATRIX:
2837 return "PROP_MATRIX";
2838 case PROP_EULER:
2839 return "PROP_EULER";
2840 case PROP_QUATERNION:
2841 return "PROP_QUATERNION";
2842 case PROP_AXISANGLE:
2843 return "PROP_AXISANGLE";
2844 case PROP_VELOCITY:
2845 return "PROP_VELOCITY";
2846 case PROP_ACCELERATION:
2847 return "PROP_ACCELERATION";
2848 case PROP_XYZ:
2849 return "PROP_XYZ";
2850 case PROP_COLOR_GAMMA:
2851 return "PROP_COLOR_GAMMA";
2852 case PROP_COORDS:
2853 return "PROP_COORDS";
2854 case PROP_LAYER:
2855 return "PROP_LAYER";
2856 case PROP_LAYER_MEMBER:
2857 return "PROP_LAYER_MEMBER";
2858 case PROP_PASSWORD:
2859 return "PROP_PASSWORD";
2860 case PROP_POWER:
2861 return "PROP_POWER";
2862 case PROP_TEMPERATURE:
2863 return "PROP_TEMPERATURE";
2864 case PROP_WAVELENGTH:
2865 return "PROP_WAVELENGTH";
2867 return "PROP_COLOR_TEMPERATURE";
2868 case PROP_FREQUENCY:
2869 return "PROP_FREQUENCY";
2870 default: {
2871 /* in case we don't have a type preset that includes the subtype */
2872 if (RNA_SUBTYPE_UNIT(type)) {
2874 }
2875 return "PROP_SUBTYPE_UNKNOWN";
2876 }
2877 }
2878}
2879
2881{
2882 switch (RNA_SUBTYPE_UNIT(type)) {
2883 case PROP_UNIT_NONE:
2884 return "PROP_UNIT_NONE";
2885 case PROP_UNIT_LENGTH:
2886 return "PROP_UNIT_LENGTH";
2887 case PROP_UNIT_AREA:
2888 return "PROP_UNIT_AREA";
2889 case PROP_UNIT_VOLUME:
2890 return "PROP_UNIT_VOLUME";
2891 case PROP_UNIT_MASS:
2892 return "PROP_UNIT_MASS";
2893 case PROP_UNIT_ROTATION:
2894 return "PROP_UNIT_ROTATION";
2895 case PROP_UNIT_TIME:
2896 return "PROP_UNIT_TIME";
2898 return "PROP_UNIT_TIME_ABSOLUTE";
2899 case PROP_UNIT_VELOCITY:
2900 return "PROP_UNIT_VELOCITY";
2902 return "PROP_UNIT_ACCELERATION";
2903 case PROP_UNIT_CAMERA:
2904 return "PROP_UNIT_CAMERA";
2905 case PROP_UNIT_POWER:
2906 return "PROP_UNIT_POWER";
2908 return "PROP_UNIT_TEMPERATURE";
2910 return "PROP_UNIT_WAVELENGTH";
2912 return "PROP_UNIT_COLOR_TEMPERATURE";
2914 return "PROP_UNIT_FREQUENCY";
2915 default:
2916 return "PROP_UNIT_UNKNOWN";
2917 }
2918}
2919
2921{
2922 for (const std::unique_ptr<StructRNA> &srna : brna->structs) {
2923 fprintf(f, "extern struct StructRNA *RNA_%s;\n", srna->identifier.c_str());
2924 }
2925}
2926
2928{
2929 fprintf(f, "struct BlenderRNA;\n");
2930 for (const std::unique_ptr<StructRNA> &srna : brna->structs) {
2931 fprintf(f, "void register_struct_%s(BlenderRNA &brna);\n", srna->identifier.c_str());
2932 }
2933}
2934
2935static void rna_generate_blender(BlenderRNA *brna, FILE *f)
2936{
2937 fprintf(f,
2938 "BlenderRNA rna_blender_rna_create()\n"
2939 "{\n"
2940 "\tBlenderRNA brna{};\n");
2941
2942 /* Allocate the structs before creating their definitions, so they can reference each other out
2943 * of their definition order.*/
2944 fprintf(f, "\tbrna.structs.resize(%d);\n", int(brna->structs.size()));
2945 fprintf(f,
2946 "\tfor (const int i : brna.structs.index_range()) {\n"
2947 "\t\tbrna.structs[i] = std::make_unique<StructRNA>();\n"
2948 "\t}\n");
2949 for (const int i : brna->structs.index_range()) {
2950 fprintf(f, "\tRNA_%s = brna.structs[%d].get();\n", brna->structs[i]->identifier.c_str(), i);
2951 }
2952
2953 for (std::unique_ptr<StructRNA> &srna : brna->structs) {
2954 fprintf(f, "\tregister_struct_%s(brna);\n", srna->identifier.c_str());
2955 }
2956 fprintf(f,
2957 "\treturn brna;\n"
2958 "}\n");
2959 fprintf(f,
2960 "BlenderRNA &RNA_blender_rna_get()\n"
2961 "{\n"
2962 "\tstatic BlenderRNA BLENDER_RNA = rna_blender_rna_create();\n");
2963 /* structs_map is created by RNA_init(). */
2964 fprintf(f,
2965 "\treturn BLENDER_RNA;\n"
2966 "}\n\n");
2967}
2968
2970{
2971 fprintf(f, "struct PropertyRNA;\n");
2972 fprintf(f, "struct StructRNA;\n\n");
2973
2975
2976 /* NOTE: Generate generic `PropertyRNA &` references. The actual, type-refined properties data
2977 * are static variables in their translation units (the `_gen.cc` files), which are assigned to
2978 * these public generic `PointerRNA &` references. */
2979 for (std::unique_ptr<StructRNA> &srna : brna->structs) {
2980 for (PropertyRNA &prop : srna->cont.properties) {
2981 fprintf(f,
2982 "extern PropertyRNA &rna_%s_%s;\n",
2983 srna->identifier.c_str(),
2984 prop.identifier.c_str());
2985 }
2986 fprintf(f, "\n");
2987 }
2988}
2989
2991 StructRNA *srna,
2992 FILE *f)
2993{
2994 StructRNA *base;
2995
2996 /* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
2997 * comments for details. */
2998 base = srna->base;
2999 while (base) {
3000 fprintf(f, "\n");
3001 for (PropertyRNA &prop : base->cont.properties) {
3002 fprintf(f,
3003 "extern PropertyRNA &rna_%s_%s;\n",
3004 base->identifier.c_str(),
3005 prop.identifier.c_str());
3006 }
3007 base = base->base;
3008 }
3009
3010 if (srna->cont.properties.first()) {
3011 fprintf(f, "\n");
3012 }
3013
3014 for (PropertyRNA &prop : srna->cont.properties) {
3015 fprintf(
3016 f, "extern PropertyRNA &rna_%s_%s;\n", srna->identifier.c_str(), prop.identifier.c_str());
3017 }
3018 fprintf(f, "\n");
3019}
3020
3022 StructRNA *srna,
3023 FunctionRNA *func,
3024 FILE *f)
3025{
3026 /* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
3027 * comments for details. */
3028 for (PropertyRNA &parm : func->cont.properties) {
3029 fprintf(f,
3030 "extern PropertyRNA &rna_%s_%s_%s;\n",
3031 srna->identifier.c_str(),
3032 func->identifier.c_str(),
3033 parm.identifier.c_str());
3034 }
3035
3036 if (func->cont.properties.first()) {
3037 fprintf(f, "\n");
3038 }
3039}
3040
3042{
3043 StructRNA *base;
3044
3045 base = srna->base;
3046 while (base) {
3047 for (const std::unique_ptr<FunctionRNA> &func : base->functions) {
3048 fprintf(f,
3049 "extern FunctionRNA *rna_%s_%s_func;\n",
3050 base->identifier.c_str(),
3051 func->identifier.c_str());
3052 rna_generate_parameter_prototypes(brna, base, func.get(), f);
3053 }
3054
3055 if (!base->functions.is_empty()) {
3056 fprintf(f, "\n");
3057 }
3058
3059 base = base->base;
3060 }
3061
3062 for (const std::unique_ptr<FunctionRNA> &func : srna->functions) {
3063 fprintf(f,
3064 "extern FunctionRNA *rna_%s_%s_func;\n",
3065 srna->identifier.c_str(),
3066 func->identifier.c_str());
3067 rna_generate_parameter_prototypes(brna, srna, func.get(), f);
3068 }
3069
3070 if (!srna->functions.is_empty()) {
3071 fprintf(f, "\n");
3072 }
3073}
3074
3076 StructRNA *srna,
3077 FunctionDefRNA *dfunc,
3078 const char *name_override,
3079 int close_prototype)
3080{
3081 FunctionRNA *func;
3082 PropertyDefRNA *dparm_return = nullptr;
3083 StructDefRNA *dsrna;
3084 PropertyType type;
3085 int flag, flag_parameter, pout, cptr, first;
3086 const char *ptrstr;
3087
3088 dsrna = rna_find_struct_def(srna);
3089 func = dfunc->func;
3090
3091 /* return type */
3092 for (PropertyDefRNA &dparm : dfunc->cont.properties) {
3093 if (dparm.prop == func->c_ret) {
3094 if (dparm.prop->arraydimension) {
3095 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
3096 }
3097 else if (dparm.prop->type == PROP_POINTER && !(dparm.prop->flag_parameter & PARM_RNAPTR)) {
3098 fprintf(f, "%s *", rna_parameter_type_name(dparm.prop));
3099 }
3100 else {
3101 fprintf(f, "%s ", rna_parameter_type_name(dparm.prop));
3102 }
3103
3104 dparm_return = &dparm;
3105 break;
3106 }
3107 }
3108
3109 /* void if nothing to return */
3110 if (!dparm_return) {
3111 fprintf(f, "void ");
3112 }
3113
3114 /* function name */
3115 if (name_override == nullptr || name_override[0] == '\0') {
3116 fprintf(f, "%s(", dfunc->call);
3117 }
3118 else {
3119 fprintf(f, "%s(", name_override);
3120 }
3121
3122 first = 1;
3123
3124 /* self, context and reports parameters */
3125 if (func->flag & FUNC_USE_SELF_ID) {
3126 fprintf(f, "ID *_selfid");
3127 first = 0;
3128 }
3129
3130 if ((func->flag & FUNC_NO_SELF) == 0) {
3131 if (!first) {
3132 fprintf(f, ", ");
3133 }
3134 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
3135 fprintf(f, "PointerRNA _self");
3136 }
3137 else if (!dsrna->dnafromprop.is_empty()) {
3138 fprintf(f, "%s *_self", dsrna->dnafromname.c_str());
3139 }
3140 else if (!dsrna->dnaname.is_empty()) {
3141 fprintf(f, "%s *_self", dsrna->dnaname.c_str());
3142 }
3143 else {
3144 fprintf(f, "%s *_self", srna->identifier.c_str());
3145 }
3146 first = 0;
3147 }
3148 else if (func->flag & FUNC_USE_SELF_TYPE) {
3149 if (!first) {
3150 fprintf(f, ", ");
3151 }
3152 fprintf(f, "StructRNA *_type");
3153 first = 0;
3154 }
3155
3156 if (func->flag & FUNC_USE_MAIN) {
3157 if (!first) {
3158 fprintf(f, ", ");
3159 }
3160 first = 0;
3161 fprintf(f, "Main *bmain");
3162 }
3163
3164 if (func->flag & FUNC_USE_CONTEXT) {
3165 if (!first) {
3166 fprintf(f, ", ");
3167 }
3168 first = 0;
3169 fprintf(f, "bContext *C");
3170 }
3171
3172 if (func->flag & FUNC_USE_REPORTS) {
3173 if (!first) {
3174 fprintf(f, ", ");
3175 }
3176 first = 0;
3177 fprintf(f, "ReportList *reports");
3178 }
3179
3180 /* defined parameters */
3181 for (PropertyDefRNA &dparm : dfunc->cont.properties) {
3182 type = dparm.prop->type;
3183 flag = dparm.prop->flag;
3184 flag_parameter = dparm.prop->flag_parameter;
3185 pout = (flag_parameter & PARM_OUTPUT);
3186 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
3187
3188 if (dparm.prop == func->c_ret) {
3189 continue;
3190 }
3191
3192 if (cptr || (flag & PROP_DYNAMIC)) {
3193 if (type == PROP_STRING) {
3194 ptrstr = pout ? "*" : "";
3195 }
3196 else {
3197 ptrstr = pout ? "**" : "*";
3198 }
3199 }
3200 else if (type == PROP_POINTER || dparm.prop->arraydimension) {
3201 ptrstr = "*";
3202 }
3203 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
3204 ptrstr = "";
3205 }
3206 else {
3207 ptrstr = pout ? "*" : "";
3208 }
3209
3210 if (!first) {
3211 fprintf(f, ", ");
3212 }
3213 first = 0;
3214
3215 if (flag & PROP_DYNAMIC) {
3216 fprintf(f, "int %s%s_num, ", pout ? "*" : "", dparm.prop->identifier.c_str());
3217 }
3218
3219 if (!(flag & PROP_DYNAMIC) && dparm.prop->arraydimension) {
3220 fprintf(f,
3221 "%s %s[%u]",
3223 rna_safe_id(dparm.prop->identifier),
3224 dparm.prop->totarraylength);
3225 }
3226 else {
3227 fprintf(f,
3228 "%s %s%s",
3230 ptrstr,
3231 rna_safe_id(dparm.prop->identifier));
3232 }
3233 }
3234
3235 /* ensure func(void) if there are no args */
3236 if (first) {
3237 fprintf(f, "void");
3238 }
3239
3240 fprintf(f, ")");
3241
3242 if (close_prototype) {
3243 fprintf(f, ";\n");
3244 }
3245}
3246
3248 StructRNA *srna,
3249 FILE *f)
3250{
3251 FunctionDefRNA *dfunc;
3252 int first = 1;
3253
3254 for (const std::unique_ptr<FunctionRNA> &func : srna->functions) {
3255 dfunc = rna_find_function_def(func.get());
3256
3257 if (dfunc->call) {
3258 if (strstr(dfunc->call, "<")) {
3259 /* Can't generate the declaration for templates. We'll still get compile errors when trying
3260 * to call it with a wrong signature. */
3261 continue;
3262 }
3263
3264 if (first) {
3265 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
3266 first = 0;
3267 }
3268
3269 rna_generate_static_parameter_prototypes(f, srna, dfunc, nullptr, 1);
3270 }
3271 }
3272
3273 fprintf(f, "\n");
3274}
3275
3276static void rna_generate_property_decl(FILE *f,
3277 StructRNA *srna,
3278 const char *nest,
3279 PropertyRNA *prop)
3280{
3281 char *strnest = (char *)"", *errnest = (char *)"";
3282 bool freenest = false;
3283
3284 if (nest != nullptr) {
3285 size_t len = strlen(nest);
3286
3287 strnest = MEM_new_array_uninitialized<char>(len + 2, "rna_generate_property -> strnest");
3288 errnest = MEM_new_array_uninitialized<char>(len + 2, "rna_generate_property -> errnest");
3289
3290 strnest[0] = '_';
3291 memcpy(strnest + 1, nest, len + 1);
3292
3293 errnest[0] = '.';
3294 memcpy(errnest + 1, nest, len + 1);
3295
3296 freenest = true;
3297 }
3298
3299 /* Generate the RNA-private, type-refined property data.
3300 *
3301 * See #rna_generate_external_property_prototypes comments for details. */
3302 fprintf(f,
3303 "static %s rna_%s%s_%s_;\n",
3305 srna->identifier.c_str(),
3306 strnest,
3307 prop->identifier.c_str());
3308
3309 /* Assign the RNA-private, type-refined static (local) property data to the public matching
3310 * generic `PropertyRNA &` reference.
3311 *
3312 * See #rna_generate_external_property_prototypes comments for details. */
3313 fprintf(
3314 f,
3315 /* Use a reference here instead of a pointer, because pointer usage somehow makes clang
3316 * optimizer take a very long time to compile the `rna_xxx_gen.cc` files (see faf56cc3bf).
3317 *
3318 * Note that in theory, any access to the 'public' `PointerRNA &` reference data is
3319 * undefined behavior (strict aliasing rules). This is currently not a real issue (these
3320 * PropertyRNA definitions are almost always only used as pointers, and are currently POD
3321 * types).
3322 *
3323 * `reinterpret_cast<PropertyRNA &>(rna_prop_data)` here is same as
3324 * `*reinterpret_cast<PropertyRNA *>(&rna_prop_data)` (see point (6) of
3325 * https://en.cppreference.com/w/cpp/language/reinterpret_cast). */
3326 "PropertyRNA &rna_%s%s_%s = reinterpret_cast<PropertyRNA &>(rna_%s%s_%s_);\n\n",
3327 srna->identifier.c_str(),
3328 strnest,
3329 prop->identifier.c_str(),
3330 srna->identifier.c_str(),
3331 strnest,
3332 prop->identifier.c_str());
3333
3334 if (freenest) {
3335 MEM_delete(strnest);
3336 MEM_delete(errnest);
3337 }
3338}
3339
3340static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
3341{
3342 char *strnest = const_cast<char *>(""), *errnest = const_cast<char *>("");
3343 bool freenest = false;
3344
3345 if (nest != nullptr) {
3346 size_t len = strlen(nest);
3347
3348 strnest = MEM_new_array_uninitialized<char>(len + 2, "rna_generate_property -> strnest");
3349 errnest = MEM_new_array_uninitialized<char>(len + 2, "rna_generate_property -> errnest");
3350
3351 strnest[0] = '_';
3352 memcpy(strnest + 1, nest, len + 1);
3353
3354 errnest[0] = '.';
3355 memcpy(errnest + 1, nest, len + 1);
3356
3357 freenest = true;
3358 }
3359
3360 if (prop->deprecated) {
3361 fprintf(f,
3362 "\tstatic const DeprecatedRNA rna_%s%s_%s_deprecated = {\n\t",
3363 srna->identifier.c_str(),
3364 strnest,
3365 prop->identifier.c_str());
3367 fprintf(f, ",\n\t\t%d, %d,\n", prop->deprecated->version, prop->deprecated->removal_version);
3368 fprintf(f, "};\n\n");
3369 }
3370
3371 switch (prop->type) {
3372 case PROP_ENUM: {
3373 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
3374 int i, defaultfound = 0, totflag = 0;
3375
3376 if (eprop->item) {
3377 /* Inline the enum if this is not a defined in "RNA_enum_items.hh". */
3378 const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
3379 if (item_global_id == nullptr) {
3380 fprintf(f,
3381 "\tstatic const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t\t",
3382 srna->identifier.c_str(),
3383 strnest,
3384 prop->identifier.c_str(),
3385 eprop->totitem + 1);
3386
3387 for (i = 0; i < eprop->totitem; i++) {
3388 fprintf(f, "{%d, ", eprop->item[i].value);
3389 rna_print_c_string(f, eprop->item[i].identifier);
3390 fprintf(f, ", ");
3391 fprintf(f, "%d, ", eprop->item[i].icon);
3392 rna_print_c_string(f, eprop->item[i].name);
3393 fprintf(f, ", ");
3394 rna_print_c_string(f, eprop->item[i].description);
3395 fprintf(f, "\t},\n\t\t");
3396
3397 if (eprop->item[i].identifier[0]) {
3398 if (prop->flag & PROP_ENUM_FLAG) {
3399 totflag |= eprop->item[i].value;
3400 }
3401 else {
3402 if (eprop->defaultvalue == eprop->item[i].value) {
3403 defaultfound = 1;
3404 }
3405 }
3406 }
3407 }
3408
3409 fprintf(f, "\t{0, nullptr, 0, nullptr, nullptr}\n\t};\n");
3410 }
3411 else {
3412 for (i = 0; i < eprop->totitem; i++) {
3413 if (eprop->item[i].identifier[0]) {
3414 if (prop->flag & PROP_ENUM_FLAG) {
3415 totflag |= eprop->item[i].value;
3416 }
3417 else {
3418 if (eprop->defaultvalue == eprop->item[i].value) {
3419 defaultfound = 1;
3420 }
3421 }
3422 }
3423 }
3424 }
3425
3426 if (prop->flag & PROP_ENUM_FLAG) {
3427 if (eprop->defaultvalue & ~totflag) {
3428 CLOG_ERROR(&LOG,
3429 "%s%s.%s, enum default includes unused bits (%d).",
3430 srna->identifier.c_str(),
3431 errnest,
3432 prop->identifier.c_str(),
3433 eprop->defaultvalue & ~totflag);
3434 DefRNA.error = true;
3435 }
3436 }
3437 else {
3438 if (!defaultfound && !(eprop->item_fn && eprop->item == rna_enum_dummy_NULL_items)) {
3439 CLOG_ERROR(&LOG,
3440 "%s%s.%s, enum default '%d' is not in items.",
3441 srna->identifier.c_str(),
3442 errnest,
3443 prop->identifier.c_str(),
3444 eprop->defaultvalue);
3445 DefRNA.error = true;
3446 }
3447 }
3448 }
3449 else {
3450 CLOG_ERROR(&LOG,
3451 "%s%s.%s, enum must have items defined.",
3452 srna->identifier.c_str(),
3453 errnest,
3454 prop->identifier.c_str());
3455 DefRNA.error = true;
3456 }
3457 break;
3458 }
3459 case PROP_BOOLEAN: {
3460 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop);
3461 uint i;
3462
3463 if (prop->arraydimension && prop->totarraylength) {
3464 fprintf(f,
3465 "\tstatic bool rna_%s%s_%s_default[%u] = {\n\t\t",
3466 srna->identifier.c_str(),
3467 strnest,
3468 prop->identifier.c_str(),
3469 prop->totarraylength);
3470
3471 for (i = 0; i < prop->totarraylength; i++) {
3472 if (bprop->defaultarray) {
3473 fprintf(f, "%d", bprop->defaultarray[i]);
3474 }
3475 else {
3476 fprintf(f, "%d", bprop->defaultvalue);
3477 }
3478 if (i != prop->totarraylength - 1) {
3479 fprintf(f, ",\n\t\t");
3480 }
3481 }
3482
3483 fprintf(f, "\n\t};\n");
3484 }
3485 break;
3486 }
3487 case PROP_INT: {
3488 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
3489 uint i;
3490
3491 if (prop->arraydimension && prop->totarraylength) {
3492 fprintf(f,
3493 "\tstatic int rna_%s%s_%s_default[%u] = {\n\t\t",
3494 srna->identifier.c_str(),
3495 strnest,
3496 prop->identifier.c_str(),
3497 prop->totarraylength);
3498
3499 for (i = 0; i < prop->totarraylength; i++) {
3500 if (iprop->defaultarray) {
3501 fprintf(f, "%d", iprop->defaultarray[i]);
3502 }
3503 else {
3504 fprintf(f, "%d", iprop->defaultvalue);
3505 }
3506 if (i != prop->totarraylength - 1) {
3507 fprintf(f, ",\n\t\t");
3508 }
3509 }
3510
3511 fprintf(f, "\n\t};\n");
3512 }
3513 break;
3514 }
3515 case PROP_FLOAT: {
3516 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
3517 uint i;
3518
3519 if (prop->arraydimension && prop->totarraylength) {
3520 fprintf(f,
3521 "\tstatic float rna_%s%s_%s_default[%u] = {\n\t\t",
3522 srna->identifier.c_str(),
3523 strnest,
3524 prop->identifier.c_str(),
3525 prop->totarraylength);
3526
3527 for (i = 0; i < prop->totarraylength; i++) {
3528 if (fprop->defaultarray) {
3529 rna_float_print(f, fprop->defaultarray[i]);
3530 }
3531 else {
3532 rna_float_print(f, fprop->defaultvalue);
3533 }
3534 if (i != prop->totarraylength - 1) {
3535 fprintf(f, ",\n\t\t");
3536 }
3537 }
3538
3539 fprintf(f, "\n\t};\n");
3540 }
3541 break;
3542 }
3543 case PROP_POINTER: {
3544 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
3545
3546 /* XXX This systematically enforces that flag on ID pointers...
3547 * we'll probably have to revisit. :/ */
3548 StructRNA *type = rna_find_struct(reinterpret_cast<const char *>(pprop->pointer_type));
3549 if (type && (type->flag & STRUCT_ID) &&
3551 {
3553 }
3554 break;
3555 }
3556 case PROP_COLLECTION: {
3557 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
3558
3559 /* XXX This systematically enforces that flag on ID pointers...
3560 * we'll probably have to revisit. :/ */
3561 StructRNA *type = rna_find_struct(reinterpret_cast<const char *>(cprop->item_type));
3562 if (type && (type->flag & STRUCT_ID) &&
3564 {
3566 }
3567 break;
3568 }
3569 default:
3570 break;
3571 }
3572
3573 fprintf(f, "\trna_%s%s_%s_ = {\n", srna->identifier.c_str(), strnest, prop->identifier.c_str());
3574
3575 if (prop->next) {
3576 fprintf(f,
3577 "\t\t{&rna_%s%s_%s, ",
3578 srna->identifier.c_str(),
3579 strnest,
3580 prop->next->identifier.c_str());
3581 }
3582 else {
3583 fprintf(f, "\t\t{nullptr, ");
3584 }
3585 if (prop->prev) {
3586 fprintf(
3587 f, "\t&rna_%s%s_%s,\n", srna->identifier.c_str(), strnest, prop->prev->identifier.c_str());
3588 }
3589 else {
3590 fprintf(f, "\tnullptr,\n");
3591 }
3592 fprintf(f, "\t\t%d, ", prop->magic);
3594 fprintf(f,
3595 "_ustr, PropertyFlag(%u), PropertyOverrideFlag(%d), ParameterFlag(%d), "
3596 "PropertyFlagIntern(%d), %d, ",
3597 prop->flag,
3598 prop->flag_override,
3599 prop->flag_parameter,
3600 prop->flag_internal,
3601 prop->tags);
3602 fprintf(f, "PropertyPathTemplateType(%d), ", prop->path_template_type);
3603 rna_print_c_string(f, prop->name);
3604 fprintf(f, ",\n\t\t");
3606 fprintf(f, ",\n\t\t");
3607 fprintf(f, "%d, ", prop->icon);
3609 fprintf(f, ",\n\t\t");
3610
3611 if (prop->deprecated) {
3612 fprintf(f,
3613 "&rna_%s%s_%s_deprecated,",
3614 srna->identifier.c_str(),
3615 strnest,
3616 prop->identifier.c_str());
3617 }
3618 else {
3619 fprintf(f, "nullptr,\n");
3620 }
3621
3622 fprintf(f,
3623 "\t\t%s, PropertySubType(int(%s) | int(%s)), %s, %u, {%u, %u, %u}, %u,\n",
3628 prop->arraydimension,
3629 prop->arraylength[0],
3630 prop->arraylength[1],
3631 prop->arraylength[2],
3632 prop->totarraylength);
3633 fprintf(f,
3634 "\t\t%s%s, %d, %s, %s, %s, %s, %s, %s, %s,\n\t",
3635 /* NOTE: void cast is needed to quiet function cast warning in C++. */
3636 (prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)(void *)" : "",
3638 prop->noteflag,
3646
3648 rna_set_raw_offset(f, srna, prop);
3649 }
3650 else {
3651 fprintf(f, "\t\t0, PROP_RAW_UNSET");
3652 }
3653
3654 /* our own type - collections/arrays only */
3655 if (prop->srna) {
3656 fprintf(f, ", RNA_%s", reinterpret_cast<const char *>(prop->srna));
3657 }
3658 else {
3659 fprintf(f, ", nullptr");
3660 }
3661
3662 fprintf(f, "},\n");
3663
3664 switch (prop->type) {
3665 case PROP_BOOLEAN: {
3666 BoolPropertyRNA *bprop = reinterpret_cast<BoolPropertyRNA *>(prop);
3667 fprintf(f,
3668 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, ",
3669 rna_function_string(bprop->get),
3670 rna_function_string(bprop->set),
3683 bprop->defaultvalue);
3684 if (prop->arraydimension && prop->totarraylength) {
3685 fprintf(f,
3686 "rna_%s%s_%s_default\n",
3687 srna->identifier.c_str(),
3688 strnest,
3689 prop->identifier.c_str());
3690 }
3691 else {
3692 fprintf(f, "nullptr\n");
3693 }
3694 break;
3695 }
3696 case PROP_INT: {
3697 IntPropertyRNA *iprop = reinterpret_cast<IntPropertyRNA *>(prop);
3698 fprintf(f,
3699 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,\n\t\t",
3700 rna_function_string(iprop->get),
3701 rna_function_string(iprop->set),
3704 rna_function_string(iprop->range),
3714 fprintf(f, "%s", rna_ui_scale_type_string(iprop->ui_scale_type));
3715 fprintf(f, ", ");
3716 rna_int_print(f, iprop->softmin);
3717 fprintf(f, ", ");
3718 rna_int_print(f, iprop->softmax);
3719 fprintf(f, ", ");
3720 rna_int_print(f, iprop->hardmin);
3721 fprintf(f, ", ");
3722 rna_int_print(f, iprop->hardmax);
3723 fprintf(f, ", ");
3724 rna_int_print(f, iprop->step);
3725 fprintf(f, ", ");
3726 fprintf(f,
3727 "%s, %s",
3730 fprintf(f, ", ");
3731 rna_int_print(f, iprop->defaultvalue);
3732 fprintf(f, ", ");
3733 if (prop->arraydimension && prop->totarraylength) {
3734 fprintf(f,
3735 "rna_%s%s_%s_default\n",
3736 srna->identifier.c_str(),
3737 strnest,
3738 prop->identifier.c_str());
3739 }
3740 else {
3741 fprintf(f, "nullptr\n");
3742 }
3743 break;
3744 }
3745 case PROP_FLOAT: {
3746 FloatPropertyRNA *fprop = reinterpret_cast<FloatPropertyRNA *>(prop);
3747 fprintf(f,
3748 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ",
3749 rna_function_string(fprop->get),
3750 rna_function_string(fprop->set),
3753 rna_function_string(fprop->range),
3763 fprintf(f, "%s, ", rna_ui_scale_type_string(fprop->ui_scale_type));
3764 rna_float_print(f, fprop->softmin);
3765 fprintf(f, ", ");
3766 rna_float_print(f, fprop->softmax);
3767 fprintf(f, ", ");
3768 rna_float_print(f, fprop->hardmin);
3769 fprintf(f, ", ");
3770 rna_float_print(f, fprop->hardmax);
3771 fprintf(f, ", ");
3772 rna_float_print(f, fprop->step);
3773 fprintf(f, ", ");
3774 rna_int_print(f, fprop->precision);
3775 fprintf(f, ", ");
3776 fprintf(f,
3777 "%s, %s",
3780 fprintf(f, ", ");
3781 rna_float_print(f, fprop->defaultvalue);
3782 fprintf(f, ", ");
3783 if (prop->arraydimension && prop->totarraylength) {
3784 fprintf(f,
3785 "rna_%s%s_%s_default\n",
3786 srna->identifier.c_str(),
3787 strnest,
3788 prop->identifier.c_str());
3789 }
3790 else {
3791 fprintf(f, "nullptr\n");
3792 }
3793 break;
3794 }
3795 case PROP_STRING: {
3796 StringPropertyRNA *sprop = reinterpret_cast<StringPropertyRNA *>(prop);
3797 fprintf(
3798 f,
3799 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, eStringPropertySearchFlag(%d), %s, %d, ",
3800 rna_function_string(sprop->get),
3802 rna_function_string(sprop->set),
3810 int(sprop->search_flag),
3812 sprop->maxlength);
3814 fprintf(f, "\n");
3815 break;
3816 }
3817 case PROP_ENUM: {
3818 EnumPropertyRNA *eprop = reinterpret_cast<EnumPropertyRNA *>(prop);
3819 fprintf(f,
3820 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, ",
3821 rna_function_string(eprop->get),
3822 rna_function_string(eprop->set),
3829 if (eprop->item) {
3830 const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
3831 if (item_global_id != nullptr) {
3832 fprintf(f, "%s, ", item_global_id);
3833 }
3834 else {
3835 fprintf(f,
3836 "rna_%s%s_%s_items, ",
3837 srna->identifier.c_str(),
3838 strnest,
3839 prop->identifier.c_str());
3840 }
3841 }
3842 else {
3843 fprintf(f, "nullptr, ");
3844 }
3845 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
3846 break;
3847 }
3848 case PROP_POINTER: {
3849 PointerPropertyRNA *pprop = reinterpret_cast<PointerPropertyRNA *>(prop);
3850 fprintf(f,
3851 "\t\t%s, %s, %s, %s, %d,",
3852 rna_function_string(pprop->get),
3853 rna_function_string(pprop->set),
3855 rna_function_string(pprop->poll),
3856 0);
3857 if (pprop->pointer_type) {
3858 fprintf(f, "RNA_%s\n", reinterpret_cast<const char *>(pprop->pointer_type));
3859 }
3860 else {
3861 fprintf(f, "nullptr\n");
3862 }
3863 break;
3864 }
3865 case PROP_COLLECTION: {
3866 CollectionPropertyRNA *cprop = reinterpret_cast<CollectionPropertyRNA *>(prop);
3867 fprintf(f,
3868 "\t\t%s, %s, %s, %s, %s, %s, %s, %s, ",
3869 rna_function_string(cprop->begin),
3870 rna_function_string(cprop->next),
3871 rna_function_string(cprop->end),
3872 rna_function_string(cprop->get),
3877 if (cprop->item_type) {
3878 fprintf(f, "RNA_%s\n", reinterpret_cast<const char *>(cprop->item_type));
3879 }
3880 else {
3881 fprintf(f, "nullptr\n");
3882 }
3883 break;
3884 }
3885 }
3886
3887 fprintf(f, "\t};\n");
3888
3889 if (freenest) {
3890 MEM_delete(strnest);
3891 MEM_delete(errnest);
3892 }
3893}
3894
3895static void rna_generate_struct_register_func(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
3896{
3897 PropertyRNA *prop;
3898 StructRNA *base;
3899
3900 fprintf(f, "/* %s */\n", srna->name);
3901
3902 /* Generate static variables before their creation. */
3903 for (PropertyRNA &prop : srna->cont.properties) {
3904 rna_generate_property_decl(f, srna, nullptr, &prop);
3905 }
3906 for (const std::unique_ptr<FunctionRNA> &func : srna->functions) {
3907 for (PropertyRNA &parm : func->cont.properties) {
3908 rna_generate_property_decl(f, srna, func->identifier.c_str(), &parm);
3909 }
3910 fprintf(
3911 f, "FunctionRNA *rna_%s_%s_func;\n", srna->identifier.c_str(), func->identifier.c_str());
3912 }
3913
3914 /* Struct and property creation runs on startup, on the first call to #RNA_blender_rna_get. */
3915 fprintf(f,
3916 "StructRNA *RNA_%s;\n"
3917 "void register_struct_%s(BlenderRNA &brna)\n"
3918 "{\n",
3919 srna->identifier.c_str(),
3920 srna->identifier.c_str());
3921
3922 for (const auto [i, prop] : srna->cont.properties.enumerate()) {
3923 if (i != 0) {
3924 fprintf(f, "\n");
3925 }
3926 rna_generate_property(f, srna, nullptr, &prop);
3927 }
3928
3929 fprintf(f,
3930 "\n"
3931 "\tStructRNA *srna = RNA_%s;\n",
3932 srna->identifier.c_str());
3933
3934 prop = srna->cont.properties.first();
3935 if (prop) {
3936 fprintf(f,
3937 "\tsrna->cont.properties = {&rna_%s_%s, ",
3938 srna->identifier.c_str(),
3939 prop->identifier.c_str());
3940 }
3941 else {
3942 fprintf(f, "\tsrna->cont.properties = {nullptr, ");
3943 }
3944
3945 prop = srna->cont.properties.last_as<PropertyRNA>();
3946 if (prop) {
3947 fprintf(f, "&rna_%s_%s};\n", srna->identifier.c_str(), prop->identifier.c_str());
3948 }
3949 else {
3950 fprintf(f, "nullptr};\n");
3951 }
3952 fprintf(f, "\tsrna->identifier = ");
3954 fprintf(f,
3955 "_ustr;\n"
3956 "\tsrna->flag = StructFlag(%d);\n",
3957 srna->flag);
3958 fprintf(f, "\tsrna->name = ");
3959 rna_print_c_string(f, srna->name);
3960 fprintf(f,
3961 ";\n"
3962 "\tsrna->description = ");
3964 fprintf(f,
3965 ";\n"
3966 "\tsrna->translation_context = ");
3968 fprintf(f,
3969 ";\n"
3970 "\tsrna->icon = %d;\n",
3971 srna->icon);
3972
3973 prop = srna->nameproperty;
3974 if (prop) {
3975 base = srna;
3976 while (base->base && base->base->nameproperty == prop) {
3977 base = base->base;
3978 }
3979
3980 fprintf(f,
3981 "\tsrna->nameproperty = &rna_%s_%s;\n",
3982 base->identifier.c_str(),
3983 prop->identifier.c_str());
3984 }
3985
3986 prop = srna->iteratorproperty;
3987 base = srna;
3988 while (base->base && base->base->iteratorproperty == prop) {
3989 base = base->base;
3990 }
3991 fprintf(f, "\tsrna->iteratorproperty = &rna_%s_rna_properties;\n", base->identifier.c_str());
3992
3993 if (srna->base) {
3994 fprintf(f, "\tsrna->base = RNA_%s;\n", srna->base->identifier.c_str());
3995 }
3996
3997 if (srna->nested) {
3998 fprintf(f, "\tsrna->nested = RNA_%s;\n", srna->nested->identifier.c_str());
3999 }
4000
4001 if (srna->refine) {
4002 fprintf(f, "\tsrna->refine = %s;\n", rna_function_string(srna->refine));
4003 }
4004 if (srna->path) {
4005 fprintf(f, "\tsrna->path = %s;\n", rna_function_string(srna->path));
4006 }
4007 if (srna->reg) {
4008 fprintf(f, "\tsrna->reg = %s;\n", rna_function_string(srna->reg));
4009 }
4010 if (srna->unreg) {
4011 fprintf(f, "\tsrna->unreg = %s;\n", rna_function_string(srna->unreg));
4012 }
4013 if (srna->instance) {
4014 fprintf(f, "\tsrna->instance = %s;\n", rna_function_string(srna->instance));
4015 }
4016 if (srna->idproperties) {
4017 fprintf(f, "\tsrna->idproperties = %s;\n", rna_function_string(srna->idproperties));
4018 }
4019 if (srna->system_idproperties) {
4020 fprintf(
4021 f, "\tsrna->system_idproperties = %s;\n", rna_function_string(srna->system_idproperties));
4022 }
4023
4024 if (srna->reg && !srna->refine) {
4025 CLOG_ERROR(&LOG,
4026 "%s has a register function, must also have refine function.",
4027 srna->identifier.c_str());
4028 DefRNA.error = true;
4029 }
4030
4031 for (const std::unique_ptr<FunctionRNA> &func : srna->functions) {
4032 fprintf(f, "\t{\n");
4033 for (PropertyRNA &parm : func->cont.properties) {
4034 rna_generate_property(f, srna, func->identifier.c_str(), &parm);
4035 }
4036 fprintf(f, "\t\tauto func = std::make_unique<FunctionRNA>();\n");
4037 if (!func->cont.properties.is_empty()) {
4038 fprintf(f,
4039 "\t\tfunc->cont.properties = {&rna_%s_%s_%s, &rna_%s_%s_%s};\n",
4040 srna->identifier.c_str(),
4041 func->identifier.c_str(),
4042 func->cont.properties.first()->identifier.c_str(),
4043 srna->identifier.c_str(),
4044 func->identifier.c_str(),
4045 func->cont.properties.last_as<PropertyRNA>()->identifier.c_str());
4046 }
4047 fprintf(f, "\t\tfunc->identifier = ");
4048 rna_print_c_string(f, func->identifier.c_str());
4049 fprintf(f, "_ustr;\n");
4050 if (func->flag != 0) {
4051 fprintf(f, "\t\tfunc->flag = FunctionFlag(%d);\n", func->flag);
4052 }
4053 fprintf(f, "\t\tfunc->description = ");
4054 rna_print_c_string(f, func->description);
4055 fprintf(f, ";\n");
4056 FunctionDefRNA *dfunc = rna_find_function_def(func.get());
4057 if (dfunc->gencall) {
4058 fprintf(f, "\t\tfunc->call = %s;\n", dfunc->gencall);
4059 }
4060 if (func->c_ret) {
4061 fprintf(f,
4062 "\t\tfunc->c_ret = &rna_%s_%s_%s;\n",
4063 srna->identifier.c_str(),
4064 func->identifier.c_str(),
4065 func->c_ret->identifier.c_str());
4066 }
4067 fprintf(f,
4068 "\t\trna_%s_%s_func = func.get();\n",
4069 srna->identifier.c_str(),
4070 func->identifier.c_str());
4071 fprintf(f,
4072 "\t\tsrna->functions.append(std::move(func));\n"
4073 "\t}\n");
4074 }
4075
4076 fprintf(f, "};\n\n");
4077}
4078
4080 const char *filename;
4081 const char *api_filename;
4082 void (*define)(BlenderRNA *brna);
4083};
4084
4086 /* This starting block of files define parent types that is used in other RNA files.
4087 * Because of this, these can't be put in alphabetical order in the main list below
4088 * because the parent types need to be defined before they are used.
4089 */
4090 {"rna_rna.cc", nullptr, RNA_def_rna},
4091 {"rna_ID.cc", nullptr, RNA_def_ID},
4092 {"rna_texture.cc", "rna_texture_api.cc", RNA_def_texture},
4093 {"rna_userdef.cc", nullptr, RNA_def_userdef},
4094
4095 {"rna_action.cc", "rna_action_api.cc", RNA_def_action},
4096 {"rna_animation.cc", "rna_animation_api.cc", RNA_def_animation},
4097 {"rna_animviz.cc", nullptr, RNA_def_animviz},
4098 {"rna_armature.cc", "rna_armature_api.cc", RNA_def_armature},
4099 {"rna_attribute.cc", nullptr, RNA_def_attribute},
4100 {"rna_asset.cc", nullptr, RNA_def_asset},
4101 {"rna_blender_project.cc", nullptr, RNA_def_blender_project},
4102 {"rna_boid.cc", nullptr, RNA_def_boid},
4103 {"rna_brush.cc", nullptr, RNA_def_brush},
4104 {"rna_cachefile.cc", nullptr, RNA_def_cachefile},
4105 {"rna_camera.cc", "rna_camera_api.cc", RNA_def_camera},
4106 {"rna_cloth.cc", nullptr, RNA_def_cloth},
4107 {"rna_collection.cc", nullptr, RNA_def_collections},
4108 {"rna_color.cc", nullptr, RNA_def_color},
4109 {"rna_constraint.cc", nullptr, RNA_def_constraint},
4110 {"rna_context.cc", nullptr, RNA_def_context},
4111 {"rna_curve.cc", "rna_curve_api.cc", RNA_def_curve},
4112 {"rna_dynamicpaint.cc", nullptr, RNA_def_dynamic_paint},
4113 {"rna_fcurve.cc", "rna_fcurve_api.cc", RNA_def_fcurve},
4114 {"rna_annotations.cc", nullptr, RNA_def_annotations},
4115 {"rna_grease_pencil.cc", "rna_grease_pencil_api.cc", RNA_def_grease_pencil},
4116 {"rna_curves.cc", "rna_curves_api.cc", RNA_def_curves},
4117 {"rna_image.cc", "rna_image_api.cc", RNA_def_image},
4118 {"rna_key.cc", nullptr, RNA_def_key},
4119 {"rna_light.cc", nullptr, RNA_def_light},
4120 {"rna_lattice.cc", "rna_lattice_api.cc", RNA_def_lattice},
4121 {"rna_layer.cc", nullptr, RNA_def_view_layer},
4122 {"rna_linestyle.cc", nullptr, RNA_def_linestyle},
4123 {"rna_blendfile_import.cc", nullptr, RNA_def_blendfile_import},
4124 {"rna_main.cc", "rna_main_api.cc", RNA_def_main},
4125 {"rna_fluid.cc", nullptr, RNA_def_fluid},
4126 {"rna_material.cc", "rna_material_api.cc", RNA_def_material},
4127 {"rna_mesh.cc", "rna_mesh_api.cc", RNA_def_mesh},
4128 {"rna_meta.cc", "rna_meta_api.cc", RNA_def_meta},
4129 {"rna_modifier.cc", nullptr, RNA_def_modifier},
4130 {"rna_shader_fx.cc", nullptr, RNA_def_shader_fx},
4131 {"rna_nla.cc", nullptr, RNA_def_nla},
4132 {"rna_nodetree.cc", nullptr, RNA_def_nodetree},
4133 {"rna_node_socket.cc", nullptr, RNA_def_node_socket_subtypes},
4134 {"rna_node_tree_interface.cc", nullptr, RNA_def_node_tree_interface},
4135 {"rna_object.cc", "rna_object_api.cc", RNA_def_object},
4136 {"rna_object_force.cc", nullptr, RNA_def_object_force},
4137 {"rna_depsgraph.cc", nullptr, RNA_def_depsgraph},
4138 {"rna_packedfile.cc", nullptr, RNA_def_packedfile},
4139 {"rna_palette.cc", nullptr, RNA_def_palette},
4140 {"rna_particle.cc", nullptr, RNA_def_particle},
4141 {"rna_pointcloud.cc", nullptr, RNA_def_pointcloud},
4142 {"rna_pose.cc", "rna_pose_api.cc", RNA_def_pose},
4143 {"rna_curveprofile.cc", nullptr, RNA_def_profile},
4144 {"rna_lightprobe.cc", nullptr, RNA_def_lightprobe},
4145 {"rna_render.cc", nullptr, RNA_def_render},
4146 {"rna_rigidbody.cc", nullptr, RNA_def_rigidbody},
4147 {"rna_scene.cc", "rna_scene_api.cc", RNA_def_scene},
4148 {"rna_screen.cc", nullptr, RNA_def_screen},
4149 {"rna_sculpt_paint.cc", nullptr, RNA_def_sculpt_paint},
4150 {"rna_sequencer.cc", "rna_sequencer_api.cc", RNA_def_sequencer},
4151 {"rna_space.cc", "rna_space_api.cc", RNA_def_space},
4152 {"rna_speaker.cc", nullptr, RNA_def_speaker},
4153 {"rna_test.cc", nullptr, RNA_def_test},
4154 {"rna_text.cc", "rna_text_api.cc", RNA_def_text},
4155 {"rna_timeline.cc", nullptr, RNA_def_timeline_marker},
4156 {"rna_sound.cc", "rna_sound_api.cc", RNA_def_sound},
4157 {"rna_ui.cc", "rna_ui_api.cc", RNA_def_ui},
4158#ifdef WITH_USD
4159 {"rna_usd.cc", nullptr, RNA_def_usd},
4160#endif
4161 {"rna_vfont.cc", "rna_vfont_api.cc", RNA_def_vfont},
4162 {"rna_volume.cc", nullptr, RNA_def_volume},
4163 {"rna_wm.cc", "rna_wm_api.cc", RNA_def_wm},
4164 {"rna_wm_gizmo.cc", "rna_wm_gizmo_api.cc", RNA_def_wm_gizmo},
4165 {"rna_wm_undo.cc", nullptr, RNA_def_undo},
4166 {"rna_workspace.cc", "rna_workspace_api.cc", RNA_def_workspace},
4167 {"rna_world.cc", nullptr, RNA_def_world},
4168 {"rna_movieclip.cc", nullptr, RNA_def_movieclip},
4169 {"rna_tracking.cc", nullptr, RNA_def_tracking},
4170 {"rna_mask.cc", nullptr, RNA_def_mask},
4171 {"rna_xr.cc", nullptr, RNA_def_xr},
4172 {nullptr, nullptr},
4173};
4174
4175static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
4176{
4177 StructDefRNA *ds;
4178 FunctionDefRNA *dfunc;
4179
4180 fprintf(f,
4181 "\n"
4182 "/* Automatically generated struct definitions for the Data API.\n"
4183 " * Do not edit manually, changes will be overwritten. */\n\n");
4184
4185 fprintf(f, "#include <float.h>\n");
4186 fprintf(f, "#include <stdio.h>\n");
4187 fprintf(f, "#include <limits.h>\n");
4188 fprintf(f, "#include <limits>\n");
4189 fprintf(f, "#include <string.h>\n\n");
4190 fprintf(f, "#include <stddef.h>\n\n");
4191 fprintf(f, "#include <algorithm>\n\n");
4192
4193 fprintf(f, "#include \"MEM_guardedalloc.h\"\n\n");
4194
4195 fprintf(f, "#include \"DNA_ID.h\"\n");
4196 fprintf(f, "#include \"DNA_scene_types.h\"\n");
4197 fprintf(f, "#include \"DNA_node_types.h\"\n");
4198
4199 fprintf(f, "#include \"BLI_fileops.hh\"\n\n");
4200 fprintf(f, "#include \"BLI_listbase.hh\"\n\n");
4201 fprintf(f, "#include \"BLI_path_utils.hh\"\n\n");
4202 fprintf(f, "#include \"BLI_rect.hh\"\n\n");
4203 fprintf(f, "#include \"BLI_string.hh\"\n\n");
4204 fprintf(f, "#include \"BLI_string_utf8.hh\"\n\n");
4205 fprintf(f, "#include \"BLI_utildefines.hh\"\n\n");
4206
4207 fprintf(f, "#include \"BKE_context.hh\"\n");
4208 fprintf(f, "#include \"BKE_lib_id.hh\"\n");
4209 fprintf(f, "#include \"BKE_main.hh\"\n");
4210 fprintf(f, "#include \"BKE_report.hh\"\n");
4211
4212 fprintf(f, "#include \"RNA_define.hh\"\n");
4213 fprintf(f, "#include \"RNA_types.hh\"\n");
4214 fprintf(f, "#include \"rna_internal.hh\"\n\n");
4215
4216 /* include the generated prototypes header */
4217 fprintf(f, "#include \"RNA_prototypes.hh\"\n\n");
4218 fprintf(f, "#include \"rna_prototypes_gen.hh\"\n\n");
4219
4220 if (filename) {
4221 fprintf(f, "#include \"%s\"\n", filename);
4222 }
4223 if (api_filename) {
4224 fprintf(f, "#include \"%s\"\n", api_filename);
4225 }
4226 fprintf(f, "\n");
4227
4228/* we want the included C files to have warnings enabled but for the generated code
4229 * ignore unused-parameter warnings which are hard to prevent */
4230#if defined(__GNUC__) || defined(__clang__)
4231 fprintf(f, "#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n\n");
4232#endif
4233
4234#if defined(__clang__)
4235 /* TODO(@ideasman42): ideally this workaround would not be needed,
4236 * could use some further investigation as these are intended to be declared. */
4237 fprintf(f, "#pragma GCC diagnostic ignored \"-Wmissing-variable-declarations\"\n\n");
4238#endif
4239
4240 fprintf(f, "/* Auto-generated Functions. */\n\n");
4241 fprintf(f, "namespace blender {\n\n");
4242
4243 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
4244 if (!filename || ds->filename == filename) {
4247 }
4248 }
4249
4250 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
4251 if (!filename || ds->filename == filename) {
4252 for (PropertyDefRNA &dp : ds->cont.properties) {
4253 rna_def_property_funcs(f, ds->srna, &dp);
4254 }
4255 }
4256 }
4257
4258 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
4259 if (!filename || ds->filename == filename) {
4260 for (PropertyDefRNA &dp : ds->cont.properties) {
4262 }
4263
4264 for (dfunc = ds->functions.first(); dfunc;
4265 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
4266 {
4267 rna_def_function_wrapper_funcs(f, ds, dfunc);
4268 rna_def_function_funcs(f, ds, dfunc);
4269 }
4270
4272 }
4273 }
4274
4275 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
4276 if (!filename || ds->filename == filename) {
4278 }
4279 }
4280
4281 if (filename && STREQ(filename, "rna_ID.cc")) {
4282 rna_generate_blender(brna, f);
4283 }
4284
4285 fprintf(f, "\n} // namespace blender\n");
4286}
4287
4288static void make_bad_file(const char *file, int line)
4289{
4290 FILE *fp = fopen(file, "w");
4291 fprintf(fp,
4292 "#error \"Error! cannot make correct RNA file from %s:%d, "
4293 "check DNA properties.\"\n",
4294 __FILE__,
4295 line);
4296 fclose(fp);
4297}
4298
4303static int rna_preprocess(const char *outfile, const char *public_header_outfile)
4304{
4305 BlenderRNA *brna;
4306 StructDefRNA *ds;
4307 FILE *file;
4308 char deffile[4096];
4309 int i;
4310 /* The exit code (returned from this function). */
4311 int status = EXIT_SUCCESS;
4312 const char *deps[3]; /* expand as needed */
4313
4314 if (!public_header_outfile) {
4315 public_header_outfile = outfile;
4316 }
4317
4318 /* define rna */
4319 brna = RNA_create();
4320
4321 for (i = 0; PROCESS_ITEMS[i].filename; i++) {
4322 if (PROCESS_ITEMS[i].define) {
4323 PROCESS_ITEMS[i].define(brna);
4324
4325 /* sanity check */
4326 if (!DefRNA.animate) {
4327 fprintf(stderr, "Error: DefRNA.animate left disabled in %s\n", PROCESS_ITEMS[i].filename);
4328 }
4329
4330 for (ds = DefRNA.structs.first(); ds; ds = static_cast<StructDefRNA *>(ds->cont.next)) {
4331 if (ds->filename.is_empty()) {
4333 }
4334 }
4335 }
4336 }
4337
4338 rna_sanity_checks();
4339 if (DefRNA.error) {
4340 status = EXIT_FAILURE;
4341 }
4342
4344 if (DefRNA.error) {
4345 status = EXIT_FAILURE;
4346 }
4347
4348 /* Create external rna struct prototype header file RNA_prototypes.hh. */
4349 SNPRINTF(deffile, "%s%s", public_header_outfile, "RNA_prototypes.hh" TMP_EXT);
4350 if (status != EXIT_SUCCESS) {
4351 make_bad_file(deffile, __LINE__);
4352 }
4353 file = fopen(deffile, "w");
4354 if (!file) {
4355 fprintf(stderr, "Unable to open file: %s\n", deffile);
4356 status = EXIT_FAILURE;
4357 }
4358 else {
4359 fprintf(file,
4360 "/* Automatically generated RNA property declarations, to statically reference \n"
4361 " * properties as `rna_[struct-name]_[property-name]`.\n"
4362 " *\n"
4363 " * DO NOT EDIT MANUALLY, changes will be overwritten.\n"
4364 " */\n\n");
4365
4366 fprintf(file, "#pragma once\n\n");
4367 fprintf(file, "namespace blender {\n\n");
4369 fprintf(file, "} // namespace blender\n");
4370 fclose(file);
4371 if (DefRNA.error) {
4372 status = EXIT_FAILURE;
4373 }
4374 replace_if_different(deffile, nullptr);
4375 }
4376
4377 /* create internal rna struct prototype header file */
4378 SNPRINTF(deffile, "%s%s", outfile, "rna_prototypes_gen.hh" TMP_EXT);
4379 if (status != EXIT_SUCCESS) {
4380 make_bad_file(deffile, __LINE__);
4381 }
4382 file = fopen(deffile, "w");
4383 if (!file) {
4384 fprintf(stderr, "Unable to open file: %s\n", deffile);
4385 status = EXIT_FAILURE;
4386 }
4387 else {
4388 fprintf(file,
4389 "/* Automatically generated function declarations for the Data API.\n"
4390 " * Do not edit manually, changes will be overwritten. */\n\n");
4391 fprintf(file, "namespace blender {\n\n");
4393 fprintf(file, "\n} // namespace blender\n");
4394 fclose(file);
4395 replace_if_different(deffile, nullptr);
4396 if (DefRNA.error) {
4397 status = EXIT_FAILURE;
4398 }
4399 }
4400
4401 /* Create `rna_gen_*.c` & `rna_gen_*.cc` files. */
4402 for (i = 0; PROCESS_ITEMS[i].filename; i++) {
4403 const bool is_cc = BLI_str_endswith(PROCESS_ITEMS[i].filename, ".cc");
4404 const int ext_len = is_cc ? 3 : 2;
4405 const int filename_len = strlen(PROCESS_ITEMS[i].filename);
4406 SNPRINTF(deffile,
4407 "%s%.*s%s" TMP_EXT,
4408 outfile,
4409 (filename_len - ext_len),
4411 is_cc ? "_gen.cc" : "_gen.c");
4412 if (status != EXIT_SUCCESS) {
4413 make_bad_file(deffile, __LINE__);
4414 }
4415 else {
4416 file = fopen(deffile, "w");
4417
4418 if (!file) {
4419 fprintf(stderr, "Unable to open file: %s\n", deffile);
4420 status = EXIT_FAILURE;
4421 }
4422 else {
4423 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
4424 fclose(file);
4425 if (DefRNA.error) {
4426 status = EXIT_FAILURE;
4427 }
4428 }
4429 }
4430
4431 /* avoid unneeded rebuilds */
4432 deps[0] = PROCESS_ITEMS[i].filename;
4433 deps[1] = PROCESS_ITEMS[i].api_filename;
4434 deps[2] = nullptr;
4435
4436 replace_if_different(deffile, deps);
4437 }
4438
4439 /* free RNA */
4440 RNA_define_free(brna);
4441 RNA_free(brna);
4442
4443 return status;
4444}
4445
4446static void mem_error_cb(const char *errorStr)
4447{
4448 fprintf(stderr, "%s", errorStr);
4449 fflush(stderr);
4450}
4451
4452} // namespace blender
4453
4454int main(int argc, char **argv)
4455{
4456 using namespace blender;
4457 int return_status = EXIT_SUCCESS;
4458
4461
4462 CLG_init();
4463
4464 /* Some useful defaults since this runs standalone. */
4467
4468 if (argc < 3) {
4469 fprintf(stderr, "Usage: %s dna_dir out_dir [header_out_dir]/\n", argv[0]);
4470 return_status = EXIT_FAILURE;
4471 }
4472 else {
4473 const char *dna_header_path = argv[1];
4478 {
4479 fprintf(stderr, "Fatal!\n");
4480 CLOG_FATAL(&LOG, "Failed to parse DNA headers for RNA registration");
4481 }
4482
4483 if (debugSRNA > 0) {
4484 fprintf(stderr, "Running makesrna\n");
4485 }
4486 makesrna_path = argv[0];
4487 return_status = rna_preprocess(argv[2], (argc > 2) ? argv[3] : nullptr);
4488 }
4489
4490 CLG_exit();
4491
4492 return return_status;
4493}
#define INT64_MIN
#define INT64_MAX
#define STR_ELEM(...)
#define STRNCPY_RLEN(dst, src)
#define SNPRINTF(dst, format,...)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
void CLG_output_use_basename_set(int value)
Definition clog.cc:892
void CLG_exit()
Definition clog.cc:877
void CLG_level_set(CLG_Level level)
Definition clog.cc:932
@ CLG_LEVEL_DEBUG
Definition CLG_log.h:62
@ CLG_LEVEL_WARN
Definition CLG_log.h:58
#define CLOG_FATAL(clg_ref,...)
Definition CLG_log.h:187
void CLG_init()
Definition clog.cc:870
Read Blender memory allocation and freeing.
#define RNA_SUBTYPE_UNIT(subtype)
Definition RNA_types.hh:266
#define BLI_assert_unreachable()
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define STREQ(a, b)
const char * c_str() const
constexpr bool is_empty() const
constexpr const char * c_str() const
#define str(s)
#define FLT_MAX
#define INT_MAX
#define main()
#define PRId64
Definition inttypes.h:78
void MEM_init_memleak_detection()
#define LOG(level)
Definition log.h:97
#define WRITE_PARAM(param)
Definition makesrna.cc:116
#define WRITE_COMMA
Definition makesrna.cc:107
#define REN_IF_DIFF
#define TMP_EXT
Definition makesrna.cc:61
void(*) MEM_set_error_callback(void(*func)(const char *))
Definition mallocn.cc:62
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
#define T
#define L
bool substitute_cpp_types(Vector< ParsedStruct > &structs, const Span< ParsedEnum > enums, bool)
Definition dna_parse.cc:833
bool parse_dna_headers(const StringRefNull base_directory, Vector< ParsedStruct > &r_structs, Vector< ParsedEnum > &r_enums, Span< const char * > include_files)
Definition dna_parse.cc:704
Span< const char * > default_dna_header_filenames()
Definition dna_parse.cc:49
std::string filename(const std::string_view &str, size_t pos)
BMesh Iterators.
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
Definition makesrna.cc:330
static const char * rna_type_type_name(PropertyRNA *prop)
Definition makesrna.cc:435
void RNA_def_linestyle(BlenderRNA *brna)
void RNA_def_workspace(BlenderRNA *brna)
static char * rna_def_property_lookup_string_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc, const char *item_type)
Definition makesrna.cc:1740
void RNA_def_brush(BlenderRNA *brna)
__int64 int64_t
Definition BKE_text.h:90
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
void RNA_def_modifier(BlenderRNA *brna)
void RNA_def_node_socket_subtypes(BlenderRNA *brna)
bool(*)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) PropCollectionLookupStringFunc
void(*)(PointerRNA *ptr, int value) PropEnumSetFunc
void(*)(PointerRNA *ptr, bool *values) PropBooleanArrayGetFunc
static const char * rna_type_type(PropertyRNA *prop)
Definition makesrna.cc:463
void RNA_def_ui(BlenderRNA *brna)
Definition rna_ui.cc:2659
bool is_dnatype_boolean_compat(const StringRef dnatype)
void RNA_def_pointcloud(BlenderRNA *brna)
@ STRUCT_ID_REFCOUNT
void RNA_def_timeline_marker(BlenderRNA *brna)
bool is_dnatype_float_compat(const StringRef dnatype)
unsigned int uint
Definition BKE_text.h:55
void RNA_def_object(BlenderRNA *brna)
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
static char * rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:610
BlenderDefRNA DefRNA
Definition rna_define.cc:71
void RNA_def_collections(BlenderRNA *brna)
void RNA_def_scene(BlenderRNA *brna)
void * rna_calloc(int buffer_size)
Definition makesrna.cc:379
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
void RNA_def_palette(BlenderRNA *brna)
void RNA_def_rna(BlenderRNA *brna)
Definition rna_rna.cc:3893
static const char * rna_find_type(const StringRef type)
Definition makesrna.cc:409
int rna_parameter_size_pad(const int size)
int(*)(PointerRNA *ptr) PropStringLengthFunc
static int rna_preprocess(const char *outfile, const char *public_header_outfile)
Definition makesrna.cc:4303
void RNA_def_view_layer(BlenderRNA *brna)
Definition rna_layer.cc:632
static const char * rna_ui_scale_type_string(const PropertyScaleType type)
Definition makesrna.cc:574
void(*)(PointerRNA *ptr, bool value) PropBooleanSetFunc
void RNA_def_wm_gizmo(BlenderRNA *brna)
int rna_parameter_size(PropertyRNA *parm)
@ PROP_UNIT_POWER
Definition RNA_types.hh:232
@ PROP_UNIT_LENGTH
Definition RNA_types.hh:222
@ PROP_UNIT_CAMERA
Definition RNA_types.hh:231
@ PROP_UNIT_TIME_ABSOLUTE
Definition RNA_types.hh:228
@ PROP_UNIT_VELOCITY
Definition RNA_types.hh:229
@ PROP_UNIT_COLOR_TEMPERATURE
Definition RNA_types.hh:235
@ PROP_UNIT_FREQUENCY
Definition RNA_types.hh:236
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:226
@ PROP_UNIT_AREA
Definition RNA_types.hh:223
@ PROP_UNIT_TEMPERATURE
Definition RNA_types.hh:233
@ PROP_UNIT_NONE
Definition RNA_types.hh:221
@ PROP_UNIT_VOLUME
Definition RNA_types.hh:224
@ PROP_UNIT_ACCELERATION
Definition RNA_types.hh:230
@ PROP_UNIT_WAVELENGTH
Definition RNA_types.hh:234
@ PROP_UNIT_MASS
Definition RNA_types.hh:225
@ PROP_UNIT_TIME
Definition RNA_types.hh:227
void RNA_def_light(BlenderRNA *brna)
Definition rna_light.cc:599
void RNA_def_animviz(BlenderRNA *brna)
void RNA_def_userdef(BlenderRNA *brna)
static void rna_auto_types()
Definition makesrna.cc:2706
@ FUNC_USE_SELF_TYPE
@ FUNC_USE_REPORTS
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:980
@ FUNC_USE_MAIN
@ FUNC_NO_SELF
Definition RNA_types.hh:998
@ FUNC_SELF_AS_RNA
Definition RNA_types.hh:991
@ FUNC_USE_CONTEXT
static void rna_print_id_get(FILE *f, PropertyDefRNA *)
Definition makesrna.cc:348
void RNA_def_cloth(BlenderRNA *brna)
static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
Definition makesrna.cc:1909
void RNA_def_wm(BlenderRNA *brna)
Definition rna_wm.cc:3442
void RNA_def_profile(BlenderRNA *brna)
void(*)(CollectionPropertyIterator *iter) PropCollectionNextFunc
void(*)(PointerRNA *ptr, const bool *values) PropBooleanArraySetFunc
static void rna_generate_blender(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:2935
void RNA_def_boid(BlenderRNA *brna)
Definition rna_boid.cc:716
static void rna_generate_parameter_prototypes(BlenderRNA *, StructRNA *srna, FunctionRNA *func, FILE *f)
Definition makesrna.cc:3021
void rna_addtail(ListBase *listbase, void *vlink)
Definition rna_define.cc:92
void RNA_def_armature(BlenderRNA *brna)
void RNA_def_constraint(BlenderRNA *brna)
static void rna_construct_wrapper_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
Definition makesrna.cc:359
void RNA_def_main(BlenderRNA *brna)
Definition rna_main.cc:408
void RNA_def_space(BlenderRNA *brna)
static const char * rna_function_string(T *func)
Definition makesrna.cc:547
StructDefRNA * rna_find_struct_def(StructRNA *srna)
void RNA_def_annotations(BlenderRNA *brna)
void RNA_def_depsgraph(BlenderRNA *brna)
static bool file_older(const char *file1, const char *file2)
Definition makesrna.cc:65
void RNA_free(BlenderRNA *brna)
void RNA_def_lattice(BlenderRNA *brna)
void RNA_def_asset(BlenderRNA *brna)
Definition rna_asset.cc:926
void RNA_def_sequencer(BlenderRNA *brna)
void(*)(PointerRNA *ptr, float value) PropFloatSetFunc
void RNA_def_grease_pencil(BlenderRNA *brna)
void RNA_def_key(BlenderRNA *brna)
Definition rna_key.cc:1164
static bool rna_parameter_is_const(const PropertyDefRNA *dparm)
Definition makesrna.cc:519
void RNA_def_particle(BlenderRNA *brna)
void RNA_def_tracking(BlenderRNA *brna)
@ PROP_INTERN_PTR_ID_REFCOUNT_FORCED
@ PROP_INTERN_PTR_OWNERSHIP_FORCED
void RNA_def_fcurve(BlenderRNA *brna)
static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
Definition makesrna.cc:1007
static char * rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1887
void RNA_def_sound(BlenderRNA *brna)
Definition rna_sound.cc:119
void RNA_def_sculpt_paint(BlenderRNA *brna)
void(*)(PointerRNA *ptr, const int *values) PropIntArraySetFunc
PropertyScaleType
Definition RNA_types.hh:251
@ PROP_SCALE_LOG
Definition RNA_types.hh:258
@ PROP_SCALE_CUBIC
Definition RNA_types.hh:263
@ PROP_SCALE_LINEAR
Definition RNA_types.hh:253
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static char * rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1464
void(*)(PointerRNA *ptr, const PointerRNA value, ReportList *reports) PropPointerSetFunc
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ PROP_STRING
Definition RNA_types.hh:213
@ PROP_COLLECTION
Definition RNA_types.hh:216
static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
Definition makesrna.cc:960
void RNA_def_attribute(BlenderRNA *brna)
BlenderRNA * RNA_create()
static const char * path_basename(const char *path)
Definition makesrna.cc:83
static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
Definition makesrna.cc:1971
void RNA_def_usd(BlenderRNA *brna)
Definition rna_usd.cc:166
void(*)(CollectionPropertyIterator *iter, PointerRNA *ptr) PropCollectionBeginFunc
void(*)(PointerRNA *ptr, float *values) PropFloatArrayGetFunc
static void rna_generate_struct_register_prototypes(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:2927
PointerRNA(*)(CollectionPropertyIterator *iter) PropCollectionGetFunc
void RNA_def_object_force(BlenderRNA *brna)
void RNA_def_mesh(BlenderRNA *brna)
Definition rna_mesh.cc:3408
@ PROP_RAW_UINT8
Definition RNA_types.hh:716
@ PROP_RAW_DOUBLE
Definition RNA_types.hh:714
@ PROP_RAW_INT8
Definition RNA_types.hh:720
@ PROP_RAW_UINT16
Definition RNA_types.hh:717
@ PROP_RAW_INT
Definition RNA_types.hh:710
@ PROP_RAW_UINT64
Definition RNA_types.hh:719
@ PROP_RAW_SHORT
Definition RNA_types.hh:711
@ PROP_RAW_FLOAT
Definition RNA_types.hh:715
@ PROP_RAW_INT64
Definition RNA_types.hh:718
@ PROP_RAW_BOOLEAN
Definition RNA_types.hh:713
@ PROP_RAW_CHAR
Definition RNA_types.hh:712
static void rna_int_print(FILE *f, int64_t num)
Definition makesrna.cc:588
static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
Definition makesrna.cc:2359
void RNA_def_texture(BlenderRNA *brna)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static const char * rna_property_subtype_unit(PropertySubType type)
Definition makesrna.cc:2880
static bool rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
Definition makesrna.cc:524
void(*)(PointerRNA *ptr, int value) PropIntSetFunc
void RNA_def_curve(BlenderRNA *brna)
static const char * rna_parameter_type_name(PropertyRNA *parm)
Definition makesrna.cc:476
void RNA_def_action(BlenderRNA *brna)
PropertyDefRNA * rna_find_parameter_def(PropertyRNA *parm)
void RNA_def_vfont(BlenderRNA *brna)
Definition rna_vfont.cc:57
ATTR_WARN_UNUSED_RESULT const size_t num
void RNA_def_lightprobe(BlenderRNA *brna)
static void mem_error_cb(const char *errorStr)
Definition makesrna.cc:4446
void RNA_def_fluid(BlenderRNA *brna)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
int(*)(PointerRNA *ptr) PropCollectionLengthFunc
static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
Definition makesrna.cc:1960
void RNA_def_blender_project(BlenderRNA *brna)
void(*)(PointerRNA *ptr, const float *values) PropFloatArraySetFunc
void RNA_def_curves(BlenderRNA *brna)
static void rna_print_c_string(FILE *f, const char *str)
Definition makesrna.cc:301
FunctionDefRNA * rna_find_function_def(FunctionRNA *func)
static char * rna_def_property_search_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1062
void RNA_def_material(BlenderRNA *brna)
static char * rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1558
static const char * rna_safe_id(const UString id)
Definition makesrna.cc:280
void RNA_def_mask(BlenderRNA *brna)
Definition rna_mask.cc:1215
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void BLI_system_backtrace(FILE *fp)
Definition system.cc:112
bool(*)(PointerRNA *ptr) PropBooleanGetFunc
void RNA_def_image(BlenderRNA *brna)
static char * rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1855
static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
Definition makesrna.cc:2287
void RNA_def_camera(BlenderRNA *brna)
void RNA_def_screen(BlenderRNA *brna)
void(*)(PointerRNA *ptr, int *values) PropIntArrayGetFunc
void(*)(PointerRNA *ptr, char *value) PropStringGetFunc
bool is_dnatype_int_compat(const StringRef dnatype)
void(*)(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn) StringPropertySearchFunc
Definition RNA_types.hh:897
void RNA_def_node_tree_interface(BlenderRNA *brna)
void(*)(PointerRNA *ptr, const char *value) PropStringSetFunc
static int replace_if_different(const char *tmpfile, const char *dep_files[])
Definition makesrna.cc:126
int bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc, const char *name_override, int close_prototype)
Definition makesrna.cc:3075
const char * RNA_property_typename(PropertyType type)
PropertyDefRNA * rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
static char * rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1092
static void rna_generate_property_decl(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
Definition makesrna.cc:3276
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:477
@ PROP_EDITABLE
Definition RNA_types.hh:376
@ PROP_ENUM_FLAG
Definition RNA_types.hh:474
@ PROP_DYNAMIC
Definition RNA_types.hh:498
@ PROP_THICK_WRAP
Definition RNA_types.hh:493
@ PROP_IDPROPERTY
Definition RNA_types.hh:496
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:465
@ PROP_ID_REFCOUNT
Definition RNA_types.hh:434
@ PROP_ID_SELF_CHECK
Definition RNA_types.hh:440
void RNA_def_nodetree(BlenderRNA *brna)
void RNA_def_ID(BlenderRNA *brna)
Definition rna_ID.cc:2913
static CLG_LogRef LOG
Definition logging.cpp:12
PointerRNA(*)(PointerRNA *ptr) PropPointerGetFunc
static StructRNA * rna_find_struct(const char *identifier)
Definition makesrna.cc:396
void RNA_def_nla(BlenderRNA *brna)
Definition rna_nla.cc:1270
void RNA_def_animation(BlenderRNA *brna)
bool(*)(PointerRNA *ptr, int key, PointerRNA *r_ptr) PropCollectionLookupIntFunc
void RNA_def_world(BlenderRNA *brna)
Definition rna_world.cc:210
static char * rna_alloc_function_name(const char *structname, const char *propname, const char *type)
Definition makesrna.cc:387
void RNA_def_pose(BlenderRNA *brna)
Definition rna_pose.cc:1616
void RNA_def_color(BlenderRNA *brna)
static int rna_enum_bitmask(PropertyRNA *prop)
Definition makesrna.cc:503
float(*)(PointerRNA *ptr) PropFloatGetFunc
static const char * rna_find_dna_type(const char *type)
Definition makesrna.cc:422
static const char * makesrna_path
Definition makesrna.cc:81
static void make_bad_file(const StringRefNull filename, int line)
Definition makesdna.cc:928
static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
Definition makesrna.cc:3041
void * rna_alloc_from_buffer(const char *buffer, int buffer_size)
Definition makesrna.cc:370
void RNA_def_text(BlenderRNA *brna)
Definition rna_text.cc:298
static const char * rna_property_subtypename(PropertySubType type)
Definition makesrna.cc:2793
static void rna_generate_struct_register_func(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:3895
static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
Definition makesrna.cc:3340
void RNA_define_free(BlenderRNA *)
@ PROP_ACCELERATION
Definition RNA_types.hh:321
@ PROP_TEMPERATURE
Definition RNA_types.hh:341
@ PROP_PERCENTAGE
Definition RNA_types.hh:307
@ PROP_DISTANCE_CAMERA
Definition RNA_types.hh:314
@ PROP_TIME_ABSOLUTE
Definition RNA_types.hh:311
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_LAYER_MEMBER
Definition RNA_types.hh:335
@ PROP_TRANSLATION
Definition RNA_types.hh:318
@ PROP_COORDS
Definition RNA_types.hh:331
@ PROP_FILENAME
Definition RNA_types.hh:286
@ PROP_DISTANCE_DIAMETER
Definition RNA_types.hh:351
@ PROP_MATRIX
Definition RNA_types.hh:322
@ PROP_BYTESTRING
Definition RNA_types.hh:295
@ PROP_DISTANCE
Definition RNA_types.hh:313
@ PROP_PIXEL_DIAMETER
Definition RNA_types.hh:350
@ PROP_VELOCITY
Definition RNA_types.hh:320
@ PROP_FILEPATH
Definition RNA_types.hh:284
@ PROP_QUATERNION
Definition RNA_types.hh:324
@ PROP_DIRPATH
Definition RNA_types.hh:285
@ PROP_FREQUENCY
Definition RNA_types.hh:349
@ PROP_COLOR_TEMPERATURE
Definition RNA_types.hh:347
@ PROP_AXISANGLE
Definition RNA_types.hh:325
@ PROP_PASSWORD
Definition RNA_types.hh:298
@ PROP_WAVELENGTH
Definition RNA_types.hh:344
@ PROP_DIRECTION
Definition RNA_types.hh:319
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:329
@ PROP_UNSIGNED
Definition RNA_types.hh:306
void(*)(CollectionPropertyIterator *iter) PropCollectionEndFunc
int(*)(PointerRNA *ptr) PropEnumGetFunc
@ PARM_RNAPTR
Definition RNA_types.hh:633
@ PARM_OUTPUT
Definition RNA_types.hh:632
void RNA_def_context(BlenderRNA *brna)
static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
Definition makesrna.cc:4175
int(*)(PointerRNA *ptr) PropIntGetFunc
static int debugSRNA
Definition makesrna.cc:50
static void rna_generate_external_property_prototypes(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:2969
static void rna_generate_struct_rna_prototypes(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:2920
static void rna_def_property_wrapper_funcs(FILE *f, StructDefRNA *dsrna, PropertyDefRNA *dp)
Definition makesrna.cc:2271
static const char * rna_property_structname(PropertyType type)
Definition makesrna.cc:2771
static void rna_float_print(FILE *f, float num)
Definition makesrna.cc:552
static RNAProcessItem PROCESS_ITEMS[]
Definition makesrna.cc:4085
static void rna_construct_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
Definition makesrna.cc:353
static char * rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, const char *manualfunc, const char *nextfunc)
Definition makesrna.cc:1644
void RNA_def_dynamic_paint(BlenderRNA *brna)
void RNA_def_packedfile(BlenderRNA *brna)
void RNA_def_volume(BlenderRNA *brna)
void RNA_def_rigidbody(BlenderRNA *brna)
void RNA_def_xr(BlenderRNA *brna)
Definition rna_xr.cc:3144
static void rna_generate_internal_property_prototypes(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:2990
void RNA_def_shader_fx(BlenderRNA *brna)
void RNA_def_cachefile(BlenderRNA *brna)
void RNA_def_meta(BlenderRNA *brna)
Definition rna_meta.cc:430
void RNA_def_undo(BlenderRNA *brna)
static void rna_generate_static_function_prototypes(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:3247
void RNA_def_blendfile_import(BlenderRNA *brna)
void RNA_def_speaker(BlenderRNA *brna)
void RNA_def_movieclip(BlenderRNA *brna)
void RNA_def_render(BlenderRNA *brna)
void RNA_def_test(BlenderRNA *brna)
Definition rna_test.cc:103
#define fabsf
ListBaseT< StructDefRNA > structs
Vector< dna::ParsedStruct > dna_structs
ListBaseT< AllocDefRNA > allocs
Vector< std::unique_ptr< StructRNA > > structs
PropBooleanArraySetFunc setarray
PropBooleanGetTransformFunc get_transform
PropBooleanSetTransformFunc set_transform
PropBooleanArraySetTransformFunc setarray_transform
PropBooleanSetFuncEx set_ex
PropBooleanArraySetFuncEx setarray_ex
PropBooleanGetFuncEx get_default
PropBooleanArrayGetFunc getarray
PropBooleanArrayGetFuncEx getarray_ex
PropBooleanGetFuncEx get_ex
PropBooleanArrayGetFuncEx get_default_array
PropBooleanArrayGetTransformFunc getarray_transform
PropCollectionLookupStringFunc lookupstring
PropCollectionAssignIntFunc assignint
PropCollectionLookupIntFunc lookupint
PropCollectionLengthFunc length
ListBaseT< PropertyDefRNA > properties
ListBaseT< PropertyRNA > properties
const EnumPropertyItem * item
PropEnumSetTransformFunc set_transform
PropEnumGetTransformFunc get_transform
PropFloatArraySetFuncEx setarray_ex
PropFloatGetTransformFunc get_transform
PropFloatRangeFuncEx range_ex
PropFloatSetTransformFunc set_transform
PropFloatArraySetTransformFunc setarray_transform
PropFloatArrayGetFuncEx getarray_ex
PropFloatArraySetFunc setarray
PropFloatArrayGetFuncEx get_default_array
PropFloatArrayGetTransformFunc getarray_transform
PropFloatArrayGetFunc getarray
PropIntArrayGetFunc getarray
PropIntArrayGetTransformFunc getarray_transform
PropIntArrayGetFuncEx getarray_ex
PropIntArraySetFuncEx setarray_ex
PropIntArraySetFunc setarray
PropIntArraySetTransformFunc setarray_transform
PropertyScaleType ui_scale_type
PropIntGetTransformFunc get_transform
PropIntSetTransformFunc set_transform
PropIntArrayGetFuncEx get_default_array
StringRefNull dnastructname
StringRefNull dnalengthname
StringRefNull dnastructfromprop
StringRefNull dnastructfromname
PropertyDefRNA * next
RNAPropOverrideDiff override_diff
PropUINameFunc ui_description_func
RNAPropOverrideApply override_apply
PropertyFlagIntern flag_internal
ItemEditableFunc itemeditable
PropArrayLengthGetFunc getlength
const DeprecatedRNA * deprecated
unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION]
PropertyOverrideFlag flag_override
RNAPropOverrideStore override_store
PropertyPathTemplateType path_template_type
const char * api_filename
Definition makesrna.cc:4081
void(*) define(BlenderRNA *brna)
Definition makesrna.cc:4082
eStringPropertySearchFlag search_flag
PropStringGetTransformFunc get_transform
StringPropertyPathFilterFunc path_filter
PropStringSetTransformFunc set_transform
StringPropertySearchFunc search
PropStringLengthFuncEx length_ex
StringRefNull dnafromname
ListBaseT< FunctionDefRNA > functions
ContainerDefRNA cont
StringRefNull dnafromprop
StructInstanceFunc instance
PropertyRNA * iteratorproperty
IDPropertiesFunc system_idproperties
Vector< std::unique_ptr< FunctionRNA > > functions
IDPropertiesFunc idproperties
StructRegisterFunc reg
StructRefineFunc refine
StructUnregisterFunc unreg
const char * translation_context