Blender V5.0
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
20#include "MEM_guardedalloc.h"
21
22#include "BLI_listbase.h"
23#include "BLI_string.h"
24#include "BLI_system.h" /* For #BLI_system_backtrace stub. */
25#include "BLI_utildefines.h"
26
27#include "RNA_define.hh"
28#include "RNA_enum_types.hh"
29#include "RNA_types.hh"
30
31#include "rna_internal.hh"
32
33#include "CLG_log.h"
34
35static CLG_LogRef LOG = {"makesrna"};
36
43static int debugSRNA = 0;
44
45/* stub for BLI_abort() */
46#ifndef NDEBUG
48{
49 (void)fp;
50}
51#endif /* !NDEBUG */
52
53/* Replace if different */
54#define TMP_EXT ".tmp"
55
56/* copied from BLI_file_older */
57#include <sys/stat.h>
58static bool file_older(const char *file1, const char *file2)
59{
60 struct stat st1, st2;
61 if (debugSRNA > 0) {
62 printf("compare: %s %s\n", file1, file2);
63 }
64
65 if (stat(file1, &st1)) {
66 return false;
67 }
68 if (stat(file2, &st2)) {
69 return false;
70 }
71
72 return (st1.st_mtime < st2.st_mtime);
73}
74static const char *makesrna_path = nullptr;
75
76static const char *path_basename(const char *path)
77{
78 const char *lfslash, *lbslash;
79
80 lfslash = strrchr(path, '/');
81 lbslash = strrchr(path, '\\');
82 if (lbslash) {
83 lbslash++;
84 }
85 if (lfslash) {
86 lfslash++;
87 }
88
89 return std::max({path, lfslash, lbslash});
90}
91
92/* forward declarations */
94 StructRNA *srna,
95 FunctionDefRNA *dfunc,
96 const char *name_override,
97 int close_prototype);
98
99/* helpers */
100#define WRITE_COMMA \
101 { \
102 if (!first) { \
103 fprintf(f, ", "); \
104 } \
105 first = 0; \
106 } \
107 (void)0
108
109#define WRITE_PARAM(param) \
110 { \
111 WRITE_COMMA; \
112 fprintf(f, param); \
113 } \
114 (void)0
115
119static int replace_if_different(const char *tmpfile, const char *dep_files[])
120{
121
122#ifdef USE_MAKEFILE_WORKAROUND
123 const bool use_makefile_workaround = true;
124#else
125 const bool use_makefile_workaround = false;
126#endif
127
128 /* Use for testing hand edited `rna_*_gen.c` files. */
129 // return 0;
130
131#define REN_IF_DIFF \
132 { \
133 FILE *file_test = fopen(orgfile, "rb"); \
134 if (file_test) { \
135 fclose(file_test); \
136 if (fp_org) { \
137 fclose(fp_org); \
138 } \
139 if (fp_new) { \
140 fclose(fp_new); \
141 } \
142 if (remove(orgfile) != 0) { \
143 CLOG_ERROR(&LOG, "remove error (%s): \"%s\"", strerror(errno), orgfile); \
144 return -1; \
145 } \
146 } \
147 } \
148 if (rename(tmpfile, orgfile) != 0) { \
149 CLOG_ERROR(&LOG, "rename error (%s): \"%s\" -> \"%s\"", strerror(errno), tmpfile, orgfile); \
150 return -1; \
151 } \
152 remove(tmpfile); \
153 return 1; \
154 ((void)0)
155 /* End `REN_IF_DIFF`. */
156
157 FILE *fp_new = nullptr, *fp_org = nullptr;
158 int len_new, len_org;
159 char *arr_new, *arr_org;
160 int cmp;
161
162 const char *makesrna_source_filepath = __FILE__;
163 const char *makesrna_source_filename = path_basename(makesrna_source_filepath);
164
165 char orgfile[4096];
166
167 STRNCPY(orgfile, tmpfile);
168 orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* Strip `.tmp`. */
169
170 fp_org = fopen(orgfile, "rb");
171
172 if (fp_org == nullptr) {
174 }
175
176 /* NOTE(@ideasman42): trick to work around dependency problem.
177 * The issue is as follows: When `makesrna.cc` or any of the `rna_*.c` files being newer than
178 * their generated output, the build-system detects that the `rna_*_gen.c` file is out-dated and
179 * requests the `rna_*_gen.c` files are re-generated (even if this function always returns 0).
180 * It happens *every* rebuild, slowing incremental builds which isn't practical for development.
181 *
182 * This is only an issue for `Unix Makefiles`, `Ninja` generator doesn't have this problem.
183 *
184 * CMake will set `use_makefile_workaround` to 0 or 1 depending on the generator used. */
185
186 if (use_makefile_workaround) {
187 /* First check if `makesrna.cc` is newer than generated files.
188 * For development on `makesrna.cc` you may want to disable this. */
189 if (file_older(orgfile, makesrna_source_filepath)) {
191 }
192
193 if (file_older(orgfile, makesrna_path)) {
195 }
196
197 /* Now check if any files we depend on are newer than any generated files. */
198 if (dep_files) {
199 int pass;
200 for (pass = 0; dep_files[pass]; pass++) {
201 char from_path[4096];
202 /* Only the directory (base-name). */
203 SNPRINTF(from_path,
204 "%.*s%s",
205 int(makesrna_source_filename - makesrna_source_filepath),
206 makesrna_source_filepath,
207 dep_files[pass]);
208 /* Account for build dependencies, if `makesrna.cc` (this file) is newer. */
209 if (file_older(orgfile, from_path)) {
211 }
212 }
213 }
214 }
215 /* XXX end dep trick */
216
217 fp_new = fopen(tmpfile, "rb");
218
219 if (fp_new == nullptr) {
220 /* Shouldn't happen, just to be safe. */
221 CLOG_ERROR(&LOG, "open error: \"%s\"", tmpfile);
222 fclose(fp_org);
223 return -1;
224 }
225
226 fseek(fp_new, 0L, SEEK_END);
227 len_new = ftell(fp_new);
228 fseek(fp_new, 0L, SEEK_SET);
229 fseek(fp_org, 0L, SEEK_END);
230 len_org = ftell(fp_org);
231 fseek(fp_org, 0L, SEEK_SET);
232
233 if (len_new != len_org) {
234 fclose(fp_new);
235 fp_new = nullptr;
236 fclose(fp_org);
237 fp_org = nullptr;
239 }
240
241 /* Now compare the files: */
242 arr_new = MEM_malloc_arrayN<char>(size_t(len_new), "rna_cmp_file_new");
243 arr_org = MEM_malloc_arrayN<char>(size_t(len_org), "rna_cmp_file_org");
244
245 if (fread(arr_new, sizeof(char), len_new, fp_new) != len_new) {
246 CLOG_ERROR(&LOG, "unable to read file %s for comparison.", tmpfile);
247 }
248 if (fread(arr_org, sizeof(char), len_org, fp_org) != len_org) {
249 CLOG_ERROR(&LOG, "unable to read file %s for comparison.", orgfile);
250 }
251
252 fclose(fp_new);
253 fp_new = nullptr;
254 fclose(fp_org);
255 fp_org = nullptr;
256
257 cmp = memcmp(arr_new, arr_org, len_new);
258
259 MEM_freeN(arr_new);
260 MEM_freeN(arr_org);
261
262 if (cmp) {
264 }
265 remove(tmpfile);
266 return 0;
267
268#undef REN_IF_DIFF
269}
270
271/* Helper to solve keyword problems with C/C++. */
272
273static const char *rna_safe_id(const char *id)
274{
275 if (STREQ(id, "default")) {
276 return "default_value";
277 }
278 if (STREQ(id, "operator")) {
279 return "operator_value";
280 }
281 if (STREQ(id, "new")) {
282 return "create";
283 }
284 if (STREQ(id, "co_return")) {
285 /* MSVC2015, C++ uses for coroutines */
286 return "coord_return";
287 }
288
289 return id;
290}
291
292/* Sorting */
293
294static int cmp_struct(const void *a, const void *b)
295{
296 const StructRNA *structa = *(const StructRNA **)a;
297 const StructRNA *structb = *(const StructRNA **)b;
298
299 return strcmp(structa->identifier, structb->identifier);
300}
301
302static int cmp_property(const void *a, const void *b)
303{
304 const PropertyRNA *propa = *(const PropertyRNA **)a;
305 const PropertyRNA *propb = *(const PropertyRNA **)b;
306
307 if (STREQ(propa->identifier, "rna_type")) {
308 return -1;
309 }
310 if (STREQ(propb->identifier, "rna_type")) {
311 return 1;
312 }
313
314 if (STREQ(propa->identifier, "name")) {
315 return -1;
316 }
317 if (STREQ(propb->identifier, "name")) {
318 return 1;
319 }
320
321 return strcmp(propa->name, propb->name);
322}
323
324static int cmp_def_struct(const void *a, const void *b)
325{
326 const StructDefRNA *dsa = *(const StructDefRNA **)a;
327 const StructDefRNA *dsb = *(const StructDefRNA **)b;
328
329 return cmp_struct(&dsa->srna, &dsb->srna);
330}
331
332static int cmp_def_property(const void *a, const void *b)
333{
334 const PropertyDefRNA *dpa = *(const PropertyDefRNA **)a;
335 const PropertyDefRNA *dpb = *(const PropertyDefRNA **)b;
336
337 return cmp_property(&dpa->prop, &dpb->prop);
338}
339
340static void rna_sortlist(ListBase *listbase, int (*cmp)(const void *, const void *))
341{
342 Link *link;
343 void **array;
344 int a, size;
345
346 if (listbase->first == listbase->last) {
347 return;
348 }
349
350 for (size = 0, link = static_cast<Link *>(listbase->first); link; link = link->next) {
351 size++;
352 }
353
354 array = MEM_malloc_arrayN<void *>(size_t(size), "rna_sortlist");
355 for (a = 0, link = static_cast<Link *>(listbase->first); link; link = link->next, a++) {
356 array[a] = link;
357 }
358
359 qsort(array, size, sizeof(void *), cmp);
360
361 listbase->first = listbase->last = nullptr;
362 for (a = 0; a < size; a++) {
363 link = static_cast<Link *>(array[a]);
364 link->next = link->prev = nullptr;
365 rna_addtail(listbase, link);
366 }
367
369}
370
371/* Preprocessing */
372
373static void rna_print_c_string(FILE *f, const char *str)
374{
375 static const char *escape[] = {
376 "\''", "\"\"", "\??", "\\\\", "\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", nullptr};
377 int i, j;
378
379 if (!str) {
380 fprintf(f, "nullptr");
381 return;
382 }
383
384 fprintf(f, "\"");
385 for (i = 0; str[i]; i++) {
386 for (j = 0; escape[j]; j++) {
387 if (str[i] == escape[j][0]) {
388 break;
389 }
390 }
391
392 if (escape[j]) {
393 fprintf(f, "\\%c", escape[j][1]);
394 }
395 else {
396 fprintf(f, "%c", str[i]);
397 }
398 }
399 fprintf(f, "\"");
400}
401
402static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
403{
404 if (dp->dnastructfromname && dp->dnastructfromprop) {
405 fprintf(f,
406 " %s *data = (%s *)(((%s *)ptr->data)->%s);\n",
407 dp->dnastructname,
408 dp->dnastructname,
411 }
412 else {
413 fprintf(f, " %s *data = (%s *)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
414 }
415}
416
417static void rna_print_id_get(FILE *f, PropertyDefRNA * /*dp*/)
418{
419 fprintf(f, " ID *id = ptr->owner_id;\n");
420}
421
423 char *buffer, int size, const char *structname, const char *propname, const char *type)
424{
425 BLI_snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
426}
427
429 char *buffer, int size, const char *structname, const char *propname, const char *type)
430{
431 if (type == nullptr || type[0] == '\0') {
432 BLI_snprintf(buffer, size, "%s_%s", structname, propname);
433 }
434 else {
435 BLI_snprintf(buffer, size, "%s_%s_%s", structname, propname, type);
436 }
437}
438
439void *rna_alloc_from_buffer(const char *buffer, int buffer_size)
440{
441 AllocDefRNA *alloc = MEM_callocN<AllocDefRNA>("AllocDefRNA");
442 alloc->mem = MEM_mallocN(buffer_size, __func__);
443 memcpy(alloc->mem, buffer, buffer_size);
444 rna_addtail(&DefRNA.allocs, alloc);
445 return alloc->mem;
446}
447
448void *rna_calloc(int buffer_size)
449{
450 AllocDefRNA *alloc = MEM_callocN<AllocDefRNA>("AllocDefRNA");
451 alloc->mem = MEM_callocN(buffer_size, __func__);
452 rna_addtail(&DefRNA.allocs, alloc);
453 return alloc->mem;
454}
455
456static char *rna_alloc_function_name(const char *structname,
457 const char *propname,
458 const char *type)
459{
460 char buffer[2048];
461 rna_construct_function_name(buffer, sizeof(buffer), structname, propname, type);
462 return static_cast<char *>(rna_alloc_from_buffer(buffer, strlen(buffer) + 1));
463}
464
465static StructRNA *rna_find_struct(const char *identifier)
466{
467 StructDefRNA *ds;
468
469 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
470 ds = static_cast<StructDefRNA *>(ds->cont.next))
471 {
472 if (STREQ(ds->srna->identifier, identifier)) {
473 return ds->srna;
474 }
475 }
476
477 return nullptr;
478}
479
480static const char *rna_find_type(const char *type)
481{
482 StructDefRNA *ds;
483
484 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
485 ds = static_cast<StructDefRNA *>(ds->cont.next))
486 {
487 if (ds->dnaname && STREQ(ds->dnaname, type)) {
488 return ds->srna->identifier;
489 }
490 }
491
492 return nullptr;
493}
494
495static const char *rna_find_dna_type(const char *type)
496{
497 StructDefRNA *ds;
498
499 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
500 ds = static_cast<StructDefRNA *>(ds->cont.next))
501 {
502 if (STREQ(ds->srna->identifier, type)) {
503 return ds->dnaname;
504 }
505 }
506
507 return nullptr;
508}
509
510static const char *rna_type_type_name(PropertyRNA *prop)
511{
512 switch (prop->type) {
513 case PROP_BOOLEAN:
514 return "bool";
515 case PROP_INT:
516 return "int";
517 case PROP_ENUM: {
518 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
519 if (eprop->native_enum_type) {
520 return eprop->native_enum_type;
521 }
522 return "int";
523 }
524 case PROP_FLOAT:
525 return "float";
526 case PROP_STRING:
527 if (prop->flag & PROP_THICK_WRAP) {
528 return "char *";
529 }
530 else {
531 return "const char *";
532 }
533 default:
534 return nullptr;
535 }
536}
537
538static const char *rna_type_type(PropertyRNA *prop)
539{
540 const char *type;
541
542 type = rna_type_type_name(prop);
543
544 if (type) {
545 return type;
546 }
547
548 return "PointerRNA";
549}
550
551static const char *rna_type_struct(PropertyRNA *prop)
552{
553 const char *type;
554
555 type = rna_type_type_name(prop);
556
557 if (type) {
558 return "";
559 }
560
561 return "struct ";
562}
563
564static const char *rna_parameter_type_name(PropertyRNA *parm)
565{
566 const char *type;
567
568 type = rna_type_type_name(parm);
569
570 if (type) {
571 return type;
572 }
573
574 switch (parm->type) {
575 case PROP_POINTER: {
576 PointerPropertyRNA *pparm = (PointerPropertyRNA *)parm;
577
578 if (parm->flag_parameter & PARM_RNAPTR) {
579 return "PointerRNA";
580 }
581 return rna_find_dna_type((const char *)pparm->type);
582 }
583 case PROP_COLLECTION: {
584 return "CollectionVector";
585 }
586 default:
587 return "<error, no type specified>";
588 }
589}
590
592{
593 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
594 int a, mask = 0;
595
596 if (eprop->item) {
597 for (a = 0; a < eprop->totitem; a++) {
598 if (eprop->item[a].identifier[0]) {
599 mask |= eprop->item[a].value;
600 }
601 }
602 }
603
604 return mask;
605}
606
607static bool rna_parameter_is_const(const PropertyDefRNA *dparm)
608{
609 return (dparm->prop->arraydimension) && ((dparm->prop->flag_parameter & PARM_OUTPUT) == 0);
610}
611
613{
614 return ((prop->type == PROP_FLOAT) && ELEM(prop->subtype, PROP_COLOR, PROP_COLOR_GAMMA) &&
615 (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0));
616}
617
623static const char *rna_enum_id_from_pointer(const EnumPropertyItem *item)
624{
625#define RNA_MAKESRNA
626#define DEF_ENUM(id) \
627 if (item == id) { \
628 return STRINGIFY(id); \
629 }
630#include "RNA_enum_items.hh"
631#undef RNA_MAKESRNA
632 return nullptr;
633}
634
635template<typename T> static const char *rna_function_string(T *func)
636{
637 return (func) ? (const char *)func : "nullptr";
638}
639
640static void rna_float_print(FILE *f, float num)
641{
642 if (num == -FLT_MAX) {
643 fprintf(f, "-FLT_MAX");
644 }
645 else if (num == FLT_MAX) {
646 fprintf(f, "FLT_MAX");
647 }
648 else if ((fabsf(num) < float(INT64_MAX)) && (int64_t(num) == num)) {
649 fprintf(f, "%.1ff", num);
650 }
651 else if (num == std::numeric_limits<float>::infinity()) {
652 fprintf(f, "std::numeric_limits<float>::infinity()");
653 }
654 else if (num == -std::numeric_limits<float>::infinity()) {
655 fprintf(f, "-std::numeric_limits<float>::infinity()");
656 }
657 else {
658 fprintf(f, "%.10ff", num);
659 }
660}
661
662static const char *rna_ui_scale_type_string(const PropertyScaleType type)
663{
664 switch (type) {
666 return "PROP_SCALE_LINEAR";
667 case PROP_SCALE_LOG:
668 return "PROP_SCALE_LOG";
669 case PROP_SCALE_CUBIC:
670 return "PROP_SCALE_CUBIC";
671 }
673 return "";
674}
675
676static void rna_int_print(FILE *f, int64_t num)
677{
678 if (num == INT_MIN) {
679 fprintf(f, "INT_MIN");
680 }
681 else if (num == INT_MAX) {
682 fprintf(f, "INT_MAX");
683 }
684 else if (num == INT64_MIN) {
685 fprintf(f, "INT64_MIN");
686 }
687 else if (num == INT64_MAX) {
688 fprintf(f, "INT64_MAX");
689 }
690 else if (num < INT_MIN || num > INT_MAX) {
691 fprintf(f, "%" PRId64 "LL", num);
692 }
693 else {
694 fprintf(f, "%d", int(num));
695 }
696}
697
699 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
700{
701 char *func;
702
703 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
704 return nullptr;
705 }
706
707 if (!manualfunc) {
708 if (!dp->dnastructname || !dp->dnaname) {
709 CLOG_ERROR(&LOG, "%s.%s has no valid dna info.", srna->identifier, prop->identifier);
710 DefRNA.error = true;
711 return nullptr;
712 }
713
714 /* Type check. */
715 if (dp->dnatype && *dp->dnatype) {
716
717 if (prop->type == PROP_FLOAT) {
718 if (IS_DNATYPE_FLOAT_COMPAT(dp->dnatype) == 0) {
719 /* Colors are an exception. these get translated. */
720 if (prop->subtype != PROP_COLOR_GAMMA) {
722 "%s.%s is a '%s' but wrapped as type '%s'.",
723 srna->identifier,
724 prop->identifier,
725 dp->dnatype,
727 DefRNA.error = true;
728 return nullptr;
729 }
730 }
731 }
732 else if (prop->type == PROP_BOOLEAN) {
733 if (IS_DNATYPE_BOOLEAN_COMPAT(dp->dnatype) == 0) {
735 "%s.%s is a '%s' but wrapped as type '%s'.",
736 srna->identifier,
737 prop->identifier,
738 dp->dnatype,
740 DefRNA.error = true;
741 return nullptr;
742 }
743 }
744 else if (ELEM(prop->type, PROP_INT, PROP_ENUM)) {
745 if (IS_DNATYPE_INT_COMPAT(dp->dnatype) == 0) {
747 "%s.%s is a '%s' but wrapped as type '%s'.",
748 srna->identifier,
749 prop->identifier,
750 dp->dnatype,
752 DefRNA.error = true;
753 return nullptr;
754 }
755 }
756 }
757
758 /* Check log scale sliders for negative range. */
759 if (prop->type == PROP_FLOAT) {
760 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
761 /* NOTE: ButType::NumSlider can't have a softmin of zero. */
762 if ((fprop->ui_scale_type == PROP_SCALE_LOG) && (fprop->hardmin < 0 || fprop->softmin < 0)) {
764 &LOG, "\"%s.%s\", range for log scale < 0.", srna->identifier, prop->identifier);
765 DefRNA.error = true;
766 return nullptr;
767 }
768 }
769 if (prop->type == PROP_INT) {
770 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
771 /* Only ButType::NumSlider is implemented and that one can't have a softmin of zero. */
772 if ((iprop->ui_scale_type == PROP_SCALE_LOG) && (iprop->hardmin <= 0 || iprop->softmin <= 0))
773 {
775 &LOG, "\"%s.%s\", range for log scale <= 0.", srna->identifier, prop->identifier);
776 DefRNA.error = true;
777 return nullptr;
778 }
779 }
780 }
781
782 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
783
784 switch (prop->type) {
785 case PROP_STRING: {
786 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
787 UNUSED_VARS_NDEBUG(sprop);
788 fprintf(f, "extern void %s(PointerRNA *ptr, char *value)\n", func);
789 fprintf(f, "{\n");
790 if (manualfunc) {
791 fprintf(f, " PropStringGetFunc fn = %s;\n", manualfunc);
792 fprintf(f, " fn(ptr, value);\n");
793 }
794 else {
795 rna_print_data_get(f, dp);
796
797 if (dp->dnapointerlevel == 1) {
798 /* Handle allocated char pointer properties. */
799 fprintf(f, " if (data->%s == nullptr) {\n", dp->dnaname);
800 fprintf(f, " *value = '\\0';\n");
801 fprintf(f, " return;\n");
802 fprintf(f, " }\n");
803 fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
804 }
805 else {
806 /* Handle char array properties. */
807
808#ifndef NDEBUG /* Assert lengths never exceed their maximum expected value. */
809 if (sprop->maxlength) {
810 fprintf(f, " BLI_assert(strlen(data->%s) < %d);\n", dp->dnaname, sprop->maxlength);
811 }
812 else {
813 fprintf(f,
814 " BLI_assert(strlen(data->%s) < sizeof(data->%s));\n",
815 dp->dnaname,
816 dp->dnaname);
817 }
818#endif
819
820 fprintf(f, " strcpy(value, data->%s);\n", dp->dnaname);
821 }
822 }
823 fprintf(f, "}\n\n");
824 break;
825 }
826 case PROP_POINTER: {
827 fprintf(f, "extern PointerRNA %s(PointerRNA *ptr)\n", func);
828 fprintf(f, "{\n");
829 if (manualfunc) {
830 fprintf(f, " PropPointerGetFunc fn = %s;\n", manualfunc);
831 fprintf(f, " return fn(ptr);\n");
832 }
833 else {
834 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
835 rna_print_data_get(f, dp);
836 if (dp->dnapointerlevel == 0) {
837 fprintf(f,
838 " return RNA_pointer_create_with_parent(*ptr, &RNA_%s, &data->%s);\n",
839 (const char *)pprop->type,
840 dp->dnaname);
841 }
842 else {
843 fprintf(f,
844 " return RNA_pointer_create_with_parent(*ptr, &RNA_%s, data->%s);\n",
845 (const char *)pprop->type,
846 dp->dnaname);
847 }
848 }
849 fprintf(f, "}\n\n");
850 break;
851 }
852 case PROP_COLLECTION: {
854
855 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
856 fprintf(f, "{\n");
857 if (manualfunc) {
858 if (STR_ELEM(manualfunc,
859 "rna_iterator_listbase_get",
860 "rna_iterator_array_get",
861 "rna_iterator_array_dereference_get"))
862 {
863 fprintf(f,
864 " return RNA_pointer_create_with_parent(iter->parent, &RNA_%s, %s(iter));\n",
865 (cprop->item_type) ? (const char *)cprop->item_type : "UnknownType",
866 manualfunc);
867 }
868 else {
869 fprintf(f, " PropCollectionGetFunc fn = %s;\n", manualfunc);
870 fprintf(f, " return fn(iter);\n");
871 }
872 }
873 fprintf(f, "}\n\n");
874 break;
875 }
876 default:
877 if (prop->arraydimension) {
878 if (prop->flag & PROP_DYNAMIC) {
879 fprintf(f, "extern void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
880 }
881 else {
882 fprintf(f,
883 "extern void %s(PointerRNA *ptr, %s values[%u])\n",
884 func,
885 rna_type_type(prop),
886 prop->totarraylength);
887 }
888 fprintf(f, "{\n");
889
890 if (manualfunc) {
891 /* Assign `fn` to ensure function signatures match. */
892 if (prop->type == PROP_BOOLEAN) {
893 fprintf(f, " PropBooleanArrayGetFunc fn = %s;\n", manualfunc);
894 fprintf(f, " fn(ptr, values);\n");
895 }
896 else if (prop->type == PROP_INT) {
897 fprintf(f, " PropIntArrayGetFunc fn = %s;\n", manualfunc);
898 fprintf(f, " fn(ptr, values);\n");
899 }
900 else if (prop->type == PROP_FLOAT) {
901 fprintf(f, " PropFloatArrayGetFunc fn = %s;\n", manualfunc);
902 fprintf(f, " fn(ptr, values);\n");
903 }
904 else {
905 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
906 fprintf(f, " %s(ptr, values);\n", manualfunc);
907 }
908 }
909 else {
910 rna_print_data_get(f, dp);
911
912 if (prop->flag & PROP_DYNAMIC) {
913 char *lenfunc = rna_alloc_function_name(
914 srna->identifier, rna_safe_id(prop->identifier), "get_length");
915 fprintf(f, " unsigned int arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
916 fprintf(f, " unsigned int i;\n");
917 fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
918 fprintf(f, " for (i = 0; i < len; i++) {\n");
919 MEM_freeN(lenfunc);
920 }
921 else {
922 fprintf(f, " unsigned int i;\n\n");
923 fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
924 }
925
926 if (dp->dnaarraylength == 1) {
927 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
928 fprintf(f,
929 " values[i] = %s((data->%s & (",
930 (dp->booleannegative) ? "!" : "",
931 dp->dnaname);
933 fprintf(f, " << i)) != 0);\n");
934 }
935 else {
936 fprintf(f,
937 " values[i] = (%s)%s((&data->%s)[i]);\n",
938 rna_type_type(prop),
939 (dp->booleannegative) ? "!" : "",
940 dp->dnaname);
941 }
942 }
943 else {
944 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
945 fprintf(f,
946 " values[i] = %s((data->%s[i] & ",
947 (dp->booleannegative) ? "!" : "",
948 dp->dnaname);
950 fprintf(f, ") != 0);\n");
951 }
952 else if (rna_color_quantize(prop, dp)) {
953 fprintf(f,
954 " values[i] = (%s)(data->%s[i] * (1.0f / 255.0f));\n",
955 rna_type_type(prop),
956 dp->dnaname);
957 }
958 else if (dp->dnatype) {
959 fprintf(f,
960 " values[i] = (%s)%s(((%s *)data->%s)[i]);\n",
961 rna_type_type(prop),
962 (dp->booleannegative) ? "!" : "",
963 dp->dnatype,
964 dp->dnaname);
965 }
966 else {
967 fprintf(f,
968 " values[i] = (%s)%s((data->%s)[i]);\n",
969 rna_type_type(prop),
970 (dp->booleannegative) ? "!" : "",
971 dp->dnaname);
972 }
973 }
974 fprintf(f, " }\n");
975 }
976 fprintf(f, "}\n\n");
977 }
978 else {
979 fprintf(f, "extern %s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
980 fprintf(f, "{\n");
981
982 if (manualfunc) {
983 /* Assign `fn` to ensure function signatures match. */
984 if (prop->type == PROP_BOOLEAN) {
985 fprintf(f, " PropBooleanGetFunc fn = %s;\n", manualfunc);
986 fprintf(f, " return fn(ptr);\n");
987 }
988 else if (prop->type == PROP_INT) {
989 fprintf(f, " PropIntGetFunc fn = %s;\n", manualfunc);
990 fprintf(f, " return fn(ptr);\n");
991 }
992 else if (prop->type == PROP_FLOAT) {
993 fprintf(f, " PropFloatGetFunc fn = %s;\n", manualfunc);
994 fprintf(f, " return fn(ptr);\n");
995 }
996 else if (prop->type == PROP_ENUM) {
997 fprintf(f, " PropEnumGetFunc fn = %s;\n", manualfunc);
998 fprintf(f, " return fn(ptr);\n");
999 }
1000 else {
1001 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
1002 fprintf(f, " return %s(ptr);\n", manualfunc);
1003 }
1004 }
1005 else {
1006 rna_print_data_get(f, dp);
1007 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1008 fprintf(
1009 f, " return %s(((data->%s) & ", (dp->booleannegative) ? "!" : "", dp->dnaname);
1010 rna_int_print(f, dp->booleanbit);
1011 fprintf(f, ") != 0);\n");
1012 }
1013 else if (prop->type == PROP_ENUM && dp->enumbitflags) {
1014 fprintf(f, " return ((data->%s) & ", dp->dnaname);
1016 fprintf(f, ");\n");
1017 }
1018 else {
1019 fprintf(f,
1020 " return (%s)%s(data->%s);\n",
1021 rna_type_type(prop),
1022 (dp->booleannegative) ? "!" : "",
1023 dp->dnaname);
1024 }
1025 }
1026
1027 fprintf(f, "}\n\n");
1028 }
1029 break;
1030 }
1031
1032 return func;
1033}
1034
1035/* defined min/max variables to be used by rna_clamp_value() */
1036static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
1037{
1038 if (prop->type == PROP_FLOAT) {
1039 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1040 if (fprop->range) {
1041 fprintf(f,
1042 " float prop_clamp_min = -FLT_MAX, prop_clamp_max = FLT_MAX, prop_soft_min, "
1043 "prop_soft_max;\n");
1044 fprintf(f,
1045 " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
1046 rna_function_string(fprop->range));
1047 }
1048 }
1049 else if (prop->type == PROP_INT) {
1050 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1051 if (iprop->range) {
1052 fprintf(f,
1053 " int prop_clamp_min = INT_MIN, prop_clamp_max = INT_MAX, prop_soft_min, "
1054 "prop_soft_max;\n");
1055 fprintf(f,
1056 " %s(ptr, &prop_clamp_min, &prop_clamp_max, &prop_soft_min, &prop_soft_max);\n",
1057 rna_function_string(iprop->range));
1058 }
1059 }
1060}
1061
1062#ifdef USE_RNA_RANGE_CHECK
1063static void rna_clamp_value_range_check(FILE *f,
1064 PropertyRNA *prop,
1065 const char *dnaname_prefix,
1066 const char *dnaname)
1067{
1068 if (prop->type == PROP_INT) {
1069 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1070 fprintf(f, " {\n");
1071 fprintf(f, "#ifdef __cplusplus\n");
1072 fprintf(f, " using T = decltype(%s%s);\n", dnaname_prefix, dnaname);
1073 fprintf(f,
1074 " static_assert(std::numeric_limits<std::decay_t<T>>::max() >= %d);\n",
1075 iprop->hardmax);
1076 fprintf(f,
1077 " static_assert(std::numeric_limits<std::decay_t<T>>::min() <= %d);\n",
1078 iprop->hardmin);
1079 fprintf(f, "#else\n");
1080 fprintf(f,
1081 " BLI_STATIC_ASSERT("
1082 "(TYPEOF_MAX(%s%s) >= %d) && "
1083 "(TYPEOF_MIN(%s%s) <= %d), "
1084 "\"invalid limits\");\n",
1085 dnaname_prefix,
1086 dnaname,
1087 iprop->hardmax,
1088 dnaname_prefix,
1089 dnaname,
1090 iprop->hardmin);
1091 fprintf(f, "#endif\n");
1092 fprintf(f, " }\n");
1093 }
1094}
1095#endif /* USE_RNA_RANGE_CHECK */
1096
1097static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
1098{
1099 if (prop->type == PROP_INT) {
1100 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
1101
1102 if (iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX || iprop->range) {
1103 if (array) {
1104 fprintf(f, "std::clamp(values[i], ");
1105 }
1106 else {
1107 fprintf(f, "std::clamp(value, ");
1108 }
1109 if (iprop->range) {
1110 fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
1111 }
1112 else {
1113 rna_int_print(f, iprop->hardmin);
1114 fprintf(f, ", ");
1115 rna_int_print(f, iprop->hardmax);
1116 fprintf(f, ");\n");
1117 }
1118 return;
1119 }
1120 }
1121 else if (prop->type == PROP_FLOAT) {
1122 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
1123
1124 if (fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX || fprop->range) {
1125 if (array) {
1126 fprintf(f, "std::clamp(values[i], ");
1127 }
1128 else {
1129 fprintf(f, "std::clamp(value, ");
1130 }
1131 if (fprop->range) {
1132 fprintf(f, "prop_clamp_min, prop_clamp_max);\n");
1133 }
1134 else {
1135 rna_float_print(f, fprop->hardmin);
1136 fprintf(f, ", ");
1137 rna_float_print(f, fprop->hardmax);
1138 fprintf(f, ");\n");
1139 }
1140 return;
1141 }
1142 }
1143
1144 if (array) {
1145 fprintf(f, "values[i];\n");
1146 }
1147 else {
1148 fprintf(f, "value;\n");
1149 }
1150}
1151
1153 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1154{
1155 char *func;
1156
1157 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1158 return nullptr;
1159 }
1160 if (!manualfunc) {
1161 return nullptr;
1162 }
1163
1164 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "search");
1165
1166 fprintf(f,
1167 "extern void %s("
1168 "const bContext *C, "
1169 "PointerRNA *ptr, "
1170 "PropertyRNA *prop, "
1171 "const char *edit_text, "
1172 "blender::FunctionRef<void(StringPropertySearchVisitParams)> visit_fn)\n",
1173 func);
1174 fprintf(f, "{\n");
1175 fprintf(f, "\n StringPropertySearchFunc fn = %s;\n", manualfunc);
1176 fprintf(f, "\n fn(C, ptr, prop, edit_text, visit_fn);\n");
1177 fprintf(f, "}\n\n");
1178 return func;
1179}
1180
1182 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1183{
1184 char *func;
1185
1186 if (!(prop->flag & PROP_EDITABLE)) {
1187 return nullptr;
1188 }
1189 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1190 return nullptr;
1191 }
1192
1193 if (!manualfunc) {
1194 if (!dp->dnastructname || !dp->dnaname) {
1195 if (prop->flag & PROP_EDITABLE) {
1196 CLOG_ERROR(&LOG, "%s.%s has no valid dna info.", srna->identifier, prop->identifier);
1197 DefRNA.error = true;
1198 }
1199 return nullptr;
1200 }
1201 }
1202
1203 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set");
1204
1205 switch (prop->type) {
1206 case PROP_STRING: {
1207 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
1208 fprintf(f, "extern void %s(PointerRNA *ptr, const char *value)\n", func);
1209 fprintf(f, "{\n");
1210 if (manualfunc) {
1211 fprintf(f, " PropStringSetFunc fn = %s;\n", manualfunc);
1212 fprintf(f, " fn(ptr, value);\n");
1213 }
1214 else {
1215 const PropertySubType subtype = prop->subtype;
1216 rna_print_data_get(f, dp);
1217
1218 if (dp->dnapointerlevel == 1) {
1219 /* Handle allocated char pointer properties. */
1220 fprintf(f,
1221 " if (data->%s != nullptr) { MEM_freeN(data->%s); }\n",
1222 dp->dnaname,
1223 dp->dnaname);
1224 fprintf(f, " const size_t length = strlen(value);\n");
1225 fprintf(f, " if (length > 0) {\n");
1226 fprintf(f,
1227 " data->%s = MEM_malloc_arrayN<char>(length + 1, __func__);\n",
1228 dp->dnaname);
1229 fprintf(f, " memcpy(data->%s, value, length + 1);\n", dp->dnaname);
1230 fprintf(f, " } else { data->%s = nullptr; }\n", dp->dnaname);
1231 }
1232 else {
1233 const char *string_copy_func =
1235 "BLI_strncpy" :
1236 "BLI_strncpy_utf8";
1237 /* Handle char array properties. */
1238 if (sprop->maxlength) {
1239 fprintf(f,
1240 " %s(data->%s, value, %d);\n",
1241 string_copy_func,
1242 dp->dnaname,
1243 sprop->maxlength);
1244 }
1245 else {
1246 fprintf(f,
1247 " %s(data->%s, value, sizeof(data->%s));\n",
1248 string_copy_func,
1249 dp->dnaname,
1250 dp->dnaname);
1251 }
1252 }
1253 }
1254 fprintf(f, "}\n\n");
1255 break;
1256 }
1257 case PROP_POINTER: {
1258 fprintf(f,
1259 "extern void %s(PointerRNA *ptr, PointerRNA value, struct ReportList *reports)\n",
1260 func);
1261 fprintf(f, "{\n");
1262 if (manualfunc) {
1263 fprintf(f, " PropPointerSetFunc fn = %s;\n", manualfunc);
1264 fprintf(f, " fn(ptr, value, reports);\n");
1265 }
1266 else {
1267 rna_print_data_get(f, dp);
1268
1270 StructRNA *type = (pprop->type) ? rna_find_struct((const char *)pprop->type) : nullptr;
1271
1272 if (prop->flag & PROP_ID_SELF_CHECK) {
1273 /* No pointers to self allowed. */
1274 rna_print_id_get(f, dp);
1275 fprintf(f, " if (id == value.data) {\n");
1276 fprintf(f, " return;\n");
1277 fprintf(f, " }\n");
1278 }
1279
1280 if (type && (type->flag & STRUCT_ID)) {
1281 /* Check if pointers between datablocks are allowed. */
1282 fprintf(f,
1283 " if (value.data && ptr->owner_id && value.owner_id && "
1284 "!BKE_id_can_use_id(*ptr->owner_id, *value.owner_id)) {\n");
1285 fprintf(f, " return;\n");
1286 fprintf(f, " }\n");
1287 }
1288
1289 if (prop->flag & PROP_ID_REFCOUNT) {
1290 /* Perform reference counting. */
1291 fprintf(f, "\n if (data->%s) {\n", dp->dnaname);
1292 fprintf(f, " id_us_min((ID *)data->%s);\n", dp->dnaname);
1293 fprintf(f, " }\n");
1294 fprintf(f, " if (value.data) {\n");
1295 fprintf(f, " id_us_plus((ID *)value.data);\n");
1296 fprintf(f, " }\n");
1297 }
1298 else if (type && (type->flag & STRUCT_ID)) {
1299 /* Still mark linked data as used if not reference counting. */
1300 fprintf(f, " if (value.data) {\n");
1301 fprintf(f, " id_lib_extern((ID *)value.data);\n");
1302 fprintf(f, " }\n");
1303 }
1304
1305 fprintf(f, " *(void **)&data->%s = value.data;\n", dp->dnaname);
1306 }
1307 fprintf(f, "}\n\n");
1308 break;
1309 }
1310 default:
1311 if (prop->arraydimension) {
1312 if (prop->flag & PROP_DYNAMIC) {
1313 fprintf(f,
1314 "extern void %s(PointerRNA *ptr, const %s values[])\n",
1315 func,
1316 rna_type_type(prop));
1317 }
1318 else {
1319 fprintf(f,
1320 "extern void %s(PointerRNA *ptr, const %s values[%u])\n",
1321 func,
1322 rna_type_type(prop),
1323 prop->totarraylength);
1324 }
1325 fprintf(f, "{\n");
1326
1327 if (manualfunc) {
1328 /* Assign `fn` to ensure function signatures match. */
1329 if (prop->type == PROP_BOOLEAN) {
1330 fprintf(f, " PropBooleanArraySetFunc fn = %s;\n", manualfunc);
1331 fprintf(f, " fn(ptr, values);\n");
1332 }
1333 else if (prop->type == PROP_INT) {
1334 fprintf(f, " PropIntArraySetFunc fn = %s;\n", manualfunc);
1335 fprintf(f, " fn(ptr, values);\n");
1336 }
1337 else if (prop->type == PROP_FLOAT) {
1338 fprintf(f, " PropFloatArraySetFunc fn = %s;\n", manualfunc);
1339 fprintf(f, " fn(ptr, values);\n");
1340 }
1341 else {
1342 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
1343 fprintf(f, " %s(ptr, values);\n", manualfunc);
1344 }
1345 }
1346 else {
1347 rna_print_data_get(f, dp);
1348
1349 if (prop->flag & PROP_DYNAMIC) {
1350 char *lenfunc = rna_alloc_function_name(
1351 srna->identifier, rna_safe_id(prop->identifier), "set_length");
1352 fprintf(f, " unsigned int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
1353 fprintf(f, " unsigned int len = %s(ptr, arraylen);\n\n", lenfunc);
1354 rna_clamp_value_range(f, prop);
1355 fprintf(f, " for (i = 0; i < len; i++) {\n");
1356 MEM_freeN(lenfunc);
1357 }
1358 else {
1359 fprintf(f, " unsigned int i;\n\n");
1360 rna_clamp_value_range(f, prop);
1361 fprintf(f, " for (i = 0; i < %u; i++) {\n", prop->totarraylength);
1362 }
1363
1364 if (dp->dnaarraylength == 1) {
1365 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1366 fprintf(f,
1367 " if (%svalues[i]) { data->%s |= (",
1368 (dp->booleannegative) ? "!" : "",
1369 dp->dnaname);
1370 rna_int_print(f, dp->booleanbit);
1371 fprintf(f, " << i); }\n");
1372 fprintf(f, " else { data->%s &= ~(", dp->dnaname);
1373 rna_int_print(f, dp->booleanbit);
1374 fprintf(f, " << i); }\n");
1375 }
1376 else {
1377 fprintf(
1378 f, " (&data->%s)[i] = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
1379 rna_clamp_value(f, prop, 1);
1380 }
1381 }
1382 else {
1383 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1384 fprintf(f,
1385 " if (%svalues[i]) { data->%s[i] |= ",
1386 (dp->booleannegative) ? "!" : "",
1387 dp->dnaname);
1388 rna_int_print(f, dp->booleanbit);
1389 fprintf(f, "; }\n");
1390 fprintf(f, " else { data->%s[i] &= ~", dp->dnaname);
1391 rna_int_print(f, dp->booleanbit);
1392 fprintf(f, "; }\n");
1393 }
1394 else if (rna_color_quantize(prop, dp)) {
1395 fprintf(
1396 f, " data->%s[i] = unit_float_to_uchar_clamp(values[i]);\n", dp->dnaname);
1397 }
1398 else {
1399 if (dp->dnatype) {
1400 fprintf(f,
1401 " ((%s *)data->%s)[i] = %s",
1402 dp->dnatype,
1403 dp->dnaname,
1404 (dp->booleannegative) ? "!" : "");
1405 }
1406 else {
1407 fprintf(f,
1408 " (data->%s)[i] = %s",
1409 dp->dnaname,
1410 (dp->booleannegative) ? "!" : "");
1411 }
1412 rna_clamp_value(f, prop, 1);
1413 }
1414 }
1415 fprintf(f, " }\n");
1416 }
1417
1418#ifdef USE_RNA_RANGE_CHECK
1419 if (dp->dnaname && manualfunc == nullptr) {
1420 if (dp->dnaarraylength == 1) {
1421 rna_clamp_value_range_check(f, prop, "data->", dp->dnaname);
1422 }
1423 else {
1424 rna_clamp_value_range_check(f, prop, "*data->", dp->dnaname);
1425 }
1426 }
1427#endif
1428
1429 fprintf(f, "}\n\n");
1430 }
1431 else {
1432 fprintf(f, "extern void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
1433 fprintf(f, "{\n");
1434
1435 if (manualfunc) {
1436 /* Assign `fn` to ensure function signatures match. */
1437 if (prop->type == PROP_BOOLEAN) {
1438 fprintf(f, " PropBooleanSetFunc fn = %s;\n", manualfunc);
1439 fprintf(f, " fn(ptr, value);\n");
1440 }
1441 else if (prop->type == PROP_INT) {
1442 fprintf(f, " PropIntSetFunc fn = %s;\n", manualfunc);
1443 fprintf(f, " fn(ptr, value);\n");
1444 }
1445 else if (prop->type == PROP_FLOAT) {
1446 fprintf(f, " PropFloatSetFunc fn = %s;\n", manualfunc);
1447 fprintf(f, " fn(ptr, value);\n");
1448 }
1449 else if (prop->type == PROP_ENUM) {
1450 fprintf(f, " PropEnumSetFunc fn = %s;\n", manualfunc);
1451 fprintf(f, " fn(ptr, value);\n");
1452 }
1453 else {
1454 BLI_assert_unreachable(); /* Valid but should be handled by type checks. */
1455 fprintf(f, " %s(ptr, value);\n", manualfunc);
1456 }
1457 }
1458 else {
1459 rna_print_data_get(f, dp);
1460 if (prop->type == PROP_BOOLEAN && dp->booleanbit) {
1461 fprintf(f,
1462 " if (%svalue) { data->%s |= ",
1463 (dp->booleannegative) ? "!" : "",
1464 dp->dnaname);
1465 rna_int_print(f, dp->booleanbit);
1466 fprintf(f, "; }\n");
1467 fprintf(f, " else { data->%s &= ~", dp->dnaname);
1468 rna_int_print(f, dp->booleanbit);
1469 fprintf(f, "; }\n");
1470 }
1471 else if (prop->type == PROP_ENUM && dp->enumbitflags) {
1472 fprintf(f, " data->%s &= ~", dp->dnaname);
1474 fprintf(f, ";\n");
1475 fprintf(f, " data->%s |= value;\n", dp->dnaname);
1476 }
1477 else {
1478 rna_clamp_value_range(f, prop);
1479 /* C++ may require casting to an enum type. */
1480 fprintf(f, "#ifdef __cplusplus\n");
1481 fprintf(f,
1482 /* If #rna_clamp_value() adds an expression like `std::clamp(...)`
1483 * (instead of an `lvalue`), #decltype() yields a reference,
1484 * so that has to be removed. */
1485 " data->%s = %s(std::remove_reference_t<decltype(data->%s)>)",
1486 dp->dnaname,
1487 (dp->booleannegative) ? "!" : "",
1488 dp->dnaname);
1489 rna_clamp_value(f, prop, 0);
1490 fprintf(f, "#else\n");
1491 fprintf(f, " data->%s = %s", dp->dnaname, (dp->booleannegative) ? "!" : "");
1492 rna_clamp_value(f, prop, 0);
1493 fprintf(f, "#endif\n");
1494 }
1495 }
1496
1497#ifdef USE_RNA_RANGE_CHECK
1498 if (dp->dnaname && manualfunc == nullptr) {
1499 rna_clamp_value_range_check(f, prop, "data->", dp->dnaname);
1500 }
1501#endif
1502
1503 fprintf(f, "}\n\n");
1504 }
1505 break;
1506 }
1507
1508 return func;
1509}
1510
1512 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1513{
1514 char *func = nullptr;
1515
1516 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1517 return nullptr;
1518 }
1519
1520 if (prop->type == PROP_STRING) {
1521 if (!manualfunc) {
1522 if (!dp->dnastructname || !dp->dnaname) {
1523 CLOG_ERROR(&LOG, "%s.%s has no valid dna info.", srna->identifier, prop->identifier);
1524 DefRNA.error = true;
1525 return nullptr;
1526 }
1527 }
1528
1529 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
1530
1531 fprintf(f, "extern int %s(PointerRNA *ptr)\n", func);
1532 fprintf(f, "{\n");
1533 if (manualfunc) {
1534 fprintf(f, " PropStringLengthFunc fn = %s;\n", manualfunc);
1535 fprintf(f, " return fn(ptr);\n");
1536 }
1537 else {
1538 rna_print_data_get(f, dp);
1539 if (dp->dnapointerlevel == 1) {
1540 /* Handle allocated char pointer properties. */
1541 fprintf(f,
1542 " return (data->%s == nullptr) ? 0 : strlen(data->%s);\n",
1543 dp->dnaname,
1544 dp->dnaname);
1545 }
1546 else {
1547 /* Handle char array properties. */
1548 fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
1549 }
1550 }
1551 fprintf(f, "}\n\n");
1552 }
1553 else if (prop->type == PROP_COLLECTION) {
1554 if (!manualfunc) {
1555 if (prop->type == PROP_COLLECTION &&
1556 (!(dp->dnalengthname || dp->dnalengthfixed) || !dp->dnaname))
1557 {
1558 CLOG_ERROR(&LOG, "%s.%s has no valid dna info.", srna->identifier, prop->identifier);
1559 DefRNA.error = true;
1560 return nullptr;
1561 }
1562 }
1563
1564 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length");
1565
1566 fprintf(f, "extern int %s(PointerRNA *ptr)\n", func);
1567 fprintf(f, "{\n");
1568 if (manualfunc) {
1569 fprintf(f, " PropCollectionLengthFunc fn = %s;\n", manualfunc);
1570 fprintf(f, " return fn(ptr);\n");
1571 }
1572 else {
1573 if (dp->dnaarraylength <= 1 || dp->dnalengthname) {
1574 rna_print_data_get(f, dp);
1575 }
1576
1577 if (dp->dnaarraylength > 1) {
1578 fprintf(f, " return ");
1579 }
1580 else {
1581 fprintf(f, " return (data->%s == nullptr) ? 0 : ", dp->dnaname);
1582 }
1583
1584 if (dp->dnalengthname) {
1585 fprintf(f, "data->%s;\n", dp->dnalengthname);
1586 }
1587 else {
1588 fprintf(f, "%d;\n", dp->dnalengthfixed);
1589 }
1590 }
1591 fprintf(f, "}\n\n");
1592 }
1593
1594 return func;
1595}
1596
1598 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
1599{
1600 char *func, *getfunc;
1601
1602 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1603 return nullptr;
1604 }
1605
1606 if (!manualfunc) {
1607 if (!dp->dnastructname || !dp->dnaname) {
1608 CLOG_ERROR(&LOG, "%s.%s has no valid dna info.", srna->identifier, prop->identifier);
1609 DefRNA.error = true;
1610 return nullptr;
1611 }
1612 }
1613
1614 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin");
1615
1616 fprintf(f, "extern void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
1617 fprintf(f, "{\n");
1618
1619 if (!manualfunc) {
1620 rna_print_data_get(f, dp);
1621 }
1622
1623 fprintf(f, "\n *iter = {};\n");
1624 fprintf(f, " iter->parent = *ptr;\n");
1625 fprintf(f, " iter->prop = &rna_%s_%s;\n", srna->identifier, prop->identifier);
1626
1627 if (dp->dnalengthname || dp->dnalengthfixed) {
1628 if (manualfunc) {
1629 fprintf(f, "\n PropCollectionBeginFunc fn = %s;\n", manualfunc);
1630 fprintf(f, " fn(iter, ptr);\n");
1631 }
1632 else {
1633 if (dp->dnalengthname) {
1634 fprintf(f,
1635 "\n rna_iterator_array_begin(iter, ptr, data->%s, sizeof(data->%s[0]), "
1636 "data->%s, 0, nullptr);\n",
1637 dp->dnaname,
1638 dp->dnaname,
1639 dp->dnalengthname);
1640 }
1641 else {
1642 fprintf(f,
1643 "\n rna_iterator_array_begin(iter, ptr, data->%s, sizeof(data->%s[0]), %d, 0, "
1644 "nullptr);\n",
1645 dp->dnaname,
1646 dp->dnaname,
1647 dp->dnalengthfixed);
1648 }
1649 }
1650 }
1651 else {
1652 if (manualfunc) {
1653 fprintf(f, "\n PropCollectionBeginFunc fn = %s;\n", manualfunc);
1654 fprintf(f, " fn(iter, ptr);\n");
1655 }
1656 else if (dp->dnapointerlevel == 0) {
1657 fprintf(
1658 f, "\n rna_iterator_listbase_begin(iter, ptr, &data->%s, nullptr);\n", dp->dnaname);
1659 }
1660 else {
1661 fprintf(
1662 f, "\n rna_iterator_listbase_begin(iter, ptr, data->%s, nullptr);\n", dp->dnaname);
1663 }
1664 }
1665
1666 getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1667
1668 fprintf(f, "\n if (iter->valid) {\n");
1669 fprintf(f, " iter->ptr = %s(iter);", getfunc);
1670 fprintf(f, "\n }\n");
1671
1672 fprintf(f, "}\n\n");
1673
1674 return func;
1675}
1676
1678 StructRNA *srna,
1679 PropertyRNA *prop,
1680 PropertyDefRNA *dp,
1681 const char *manualfunc,
1682 const char *nextfunc)
1683{
1684 /* note on indices, this is for external functions and ignores skipped values.
1685 * so the index can only be checked against the length when there is no 'skip' function. */
1686 char *func;
1687
1688 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1689 return nullptr;
1690 }
1691
1692 if (!manualfunc) {
1693 if (!dp->dnastructname || !dp->dnaname) {
1694 return nullptr;
1695 }
1696
1697 /* only supported in case of standard next functions */
1698 if (STREQ(nextfunc, "rna_iterator_array_next")) {
1699 }
1700 else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {
1701 }
1702 else {
1703 return nullptr;
1704 }
1705 }
1706
1707 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int");
1708
1709 fprintf(f, "extern bool %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func);
1710 fprintf(f, "{\n");
1711
1712 if (manualfunc) {
1713 fprintf(f, "\n PropCollectionLookupIntFunc fn = %s;\n", manualfunc);
1714 fprintf(f, " return fn(ptr, index, r_ptr);\n");
1715 fprintf(f, "}\n\n");
1716 return func;
1717 }
1718
1719 fprintf(f, " bool found = false;\n");
1720 fprintf(f, " CollectionPropertyIterator iter;\n\n");
1721
1722 fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1723 fprintf(f, " if (iter.valid) {\n");
1724
1725 if (STREQ(nextfunc, "rna_iterator_array_next")) {
1726 fprintf(f, " ArrayIterator *internal = &iter.internal.array;\n");
1727 fprintf(f, " if (index < 0 || index >= internal->length) {\n");
1728 fprintf(f, "#ifdef __GNUC__\n");
1729 fprintf(f,
1730 " printf(\"Array iterator out of range: %%s (index %%d)\\n\", __func__, "
1731 "index);\n");
1732 fprintf(f, "#else\n");
1733 fprintf(f, " printf(\"Array iterator out of range: (index %%d)\\n\", index);\n");
1734 fprintf(f, "#endif\n");
1735 fprintf(f, " }\n");
1736 fprintf(f, " else if (internal->skip) {\n");
1737 fprintf(f, " while (index-- > 0 && iter.valid) {\n");
1738 fprintf(f, " rna_iterator_array_next(&iter);\n");
1739 fprintf(f, " }\n");
1740 fprintf(f, " found = (index == -1 && iter.valid);\n");
1741 fprintf(f, " }\n");
1742 fprintf(f, " else {\n");
1743 fprintf(f, " internal->ptr += internal->itemsize * index;\n");
1744 fprintf(f, " found = 1;\n");
1745 fprintf(f, " }\n");
1746 }
1747 else if (STREQ(nextfunc, "rna_iterator_listbase_next")) {
1748 fprintf(f, " ListBaseIterator *internal = &iter.internal.listbase;\n");
1749 fprintf(f, " if (internal->skip) {\n");
1750 fprintf(f, " while (index-- > 0 && iter.valid) {\n");
1751 fprintf(f, " rna_iterator_listbase_next(&iter);\n");
1752 fprintf(f, " }\n");
1753 fprintf(f, " found = (index == -1 && iter.valid);\n");
1754 fprintf(f, " }\n");
1755 fprintf(f, " else {\n");
1756 fprintf(f, " while (index-- > 0 && internal->link) {\n");
1757 fprintf(f, " internal->link = internal->link->next;\n");
1758 fprintf(f, " }\n");
1759 fprintf(f, " found = (index == -1 && internal->link);\n");
1760 fprintf(f, " }\n");
1761 }
1762
1763 fprintf(f,
1764 " if (found) { *r_ptr = %s_%s_get(&iter); }\n",
1765 srna->identifier,
1766 rna_safe_id(prop->identifier));
1767 fprintf(f, " }\n\n");
1768 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1769
1770 fprintf(f, " return found;\n");
1771
1772#if 0
1773 rna_print_data_get(f, dp);
1774 item_type = (cprop->item_type) ? (const char *)cprop->item_type : "UnknownType";
1775
1776 if (dp->dnalengthname || dp->dnalengthfixed) {
1777 if (dp->dnalengthname) {
1778 fprintf(f,
1779 "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, "
1780 "index);\n",
1781 item_type,
1782 dp->dnaname,
1783 dp->dnaname,
1784 dp->dnalengthname);
1785 }
1786 else {
1787 fprintf(
1788 f,
1789 "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n",
1790 item_type,
1791 dp->dnaname,
1792 dp->dnaname,
1793 dp->dnalengthfixed);
1794 }
1795 }
1796 else {
1797 if (dp->dnapointerlevel == 0) {
1798 fprintf(f,
1799 "\n return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n",
1800 item_type,
1801 dp->dnaname);
1802 }
1803 else {
1804 fprintf(f,
1805 "\n return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n",
1806 item_type,
1807 dp->dnaname);
1808 }
1809 }
1810#endif
1811
1812 fprintf(f, "}\n\n");
1813
1814 return func;
1815}
1816
1818 StructRNA *srna,
1819 PropertyRNA *prop,
1820 PropertyDefRNA *dp,
1821 const char *manualfunc,
1822 const char *item_type)
1823{
1824 char *func;
1825 StructRNA *item_srna, *item_name_base;
1826 PropertyRNA *item_name_prop;
1827 const int namebuflen = 1024;
1828
1829 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1830 return nullptr;
1831 }
1832
1833 if (!manualfunc) {
1834 if (!dp->dnastructname || !dp->dnaname) {
1835 return nullptr;
1836 }
1837
1838 /* only supported for collection items with name properties */
1839 item_srna = rna_find_struct(item_type);
1840 if (item_srna && item_srna->nameproperty) {
1841 item_name_prop = item_srna->nameproperty;
1842 item_name_base = item_srna;
1843 while (item_name_base->base && item_name_base->base->nameproperty == item_name_prop) {
1844 item_name_base = item_name_base->base;
1845 }
1846 }
1847 else {
1848 return nullptr;
1849 }
1850 }
1851
1852 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_string");
1853
1854 if (!manualfunc) {
1855 /* XXX extern declaration could be avoid by including RNA_blender.hh, but this has lots of
1856 * unknown DNA types in functions, leading to conflicting function signatures.
1857 */
1858 fprintf(f,
1859 "extern int %s_%s_length(PointerRNA *);\n",
1860 item_name_base->identifier,
1861 rna_safe_id(item_name_prop->identifier));
1862 fprintf(f,
1863 "extern void %s_%s_get(PointerRNA *, char *);\n\n",
1864 item_name_base->identifier,
1865 rna_safe_id(item_name_prop->identifier));
1866 }
1867
1868 fprintf(f, "extern bool %s(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)\n", func);
1869 fprintf(f, "{\n");
1870
1871 if (manualfunc) {
1872 fprintf(f, " PropCollectionLookupStringFunc fn = %s;\n", manualfunc);
1873 fprintf(f, " return fn(ptr, key, r_ptr);\n");
1874 fprintf(f, "}\n\n");
1875 return func;
1876 }
1877
1878 fprintf(f, " bool found = false;\n");
1879 fprintf(f, " CollectionPropertyIterator iter;\n");
1880 fprintf(f, " char namebuf[%d];\n", namebuflen);
1881 fprintf(f, " char *name;\n\n");
1882
1883 fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1884
1885 fprintf(f, " while (iter.valid) {\n");
1886 fprintf(f, " if (iter.ptr.data) {\n");
1887 fprintf(f,
1888 " int namelen = %s_%s_length(&iter.ptr);\n",
1889 item_name_base->identifier,
1890 rna_safe_id(item_name_prop->identifier));
1891 fprintf(f, " if (namelen < %d) {\n", namebuflen);
1892 fprintf(f,
1893 " %s_%s_get(&iter.ptr, namebuf);\n",
1894 item_name_base->identifier,
1895 rna_safe_id(item_name_prop->identifier));
1896 fprintf(f, " if (strcmp(namebuf, key) == 0) {\n");
1897 fprintf(f, " found = true;\n");
1898 fprintf(f, " *r_ptr = iter.ptr;\n");
1899 fprintf(f, " break;\n");
1900 fprintf(f, " }\n");
1901 fprintf(f, " }\n");
1902 fprintf(f, " else {\n");
1903 fprintf(f, " name = MEM_malloc_arrayN<char>(size_t(namelen) + 1,\n");
1904 fprintf(f, " \"name string\");\n");
1905 fprintf(f,
1906 " %s_%s_get(&iter.ptr, name);\n",
1907 item_name_base->identifier,
1908 rna_safe_id(item_name_prop->identifier));
1909 fprintf(f, " if (strcmp(name, key) == 0) {\n");
1910 fprintf(f, " MEM_freeN(name);\n\n");
1911 fprintf(f, " found = true;\n");
1912 fprintf(f, " *r_ptr = iter.ptr;\n");
1913 fprintf(f, " break;\n");
1914 fprintf(f, " }\n");
1915 fprintf(f, " else {\n");
1916 fprintf(f, " MEM_freeN(name);\n");
1917 fprintf(f, " }\n");
1918 fprintf(f, " }\n");
1919 fprintf(f, " }\n");
1920 fprintf(f, " %s_%s_next(&iter);\n", srna->identifier, rna_safe_id(prop->identifier));
1921 fprintf(f, " }\n");
1922 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier));
1923
1924 fprintf(f, " return found;\n");
1925 fprintf(f, "}\n\n");
1926
1927 return func;
1928}
1929
1931 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1932{
1933 char *func, *getfunc;
1934
1935 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1936 return nullptr;
1937 }
1938
1939 if (!manualfunc) {
1940 return nullptr;
1941 }
1942
1943 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next");
1944
1945 fprintf(f, "extern void %s(CollectionPropertyIterator *iter)\n", func);
1946 fprintf(f, "{\n");
1947 fprintf(f, " PropCollectionNextFunc fn = %s;\n", manualfunc);
1948 fprintf(f, " fn(iter);\n");
1949
1950 getfunc = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get");
1951
1952 fprintf(f, "\n if (iter->valid) {\n");
1953 fprintf(f, " iter->ptr = %s(iter);", getfunc);
1954 fprintf(f, "\n }\n");
1955
1956 fprintf(f, "}\n\n");
1957
1958 return func;
1959}
1960
1962 FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA * /*dp*/, const char *manualfunc)
1963{
1964 char *func;
1965
1966 if (prop->flag & PROP_IDPROPERTY && manualfunc == nullptr) {
1967 return nullptr;
1968 }
1969
1970 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end");
1971
1972 fprintf(f, "extern void %s(CollectionPropertyIterator *iter)\n", func);
1973 fprintf(f, "{\n");
1974 if (manualfunc) {
1975 fprintf(f, " PropCollectionEndFunc fn = %s;\n", manualfunc);
1976 fprintf(f, " fn(iter);\n");
1977 }
1978 fprintf(f, "}\n\n");
1979
1980 return func;
1981}
1982
1984{
1985 if (dp->dnapointerlevel != 0) {
1986 return;
1987 }
1988 if (!dp->dnatype || !dp->dnaname || !dp->dnastructname) {
1989 return;
1990 }
1991
1992 if (STREQ(dp->dnatype, "char")) {
1995 }
1996 else if (STREQ(dp->dnatype, "int8_t")) {
1999 }
2000 else if (STREQ(dp->dnatype, "uchar")) {
2003 }
2004 else if (STREQ(dp->dnatype, "short")) {
2005 prop->rawtype = PROP_RAW_SHORT;
2007 }
2008 else if (STREQ(dp->dnatype, "ushort")) {
2009 prop->rawtype = PROP_RAW_UINT16;
2011 }
2012 else if (STREQ(dp->dnatype, "int")) {
2013 prop->rawtype = PROP_RAW_INT;
2015 }
2016 else if (STREQ(dp->dnatype, "float")) {
2017 prop->rawtype = PROP_RAW_FLOAT;
2019 }
2020 else if (STREQ(dp->dnatype, "double")) {
2021 prop->rawtype = PROP_RAW_DOUBLE;
2023 }
2024 else if (STREQ(dp->dnatype, "int64_t")) {
2025 prop->rawtype = PROP_RAW_INT64;
2027 }
2028 else if (STREQ(dp->dnatype, "uint64_t")) {
2029 prop->rawtype = PROP_RAW_UINT64;
2031 }
2032}
2033
2034static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
2035{
2037
2038 fprintf(
2039 f, "\toffsetof(%s, %s), RawPropertyType(%d)", dp->dnastructname, dp->dnaname, prop->rawtype);
2040}
2041
2042static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
2043{
2044 PropertyRNA *prop;
2045
2046 prop = dp->prop;
2047
2048 switch (prop->type) {
2049 case PROP_BOOLEAN: {
2050 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
2051
2052 if (!(prop->flag & PROP_EDITABLE) &&
2053 (bprop->set || bprop->set_ex || bprop->set_transform || bprop->setarray ||
2054 bprop->setarray_ex || bprop->setarray_transform))
2055 {
2056 CLOG_ERROR(&LOG,
2057 "%s.%s, is read-only but has defines a \"set\" callback.",
2058 srna->identifier,
2059 prop->identifier);
2060 DefRNA.error = true;
2061 }
2062
2063 if (!prop->arraydimension &&
2064 (bprop->getarray || bprop->getarray_ex || bprop->getarray_transform || bprop->setarray ||
2065 bprop->setarray_ex || bprop->setarray_transform))
2066 {
2067 CLOG_ERROR(&LOG,
2068 "%s.%s, is not an array but defines an array callback.",
2069 srna->identifier,
2070 prop->identifier);
2071 DefRNA.error = true;
2072 }
2073
2074 if (!prop->arraydimension) {
2075 if (!bprop->get && !bprop->set && !dp->booleanbit) {
2076 rna_set_raw_property(dp, prop);
2077 }
2078
2079 bprop->get = reinterpret_cast<PropBooleanGetFunc>(
2080 rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->get));
2081 bprop->set = reinterpret_cast<PropBooleanSetFunc>(
2082 rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->set));
2083 }
2084 else {
2085 bprop->getarray = reinterpret_cast<PropBooleanArrayGetFunc>(
2086 rna_def_property_get_func(f, srna, prop, dp, (const char *)bprop->getarray));
2087 bprop->setarray = reinterpret_cast<PropBooleanArraySetFunc>(
2088 rna_def_property_set_func(f, srna, prop, dp, (const char *)bprop->setarray));
2089 }
2090 break;
2091 }
2092 case PROP_INT: {
2093 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
2094
2095 if (!(prop->flag & PROP_EDITABLE) &&
2096 (iprop->set || iprop->set_ex || iprop->set_transform || iprop->setarray ||
2097 iprop->setarray_ex || iprop->setarray_transform))
2098 {
2099 CLOG_ERROR(&LOG,
2100 "%s.%s, is read-only but has defines a \"set\" callback.",
2101 srna->identifier,
2102 prop->identifier);
2103 DefRNA.error = true;
2104 }
2105
2106 if (!prop->arraydimension &&
2107 (iprop->getarray || iprop->getarray_ex || iprop->getarray_transform || iprop->setarray ||
2108 iprop->setarray_ex || iprop->setarray_transform))
2109 {
2110 CLOG_ERROR(&LOG,
2111 "%s.%s, is not an array but defines an array callback.",
2112 srna->identifier,
2113 prop->identifier);
2114 DefRNA.error = true;
2115 }
2116
2117 if (!prop->arraydimension) {
2118 if (!iprop->get && !iprop->set) {
2119 rna_set_raw_property(dp, prop);
2120 }
2121
2122 iprop->get = reinterpret_cast<PropIntGetFunc>(
2123 rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->get));
2124 iprop->set = reinterpret_cast<PropIntSetFunc>(
2125 rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->set));
2126 }
2127 else {
2128 if (!iprop->getarray && !iprop->setarray) {
2129 rna_set_raw_property(dp, prop);
2130 }
2131
2132 iprop->getarray = reinterpret_cast<PropIntArrayGetFunc>(
2133 rna_def_property_get_func(f, srna, prop, dp, (const char *)iprop->getarray));
2134 iprop->setarray = reinterpret_cast<PropIntArraySetFunc>(
2135 rna_def_property_set_func(f, srna, prop, dp, (const char *)iprop->setarray));
2136 }
2137 break;
2138 }
2139 case PROP_FLOAT: {
2140 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
2141
2142 if (!(prop->flag & PROP_EDITABLE) &&
2143 (fprop->set || fprop->set_ex || fprop->set_transform || fprop->setarray ||
2144 fprop->setarray_ex || fprop->setarray_transform))
2145 {
2146 CLOG_ERROR(&LOG,
2147 "%s.%s, is read-only but has defines a \"set\" callback.",
2148 srna->identifier,
2149 prop->identifier);
2150 DefRNA.error = true;
2151 }
2152
2153 if (!prop->arraydimension &&
2154 (fprop->getarray || fprop->getarray_ex || fprop->getarray_transform || fprop->setarray ||
2155 fprop->setarray_ex || fprop->setarray_transform))
2156 {
2157 CLOG_ERROR(&LOG,
2158 "%s.%s, is not an array but defines an array callback.",
2159 srna->identifier,
2160 prop->identifier);
2161 DefRNA.error = true;
2162 }
2163
2164 if (!prop->arraydimension) {
2165 if (!fprop->get && !fprop->set) {
2166 rna_set_raw_property(dp, prop);
2167 }
2168
2169 fprop->get = reinterpret_cast<PropFloatGetFunc>(
2170 rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->get));
2171 fprop->set = reinterpret_cast<PropFloatSetFunc>(
2172 rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->set));
2173 }
2174 else {
2175 if (!fprop->getarray && !fprop->setarray) {
2176 rna_set_raw_property(dp, prop);
2177 }
2178
2179 fprop->getarray = reinterpret_cast<PropFloatArrayGetFunc>(
2180 rna_def_property_get_func(f, srna, prop, dp, (const char *)fprop->getarray));
2181 fprop->setarray = reinterpret_cast<PropFloatArraySetFunc>(
2182 rna_def_property_set_func(f, srna, prop, dp, (const char *)fprop->setarray));
2183 }
2184 break;
2185 }
2186 case PROP_ENUM: {
2187 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2188
2189 if (dp->enumbitflags && eprop->item_fn &&
2190 !(eprop->item != rna_enum_dummy_NULL_items || eprop->set || eprop->set_ex ||
2191 eprop->set_transform))
2192 {
2193 CLOG_ERROR(&LOG,
2194 "%s.%s, bitflag enum should not define an `item` callback function, unless "
2195 "they also define a static list of items, or a custom `set` callback.",
2196 srna->identifier,
2197 prop->identifier);
2198 DefRNA.error = true;
2199 }
2200
2201 if (!(prop->flag & PROP_EDITABLE) && (eprop->set || eprop->set_ex || eprop->set_transform)) {
2202 CLOG_ERROR(&LOG,
2203 "%s.%s, is read-only but has defines a \"set\" callback.",
2204 srna->identifier,
2205 prop->identifier);
2206 DefRNA.error = true;
2207 }
2208
2209 if (!eprop->get && !eprop->set) {
2210 rna_set_raw_property(dp, prop);
2211 }
2212
2213 eprop->get = reinterpret_cast<PropEnumGetFunc>(
2214 rna_def_property_get_func(f, srna, prop, dp, (const char *)eprop->get));
2215 eprop->set = reinterpret_cast<PropEnumSetFunc>(
2216 rna_def_property_set_func(f, srna, prop, dp, (const char *)eprop->set));
2217 break;
2218 }
2219 case PROP_STRING: {
2220 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2221
2222 if (!(prop->flag & PROP_EDITABLE) && (sprop->set || sprop->set_ex || sprop->set_transform)) {
2223 CLOG_ERROR(&LOG,
2224 "%s.%s, is read-only but has defines a \"set\" callback.",
2225 srna->identifier,
2226 prop->identifier);
2227 DefRNA.error = true;
2228 }
2229
2230 sprop->get = reinterpret_cast<PropStringGetFunc>(
2231 rna_def_property_get_func(f, srna, prop, dp, (const char *)sprop->get));
2232 sprop->length = reinterpret_cast<PropStringLengthFunc>(
2233 rna_def_property_length_func(f, srna, prop, dp, (const char *)sprop->length));
2234 sprop->set = reinterpret_cast<PropStringSetFunc>(
2235 rna_def_property_set_func(f, srna, prop, dp, (const char *)sprop->set));
2236 sprop->search = reinterpret_cast<StringPropertySearchFunc>(
2237 rna_def_property_search_func(f, srna, prop, dp, (const char *)sprop->search));
2238 break;
2239 }
2240 case PROP_POINTER: {
2241 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
2242
2243 if (!(prop->flag & PROP_EDITABLE) && pprop->set) {
2244 CLOG_ERROR(&LOG,
2245 "%s.%s, is read-only but has defines a \"set\" callback.",
2246 srna->identifier,
2247 prop->identifier);
2248 DefRNA.error = true;
2249 }
2250
2251 pprop->get = reinterpret_cast<PropPointerGetFunc>(
2252 rna_def_property_get_func(f, srna, prop, dp, (const char *)pprop->get));
2253 pprop->set = reinterpret_cast<PropPointerSetFunc>(
2254 rna_def_property_set_func(f, srna, prop, dp, (const char *)pprop->set));
2255 if (!pprop->type) {
2256 CLOG_ERROR(
2257 &LOG, "%s.%s, pointer must have a struct type.", srna->identifier, prop->identifier);
2258 DefRNA.error = true;
2259 }
2260 break;
2261 }
2262 case PROP_COLLECTION: {
2264 const char *nextfunc = (const char *)cprop->next;
2265 const char *item_type = (const char *)cprop->item_type;
2266
2267 if (cprop->length) {
2268 /* always generate if we have a manual implementation */
2269 cprop->length = reinterpret_cast<PropCollectionLengthFunc>(
2270 rna_def_property_length_func(f, srna, prop, dp, (const char *)cprop->length));
2271 }
2272 else if (dp->dnatype && STREQ(dp->dnatype, "ListBase")) {
2273 /* pass */
2274 }
2275 else if (dp->dnalengthname || dp->dnalengthfixed) {
2276 cprop->length = reinterpret_cast<PropCollectionLengthFunc>(
2277 rna_def_property_length_func(f, srna, prop, dp, (const char *)cprop->length));
2278 }
2279
2280 /* test if we can allow raw array access, if it is using our standard
2281 * array get/next function, we can be sure it is an actual array */
2282 if (cprop->next && cprop->get) {
2283 if (STREQ((const char *)cprop->next, "rna_iterator_array_next") &&
2284 STREQ((const char *)cprop->get, "rna_iterator_array_get"))
2285 {
2287 }
2288 }
2289
2290 cprop->get = reinterpret_cast<PropCollectionGetFunc>(
2291 rna_def_property_get_func(f, srna, prop, dp, (const char *)cprop->get));
2292 cprop->begin = reinterpret_cast<PropCollectionBeginFunc>(
2293 rna_def_property_begin_func(f, srna, prop, dp, (const char *)cprop->begin));
2294 cprop->next = reinterpret_cast<PropCollectionNextFunc>(
2295 rna_def_property_next_func(f, srna, prop, dp, (const char *)cprop->next));
2296 cprop->end = reinterpret_cast<PropCollectionEndFunc>(
2297 rna_def_property_end_func(f, srna, prop, dp, (const char *)cprop->end));
2298 cprop->lookupint = reinterpret_cast<PropCollectionLookupIntFunc>(
2300 f, srna, prop, dp, (const char *)cprop->lookupint, nextfunc));
2301 cprop->lookupstring = reinterpret_cast<PropCollectionLookupStringFunc>(
2303 f, srna, prop, dp, (const char *)cprop->lookupstring, item_type));
2304
2305 if (!(prop->flag & PROP_IDPROPERTY)) {
2306 if (!cprop->begin) {
2307 CLOG_ERROR(&LOG,
2308 "%s.%s, collection must have a begin function.",
2309 srna->identifier,
2310 prop->identifier);
2311 DefRNA.error = true;
2312 }
2313 if (!cprop->next) {
2314 CLOG_ERROR(&LOG,
2315 "%s.%s, collection must have a next function.",
2316 srna->identifier,
2317 prop->identifier);
2318 DefRNA.error = true;
2319 }
2320 if (!cprop->get) {
2321 CLOG_ERROR(&LOG,
2322 "%s.%s, collection must have a get function.",
2323 srna->identifier,
2324 prop->identifier);
2325 DefRNA.error = true;
2326 }
2327 }
2328 if (!cprop->item_type) {
2329 CLOG_ERROR(&LOG,
2330 "%s.%s, collection must have a struct type.",
2331 srna->identifier,
2332 prop->identifier);
2333 DefRNA.error = true;
2334 }
2335 break;
2336 }
2337 }
2338}
2339
2341{
2342 PropertyRNA *prop;
2343 const char *func;
2344
2345 prop = dp->prop;
2346
2347 if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
2348 return;
2349 }
2350
2351 func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
2352
2353 switch (prop->type) {
2354 case PROP_BOOLEAN: {
2355 if (!prop->arraydimension) {
2356 fprintf(f, "bool %sget(PointerRNA *ptr);\n", func);
2357 fprintf(f, "void %sset(PointerRNA *ptr, bool value);\n", func);
2358 }
2359 else if ((prop->flag & PROP_DYNAMIC) == 0 && prop->arraydimension && prop->totarraylength) {
2360 fprintf(f, "void %sget(PointerRNA *ptr, bool values[%u]);\n", func, prop->totarraylength);
2361 fprintf(f,
2362 "void %sset(PointerRNA *ptr, const bool values[%u]);\n",
2363 func,
2364 prop->totarraylength);
2365 }
2366 else {
2367 fprintf(f, "void %sget(PointerRNA *ptr, bool values[]);\n", func);
2368 fprintf(f, "void %sset(PointerRNA *ptr, const bool values[]);\n", func);
2369 }
2370 break;
2371 }
2372 case PROP_INT: {
2373 if (!prop->arraydimension) {
2374 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
2375 fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
2376 }
2377 else if ((prop->flag & PROP_DYNAMIC) == 0 && prop->arraydimension && prop->totarraylength) {
2378 fprintf(f, "void %sget(PointerRNA *ptr, int values[%u]);\n", func, prop->totarraylength);
2379 fprintf(
2380 f, "void %sset(PointerRNA *ptr, const int values[%u]);\n", func, prop->totarraylength);
2381 }
2382 else {
2383 fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func);
2384 fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func);
2385 }
2386 break;
2387 }
2388 case PROP_FLOAT: {
2389 if (!prop->arraydimension) {
2390 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
2391 fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
2392 }
2393 else if ((prop->flag & PROP_DYNAMIC) == 0 && prop->arraydimension && prop->totarraylength) {
2394 fprintf(f, "void %sget(PointerRNA *ptr, float values[%u]);\n", func, prop->totarraylength);
2395 fprintf(f,
2396 "void %sset(PointerRNA *ptr, const float values[%u]);\n",
2397 func,
2398 prop->totarraylength);
2399 }
2400 else {
2401 fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func);
2402 fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);", func);
2403 }
2404 break;
2405 }
2406 case PROP_ENUM: {
2407 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2408 int i;
2409
2410 if (eprop->item && eprop->totitem) {
2411 fprintf(f, "enum {\n");
2412
2413 for (i = 0; i < eprop->totitem; i++) {
2414 if (eprop->item[i].identifier[0]) {
2415 fprintf(f,
2416 "\t%s_%s_%s = %d,\n",
2417 srna->identifier,
2418 prop->identifier,
2419 eprop->item[i].identifier,
2420 eprop->item[i].value);
2421 }
2422 }
2423
2424 fprintf(f, "};\n\n");
2425 }
2426
2427 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
2428 fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
2429
2430 break;
2431 }
2432 case PROP_STRING: {
2433 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
2434
2435 if (sprop->maxlength) {
2436 fprintf(
2437 f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
2438 }
2439
2440 fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
2441 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
2442 fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
2443
2444 break;
2445 }
2446 case PROP_POINTER: {
2447 fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
2448 // fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func);
2449 break;
2450 }
2451 case PROP_COLLECTION: {
2453 fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
2454 fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
2455 fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
2456 if (cprop->length) {
2457 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
2458 }
2459 if (cprop->lookupint) {
2460 fprintf(f, "bool %slookup_int(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n", func);
2461 }
2462 if (cprop->lookupstring) {
2463 fprintf(f,
2464 "bool %slookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n",
2465 func);
2466 }
2467 break;
2468 }
2469 }
2470
2471 if (prop->getlength) {
2472 char funcname[2048];
2474 funcname, sizeof(funcname), srna->identifier, prop->identifier, "get_length");
2475 fprintf(f, "int %s(PointerRNA *ptr, int *arraylen);\n", funcname);
2476 }
2477
2478 fprintf(f, "\n");
2479}
2480
2481static void rna_def_function_funcs_header(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
2482{
2483 FunctionRNA *func = dfunc->func;
2484 char funcname[2048];
2485
2487 funcname, sizeof(funcname), srna->identifier, func->identifier, "func");
2488 rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 1);
2489}
2490
2492{
2493 PropertyRNA *prop;
2494
2495 prop = dp->prop;
2496
2497 if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
2498 return;
2499 }
2500
2501/* Disabled for now to avoid MSVC compiler error due to large file size. */
2502#if 0
2503 if (prop->name && prop->description && prop->description[0] != '\0') {
2504 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
2505 }
2506 else if (prop->name) {
2507 fprintf(f, "\t/* %s */\n", prop->name);
2508 }
2509 else {
2510 fprintf(f, "\t/* */\n");
2511 }
2512#endif
2513
2514 switch (prop->type) {
2515 case PROP_BOOLEAN: {
2516 if (!prop->arraydimension) {
2517 fprintf(f, "\tinline bool %s(void);\n", rna_safe_id(prop->identifier));
2518 fprintf(f, "\tinline void %s(bool value);", rna_safe_id(prop->identifier));
2519 }
2520 else if (prop->totarraylength) {
2521 fprintf(f,
2522 "\tinline Array<bool, %u> %s(void);\n",
2523 prop->totarraylength,
2524 rna_safe_id(prop->identifier));
2525 fprintf(f,
2526 "\tinline void %s(bool values[%u]);",
2527 rna_safe_id(prop->identifier),
2528 prop->totarraylength);
2529 }
2530 else if (prop->getlength) {
2531 fprintf(f, "\tinline DynamicArray<bool> %s(void);\n", rna_safe_id(prop->identifier));
2532 fprintf(f, "\tinline void %s(bool values[]);", rna_safe_id(prop->identifier));
2533 }
2534 break;
2535 }
2536 case PROP_INT: {
2537 if (!prop->arraydimension) {
2538 fprintf(f, "\tinline int %s(void);\n", rna_safe_id(prop->identifier));
2539 fprintf(f, "\tinline void %s(int value);", rna_safe_id(prop->identifier));
2540 }
2541 else if (prop->totarraylength) {
2542 fprintf(f,
2543 "\tinline Array<int, %u> %s(void);\n",
2544 prop->totarraylength,
2545 rna_safe_id(prop->identifier));
2546 fprintf(f,
2547 "\tinline void %s(int values[%u]);",
2548 rna_safe_id(prop->identifier),
2549 prop->totarraylength);
2550 }
2551 else if (prop->getlength) {
2552 fprintf(f, "\tinline DynamicArray<int> %s(void);\n", rna_safe_id(prop->identifier));
2553 fprintf(f, "\tinline void %s(int values[]);", rna_safe_id(prop->identifier));
2554 }
2555 break;
2556 }
2557 case PROP_FLOAT: {
2558 if (!prop->arraydimension) {
2559 fprintf(f, "\tinline float %s(void);\n", rna_safe_id(prop->identifier));
2560 fprintf(f, "\tinline void %s(float value);", rna_safe_id(prop->identifier));
2561 }
2562 else if (prop->totarraylength) {
2563 fprintf(f,
2564 "\tinline Array<float, %u> %s(void);\n",
2565 prop->totarraylength,
2566 rna_safe_id(prop->identifier));
2567 fprintf(f,
2568 "\tinline void %s(float values[%u]);",
2569 rna_safe_id(prop->identifier),
2570 prop->totarraylength);
2571 }
2572 else if (prop->getlength) {
2573 fprintf(f, "\tinline DynamicArray<float> %s(void);\n", rna_safe_id(prop->identifier));
2574 fprintf(f, "\tinline void %s(float values[]);", rna_safe_id(prop->identifier));
2575 }
2576 break;
2577 }
2578 case PROP_ENUM: {
2579 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
2580 int i;
2581
2582 if (eprop->item) {
2583 fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier));
2584
2585 for (i = 0; i < eprop->totitem; i++) {
2586 if (eprop->item[i].identifier[0]) {
2587 fprintf(f,
2588 "\t\t%s_%s = %d,\n",
2589 rna_safe_id(prop->identifier),
2590 eprop->item[i].identifier,
2591 eprop->item[i].value);
2592 }
2593 }
2594
2595 fprintf(f, "\t};\n");
2596 }
2597
2598 fprintf(f,
2599 "\tinline %s_enum %s(void);\n",
2600 rna_safe_id(prop->identifier),
2601 rna_safe_id(prop->identifier));
2602 fprintf(f,
2603 "\tinline void %s(%s_enum value);",
2604 rna_safe_id(prop->identifier),
2605 rna_safe_id(prop->identifier));
2606 break;
2607 }
2608 case PROP_STRING: {
2609 fprintf(f, "\tinline std::string %s(void);\n", rna_safe_id(prop->identifier));
2610 fprintf(f, "\tinline void %s(const std::string& value);", rna_safe_id(prop->identifier));
2611 break;
2612 }
2613 case PROP_POINTER: {
2615
2616 if (pprop->type) {
2617 fprintf(
2618 f, "\tinline %s %s(void);", (const char *)pprop->type, rna_safe_id(prop->identifier));
2619 }
2620 else {
2621 fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier));
2622 }
2623 break;
2624 }
2625 case PROP_COLLECTION: {
2627 const char *collection_funcs = "DefaultCollectionFunctions";
2628
2630 cprop->property.srna)
2631 {
2632 collection_funcs = (char *)cprop->property.srna;
2633 }
2634
2635 if (cprop->item_type) {
2636 fprintf(f,
2637 "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)",
2638 collection_funcs,
2639 (const char *)cprop->item_type,
2640 srna->identifier,
2641 rna_safe_id(prop->identifier),
2642 (cprop->length ? "true" : "false"),
2643 (cprop->lookupint ? "true" : "false"),
2644 (cprop->lookupstring ? "true" : "false"));
2645 }
2646 else {
2647 fprintf(f,
2648 "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)",
2649 collection_funcs,
2650 "UnknownType",
2651 srna->identifier,
2652 rna_safe_id(prop->identifier),
2653 (cprop->length ? "true" : "false"),
2654 (cprop->lookupint ? "true" : "false"),
2655 (cprop->lookupstring ? "true" : "false"));
2656 }
2657 break;
2658 }
2659 }
2660
2661 fprintf(f, "\n");
2662}
2663
2665{
2666 if (prop->type == PROP_POINTER) {
2667 /* For the C++ API we need to use RNA structures names for pointers. */
2668 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
2669
2670 return (const char *)pprop->type;
2671 }
2672 return rna_parameter_type_name(prop);
2673}
2674
2676 StructRNA * /*srna*/,
2677 FunctionDefRNA *dfunc,
2678 const char *cpp_namespace,
2679 int close_prototype)
2680{
2681 FunctionRNA *func = dfunc->func;
2682
2683 int first = 1;
2684 const char *retval_type = "void";
2685
2686 if (func->c_ret) {
2688 retval_type = rna_parameter_type_cpp_name(dp->prop);
2689 }
2690
2691 if (cpp_namespace && cpp_namespace[0]) {
2692 fprintf(f, "\tinline %s %s::%s(", retval_type, cpp_namespace, rna_safe_id(func->identifier));
2693 }
2694 else {
2695 fprintf(f, "\tinline %s %s(", retval_type, rna_safe_id(func->identifier));
2696 }
2697
2698 if (func->flag & FUNC_USE_MAIN) {
2699 WRITE_PARAM("void *main");
2700 }
2701
2702 if (func->flag & FUNC_USE_CONTEXT) {
2703 WRITE_PARAM("Context C");
2704 }
2705
2707 int type, flag, flag_parameter, pout;
2708 const char *ptrstr;
2709
2710 if (dp->prop == func->c_ret) {
2711 continue;
2712 }
2713
2714 type = dp->prop->type;
2715 flag = dp->prop->flag;
2716 flag_parameter = dp->prop->flag_parameter;
2717 pout = (flag_parameter & PARM_OUTPUT);
2718
2719 if (flag & PROP_DYNAMIC) {
2720 if (type == PROP_STRING) {
2721 ptrstr = pout ? "*" : "";
2722 }
2723 else {
2724 ptrstr = pout ? "**" : "*";
2725 }
2726 }
2727 else if (type == PROP_POINTER) {
2728 ptrstr = pout ? "*" : "";
2729 }
2730 else if (dp->prop->arraydimension) {
2731 ptrstr = "*";
2732 }
2733 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
2734 ptrstr = "";
2735 }
2736 else {
2737 ptrstr = pout ? "*" : "";
2738 }
2739
2741
2742 if (flag & PROP_DYNAMIC) {
2743 fprintf(
2744 f, "int %s%s_len, ", (flag_parameter & PARM_OUTPUT) ? "*" : "", dp->prop->identifier);
2745 }
2746
2747 if (!(flag & PROP_DYNAMIC) && dp->prop->arraydimension) {
2748 fprintf(f,
2749 "%s %s[%u]",
2751 rna_safe_id(dp->prop->identifier),
2752 dp->prop->totarraylength);
2753 }
2754 else {
2755 fprintf(f,
2756 "%s%s%s%s",
2758 (dp->prop->type == PROP_POINTER && ptrstr[0] == '\0') ? "& " : " ",
2759 ptrstr,
2760 rna_safe_id(dp->prop->identifier));
2761 }
2762 }
2763
2764 fprintf(f, ")");
2765 if (close_prototype) {
2766 fprintf(f, ";\n");
2767 }
2768}
2769
2771{
2772 if (dfunc->call) {
2773/* Disabled for now to avoid MSVC compiler error due to large file size. */
2774#if 0
2775 FunctionRNA *func = dfunc->func;
2776 fprintf(f, "\n\t/* %s */\n", func->description);
2777#endif
2778
2779 rna_def_struct_function_prototype_cpp(f, srna, dfunc, nullptr, 1);
2780 }
2781}
2782
2784{
2785 PropertyRNA *prop;
2786
2787 prop = dp->prop;
2788
2789 if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
2790 return;
2791 }
2792
2793 switch (prop->type) {
2794 case PROP_BOOLEAN: {
2795 if (!prop->arraydimension) {
2796 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
2797 }
2798 else if (prop->totarraylength) {
2799 fprintf(f,
2800 "\tBOOLEAN_ARRAY_PROPERTY(%s, %u, %s)",
2801 srna->identifier,
2802 prop->totarraylength,
2803 rna_safe_id(prop->identifier));
2804 }
2805 else if (prop->getlength) {
2806 fprintf(f,
2807 "\tBOOLEAN_DYNAMIC_ARRAY_PROPERTY(%s, %s)",
2808 srna->identifier,
2809 rna_safe_id(prop->identifier));
2810 }
2811 break;
2812 }
2813 case PROP_INT: {
2814 if (!prop->arraydimension) {
2815 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
2816 }
2817 else if (prop->totarraylength) {
2818 fprintf(f,
2819 "\tINT_ARRAY_PROPERTY(%s, %u, %s)",
2820 srna->identifier,
2821 prop->totarraylength,
2822 rna_safe_id(prop->identifier));
2823 }
2824 else if (prop->getlength) {
2825 fprintf(f,
2826 "\tINT_DYNAMIC_ARRAY_PROPERTY(%s, %s)",
2827 srna->identifier,
2828 rna_safe_id(prop->identifier));
2829 }
2830 break;
2831 }
2832 case PROP_FLOAT: {
2833 if (!prop->arraydimension) {
2834 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
2835 }
2836 else if (prop->totarraylength) {
2837 fprintf(f,
2838 "\tFLOAT_ARRAY_PROPERTY(%s, %u, %s)",
2839 srna->identifier,
2840 prop->totarraylength,
2841 rna_safe_id(prop->identifier));
2842 }
2843 else if (prop->getlength) {
2844 fprintf(f,
2845 "\tFLOAT_DYNAMIC_ARRAY_PROPERTY(%s, %s)",
2846 srna->identifier,
2847 rna_safe_id(prop->identifier));
2848 }
2849 break;
2850 }
2851 case PROP_ENUM: {
2852 fprintf(f,
2853 "\tENUM_PROPERTY(%s_enum, %s, %s)",
2854 rna_safe_id(prop->identifier),
2855 srna->identifier,
2856 rna_safe_id(prop->identifier));
2857
2858 break;
2859 }
2860 case PROP_STRING: {
2861 fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, rna_safe_id(prop->identifier));
2862 break;
2863 }
2864 case PROP_POINTER: {
2866
2867 if (pprop->type) {
2868 fprintf(f,
2869 "\tPOINTER_PROPERTY(%s, %s, %s)",
2870 (const char *)pprop->type,
2871 srna->identifier,
2872 rna_safe_id(prop->identifier));
2873 }
2874 else {
2875 fprintf(f,
2876 "\tPOINTER_PROPERTY(%s, %s, %s)",
2877 "UnknownType",
2878 srna->identifier,
2879 rna_safe_id(prop->identifier));
2880 }
2881 break;
2882 }
2883 case PROP_COLLECTION: {
2884#if 0
2886
2887 if (cprop->type) {
2888 fprintf(f,
2889 "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)",
2890 (const char *)cprop->type,
2891 srna->identifier,
2892 prop->identifier,
2893 (cprop->length ? "true" : "false"),
2894 (cprop->lookupint ? "true" : "false"),
2895 (cprop->lookupstring ? "true" : "false"));
2896 }
2897 else {
2898 fprintf(f,
2899 "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s)",
2900 "UnknownType",
2901 srna->identifier,
2902 prop->identifier,
2903 (cprop->length ? "true" : "false"),
2904 (cprop->lookupint ? "true" : "false"),
2905 (cprop->lookupstring ? "true" : "false"));
2906 }
2907#endif
2908 break;
2909 }
2910 }
2911
2912 fprintf(f, "\n");
2913}
2914
2916{
2917 PropertyDefRNA *dp;
2918 StructDefRNA *dsrna;
2919 FunctionRNA *func = dfunc->func;
2920 char funcname[2048];
2921
2922 int first = 1;
2923
2925 funcname, sizeof(funcname), srna->identifier, func->identifier, "func");
2926
2927 fprintf(f, "%s(", funcname);
2928
2929 dsrna = rna_find_struct_def(srna);
2930
2931 if (func->flag & FUNC_USE_SELF_ID) {
2932 WRITE_PARAM("(::ID *) ptr.owner_id");
2933 }
2934
2935 if ((func->flag & FUNC_NO_SELF) == 0) {
2937 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
2938 fprintf(f, "this->ptr");
2939 }
2940 else if (dsrna->dnafromprop) {
2941 fprintf(f, "(::%s *) this->ptr.data", dsrna->dnafromname);
2942 }
2943 else if (dsrna->dnaname) {
2944 fprintf(f, "(::%s *) this->ptr.data", dsrna->dnaname);
2945 }
2946 else {
2947 fprintf(f, "(::%s *) this->ptr.data", srna->identifier);
2948 }
2949 }
2950 else if (func->flag & FUNC_USE_SELF_TYPE) {
2952 fprintf(f, "this->ptr.type");
2953 }
2954
2955 if (func->flag & FUNC_USE_MAIN) {
2956 WRITE_PARAM("(::Main *) main");
2957 }
2958
2959 if (func->flag & FUNC_USE_CONTEXT) {
2960 WRITE_PARAM("(::bContext *) C.ptr.data");
2961 }
2962
2963 if (func->flag & FUNC_USE_REPORTS) {
2964 WRITE_PARAM("nullptr");
2965 }
2966
2967 dp = static_cast<PropertyDefRNA *>(dfunc->cont.properties.first);
2968 for (; dp; dp = dp->next) {
2969 if (dp->prop == func->c_ret) {
2970 continue;
2971 }
2972
2974
2975 if (dp->prop->flag & PROP_DYNAMIC) {
2976 fprintf(f, "%s_len, ", dp->prop->identifier);
2977 }
2978
2979 if (dp->prop->type == PROP_POINTER) {
2980 if ((dp->prop->flag_parameter & PARM_RNAPTR) && !(dp->prop->flag & PROP_THICK_WRAP)) {
2981 fprintf(f,
2982 "(::%s *) &%s.ptr",
2985 }
2986 else if (dp->prop->flag_parameter & PARM_OUTPUT) {
2987 if (dp->prop->flag_parameter & PARM_RNAPTR) {
2988 fprintf(f, "&%s->ptr", rna_safe_id(dp->prop->identifier));
2989 }
2990 else {
2991 fprintf(f,
2992 "(::%s **) &%s->ptr.data",
2995 }
2996 }
2997 else if (dp->prop->flag_parameter & PARM_RNAPTR) {
2998 fprintf(f,
2999 "(::%s *) &%s",
3002 }
3003 else {
3004 fprintf(f,
3005 "(::%s *) %s.ptr.data",
3008 }
3009 }
3010 else {
3011 fprintf(f, "%s", rna_safe_id(dp->prop->identifier));
3012 }
3013 }
3014
3015 fprintf(f, ");\n");
3016}
3017
3019{
3020 PropertyDefRNA *dp;
3021 PointerPropertyRNA *pprop;
3022
3023 FunctionRNA *func = dfunc->func;
3024
3025 if (!dfunc->call) {
3026 return;
3027 }
3028
3029 rna_def_struct_function_prototype_cpp(f, srna, dfunc, srna->identifier, 0);
3030
3031 fprintf(f, " {\n");
3032
3033 if (func->c_ret) {
3034 dp = rna_find_parameter_def(func->c_ret);
3035
3036 if (dp->prop->type == PROP_POINTER) {
3037 pprop = (PointerPropertyRNA *)dp->prop;
3038
3039 fprintf(f, "\t\tPointerRNA result;\n");
3040
3041 if ((dp->prop->flag_parameter & PARM_RNAPTR) == 0) {
3042 StructRNA *ret_srna = rna_find_struct((const char *)pprop->type);
3043 fprintf(f, "\t\t::%s *retdata = ", rna_parameter_type_name(dp->prop));
3045 if (ret_srna->flag & STRUCT_ID) {
3046 fprintf(f, "\t\tresult = RNA_id_pointer_create((::ID *) retdata);\n");
3047 }
3048 else {
3049 fprintf(f,
3050 "\t\tresult = RNA_pointer_create_with_parent(ptr, &RNA_%s, retdata);\n",
3051 (const char *)pprop->type);
3052 }
3053 }
3054 else {
3055 fprintf(f, "\t\tresult = ");
3057 }
3058
3059 fprintf(f, "\t\treturn %s(result);\n", (const char *)pprop->type);
3060 }
3061 else {
3062 fprintf(f, "\t\treturn ");
3064 }
3065 }
3066 else {
3067 fprintf(f, "\t\t");
3069 }
3070
3071 fprintf(f, "\t}\n\n");
3072}
3073
3075{
3076 if (dp->prop->getlength) {
3077 char funcname[2048];
3079 funcname, sizeof(funcname), dsrna->srna->identifier, dp->prop->identifier, "get_length");
3080 fprintf(f, "extern int %s(PointerRNA *ptr, int *arraylen)\n", funcname);
3081 fprintf(f, "{\n");
3082 fprintf(f, "\treturn %s(ptr, arraylen);\n", rna_function_string(dp->prop->getlength));
3083 fprintf(f, "}\n\n");
3084 }
3085}
3086
3088{
3089 StructRNA *srna = dsrna->srna;
3090 FunctionRNA *func = dfunc->func;
3091 PropertyDefRNA *dparm;
3092
3093 int first;
3094 char funcname[2048];
3095
3096 if (!dfunc->call) {
3097 return;
3098 }
3099
3101 funcname, sizeof(funcname), srna->identifier, func->identifier, "func");
3102
3103 fprintf(f, "extern ");
3104 rna_generate_static_parameter_prototypes(f, srna, dfunc, funcname, 0);
3105
3106 fprintf(f, "\n{\n");
3107
3108 if (func->c_ret) {
3109 fprintf(f, "\treturn %s(", dfunc->call);
3110 }
3111 else {
3112 fprintf(f, "\t%s(", dfunc->call);
3113 }
3114
3115 first = 1;
3116
3117 if (func->flag & FUNC_USE_SELF_ID) {
3118 WRITE_PARAM("_selfid");
3119 }
3120
3121 if ((func->flag & FUNC_NO_SELF) == 0) {
3122 WRITE_PARAM("_self");
3123 }
3124 else if (func->flag & FUNC_USE_SELF_TYPE) {
3125 WRITE_PARAM("_type");
3126 }
3127
3128 if (func->flag & FUNC_USE_MAIN) {
3129 WRITE_PARAM("bmain");
3130 }
3131
3132 if (func->flag & FUNC_USE_CONTEXT) {
3133 WRITE_PARAM("C");
3134 }
3135
3136 if (func->flag & FUNC_USE_REPORTS) {
3137 WRITE_PARAM("reports");
3138 }
3139
3140 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.first);
3141 for (; dparm; dparm = dparm->next) {
3142 if (dparm->prop == func->c_ret) {
3143 continue;
3144 }
3145
3147
3148 if (dparm->prop->flag & PROP_DYNAMIC) {
3149 fprintf(f, "%s, %s_num", dparm->prop->identifier, dparm->prop->identifier);
3150 }
3151 else {
3152 fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
3153 }
3154 }
3155
3156 fprintf(f, ");\n");
3157 fprintf(f, "}\n\n");
3158}
3159
3160static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
3161{
3162 StructRNA *srna;
3163 FunctionRNA *func;
3164 PropertyDefRNA *dparm;
3165 PropertyType type;
3166 const char *funcname, *valstr;
3167 const char *ptrstr;
3168 const bool has_data = (dfunc->cont.properties.first != nullptr);
3169 int flag, flag_parameter, pout, cptr, first;
3170
3171 srna = dsrna->srna;
3172 func = dfunc->func;
3173
3174 if (!dfunc->call) {
3175 return;
3176 }
3177
3178 funcname = rna_alloc_function_name(srna->identifier, func->identifier, "call");
3179
3180 /* function definition */
3181 fprintf(
3182 f,
3183 "static void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)",
3184 funcname);
3185 fprintf(f, "\n{\n");
3186
3187 /* variable definitions */
3188
3189 if (func->flag & FUNC_USE_SELF_ID) {
3190 fprintf(f, "\tstruct ID *_selfid;\n");
3191 }
3192
3193 if ((func->flag & FUNC_NO_SELF) == 0) {
3194 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
3195 fprintf(f, "\tstruct PointerRNA _self;\n");
3196 }
3197 else if (dsrna->dnafromprop) {
3198 fprintf(f, "\tstruct %s *_self;\n", dsrna->dnafromname);
3199 }
3200 else if (dsrna->dnaname) {
3201 fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
3202 }
3203 else {
3204 fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
3205 }
3206 }
3207 else if (func->flag & FUNC_USE_SELF_TYPE) {
3208 fprintf(f, "\tstruct StructRNA *_type;\n");
3209 }
3210
3211 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.first);
3212 for (; dparm; dparm = dparm->next) {
3213 type = dparm->prop->type;
3214 flag = dparm->prop->flag;
3215 flag_parameter = dparm->prop->flag_parameter;
3216 pout = (flag_parameter & PARM_OUTPUT);
3217 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
3218
3219 if (dparm->prop == func->c_ret) {
3220 ptrstr = cptr || dparm->prop->arraydimension ? "*" : "";
3221 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
3222 }
3223 else if (cptr || (flag & PROP_DYNAMIC)) {
3224 if (type == PROP_STRING) {
3225 ptrstr = pout ? "*" : "";
3226 }
3227 else {
3228 ptrstr = pout ? "**" : "*";
3229 }
3230 /* Fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack,
3231 * pass a pointer to it. */
3232 }
3233 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
3234 ptrstr = "*";
3235 }
3236 else if ((type == PROP_POINTER) && (flag_parameter & PARM_RNAPTR) && !(flag & PROP_THICK_WRAP))
3237 {
3238 ptrstr = "*";
3239 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack,
3240 * but type name for string props is already (char *), so leave empty */
3241 }
3242 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
3243 ptrstr = "";
3244 }
3245 else {
3246 ptrstr = pout ? "*" : "";
3247 }
3248
3249 /* for dynamic parameters we pass an additional int for the length of the parameter */
3250 if (flag & PROP_DYNAMIC) {
3251 fprintf(f, "\tint %s%s_num;\n", pout ? "*" : "", dparm->prop->identifier);
3252 }
3253
3254 fprintf(f,
3255 "\t%s%s%s %s%s;\n",
3256 rna_parameter_is_const(dparm) ? "const " : "",
3257 rna_type_struct(dparm->prop),
3259 ptrstr,
3260 rna_safe_id(dparm->prop->identifier));
3261 }
3262
3263 if (has_data) {
3264 fprintf(f, "\tchar *_data");
3265 if (func->c_ret) {
3266 fprintf(f, ", *_retdata");
3267 }
3268 fprintf(f, ";\n");
3269 fprintf(f, "\t\n");
3270 }
3271
3272 /* assign self */
3273 if (func->flag & FUNC_USE_SELF_ID) {
3274 fprintf(f, "\t_selfid = (struct ID *)_ptr->owner_id;\n");
3275 }
3276
3277 if ((func->flag & FUNC_NO_SELF) == 0) {
3278 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
3279 fprintf(f, "\t_self = *_ptr;\n");
3280 }
3281 else if (dsrna->dnafromprop) {
3282 fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", dsrna->dnafromname);
3283 }
3284 else if (dsrna->dnaname) {
3285 fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", dsrna->dnaname);
3286 }
3287 else {
3288 fprintf(f, "\t_self = (struct %s *)_ptr->data;\n", srna->identifier);
3289 }
3290 }
3291 else if (func->flag & FUNC_USE_SELF_TYPE) {
3292 fprintf(f, "\t_type = _ptr->type;\n");
3293 }
3294
3295 if (has_data) {
3296 fprintf(f, "\t_data = (char *)_parms->data;\n");
3297 }
3298
3299 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.first);
3300 for (; dparm; dparm = dparm->next) {
3301 type = dparm->prop->type;
3302 flag = dparm->prop->flag;
3303 flag_parameter = dparm->prop->flag_parameter;
3304 pout = (flag_parameter & PARM_OUTPUT);
3305 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
3306
3307 if (dparm->prop == func->c_ret) {
3308 fprintf(f, "\t_retdata = _data;\n");
3309 }
3310 else {
3311 const char *data_str;
3312 if (cptr || (flag & PROP_DYNAMIC)) {
3313 if (type == PROP_STRING) {
3314 ptrstr = "*";
3315 valstr = "";
3316 }
3317 else {
3318 ptrstr = "**";
3319 valstr = "*";
3320 }
3321 }
3322 else if ((type == PROP_POINTER) && !(flag & PROP_THICK_WRAP)) {
3323 ptrstr = "**";
3324 valstr = "*";
3325 }
3326 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
3327 ptrstr = "*";
3328 valstr = "";
3329 }
3330 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
3331 ptrstr = "";
3332 valstr = "";
3333 }
3334 else {
3335 ptrstr = "*";
3336 valstr = "*";
3337 }
3338
3339 /* This must be kept in sync with RNA_parameter_dynamic_length_get_data and
3340 * RNA_parameter_get, we could just call the function directly, but this is faster. */
3341 if (flag & PROP_DYNAMIC) {
3342 fprintf(f,
3343 "\t%s_num = %s((ParameterDynAlloc *)_data)->array_tot;\n",
3344 rna_safe_id(dparm->prop->identifier),
3345 pout ? "(int *)&" : "(int)");
3346 data_str = "(&(((ParameterDynAlloc *)_data)->array))";
3347 }
3348 else {
3349 data_str = "_data";
3350 }
3351 fprintf(f, "\t%s = ", rna_safe_id(dparm->prop->identifier));
3352
3353 if (!pout) {
3354 fprintf(f, "%s", valstr);
3355 }
3356
3357 fprintf(f,
3358 "((%s%s%s %s)%s);\n",
3359 rna_parameter_is_const(dparm) ? "const " : "",
3360 rna_type_struct(dparm->prop),
3362 ptrstr,
3363 data_str);
3364 }
3365
3366 if (dparm->next) {
3367 fprintf(f, "\t_data += %d;\n", rna_parameter_size_pad(rna_parameter_size(dparm->prop)));
3368 }
3369 }
3370
3371 if (dfunc->call) {
3372 fprintf(f, "\t\n");
3373 fprintf(f, "\t");
3374 if (func->c_ret) {
3375 fprintf(f, "%s = ", func->c_ret->identifier);
3376 }
3377 fprintf(f, "%s(", dfunc->call);
3378
3379 first = 1;
3380
3381 if (func->flag & FUNC_USE_SELF_ID) {
3382 fprintf(f, "_selfid");
3383 first = 0;
3384 }
3385
3386 if ((func->flag & FUNC_NO_SELF) == 0) {
3387 if (!first) {
3388 fprintf(f, ", ");
3389 }
3390 fprintf(f, "_self");
3391 first = 0;
3392 }
3393 else if (func->flag & FUNC_USE_SELF_TYPE) {
3394 if (!first) {
3395 fprintf(f, ", ");
3396 }
3397 fprintf(f, "_type");
3398 first = 0;
3399 }
3400
3401 if (func->flag & FUNC_USE_MAIN) {
3402 if (!first) {
3403 fprintf(f, ", ");
3404 }
3405 first = 0;
3406 fprintf(f, "CTX_data_main(C)"); /* may have direct access later */
3407 }
3408
3409 if (func->flag & FUNC_USE_CONTEXT) {
3410 if (!first) {
3411 fprintf(f, ", ");
3412 }
3413 first = 0;
3414 fprintf(f, "C");
3415 }
3416
3417 if (func->flag & FUNC_USE_REPORTS) {
3418 if (!first) {
3419 fprintf(f, ", ");
3420 }
3421 first = 0;
3422 fprintf(f, "reports");
3423 }
3424
3425 dparm = static_cast<PropertyDefRNA *>(dfunc->cont.properties.first);
3426 for (; dparm; dparm = dparm->next) {
3427 if (dparm->prop == func->c_ret) {
3428 continue;
3429 }
3430
3431 if (!first) {
3432 fprintf(f, ", ");
3433 }
3434 first = 0;
3435
3436 if (dparm->prop->flag & PROP_DYNAMIC) {
3437 fprintf(f,
3438 "%s, %s_num",
3439 rna_safe_id(dparm->prop->identifier),
3440 rna_safe_id(dparm->prop->identifier));
3441 }
3442 else {
3443 fprintf(f, "%s", rna_safe_id(dparm->prop->identifier));
3444 }
3445 }
3446
3447 fprintf(f, ");\n");
3448
3449 if (func->c_ret) {
3450 dparm = rna_find_parameter_def(func->c_ret);
3451 if ((dparm->prop->type == PROP_POINTER) && (dparm->prop->flag_parameter & PARM_RNAPTR) &&
3452 (dparm->prop->flag & PROP_THICK_WRAP))
3453 {
3454 const char *parameter_type_name = rna_parameter_type_name(dparm->prop);
3455 fprintf(f,
3456 "\t*reinterpret_cast<%s *>(_retdata) = %s;\n",
3457 parameter_type_name,
3458 func->c_ret->identifier);
3459 }
3460 else {
3461 ptrstr = (((dparm->prop->type == PROP_POINTER) &&
3462 !(dparm->prop->flag_parameter & PARM_RNAPTR)) ||
3463 (dparm->prop->arraydimension)) ?
3464 "*" :
3465 "";
3466 if (dparm->prop->type == PROP_COLLECTION) {
3467 /* Placement new is necessary because #ParameterList::data is not initialized. */
3468 fprintf(f,
3469 "\tnew ((CollectionVector *)_retdata) CollectionVector(std::move(%s));\n",
3470 func->c_ret->identifier);
3471 }
3472 else {
3473 fprintf(f,
3474 "\t*((%s%s %s*)_retdata) = %s;\n",
3475 rna_type_struct(dparm->prop),
3477 ptrstr,
3478 func->c_ret->identifier);
3479 }
3480 }
3481 }
3482 }
3483
3484 fprintf(f, "}\n\n");
3485
3486 dfunc->gencall = funcname;
3487}
3488
3489static void rna_sanity_checks()
3490{
3491 /* Ensure RNA enum definitions follow naming convention. */
3492 {
3493#define DEF_ENUM(id) #id,
3494 const char *rna_enum_id_array[] = {
3495#include "RNA_enum_items.hh"
3496 };
3497 for (int i = 0; i < ARRAY_SIZE(rna_enum_id_array); i++) {
3498 if (!(BLI_str_startswith(rna_enum_id_array[i], "rna_enum_") &&
3499 BLI_str_endswith(rna_enum_id_array[i], "_items")))
3500 {
3501 fprintf(stderr,
3502 "Error: enum defined in \"RNA_enum_items.hh\" "
3503 "doesn't confirm to \"rna_enum_*_items\" convention!\n");
3504 DefRNA.error = true;
3505 }
3506 }
3507 }
3508}
3509
3510static void rna_auto_types()
3511{
3512 StructDefRNA *ds;
3513
3514 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
3515 ds = static_cast<StructDefRNA *>(ds->cont.next))
3516 {
3517 /* DNA name for Screen is patched in 2.5, we do the reverse here. */
3518 if (ds->dnaname) {
3519 if (STREQ(ds->dnaname, "Screen")) {
3520 ds->dnaname = "bScreen";
3521 }
3522 if (STREQ(ds->dnaname, "Group")) {
3523 ds->dnaname = "Collection";
3524 }
3525 if (STREQ(ds->dnaname, "GroupObject")) {
3526 ds->dnaname = "CollectionObject";
3527 }
3528 }
3529
3531 if (dp->dnastructname) {
3532 if (STREQ(dp->dnastructname, "Screen")) {
3533 dp->dnastructname = "bScreen";
3534 }
3535 if (STREQ(dp->dnastructname, "Group")) {
3536 dp->dnastructname = "Collection";
3537 }
3538 if (STREQ(dp->dnastructname, "GroupObject")) {
3539 dp->dnastructname = "CollectionObject";
3540 }
3541 }
3542
3543 if (dp->dnatype) {
3544 if (dp->prop->type == PROP_POINTER) {
3545 PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
3546 StructRNA *type;
3547
3548 if (!pprop->type && !pprop->get) {
3549 pprop->type = (StructRNA *)rna_find_type(dp->dnatype);
3550 }
3551
3552 /* Only automatically define `PROP_ID_REFCOUNT` if it was not already explicitly set or
3553 * cleared by calls to `RNA_def_property_flag` or `RNA_def_property_clear_flag`. */
3555 pprop->type)
3556 {
3557 type = rna_find_struct((const char *)pprop->type);
3558 if (type && (type->flag & STRUCT_ID_REFCOUNT)) {
3559 pprop->property.flag |= PROP_ID_REFCOUNT;
3560 }
3561 }
3562 }
3563 else if (dp->prop->type == PROP_COLLECTION) {
3564 CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
3565
3566 if (!cprop->item_type && !cprop->get && STREQ(dp->dnatype, "ListBase")) {
3567 cprop->item_type = (StructRNA *)rna_find_type(dp->dnatype);
3568 }
3569 }
3570 }
3571 }
3572 }
3573}
3574
3575static void rna_sort(BlenderRNA *brna)
3576{
3577 StructDefRNA *ds;
3578 StructRNA *srna;
3579
3582
3583 for (srna = static_cast<StructRNA *>(brna->structs.first); srna;
3584 srna = static_cast<StructRNA *>(srna->cont.next))
3585 {
3587 }
3588
3589 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
3590 ds = static_cast<StructDefRNA *>(ds->cont.next))
3591 {
3593 }
3594}
3595
3597{
3598 switch (type) {
3599 case PROP_BOOLEAN:
3600 return "BoolPropertyRNA";
3601 case PROP_INT:
3602 return "IntPropertyRNA";
3603 case PROP_FLOAT:
3604 return "FloatPropertyRNA";
3605 case PROP_STRING:
3606 return "StringPropertyRNA";
3607 case PROP_ENUM:
3608 return "EnumPropertyRNA";
3609 case PROP_POINTER:
3610 return "PointerPropertyRNA";
3611 case PROP_COLLECTION:
3612 return "CollectionPropertyRNA";
3613 default:
3614 return "UnknownPropertyRNA";
3615 }
3616}
3617
3619{
3620 switch (type) {
3621 case PROP_NONE:
3622 return "PROP_NONE";
3623 case PROP_FILEPATH:
3624 return "PROP_FILEPATH";
3625 case PROP_FILENAME:
3626 return "PROP_FILENAME";
3627 case PROP_DIRPATH:
3628 return "PROP_DIRPATH";
3629 case PROP_PIXEL:
3630 return "PROP_PIXEL";
3632 return "PROP_PIXEL_DIAMETER";
3633 case PROP_BYTESTRING:
3634 return "PROP_BYTESTRING";
3635 case PROP_UNSIGNED:
3636 return "PROP_UNSIGNED";
3637 case PROP_PERCENTAGE:
3638 return "PROP_PERCENTAGE";
3639 case PROP_FACTOR:
3640 return "PROP_FACTOR";
3641 case PROP_ANGLE:
3642 return "PROP_ANGLE";
3643 case PROP_TIME:
3644 return "PROP_TIME";
3645 case PROP_TIME_ABSOLUTE:
3646 return "PROP_TIME_ABSOLUTE";
3647 case PROP_DISTANCE:
3648 return "PROP_DISTANCE";
3650 return "PROP_DISTANCE_DIAMETER";
3652 return "PROP_DISTANCE_CAMERA";
3653 case PROP_COLOR:
3654 return "PROP_COLOR";
3655 case PROP_TRANSLATION:
3656 return "PROP_TRANSLATION";
3657 case PROP_DIRECTION:
3658 return "PROP_DIRECTION";
3659 case PROP_MATRIX:
3660 return "PROP_MATRIX";
3661 case PROP_EULER:
3662 return "PROP_EULER";
3663 case PROP_QUATERNION:
3664 return "PROP_QUATERNION";
3665 case PROP_AXISANGLE:
3666 return "PROP_AXISANGLE";
3667 case PROP_VELOCITY:
3668 return "PROP_VELOCITY";
3669 case PROP_ACCELERATION:
3670 return "PROP_ACCELERATION";
3671 case PROP_XYZ:
3672 return "PROP_XYZ";
3673 case PROP_COLOR_GAMMA:
3674 return "PROP_COLOR_GAMMA";
3675 case PROP_COORDS:
3676 return "PROP_COORDS";
3677 case PROP_LAYER:
3678 return "PROP_LAYER";
3679 case PROP_LAYER_MEMBER:
3680 return "PROP_LAYER_MEMBER";
3681 case PROP_PASSWORD:
3682 return "PROP_PASSWORD";
3683 case PROP_POWER:
3684 return "PROP_POWER";
3685 case PROP_TEMPERATURE:
3686 return "PROP_TEMPERATURE";
3687 case PROP_WAVELENGTH:
3688 return "PROP_WAVELENGTH";
3690 return "PROP_COLOR_TEMPERATURE";
3691 case PROP_FREQUENCY:
3692 return "PROP_FREQUENCY";
3693 default: {
3694 /* in case we don't have a type preset that includes the subtype */
3695 if (RNA_SUBTYPE_UNIT(type)) {
3697 }
3698 return "PROP_SUBTYPE_UNKNOWN";
3699 }
3700 }
3701}
3702
3704{
3705 switch (RNA_SUBTYPE_UNIT(type)) {
3706 case PROP_UNIT_NONE:
3707 return "PROP_UNIT_NONE";
3708 case PROP_UNIT_LENGTH:
3709 return "PROP_UNIT_LENGTH";
3710 case PROP_UNIT_AREA:
3711 return "PROP_UNIT_AREA";
3712 case PROP_UNIT_VOLUME:
3713 return "PROP_UNIT_VOLUME";
3714 case PROP_UNIT_MASS:
3715 return "PROP_UNIT_MASS";
3716 case PROP_UNIT_ROTATION:
3717 return "PROP_UNIT_ROTATION";
3718 case PROP_UNIT_TIME:
3719 return "PROP_UNIT_TIME";
3721 return "PROP_UNIT_TIME_ABSOLUTE";
3722 case PROP_UNIT_VELOCITY:
3723 return "PROP_UNIT_VELOCITY";
3725 return "PROP_UNIT_ACCELERATION";
3726 case PROP_UNIT_CAMERA:
3727 return "PROP_UNIT_CAMERA";
3728 case PROP_UNIT_POWER:
3729 return "PROP_UNIT_POWER";
3731 return "PROP_UNIT_TEMPERATURE";
3733 return "PROP_UNIT_WAVELENGTH";
3735 return "PROP_UNIT_COLOR_TEMPERATURE";
3737 return "PROP_UNIT_FREQUENCY";
3738 default:
3739 return "PROP_UNIT_UNKNOWN";
3740 }
3741}
3742
3744{
3745 StructRNA *srna;
3746
3747 for (srna = static_cast<StructRNA *>(brna->structs.first); srna;
3748 srna = static_cast<StructRNA *>(srna->cont.next))
3749 {
3750 fprintf(f, "extern struct StructRNA RNA_%s;\n", srna->identifier);
3751 }
3752 fprintf(f, "\n");
3753}
3754
3755static void rna_generate_blender(BlenderRNA *brna, FILE *f)
3756{
3757 StructRNA *srna;
3758
3759 fprintf(f,
3760 "BlenderRNA BLENDER_RNA = {\n"
3761 "\t/*structs*/ {");
3762 srna = static_cast<StructRNA *>(brna->structs.first);
3763 if (srna) {
3764 fprintf(f, "&RNA_%s, ", srna->identifier);
3765 }
3766 else {
3767 fprintf(f, "nullptr, ");
3768 }
3769
3770 srna = static_cast<StructRNA *>(brna->structs.last);
3771 if (srna) {
3772 fprintf(f, "&RNA_%s},\n", srna->identifier);
3773 }
3774 else {
3775 fprintf(f, "nullptr},\n");
3776 }
3777
3778 fprintf(f,
3779 "\t/*structs_map*/ nullptr,\n"
3780 "\t/*structs_len*/ 0,\n"
3781 "};\n\n");
3782}
3783
3785{
3786 fprintf(f, "struct PropertyRNA;\n\n");
3787
3789
3790 /* NOTE: Generate generic `PropertyRNA &` references. The actual, type-refined properties data
3791 * are static variables in their translation units (the `_gen.cc` files), which are assigned to
3792 * these public generic `PointerRNA &` references. */
3793 for (StructRNA *srna = static_cast<StructRNA *>(brna->structs.first); srna;
3794 srna = static_cast<StructRNA *>(srna->cont.next))
3795 {
3796 LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) {
3797 fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", srna->identifier, prop->identifier);
3798 }
3799 fprintf(f, "\n");
3800 }
3801}
3802
3804 StructRNA *srna,
3805 FILE *f)
3806{
3807 StructRNA *base;
3808
3809 /* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
3810 * comments for details. */
3811 base = srna->base;
3812 while (base) {
3813 fprintf(f, "\n");
3814 LISTBASE_FOREACH (PropertyRNA *, prop, &base->cont.properties) {
3815 fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", base->identifier, prop->identifier);
3816 }
3817 base = base->base;
3818 }
3819
3820 if (srna->cont.properties.first) {
3821 fprintf(f, "\n");
3822 }
3823
3824 LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) {
3825 fprintf(f, "extern PropertyRNA &rna_%s_%s;\n", srna->identifier, prop->identifier);
3826 }
3827 fprintf(f, "\n");
3828}
3829
3831 StructRNA *srna,
3832 FunctionRNA *func,
3833 FILE *f)
3834{
3835 /* NOTE: Generic `PropertyRNA &` references, see #rna_generate_external_property_prototypes
3836 * comments for details. */
3837 LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) {
3838 fprintf(f,
3839 "extern PropertyRNA &rna_%s_%s_%s;\n",
3840 srna->identifier,
3841 func->identifier,
3842 parm->identifier);
3843 }
3844
3845 if (func->cont.properties.first) {
3846 fprintf(f, "\n");
3847 }
3848}
3849
3851{
3852 FunctionRNA *func;
3853 StructRNA *base;
3854
3855 base = srna->base;
3856 while (base) {
3857 for (func = static_cast<FunctionRNA *>(base->functions.first); func;
3858 func = static_cast<FunctionRNA *>(func->cont.next))
3859 {
3860 fprintf(f, "extern FunctionRNA rna_%s_%s_func;\n", base->identifier, func->identifier);
3861 rna_generate_parameter_prototypes(brna, base, func, f);
3862 }
3863
3864 if (base->functions.first) {
3865 fprintf(f, "\n");
3866 }
3867
3868 base = base->base;
3869 }
3870
3871 for (func = static_cast<FunctionRNA *>(srna->functions.first); func;
3872 func = static_cast<FunctionRNA *>(func->cont.next))
3873 {
3874 fprintf(f, "extern FunctionRNA rna_%s_%s_func;\n", srna->identifier, func->identifier);
3875 rna_generate_parameter_prototypes(brna, srna, func, f);
3876 }
3877
3878 if (srna->functions.first) {
3879 fprintf(f, "\n");
3880 }
3881}
3882
3884 StructRNA *srna,
3885 FunctionDefRNA *dfunc,
3886 const char *name_override,
3887 int close_prototype)
3888{
3889 FunctionRNA *func;
3890 PropertyDefRNA *dparm_return = nullptr;
3891 StructDefRNA *dsrna;
3892 PropertyType type;
3893 int flag, flag_parameter, pout, cptr, first;
3894 const char *ptrstr;
3895
3896 dsrna = rna_find_struct_def(srna);
3897 func = dfunc->func;
3898
3899 /* return type */
3900 LISTBASE_FOREACH (PropertyDefRNA *, dparm, &dfunc->cont.properties) {
3901 if (dparm->prop == func->c_ret) {
3902 if (dparm->prop->arraydimension) {
3903 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
3904 }
3905 else if (dparm->prop->type == PROP_POINTER && !(dparm->prop->flag_parameter & PARM_RNAPTR)) {
3906 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
3907 }
3908 else {
3909 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
3910 }
3911
3912 dparm_return = dparm;
3913 break;
3914 }
3915 }
3916
3917 /* void if nothing to return */
3918 if (!dparm_return) {
3919 fprintf(f, "void ");
3920 }
3921
3922 /* function name */
3923 if (name_override == nullptr || name_override[0] == '\0') {
3924 fprintf(f, "%s(", dfunc->call);
3925 }
3926 else {
3927 fprintf(f, "%s(", name_override);
3928 }
3929
3930 first = 1;
3931
3932 /* self, context and reports parameters */
3933 if (func->flag & FUNC_USE_SELF_ID) {
3934 fprintf(f, "struct ID *_selfid");
3935 first = 0;
3936 }
3937
3938 if ((func->flag & FUNC_NO_SELF) == 0) {
3939 if (!first) {
3940 fprintf(f, ", ");
3941 }
3942 if ((func->flag & FUNC_SELF_AS_RNA) != 0) {
3943 fprintf(f, "struct PointerRNA _self");
3944 }
3945 else if (dsrna->dnafromprop) {
3946 fprintf(f, "struct %s *_self", dsrna->dnafromname);
3947 }
3948 else if (dsrna->dnaname) {
3949 fprintf(f, "struct %s *_self", dsrna->dnaname);
3950 }
3951 else {
3952 fprintf(f, "struct %s *_self", srna->identifier);
3953 }
3954 first = 0;
3955 }
3956 else if (func->flag & FUNC_USE_SELF_TYPE) {
3957 if (!first) {
3958 fprintf(f, ", ");
3959 }
3960 fprintf(f, "struct StructRNA *_type");
3961 first = 0;
3962 }
3963
3964 if (func->flag & FUNC_USE_MAIN) {
3965 if (!first) {
3966 fprintf(f, ", ");
3967 }
3968 first = 0;
3969 fprintf(f, "Main *bmain");
3970 }
3971
3972 if (func->flag & FUNC_USE_CONTEXT) {
3973 if (!first) {
3974 fprintf(f, ", ");
3975 }
3976 first = 0;
3977 fprintf(f, "bContext *C");
3978 }
3979
3980 if (func->flag & FUNC_USE_REPORTS) {
3981 if (!first) {
3982 fprintf(f, ", ");
3983 }
3984 first = 0;
3985 fprintf(f, "ReportList *reports");
3986 }
3987
3988 /* defined parameters */
3989 LISTBASE_FOREACH (PropertyDefRNA *, dparm, &dfunc->cont.properties) {
3990 type = dparm->prop->type;
3991 flag = dparm->prop->flag;
3992 flag_parameter = dparm->prop->flag_parameter;
3993 pout = (flag_parameter & PARM_OUTPUT);
3994 cptr = ((type == PROP_POINTER) && !(flag_parameter & PARM_RNAPTR));
3995
3996 if (dparm->prop == func->c_ret) {
3997 continue;
3998 }
3999
4000 if (cptr || (flag & PROP_DYNAMIC)) {
4001 if (type == PROP_STRING) {
4002 ptrstr = pout ? "*" : "";
4003 }
4004 else {
4005 ptrstr = pout ? "**" : "*";
4006 }
4007 }
4008 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
4009 ptrstr = "*";
4010 }
4011 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
4012 ptrstr = "";
4013 }
4014 else {
4015 ptrstr = pout ? "*" : "";
4016 }
4017
4018 if (!first) {
4019 fprintf(f, ", ");
4020 }
4021 first = 0;
4022
4023 if (flag & PROP_DYNAMIC) {
4024 fprintf(f, "int %s%s_num, ", pout ? "*" : "", dparm->prop->identifier);
4025 }
4026
4027 if (!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension) {
4028 fprintf(f,
4029 "%s%s %s[%u]",
4030 rna_type_struct(dparm->prop),
4031 rna_parameter_type_name(dparm->prop),
4032 rna_safe_id(dparm->prop->identifier),
4033 dparm->prop->totarraylength);
4034 }
4035 else {
4036 fprintf(f,
4037 "%s%s %s%s",
4038 rna_type_struct(dparm->prop),
4039 rna_parameter_type_name(dparm->prop),
4040 ptrstr,
4041 rna_safe_id(dparm->prop->identifier));
4042 }
4043 }
4044
4045 /* ensure func(void) if there are no args */
4046 if (first) {
4047 fprintf(f, "void");
4048 }
4049
4050 fprintf(f, ")");
4051
4052 if (close_prototype) {
4053 fprintf(f, ";\n");
4054 }
4055}
4056
4058 StructRNA *srna,
4059 FILE *f)
4060{
4061 FunctionRNA *func;
4062 FunctionDefRNA *dfunc;
4063 int first = 1;
4064
4065 for (func = static_cast<FunctionRNA *>(srna->functions.first); func;
4066 func = static_cast<FunctionRNA *>(func->cont.next))
4067 {
4068 dfunc = rna_find_function_def(func);
4069
4070 if (dfunc->call) {
4071 if (strstr(dfunc->call, "<")) {
4072 /* Can't generate the declaration for templates. We'll still get compile errors when trying
4073 * to call it with a wrong signature. */
4074 continue;
4075 }
4076
4077 if (first) {
4078 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
4079 first = 0;
4080 }
4081
4082 rna_generate_static_parameter_prototypes(f, srna, dfunc, nullptr, 1);
4083 }
4084 }
4085
4086 fprintf(f, "\n");
4087}
4088
4090{
4091 StructDefRNA *ds;
4092 FunctionDefRNA *dfunc;
4093 const char *structures[2048];
4094 int all_structures = 0;
4095
4096 /* structures definitions */
4097 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
4098 ds = static_cast<StructDefRNA *>(ds->cont.next))
4099 {
4100 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
4101 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
4102 {
4103 if (dfunc->call) {
4105 if (dp->prop->type == PROP_POINTER) {
4106 int a, found = 0;
4107 const char *struct_name = rna_parameter_type_name(dp->prop);
4108 if (struct_name == nullptr) {
4109 printf("No struct found for property '%s'\n", dp->prop->identifier);
4110 exit(1);
4111 }
4112
4113 for (a = 0; a < all_structures; a++) {
4114 if (STREQ(struct_name, structures[a])) {
4115 found = 1;
4116 break;
4117 }
4118 }
4119
4120 if (found == 0) {
4121 fprintf(f, "struct %s;\n", struct_name);
4122
4123 if (all_structures >= ARRAY_SIZE(structures)) {
4124 printf("Array size to store all structures names is too small\n");
4125 exit(1);
4126 }
4127
4128 structures[all_structures++] = struct_name;
4129 }
4130 }
4131 }
4132 }
4133 }
4134 }
4135
4136 fprintf(f, "\n");
4137}
4138
4139static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
4140{
4141 char *strnest = (char *)"", *errnest = (char *)"";
4142 bool freenest = false;
4143
4144 if (nest != nullptr) {
4145 size_t len = strlen(nest);
4146
4147 strnest = MEM_malloc_arrayN<char>(len + 2, "rna_generate_property -> strnest");
4148 errnest = MEM_malloc_arrayN<char>(len + 2, "rna_generate_property -> errnest");
4149
4150 strnest[0] = '_';
4151 memcpy(strnest + 1, nest, len + 1);
4152
4153 errnest[0] = '.';
4154 memcpy(errnest + 1, nest, len + 1);
4155
4156 freenest = true;
4157 }
4158
4159 if (prop->deprecated) {
4160 fprintf(f,
4161 "static const DeprecatedRNA rna_%s%s_%s_deprecated = {\n\t",
4162 srna->identifier,
4163 strnest,
4164 prop->identifier);
4166 fprintf(f, ",\n\t%d, %d,\n", prop->deprecated->version, prop->deprecated->removal_version);
4167 fprintf(f, "};\n\n");
4168 }
4169
4170 switch (prop->type) {
4171 case PROP_ENUM: {
4172 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
4173 int i, defaultfound = 0, totflag = 0;
4174
4175 if (eprop->item) {
4176 /* Inline the enum if this is not a defined in "RNA_enum_items.hh". */
4177 const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
4178 if (item_global_id == nullptr) {
4179 fprintf(f,
4180 "static const EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t",
4181 srna->identifier,
4182 strnest,
4183 prop->identifier,
4184 eprop->totitem + 1);
4185
4186 for (i = 0; i < eprop->totitem; i++) {
4187 fprintf(f, "{%d, ", eprop->item[i].value);
4188 rna_print_c_string(f, eprop->item[i].identifier);
4189 fprintf(f, ", ");
4190 fprintf(f, "%d, ", eprop->item[i].icon);
4191 rna_print_c_string(f, eprop->item[i].name);
4192 fprintf(f, ", ");
4194 fprintf(f, "},\n\t");
4195
4196 if (eprop->item[i].identifier[0]) {
4197 if (prop->flag & PROP_ENUM_FLAG) {
4198 totflag |= eprop->item[i].value;
4199 }
4200 else {
4201 if (eprop->defaultvalue == eprop->item[i].value) {
4202 defaultfound = 1;
4203 }
4204 }
4205 }
4206 }
4207
4208 fprintf(f, "{0, nullptr, 0, nullptr, nullptr}\n};\n\n");
4209 }
4210 else {
4211 for (i = 0; i < eprop->totitem; i++) {
4212 if (eprop->item[i].identifier[0]) {
4213 if (prop->flag & PROP_ENUM_FLAG) {
4214 totflag |= eprop->item[i].value;
4215 }
4216 else {
4217 if (eprop->defaultvalue == eprop->item[i].value) {
4218 defaultfound = 1;
4219 }
4220 }
4221 }
4222 }
4223 }
4224
4225 if (prop->flag & PROP_ENUM_FLAG) {
4226 if (eprop->defaultvalue & ~totflag) {
4227 CLOG_ERROR(&LOG,
4228 "%s%s.%s, enum default includes unused bits (%d).",
4229 srna->identifier,
4230 errnest,
4231 prop->identifier,
4232 eprop->defaultvalue & ~totflag);
4233 DefRNA.error = true;
4234 }
4235 }
4236 else {
4237 if (!defaultfound && !(eprop->item_fn && eprop->item == rna_enum_dummy_NULL_items)) {
4238 CLOG_ERROR(&LOG,
4239 "%s%s.%s, enum default '%d' is not in items.",
4240 srna->identifier,
4241 errnest,
4242 prop->identifier,
4243 eprop->defaultvalue);
4244 DefRNA.error = true;
4245 }
4246 }
4247 }
4248 else {
4249 CLOG_ERROR(&LOG,
4250 "%s%s.%s, enum must have items defined.",
4251 srna->identifier,
4252 errnest,
4253 prop->identifier);
4254 DefRNA.error = true;
4255 }
4256 break;
4257 }
4258 case PROP_BOOLEAN: {
4259 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
4260 uint i;
4261
4262 if (prop->arraydimension && prop->totarraylength) {
4263 fprintf(f,
4264 "static bool rna_%s%s_%s_default[%u] = {\n\t",
4265 srna->identifier,
4266 strnest,
4267 prop->identifier,
4268 prop->totarraylength);
4269
4270 for (i = 0; i < prop->totarraylength; i++) {
4271 if (bprop->defaultarray) {
4272 fprintf(f, "%d", bprop->defaultarray[i]);
4273 }
4274 else {
4275 fprintf(f, "%d", bprop->defaultvalue);
4276 }
4277 if (i != prop->totarraylength - 1) {
4278 fprintf(f, ",\n\t");
4279 }
4280 }
4281
4282 fprintf(f, "\n};\n\n");
4283 }
4284 break;
4285 }
4286 case PROP_INT: {
4287 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
4288 uint i;
4289
4290 if (prop->arraydimension && prop->totarraylength) {
4291 fprintf(f,
4292 "static int rna_%s%s_%s_default[%u] = {\n\t",
4293 srna->identifier,
4294 strnest,
4295 prop->identifier,
4296 prop->totarraylength);
4297
4298 for (i = 0; i < prop->totarraylength; i++) {
4299 if (iprop->defaultarray) {
4300 fprintf(f, "%d", iprop->defaultarray[i]);
4301 }
4302 else {
4303 fprintf(f, "%d", iprop->defaultvalue);
4304 }
4305 if (i != prop->totarraylength - 1) {
4306 fprintf(f, ",\n\t");
4307 }
4308 }
4309
4310 fprintf(f, "\n};\n\n");
4311 }
4312 break;
4313 }
4314 case PROP_FLOAT: {
4315 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
4316 uint i;
4317
4318 if (prop->arraydimension && prop->totarraylength) {
4319 fprintf(f,
4320 "static float rna_%s%s_%s_default[%u] = {\n\t",
4321 srna->identifier,
4322 strnest,
4323 prop->identifier,
4324 prop->totarraylength);
4325
4326 for (i = 0; i < prop->totarraylength; i++) {
4327 if (fprop->defaultarray) {
4328 rna_float_print(f, fprop->defaultarray[i]);
4329 }
4330 else {
4331 rna_float_print(f, fprop->defaultvalue);
4332 }
4333 if (i != prop->totarraylength - 1) {
4334 fprintf(f, ",\n\t");
4335 }
4336 }
4337
4338 fprintf(f, "\n};\n\n");
4339 }
4340 break;
4341 }
4342 case PROP_POINTER: {
4343 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
4344
4345 /* XXX This systematically enforces that flag on ID pointers...
4346 * we'll probably have to revisit. :/ */
4347 StructRNA *type = rna_find_struct((const char *)pprop->type);
4348 if (type && (type->flag & STRUCT_ID) &&
4350 {
4352 }
4353 break;
4354 }
4355 case PROP_COLLECTION: {
4357
4358 /* XXX This systematically enforces that flag on ID pointers...
4359 * we'll probably have to revisit. :/ */
4360 StructRNA *type = rna_find_struct((const char *)cprop->item_type);
4361 if (type && (type->flag & STRUCT_ID) &&
4363 {
4365 }
4366 break;
4367 }
4368 default:
4369 break;
4370 }
4371
4372 /* Generate the RNA-private, type-refined property data.
4373 *
4374 * See #rna_generate_external_property_prototypes comments for details. */
4375 fprintf(f,
4376 "static %s rna_%s%s_%s_ = {\n",
4378 srna->identifier,
4379 strnest,
4380 prop->identifier);
4381
4382 if (prop->next) {
4383 fprintf(f, "\t{&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
4384 }
4385 else {
4386 fprintf(f, "\t{nullptr, ");
4387 }
4388 if (prop->prev) {
4389 fprintf(f, "&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
4390 }
4391 else {
4392 fprintf(f, "nullptr,\n");
4393 }
4394 fprintf(f, "\t%d, ", prop->magic);
4396 fprintf(f,
4397 ", %d, %d, %d, %d, %d, ",
4398 prop->flag,
4399 prop->flag_override,
4400 prop->flag_parameter,
4401 prop->flag_internal,
4402 prop->tags);
4403 fprintf(f, "PropertyPathTemplateType(%d), ", prop->path_template_type);
4404 rna_print_c_string(f, prop->name);
4405 fprintf(f, ",\n\t");
4407 fprintf(f, ",\n\t");
4408 fprintf(f, "%d, ", prop->icon);
4410 fprintf(f, ",\n\t");
4411
4412 if (prop->deprecated) {
4413 fprintf(f, "&rna_%s%s_%s_deprecated,", srna->identifier, strnest, prop->identifier);
4414 }
4415 else {
4416 fprintf(f, "nullptr,\n");
4417 }
4418
4419 fprintf(f,
4420 "\t%s, PropertySubType(int(%s) | int(%s)), %s, %u, {%u, %u, %u}, %u,\n",
4425 prop->arraydimension,
4426 prop->arraylength[0],
4427 prop->arraylength[1],
4428 prop->arraylength[2],
4429 prop->totarraylength);
4430 fprintf(f,
4431 "\t%s%s, %d, %s, %s, %s, %s, %s, %s,\n",
4432 /* NOTE: void cast is needed to quiet function cast warning in C++. */
4433 (prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)(void *)" : "",
4435 prop->noteflag,
4442
4444 rna_set_raw_offset(f, srna, prop);
4445 }
4446 else {
4447 fprintf(f, "\t0, PROP_RAW_UNSET");
4448 }
4449
4450 /* our own type - collections/arrays only */
4451 if (prop->srna) {
4452 fprintf(f, ", &RNA_%s", (const char *)prop->srna);
4453 }
4454 else {
4455 fprintf(f, ", nullptr");
4456 }
4457
4458 fprintf(f, "},\n");
4459
4460 switch (prop->type) {
4461 case PROP_BOOLEAN: {
4462 BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
4463 fprintf(f,
4464 "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, ",
4465 rna_function_string(bprop->get),
4466 rna_function_string(bprop->set),
4479 bprop->defaultvalue);
4480 if (prop->arraydimension && prop->totarraylength) {
4481 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
4482 }
4483 else {
4484 fprintf(f, "nullptr\n");
4485 }
4486 break;
4487 }
4488 case PROP_INT: {
4489 IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
4490 fprintf(f,
4491 "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,\n\t",
4492 rna_function_string(iprop->get),
4493 rna_function_string(iprop->set),
4496 rna_function_string(iprop->range),
4506 fprintf(f, "%s", rna_ui_scale_type_string(iprop->ui_scale_type));
4507 fprintf(f, ", ");
4508 rna_int_print(f, iprop->softmin);
4509 fprintf(f, ", ");
4510 rna_int_print(f, iprop->softmax);
4511 fprintf(f, ", ");
4512 rna_int_print(f, iprop->hardmin);
4513 fprintf(f, ", ");
4514 rna_int_print(f, iprop->hardmax);
4515 fprintf(f, ", ");
4516 rna_int_print(f, iprop->step);
4517 fprintf(f, ", ");
4518 fprintf(f,
4519 "%s, %s",
4522 fprintf(f, ", ");
4523 rna_int_print(f, iprop->defaultvalue);
4524 fprintf(f, ", ");
4525 if (prop->arraydimension && prop->totarraylength) {
4526 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
4527 }
4528 else {
4529 fprintf(f, "nullptr\n");
4530 }
4531 break;
4532 }
4533 case PROP_FLOAT: {
4534 FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
4535 fprintf(f,
4536 "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ",
4537 rna_function_string(fprop->get),
4538 rna_function_string(fprop->set),
4541 rna_function_string(fprop->range),
4551 fprintf(f, "%s, ", rna_ui_scale_type_string(fprop->ui_scale_type));
4552 rna_float_print(f, fprop->softmin);
4553 fprintf(f, ", ");
4554 rna_float_print(f, fprop->softmax);
4555 fprintf(f, ", ");
4556 rna_float_print(f, fprop->hardmin);
4557 fprintf(f, ", ");
4558 rna_float_print(f, fprop->hardmax);
4559 fprintf(f, ", ");
4560 rna_float_print(f, fprop->step);
4561 fprintf(f, ", ");
4562 rna_int_print(f, fprop->precision);
4563 fprintf(f, ", ");
4564 fprintf(f,
4565 "%s, %s",
4568 fprintf(f, ", ");
4569 rna_float_print(f, fprop->defaultvalue);
4570 fprintf(f, ", ");
4571 if (prop->arraydimension && prop->totarraylength) {
4572 fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
4573 }
4574 else {
4575 fprintf(f, "nullptr\n");
4576 }
4577 break;
4578 }
4579 case PROP_STRING: {
4580 StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
4581 fprintf(f,
4582 "\t%s, %s, %s, %s, %s, %s, %s, %s, %s, eStringPropertySearchFlag(%d), %s, %d, ",
4583 rna_function_string(sprop->get),
4585 rna_function_string(sprop->set),
4592 int(sprop->search_flag),
4594 sprop->maxlength);
4596 fprintf(f, "\n");
4597 break;
4598 }
4599 case PROP_ENUM: {
4600 EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
4601 fprintf(f,
4602 "\t%s, %s, %s, %s, %s, %s, %s, %s, ",
4603 rna_function_string(eprop->get),
4604 rna_function_string(eprop->set),
4611 if (eprop->item) {
4612 const char *item_global_id = rna_enum_id_from_pointer(eprop->item);
4613 if (item_global_id != nullptr) {
4614 fprintf(f, "%s, ", item_global_id);
4615 }
4616 else {
4617 fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
4618 }
4619 }
4620 else {
4621 fprintf(f, "nullptr, ");
4622 }
4623 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
4624 break;
4625 }
4626 case PROP_POINTER: {
4627 PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
4628 fprintf(f,
4629 "\t%s, %s, %s, %s,",
4630 rna_function_string(pprop->get),
4631 rna_function_string(pprop->set),
4633 rna_function_string(pprop->poll));
4634 if (pprop->type) {
4635 fprintf(f, "&RNA_%s\n", (const char *)pprop->type);
4636 }
4637 else {
4638 fprintf(f, "nullptr\n");
4639 }
4640 break;
4641 }
4642 case PROP_COLLECTION: {
4644 fprintf(f,
4645 "\t%s, %s, %s, %s, %s, %s, %s, %s, ",
4646 rna_function_string(cprop->begin),
4647 rna_function_string(cprop->next),
4648 rna_function_string(cprop->end),
4649 rna_function_string(cprop->get),
4654 if (cprop->item_type) {
4655 fprintf(f, "&RNA_%s\n", (const char *)cprop->item_type);
4656 }
4657 else {
4658 fprintf(f, "nullptr\n");
4659 }
4660 break;
4661 }
4662 }
4663
4664 fprintf(f, "};\n");
4665
4666 /* Assign the RNA-private, type-refined static (local) property data to the public matching
4667 * generic `PropertyRNA &` reference.
4668 *
4669 * See #rna_generate_external_property_prototypes comments for details. */
4670 fprintf(
4671 f,
4672 /* Use a reference here instead of a pointer, because pointer usage somehow makes clang
4673 * optimizer take a very long time to compile the `rna_xxx_gen.cc` files (see faf56cc3bf).
4674 *
4675 * Note that in theory, any access to the 'public' `PointerRNA &` reference data is
4676 * undefined behavior (strict aliasing rules). This is currently not a real issue (these
4677 * PropertyRNA definitions are almost always only used as pointers, and are currently POD
4678 * types).
4679 *
4680 * `reinterpret_cast<PropertyRNA &>(rna_prop_data)` here is same as
4681 * `*reinterpret_cast<PropertyRNA *>(&rna_prop_data)` (see point (6) of
4682 * https://en.cppreference.com/w/cpp/language/reinterpret_cast). */
4683 "PropertyRNA &rna_%s%s_%s = reinterpret_cast<PropertyRNA &>(rna_%s%s_%s_);\n\n",
4684 srna->identifier,
4685 strnest,
4686 prop->identifier,
4687 srna->identifier,
4688 strnest,
4689 prop->identifier);
4690
4691 if (freenest) {
4692 MEM_freeN(strnest);
4693 MEM_freeN(errnest);
4694 }
4695}
4696
4697static void rna_generate_struct(BlenderRNA * /*brna*/, StructRNA *srna, FILE *f)
4698{
4699 FunctionRNA *func;
4700 FunctionDefRNA *dfunc;
4701 PropertyRNA *prop, *parm;
4702 StructRNA *base;
4703
4704 fprintf(f, "/* %s */\n", srna->name);
4705
4706 LISTBASE_FOREACH (PropertyRNA *, prop, &srna->cont.properties) {
4707 rna_generate_property(f, srna, nullptr, prop);
4708 }
4709
4710 for (func = static_cast<FunctionRNA *>(srna->functions.first); func;
4711 func = static_cast<FunctionRNA *>(func->cont.next))
4712 {
4713 LISTBASE_FOREACH (PropertyRNA *, parm, &func->cont.properties) {
4714 rna_generate_property(f, srna, func->identifier, parm);
4715 }
4716
4717 fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
4718
4719 if (func->cont.next) {
4720 fprintf(f,
4721 "\t{(FunctionRNA *)&rna_%s_%s_func, ",
4722 srna->identifier,
4723 ((FunctionRNA *)func->cont.next)->identifier);
4724 }
4725 else {
4726 fprintf(f, "\t{nullptr, ");
4727 }
4728 if (func->cont.prev) {
4729 fprintf(f,
4730 "(FunctionRNA *)&rna_%s_%s_func,\n",
4731 srna->identifier,
4732 ((FunctionRNA *)func->cont.prev)->identifier);
4733 }
4734 else {
4735 fprintf(f, "nullptr,\n");
4736 }
4737
4738 fprintf(f, "\tnullptr,\n");
4739
4740 parm = static_cast<PropertyRNA *>(func->cont.properties.first);
4741 if (parm) {
4742 fprintf(f, "\t{&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
4743 }
4744 else {
4745 fprintf(f, "\t{nullptr, ");
4746 }
4747
4748 parm = static_cast<PropertyRNA *>(func->cont.properties.last);
4749 if (parm) {
4750 fprintf(f, "&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
4751 }
4752 else {
4753 fprintf(f, "nullptr}},\n");
4754 }
4755
4756 fprintf(f, "\t");
4758 fprintf(f, ", %d, ", func->flag);
4760 fprintf(f, ",\n");
4761
4762 dfunc = rna_find_function_def(func);
4763 if (dfunc->gencall) {
4764 fprintf(f, "\t%s,\n", dfunc->gencall);
4765 }
4766 else {
4767 fprintf(f, "\tnullptr,\n");
4768 }
4769
4770 if (func->c_ret) {
4771 fprintf(f, "\t&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
4772 }
4773 else {
4774 fprintf(f, "\tnullptr\n");
4775 }
4776
4777 fprintf(f, "};\n");
4778 fprintf(f, "\n");
4779 }
4780
4781 fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
4782
4783 if (srna->cont.next) {
4784 fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA *)srna->cont.next)->identifier);
4785 }
4786 else {
4787 fprintf(f, "\t{nullptr, ");
4788 }
4789 if (srna->cont.prev) {
4790 fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA *)srna->cont.prev)->identifier);
4791 }
4792 else {
4793 fprintf(f, "nullptr,\n");
4794 }
4795
4796 fprintf(f, "\tnullptr,\n");
4797
4798 prop = static_cast<PropertyRNA *>(srna->cont.properties.first);
4799 if (prop) {
4800 fprintf(f, "\t{&rna_%s_%s, ", srna->identifier, prop->identifier);
4801 }
4802 else {
4803 fprintf(f, "\t{nullptr, ");
4804 }
4805
4806 prop = static_cast<PropertyRNA *>(srna->cont.properties.last);
4807 if (prop) {
4808 fprintf(f, "&rna_%s_%s}},\n", srna->identifier, prop->identifier);
4809 }
4810 else {
4811 fprintf(f, "nullptr}},\n");
4812 }
4813 fprintf(f, "\t");
4815 fprintf(f, ", nullptr, nullptr"); /* PyType - Can't initialize here */
4816 fprintf(f, ", %d, nullptr, ", srna->flag);
4817 rna_print_c_string(f, srna->name);
4818 fprintf(f, ",\n\t");
4820 fprintf(f, ",\n\t");
4822 fprintf(f, ", %d,\n", srna->icon);
4823
4824 prop = srna->nameproperty;
4825 if (prop) {
4826 base = srna;
4827 while (base->base && base->base->nameproperty == prop) {
4828 base = base->base;
4829 }
4830
4831 fprintf(f, "\t&rna_%s_%s, ", base->identifier, prop->identifier);
4832 }
4833 else {
4834 fprintf(f, "\tnullptr, ");
4835 }
4836
4837 prop = srna->iteratorproperty;
4838 base = srna;
4839 while (base->base && base->base->iteratorproperty == prop) {
4840 base = base->base;
4841 }
4842 fprintf(f, "&rna_%s_rna_properties,\n", base->identifier);
4843
4844 if (srna->base) {
4845 fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
4846 }
4847 else {
4848 fprintf(f, "\tnullptr,\n");
4849 }
4850
4851 if (srna->nested) {
4852 fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
4853 }
4854 else {
4855 fprintf(f, "\tnullptr,\n");
4856 }
4857
4858 fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
4859 fprintf(f, "\t%s,\n", rna_function_string(srna->path));
4860 fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
4861 fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
4862 fprintf(f, "\t%s,\n", rna_function_string(srna->instance));
4863 fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
4864 fprintf(f, "\t%s,\n", rna_function_string(srna->system_idproperties));
4865
4866 if (srna->reg && !srna->refine) {
4867 CLOG_ERROR(
4868 &LOG, "%s has a register function, must also have refine function.", srna->identifier);
4869 DefRNA.error = true;
4870 }
4871
4872 func = static_cast<FunctionRNA *>(srna->functions.first);
4873 if (func) {
4874 fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier, func->identifier);
4875 }
4876 else {
4877 fprintf(f, "\t{nullptr, ");
4878 }
4879
4880 func = static_cast<FunctionRNA *>(srna->functions.last);
4881 if (func) {
4882 fprintf(f, "(FunctionRNA *)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
4883 }
4884 else {
4885 fprintf(f, "nullptr}\n");
4886 }
4887
4888 fprintf(f, "};\n");
4889
4890 fprintf(f, "\n");
4891}
4892
4894 const char *filename;
4895 const char *api_filename;
4896 void (*define)(BlenderRNA *brna);
4897};
4898
4900 {"rna_rna.cc", nullptr, RNA_def_rna},
4901 {"rna_ID.cc", nullptr, RNA_def_ID},
4902 {"rna_texture.cc", "rna_texture_api.cc", RNA_def_texture},
4903 {"rna_action.cc", "rna_action_api.cc", RNA_def_action},
4904 {"rna_animation.cc", "rna_animation_api.cc", RNA_def_animation},
4905 {"rna_animviz.cc", nullptr, RNA_def_animviz},
4906 {"rna_armature.cc", "rna_armature_api.cc", RNA_def_armature},
4907 {"rna_attribute.cc", nullptr, RNA_def_attribute},
4908 {"rna_asset.cc", nullptr, RNA_def_asset},
4909 {"rna_boid.cc", nullptr, RNA_def_boid},
4910 {"rna_brush.cc", nullptr, RNA_def_brush},
4911 {"rna_cachefile.cc", nullptr, RNA_def_cachefile},
4912 {"rna_camera.cc", "rna_camera_api.cc", RNA_def_camera},
4913 {"rna_cloth.cc", nullptr, RNA_def_cloth},
4914 {"rna_collection.cc", nullptr, RNA_def_collections},
4915 {"rna_color.cc", nullptr, RNA_def_color},
4916 {"rna_constraint.cc", nullptr, RNA_def_constraint},
4917 {"rna_context.cc", nullptr, RNA_def_context},
4918 {"rna_curve.cc", "rna_curve_api.cc", RNA_def_curve},
4919 {"rna_dynamicpaint.cc", nullptr, RNA_def_dynamic_paint},
4920 {"rna_fcurve.cc", "rna_fcurve_api.cc", RNA_def_fcurve},
4921 {"rna_annotations.cc", nullptr, RNA_def_annotations},
4922 {"rna_grease_pencil.cc", "rna_grease_pencil_api.cc", RNA_def_grease_pencil},
4923 {"rna_curves.cc", "rna_curves_api.cc", RNA_def_curves},
4924 {"rna_image.cc", "rna_image_api.cc", RNA_def_image},
4925 {"rna_key.cc", nullptr, RNA_def_key},
4926 {"rna_light.cc", nullptr, RNA_def_light},
4927 {"rna_lattice.cc", "rna_lattice_api.cc", RNA_def_lattice},
4928 {"rna_layer.cc", nullptr, RNA_def_view_layer},
4929 {"rna_linestyle.cc", nullptr, RNA_def_linestyle},
4930 {"rna_blendfile_import.cc", nullptr, RNA_def_blendfile_import},
4931 {"rna_main.cc", "rna_main_api.cc", RNA_def_main},
4932 {"rna_fluid.cc", nullptr, RNA_def_fluid},
4933 {"rna_material.cc", "rna_material_api.cc", RNA_def_material},
4934 {"rna_mesh.cc", "rna_mesh_api.cc", RNA_def_mesh},
4935 {"rna_meta.cc", "rna_meta_api.cc", RNA_def_meta},
4936 {"rna_modifier.cc", nullptr, RNA_def_modifier},
4937 {"rna_shader_fx.cc", nullptr, RNA_def_shader_fx},
4938 {"rna_nla.cc", nullptr, RNA_def_nla},
4939 {"rna_nodetree.cc", nullptr, RNA_def_nodetree},
4940 {"rna_node_socket.cc", nullptr, RNA_def_node_socket_subtypes},
4941 {"rna_node_tree_interface.cc", nullptr, RNA_def_node_tree_interface},
4942 {"rna_object.cc", "rna_object_api.cc", RNA_def_object},
4943 {"rna_object_force.cc", nullptr, RNA_def_object_force},
4944 {"rna_depsgraph.cc", nullptr, RNA_def_depsgraph},
4945 {"rna_packedfile.cc", nullptr, RNA_def_packedfile},
4946 {"rna_palette.cc", nullptr, RNA_def_palette},
4947 {"rna_particle.cc", nullptr, RNA_def_particle},
4948 {"rna_pointcloud.cc", nullptr, RNA_def_pointcloud},
4949 {"rna_pose.cc", "rna_pose_api.cc", RNA_def_pose},
4950 {"rna_curveprofile.cc", nullptr, RNA_def_profile},
4951 {"rna_lightprobe.cc", nullptr, RNA_def_lightprobe},
4952 {"rna_render.cc", nullptr, RNA_def_render},
4953 {"rna_rigidbody.cc", nullptr, RNA_def_rigidbody},
4954 {"rna_scene.cc", "rna_scene_api.cc", RNA_def_scene},
4955 {"rna_screen.cc", nullptr, RNA_def_screen},
4956 {"rna_sculpt_paint.cc", nullptr, RNA_def_sculpt_paint},
4957 {"rna_sequencer.cc", "rna_sequencer_api.cc", RNA_def_sequencer},
4958 {"rna_space.cc", "rna_space_api.cc", RNA_def_space},
4959 {"rna_speaker.cc", nullptr, RNA_def_speaker},
4960 {"rna_test.cc", nullptr, RNA_def_test},
4961 {"rna_text.cc", "rna_text_api.cc", RNA_def_text},
4962 {"rna_timeline.cc", nullptr, RNA_def_timeline_marker},
4963 {"rna_sound.cc", "rna_sound_api.cc", RNA_def_sound},
4964 {"rna_ui.cc", "rna_ui_api.cc", RNA_def_ui},
4965#ifdef WITH_USD
4966 {"rna_usd.cc", nullptr, RNA_def_usd},
4967#endif
4968 {"rna_userdef.cc", nullptr, RNA_def_userdef},
4969 {"rna_vfont.cc", "rna_vfont_api.cc", RNA_def_vfont},
4970 {"rna_volume.cc", nullptr, RNA_def_volume},
4971 {"rna_wm.cc", "rna_wm_api.cc", RNA_def_wm},
4972 {"rna_wm_gizmo.cc", "rna_wm_gizmo_api.cc", RNA_def_wm_gizmo},
4973 {"rna_workspace.cc", "rna_workspace_api.cc", RNA_def_workspace},
4974 {"rna_world.cc", nullptr, RNA_def_world},
4975 {"rna_movieclip.cc", nullptr, RNA_def_movieclip},
4976 {"rna_tracking.cc", nullptr, RNA_def_tracking},
4977 {"rna_mask.cc", nullptr, RNA_def_mask},
4978 {"rna_xr.cc", nullptr, RNA_def_xr},
4979 {nullptr, nullptr},
4980};
4981
4982static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
4983{
4984 StructDefRNA *ds;
4985 FunctionDefRNA *dfunc;
4986
4987 fprintf(f,
4988 "\n"
4989 "/* Automatically generated struct definitions for the Data API.\n"
4990 " * Do not edit manually, changes will be overwritten. */\n\n"
4991 "#define RNA_RUNTIME\n\n");
4992
4993 fprintf(f, "#include <float.h>\n");
4994 fprintf(f, "#include <stdio.h>\n");
4995 fprintf(f, "#include <limits.h>\n");
4996 fprintf(f, "#include <limits>\n");
4997 fprintf(f, "#include <string.h>\n\n");
4998 fprintf(f, "#include <stddef.h>\n\n");
4999 fprintf(f, "#include <algorithm>\n\n");
5000
5001 fprintf(f, "#include \"MEM_guardedalloc.h\"\n\n");
5002
5003 fprintf(f, "#include \"DNA_ID.h\"\n");
5004 fprintf(f, "#include \"DNA_scene_types.h\"\n");
5005 fprintf(f, "#include \"DNA_node_types.h\"\n");
5006
5007 fprintf(f, "#include \"BLI_fileops.h\"\n\n");
5008 fprintf(f, "#include \"BLI_listbase.h\"\n\n");
5009 fprintf(f, "#include \"BLI_path_utils.hh\"\n\n");
5010 fprintf(f, "#include \"BLI_rect.h\"\n\n");
5011 fprintf(f, "#include \"BLI_string.h\"\n\n");
5012 fprintf(f, "#include \"BLI_string_utf8.h\"\n\n");
5013 fprintf(f, "#include \"BLI_utildefines.h\"\n\n");
5014
5015 fprintf(f, "#include \"BKE_context.hh\"\n");
5016 fprintf(f, "#include \"BKE_lib_id.hh\"\n");
5017 fprintf(f, "#include \"BKE_main.hh\"\n");
5018 fprintf(f, "#include \"BKE_report.hh\"\n");
5019
5020 fprintf(f, "#include \"RNA_define.hh\"\n");
5021 fprintf(f, "#include \"RNA_types.hh\"\n");
5022 fprintf(f, "#include \"rna_internal.hh\"\n\n");
5023
5024 /* include the generated prototypes header */
5025 fprintf(f, "#include \"rna_prototypes_gen.hh\"\n\n");
5026
5027 if (filename) {
5028 fprintf(f, "#include \"%s\"\n", filename);
5029 }
5030 if (api_filename) {
5031 fprintf(f, "#include \"%s\"\n", api_filename);
5032 }
5033 fprintf(f, "\n");
5034
5035/* we want the included C files to have warnings enabled but for the generated code
5036 * ignore unused-parameter warnings which are hard to prevent */
5037#if defined(__GNUC__) || defined(__clang__)
5038 fprintf(f, "#pragma GCC diagnostic ignored \"-Wunused-parameter\"\n\n");
5039#endif
5040
5041#if defined(__clang__)
5042 /* TODO(@ideasman42): ideally this workaround would not be needed,
5043 * could use some further investigation as these are intended to be declared. */
5044 fprintf(f, "#pragma GCC diagnostic ignored \"-Wmissing-variable-declarations\"\n\n");
5045#endif
5046
5047 fprintf(f, "/* Auto-generated Functions. */\n\n");
5048
5049 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5050 ds = static_cast<StructDefRNA *>(ds->cont.next))
5051 {
5052 if (!filename || ds->filename == filename) {
5055 }
5056 }
5057
5058 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5059 ds = static_cast<StructDefRNA *>(ds->cont.next))
5060 {
5061 if (!filename || ds->filename == filename) {
5063 rna_def_property_funcs(f, ds->srna, dp);
5064 }
5065 }
5066 }
5067
5068 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5069 ds = static_cast<StructDefRNA *>(ds->cont.next))
5070 {
5071 if (!filename || ds->filename == filename) {
5074 }
5075
5076 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
5077 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
5078 {
5079 rna_def_function_wrapper_funcs(f, ds, dfunc);
5080 rna_def_function_funcs(f, ds, dfunc);
5081 }
5082
5084 }
5085 }
5086
5087 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5088 ds = static_cast<StructDefRNA *>(ds->cont.next))
5089 {
5090 if (!filename || ds->filename == filename) {
5091 rna_generate_struct(brna, ds->srna, f);
5092 }
5093 }
5094
5095 if (filename && STREQ(filename, "rna_ID.cc")) {
5096 /* this is ugly, but we cannot have c files compiled for both
5097 * makesrna and blender with some build systems at the moment */
5098 fprintf(f, "#include \"rna_define.cc\"\n\n");
5099
5100 rna_generate_blender(brna, f);
5101 }
5102}
5103
5104static void rna_generate_header(BlenderRNA * /*brna*/, FILE *f)
5105{
5106 StructDefRNA *ds;
5107 StructRNA *srna;
5108 FunctionDefRNA *dfunc;
5109
5110 fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
5111 fprintf(f, "#define __RNA_BLENDER_H__\n\n");
5112
5113 fprintf(f,
5114 "/* Automatically generated function declarations for the Data API.\n"
5115 " * Do not edit manually, changes will be overwritten. */\n\n");
5116
5117 fprintf(f, "#include \"RNA_types.hh\"\n\n");
5118 fprintf(f, "#include \"DNA_node_types.h\"\n\n");
5119
5120 fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
5121 fprintf(f, " { \\\n");
5122 fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
5123 fprintf(f,
5124 " for (property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; "
5125 "property##_next(&rna_macro_iter)) { \\\n");
5126 fprintf(f, " itemptr = rna_macro_iter.ptr;\n\n");
5127
5128 fprintf(f, "#define FOREACH_END(property) \\\n");
5129 fprintf(f, " } \\\n");
5130 fprintf(f, " property##_end(&rna_macro_iter); \\\n");
5131 fprintf(f, " }\n\n");
5132
5133 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5134 ds = static_cast<StructDefRNA *>(ds->cont.next))
5135 {
5136 srna = ds->srna;
5137
5138 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
5139
5140 while (srna) {
5141 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
5142 srna = srna->base;
5143 }
5144 fprintf(f, "\n");
5145
5148 }
5149
5150 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
5151 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
5152 {
5153 rna_def_function_funcs_header(f, ds->srna, dfunc);
5154 }
5155 }
5156
5157 fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
5158}
5159
5160static const char *cpp_classes =
5161 ""
5162 "\n"
5163 "#include <stdlib.h> /* for malloc */\n"
5164 "#include <string>\n"
5165 "#include <string.h> /* for memcpy */\n"
5166 "\n"
5167 "namespace BL {\n"
5168 "\n"
5169 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
5170 " inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr) ? true: "
5171 "false; } \\\n"
5172 " inline void sname::identifier(bool value) { sname##_##identifier##_set(&ptr, value); }\n"
5173 "\n"
5174 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
5175 " inline Array<bool, size> sname::identifier(void) \\\n"
5176 " { Array<bool, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
5177 " inline void sname::identifier(bool values[size]) \\\n"
5178 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5179 "\n"
5180 "#define BOOLEAN_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
5181 " inline DynamicArray<bool> sname::identifier(void) { \\\n"
5182 " int arraylen[3]; \\\n"
5183 " int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
5184 " DynamicArray<bool> ar(len); \\\n"
5185 " sname##_##identifier##_get(&ptr, ar.data); \\\n"
5186 " return ar; } \\\n"
5187 " inline void sname::identifier(bool values[]) \\\n"
5188 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5189 "\n"
5190 "#define INT_PROPERTY(sname, identifier) \\\n"
5191 " inline int sname::identifier(void) { return sname##_##identifier##_get(&ptr); } \\\n"
5192 " inline void sname::identifier(int value) { sname##_##identifier##_set(&ptr, value); }\n"
5193 "\n"
5194 "#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
5195 " inline Array<int, size> sname::identifier(void) \\\n"
5196 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
5197 " inline void sname::identifier(int values[size]) \\\n"
5198 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5199 "\n"
5200 "#define INT_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
5201 " inline DynamicArray<int> sname::identifier(void) { \\\n"
5202 " int arraylen[3]; \\\n"
5203 " int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
5204 " DynamicArray<int> ar(len); \\\n"
5205 " sname##_##identifier##_get(&ptr, ar.data); \\\n"
5206 " return ar; } \\\n"
5207 " inline void sname::identifier(int values[]) \\\n"
5208 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5209 "\n"
5210 "#define FLOAT_PROPERTY(sname, identifier) \\\n"
5211 " inline float sname::identifier(void) { return sname##_##identifier##_get(&ptr); } \\\n"
5212 " inline void sname::identifier(float value) { sname##_##identifier##_set(&ptr, value); }\n"
5213 "\n"
5214 "#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
5215 " inline Array<float, size> sname::identifier(void) \\\n"
5216 " { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; } \\\n"
5217 " inline void sname::identifier(float values[size]) \\\n"
5218 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5219 "\n"
5220 "#define FLOAT_DYNAMIC_ARRAY_PROPERTY(sname, identifier) \\\n"
5221 " inline DynamicArray<float> sname::identifier(void) { \\\n"
5222 " int arraylen[3]; \\\n"
5223 " int len = sname##_##identifier##_get_length(&ptr, arraylen); \\\n"
5224 " DynamicArray<float> ar(len); \\\n"
5225 " sname##_##identifier##_get(&ptr, ar.data); \\\n"
5226 " return ar; } \\\n"
5227 " inline void sname::identifier(float values[]) \\\n"
5228 " { sname##_##identifier##_set(&ptr, values); } \\\n"
5229 "\n"
5230 "#define ENUM_PROPERTY(type, sname, identifier) \\\n"
5231 " inline sname::type sname::identifier(void) { return "
5232 "(type)sname##_##identifier##_get(&ptr); } \\\n"
5233 " inline void sname::identifier(sname::type value) { sname##_##identifier##_set(&ptr, "
5234 "value); }\n"
5235 "\n"
5236 "#define STRING_PROPERTY(sname, identifier) \\\n"
5237 " inline std::string sname::identifier(void) { \\\n"
5238 " int len = sname##_##identifier##_length(&ptr); \\\n"
5239 " std::string str; str.resize(len); \\\n"
5240 " sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
5241 " inline void sname::identifier(const std::string& value) { \\\n"
5242 " sname##_##identifier##_set(&ptr, value.c_str()); } \\\n"
5243 "\n"
5244 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
5245 " inline type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
5246 "\n"
5247 "#define COLLECTION_PROPERTY_LENGTH_false(sname, identifier) \\\n"
5248 " inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
5249 " { \\\n"
5250 " CollectionPropertyIterator iter; \\\n"
5251 " int length = 0; \\\n"
5252 " sname##_##identifier##_begin(&iter, ptr); \\\n"
5253 " while (iter.valid) { \\\n"
5254 " sname##_##identifier##_next(&iter); \\\n"
5255 " ++length; \\\n"
5256 " } \\\n"
5257 " sname##_##identifier##_end(&iter); \\\n"
5258 " return length; \\\n"
5259 " } \n"
5260 "#define COLLECTION_PROPERTY_LENGTH_true(sname, identifier) \\\n"
5261 " inline static int sname##_##identifier##_length_wrap(PointerRNA *ptr) \\\n"
5262 " { return sname##_##identifier##_length(ptr); } \n"
5263 "\n"
5264 "#define COLLECTION_PROPERTY_EMPTY_false(sname, identifier) \\\n"
5265 " inline static bool sname##_##identifier##_empty_wrap(PointerRNA *ptr) \\\n"
5266 " { \\\n"
5267 " CollectionPropertyIterator iter; \\\n"
5268 " sname##_##identifier##_begin(&iter, ptr); \\\n"
5269 " bool empty = !iter.valid; \\\n"
5270 " sname##_##identifier##_end(&iter); \\\n"
5271 " return empty; \\\n"
5272 " } \n"
5273 "#define COLLECTION_PROPERTY_EMPTY_true(sname, identifier) \\\n"
5274 " inline static bool sname##_##identifier##_empty_wrap(PointerRNA *ptr) \\\n"
5275 " { return sname##_##identifier##_length(ptr) == 0; } \n"
5276 "\n"
5277 "#define COLLECTION_PROPERTY_LOOKUP_INT_false(sname, identifier) \\\n"
5278 " inline static bool sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, "
5279 "PointerRNA *r_ptr) \\\n"
5280 " { \\\n"
5281 " CollectionPropertyIterator iter; \\\n"
5282 " int i = 0; \\\n"
5283 " bool found = false; \\\n"
5284 " sname##_##identifier##_begin(&iter, ptr); \\\n"
5285 " while (iter.valid) { \\\n"
5286 " if (i == key) { \\\n"
5287 " *r_ptr = iter.ptr; \\\n"
5288 " found = true; \\\n"
5289 " break; \\\n"
5290 " } \\\n"
5291 " sname##_##identifier##_next(&iter); \\\n"
5292 " ++i; \\\n"
5293 " } \\\n"
5294 " sname##_##identifier##_end(&iter); \\\n"
5295 " if (!found) { \\\n"
5296 " *r_ptr = {}; \\\n"
5297 " } \\\n"
5298 " return found; \\\n"
5299 " } \n"
5300 "#define COLLECTION_PROPERTY_LOOKUP_INT_true(sname, identifier) \\\n"
5301 " inline static bool sname##_##identifier##_lookup_int_wrap(PointerRNA *ptr, int key, "
5302 "PointerRNA *r_ptr) \\\n"
5303 " { \\\n"
5304 " bool found = sname##_##identifier##_lookup_int(ptr, key, r_ptr); \\\n"
5305 " if (!found) { \\\n"
5306 " *r_ptr = {}; \\\n"
5307 " } \\\n"
5308 " return found; \\\n"
5309 " } \n"
5310 "#define COLLECTION_PROPERTY_LOOKUP_STRING_false(sname, identifier) \\\n"
5311 " inline static bool sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char "
5312 "*key, PointerRNA *r_ptr) \\\n"
5313 " { \\\n"
5314 " CollectionPropertyIterator iter; \\\n"
5315 " bool found = false; \\\n"
5316 " PropertyRNA *item_name_prop = RNA_struct_name_property(ptr->type); \\\n"
5317 " sname##_##identifier##_begin(&iter, ptr); \\\n"
5318 " while (iter.valid && !found) { \\\n"
5319 " char name_fixed[32]; \\\n"
5320 " const char *name; \\\n"
5321 " int name_length; \\\n"
5322 " name = RNA_property_string_get_alloc(&iter.ptr, item_name_prop, name_fixed, "
5323 "sizeof(name_fixed), &name_length); \\\n"
5324 " if (!strncmp(name, key, name_length)) { \\\n"
5325 " *r_ptr = iter.ptr; \\\n"
5326 " found = true; \\\n"
5327 " } \\\n"
5328 " if (name_fixed != name) { \\\n"
5329 " MEM_freeN( name); \\\n"
5330 " } \\\n"
5331 " sname##_##identifier##_next(&iter); \\\n"
5332 " } \\\n"
5333 " sname##_##identifier##_end(&iter); \\\n"
5334 " if (!found) { \\\n"
5335 " *r_ptr = {}; \\\n"
5336 " } \\\n"
5337 " return found; \\\n"
5338 " } \n"
5339 "#define COLLECTION_PROPERTY_LOOKUP_STRING_true(sname, identifier) \\\n"
5340 " inline static bool sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char "
5341 "*key, PointerRNA *r_ptr) \\\n"
5342 " { \\\n"
5343 " bool found = sname##_##identifier##_lookup_string(ptr, key, r_ptr); \\\n"
5344 " if (!found) { \\\n"
5345 " *r_ptr = {}; \\\n"
5346 " } \\\n"
5347 " return found; \\\n"
5348 " } \n"
5349 "#define COLLECTION_PROPERTY(collection_funcs, type, sname, identifier, has_length, "
5350 "has_lookup_int, has_lookup_string) \\\n"
5351 " typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
5352 " sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
5353 " COLLECTION_PROPERTY_LENGTH_##has_length(sname, identifier) \\\n"
5354 " COLLECTION_PROPERTY_EMPTY_##has_length(sname, identifier) \\\n"
5355 " COLLECTION_PROPERTY_LOOKUP_INT_##has_lookup_int(sname, identifier) \\\n"
5356 " COLLECTION_PROPERTY_LOOKUP_STRING_##has_lookup_string(sname, identifier) \\\n"
5357 " CollectionRef<sname, type, sname##_##identifier##_begin, \\\n"
5358 " sname##_##identifier##_next, sname##_##identifier##_end, \\\n"
5359 " sname##_##identifier##_length_wrap, \\\n"
5360 " sname##_##identifier##_empty_wrap, \\\n"
5361 " sname##_##identifier##_lookup_int_wrap, sname##_##identifier##_lookup_string_wrap, "
5362 "collection_funcs> identifier;\n"
5363 "\n"
5364 "class Pointer {\n"
5365 "public:\n"
5366 " Pointer(const PointerRNA &p) : ptr(p) { }\n"
5367 " operator const PointerRNA&() { return ptr; }\n"
5368 " bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type) ? true: false; }\n"
5369 " operator void*() { return ptr.data; }\n"
5370 " operator bool() const { return ptr.data != nullptr; }\n"
5371 "\n"
5372 " bool operator==(const Pointer &other) const { return ptr.data == other.ptr.data; }\n"
5373 " bool operator!=(const Pointer &other) const { return ptr.data != other.ptr.data; }\n"
5374 " bool operator<(const Pointer &other) const { return ptr.data < other.ptr.data; }\n"
5375 "\n"
5376 " PointerRNA ptr;\n"
5377 "};\n"
5378 "\n"
5379 "\n"
5380 "template<typename T, int Tsize>\n"
5381 "class Array {\n"
5382 "public:\n"
5383 " T data[Tsize];\n"
5384 "\n"
5385 " Array() {}\n"
5386 " Array(const Array<T, Tsize>& other) { memcpy(data, other.data, sizeof(T) * Tsize); }\n"
5387 " const Array<T, Tsize>& operator = (const Array<T, Tsize>& other) { memcpy(data, "
5388 "other.data, sizeof(T) * Tsize); "
5389 "return *this; }\n"
5390 "\n"
5391 " operator T*() { return data; }\n"
5392 " operator const T*() const { return data; }\n"
5393 "};\n"
5394 "\n"
5395 "template<typename T>\n"
5396 "class DynamicArray {\n"
5397 "public:\n"
5398 " T *data;\n"
5399 " int length;\n"
5400 "\n"
5401 " DynamicArray() : data(nullptr), length(0) {}\n"
5402 " DynamicArray(int new_length) : data(nullptr), length(new_length) { data = (T "
5403 "*)malloc(sizeof(T) * new_length); }\n"
5404 " DynamicArray(const DynamicArray<T>& other) : data(nullptr), length(0) { "
5405 "copy_from(other); "
5406 "}\n"
5407 " const DynamicArray<T>& operator = (const DynamicArray<T>& other) { copy_from(other); "
5408 "return *this; }\n"
5409 "\n"
5410 " ~DynamicArray() { if (data) free(data); }\n"
5411 "\n"
5412 " operator T*() { return data; }\n"
5413 "\n"
5414 "protected:\n"
5415 " void copy_from(const DynamicArray<T>& other) {\n"
5416 " if (data) free(data);\n"
5417 " data = (T *)malloc(sizeof(T) * other.length);\n"
5418 " memcpy(data, other.data, sizeof(T) * other.length);\n"
5419 " length = other.length;\n"
5420 " }\n"
5421 "};\n"
5422 "\n"
5423 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
5424 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
5425 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
5426 "typedef int (*TLengthFunc)(PointerRNA *ptr);\n"
5427 "typedef bool (*TEmptyFunc)(PointerRNA *ptr);\n"
5428 "typedef bool (*TLookupIntFunc)(PointerRNA *ptr, int key, PointerRNA *r_ptr);\n"
5429 "typedef bool (*TLookupStringFunc)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr);\n"
5430 "\n"
5431 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
5432 "class CollectionIterator {\n"
5433 "public:\n"
5434 " CollectionIterator() : iter(), t(iter.ptr), init(false) { iter.valid = false; }\n"
5435 " CollectionIterator(const PointerRNA &ptr) : CollectionIterator() { this->begin(ptr); }\n"
5436 " ~CollectionIterator(void) { if (init) Tend(&iter); };\n"
5437 "\n"
5438 " CollectionIterator(const CollectionIterator &other) = delete;\n"
5439 " CollectionIterator(CollectionIterator &&other) = delete;\n"
5440 " CollectionIterator &operator=(const CollectionIterator &other) = delete;\n"
5441 " CollectionIterator &operator=(CollectionIterator &&other) = delete;\n"
5442 "\n"
5443 " operator bool(void) const\n"
5444 " { return iter.valid != 0; }\n"
5445 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = "
5446 "T(iter.ptr); return *this; }\n"
5447 "\n"
5448 " T& operator*(void) { return t; }\n"
5449 " T* operator->(void) { return &t; }\n"
5450 " bool operator == (const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
5451 "{ return iter.valid == other.iter.valid; }\n"
5452 " bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) "
5453 "{ return iter.valid != other.iter.valid; }\n"
5454 "\n"
5455 " void begin(const Pointer &ptr)\n"
5456 " { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA *)&ptr.ptr); t = T(iter.ptr); init = "
5457 "true; }\n"
5458 "\n"
5459 "private:\n"
5460 " CollectionPropertyIterator iter;\n"
5461 " T t;\n"
5462 " bool init;\n"
5463 "};\n"
5464 "\n"
5465 "template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend,\n"
5466 " TLengthFunc Tlength, TEmptyFunc Tempty, TLookupIntFunc Tlookup_int,\n"
5467 " TLookupStringFunc Tlookup_string, typename Tcollection_funcs>\n"
5468 "class CollectionRef : public Tcollection_funcs {\n"
5469 "public:\n"
5470 " CollectionRef(const PointerRNA &p) : Tcollection_funcs(p), ptr(p) {}\n"
5471 "\n"
5472 " void begin(CollectionIterator<T, Tbegin, Tnext, Tend>& iter)\n"
5473 " { iter.begin(ptr); }\n"
5474 " CollectionIterator<T, Tbegin, Tnext, Tend> begin()\n"
5475 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(ptr); }\n"
5476 " CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
5477 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
5478 ""
5479 " int length()\n"
5480 " { return Tlength(&ptr); }\n"
5481 " bool empty()\n"
5482 " { return Tempty(&ptr); }\n"
5483 " T operator[](int key)\n"
5484 " { PointerRNA r_ptr; Tlookup_int(&ptr, key, &r_ptr); return T(r_ptr); }\n"
5485 " T operator[](const std::string &key)\n"
5486 " { PointerRNA r_ptr; Tlookup_string(&ptr, key.c_str(), &r_ptr); return T(r_ptr); }\n"
5487 "\n"
5488 "private:\n"
5489 " PointerRNA ptr;\n"
5490 "};\n"
5491 "\n"
5492 "class DefaultCollectionFunctions {\n"
5493 "public:\n"
5494 " DefaultCollectionFunctions(const PointerRNA & /*p*/) {}\n"
5495 "};\n"
5496 "\n"
5497 "\n";
5498
5500{
5501 if (!(prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN)) {
5502 if (prop->type == PROP_COLLECTION) {
5503 return true;
5504 }
5505 }
5506
5507 return false;
5508}
5509
5510static bool rna_is_collection_functions_struct(const char **collection_structs,
5511 const char *struct_name)
5512{
5513 int a = 0;
5514 bool found = false;
5515
5516 while (collection_structs[a]) {
5517 if (STREQ(collection_structs[a], struct_name)) {
5518 found = true;
5519 break;
5520 }
5521 a++;
5522 }
5523
5524 return found;
5525}
5526
5528{
5529 StructRNA *srna = ds->srna;
5530 FunctionDefRNA *dfunc;
5531
5532 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
5533
5534 fprintf(f,
5535 "class %s : public %s {\n",
5536 srna->identifier,
5537 (srna->base) ? srna->base->identifier : "Pointer");
5538 fprintf(f, "public:\n");
5539 fprintf(f,
5540 "\t%s(const PointerRNA &ptr_arg) :\n\t\t%s(ptr_arg)",
5541 srna->identifier,
5542 (srna->base) ? srna->base->identifier : "Pointer");
5544 if (rna_is_collection_prop(dp->prop)) {
5545 fprintf(f, ",\n\t\t%s(ptr_arg)", dp->prop->identifier);
5546 }
5547 }
5548 fprintf(f, "\n\t\t{}\n\n");
5549
5552 }
5553
5554 fprintf(f, "\n");
5555 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
5556 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
5557 {
5558 rna_def_struct_function_header_cpp(f, srna, dfunc);
5559 }
5560
5561 fprintf(f, "};\n\n");
5562}
5563
5564static void rna_generate_header_cpp(BlenderRNA * /*brna*/, FILE *f)
5565{
5566 StructDefRNA *ds;
5567 StructRNA *srna;
5568 FunctionDefRNA *dfunc;
5569 const char *first_collection_func_struct = nullptr;
5570 const char *collection_func_structs[256] = {nullptr};
5571 int all_collection_func_structs = 0;
5572 int max_collection_func_structs = sizeof(collection_func_structs) /
5573 sizeof(collection_func_structs[0]) -
5574 1;
5575
5576 fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
5577 fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
5578
5579 fprintf(f,
5580 "/* Automatically generated classes for the Data API.\n"
5581 " * Do not edit manually, changes will be overwritten. */\n\n");
5582
5583 fprintf(f, "#include \"RNA_blender.hh\"\n");
5584 fprintf(f, "#include \"RNA_types.hh\"\n");
5585 fprintf(f, "#include \"RNA_access.hh\"\n");
5586 fprintf(f, "#include \"DNA_node_types.h\"\n");
5587
5588 fprintf(f, "%s", cpp_classes);
5589
5590 fprintf(f, "/**************** Declarations ****************/\n\n");
5591
5592 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5593 ds = static_cast<StructDefRNA *>(ds->cont.next))
5594 {
5595 fprintf(f, "class %s;\n", ds->srna->identifier);
5596 }
5597 fprintf(f, "\n");
5598
5599 /* first get list of all structures used as collection functions, so they'll be declared first */
5600 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5601 ds = static_cast<StructDefRNA *>(ds->cont.next))
5602 {
5604 if (rna_is_collection_prop(dp->prop)) {
5605 PropertyRNA *prop = dp->prop;
5606
5607 if (prop->srna) {
5608 /* store name of structure which first uses custom functions for collections */
5609 if (first_collection_func_struct == nullptr) {
5610 first_collection_func_struct = ds->srna->identifier;
5611 }
5612
5613 if (!rna_is_collection_functions_struct(collection_func_structs, (char *)prop->srna)) {
5614 if (all_collection_func_structs >= max_collection_func_structs) {
5615 printf("Array size to store all collection structures names is too small\n");
5616 exit(1);
5617 }
5618
5619 collection_func_structs[all_collection_func_structs++] = (char *)prop->srna;
5620 }
5621 }
5622 }
5623 }
5624 }
5625
5626 /* declare all structures in such order:
5627 * - first N structures which doesn't use custom functions for collections
5628 * - all structures used for custom functions in collections
5629 * - all the rest structures
5630 * such an order prevents usage of non-declared classes
5631 */
5632 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5633 ds = static_cast<StructDefRNA *>(ds->cont.next))
5634 {
5635 srna = ds->srna;
5636
5637 if (STREQ(srna->identifier, first_collection_func_struct)) {
5638 StructDefRNA *ds2;
5639 StructRNA *srna2;
5640
5641 for (ds2 = static_cast<StructDefRNA *>(DefRNA.structs.first); ds2;
5642 ds2 = static_cast<StructDefRNA *>(ds2->cont.next))
5643 {
5644 srna2 = ds2->srna;
5645
5646 if (rna_is_collection_functions_struct(collection_func_structs, srna2->identifier)) {
5648 }
5649 }
5650 }
5651
5652 if (!rna_is_collection_functions_struct(collection_func_structs, srna->identifier)) {
5654 }
5655 }
5656
5657 fprintf(f, "} /* namespace BL */\n");
5658
5659 fprintf(f, "\n");
5660 fprintf(f, "/**************** Implementation ****************/\n");
5661 fprintf(f, "\n");
5662
5663 fprintf(f, "/* Structure prototypes */\n\n");
5665
5666 fprintf(f, "namespace BL {\n");
5667
5668 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5669 ds = static_cast<StructDefRNA *>(ds->cont.next))
5670 {
5671 srna = ds->srna;
5672
5675 }
5676
5677 fprintf(f, "\n");
5678
5679 for (dfunc = static_cast<FunctionDefRNA *>(ds->functions.first); dfunc;
5680 dfunc = static_cast<FunctionDefRNA *>(dfunc->cont.next))
5681 {
5682 rna_def_struct_function_impl_cpp(f, srna, dfunc);
5683 }
5684
5685 fprintf(f, "\n");
5686 }
5687
5688 fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
5689}
5690
5691static void make_bad_file(const char *file, int line)
5692{
5693 FILE *fp = fopen(file, "w");
5694 fprintf(fp,
5695 "#error \"Error! cannot make correct RNA file from %s:%d, "
5696 "check DNA properties.\"\n",
5697 __FILE__,
5698 line);
5699 fclose(fp);
5700}
5701
5706static int rna_preprocess(const char *outfile, const char *public_header_outfile)
5707{
5708 BlenderRNA *brna;
5709 StructDefRNA *ds;
5710 FILE *file;
5711 char deffile[4096];
5712 int i;
5713 /* The exit code (returned from this function). */
5714 int status = EXIT_SUCCESS;
5715 const char *deps[3]; /* expand as needed */
5716
5717 if (!public_header_outfile) {
5718 public_header_outfile = outfile;
5719 }
5720
5721 /* define rna */
5722 brna = RNA_create();
5723
5724 for (i = 0; PROCESS_ITEMS[i].filename; i++) {
5725 if (PROCESS_ITEMS[i].define) {
5726 PROCESS_ITEMS[i].define(brna);
5727
5728 /* sanity check */
5729 if (!DefRNA.animate) {
5730 fprintf(stderr, "Error: DefRNA.animate left disabled in %s\n", PROCESS_ITEMS[i].filename);
5731 }
5732
5733 for (ds = static_cast<StructDefRNA *>(DefRNA.structs.first); ds;
5734 ds = static_cast<StructDefRNA *>(ds->cont.next))
5735 {
5736 if (!ds->filename) {
5737 ds->filename = PROCESS_ITEMS[i].filename;
5738 }
5739 }
5740 }
5741 }
5742
5743 rna_sanity_checks();
5744 if (DefRNA.error) {
5745 status = EXIT_FAILURE;
5746 }
5747
5749 if (DefRNA.error) {
5750 status = EXIT_FAILURE;
5751 }
5752
5753 /* Create external rna struct prototype header file RNA_prototypes.hh. */
5754 SNPRINTF(deffile, "%s%s", public_header_outfile, "RNA_prototypes.hh" TMP_EXT);
5755 if (status != EXIT_SUCCESS) {
5756 make_bad_file(deffile, __LINE__);
5757 }
5758 file = fopen(deffile, "w");
5759 if (!file) {
5760 fprintf(stderr, "Unable to open file: %s\n", deffile);
5761 status = EXIT_FAILURE;
5762 }
5763 else {
5764 fprintf(file,
5765 "/* Automatically generated RNA property declarations, to statically reference \n"
5766 " * properties as `rna_[struct-name]_[property-name]`.\n"
5767 " *\n"
5768 " * DO NOT EDIT MANUALLY, changes will be overwritten.\n"
5769 " */\n\n");
5770
5771 fprintf(file, "#pragma once\n\n");
5773 fclose(file);
5774 if (DefRNA.error) {
5775 status = EXIT_FAILURE;
5776 }
5777 replace_if_different(deffile, nullptr);
5778 }
5779
5780 /* create internal rna struct prototype header file */
5781 SNPRINTF(deffile, "%s%s", outfile, "rna_prototypes_gen.hh" TMP_EXT);
5782 if (status != EXIT_SUCCESS) {
5783 make_bad_file(deffile, __LINE__);
5784 }
5785 file = fopen(deffile, "w");
5786 if (!file) {
5787 fprintf(stderr, "Unable to open file: %s\n", deffile);
5788 status = EXIT_FAILURE;
5789 }
5790 else {
5791 fprintf(file,
5792 "/* Automatically generated function declarations for the Data API.\n"
5793 " * Do not edit manually, changes will be overwritten. */\n\n");
5795 fclose(file);
5796 replace_if_different(deffile, nullptr);
5797 if (DefRNA.error) {
5798 status = EXIT_FAILURE;
5799 }
5800 }
5801
5802 /* Create `rna_gen_*.c` & `rna_gen_*.cc` files. */
5803 for (i = 0; PROCESS_ITEMS[i].filename; i++) {
5804 const bool is_cc = BLI_str_endswith(PROCESS_ITEMS[i].filename, ".cc");
5805 const int ext_len = is_cc ? 3 : 2;
5806 const int filename_len = strlen(PROCESS_ITEMS[i].filename);
5807 SNPRINTF(deffile,
5808 "%s%.*s%s" TMP_EXT,
5809 outfile,
5810 (filename_len - ext_len),
5811 PROCESS_ITEMS[i].filename,
5812 is_cc ? "_gen.cc" : "_gen.c");
5813 if (status != EXIT_SUCCESS) {
5814 make_bad_file(deffile, __LINE__);
5815 }
5816 else {
5817 file = fopen(deffile, "w");
5818
5819 if (!file) {
5820 fprintf(stderr, "Unable to open file: %s\n", deffile);
5821 status = EXIT_FAILURE;
5822 }
5823 else {
5824 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
5825 fclose(file);
5826 if (DefRNA.error) {
5827 status = EXIT_FAILURE;
5828 }
5829 }
5830 }
5831
5832 /* avoid unneeded rebuilds */
5833 deps[0] = PROCESS_ITEMS[i].filename;
5834 deps[1] = PROCESS_ITEMS[i].api_filename;
5835 deps[2] = nullptr;
5836
5837 replace_if_different(deffile, deps);
5838 }
5839
5840 /* Create `RNA_blender_cpp.hh`. */
5841 SNPRINTF(deffile, "%s%s", outfile, "RNA_blender_cpp.hh" TMP_EXT);
5842
5843 if (status != EXIT_SUCCESS) {
5844 make_bad_file(deffile, __LINE__);
5845 }
5846 else {
5847 file = fopen(deffile, "w");
5848
5849 if (!file) {
5850 fprintf(stderr, "Unable to open file: %s\n", deffile);
5851 status = EXIT_FAILURE;
5852 }
5853 else {
5854 rna_generate_header_cpp(brna, file);
5855 fclose(file);
5856 if (DefRNA.error) {
5857 status = EXIT_FAILURE;
5858 }
5859 }
5860 }
5861
5862 replace_if_different(deffile, nullptr);
5863
5864 rna_sort(brna);
5865
5866 /* Create `RNA_blender.hh`. */
5867 SNPRINTF(deffile, "%s%s", outfile, "RNA_blender.hh" TMP_EXT);
5868
5869 if (status != EXIT_SUCCESS) {
5870 make_bad_file(deffile, __LINE__);
5871 }
5872 else {
5873 file = fopen(deffile, "w");
5874
5875 if (!file) {
5876 fprintf(stderr, "Unable to open file: %s\n", deffile);
5877 status = EXIT_FAILURE;
5878 }
5879 else {
5880 rna_generate_header(brna, file);
5881 fclose(file);
5882 if (DefRNA.error) {
5883 status = EXIT_FAILURE;
5884 }
5885 }
5886 }
5887
5888 replace_if_different(deffile, nullptr);
5889
5890 /* free RNA */
5891 RNA_define_free(brna);
5892 RNA_free(brna);
5893
5894 return status;
5895}
5896
5897static void mem_error_cb(const char *errorStr)
5898{
5899 fprintf(stderr, "%s", errorStr);
5900 fflush(stderr);
5901}
5902
5903int main(int argc, char **argv)
5904{
5905 int return_status = EXIT_SUCCESS;
5906
5909
5910 CLG_init();
5911
5912 /* Some useful defaults since this runs standalone. */
5915
5916 if (argc < 2) {
5917 fprintf(stderr, "Usage: %s outdirectory [public header outdirectory]/\n", argv[0]);
5918 return_status = EXIT_FAILURE;
5919 }
5920 else {
5921 if (debugSRNA > 0) {
5922 fprintf(stderr, "Running makesrna\n");
5923 }
5924 makesrna_path = argv[0];
5925 return_status = rna_preprocess(argv[1], (argc > 2) ? argv[2] : nullptr);
5926 }
5927
5928 CLG_exit();
5929
5930 return return_status;
5931}
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
#define LISTBASE_FOREACH(type, var, list)
ATTR_WARN_UNUSED_RESULT const size_t num
int bool BLI_str_startswith(const char *__restrict str, const char *__restrict start) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
#define STR_ELEM(...)
Definition BLI_string.h:661
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:604
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
size_t BLI_snprintf(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
unsigned int uint
#define ARRAY_SIZE(arr)
#define UNUSED_VARS_NDEBUG(...)
#define ELEM(...)
#define STREQ(a, b)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
void CLG_output_use_basename_set(int value)
Definition clog.cc:895
void CLG_exit()
Definition clog.cc:880
void CLG_level_set(CLG_Level level)
Definition clog.cc:935
@ CLG_LEVEL_DEBUG
Definition CLG_log.h:62
@ CLG_LEVEL_WARN
Definition CLG_log.h:58
void CLG_init()
Definition clog.cc:873
Read Guarded memory(de)allocation.
#define IS_DNATYPE_BOOLEAN_COMPAT(_str)
#define IS_DNATYPE_FLOAT_COMPAT(_str)
#define IS_DNATYPE_INT_COMPAT(_str)
@ PARM_RNAPTR
Definition RNA_types.hh:547
@ PARM_OUTPUT
Definition RNA_types.hh:546
PropertyScaleType
Definition RNA_types.hh:203
@ PROP_SCALE_LOG
Definition RNA_types.hh:210
@ PROP_SCALE_LINEAR
Definition RNA_types.hh:205
@ PROP_SCALE_CUBIC
Definition RNA_types.hh:215
@ FUNC_USE_REPORTS
Definition RNA_types.hh:914
@ FUNC_USE_SELF_TYPE
Definition RNA_types.hh:909
@ FUNC_NO_SELF
Definition RNA_types.hh:907
@ FUNC_USE_MAIN
Definition RNA_types.hh:912
@ FUNC_SELF_AS_RNA
Definition RNA_types.hh:900
@ FUNC_USE_CONTEXT
Definition RNA_types.hh:913
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:889
@ STRUCT_ID_REFCOUNT
Definition RNA_types.hh:959
@ STRUCT_ID
Definition RNA_types.hh:953
PropertyType
Definition RNA_types.hh:161
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_ENUM
Definition RNA_types.hh:166
@ PROP_INT
Definition RNA_types.hh:163
@ PROP_STRING
Definition RNA_types.hh:165
@ PROP_POINTER
Definition RNA_types.hh:167
@ PROP_COLLECTION
Definition RNA_types.hh:168
void(*)(const bContext *C, PointerRNA *ptr, PropertyRNA *prop, const char *edit_text, blender::FunctionRef< void(StringPropertySearchVisitParams)> visit_fn) StringPropertySearchFunc
Definition RNA_types.hh:806
@ PROP_UNIT_VOLUME
Definition RNA_types.hh:176
@ PROP_UNIT_POWER
Definition RNA_types.hh:184
@ PROP_UNIT_ROTATION
Definition RNA_types.hh:178
@ PROP_UNIT_FREQUENCY
Definition RNA_types.hh:188
@ PROP_UNIT_WAVELENGTH
Definition RNA_types.hh:186
@ PROP_UNIT_VELOCITY
Definition RNA_types.hh:181
@ PROP_UNIT_LENGTH
Definition RNA_types.hh:174
@ PROP_UNIT_NONE
Definition RNA_types.hh:173
@ PROP_UNIT_ACCELERATION
Definition RNA_types.hh:182
@ PROP_UNIT_AREA
Definition RNA_types.hh:175
@ PROP_UNIT_TIME
Definition RNA_types.hh:179
@ PROP_UNIT_CAMERA
Definition RNA_types.hh:183
@ PROP_UNIT_TEMPERATURE
Definition RNA_types.hh:185
@ PROP_UNIT_MASS
Definition RNA_types.hh:177
@ PROP_UNIT_TIME_ABSOLUTE
Definition RNA_types.hh:180
@ PROP_UNIT_COLOR_TEMPERATURE
Definition RNA_types.hh:187
#define RNA_SUBTYPE_UNIT(subtype)
Definition RNA_types.hh:218
@ PROP_RAW_INT8
Definition RNA_types.hh:634
@ PROP_RAW_UINT64
Definition RNA_types.hh:633
@ PROP_RAW_INT
Definition RNA_types.hh:624
@ PROP_RAW_INT64
Definition RNA_types.hh:632
@ PROP_RAW_BOOLEAN
Definition RNA_types.hh:627
@ PROP_RAW_CHAR
Definition RNA_types.hh:626
@ PROP_RAW_FLOAT
Definition RNA_types.hh:629
@ PROP_RAW_DOUBLE
Definition RNA_types.hh:628
@ PROP_RAW_UINT8
Definition RNA_types.hh:630
@ PROP_RAW_UINT16
Definition RNA_types.hh:631
@ PROP_RAW_SHORT
Definition RNA_types.hh:625
@ PROP_THICK_WRAP
Definition RNA_types.hh:423
@ PROP_DYNAMIC
Definition RNA_types.hh:428
@ PROP_CONTEXT_UPDATE
Definition RNA_types.hh:407
@ PROP_EDITABLE
Definition RNA_types.hh:306
@ PROP_ENUM_FLAG
Definition RNA_types.hh:404
@ PROP_PTR_NO_OWNERSHIP
Definition RNA_types.hh:395
@ PROP_ID_SELF_CHECK
Definition RNA_types.hh:370
@ PROP_ID_REFCOUNT
Definition RNA_types.hh:364
@ PROP_IDPROPERTY
Definition RNA_types.hh:426
PropertySubType
Definition RNA_types.hh:232
@ PROP_TIME
Definition RNA_types.hh:253
@ PROP_MATRIX
Definition RNA_types.hh:265
@ PROP_DIRECTION
Definition RNA_types.hh:262
@ PROP_XYZ
Definition RNA_types.hh:269
@ PROP_DISTANCE
Definition RNA_types.hh:256
@ PROP_ACCELERATION
Definition RNA_types.hh:264
@ PROP_TEMPERATURE
Definition RNA_types.hh:284
@ PROP_BYTESTRING
Definition RNA_types.hh:240
@ PROP_POWER
Definition RNA_types.hh:281
@ PROP_LAYER_MEMBER
Definition RNA_types.hh:278
@ PROP_FILENAME
Definition RNA_types.hh:238
@ PROP_PASSWORD
Definition RNA_types.hh:243
@ PROP_COLOR
Definition RNA_types.hh:260
@ PROP_PIXEL
Definition RNA_types.hh:248
@ PROP_ANGLE
Definition RNA_types.hh:252
@ PROP_TIME_ABSOLUTE
Definition RNA_types.hh:254
@ PROP_DISTANCE_CAMERA
Definition RNA_types.hh:257
@ PROP_AXISANGLE
Definition RNA_types.hh:268
@ PROP_PIXEL_DIAMETER
Definition RNA_types.hh:293
@ PROP_EULER
Definition RNA_types.hh:266
@ PROP_COORDS
Definition RNA_types.hh:274
@ PROP_COLOR_TEMPERATURE
Definition RNA_types.hh:290
@ PROP_NONE
Definition RNA_types.hh:233
@ PROP_DIRPATH
Definition RNA_types.hh:237
@ PROP_PERCENTAGE
Definition RNA_types.hh:250
@ PROP_FREQUENCY
Definition RNA_types.hh:292
@ PROP_FACTOR
Definition RNA_types.hh:251
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:272
@ PROP_TRANSLATION
Definition RNA_types.hh:261
@ PROP_UNSIGNED
Definition RNA_types.hh:249
@ PROP_LAYER
Definition RNA_types.hh:277
@ PROP_QUATERNION
Definition RNA_types.hh:267
@ PROP_FILEPATH
Definition RNA_types.hh:236
@ PROP_VELOCITY
Definition RNA_types.hh:263
@ PROP_DISTANCE_DIAMETER
Definition RNA_types.hh:294
@ PROP_WAVELENGTH
Definition RNA_types.hh:287
long long int int64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define str(s)
#define INT64_MIN
#define INT64_MAX
#define main()
#define printf(...)
#define PRId64
Definition inttypes.h:78
void MEM_init_memleak_detection()
#define LOG(level)
Definition log.h:97
static void rna_def_struct_function_header_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
Definition makesrna.cc:2770
static char * rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1961
static char * rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc, const char *nextfunc)
Definition makesrna.cc:1677
static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
Definition makesrna.cc:402
static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
Definition makesrna.cc:3160
void * rna_calloc(int buffer_size)
Definition makesrna.cc:448
static StructRNA * rna_find_struct(const char *identifier)
Definition makesrna.cc:465
static void rna_auto_types()
Definition makesrna.cc:3510
static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
Definition makesrna.cc:1097
static const char * rna_type_type(PropertyRNA *prop)
Definition makesrna.cc:538
static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
Definition makesrna.cc:2042
static bool rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
Definition makesrna.cc:612
static void rna_generate_header_cpp(BlenderRNA *, FILE *f)
Definition makesrna.cc:5564
static char * rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:698
static char * rna_def_property_search_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1152
static void rna_print_c_string(FILE *f, const char *str)
Definition makesrna.cc:373
static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
Definition makesrna.cc:2034
static void rna_print_id_get(FILE *f, PropertyDefRNA *)
Definition makesrna.cc:417
static int replace_if_different(const char *tmpfile, const char *dep_files[])
Definition makesrna.cc:119
static bool file_older(const char *file1, const char *file2)
Definition makesrna.cc:58
static void rna_float_print(FILE *f, float num)
Definition makesrna.cc:640
static const char * rna_type_struct(PropertyRNA *prop)
Definition makesrna.cc:551
static RNAProcessItem PROCESS_ITEMS[]
Definition makesrna.cc:4899
static void rna_generate_header(BlenderRNA *, FILE *f)
Definition makesrna.cc:5104
static const char * rna_find_dna_type(const char *type)
Definition makesrna.cc:495
static const char * cpp_classes
Definition makesrna.cc:5160
static bool rna_is_collection_functions_struct(const char **collection_structs, const char *struct_name)
Definition makesrna.cc:5510
static void mem_error_cb(const char *errorStr)
Definition makesrna.cc:5897
static char * rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1181
static int rna_enum_bitmask(PropertyRNA *prop)
Definition makesrna.cc:591
static void rna_generate_header_class_cpp(StructDefRNA *ds, FILE *f)
Definition makesrna.cc:5527
static const char * rna_ui_scale_type_string(const PropertyScaleType type)
Definition makesrna.cc:662
static void rna_generate_blender(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:3755
static void rna_def_struct_function_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
Definition makesrna.cc:3018
static const char * rna_safe_id(const char *id)
Definition makesrna.cc:273
static int cmp_def_struct(const void *a, const void *b)
Definition makesrna.cc:324
static void rna_def_struct_function_call_impl_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
Definition makesrna.cc:2915
static void rna_generate_static_function_prototypes(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:4057
static void rna_def_function_wrapper_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
Definition makesrna.cc:3087
static const char * rna_property_subtypename(PropertySubType type)
Definition makesrna.cc:3618
static char * rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1597
static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
Definition makesrna.cc:4139
static void rna_sort(BlenderRNA *brna)
Definition makesrna.cc:3575
void BLI_system_backtrace(FILE *fp)
Definition makesrna.cc:47
static void rna_def_function_funcs_header(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc)
Definition makesrna.cc:2481
static void rna_clamp_value_range(FILE *f, PropertyRNA *prop)
Definition makesrna.cc:1036
#define WRITE_PARAM(param)
Definition makesrna.cc:109
static const char * path_basename(const char *path)
Definition makesrna.cc:76
static void rna_generate_parameter_prototypes(BlenderRNA *, StructRNA *srna, FunctionRNA *func, FILE *f)
Definition makesrna.cc:3830
static void rna_generate_struct_rna_prototypes(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:3743
static void rna_generate_static_parameter_prototypes(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc, const char *name_override, int close_prototype)
Definition makesrna.cc:3883
static int cmp_def_property(const void *a, const void *b)
Definition makesrna.cc:332
static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
Definition makesrna.cc:2491
static const char * rna_find_type(const char *type)
Definition makesrna.cc:480
#define WRITE_COMMA
Definition makesrna.cc:100
static const char * rna_parameter_type_name(PropertyRNA *parm)
Definition makesrna.cc:564
static const char * rna_type_type_name(PropertyRNA *prop)
Definition makesrna.cc:510
static const char * makesrna_path
Definition makesrna.cc:74
static void rna_generate_external_property_prototypes(BlenderRNA *brna, FILE *f)
Definition makesrna.cc:3784
static char * rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
Definition makesrna.cc:1511
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:1817
static int cmp_property(const void *a, const void *b)
Definition makesrna.cc:302
static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
Definition makesrna.cc:3850
static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
Definition makesrna.cc:2340
static int debugSRNA
Definition makesrna.cc:43
static void rna_construct_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
Definition makesrna.cc:422
static void rna_int_print(FILE *f, int64_t num)
Definition makesrna.cc:676
static void rna_sortlist(ListBase *listbase, int(*cmp)(const void *, const void *))
Definition makesrna.cc:340
static const char * rna_property_subtype_unit(PropertySubType type)
Definition makesrna.cc:3703
static void rna_generate_struct_prototypes(FILE *f)
Definition makesrna.cc:4089
static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const char *api_filename)
Definition makesrna.cc:4982
#define REN_IF_DIFF
static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *, FunctionDefRNA *dfunc, const char *cpp_namespace, int close_prototype)
Definition makesrna.cc:2675
static void rna_def_property_wrapper_funcs(FILE *f, StructDefRNA *dsrna, PropertyDefRNA *dp)
Definition makesrna.cc:3074
static void rna_generate_struct(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:4697
#define TMP_EXT
Definition makesrna.cc:54
static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
Definition makesrna.cc:2783
static const char * rna_parameter_type_cpp_name(PropertyRNA *prop)
Definition makesrna.cc:2664
static char * rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *, const char *manualfunc)
Definition makesrna.cc:1930
static int cmp_struct(const void *a, const void *b)
Definition makesrna.cc:294
void * rna_alloc_from_buffer(const char *buffer, int buffer_size)
Definition makesrna.cc:439
static bool rna_is_collection_prop(PropertyRNA *prop)
Definition makesrna.cc:5499
static const char * rna_property_structname(PropertyType type)
Definition makesrna.cc:3596
static char * rna_alloc_function_name(const char *structname, const char *propname, const char *type)
Definition makesrna.cc:456
static bool rna_parameter_is_const(const PropertyDefRNA *dparm)
Definition makesrna.cc:607
static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
Definition makesrna.cc:1983
static void rna_construct_wrapper_function_name(char *buffer, int size, const char *structname, const char *propname, const char *type)
Definition makesrna.cc:428
static const char * rna_function_string(T *func)
Definition makesrna.cc:635
static void make_bad_file(const char *file, int line)
Definition makesrna.cc:5691
static int rna_preprocess(const char *outfile, const char *public_header_outfile)
Definition makesrna.cc:5706
static void rna_generate_internal_property_prototypes(BlenderRNA *, StructRNA *srna, FILE *f)
Definition makesrna.cc:3803
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
void(* MEM_set_error_callback)(void(*func)(const char *))
Definition mallocn.cc:67
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
#define T
#define L
const int status
#define fabsf
void RNA_def_ID(BlenderRNA *brna)
Definition rna_ID.cc:2806
void RNA_def_action(BlenderRNA *brna)
void RNA_def_animation(BlenderRNA *brna)
void RNA_def_animviz(BlenderRNA *brna)
void RNA_def_annotations(BlenderRNA *brna)
void RNA_def_armature(BlenderRNA *brna)
void RNA_def_asset(BlenderRNA *brna)
Definition rna_asset.cc:717
void RNA_def_attribute(BlenderRNA *brna)
void RNA_def_blendfile_import(BlenderRNA *brna)
void RNA_def_boid(BlenderRNA *brna)
Definition rna_boid.cc:705
void RNA_def_brush(BlenderRNA *brna)
void RNA_def_cachefile(BlenderRNA *brna)
void RNA_def_camera(BlenderRNA *brna)
void RNA_def_cloth(BlenderRNA *brna)
void RNA_def_collections(BlenderRNA *brna)
void RNA_def_color(BlenderRNA *brna)
void RNA_def_constraint(BlenderRNA *brna)
void RNA_def_context(BlenderRNA *brna)
void RNA_def_curve(BlenderRNA *brna)
void RNA_def_profile(BlenderRNA *brna)
void RNA_def_curves(BlenderRNA *brna)
const char * RNA_property_typename(PropertyType type)
FunctionDefRNA * rna_find_function_def(FunctionRNA *func)
void RNA_free(BlenderRNA *brna)
BlenderRNA * RNA_create()
PropertyDefRNA * rna_find_parameter_def(PropertyRNA *parm)
int rna_parameter_size(PropertyRNA *parm)
BlenderDefRNA DefRNA
Definition rna_define.cc:71
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
PropertyDefRNA * rna_find_struct_property_def(StructRNA *srna, PropertyRNA *prop)
StructDefRNA * rna_find_struct_def(StructRNA *srna)
void RNA_define_free(BlenderRNA *)
int rna_parameter_size_pad(const int size)
void rna_addtail(ListBase *listbase, void *vlink)
void RNA_def_depsgraph(BlenderRNA *brna)
void RNA_def_dynamic_paint(BlenderRNA *brna)
void RNA_def_fcurve(BlenderRNA *brna)
void RNA_def_fluid(BlenderRNA *brna)
void RNA_def_grease_pencil(BlenderRNA *brna)
void RNA_def_image(BlenderRNA *brna)
void RNA_def_rna(BlenderRNA *brna)
Definition rna_rna.cc:3853
void RNA_def_wm(BlenderRNA *brna)
Definition rna_wm.cc:3301
void RNA_def_nla(BlenderRNA *brna)
Definition rna_nla.cc:1238
void RNA_def_sculpt_paint(BlenderRNA *brna)
void RNA_def_rigidbody(BlenderRNA *brna)
void RNA_def_palette(BlenderRNA *brna)
void RNA_def_meta(BlenderRNA *brna)
Definition rna_meta.cc:422
void RNA_def_sequencer(BlenderRNA *brna)
void RNA_def_lightprobe(BlenderRNA *brna)
void RNA_def_material(BlenderRNA *brna)
void RNA_def_test(BlenderRNA *brna)
Definition rna_test.cc:101
void RNA_def_movieclip(BlenderRNA *brna)
void RNA_def_light(BlenderRNA *brna)
Definition rna_light.cc:562
void RNA_def_shader_fx(BlenderRNA *brna)
void RNA_def_usd(BlenderRNA *brna)
Definition rna_usd.cc:160
void RNA_def_packedfile(BlenderRNA *brna)
void RNA_def_main(BlenderRNA *brna)
Definition rna_main.cc:269
void RNA_def_linestyle(BlenderRNA *brna)
void RNA_def_mesh(BlenderRNA *brna)
Definition rna_mesh.cc:3229
void RNA_def_sound(BlenderRNA *brna)
Definition rna_sound.cc:110
void RNA_def_lattice(BlenderRNA *brna)
void RNA_def_scene(BlenderRNA *brna)
void RNA_def_space(BlenderRNA *brna)
void RNA_def_speaker(BlenderRNA *brna)
void RNA_def_tracking(BlenderRNA *brna)
void RNA_def_node_socket_subtypes(BlenderRNA *brna)
void RNA_def_nodetree(BlenderRNA *brna)
void RNA_def_particle(BlenderRNA *brna)
void RNA_def_render(BlenderRNA *brna)
void RNA_def_modifier(BlenderRNA *brna)
void RNA_def_world(BlenderRNA *brna)
Definition rna_world.cc:204
void RNA_def_mask(BlenderRNA *brna)
Definition rna_mask.cc:1186
void RNA_def_workspace(BlenderRNA *brna)
void RNA_def_pose(BlenderRNA *brna)
Definition rna_pose.cc:1560
void RNA_def_node_tree_interface(BlenderRNA *brna)
void RNA_def_userdef(BlenderRNA *brna)
void RNA_def_texture(BlenderRNA *brna)
void RNA_def_wm_gizmo(BlenderRNA *brna)
void RNA_def_pointcloud(BlenderRNA *brna)
void RNA_def_vfont(BlenderRNA *brna)
Definition rna_vfont.cc:51
void RNA_def_view_layer(BlenderRNA *brna)
Definition rna_layer.cc:607
void RNA_def_object(BlenderRNA *brna)
void RNA_def_key(BlenderRNA *brna)
Definition rna_key.cc:1140
void RNA_def_object_force(BlenderRNA *brna)
void RNA_def_timeline_marker(BlenderRNA *brna)
void RNA_def_xr(BlenderRNA *brna)
Definition rna_xr.cc:2553
void RNA_def_text(BlenderRNA *brna)
Definition rna_text.cc:288
void RNA_def_screen(BlenderRNA *brna)
void RNA_def_ui(BlenderRNA *brna)
Definition rna_ui.cc:2567
void RNA_def_volume(BlenderRNA *brna)
void(*)(PointerRNA *ptr, bool *values) PropBooleanArrayGetFunc
void(*)(CollectionPropertyIterator *iter) PropCollectionNextFunc
int(*)(PointerRNA *ptr) PropStringLengthFunc
void(*)(CollectionPropertyIterator *iter, PointerRNA *ptr) PropCollectionBeginFunc
bool(*)(PointerRNA *ptr, int key, PointerRNA *r_ptr) PropCollectionLookupIntFunc
PointerRNA(*)(CollectionPropertyIterator *iter) PropCollectionGetFunc
void(*)(PointerRNA *ptr, const PointerRNA value, ReportList *reports) PropPointerSetFunc
@ PROP_INTERN_BUILTIN
@ PROP_INTERN_RAW_ACCESS
@ PROP_INTERN_PTR_OWNERSHIP_FORCED
@ PROP_INTERN_RAW_ARRAY
@ PROP_INTERN_PTR_ID_REFCOUNT_FORCED
void(*)(PointerRNA *ptr, int value) PropEnumSetFunc
int(*)(PointerRNA *ptr) PropEnumGetFunc
void(*)(PointerRNA *ptr, int value) PropIntSetFunc
PointerRNA(*)(PointerRNA *ptr) PropPointerGetFunc
void(*)(PointerRNA *ptr, const float *values) PropFloatArraySetFunc
void(*)(PointerRNA *ptr, char *value) PropStringGetFunc
void(*)(PointerRNA *ptr, bool value) PropBooleanSetFunc
bool(*)(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) PropCollectionLookupStringFunc
int(*)(PointerRNA *ptr) PropCollectionLengthFunc
void(*)(PointerRNA *ptr, const bool *values) PropBooleanArraySetFunc
bool(*)(PointerRNA *ptr) PropBooleanGetFunc
void(*)(PointerRNA *ptr, int *values) PropIntArrayGetFunc
void(*)(PointerRNA *ptr, float value) PropFloatSetFunc
void(*)(PointerRNA *ptr, const int *values) PropIntArraySetFunc
int(*)(PointerRNA *ptr) PropIntGetFunc
void(*)(PointerRNA *ptr, const char *value) PropStringSetFunc
float(*)(PointerRNA *ptr) PropFloatGetFunc
void(*)(PointerRNA *ptr, float *values) PropFloatArrayGetFunc
void(*)(CollectionPropertyIterator *iter) PropCollectionEndFunc
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:26
#define FLT_MAX
Definition stdcycles.h:14
PropBooleanArrayGetTransformFunc getarray_transform
PropBooleanGetFuncEx get_default
PropBooleanSetTransformFunc set_transform
PropBooleanArraySetFuncEx setarray_ex
PropBooleanArrayGetFuncEx getarray_ex
PropBooleanGetTransformFunc get_transform
PropBooleanArraySetFunc setarray
const bool * defaultarray
PropBooleanArrayGetFuncEx get_default_array
PropBooleanSetFunc set
PropBooleanGetFunc get
PropBooleanSetFuncEx set_ex
PropBooleanGetFuncEx get_ex
PropBooleanArraySetTransformFunc setarray_transform
PropBooleanArrayGetFunc getarray
PropCollectionNextFunc next
PropCollectionLookupStringFunc lookupstring
PropCollectionLengthFunc length
PropCollectionLookupIntFunc lookupint
PropCollectionBeginFunc begin
PropCollectionAssignIntFunc assignint
PropCollectionEndFunc end
PropCollectionGetFunc get
ListBase properties
short removal_version
const char * note
const char * identifier
Definition RNA_types.hh:657
const char * name
Definition RNA_types.hh:661
const char * description
Definition RNA_types.hh:663
const EnumPropertyItem * item
PropEnumSetFuncEx set_ex
PropEnumGetTransformFunc get_transform
PropEnumGetFuncEx get_default
PropEnumGetFunc get
const char * native_enum_type
PropEnumItemFunc item_fn
PropEnumSetTransformFunc set_transform
PropEnumGetFuncEx get_ex
PropEnumSetFunc set
PropFloatSetTransformFunc set_transform
PropFloatSetFuncEx set_ex
PropertyScaleType ui_scale_type
PropFloatGetFunc get
PropFloatRangeFuncEx range_ex
PropFloatArrayGetTransformFunc getarray_transform
PropFloatArrayGetFuncEx getarray_ex
PropFloatArraySetFuncEx setarray_ex
PropFloatArrayGetFunc getarray
PropFloatGetFuncEx get_default
PropFloatArraySetTransformFunc setarray_transform
PropFloatGetTransformFunc get_transform
PropFloatSetFunc set
const float * defaultarray
PropFloatRangeFunc range
PropFloatArraySetFunc setarray
PropFloatGetFuncEx get_ex
PropFloatArrayGetFuncEx get_default_array
const char * gencall
FunctionRNA * func
ContainerDefRNA cont
const char * call
const char * identifier
PropertyRNA * c_ret
ContainerRNA cont
const char * description
PropIntRangeFuncEx range_ex
PropIntArrayGetFunc getarray
PropIntArrayGetFuncEx getarray_ex
PropIntArraySetTransformFunc setarray_transform
PropIntRangeFunc range
PropIntArraySetFunc setarray
PropIntGetFuncEx get_ex
PropIntArrayGetFuncEx get_default_array
PropIntSetTransformFunc set_transform
PropIntArraySetFuncEx setarray_ex
PropIntGetTransformFunc get_transform
PropertyScaleType ui_scale_type
PropIntArrayGetTransformFunc getarray_transform
PropIntGetFuncEx get_default
PropIntSetFuncEx set_ex
void * last
void * first
PropPointerTypeFunc type_fn
PropPointerGetFunc get
PropPointerPollFunc poll
PropPointerSetFunc set
const char * dnatype
const char * dnaname
const char * dnastructfromprop
const char * dnastructname
const char * dnalengthname
const char * dnastructfromname
PropertyDefRNA * next
PropertyRNA * prop
ItemEditableFunc itemeditable
PropArrayLengthGetFunc getlength
const char * translation_context
RNAPropOverrideApply override_apply
unsigned int arraydimension
PropertyRNA * prev
const DeprecatedRNA * deprecated
EditableFunc editable
PropertyPathTemplateType path_template_type
RNAPropOverrideStore override_store
PropUINameFunc ui_name_func
PropertyRNA * next
RNAPropOverrideDiff override_diff
PropertySubType subtype
unsigned int arraylength[RNA_MAX_ARRAY_DIMENSION]
const char * description
const char * name
unsigned int totarraylength
const char * identifier
RawPropertyType rawtype
PropertyType type
void(* define)(BlenderRNA *brna)
Definition makesrna.cc:4896
const char * filename
Definition makesrna.cc:4894
const char * api_filename
Definition makesrna.cc:4895
StringPropertyPathFilterFunc path_filter
PropStringSetFunc set
PropStringLengthFuncEx length_ex
PropStringLengthFunc length
PropStringGetFuncEx get_ex
PropStringSetFuncEx set_ex
PropStringGetTransformFunc get_transform
PropStringSetTransformFunc set_transform
PropStringGetFunc get
StringPropertySearchFunc search
eStringPropertySearchFlag search_flag
const char * dnaname
ContainerDefRNA cont
StructRNA * srna
ListBase functions
const char * filename
const char * dnafromprop
const char * dnafromname
StructRNA * nested
StructRegisterFunc reg
StructUnregisterFunc unreg
const char * name
const char * identifier
StructInstanceFunc instance
ContainerRNA cont
const char * translation_context
PropertyRNA * nameproperty
const char * description
IDPropertiesFunc idproperties
PropertyRNA * iteratorproperty
StructRNA * base
StructRefineFunc refine
IDPropertiesFunc system_idproperties
StructPathFunc path
i
Definition text_draw.cc:230
uint len
uint8_t flag
Definition wm_window.cc:145