RNA:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 Apr 2009 15:12:42 +0000 (15:12 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 15 Apr 2009 15:12:42 +0000 (15:12 +0000)
* For RNA wrapped functions, the prototypes of the original
  function being wrapped is now generated as well. This is
  an extra check to ensure that the function is correctly
  wrapped. It's printed after the function is used to still
  get proper warnings in case the #include for it is missing.

source/blender/makesrna/intern/makesrna.c
source/blender/makesrna/intern/rna_internal.h

index 5eceb62f8971083923b797990b25d100df0cad2a..c66d938448efef448f3ff357b620960905090833 100644 (file)
@@ -1165,7 +1165,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA
 
        fprintf(f, "}\n\n");
 
-       dfunc->call= funcname;
+       dfunc->gencall= funcname;
 }
 
 static void rna_auto_types()
@@ -1345,6 +1345,65 @@ static void rna_generate_function_prototypes(BlenderRNA *brna, StructRNA *srna,
                fprintf(f, "\n");
 }
 
+static void rna_generate_static_parameter_prototypes(BlenderRNA *brna, StructRNA *srna, FunctionDefRNA *dfunc, FILE *f)
+{
+       FunctionRNA *func;
+       PropertyDefRNA *dparm;
+       StructDefRNA *dsrna;
+
+       dsrna= rna_find_struct_def(srna);
+       func= dfunc->func;
+
+       for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
+               if(dparm->prop==func->ret) {
+                       if(dparm->prop->arraylength)
+                               fprintf(f, "XXX no array return types yet"); /* XXX not supported */
+                       else if(dparm->prop->type == PROP_POINTER)
+                               fprintf(f, "%s%s *", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
+                       else
+                               fprintf(f, "%s%s ", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop));
+
+                       break;
+               }
+       }
+
+       if(!dparm)
+               fprintf(f, "void ");
+
+       fprintf(f, "%s(", dfunc->call);
+
+       if(dsrna->dnaname) fprintf(f, "struct %s *_self", dsrna->dnaname);
+       else fprintf(f, "struct %s *_self", srna->identifier);
+
+       for(dparm= dfunc->cont.properties.first; dparm; dparm= dparm->next) {
+               if(dparm->prop==func->ret) ;
+               else if(dparm->prop->arraylength)
+                       fprintf(f, ", %s%s %s[%d]", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier, dparm->prop->arraylength);
+               else if(dparm->prop->type == PROP_POINTER)
+                       fprintf(f, ", %s%s *%s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier);
+               else
+                       fprintf(f, ", %s%s %s", rna_type_struct(dparm->prop), rna_parameter_type_name(dparm->prop), dparm->prop->identifier);
+       }
+
+       fprintf(f, ");\n");
+}
+
+static void rna_generate_static_function_prototypes(BlenderRNA *brna, StructRNA *srna, FILE *f)
+{
+       FunctionRNA *func;
+       FunctionDefRNA *dfunc;
+
+       fprintf(f, "/* Repeated prototypes to detect errors */\n\n");
+
+       for(func= srna->functions.first; func; func= func->cont.next) {
+               dfunc= rna_find_function_def(func);
+               if(dfunc->call)
+                       rna_generate_static_parameter_prototypes(brna, srna, dfunc, f);
+       }
+
+       fprintf(f, "\n");
+}
+
 static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, PropertyRNA *prop) 
 {
        char *strnest= "", *errnest= "";
@@ -1580,7 +1639,7 @@ static void rna_generate_struct(BlenderRNA *brna, StructRNA *srna, FILE *f)
                rna_print_c_string(f, func->description); fprintf(f, ",\n");
 
                dfunc= rna_find_function_def(func);
-               if(dfunc->call) fprintf(f, "\t%s,\n", dfunc->call);
+               if(dfunc->gencall) fprintf(f, "\t%s,\n", dfunc->gencall);
                else fprintf(f, "\tNULL,\n");
        
                if(func->ret) fprintf(f, "\t(PropertyRNA*)&rna_%s_%s_%s\n", srna->identifier, func->identifier, func->ret->identifier);
@@ -1750,11 +1809,15 @@ static void rna_generate(BlenderRNA *brna, FILE *f, char *filename)
                        for(dp=ds->cont.properties.first; dp; dp=dp->next)
                                rna_def_property_funcs(f, ds->srna, dp);
 
-       for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
-               if(!filename || ds->filename == filename)
+       for(ds=DefRNA.structs.first; ds; ds=ds->cont.next) {
+               if(!filename || ds->filename == filename) {
                        for(dfunc=ds->functions.first; dfunc; dfunc= dfunc->cont.next)
                                rna_def_function_funcs(f, ds, dfunc);
 
+                       rna_generate_static_function_prototypes(brna, ds->srna, f);
+               }
+       }
+
        for(ds=DefRNA.structs.first; ds; ds=ds->cont.next)
                if(!filename || ds->filename == filename)
                        rna_generate_struct(brna, ds->srna, f);
index d0aa60dc390a30b6b67248e4f0c2a3ae8cc5fd1b..fbdde596a59bb8fee2f9df362d6aaae6786ac4bc 100644 (file)
@@ -47,6 +47,7 @@ typedef struct FunctionDefRNA {
        FunctionRNA *func;
        const char *srna;
        const char *call;
+       const char *gencall;
 } FunctionDefRNA;
 
 typedef struct PropertyDefRNA {