use bool for rna funcs.
[blender.git] / source / blender / makesrna / intern / makesrna.c
index 2785a95ddb009e7e37ad368a5493778c9cdeefbc..f3891c20ab55b00e1202a8eff5318c8f33dbf063 100644 (file)
@@ -24,7 +24,6 @@
  *  \ingroup RNA
  */
 
-
 #include <float.h>
 #include <limits.h>
 #include <stdio.h>
@@ -34,6 +33,8 @@
 
 #include "MEM_guardedalloc.h"
 
+#include "BLI_utildefines.h"
+
 #include "RNA_access.h"
 #include "RNA_define.h"
 #include "RNA_types.h"
@@ -415,10 +416,10 @@ static const char *rna_type_type_name(PropertyRNA *prop)
                        return "float";
                case PROP_STRING:
                        if (prop->flag & PROP_THICK_WRAP) {
-                               return "char*";
+                               return "char *";
                        }
                        else {
-                               return "const char*";
+                               return "const char *";
                        }
                default:
                        return NULL;
@@ -870,16 +871,16 @@ static char *rna_def_property_set_func(FILE *f, StructRNA *srna, PropertyRNA *pr
 
                                if (prop->flag & PROP_ID_REFCOUNT) {
                                        fprintf(f, "\n  if (data->%s)\n", dp->dnaname);
-                                       fprintf(f, "            id_us_min((ID*)data->%s);\n", dp->dnaname);
+                                       fprintf(f, "            id_us_min((ID *)data->%s);\n", dp->dnaname);
                                        fprintf(f, "    if (value.data)\n");
-                                       fprintf(f, "            id_us_plus((ID*)value.data);\n\n");
+                                       fprintf(f, "            id_us_plus((ID *)value.data);\n\n");
                                }
                                else {
                                        PointerPropertyRNA *pprop = (PointerPropertyRNA *)dp->prop;
                                        StructRNA *type = rna_find_struct((const char *)pprop->type);
                                        if (type && (type->flag & STRUCT_ID)) {
                                                fprintf(f, "    if (value.data)\n");
-                                               fprintf(f, "            id_lib_extern((ID*)value.data);\n\n");
+                                               fprintf(f, "            id_lib_extern((ID *)value.data);\n\n");
                                        }
                                }
 
@@ -1084,7 +1085,7 @@ static char *rna_def_property_begin_func(FILE *f, StructRNA *srna, PropertyRNA *
 
        fprintf(f, "\n  memset(iter, 0, sizeof(*iter));\n");
        fprintf(f, "    iter->parent= *ptr;\n");
-       fprintf(f, "    iter->prop= (PropertyRNA*)&rna_%s_%s;\n", srna->identifier, prop->identifier);
+       fprintf(f, "    iter->prop= (PropertyRNA *)&rna_%s_%s;\n", srna->identifier, prop->identifier);
 
        if (dp->dnalengthname || dp->dnalengthfixed) {
                if (manualfunc) {
@@ -1768,7 +1769,7 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
                        const char *collection_funcs = "DefaultCollectionFunctions";
 
                        if (!(dp->prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN)) && cprop->property.srna)
-                               collection_funcs  = (char*)cprop->property.srna;
+                               collection_funcs  = (char *)cprop->property.srna;
 
                        if (cprop->item_type)
                                fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s, %s, %s, %s, %s)", collection_funcs, (const char *)cprop->item_type, srna->identifier,
@@ -1798,7 +1799,7 @@ static const char *rna_parameter_type_cpp_name(PropertyRNA *prop)
        }
 }
 
-static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *srna, FunctionDefRNA *dfunc,
+static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *UNUSED(srna), FunctionDefRNA *dfunc,
                                                   const char *namespace, int close_prototype)
 {
        PropertyDefRNA *dp;
@@ -2444,7 +2445,6 @@ static const char *rna_property_subtypename(PropertySubType type)
                case PROP_FILENAME: return "PROP_FILENAME";
                case PROP_DIRPATH: return "PROP_DIRPATH";
                case PROP_BYTESTRING: return "PROP_BYTESTRING";
-               case PROP_TRANSLATE: return "PROP_TRANSLATE";
                case PROP_UNSIGNED: return "PROP_UNSIGNED";
                case PROP_PERCENTAGE: return "PROP_PERCENTAGE";
                case PROP_FACTOR: return "PROP_FACTOR";
@@ -2466,7 +2466,8 @@ static const char *rna_property_subtypename(PropertySubType type)
                case PROP_LAYER: return "PROP_LAYER";
                case PROP_LAYER_MEMBER: return "PROP_LAYER_MEMBER";
                case PROP_PASSWORD: return "PROP_PASSWORD";
-               default: {
+               default:
+               {
                        /* in case we don't have a type preset that includes the subtype */
                        if (RNA_SUBTYPE_UNIT(type)) {
                                return rna_property_subtypename(type & ~RNA_SUBTYPE_UNIT(type));
@@ -2906,9 +2907,9 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                rna_property_structname(prop->type),
                srna->identifier, strnest, prop->identifier);
 
-       if (prop->next) fprintf(f, "\t{(PropertyRNA*)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
+       if (prop->next) fprintf(f, "\t{(PropertyRNA *)&rna_%s%s_%s, ", srna->identifier, strnest, prop->next->identifier);
        else fprintf(f, "\t{NULL, ");
-       if (prop->prev) fprintf(f, "(PropertyRNA*)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
+       if (prop->prev) fprintf(f, "(PropertyRNA *)&rna_%s%s_%s,\n", srna->identifier, strnest, prop->prev->identifier);
        else fprintf(f, "NULL,\n");
        fprintf(f, "\t%d, ", prop->magic);
        rna_print_c_string(f, prop->identifier);
@@ -2947,11 +2948,15 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_BOOLEAN:
                {
                        BoolPropertyRNA *bprop = (BoolPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %d, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %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),
+                               rna_function_string(bprop->get_ex),
+                               rna_function_string(bprop->set_ex),
+                               rna_function_string(bprop->getarray_ex),
+                               rna_function_string(bprop->setarray_ex),
                                bprop->defaultvalue);
                        if (prop->arraydimension && prop->totarraylength)
                                fprintf(f, "rna_%s%s_%s_default\n", srna->identifier, strnest, prop->identifier);
@@ -2961,12 +2966,17 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_INT:
                {
                        IntPropertyRNA *iprop = (IntPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %s,\n\t",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %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));
+                               rna_function_string(iprop->range),
+                               rna_function_string(iprop->get_ex),
+                               rna_function_string(iprop->set_ex),
+                               rna_function_string(iprop->getarray_ex),
+                               rna_function_string(iprop->setarray_ex),
+                               rna_function_string(iprop->range_ex));
                        rna_int_print(f, iprop->softmin); fprintf(f, ", ");
                        rna_int_print(f, iprop->softmax); fprintf(f, ", ");
                        rna_int_print(f, iprop->hardmin); fprintf(f, ", ");
@@ -2981,12 +2991,17 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_FLOAT:
                {
                        FloatPropertyRNA *fprop = (FloatPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %s, %s, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %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));
+                               rna_function_string(fprop->range),
+                               rna_function_string(fprop->get_ex),
+                               rna_function_string(fprop->set_ex),
+                               rna_function_string(fprop->getarray_ex),
+                               rna_function_string(fprop->setarray_ex),
+                               rna_function_string(fprop->range_ex));
                        rna_float_print(f, fprop->softmin); fprintf(f, ", ");
                        rna_float_print(f, fprop->softmax); fprintf(f, ", ");
                        rna_float_print(f, fprop->hardmin); fprintf(f, ", ");
@@ -3002,10 +3017,13 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_STRING:
                {
                        StringPropertyRNA *sprop = (StringPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, %d, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, %s, %d, ",
                                rna_function_string(sprop->get),
                                rna_function_string(sprop->length),
                                rna_function_string(sprop->set),
+                               rna_function_string(sprop->get_ex),
+                               rna_function_string(sprop->length_ex),
+                               rna_function_string(sprop->set_ex),
                                sprop->maxlength);
                        rna_print_c_string(f, sprop->defaultvalue); fprintf(f, "\n");
                        break;
@@ -3013,10 +3031,12 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
                case PROP_ENUM:
                {
                        EnumPropertyRNA *eprop = (EnumPropertyRNA *)prop;
-                       fprintf(f, "\t%s, %s, %s, NULL, ",
+                       fprintf(f, "\t%s, %s, %s, %s, %s, NULL, ",
                                rna_function_string(eprop->get),
                                rna_function_string(eprop->set),
-                               rna_function_string(eprop->itemf));
+                               rna_function_string(eprop->itemf),
+                               rna_function_string(eprop->get_ex),
+                               rna_function_string(eprop->set_ex));
                        if (eprop->item)
                                fprintf(f, "rna_%s%s_%s_items, ", srna->identifier, strnest, prop->identifier);
                        else
@@ -3080,12 +3100,12 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                fprintf(f, "%s%s rna_%s_%s_func = {\n", "", "FunctionRNA", srna->identifier, func->identifier);
 
                if (func->cont.next)
-                       fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier,
+                       fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier,
                                ((FunctionRNA *)func->cont.next)->identifier);
                else
                        fprintf(f, "\t{NULL, ");
                if (func->cont.prev)
-                       fprintf(f, "(FunctionRNA*)&rna_%s_%s_func,\n", srna->identifier,
+                       fprintf(f, "(FunctionRNA *)&rna_%s_%s_func,\n", srna->identifier,
                                ((FunctionRNA *)func->cont.prev)->identifier);
                else
                        fprintf(f, "NULL,\n");
@@ -3093,11 +3113,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                fprintf(f, "\tNULL,\n");
 
                parm = func->cont.properties.first;
-               if (parm) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
+               if (parm) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s_%s, ", srna->identifier, func->identifier, parm->identifier);
                else fprintf(f, "\t{NULL, ");
 
                parm = func->cont.properties.last;
-               if (parm) fprintf(f, "(PropertyRNA*)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
+               if (parm) fprintf(f, "(PropertyRNA *)&rna_%s_%s_%s}},\n", srna->identifier, func->identifier, parm->identifier);
                else fprintf(f, "NULL}},\n");
 
                fprintf(f, "\t");
@@ -3110,7 +3130,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                else fprintf(f, "\tNULL,\n");
 
                if (func->c_ret)
-                       fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
+                       fprintf(f, "\t(PropertyRNA *)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->c_ret->identifier);
                else
                        fprintf(f, "\tNULL\n");
 
@@ -3128,11 +3148,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        fprintf(f, "\tNULL,\n");
 
        prop = srna->cont.properties.first;
-       if (prop) fprintf(f, "\t{(PropertyRNA*)&rna_%s_%s, ", srna->identifier, prop->identifier);
+       if (prop) fprintf(f, "\t{(PropertyRNA *)&rna_%s_%s, ", srna->identifier, prop->identifier);
        else fprintf(f, "\t{NULL, ");
 
        prop = srna->cont.properties.last;
-       if (prop) fprintf(f, "(PropertyRNA*)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
+       if (prop) fprintf(f, "(PropertyRNA *)&rna_%s_%s}},\n", srna->identifier, prop->identifier);
        else fprintf(f, "NULL}},\n");
        fprintf(f, "\t");
        rna_print_c_string(f, srna->identifier);
@@ -3151,7 +3171,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
                while (base->base && base->base->nameproperty == prop)
                        base = base->base;
 
-               fprintf(f, "\t(PropertyRNA*)&rna_%s_%s, ", base->identifier, prop->identifier);
+               fprintf(f, "\t(PropertyRNA *)&rna_%s_%s, ", base->identifier, prop->identifier);
        }
        else fprintf(f, "\tNULL, ");
 
@@ -3159,7 +3179,7 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        base = srna;
        while (base->base && base->base->iteratorproperty == prop)
                base = base->base;
-       fprintf(f, "(PropertyRNA*)&rna_%s_rna_properties,\n", base->identifier);
+       fprintf(f, "(PropertyRNA *)&rna_%s_rna_properties,\n", base->identifier);
 
        if (srna->base) fprintf(f, "\t&RNA_%s,\n", srna->base->identifier);
        else fprintf(f, "\tNULL,\n");
@@ -3181,11 +3201,11 @@ static void rna_generate_struct(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE
        }
 
        func = srna->functions.first;
-       if (func) fprintf(f, "\t{(FunctionRNA*)&rna_%s_%s_func, ", srna->identifier, func->identifier);
+       if (func) fprintf(f, "\t{(FunctionRNA *)&rna_%s_%s_func, ", srna->identifier, func->identifier);
        else fprintf(f, "\t{NULL, ");
 
        func = srna->functions.last;
-       if (func) fprintf(f, "(FunctionRNA*)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
+       if (func) fprintf(f, "(FunctionRNA *)&rna_%s_%s_func}\n", srna->identifier, func->identifier);
        else fprintf(f, "NULL}\n");
 
        fprintf(f, "};\n");
@@ -3229,7 +3249,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
        {"rna_main.c", "rna_main_api.c", RNA_def_main},
        {"rna_material.c", "rna_material_api.c", RNA_def_material},
        {"rna_mesh.c", "rna_mesh_api.c", RNA_def_mesh},
-       {"rna_meta.c", NULL, RNA_def_meta},
+       {"rna_meta.c", "rna_meta_api.c", RNA_def_meta},
        {"rna_modifier.c", NULL, RNA_def_modifier},
        {"rna_nla.c", NULL, RNA_def_nla},
        {"rna_nodetree.c", NULL, RNA_def_nodetree},
@@ -3240,6 +3260,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
        {"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
        {"rna_property.c", NULL, RNA_def_gameproperty},
        {"rna_render.c", NULL, RNA_def_render},
+       {"rna_rigidbody.c", NULL, RNA_def_rigidbody},
        {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
        {"rna_screen.c", NULL, RNA_def_screen},
        {"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
@@ -3407,7 +3428,7 @@ static const char *cpp_classes = ""
 "namespace BL {\n"
 "\n"
 "#define BOOLEAN_PROPERTY(sname, identifier) \\\n"
-"      inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr)? true: false; } \\\n"
+"      inline bool sname::identifier(void) { return sname##_##identifier##_get(&ptr) ? true: false; } \\\n"
 "      inline void sname::identifier(int value) { sname##_##identifier##_set(&ptr, value); }\n"
 "\n"
 "#define BOOLEAN_ARRAY_PROPERTY(sname, size, identifier) \\\n"
@@ -3525,8 +3546,27 @@ static const char *cpp_classes = ""
 "#define COLLECTION_PROPERTY_LOOKUP_STRING_FALSE(sname, identifier) \\\n"
 "      inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
 "      { \\\n"
-"              memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
-"              return 0; \\\n"
+"              CollectionPropertyIterator iter; \\\n"
+"              int found = 0; \\\n"
+"              PropertyRNA *item_name_prop = RNA_struct_name_property(ptr->type); \\\n"
+"              sname##_##identifier##_begin(&iter, ptr); \\\n"
+"              while (iter.valid && !found) { \\\n"
+"                      char name_fixed[32]; \\\n"
+"                      const char *name; \\\n"
+"                      int name_length; \\\n"
+"                      name = RNA_property_string_get_alloc(&iter.ptr, item_name_prop, name_fixed, sizeof(name_fixed), &name_length); \\\n"
+"                      if (!strncmp(name, key, name_length)) { \\\n"
+"                              *r_ptr = iter.ptr; \\\n"
+"                              found = 1; \\\n"
+"                      } \\\n"
+"                      if (name_fixed != name) \\\n"
+"                              MEM_freeN((void *) name); \\\n"
+"                      sname##_##identifier##_next(&iter); \\\n"
+"              } \\\n"
+"              sname##_##identifier##_end(&iter); \\\n"
+"              if (!found) \\\n"
+"                      memset(r_ptr, 0, sizeof(*r_ptr)); \\\n"
+"              return found; \\\n"
 "      } \n"
 "#define COLLECTION_PROPERTY_LOOKUP_STRING_TRUE(sname, identifier) \\\n"
 "      inline static int sname##_##identifier##_lookup_string_wrap(PointerRNA *ptr, const char *key, PointerRNA *r_ptr) \\\n"
@@ -3547,7 +3587,7 @@ static const char *cpp_classes = ""
 "public:\n"
 "      Pointer(const PointerRNA &p) : ptr(p) { }\n"
 "      operator const PointerRNA&() { return ptr; }\n"
-"      bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type)? true: false; }\n"
+"      bool is_a(StructRNA *type) { return RNA_struct_is_a(ptr.type, type) ? true: false; }\n"
 "      operator void*() { return ptr.data; }\n"
 "      operator bool() { return ptr.data != NULL; }\n"
 "\n"
@@ -3575,7 +3615,7 @@ static const char *cpp_classes = ""
 "      int length;\n"
 "\n"
 "      DynamicArray() : data(NULL), length(0) {}\n"
-"      DynamicArray(int new_length) : data(NULL), length(new_length) { data = (float*)malloc(sizeof(T) * new_length); }\n"
+"      DynamicArray(int new_length) : data(NULL), length(new_length) { data = (float *)malloc(sizeof(T) * new_length); }\n"
 "      DynamicArray(const DynamicArray<T>& other) { copy_from(other); }\n"
 "      const DynamicArray<T>& operator=(const DynamicArray<T>& other) { copy_from(other); return *this; }\n"
 "\n"
@@ -3586,7 +3626,7 @@ static const char *cpp_classes = ""
 "protected:\n"
 "      void copy_from(const DynamicArray<T>& other) {\n"
 "              if (data) free(data);\n"
-"              data = (float*)malloc(sizeof(T) * other.length);\n"
+"              data = (float *)malloc(sizeof(T) * other.length);\n"
 "              memcpy(data, other.data, sizeof(T) * other.length);\n"
 "              length = other.length;\n"
 "      }\n"
@@ -3617,7 +3657,7 @@ static const char *cpp_classes = ""
 "{ return iter.valid != other.iter.valid; }\n"
 "\n"
 "      void begin(const Pointer &ptr)\n"
-"      { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA*)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
+"      { if (init) Tend(&iter); Tbegin(&iter, (PointerRNA *)&ptr.ptr); t = T(iter.ptr); init = true; }\n"
 "\n"
 "private:\n"
 "      const CollectionIterator<T, Tbegin, Tnext, Tend>& operator="
@@ -3751,13 +3791,13 @@ static void rna_generate_header_cpp(BlenderRNA *UNUSED(brna), FILE *f)
                                        if (first_collection_func_struct == NULL)
                                                first_collection_func_struct = ds->srna->identifier;
 
-                                       if (!rna_is_collection_functions_struct(collection_func_structs, (char*)prop->srna)) {
+                                       if (!rna_is_collection_functions_struct(collection_func_structs, (char *)prop->srna)) {
                                                if (all_collection_func_structs >= max_collection_func_structs) {
                                                        printf("Array size to store all collection structures names is too small\n");
                                                        exit(1);
                                                }
 
-                                               collection_func_structs[all_collection_func_structs++] = (char*)prop->srna;
+                                               collection_func_structs[all_collection_func_structs++] = (char *)prop->srna;
                                        }
                                }
                        }
@@ -3843,6 +3883,13 @@ static int rna_preprocess(const char *outfile)
                if (PROCESS_ITEMS[i].define) {
                        PROCESS_ITEMS[i].define(brna);
 
+                       /* sanity check */
+                       if (!DefRNA.animate) {
+                               fprintf(stderr,
+                                       "Error: DefRNA.animate left disabled in %s\n",
+                                       PROCESS_ITEMS[i].filename);
+                       }
+
                        for (ds = DefRNA.structs.first; ds; ds = ds->cont.next)
                                if (!ds->filename)
                                        ds->filename = PROCESS_ITEMS[i].filename;