Revision: 36747 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36747 Author: blendix Date: 2011-05-18 12:56:58 +0000 (Wed, 18 May 2011) Log Message: ----------- RNA: some compile fixes for C/C++ api.
Modified Paths: -------------- trunk/blender/source/blender/makesrna/intern/makesrna.c Modified: trunk/blender/source/blender/makesrna/intern/makesrna.c =================================================================== --- trunk/blender/source/blender/makesrna/intern/makesrna.c 2011-05-18 11:21:10 UTC (rev 36746) +++ trunk/blender/source/blender/makesrna/intern/makesrna.c 2011-05-18 12:56:58 UTC (rev 36747) @@ -193,8 +193,18 @@ #undef REN_IF_DIFF } +/* Helper to solve keyword problems with C/C++ */ +static const char *rna_safe_id(const char *id) +{ + if(strcmp(id, "default") == 0) + return "default_value"; + else if(strcmp(id, "operator") == 0) + return "operator_value"; + return id; +} + /* Sorting */ static int cmp_struct(const void *a, const void *b) @@ -501,7 +511,7 @@ } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "get"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get"); switch(prop->type) { case PROP_STRING: { @@ -569,7 +579,7 @@ rna_print_data_get(f, dp); if(prop->flag & PROP_DYNAMIC) { - char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get_length"); + char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get_length"); fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n"); fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc); fprintf(f, " for(i=0; i<len; i++) {\n"); @@ -684,7 +694,7 @@ } } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "set"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set"); switch(prop->type) { case PROP_STRING: { @@ -754,7 +764,7 @@ rna_print_data_get(f, dp); if(prop->flag & PROP_DYNAMIC) { - char *lenfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "set_length"); + char *lenfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "set_length"); fprintf(f, " int i, arraylen[RNA_MAX_ARRAY_DIMENSION];\n"); fprintf(f, " int len= %s(ptr, arraylen);\n\n", lenfunc); fprintf(f, " for(i=0; i<len; i++) {\n"); @@ -851,7 +861,7 @@ } } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "length"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length"); fprintf(f, "int %s(PointerRNA *ptr)\n", func); fprintf(f, "{\n"); @@ -873,7 +883,7 @@ } } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "length"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "length"); fprintf(f, "int %s(PointerRNA *ptr)\n", func); fprintf(f, "{\n"); @@ -908,7 +918,7 @@ } } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "begin"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "begin"); fprintf(f, "void %s(CollectionPropertyIterator *iter, PointerRNA *ptr)\n", func); fprintf(f, "{\n"); @@ -940,7 +950,7 @@ fprintf(f, "\n rna_iterator_listbase_begin(iter, data->%s, NULL);\n", dp->dnaname); } - getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get"); + getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get"); fprintf(f, "\n if(iter->valid)\n"); fprintf(f, " iter->ptr= %s(iter);\n", getfunc); @@ -970,7 +980,7 @@ else return NULL; } - func= rna_alloc_function_name(srna->identifier, prop->identifier, "lookup_int"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "lookup_int"); fprintf(f, "int %s(PointerRNA *ptr, int index, PointerRNA *r_ptr)\n", func); fprintf(f, "{\n"); @@ -984,7 +994,7 @@ fprintf(f, " int found= 0;\n"); fprintf(f, " CollectionPropertyIterator iter;\n\n"); - fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, prop->identifier); + fprintf(f, " %s_%s_begin(&iter, ptr);\n\n", srna->identifier, rna_safe_id(prop->identifier)); fprintf(f, " if(iter.valid){\n"); if(strcmp(nextfunc, "rna_iterator_array_next") == 0) { @@ -1022,9 +1032,9 @@ fprintf(f, " }\n"); } - fprintf(f, " if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, prop->identifier); + fprintf(f, " if(found) *r_ptr = %s_%s_get(&iter);\n", srna->identifier, rna_safe_id(prop->identifier)); fprintf(f, " }\n\n"); - fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, prop->identifier); + fprintf(f, " %s_%s_end(&iter);\n\n", srna->identifier, rna_safe_id(prop->identifier)); fprintf(f, " return found;\n"); @@ -1061,13 +1071,13 @@ if(!manualfunc) return NULL; - func= rna_alloc_function_name(srna->identifier, prop->identifier, "next"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "next"); fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func); fprintf(f, "{\n"); fprintf(f, " %s(iter);\n", manualfunc); - getfunc= rna_alloc_function_name(srna->identifier, prop->identifier, "get"); + getfunc= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "get"); fprintf(f, "\n if(iter->valid)\n"); fprintf(f, " iter->ptr= %s(iter);\n", getfunc); @@ -1084,7 +1094,7 @@ if(prop->flag & PROP_IDPROPERTY && manualfunc==NULL) return NULL; - func= rna_alloc_function_name(srna->identifier, prop->identifier, "end"); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "end"); fprintf(f, "void %s(CollectionPropertyIterator *iter)\n", func); fprintf(f, "{\n"); @@ -1272,7 +1282,7 @@ if(prop->flag & (PROP_IDPROPERTY|PROP_BUILTIN)) return; - func= rna_alloc_function_name(srna->identifier, prop->identifier, ""); + func= rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), ""); switch(prop->type) { case PROP_BOOLEAN: @@ -1281,10 +1291,14 @@ fprintf(f, "int %sget(PointerRNA *ptr);\n", func); //fprintf(f, "void %sset(PointerRNA *ptr, int value);\n", func); } - else { + else if(prop->arraydimension && prop->totarraylength) { fprintf(f, "void %sget(PointerRNA *ptr, int values[%d]);\n", func, prop->totarraylength); //fprintf(f, "void %sset(PointerRNA *ptr, const int values[%d]);\n", func, prop->arraylength); } + else { + fprintf(f, "void %sget(PointerRNA *ptr, int values[]);\n", func); + //fprintf(f, "void %sset(PointerRNA *ptr, const int values[]);\n", func); + } break; } case PROP_FLOAT: { @@ -1292,10 +1306,14 @@ fprintf(f, "float %sget(PointerRNA *ptr);\n", func); //fprintf(f, "void %sset(PointerRNA *ptr, float value);\n", func); } - else { + else if(prop->arraydimension && prop->totarraylength) { fprintf(f, "void %sget(PointerRNA *ptr, float values[%d]);\n", func, prop->totarraylength); //fprintf(f, "void %sset(PointerRNA *ptr, const float values[%d]);\n", func, prop->arraylength); } + else { + fprintf(f, "void %sget(PointerRNA *ptr, float values[]);\n", func); + //fprintf(f, "void %sset(PointerRNA *ptr, const float values[]);\n", func); + } break; } case PROP_ENUM: { @@ -1368,23 +1386,23 @@ switch(prop->type) { case PROP_BOOLEAN: { if(!prop->arraydimension) - fprintf(f, "\tbool %s(void);", prop->identifier); + fprintf(f, "\tinline bool %s(void);", rna_safe_id(prop->identifier)); else - fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier); + fprintf(f, "\tinline Array<int, %d> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } case PROP_INT: { if(!prop->arraydimension) - fprintf(f, "\tint %s(void);", prop->identifier); + fprintf(f, "\tinline int %s(void);", rna_safe_id(prop->identifier)); else - fprintf(f, "\tArray<int, %d> %s(void);", prop->totarraylength, prop->identifier); + fprintf(f, "\tinline Array<int, %d> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } case PROP_FLOAT: { if(!prop->arraydimension) - fprintf(f, "\tfloat %s(void);", prop->identifier); + fprintf(f, "\tinline float %s(void);", rna_safe_id(prop->identifier)); else - fprintf(f, "\tArray<float, %d> %s(void);", prop->totarraylength, prop->identifier); + fprintf(f, "\tinline Array<float, %d> %s(void);", prop->totarraylength, rna_safe_id(prop->identifier)); break; } case PROP_ENUM: { @@ -1392,38 +1410,38 @@ int i; if(eprop->item) { - fprintf(f, "\tenum %s_enum {\n", prop->identifier); + fprintf(f, "\tenum %s_enum {\n", rna_safe_id(prop->identifier)); for(i=0; i<eprop->totitem; i++) if(eprop->item[i].identifier[0]) - fprintf(f, "\t\t%s_%s = %d,\n", prop->identifier, eprop->item[i].identifier, eprop->item[i].value); + fprintf(f, "\t\t%s_%s = %d,\n", rna_safe_id(prop->identifier), eprop->item[i].identifier, eprop->item[i].value); fprintf(f, "\t};\n"); } - fprintf(f, "\t%s_enum %s(void);", prop->identifier, prop->identifier); + fprintf(f, "\tinline %s_enum %s(void);", rna_safe_id(prop->identifier), rna_safe_id(prop->identifier)); break; } case PROP_STRING: { - fprintf(f, "\tstd::string %s(void);", prop->identifier); + fprintf(f, "\tinline std::string %s(void);", rna_safe_id(prop->identifier)); break; } case PROP_POINTER: { PointerPropertyRNA *pprop= (PointerPropertyRNA*)dp->prop; if(pprop->type) - fprintf(f, "\t%s %s(void);", (char*)pprop->type, prop->identifier); + fprintf(f, "\tinline %s %s(void);", (char*)pprop->type, rna_safe_id(prop->identifier)); else - fprintf(f, "\t%s %s(void);", "UnknownType", prop->identifier); + fprintf(f, "\tinline %s %s(void);", "UnknownType", rna_safe_id(prop->identifier)); break; } case PROP_COLLECTION: { CollectionPropertyRNA *cprop= (CollectionPropertyRNA*)dp->prop; if(cprop->item_type) - fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->item_type, srna->identifier, prop->identifier); + fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", (char*)cprop->item_type, srna->identifier, rna_safe_id(prop->identifier)); else - fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, prop->identifier); + fprintf(f, "\tCOLLECTION_PROPERTY(%s, %s, %s)", "UnknownType", srna->identifier, rna_safe_id(prop->identifier)); break; } } @@ -1443,41 +1461,41 @@ switch(prop->type) { case PROP_BOOLEAN: { if(!prop->arraydimension) @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs