4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
31 #include "MEM_guardedalloc.h"
33 #include "RNA_define.h"
35 #include "rna_internal.h"
37 #define RNA_VERSION_DATE "$Id$"
41 #define snprintf _snprintf
45 /* Replace if different */
46 #define TMP_EXT ".tmp"
48 static int replace_if_different(char *tmpfile)
53 if(rename(tmpfile, orgfile) != 0) { \
54 fprintf(stderr, "%s:%d, rename error: \"%s\" -> \"%s\"\n", __FILE__, __LINE__, tmpfile, orgfile); \
62 FILE *fp_new, *fp_org;
64 char *arr_new, *arr_org;
69 strcpy(orgfile, tmpfile);
70 orgfile[strlen(orgfile) - strlen(TMP_EXT)] = '\0'; /* strip '.tmp' */
72 fp_org= fopen(orgfile, "rb");
78 fp_new= fopen(tmpfile, "rb");
81 /* shouldn't happen, just to be safe */
82 fprintf(stderr, "%s:%d, open error: \"%s\"\n", __FILE__, __LINE__, tmpfile);
86 fseek(fp_new, 0L, SEEK_END); len_new = ftell(fp_new); fseek(fp_new, 0L, SEEK_SET);
87 fseek(fp_org, 0L, SEEK_END); len_org = ftell(fp_org); fseek(fp_org, 0L, SEEK_SET);
90 if(len_new != len_org) {
96 /* now compare the files... */
97 arr_new= MEM_mallocN(sizeof(char)*len_new, "rna_cmp_file_new");
98 arr_org= MEM_mallocN(sizeof(char)*len_org, "rna_cmp_file_org");
100 if(fread(arr_new, sizeof(char), len_new, fp_new) != len_new)
101 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, tmpfile);
102 if(fread(arr_org, sizeof(char), len_org, fp_org) != len_org)
103 fprintf(stderr, "%s:%d, error reading file %s for comparison.\n", __FILE__, __LINE__, orgfile);
108 cmp= memcmp(arr_new, arr_org, len_new);
128 static int cmp_struct(const void *a, const void *b)
130 const StructRNA *structa= *(const StructRNA**)a;
131 const StructRNA *structb= *(const StructRNA**)b;
133 return strcmp(structa->identifier, structb->identifier);
136 static int cmp_property(const void *a, const void *b)
138 const PropertyRNA *propa= *(const PropertyRNA**)a;
139 const PropertyRNA *propb= *(const PropertyRNA**)b;
141 if(strcmp(propa->identifier, "rna_type") == 0) return -1;
142 else if(strcmp(propb->identifier, "rna_type") == 0) return 1;
144 if(strcmp(propa->identifier, "name") == 0) return -1;
145 else if(strcmp(propb->identifier, "name") == 0) return 1;
147 return strcmp(propa->name, propb->name);
150 static int cmp_def_struct(const void *a, const void *b)
152 const StructDefRNA *dsa= *(const StructDefRNA**)a;
153 const StructDefRNA *dsb= *(const StructDefRNA**)b;
155 return cmp_struct(&dsa->srna, &dsb->srna);
158 static int cmp_def_property(const void *a, const void *b)
160 const PropertyDefRNA *dpa= *(const PropertyDefRNA**)a;
161 const PropertyDefRNA *dpb= *(const PropertyDefRNA**)b;
163 return cmp_property(&dpa->prop, &dpb->prop);
166 static void rna_sortlist(ListBase *listbase, int(*cmp)(const void*, const void*))
172 if(listbase->first == listbase->last)
175 for(size=0, link=listbase->first; link; link=link->next)
178 array= MEM_mallocN(sizeof(void*)*size, "rna_sortlist");
179 for(a=0, link=listbase->first; link; link=link->next, a++)
182 qsort(array, size, sizeof(void*), cmp);
184 listbase->first= listbase->last= NULL;
185 for(a=0; a<size; a++) {
187 link->next= link->prev= NULL;
188 rna_addtail(listbase, link);
196 static void rna_print_c_string(FILE *f, const char *str)
198 static char *escape[] = {"\''", "\"\"", "\??", "\\\\","\aa", "\bb", "\ff", "\nn", "\rr", "\tt", "\vv", NULL};
207 for(i=0; str[i]; i++) {
208 for(j=0; escape[j]; j++)
209 if(str[i] == escape[j][0])
212 if(escape[j]) fprintf(f, "\\%c", escape[j][1]);
213 else fprintf(f, "%c", str[i]);
218 static void rna_print_data_get(FILE *f, PropertyDefRNA *dp)
220 if(dp->dnastructfromname && dp->dnastructfromprop)
221 fprintf(f, " %s *data= (%s*)(((%s*)ptr->data)->%s);\n", dp->dnastructname, dp->dnastructname, dp->dnastructfromname, dp->dnastructfromprop);
223 fprintf(f, " %s *data= (%s*)(ptr->data);\n", dp->dnastructname, dp->dnastructname);
226 static void rna_print_id_get(FILE *f, PropertyDefRNA *dp)
228 fprintf(f, " ID *id= ptr->id.data;\n");
231 static char *rna_alloc_function_name(const char *structname, const char *propname, const char *type)
237 snprintf(buffer, sizeof(buffer), "%s_%s_%s", structname, propname, type);
238 result= MEM_callocN(sizeof(char)*strlen(buffer)+1, "rna_alloc_function_name");
239 strcpy(result, buffer);
241 alloc= MEM_callocN(sizeof(AllocDefRNA), "AllocDefRNA");
243 rna_addtail(&DefRNA.allocs, alloc);
248 static StructRNA *rna_find_struct(const char *identifier)
252 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
253 if(strcmp(ds->srna->identifier, identifier)==0)
259 static const char *rna_find_type(const char *type)
263 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
264 if(ds->dnaname && strcmp(ds->dnaname, type)==0)
265 return ds->srna->identifier;
270 static const char *rna_find_dna_type(const char *type)
274 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
275 if(strcmp(ds->srna->identifier, type)==0)
281 static const char *rna_type_type_name(PropertyRNA *prop)
297 static const char *rna_type_type(PropertyRNA *prop)
301 type= rna_type_type_name(prop);
309 static const char *rna_type_struct(PropertyRNA *prop)
313 type= rna_type_type_name(prop);
321 static const char *rna_parameter_type_name(PropertyRNA *parm)
325 type= rna_type_type_name(parm);
332 PointerPropertyRNA *pparm= (PointerPropertyRNA*)parm;
334 if(parm->flag & PROP_RNAPTR)
337 return rna_find_dna_type((const char *)pparm->type);
339 case PROP_COLLECTION: {
343 return "<error, no type specified>";
347 static int rna_enum_bitmask(PropertyRNA *prop)
349 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
353 for(a=0; a<eprop->totitem; a++)
354 if(eprop->item[a].identifier[0])
355 mask |= eprop->item[a].value;
361 static int rna_color_quantize(PropertyRNA *prop, PropertyDefRNA *dp)
363 if(prop->type == PROP_FLOAT && prop->subtype == PROP_COLOR)
364 if(strcmp(dp->dnatype, "float") != 0 && strcmp(dp->dnatype, "double") != 0)
370 static const char *rna_function_string(void *func)
372 return (func)? (const char*)func: "NULL";
375 static void rna_float_print(FILE *f, float num)
377 if(num == -FLT_MAX) fprintf(f, "-FLT_MAX");
378 else if(num == FLT_MAX) fprintf(f, "FLT_MAX");
379 else if((int)num == num) fprintf(f, "%.1ff", num);
380 else fprintf(f, "%.10ff", num);
383 static void rna_int_print(FILE *f, int num)
385 if(num == INT_MIN) fprintf(f, "INT_MIN");
386 else if(num == INT_MAX) fprintf(f, "INT_MAX");
387 else fprintf(f, "%d", num);
390 static char *rna_def_property_get_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, const char *manualfunc)
394 if(prop->flag & PROP_IDPROPERTY)
398 if(!dp->dnastructname || !dp->dnaname) {
399 fprintf(stderr, "rna_def_property_get_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
405 func= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
409 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
410 fprintf(f, "void %s(PointerRNA *ptr, char *value)\n", func);
413 fprintf(f, " %s(ptr, value);\n", manualfunc);
416 rna_print_data_get(f, dp);
418 fprintf(f, " BLI_strncpy(value, data->%s, %d);\n", dp->dnaname, sprop->maxlength);
420 fprintf(f, " BLI_strncpy(value, data->%s, sizeof(data->%s));\n", dp->dnaname, dp->dnaname);
426 fprintf(f, "PointerRNA %s(PointerRNA *ptr)\n", func);
429 fprintf(f, " return %s(ptr);\n", manualfunc);
432 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
433 rna_print_data_get(f, dp);
434 if(dp->dnapointerlevel == 0)
435 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, &data->%s);\n", (char*)pprop->type, dp->dnaname);
437 fprintf(f, " return rna_pointer_inherit_refine(ptr, &RNA_%s, data->%s);\n", (char*)pprop->type, dp->dnaname);
442 case PROP_COLLECTION: {
443 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
445 fprintf(f, "static PointerRNA %s(CollectionPropertyIterator *iter)\n", func);
448 if(strcmp(manualfunc, "rna_iterator_listbase_get") == 0 ||
449 strcmp(manualfunc, "rna_iterator_array_get") == 0 ||
450 strcmp(manualfunc, "rna_iterator_array_dereference_get") == 0)
451 fprintf(f, " return rna_pointer_inherit_refine(&iter->parent, &RNA_%s, %s(iter));\n", (cprop->item_type)? (char*)cprop->item_type: "UnknownType", manualfunc);
453 fprintf(f, " return %s(iter);\n", manualfunc);
459 if(prop->arraydimension) {
460 if(prop->flag & PROP_DYNAMIC)
461 fprintf(f, "void %s(PointerRNA *ptr, %s values[])\n", func, rna_type_type(prop));
463 fprintf(f, "void %s(PointerRNA *ptr, %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
467 fprintf(f, " %s(ptr, values);\n", manualfunc);
470 rna_print_data_get(f, dp);
472 if(prop->flag & PROP_DYNAMIC) {
473 char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get_length");
474 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
475 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
476 fprintf(f, " for(i=0; i<len; i++) {\n");
480 fprintf(f, " int i;\n\n");
481 fprintf(f, " for(i=0; i<%d; i++) {\n", prop->totarraylength);
484 if(dp->dnaarraylength == 1) {
485 if(prop->type == PROP_BOOLEAN && dp->booleanbit)
486 fprintf(f, " values[i]= (%s(data->%s & (%d<<i)) != 0);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
488 fprintf(f, " values[i]= (%s)%s((&data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
491 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
492 fprintf(f, " values[i]= (%s(data->%s[i] & ", (dp->booleannegative)? "!": "", dp->dnaname);
493 rna_int_print(f, dp->booleanbit);
494 fprintf(f, ") != 0);\n");
496 else if(rna_color_quantize(prop, dp))
497 fprintf(f, " values[i]= (%s)(data->%s[i]*(1.0f/255.0f));\n", rna_type_type(prop), dp->dnaname);
499 fprintf(f, " values[i]= (%s)%s(((%s*)data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnatype, dp->dnaname);
501 fprintf(f, " values[i]= (%s)%s((data->%s)[i]);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
508 fprintf(f, "%s %s(PointerRNA *ptr)\n", rna_type_type(prop), func);
512 fprintf(f, " return %s(ptr);\n", manualfunc);
515 rna_print_data_get(f, dp);
516 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
517 fprintf(f, " return (%s((data->%s) & ", (dp->booleannegative)? "!": "", dp->dnaname);
518 rna_int_print(f, dp->booleanbit);
519 fprintf(f, ") != 0);\n");
521 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
522 fprintf(f, " return ((data->%s) & ", dp->dnaname);
523 rna_int_print(f, rna_enum_bitmask(prop));
527 fprintf(f, " return (%s)%s(data->%s);\n", rna_type_type(prop), (dp->booleannegative)? "!": "", dp->dnaname);
538 static void rna_clamp_value(FILE *f, PropertyRNA *prop, int array)
540 if(prop->type == PROP_INT) {
541 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
543 if(iprop->hardmin != INT_MIN || iprop->hardmax != INT_MAX) {
544 if(array) fprintf(f, "CLAMPIS(values[i], ");
545 else fprintf(f, "CLAMPIS(value, ");
546 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
547 rna_int_print(f, iprop->hardmax); fprintf(f, ");\n");
551 else if(prop->type == PROP_FLOAT) {
552 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
554 if(fprop->hardmin != -FLT_MAX || fprop->hardmax != FLT_MAX) {
555 if(array) fprintf(f, "CLAMPIS(values[i], ");
556 else fprintf(f, "CLAMPIS(value, ");
557 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
558 rna_float_print(f, fprop->hardmax); fprintf(f, ");\n");
564 fprintf(f, "values[i];\n");
566 fprintf(f, "value;\n");
569 static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
573 if(!(prop->flag & PROP_EDITABLE))
575 if(prop->flag & PROP_IDPROPERTY)
579 if(!dp->dnastructname || !dp->dnaname) {
580 if(prop->flag & PROP_EDITABLE) {
581 fprintf(stderr, "rna_def_property_set_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
588 func= rna_alloc_function_name(srna->identifier, prop->identifier, "set");
592 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
593 fprintf(f, "void %s(PointerRNA *ptr, const char *value)\n", func);
596 fprintf(f, " %s(ptr, value);\n", manualfunc);
599 rna_print_data_get(f, dp);
601 fprintf(f, " BLI_strncpy(data->%s, value, %d);\n", dp->dnaname, sprop->maxlength);
603 fprintf(f, " BLI_strncpy(data->%s, value, sizeof(data->%s));\n", dp->dnaname, dp->dnaname);
609 fprintf(f, "void %s(PointerRNA *ptr, PointerRNA value)\n", func);
612 fprintf(f, " %s(ptr, value);\n", manualfunc);
615 rna_print_data_get(f, dp);
617 if(prop->flag & PROP_ID_SELF_CHECK) {
618 rna_print_id_get(f, dp);
619 fprintf(f, " if(id==value.data) return;\n\n");
622 if(prop->flag & PROP_ID_REFCOUNT) {
623 fprintf(f, "\n if(data->%s)\n", dp->dnaname);
624 fprintf(f, " id_us_min((ID*)data->%s);\n", dp->dnaname);
625 fprintf(f, " if(value.data)\n");
626 fprintf(f, " id_us_plus((ID*)value.data);\n\n");
629 fprintf(f, " data->%s= value.data;\n", dp->dnaname);
636 if(prop->arraydimension) {
637 if(prop->flag & PROP_DYNAMIC)
638 fprintf(f, "void %s(PointerRNA *ptr, const %s values[])\n", func, rna_type_type(prop));
640 fprintf(f, "void %s(PointerRNA *ptr, const %s values[%d])\n", func, rna_type_type(prop), prop->totarraylength);
644 fprintf(f, " %s(ptr, values);\n", manualfunc);
647 rna_print_data_get(f, dp);
649 if(prop->flag & PROP_DYNAMIC) {
650 char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "set_length");
651 fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n");
652 fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc);
653 fprintf(f, " for(i=0; i<len; i++) {\n");
657 fprintf(f, " int i;\n\n");
658 fprintf(f, " for(i=0; i<%d; i++) {\n", prop->totarraylength);
661 if(dp->dnaarraylength == 1) {
662 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
663 fprintf(f, " if(%svalues[i]) data->%s |= (%d<<i);\n", (dp->booleannegative)? "!": "", dp->dnaname, dp->booleanbit);
664 fprintf(f, " else data->%s &= ~(%d<<i);\n", dp->dnaname, dp->booleanbit);
667 fprintf(f, " (&data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
668 rna_clamp_value(f, prop, 1);
672 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
673 fprintf(f, " if(%svalues[i]) data->%s[i] |= ", (dp->booleannegative)? "!": "", dp->dnaname);
674 rna_int_print(f, dp->booleanbit);
676 fprintf(f, " else data->%s[i] &= ~", dp->dnaname);
677 rna_int_print(f, dp->booleanbit);
680 else if(rna_color_quantize(prop, dp)) {
681 fprintf(f, " data->%s[i]= FTOCHAR(values[i]);\n", dp->dnaname);
685 fprintf(f, " ((%s*)data->%s)[i]= %s", dp->dnatype, dp->dnaname, (dp->booleannegative)? "!": "");
687 fprintf(f, " (data->%s)[i]= %s", dp->dnaname, (dp->booleannegative)? "!": "");
688 rna_clamp_value(f, prop, 1);
696 fprintf(f, "void %s(PointerRNA *ptr, %s value)\n", func, rna_type_type(prop));
700 fprintf(f, " %s(ptr, value);\n", manualfunc);
703 rna_print_data_get(f, dp);
704 if(prop->type == PROP_BOOLEAN && dp->booleanbit) {
705 fprintf(f, " if(%svalue) data->%s |= ", (dp->booleannegative)? "!": "", dp->dnaname);
706 rna_int_print(f, dp->booleanbit);
708 fprintf(f, " else data->%s &= ~", dp->dnaname);
709 rna_int_print(f, dp->booleanbit);
712 else if(prop->type == PROP_ENUM && dp->enumbitflags) {
713 fprintf(f, " data->%s &= ~", dp->dnaname);
714 rna_int_print(f, rna_enum_bitmask(prop));
716 fprintf(f, " data->%s |= value;\n", dp->dnaname);
719 fprintf(f, " data->%s= %s", dp->dnaname, (dp->booleannegative)? "!": "");
720 rna_clamp_value(f, prop, 0);
731 static char *rna_def_property_length_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
735 if(prop->flag & PROP_IDPROPERTY)
738 if(prop->type == PROP_STRING) {
740 if(!dp->dnastructname || !dp->dnaname) {
741 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
747 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
749 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
752 fprintf(f, " return %s(ptr);\n", manualfunc);
755 rna_print_data_get(f, dp);
756 fprintf(f, " return strlen(data->%s);\n", dp->dnaname);
760 else if(prop->type == PROP_COLLECTION) {
762 if(prop->type == PROP_COLLECTION && (!(dp->dnalengthname || dp->dnalengthfixed)|| !dp->dnaname)) {
763 fprintf(stderr, "rna_def_property_length_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
769 func= rna_alloc_function_name(srna->identifier, prop->identifier, "length");
771 fprintf(f, "int %s(PointerRNA *ptr)\n", func);
774 fprintf(f, " return %s(ptr);\n", manualfunc);
777 rna_print_data_get(f, dp);
778 if(dp->dnalengthname)
779 fprintf(f, " return (data->%s == NULL)? 0: data->%s;\n", dp->dnaname, dp->dnalengthname);
781 fprintf(f, " return (data->%s == NULL)? 0: %d;\n", dp->dnaname, dp->dnalengthfixed);
789 static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
791 char *func, *getfunc;
793 if(prop->flag & PROP_IDPROPERTY)
797 if(!dp->dnastructname || !dp->dnaname) {
798 fprintf(stderr, "rna_def_property_begin_func: %s.%s has no valid dna info.\n", srna->identifier, prop->identifier);
804 func= rna_alloc_function_name(srna->identifier, prop->identifier, "begin");
806 fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func);
810 rna_print_data_get(f, dp);
812 fprintf(f, "\n memset(iter, 0, sizeof(*iter));\n");
813 fprintf(f, " iter->parent= *ptr;\n");
814 fprintf(f, " iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
816 if(dp->dnalengthname || dp->dnalengthfixed) {
818 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
821 if(dp->dnalengthname)
822 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), data->%s, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthname);
824 fprintf(f, "\n rna_iterator_array_begin(iter, data->%s, sizeof(data->%s[0]), %d, 0, NULL);\n", dp->dnaname, dp->dnaname, dp->dnalengthfixed);
829 fprintf(f, "\n %s(iter, ptr);\n", manualfunc);
830 else if(dp->dnapointerlevel == 0)
831 fprintf(f, "\n rna_iterator_listbase_begin(iter, &data->%s, NULL);\n", dp->dnaname);
833 fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname);
836 getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
838 fprintf(f, "\n if(iter->valid)\n");
839 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
847 static char *rna_def_property_lookup_int_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc, char *nextfunc)
851 if(prop->flag & PROP_IDPROPERTY)
855 if(!dp->dnastructname || !dp->dnaname)
858 /* only supported in case of standard next functions */
859 if(strcmp(nextfunc, "rna_iterator_array_next") == 0);
860 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0);
864 func= rna_alloc_function_name(srna->identifier, prop->identifier, "lookup_int");
866 fprintf(f, "PointerRNA %s(PointerRNA *ptr, int index)\n", func);
870 fprintf(f, "\n return %s(ptr, index);\n", manualfunc);
875 fprintf(f, " PointerRNA r_ptr;\n");
876 fprintf(f, " CollectionPropertyIterator iter;\n\n");
878 fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, prop->identifier);
881 if(strcmp(nextfunc, "rna_iterator_array_next") == 0) {
882 fprintf(f, " ArrayIterator *internal= iter.internal;\n");
883 fprintf(f, " if(internal->skip) {\n");
884 fprintf(f, " while(index-- > 0) {\n");
885 fprintf(f, " do {\n");
886 fprintf(f, " internal->ptr += internal->itemsize;\n");
887 fprintf(f, " } while(internal->skip(&iter, internal->ptr));\n");
890 fprintf(f, " else {\n");
891 fprintf(f, " internal->ptr += internal->itemsize*index;\n");
894 else if(strcmp(nextfunc, "rna_iterator_listbase_next") == 0) {
895 fprintf(f, " ListBaseIterator *internal= iter.internal;\n");
896 fprintf(f, " if(internal->skip) {\n");
897 fprintf(f, " while(index-- > 0) {\n");
898 fprintf(f, " do {\n");
899 fprintf(f, " internal->link= internal->link->next;\n");
900 fprintf(f, " } while(internal->skip(&iter, internal->link));\n");
903 fprintf(f, " else {\n");
904 fprintf(f, " while(index-- > 0)\n");
905 fprintf(f, " internal->link= internal->link->next;\n");
909 fprintf(f, " }\n\n");
911 fprintf(f, " r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier);
912 fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, prop->identifier);
914 fprintf(f, " return r_ptr;\n");
917 rna_print_data_get(f, dp);
918 item_type= (cprop->item_type)? (char*)cprop->item_type: "UnknownType";
920 if(dp->dnalengthname || dp->dnalengthfixed) {
921 if(dp->dnalengthname)
922 fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), data->%s, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthname);
924 fprintf(f, "\n rna_array_lookup_int(ptr, &RNA_%s, data->%s, sizeof(data->%s[0]), %d, index);\n", item_type, dp->dnaname, dp->dnaname, dp->dnalengthfixed);
927 if(dp->dnapointerlevel == 0)
928 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, &data->%s, index);\n", item_type, dp->dnaname);
930 fprintf(f, "\n return rna_listbase_lookup_int(ptr, &RNA_%s, data->%s, index);\n", item_type, dp->dnaname);
939 static char *rna_def_property_next_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
941 char *func, *getfunc;
943 if(prop->flag & PROP_IDPROPERTY)
949 func= rna_alloc_function_name(srna->identifier, prop->identifier, "next");
951 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
953 fprintf(f, " %s(iter);\n", manualfunc);
955 getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get");
957 fprintf(f, "\n if(iter->valid)\n");
958 fprintf(f, " iter->ptr= %s(iter);\n", getfunc);
965 static char *rna_def_property_end_func(FILE *f, StructRNA *srna, PropertyRNA *prop, PropertyDefRNA *dp, char *manualfunc)
969 if(prop->flag & PROP_IDPROPERTY)
972 func= rna_alloc_function_name(srna->identifier, prop->identifier, "end");
974 fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func);
977 fprintf(f, " %s(iter);\n", manualfunc);
983 static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
985 if(dp->dnapointerlevel != 0)
987 if(!dp->dnatype || !dp->dnaname || !dp->dnastructname)
990 if(strcmp(dp->dnatype, "char") == 0) {
991 prop->rawtype= PROP_RAW_CHAR;
992 prop->flag |= PROP_RAW_ACCESS;
994 else if(strcmp(dp->dnatype, "short") == 0) {
995 prop->rawtype= PROP_RAW_SHORT;
996 prop->flag |= PROP_RAW_ACCESS;
998 else if(strcmp(dp->dnatype, "int") == 0) {
999 prop->rawtype= PROP_RAW_INT;
1000 prop->flag |= PROP_RAW_ACCESS;
1002 else if(strcmp(dp->dnatype, "float") == 0) {
1003 prop->rawtype= PROP_RAW_FLOAT;
1004 prop->flag |= PROP_RAW_ACCESS;
1006 else if(strcmp(dp->dnatype, "double") == 0) {
1007 prop->rawtype= PROP_RAW_DOUBLE;
1008 prop->flag |= PROP_RAW_ACCESS;
1012 static void rna_set_raw_offset(FILE *f, StructRNA *srna, PropertyRNA *prop)
1014 PropertyDefRNA *dp= rna_find_struct_property_def(srna, prop);
1016 fprintf(f, "\toffsetof(%s, %s), %d", dp->dnastructname, dp->dnaname, prop->rawtype);
1019 static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1025 switch(prop->type) {
1026 case PROP_BOOLEAN: {
1027 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1029 if(!prop->arraydimension) {
1030 if(!bprop->get && !bprop->set && !dp->booleanbit)
1031 rna_set_raw_property(dp, prop);
1033 bprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->get);
1034 bprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->set);
1037 bprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)bprop->getarray);
1038 bprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)bprop->setarray);
1043 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1045 if(!prop->arraydimension) {
1046 if(!iprop->get && !iprop->set)
1047 rna_set_raw_property(dp, prop);
1049 iprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->get);
1050 iprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->set);
1053 if(!iprop->getarray && !iprop->setarray)
1054 rna_set_raw_property(dp, prop);
1056 iprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)iprop->getarray);
1057 iprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)iprop->setarray);
1062 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1064 if(!prop->arraydimension) {
1065 if(!fprop->get && !fprop->set)
1066 rna_set_raw_property(dp, prop);
1068 fprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->get);
1069 fprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->set);
1072 if(!fprop->getarray && !fprop->setarray)
1073 rna_set_raw_property(dp, prop);
1075 fprop->getarray= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)fprop->getarray);
1076 fprop->setarray= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)fprop->setarray);
1081 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1083 eprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)eprop->get);
1084 eprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)eprop->set);
1088 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1090 sprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)sprop->get);
1091 sprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)sprop->length);
1092 sprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)sprop->set);
1095 case PROP_POINTER: {
1096 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
1098 pprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)pprop->get);
1099 pprop->set= (void*)rna_def_property_set_func(f, srna, prop, dp, (char*)pprop->set);
1101 fprintf(stderr, "rna_def_property_funcs: %s.%s, pointer must have a struct type.\n", srna->identifier, prop->identifier);
1106 case PROP_COLLECTION: {
1107 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
1108 char *nextfunc= (char*)cprop->next;
1110 if(dp->dnatype && strcmp(dp->dnatype, "ListBase")==0);
1111 else if(dp->dnalengthname || dp->dnalengthfixed)
1112 cprop->length= (void*)rna_def_property_length_func(f, srna, prop, dp, (char*)cprop->length);
1114 /* test if we can allow raw array access, if it is using our standard
1115 * array get/next function, we can be sure it is an actual array */
1116 if(cprop->next && cprop->get)
1117 if(strcmp((char*)cprop->next, "rna_iterator_array_next") == 0 &&
1118 strcmp((char*)cprop->get, "rna_iterator_array_get") == 0)
1119 prop->flag |= PROP_RAW_ARRAY;
1121 cprop->get= (void*)rna_def_property_get_func(f, srna, prop, dp, (char*)cprop->get);
1122 cprop->begin= (void*)rna_def_property_begin_func(f, srna, prop, dp, (char*)cprop->begin);
1123 cprop->next= (void*)rna_def_property_next_func(f, srna, prop, dp, (char*)cprop->next);
1124 cprop->end= (void*)rna_def_property_end_func(f, srna, prop, dp, (char*)cprop->end);
1125 cprop->lookupint= (void*)rna_def_property_lookup_int_func(f, srna, prop, dp, (char*)cprop->lookupint, nextfunc);
1127 if(!(prop->flag & PROP_IDPROPERTY)) {
1129 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a begin function.\n", srna->identifier, prop->identifier);
1133 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a next function.\n", srna->identifier, prop->identifier);
1137 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a get function.\n", srna->identifier, prop->identifier);
1141 if(!cprop->item_type) {
1142 fprintf(stderr, "rna_def_property_funcs: %s.%s, collection must have a struct type.\n", srna->identifier, prop->identifier);
1150 static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1157 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1160 func= rna_alloc_function_name(srna->identifier, prop->identifier, "");
1162 switch(prop->type) {
1165 if(!prop->arraydimension) {
1166 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1167 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1170 fprintf(f, "void %sget(PointerRNA *ptr, int values[%d]);\n", func, prop->totarraylength);
1171 //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength);
1176 if(!prop->arraydimension) {
1177 fprintf(f, "float %sget(PointerRNA *ptr);\n", func);
1178 //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func);
1181 fprintf(f, "void %sget(PointerRNA *ptr, float values[%d]);\n", func, prop->totarraylength);
1182 //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength);
1187 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1191 fprintf(f, "enum {\n");
1193 for(i=0; i<eprop->totitem; i++)
1194 if(eprop->item[i].identifier[0])
1195 fprintf(f, "\t%s_%s_%s = %d,\n", srna->identifier, prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1197 fprintf(f, "};\n\n");
1200 fprintf(f, "int %sget(PointerRNA *ptr);\n", func);
1201 //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func);
1206 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
1208 if(sprop->maxlength) {
1209 fprintf(f, "#define %s_%s_MAX %d\n\n", srna->identifier, prop->identifier, sprop->maxlength);
1212 fprintf(f, "void %sget(PointerRNA *ptr, char *value);\n", func);
1213 fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1214 //fprintf(f, "void %sset(PointerRNA *ptr, const char *value);\n", func);
1218 case PROP_POINTER: {
1219 fprintf(f, "PointerRNA %sget(PointerRNA *ptr);\n", func);
1220 //fprintf(f, "void %sset(PointerRNA *ptr, PointerRNA value);\n", func);
1223 case PROP_COLLECTION: {
1224 fprintf(f, "void %sbegin(CollectionPropertyIterator *iter, PointerRNA *ptr);\n", func);
1225 fprintf(f, "void %snext(CollectionPropertyIterator *iter);\n", func);
1226 fprintf(f, "void %send(CollectionPropertyIterator *iter);\n", func);
1227 //fprintf(f, "int %slength(PointerRNA *ptr);\n", func);
1228 //fprintf(f, "void %slookup_int(PointerRNA *ptr, int key, StructRNA **type);\n", func);
1229 //fprintf(f, "void %slookup_string(PointerRNA *ptr, const char *key, StructRNA **type);\n", func);
1237 static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1243 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1246 if(prop->name && prop->description && strcmp(prop->description, "") != 0)
1247 fprintf(f, "\t/* %s: %s */\n", prop->name, prop->description);
1249 fprintf(f, "\t/* %s */\n", prop->name);
1251 fprintf(f, "\t/* */\n");
1253 switch(prop->type) {
1254 case PROP_BOOLEAN: {
1255 if(!prop->arraydimension)
1256 fprintf(f, "\tbool %s(void);", prop->identifier);
1258 fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
1262 if(!prop->arraydimension)
1263 fprintf(f, "\tint %s(void);", prop->identifier);
1265 fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier);
1269 if(!prop->arraydimension)
1270 fprintf(f, "\tfloat %s(void);", prop->identifier);
1272 fprintf(f, "\tArray<float, %d> %s(void);", prop->totarraylength, prop->identifier);
1276 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1280 fprintf(f, "\tenum %s_enum {\n", prop->identifier);
1282 for(i=0; i<eprop->totitem; i++)
1283 if(eprop->item[i].identifier[0])
1284 fprintf(f, "\t\t%s_%s = %d,\n", prop->identifier, eprop->item[i].identifier, eprop->item[i].value);
1286 fprintf(f, "\t};\n");
1289 fprintf(f, "\t%s_enum %s(void);", prop->identifier, prop->identifier);
1293 fprintf(f, "\tstd::string %s(void);", prop->identifier);
1296 case PROP_POINTER: {
1297 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1300 fprintf(f, "\t%s %s(void);", (char*)pprop->type, prop->identifier);
1302 fprintf(f, "\t%s %s(void);", "UnknownType", prop->identifier);
1305 case PROP_COLLECTION: {
1306 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1308 if(cprop->item_type)
1309 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->item_type, srna->identifier, prop->identifier);
1311 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
1319 static void rna_def_property_funcs_impl_cpp(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
1325 if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN))
1328 switch(prop->type) {
1329 case PROP_BOOLEAN: {
1330 if(!prop->arraydimension)
1331 fprintf(f, "\tBOOLEAN_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1333 fprintf(f, "\tBOOLEAN_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1337 if(!prop->arraydimension)
1338 fprintf(f, "\tINT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1340 fprintf(f, "\tINT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1344 if(!prop->arraydimension)
1345 fprintf(f, "\tFLOAT_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1347 fprintf(f, "\tFLOAT_ARRAY_PROPERTY(%s, %d, %s)", srna->identifier, prop->totarraylength, prop->identifier);
1351 fprintf(f, "\tENUM_PROPERTY(%s_enum, %s, %s)", prop->identifier, srna->identifier, prop->identifier);
1356 fprintf(f, "\tSTRING_PROPERTY(%s, %s)", srna->identifier, prop->identifier);
1359 case PROP_POINTER: {
1360 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1363 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", (char*)pprop->type, srna->identifier, prop->identifier);
1365 fprintf(f, "\tPOINTER_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);
1368 case PROP_COLLECTION: {
1369 /*CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1372 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->type, srna->identifier, prop->identifier);
1374 fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier);*/
1382 static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA *dfunc)
1386 PropertyDefRNA *dparm;
1388 char *funcname, *ptrstr, *valstr;
1389 int flag, pout, cptr, first;
1397 funcname= rna_alloc_function_name(srna->identifier, func->identifier, "call");
1399 /* function definition */
1400 fprintf(f, "void %s(bContext *C, ReportList *reports, PointerRNA *_ptr, ParameterList *_parms)", funcname);
1401 fprintf(f, "\n{\n");
1403 /* variable definitions */
1404 if((func->flag & FUNC_NO_SELF)==0) {
1405 if(func->flag & FUNC_USE_SELF_ID)
1406 fprintf(f, "\tstruct ID *_selfid;\n");
1408 if(dsrna->dnaname) fprintf(f, "\tstruct %s *_self;\n", dsrna->dnaname);
1409 else fprintf(f, "\tstruct %s *_self;\n", srna->identifier);
1412 dparm= dfunc->cont.properties.first;
1413 for(; dparm; dparm= dparm->next) {
1414 type = dparm->prop->type;
1415 flag = dparm->prop->flag;
1416 pout = (flag & PROP_OUTPUT);
1417 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1419 if(dparm->prop==func->c_ret)
1420 ptrstr= cptr || dparm->prop->arraydimension ? "*" : "";
1421 /* XXX only arrays and strings are allowed to be dynamic, is this checked anywhere? */
1422 else if (cptr || (flag & PROP_DYNAMIC))
1423 ptrstr= pout ? "**" : "*";
1424 /* fixed size arrays and RNA pointers are pre-allocated on the ParameterList stack, pass a pointer to it */
1425 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1427 /* PROP_THICK_WRAP strings are pre-allocated on the ParameterList stack, but type name for string props is already char*, so leave empty */
1428 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1431 ptrstr= pout ? "*" : "";
1433 fprintf(f, "\t%s%s %s%s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1435 /* for dynamic parameters we pass an additional int for the length of the parameter */
1436 if (flag & PROP_DYNAMIC)
1437 fprintf(f, "\tint %s%s_len;\n", pout ? "*" : "", dparm->prop->identifier);
1440 fprintf(f, "\tchar *_data");
1441 if(func->c_ret) fprintf(f, ", *_retdata");
1446 if((func->flag & FUNC_NO_SELF)==0) {
1447 if(func->flag & FUNC_USE_SELF_ID)
1448 fprintf(f, "\t_selfid= (struct ID*)_ptr->id.data;\n");
1450 if(dsrna->dnaname) fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", dsrna->dnaname);
1451 else fprintf(f, "\t_self= (struct %s *)_ptr->data;\n", srna->identifier);
1454 fprintf(f, "\t_data= (char *)_parms->data;\n");
1456 dparm= dfunc->cont.properties.first;
1457 for(; dparm; dparm= dparm->next) {
1458 type = dparm->prop->type;
1459 flag = dparm->prop->flag;
1460 pout = (flag & PROP_OUTPUT);
1461 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1463 if(dparm->prop==func->c_ret)
1464 fprintf(f, "\t_retdata= _data;\n");
1466 if (cptr || (flag & PROP_DYNAMIC)) {
1470 else if (type == PROP_POINTER || dparm->prop->arraydimension) {
1474 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP)) {
1483 fprintf(f, "\t%s= ", dparm->prop->identifier);
1486 fprintf(f, "%s", valstr);
1488 fprintf(f, "((%s%s%s)_data);\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr);
1490 /* this must be kept in sync with RNA_parameter_length_get_data, we could just call the function directly, but this is faster */
1491 if (flag & PROP_DYNAMIC)
1492 fprintf(f, "\t%s_len= %s((int *)(_data+%d));\n", dparm->prop->identifier, pout ? "" : "*", rna_parameter_size(dparm->prop));
1496 fprintf(f, "\t_data+= %d;\n", rna_parameter_size_alloc(dparm->prop));
1502 if(func->c_ret) fprintf(f, "%s= ", func->c_ret->identifier);
1503 fprintf(f, "%s(", dfunc->call);
1507 if((func->flag & FUNC_NO_SELF)==0) {
1508 if(func->flag & FUNC_USE_SELF_ID)
1509 fprintf(f, "_selfid, ");
1511 fprintf(f, "_self");
1515 if(func->flag & FUNC_USE_CONTEXT) {
1516 if(!first) fprintf(f, ", ");
1521 if(func->flag & FUNC_USE_REPORTS) {
1522 if(!first) fprintf(f, ", ");
1524 fprintf(f, "reports");
1527 dparm= dfunc->cont.properties.first;
1528 for(; dparm; dparm= dparm->next) {
1529 if(dparm->prop==func->c_ret)
1532 if(!first) fprintf(f, ", ");
1535 fprintf(f, "%s", dparm->prop->identifier);
1537 if (dparm->prop->flag & PROP_DYNAMIC)
1538 fprintf(f, ", %s_len", dparm->prop->identifier);
1544 dparm= rna_find_parameter_def(func->c_ret);
1545 ptrstr= (((dparm->prop->type == PROP_POINTER) && !(dparm->prop->flag & PROP_RNAPTR)) || (dparm->prop->arraydimension))? "*": "";
1546 fprintf(f, "\t*((%s%s%s*)_retdata)= %s;\n", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, func->c_ret->identifier);
1550 fprintf(f, "}\n\n");
1552 dfunc->gencall= funcname;
1555 static void rna_auto_types()
1560 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
1561 /* DNA name for Screen is patched in 2.5, we do the reverse here .. */
1562 if(ds->dnaname && strcmp(ds->dnaname, "Screen") == 0)
1563 ds->dnaname= "bScreen";
1565 for(dp=ds->cont.properties.first; dp; dp=dp->next) {
1566 if(dp->dnastructname && strcmp(dp->dnastructname, "Screen") == 0)
1567 dp->dnastructname= "bScreen";
1570 if(dp->prop->type == PROP_POINTER) {
1571 PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop;
1574 if(!pprop->type && !pprop->get)
1575 pprop->type= (StructRNA*)rna_find_type(dp->dnatype);
1578 type= rna_find_struct((char*)pprop->type);
1579 if(type && (type->flag & STRUCT_ID_REFCOUNT))
1580 pprop->property.flag |= PROP_ID_REFCOUNT;
1583 else if(dp->prop->type== PROP_COLLECTION) {
1584 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop;
1586 if(!cprop->item_type && !cprop->get && strcmp(dp->dnatype, "ListBase")==0)
1587 cprop->item_type= (StructRNA*)rna_find_type(dp->dnatype);
1594 static void rna_sort(BlenderRNA *brna)
1599 rna_sortlist(&brna->structs, cmp_struct);
1600 rna_sortlist(&DefRNA.structs, cmp_def_struct);
1602 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1603 rna_sortlist(&srna->cont.properties, cmp_property);
1605 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
1606 rna_sortlist(&ds->cont.properties, cmp_def_property);
1609 static const char *rna_property_structname(PropertyType type)
1612 case PROP_BOOLEAN: return "BooleanPropertyRNA";
1613 case PROP_INT: return "IntPropertyRNA";
1614 case PROP_FLOAT: return "FloatPropertyRNA";
1615 case PROP_STRING: return "StringPropertyRNA";
1616 case PROP_ENUM: return "EnumPropertyRNA";
1617 case PROP_POINTER: return "PointerPropertyRNA";
1618 case PROP_COLLECTION: return "CollectionPropertyRNA";
1619 default: return "UnknownPropertyRNA";
1623 static const char *rna_property_typename(PropertyType type)
1626 case PROP_BOOLEAN: return "PROP_BOOLEAN";
1627 case PROP_INT: return "PROP_INT";
1628 case PROP_FLOAT: return "PROP_FLOAT";
1629 case PROP_STRING: return "PROP_STRING";
1630 case PROP_ENUM: return "PROP_ENUM";
1631 case PROP_POINTER: return "PROP_POINTER";
1632 case PROP_COLLECTION: return "PROP_COLLECTION";
1633 default: return "PROP_UNKNOWN";
1637 static const char *rna_property_subtypename(PropertyType type)
1640 case PROP_NONE: return "PROP_NONE";
1641 case PROP_FILEPATH: return "PROP_FILEPATH";
1642 case PROP_FILENAME: return "PROP_FILENAME";
1643 case PROP_DIRPATH: return "PROP_DIRPATH";
1644 case PROP_UNSIGNED: return "PROP_UNSIGNED";
1645 case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
1646 case PROP_FACTOR: return "PROP_FACTOR";
1647 case PROP_ANGLE: return "PROP_ANGLE";
1648 case PROP_TIME: return "PROP_TIME";
1649 case PROP_DISTANCE: return "PROP_DISTANCE";
1650 case PROP_COLOR: return "PROP_COLOR";
1651 case PROP_TRANSLATION: return "PROP_TRANSLATION";
1652 case PROP_DIRECTION: return "PROP_DIRECTION";
1653 case PROP_MATRIX: return "PROP_MATRIX";
1654 case PROP_EULER: return "PROP_EULER";
1655 case PROP_QUATERNION: return "PROP_QUATERNION";
1656 case PROP_AXISANGLE: return "PROP_AXISANGLE";
1657 case PROP_VELOCITY: return "PROP_VELOCITY";
1658 case PROP_ACCELERATION: return "PROP_ACCELERATION";
1659 case PROP_XYZ: return "PROP_XYZ";
1660 case PROP_COLOR_GAMMA: return "PROP_COLOR_GAMMA";
1661 case PROP_LAYER: return "PROP_LAYER";
1662 case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
1664 /* incase we dont have a type preset that includes the subtype */
1665 if(RNA_SUBTYPE_UNIT(type)) {
1666 return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
1669 return "PROP_SUBTYPE_UNKNOWN";
1675 static const char *rna_property_subtype_unit(PropertyType type)
1677 switch(RNA_SUBTYPE_UNIT(type)) {
1678 case PROP_UNIT_NONE: return "PROP_UNIT_NONE";
1679 case PROP_UNIT_LENGTH: return "PROP_UNIT_LENGTH";
1680 case PROP_UNIT_AREA: return "PROP_UNIT_AREA";
1681 case PROP_UNIT_VOLUME: return "PROP_UNIT_VOLUME";
1682 case PROP_UNIT_MASS: return "PROP_UNIT_MASS";
1683 case PROP_UNIT_ROTATION: return "PROP_UNIT_ROTATION";
1684 case PROP_UNIT_TIME: return "PROP_UNIT_TIME";
1685 case PROP_UNIT_VELOCITY: return "PROP_UNIT_VELOCITY";
1686 case PROP_UNIT_ACCELERATION:return "PROP_UNIT_ACCELERATION";
1687 default: return "PROP_UNKNOWN";
1691 static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
1695 for(srna=brna->structs.first; srna; srna=srna->cont.next)
1696 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
1700 static void rna_generate_blender(BlenderRNA *brna, FILE *f)
1704 fprintf(f, "BlenderRNA BLENDER_RNA = {");
1706 srna= brna->structs.first;
1707 if(srna) fprintf(f, "{&RNA_%s, ", srna->identifier);
1708 else fprintf(f, "{NULL, ");
1710 srna= brna->structs.last;
1711 if(srna) fprintf(f, "&RNA_%s}", srna->identifier);
1712 else fprintf(f, "NULL}");
1714 fprintf(f, "};\n\n");
1717 static void rna_generate_property_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1725 for(prop=base->cont.properties.first; prop; prop=prop->next)
1726 fprintf(f, "%s%s rna_%s_%s;\n", "extern ", rna_property_structname(prop->type), base->identifier, prop->identifier);
1730 if(srna->cont.properties.first)
1733 for(prop=srna->cont.properties.first; prop; prop=prop->next)
1734 fprintf(f, "%s%s rna_%s_%s;\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, prop->identifier);
1738 static void rna_generate_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionRNA *func, FILE *f)
1742 for(parm= func->cont.properties.first; parm; parm= parm->next)
1743 fprintf(f, "%s%s rna_%s_%s_%s;\n", "extern ", rna_property_structname(parm->type), srna->identifier, func->identifier, parm->identifier);
1745 if(func->cont.properties.first)
1749 static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1756 for(func= base->functions.first; func; func= func->cont.next) {
1757 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", base->identifier, func->identifier);
1758 rna_generate_parameter_prototypes(brna, base, func, f);
1761 if(base->functions.first)
1767 for(func= srna->functions.first; func; func= func->cont.next) {
1768 fprintf(f, "%s%s rna_%s_%s_func;\n", "extern ", "FunctionRNA", srna->identifier, func->identifier);
1769 rna_generate_parameter_prototypes(brna, srna, func, f);
1772 if(srna->functions.first)
1776 static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionDefRNA *dfunc, FILE *f)
1779 PropertyDefRNA *dparm;
1780 StructDefRNA *dsrna;
1782 int flag, pout, cptr, first;
1785 dsrna= rna_find_struct_def(srna);
1789 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1790 if(dparm->prop==func->c_ret) {
1791 if(dparm->prop->arraydimension)
1792 fprintf(f, "XXX no array return types yet"); /* XXX not supported */
1793 else if(dparm->prop->type == PROP_POINTER && !(dparm->prop->flag & PROP_RNAPTR))
1794 fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1796 fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
1802 /* void if nothing to return */
1804 fprintf(f, "void ");
1807 fprintf(f, "%s(", dfunc->call);
1811 /* self, context and reports parameters */
1812 if((func->flag & FUNC_NO_SELF)==0) {
1813 if(func->flag & FUNC_USE_SELF_ID)
1814 fprintf(f, "struct ID *_selfid, ");
1816 if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
1817 else fprintf(f, "struct %s *_self", srna->identifier);
1821 if(func->flag & FUNC_USE_CONTEXT) {
1822 if(!first) fprintf(f, ", ");
1824 fprintf(f, "bContext *C");
1827 if(func->flag & FUNC_USE_REPORTS) {
1828 if(!first) fprintf(f, ", ");
1830 fprintf(f, "ReportList *reports");
1833 /* defined parameters */
1834 for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
1835 type = dparm->prop->type;
1836 flag = dparm->prop->flag;
1837 pout = (flag & PROP_OUTPUT);
1838 cptr = ((type == PROP_POINTER) && !(flag & PROP_RNAPTR));
1840 if(dparm->prop==func->c_ret)
1843 if (cptr || (flag & PROP_DYNAMIC))
1844 ptrstr= pout ? "**" : "*";
1845 else if (type == PROP_POINTER || dparm->prop->arraydimension)
1847 else if (type == PROP_STRING && (flag & PROP_THICK_WRAP))
1850 ptrstr= pout ? "*" : "";
1852 if(!first) fprintf(f, ", ");
1855 if(!(flag & PROP_DYNAMIC) && dparm->prop->arraydimension)
1856 fprintf(f, "%s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->totarraylength);
1858 fprintf(f, "%s%s %s%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), ptrstr, dparm->prop->identifier);
1860 if (flag & PROP_DYNAMIC)
1861 fprintf(f, ", int %s%s_len", pout ? "*" : "", dparm->prop->identifier);
1867 static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
1870 FunctionDefRNA *dfunc;
1873 for(func= srna->functions.first; func; func= func->cont.next) {
1874 dfunc= rna_find_function_def(func);
1878 fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
1882 rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
1889 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop)
1891 char *strnest= "", *errnest= "";
1892 int len, freenest= 0;
1897 strnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> strnest");
1898 errnest= MEM_mallocN(sizeof(char)*(len+2), "rna_generate_property -> errnest");
1900 strcpy(strnest, "_"); strcat(strnest, nest);
1901 strcpy(errnest, "."); strcat(errnest, nest);
1906 switch(prop->type) {
1908 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
1909 int i, defaultfound= 0;
1912 fprintf(f, "static EnumPropertyItem rna_%s%s_%s_items[%d] = {\n\t", srna->identifier, strnest, prop->identifier, eprop->totitem+1);
1914 for(i=0; i<eprop->totitem; i++) {
1915 fprintf(f, "{%d, ", eprop->item[i].value);
1916 rna_print_c_string(f, eprop->item[i].identifier); fprintf(f, ", ");
1917 fprintf(f, "%d, ", eprop->item[i].icon);
1918 rna_print_c_string(f, eprop->item[i].name); fprintf(f, ", ");
1919 rna_print_c_string(f, eprop->item[i].description); fprintf(f, "},\n\t");
1921 if(eprop->item[i].identifier[0])
1922 if(eprop->defaultvalue == eprop->item[i].value)
1926 fprintf(f, "{0, NULL, 0, NULL, NULL}\n};\n\n");
1929 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum default is not in items.\n", srna->identifier, errnest, prop->identifier);
1934 fprintf(stderr, "rna_generate_structs: %s%s.%s, enum must have items defined.\n", srna->identifier, errnest, prop->identifier);
1939 case PROP_BOOLEAN: {
1940 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
1943 if(prop->arraydimension && prop->totarraylength) {
1944 fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1946 for(i=0; i<prop->totarraylength; i++) {
1947 if(bprop->defaultarray)
1948 fprintf(f, "%d", bprop->defaultarray[i]);
1950 fprintf(f, "%d", bprop->defaultvalue);
1951 if(i != prop->totarraylength-1)
1952 fprintf(f, ",\n\t");
1955 fprintf(f, "\n};\n\n");
1960 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
1963 if(prop->arraydimension && prop->totarraylength) {
1964 fprintf(f, "static int rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1966 for(i=0; i<prop->totarraylength; i++) {
1967 if(iprop->defaultarray)
1968 fprintf(f, "%d", iprop->defaultarray[i]);
1970 fprintf(f, "%d", iprop->defaultvalue);
1971 if(i != prop->totarraylength-1)
1972 fprintf(f, ",\n\t");
1975 fprintf(f, "\n};\n\n");
1980 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
1983 if(prop->arraydimension && prop->totarraylength) {
1984 fprintf(f, "static float rna_%s%s_%s_default[%d] = {\n\t", srna->identifier, strnest, prop->identifier, prop->totarraylength);
1986 for(i=0; i<prop->totarraylength; i++) {
1987 if(fprop->defaultarray)
1988 rna_float_print(f, fprop->defaultarray[i]);
1990 rna_float_print(f, fprop->defaultvalue);
1991 if(i != prop->totarraylength-1)
1992 fprintf(f, ",\n\t");
1995 fprintf(f, "\n};\n\n");
2003 fprintf(f, "%s%s rna_%s%s_%s = {\n", (prop->flag & PROP_EXPORT)? "": "", rna_property_structname(prop->type), srna->identifier, strnest, prop->identifier);
2005 if(prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
2006 else fprintf(f, "\t{NULL, ");
2007 if(prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
2008 else fprintf(f, "NULL,\n");
2009 fprintf(f, "\t%d, ", prop->magic);
2010 rna_print_c_string(f, prop->identifier);
2011 fprintf(f, ", %d, ", prop->flag);
2012 rna_print_c_string(f, prop->name); fprintf(f, ",\n\t");
2013 rna_print_c_string(f, prop->description); fprintf(f, ",\n\t");
2014 fprintf(f, "%d,\n", prop->icon);
2015 fprintf(f, "\t%s, %s|%s, %s, %d, {%d, %d, %d}, %d,\n", rna_property_typename(prop->type), rna_property_subtypename(prop->subtype), rna_property_subtype_unit(prop->subtype), rna_function_string(prop->getlength), prop->arraydimension, prop->arraylength[0], prop->arraylength[1], prop->arraylength[2], prop->totarraylength);
2016 fprintf(f, "\t%s%s, %d, %s, %s,\n", (prop->flag & PROP_CONTEXT_UPDATE)? "(UpdateFunc)": "", rna_function_string(prop->update), prop->noteflag, rna_function_string(prop->editable), rna_function_string(prop->itemeditable));
2018 if(prop->flag & PROP_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
2019 else fprintf(f, "\t0, -1");
2021 /* our own type - collections/arrays only */
2022 if(prop->srna) fprintf(f, ", &RNA_%s", (char*)prop->srna);
2023 else fprintf(f, ", NULL");
2027 switch(prop->type) {
2028 case PROP_BOOLEAN: {
2029 BooleanPropertyRNA *bprop= (BooleanPropertyRNA*)prop;
2030 fprintf(f, "\t%s, %s, %s, %s, %d, ", rna_function_string(bprop->get), rna_function_string(bprop->set), rna_function_string(bprop->getarray), rna_function_string(bprop->setarray), bprop->defaultvalue);
2031 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2032 else fprintf(f, "NULL\n");
2036 IntPropertyRNA *iprop= (IntPropertyRNA*)prop;
2037 fprintf(f, "\t%s, %s, %s, %s, %s,\n\t", rna_function_string(iprop->get), rna_function_string(iprop->set), rna_function_string(iprop->getarray), rna_function_string(iprop->setarray), rna_function_string(iprop->range));
2038 rna_int_print(f, iprop->softmin); fprintf(f, ", ");
2039 rna_int_print(f, iprop->softmax); fprintf(f, ", ");
2040 rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
2041 rna_int_print(f, iprop->hardmax); fprintf(f, ", ");
2042 rna_int_print(f, iprop->step); fprintf(f, ", ");
2043 rna_int_print(f, iprop->defaultvalue); fprintf(f, ", ");
2044 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2045 else fprintf(f, "NULL\n");
2049 FloatPropertyRNA *fprop= (FloatPropertyRNA*)prop;
2050 fprintf(f, "\t%s, %s, %s, %s, %s, ", rna_function_string(fprop->get), rna_function_string(fprop->set), rna_function_string(fprop->getarray), rna_function_string(fprop->setarray), rna_function_string(fprop->range));
2051 rna_float_print(f, fprop->softmin); fprintf(f, ", ");
2052 rna_float_print(f, fprop->softmax); fprintf(f, ", ");
2053 rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
2054 rna_float_print(f, fprop->hardmax); fprintf(f, ", ");
2055 rna_float_print(f, fprop->step); fprintf(f, ", ");
2056 rna_int_print(f, (int)fprop->precision); fprintf(f, ", ");
2057 rna_float_print(f, fprop->defaultvalue); fprintf(f, ", ");
2058 if(prop->arraydimension && prop->totarraylength) fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
2059 else fprintf(f, "NULL\n");
2063 StringPropertyRNA *sprop= (StringPropertyRNA*)prop;
2064 fprintf(f, "\t%s, %s, %s, %d, ", rna_function_string(sprop->get), rna_function_string(sprop->length), rna_function_string(sprop->set), sprop->maxlength);
2065 rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
2069 EnumPropertyRNA *eprop= (EnumPropertyRNA*)prop;
2070 fprintf(f, "\t%s, %s, %s, ", rna_function_string(eprop->get), rna_function_string(eprop->set), rna_function_string(eprop->itemf));
2072 fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
2074 fprintf(f, "NULL, ");
2075 fprintf(f, "%d, %d\n", eprop->totitem, eprop->defaultvalue);
2078 case PROP_POINTER: {
2079 PointerPropertyRNA *pprop= (PointerPropertyRNA*)prop;
2080 fprintf(f, "\t%s, %s, %s, ", rna_function_string(pprop->get), rna_function_string(pprop->set), rna_function_string(pprop->typef));
2081 if(pprop->type) fprintf(f, "&RNA_%s\n", (char*)pprop->type);
2082 else fprintf(f, "NULL\n");
2085 case PROP_COLLECTION: {
2086 CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)prop;
2087 fprintf(f, "\t%s, %s, %s, %s, %s, %s, %s, ", rna_function_string(cprop->begin), rna_function_string(cprop->next), rna_function_string(cprop->end), rna_function_string(cprop->get), rna_function_string(cprop->length), rna_function_string(cprop->lookupint), rna_function_string(cprop->lookupstring));
2088 if(cprop->item_type) fprintf(f, "&RNA_%s\n", (char*)cprop->item_type);
2089 else fprintf(f, "NULL\n");
2094 fprintf(f, "};\n\n");
2102 static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
2105 FunctionDefRNA *dfunc;
2106 PropertyRNA *prop, *parm;
2109 fprintf(f, "/* %s */\n", srna->name);
2111 for(prop= srna->cont.properties.first; prop; prop= prop->next)
2112 rna_generate_property(f, srna, NULL, prop);
2114 for(func= srna->functions.first; func; func= func->cont.next) {
2115 for(parm= func->cont.properties.first; parm; parm= parm->next)
2116 rna_generate_property(f, srna, func->identifier, parm);
2118 fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
2120 if(func->cont.next) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, ((FunctionRNA*)func->cont.next)->identifier);
2121 else fprintf(f, "\t{NULL, ");
2122 if(func->cont.prev) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier, ((FunctionRNA*)func->cont.prev)->identifier);
2123 else fprintf(f, "NULL,\n");
2125 fprintf(f, "\tNULL,\n");
2127 parm= func->cont.properties.first;
2128 if(parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
2129 else fprintf(f, "\t{NULL, ");
2131 parm= func->cont.properties.last;
2132 if(parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
2133 else fprintf(f, "NULL}},\n");
2136 rna_print_c_string(f, func->identifier);
2137 fprintf(f, ", %d, ", func->flag);
2138 rna_print_c_string(f, func->description); fprintf(f, ",\n");
2140 dfunc= rna_find_function_def(func);
2141 if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
2142 else fprintf(f, "\tNULL,\n");
2144 if(func->c_ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
2145 else fprintf(f, "\tNULL\n");
2151 fprintf(f, "StructRNA RNA_%s = {\n", srna->identifier);
2153 if(srna->cont.next) fprintf(f, "\t{(ContainerRNA *)&RNA_%s, ", ((StructRNA*)srna->cont.next)->identifier);
2154 else fprintf(f, "\t{NULL, ");
2155 if(srna->cont.prev) fprintf(f, "(ContainerRNA *)&RNA_%s,\n", ((StructRNA*)srna->cont.prev)->identifier);
2156 else fprintf(f, "NULL,\n");
2158 fprintf(f, "\tNULL,\n");
2160 prop= srna->cont.properties.first;
2161 if(prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
2162 else fprintf(f, "\t{NULL, ");
2164 prop= srna->cont.properties.last;
2165 if(prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
2166 else fprintf(f, "NULL}},\n");
2168 fprintf(f, "\tNULL,NULL,\n"); /* PyType - Cant initialize here */
2171 rna_print_c_string(f, srna->identifier);
2172 fprintf(f, ", %d, ", srna->flag);
2173 rna_print_c_string(f, srna->name);
2175 rna_print_c_string(f, srna->description);
2176 fprintf(f, ",\n\t%d,\n", srna->icon);
2178 prop= srna->nameproperty;
2181 while (base->base && base->base->nameproperty==prop)
2184 fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
2186 else fprintf(f, "\tNULL, ");
2188 prop= srna->iteratorproperty;
2190 while (base->base && base->base->iteratorproperty==prop)
2192 fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
2194 if(srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
2195 else fprintf(f, "\tNULL,\n");
2197 if(srna->nested) fprintf(f, "\t&RNA_%s,\n", srna->nested->identifier);
2198 else fprintf(f, "\tNULL,\n");
2200 fprintf(f, "\t%s,\n", rna_function_string(srna->refine));
2201 fprintf(f, "\t%s,\n", rna_function_string(srna->path));
2202 fprintf(f, "\t%s,\n", rna_function_string(srna->reg));
2203 fprintf(f, "\t%s,\n", rna_function_string(srna->unreg));
2204 fprintf(f, "\t%s,\n", rna_function_string(srna->idproperties));
2206 if(srna->reg && !srna->refine) {
2207 fprintf(stderr, "rna_generate_struct: %s has a register function, must also have refine function.\n", srna->identifier);
2211 func= srna->functions.first;
2212 if(func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
2213 else fprintf(f, "\t{NULL, ");
2215 func= srna->functions.last;
2216 if(func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
2217 else fprintf(f, "NULL}\n");
2224 typedef struct RNAProcessItem {
2227 void (*define)(BlenderRNA *brna);
2230 RNAProcessItem PROCESS_ITEMS[]= {
2231 {"rna_rna.c", NULL, RNA_def_rna},
2232 {"rna_ID.c", NULL, RNA_def_ID},
2233 {"rna_texture.c", NULL, RNA_def_texture},
2234 {"rna_action.c", "rna_action_api.c", RNA_def_action},
2235 {"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
2236 {"rna_animviz.c", NULL, RNA_def_animviz},
2237 {"rna_actuator.c", NULL, RNA_def_actuator},
2238 {"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
2239 {"rna_boid.c", NULL, RNA_def_boid},
2240 {"rna_brush.c", NULL, RNA_def_brush},
2241 {"rna_camera.c", NULL, RNA_def_camera},
2242 {"rna_cloth.c", NULL, RNA_def_cloth},
2243 {"rna_color.c", NULL, RNA_def_color},
2244 {"rna_constraint.c", NULL, RNA_def_constraint},
2245 {"rna_context.c", NULL, RNA_def_context},
2246 {"rna_controller.c", NULL, RNA_def_controller},
2247 {"rna_curve.c", NULL, RNA_def_curve},
2248 {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
2249 {"rna_fluidsim.c", NULL, RNA_def_fluidsim},
2250 {"rna_gpencil.c", NULL, RNA_def_gpencil},
2251 {"rna_group.c", NULL, RNA_def_group},
2252 {"rna_image.c", "rna_image_api.c", RNA_def_image},
2253 {"rna_key.c", NULL, RNA_def_key},
2254 {"rna_lamp.c", NULL, RNA_def_lamp},
2255 {"rna_lattice.c", NULL, RNA_def_lattice},
2256 {"rna_main.c", "rna_main_api.c", RNA_def_main},
2257 {"rna_material.c", "rna_material_api.c", RNA_def_material},
2258 {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
2259 {"rna_meta.c", NULL, RNA_def_meta},
2260 {"rna_modifier.c", NULL, RNA_def_modifier},
2261 {"rna_nla.c", NULL, RNA_def_nla},
2262 {"rna_nodetree.c", NULL, RNA_def_nodetree},
2263 {"rna_object.c", "rna_object_api.c", RNA_def_object},
2264 {"rna_object_force.c", NULL, RNA_def_object_force},
2265 {"rna_packedfile.c", NULL, RNA_def_packedfile},
2266 {"rna_particle.c", NULL, RNA_def_particle},
2267 {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
2268 {"rna_property.c", NULL, RNA_def_gameproperty},
2269 {"rna_render.c", NULL, RNA_def_render},
2270 {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
2271 {"rna_screen.c", NULL, RNA_def_screen},
2272 {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
2273 {"rna_sensor.c", NULL, RNA_def_sensor},
2274 {"rna_sequencer.c", NULL, RNA_def_sequencer},
2275 {"rna_smoke.c", NULL, RNA_def_smoke},
2276 {"rna_space.c", NULL, RNA_def_space},
2277 {"rna_test.c", NULL, RNA_def_test},
2278 {"rna_text.c", NULL, RNA_def_text},
2279 {"rna_timeline.c", NULL, RNA_def_timeline_marker},
2280 {"rna_sound.c", NULL, RNA_def_sound},
2281 {"rna_ui.c", "rna_ui_api.c", RNA_def_ui},
2282 {"rna_userdef.c", NULL, RNA_def_userdef},
2283 {"rna_vfont.c", NULL, RNA_def_vfont},
2284 {"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
2285 {"rna_world.c", NULL, RNA_def_world},
2288 static void rna_generate(BlenderRNA *brna, FILE *f, char *filename, char *api_filename)
2292 FunctionDefRNA *dfunc;
2294 fprintf(f, "\n/* Automatically generated struct definitions for the Data API.\n"
2295 " Do not edit manually, changes will be overwritten. */\n\n"
2296 "#define RNA_RUNTIME\n\n");
2298 fprintf(f, "#include <float.h>\n");
2299 fprintf(f, "#include <limits.h>\n");
2300 fprintf(f, "#include <string.h>\n\n");
2301 fprintf(f, "#include <stddef.h>\n\n");
2303 fprintf(f, "#include \"DNA_ID.h\"\n");
2304 fprintf(f, "#include \"DNA_scene_types.h\"\n");
2306 fprintf(f, "#include \"BLI_blenlib.h\"\n\n");
2308 fprintf(f, "#include \"BKE_context.h\"\n");
2309 fprintf(f, "#include \"BKE_library.h\"\n");
2310 fprintf(f, "#include \"BKE_main.h\"\n");
2311 fprintf(f, "#include \"BKE_report.h\"\n");
2312 fprintf(f, "#include \"BKE_utildefines.h\"\n\n");
2314 fprintf(f, "#include \"RNA_define.h\"\n");
2315 fprintf(f, "#include \"RNA_types.h\"\n");
2316 fprintf(f, "#include \"rna_internal.h\"\n\n");
2318 rna_generate_prototypes(brna, f);
2320 fprintf(f, "#include \"%s\"\n", filename);
2322 fprintf(f, "#include \"%s\"\n", api_filename);
2325 fprintf(f, "/* Autogenerated Functions */\n\n");
2327 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2328 if(!filename || ds->filename == filename) {
2329 rna_generate_property_prototypes(brna, ds->srna, f);
2330 rna_generate_function_prototypes(brna, ds->srna, f);
2334 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2335 if(!filename || ds->filename == filename)
2336 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2337 rna_def_property_funcs(f, ds->srna, dp);
2339 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2340 if(!filename || ds->filename == filename) {
2341 for(dfunc=ds->functions.first; dfunc; dfunc= dfunc->cont.next)
2342 rna_def_function_funcs(f, ds, dfunc);
2344 rna_generate_static_function_prototypes(brna, ds->srna, f);
2348 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2349 if(!filename || ds->filename == filename)
2350 rna_generate_struct(brna, ds->srna, f);
2352 if(strcmp(filename, "rna_ID.c") == 0) {
2353 /* this is ugly, but we cannot have c files compiled for both
2354 * makesrna and blender with some build systems at the moment */
2355 fprintf(f, "#include \"rna_define.c\"\n\n");
2357 rna_generate_blender(brna, f);
2361 static void rna_generate_header(BlenderRNA *brna, FILE *f)
2367 fprintf(f, "\n#ifndef __RNA_BLENDER_H__\n");
2368 fprintf(f, "#define __RNA_BLENDER_H__\n\n");
2370 fprintf(f, "/* Automatically generated function declarations for the Data API.\n"
2371 " Do not edit manually, changes will be overwritten. */\n\n");
2373 fprintf(f, "#include \"RNA_types.h\"\n\n");
2375 fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n");
2377 fprintf(f, "#define FOREACH_BEGIN(property, sptr, itemptr) \\\n");
2378 fprintf(f, " { \\\n");
2379 fprintf(f, " CollectionPropertyIterator rna_macro_iter; \\\n");
2380 fprintf(f, " for(property##_begin(&rna_macro_iter, sptr); rna_macro_iter.valid; property##_next(&rna_macro_iter)) { \\\n");
2381 fprintf(f, " itemptr= rna_macro_iter.ptr;\n\n");
2383 fprintf(f, "#define FOREACH_END(property) \\\n");
2384 fprintf(f, " } \\\n");
2385 fprintf(f, " property##_end(&rna_macro_iter); \\\n");
2386 fprintf(f, " }\n\n");
2388 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2391 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2394 fprintf(f, "extern StructRNA RNA_%s;\n", srna->identifier);
2399 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2400 rna_def_property_funcs_header(f, ds->srna, dp);
2403 fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n");
2405 fprintf(f, "#endif /* __RNA_BLENDER_H__ */\n\n");
2408 static const char *cpp_classes = ""
2410 "#include <string>\n"
2414 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
2415 " bool sname::identifier(void) { return (bool)sname##_##identifier##_get(&ptr); }\n"
2417 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2418 " Array<int,size> sname::identifier(void) \\\n"
2419 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2421 "#define INT_PROPERTY(sname, identifier) \\\n"
2422 " int sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2424 "#define INT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2425 " Array<int,size> sname::identifier(void) \\\n"
2426 " { Array<int, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2428 "#define FLOAT_PROPERTY(sname, identifier) \\\n"
2429 " float sname::identifier(void) { return sname##_##identifier##_get(&ptr); }\n"
2431 "#define FLOAT_ARRAY_PROPERTY(sname, size, identifier) \\\n"
2432 " Array<float,size> sname::identifier(void) \\\n"
2433 " { Array<float, size> ar; sname##_##identifier##_get(&ptr, ar.data); return ar; }\n"
2435 "#define ENUM_PROPERTY(type, sname, identifier) \\\n"
2436 " sname::type sname::identifier(void) { return (type)sname##_##identifier##_get(&ptr); }\n"
2438 "#define STRING_PROPERTY(sname, identifier) \\\n"
2439 " std::string sname::identifier(void) { \\\n"
2440 " int len= sname##_##identifier##_length(&ptr); \\\n"
2441 " std::string str; str.resize(len); \\\n"
2442 " sname##_##identifier##_get(&ptr, &str[0]); return str; } \\\n"
2444 "#define POINTER_PROPERTY(type, sname, identifier) \\\n"
2445 " type sname::identifier(void) { return type(sname##_##identifier##_get(&ptr)); }\n"
2447 "#define COLLECTION_PROPERTY(type, sname, identifier) \\\n"
2448 " typedef CollectionIterator<type, sname##_##identifier##_begin, \\\n"
2449 " sname##_##identifier##_next, sname##_##identifier##_end> identifier##_iterator; \\\n"
2450 " Collection<sname, type, sname##_##identifier##_begin, \\\n"
2451 " sname##_##identifier##_next, sname##_##identifier##_end> identifier;\n"
2455 " Pointer(const PointerRNA& p) : ptr(p) { }\n"
2456 " operator const PointerRNA&() { return ptr; }\n"
2457 " bool is_a(StructRNA *type) { return RNA_struct_is_a(&ptr, type); }\n"
2458 " operator void*() { return ptr.data; }\n"
2459 " operator bool() { return ptr.data != NULL; }\n"
2461 " PointerRNA ptr;\n"
2465 "template<typename T, int Tsize>\n"
2469 " operator T*() { return data; }\n"
2472 "typedef void (*TBeginFunc)(CollectionPropertyIterator *iter, PointerRNA *ptr);\n"
2473 "typedef void (*TNextFunc)(CollectionPropertyIterator *iter);\n"
2474 "typedef void (*TEndFunc)(CollectionPropertyIterator *iter);\n"
2476 "template<typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2477 "class CollectionIterator {\n"
2479 " CollectionIterator() : t(iter.ptr), init(false) { iter.valid= false; }\n"
2480 " ~CollectionIterator(void) { if(init) Tend(&iter); };\n"
2481 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator=(const CollectionIterator<T, Tbegin, Tnext, Tend>& copy)\n"
2482 " { if(init) Tend(&iter); iter= copy.iter; if(iter.internal) iter.internal= MEM_dupallocN(iter.internal); t= copy.t; init= copy.init; return *this; }\n"
2484 " operator bool(void)\n"
2485 " { return iter.valid != 0; }\n"
2486 " const CollectionIterator<T, Tbegin, Tnext, Tend>& operator++() { Tnext(&iter); t = T(iter.ptr); return *this; }\n"
2487 " T& operator*(void) { return t; }\n"
2488 " T* operator->(void) { return &t; }\n"
2489 " bool operator==(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid == other.iter.valid; }\n"
2490 " bool operator!=(const CollectionIterator<T, Tbegin, Tnext, Tend>& other) { return iter.valid != other.iter.valid; }\n"
2492 " void begin(const Pointer& ptr)\n"
2493 " { if(init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
2496 " CollectionPropertyIterator iter;\n"
2501 "template<typename Tp, typename T, TBeginFunc Tbegin, TNextFunc Tnext, TEndFunc Tend>\n"
2502 "class Collection {\n"
2504 " Collection(const PointerRNA& p) : ptr(p) {}\n"
2506 " CollectionIterator<T, Tbegin, Tnext, Tend> begin()\n"
2507 " { CollectionIterator<T, Tbegin, Tnext, Tend> iter; iter.begin(ptr); return iter; }\n"
2508 " CollectionIterator<T, Tbegin, Tnext, Tend> end()\n"
2509 " { return CollectionIterator<T, Tbegin, Tnext, Tend>(); } /* test */ \n"
2512 " PointerRNA ptr;\n"
2516 static void rna_generate_header_cpp(BlenderRNA *brna, FILE *f)
2522 fprintf(f, "\n#ifndef __RNA_BLENDER_CPP_H__\n");
2523 fprintf(f, "#define __RNA_BLENDER_CPP_H__\n\n");
2525 fprintf(f, "/* Automatically generated classes for the Data API.\n"
2526 " Do not edit manually, changes will be overwritten. */\n\n");
2528 fprintf(f, "#include \"RNA_blender.h\"\n");
2529 fprintf(f, "#include \"RNA_types.h\"\n");
2531 fprintf(f, "%s", cpp_classes);
2533 fprintf(f, "/**************** Declarations ****************/\n\n");
2535 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2536 fprintf(f, "class %s;\n", ds->srna->identifier);
2539 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2542 fprintf(f, "/**************** %s ****************/\n\n", srna->name);
2544 fprintf(f, "class %s : public %s {\n", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2545 fprintf(f, "public:\n");
2546 fprintf(f, "\t%s(const PointerRNA& ptr) :\n\t\t%s(ptr)", srna->identifier, (srna->base)? srna->base->identifier: "Pointer");
2547 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2548 if(!(dp->prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN)))
2549 if(dp->prop->type == PROP_COLLECTION)
2550 fprintf(f, ",\n\t\t%s(ptr)", dp->prop->identifier);
2551 fprintf(f, "\n\t\t{}\n\n");
2553 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2554 rna_def_property_funcs_header_cpp(f, ds->srna, dp);
2555 fprintf(f, "};\n\n");
2559 fprintf(f, "/**************** Implementation ****************/\n");
2561 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
2562 for(dp=ds->cont.properties.first; dp; dp=dp->next)
2563 rna_def_property_funcs_impl_cpp(f, ds->srna, dp);
2568 fprintf(f, "}\n\n#endif /* __RNA_BLENDER_CPP_H__ */\n\n");
2571 static void make_bad_file(char *file, int line)
2573 FILE *fp= fopen(file, "w");
2574 fprintf(fp, "#error \"Error! can't make correct RNA file from %s:%d, STUPID!\"\n", __FILE__, line);
2578 static int rna_preprocess(char *outfile)
2589 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2590 if(PROCESS_ITEMS[i].define) {
2591 PROCESS_ITEMS[i].define(brna);
2593 for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
2595 ds->filename= PROCESS_ITEMS[i].filename;
2602 /* create RNA_blender_cpp.h */
2603 strcpy(deffile, outfile);
2604 strcat(deffile, "RNA_blender_cpp.h" TMP_EXT);
2606 status= (DefRNA.error != 0);
2609 make_bad_file(deffile, __LINE__);
2612 file = fopen(deffile, "w");
2615 printf ("Unable to open file: %s\n", deffile);
2619 rna_generate_header_cpp(brna, file);
2621 status= (DefRNA.error != 0);
2625 replace_if_different(deffile);
2629 /* create rna_gen_*.c files */
2630 for(i=0; PROCESS_ITEMS[i].filename; i++) {
2631 strcpy(deffile, outfile);
2632 strcat(deffile, PROCESS_ITEMS[i].filename);
2633 deffile[strlen(deffile)-2] = '\0';
2634 strcat(deffile, "_gen.c" TMP_EXT);
2637 make_bad_file(deffile, __LINE__);
2640 file = fopen(deffile, "w");
2643 printf ("Unable to open file: %s\n", deffile);
2647 rna_generate(brna, file, PROCESS_ITEMS[i].filename, PROCESS_ITEMS[i].api_filename);
2649 status= (DefRNA.error != 0);
2653 replace_if_different(deffile);
2656 /* create RNA_blender.h */
2657 strcpy(deffile, outfile);
2658 strcat(deffile, "RNA_blender.h" TMP_EXT);
2661 make_bad_file(deffile, __LINE__);
2664 file = fopen(deffile, "w");
2667 printf ("Unable to open file: %s\n", deffile);
2671 rna_generate_header(brna, file);
2673 status= (DefRNA.error != 0);
2677 replace_if_different(deffile);
2680 RNA_define_free(brna);
2686 static void mem_error_cb(const char *errorStr)
2688 fprintf(stderr, "%s", errorStr);
2692 int main(int argc, char **argv)
2694 int totblock, return_status = 0;
2697 printf("Usage: %s outdirectory/\n", argv[0]);
2701 printf("Running makesrna, program versions %s\n", RNA_VERSION_DATE);
2702 return_status= rna_preprocess(argv[1]);
2705 totblock= MEM_get_memory_blocks_in_use();
2707 printf("Error Totblock: %d\n",totblock);
2708 MEM_set_error_callback(mem_error_cb);
2712 return return_status;