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