[Bf-blender-cvs] [440d104] master: Refactor RNA property: split flags in property flags, parameter flags, and internal flags.

Bastien Montagne noreply at git.blender.org
Mon Dec 12 15:59:35 CET 2016


Commit: 440d1042798113a0e8115ea1f1d016a44712e7a0
Author: Bastien Montagne
Date:   Mon Dec 12 15:23:55 2016 +0100
Branches: master
https://developer.blender.org/rB440d1042798113a0e8115ea1f1d016a44712e7a0

Refactor RNA property: split flags in property flags, parameter flags, and internal flags.

This gives us 9 flags available again for properties (we had none anymore),
and also makes things slightly cleaner.

To simplify (and make more clear the differences between mere properties
and function parameters), also added RNA_def_parameter_flags function (and
its clear counterpart), to be used instead of RNA_def_property_flag for
function parameters.

This patch is also a big cleanup (some RNA function definitions were
still using 'prop' PropertyRNA pointer, etc.).

And yes, am aware this will be annoying for all branches, but we really need
to get new flags available for properties (will need at least one for override, etc.).

Reviewers: sergey, Severin

Subscribers: dfelinto, brecht

Differential Revision: https://developer.blender.org/D2400

===================================================================

M	source/blender/makesrna/RNA_access.h
M	source/blender/makesrna/RNA_define.h
M	source/blender/makesrna/RNA_types.h
M	source/blender/makesrna/intern/makesrna.c
M	source/blender/makesrna/intern/rna_ID.c
M	source/blender/makesrna/intern/rna_access.c
M	source/blender/makesrna/intern/rna_action.c
M	source/blender/makesrna/intern/rna_actuator_api.c
M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/makesrna/intern/rna_armature.c
M	source/blender/makesrna/intern/rna_armature_api.c
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_curve.c
M	source/blender/makesrna/intern/rna_curve_api.c
M	source/blender/makesrna/intern/rna_define.c
M	source/blender/makesrna/intern/rna_depsgraph.c
M	source/blender/makesrna/intern/rna_dynamicpaint.c
M	source/blender/makesrna/intern/rna_fcurve.c
M	source/blender/makesrna/intern/rna_fcurve_api.c
M	source/blender/makesrna/intern/rna_gpencil.c
M	source/blender/makesrna/intern/rna_group.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/makesrna/intern/rna_internal_types.h
M	source/blender/makesrna/intern/rna_key.c
M	source/blender/makesrna/intern/rna_lattice_api.c
M	source/blender/makesrna/intern/rna_linestyle.c
M	source/blender/makesrna/intern/rna_main_api.c
M	source/blender/makesrna/intern/rna_mask.c
M	source/blender/makesrna/intern/rna_material.c
M	source/blender/makesrna/intern/rna_mesh.c
M	source/blender/makesrna/intern/rna_mesh_api.c
M	source/blender/makesrna/intern/rna_meta.c
M	source/blender/makesrna/intern/rna_meta_api.c
M	source/blender/makesrna/intern/rna_nla.c
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_object_api.c
M	source/blender/makesrna/intern/rna_palette.c
M	source/blender/makesrna/intern/rna_particle.c
M	source/blender/makesrna/intern/rna_pose.c
M	source/blender/makesrna/intern/rna_pose_api.c
M	source/blender/makesrna/intern/rna_render.c
M	source/blender/makesrna/intern/rna_rigidbody.c
M	source/blender/makesrna/intern/rna_rna.c
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/makesrna/intern/rna_scene_api.c
M	source/blender/makesrna/intern/rna_screen.c
M	source/blender/makesrna/intern/rna_sensor_api.c
M	source/blender/makesrna/intern/rna_sequencer.c
M	source/blender/makesrna/intern/rna_sequencer_api.c
M	source/blender/makesrna/intern/rna_space.c
M	source/blender/makesrna/intern/rna_space_api.c
M	source/blender/makesrna/intern/rna_text_api.c
M	source/blender/makesrna/intern/rna_texture_api.c
M	source/blender/makesrna/intern/rna_tracking.c
M	source/blender/makesrna/intern/rna_ui.c
M	source/blender/makesrna/intern/rna_ui_api.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/makesrna/intern/rna_wm_api.c
M	source/blender/python/intern/bpy_rna.c

===================================================================

diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index 44d1a6b..f97a573 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -793,6 +793,7 @@ PropertyType RNA_property_type(PropertyRNA *prop);
 PropertySubType RNA_property_subtype(PropertyRNA *prop);
 PropertyUnit RNA_property_unit(PropertyRNA *prop);
 int RNA_property_flag(PropertyRNA *prop);
+bool RNA_property_builtin(PropertyRNA *prop);
 void *RNA_property_py_data_get(PropertyRNA *prop);
 
 int  RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop);
@@ -1142,6 +1143,8 @@ const struct ListBase *RNA_function_defined_parameters(FunctionRNA *func);
 
 /* Utility */
 
+int RNA_parameter_flag(PropertyRNA *prop);
+
 ParameterList *RNA_parameter_list_create(ParameterList *parms, PointerRNA *ptr, FunctionRNA *func);
 void RNA_parameter_list_free(ParameterList *parms);
 int  RNA_parameter_list_size(ParameterList *parms);
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index bf8ea04..2a680b6 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -137,8 +137,8 @@ void RNA_def_property_enum_bitflag_sdna(PropertyRNA *prop, const char *structnam
 void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname);
 void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname);
 
-void RNA_def_property_flag(PropertyRNA *prop, int flag);
-void RNA_def_property_clear_flag(PropertyRNA *prop, int flag);
+void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag);
+void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag);
 void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype);
 void RNA_def_property_array(PropertyRNA *prop, int length);
 void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[]);
@@ -201,6 +201,9 @@ void RNA_def_function_output(FunctionRNA *func, PropertyRNA *ret);
 void RNA_def_function_flag(FunctionRNA *func, int flag);
 void RNA_def_function_ui_description(FunctionRNA *func, const char *description);
 
+void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter);
+void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter);
+
 /* Dynamic Enums
  * strings are not freed, assumed pointing to static location. */
 
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 2765319..1a191a6 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -155,7 +155,8 @@ typedef enum PropertySubType {
 } PropertySubType;
 
 /* Make sure enums are updated with these */
-/* HIGHEST FLAG IN USE: 1 << 31 */
+/* HIGHEST FLAG IN USE: 1 << 31
+ * FREE FLAGS: 2, 3, 7, 9, 11, 13, 14, 15, 30 */
 typedef enum PropertyFlag {
 	/* editable means the property is editable in the user
 	 * interface, properties are editable by default except
@@ -185,20 +186,6 @@ typedef enum PropertyFlag {
 	/* do not write in presets */
 	PROP_SKIP_SAVE               = (1 << 28),
 
-	/* function parameter flags */
-	PROP_REQUIRED                = (1 << 2),
-	PROP_OUTPUT                  = (1 << 3),
-	PROP_RNAPTR                  = (1 << 11),
-	/* This allows for non-breaking API updates, when adding non-critical new parameter to a callback function.
-	 * This way, old py code defining funcs without that parameter would still work.
-	 * WARNING: any parameter after the first PYFUNC_OPTIONAL one will be considered as optional!
-	 * NOTE: only for input parameters!
-	 */
-	PROP_PYFUNC_OPTIONAL         = (1 << 30),
-	/* registering */
-	PROP_REGISTER                = (1 << 4),
-	PROP_REGISTER_OPTIONAL       = PROP_REGISTER | (1 << 5),
-
 	/* numbers */
 
 	/* each value is related proportionally (object scale, image size) */
@@ -229,25 +216,37 @@ typedef enum PropertyFlag {
 
 	/* need context for update function */
 	PROP_CONTEXT_UPDATE          = (1 << 22),
-	PROP_CONTEXT_PROPERTY_UPDATE = (1 << 22) | (1 << 27),
+	PROP_CONTEXT_PROPERTY_UPDATE = PROP_CONTEXT_UPDATE | (1 << 27),
+
+	/* registering */
+	PROP_REGISTER                = (1 << 4),
+	PROP_REGISTER_OPTIONAL       = PROP_REGISTER | (1 << 5),
 
 	/* Use for arrays or for any data that should not have a reference kept
 	 * most common case is functions that return arrays where the array */
 	PROP_THICK_WRAP              = (1 << 23),
 
-	/* internal flags */
-	PROP_BUILTIN                 = (1 << 7),
-	PROP_EXPORT                  = (1 << 8),
-	PROP_RUNTIME                 = (1 << 9),
-	PROP_IDPROPERTY              = (1 << 10),
-	PROP_RAW_ACCESS              = (1 << 13),
-	PROP_RAW_ARRAY               = (1 << 14),
-	PROP_FREE_POINTERS           = (1 << 15),
+	PROP_EXPORT                  = (1 << 8),  /* XXX Is this still used? makesrna.c seems to ignore it currently... */
+	PROP_IDPROPERTY              = (1 << 10), /* This is an IDProperty, not a DNA one. */
 	PROP_DYNAMIC                 = (1 << 17), /* for dynamic arrays, and retvals of type string */
 	PROP_ENUM_NO_CONTEXT         = (1 << 24), /* for enum that shouldn't be contextual */
 	PROP_ENUM_NO_TRANSLATE       = (1 << 29), /* for enums not to be translated (e.g. renderlayers' names in nodes) */
 } PropertyFlag;
 
+/* Function parameters flags.
+ * WARNING: 16bits only. */
+typedef enum ParameterFlag {
+	PARM_REQUIRED                = (1 << 0),
+	PARM_OUTPUT                  = (1 << 1),
+	PARM_RNAPTR                  = (1 << 2),
+	/* This allows for non-breaking API updates, when adding non-critical new parameter to a callback function.
+	 * This way, old py code defining funcs without that parameter would still work.
+	 * WARNING: any parameter after the first PYFUNC_OPTIONAL one will be considered as optional!
+	 * NOTE: only for input parameters!
+	 */
+	PARM_PYFUNC_OPTIONAL         = (1 << 3),
+} ParameterFlag;
+
 struct CollectionPropertyIterator;
 struct Link;
 typedef int (*IteratorSkipFunc)(struct CollectionPropertyIterator *iter, void *data);
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 309d39a..d557697 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -463,7 +463,7 @@ static const char *rna_parameter_type_name(PropertyRNA *parm)
 		{
 			PointerPropertyRNA *pparm = (PointerPropertyRNA *)parm;
 
-			if (parm->flag & PROP_RNAPTR)
+			if (parm->flag_parameter & PARM_RNAPTR)
 				return "PointerRNA";
 			else
 				return rna_find_dna_type((const char *)pparm->type);
@@ -1409,23 +1409,23 @@ static void rna_set_raw_property(PropertyDefRNA *dp, PropertyRNA *prop)
 	
 	if (STREQ(dp->dnatype, "char")) {
 		prop->rawtype = PROP_RAW_CHAR;
-		prop->flag |= PROP_RAW_ACCESS;
+		prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
 	}
 	else if (STREQ(dp->dnatype, "short")) {
 		prop->rawtype = PROP_RAW_SHORT;
-		prop->flag |= PROP_RAW_ACCESS;
+		prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
 	}
 	else if (STREQ(dp->dnatype, "int")) {
 		prop->rawtype = PROP_RAW_INT;
-		prop->flag |= PROP_RAW_ACCESS;
+		prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
 	}
 	else if (STREQ(dp->dnatype, "float")) {
 		prop->rawtype = PROP_RAW_FLOAT;
-		prop->flag |= PROP_RAW_ACCESS;
+		prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
 	}
 	else if (STREQ(dp->dnatype, "double")) {
 		prop->rawtype = PROP_RAW_DOUBLE;
-		prop->flag |= PROP_RAW_ACCESS;
+		prop->flag_internal |= PROP_INTERN_RAW_ACCESS;
 	}
 }
 
@@ -1553,7 +1553,7 @@ static void rna_def_property_funcs(FILE *f, StructRNA *srna, PropertyDefRNA *dp)
 				if (STREQ((const char *)cprop->next, "rna_iterator_array_next") &&
 				    STREQ((const char *)cprop->get, "rna_iterator_array_get"))
 				{
-					prop->flag |= PROP_RAW_ARRAY;
+					prop->flag_internal |= PROP_INTERN_RAW_ARRAY;
 				}
 
 			cprop->get = (void *)rna_def_property_get_func(f, srna, prop, dp, (const char *)cprop->get);
@@ -1599,8 +1599,9 @@ static void rna_def_property_funcs_header(FILE *f, StructRNA *srna, PropertyDefR
 
 	prop = dp->prop;
 
-	if (prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN))
+	if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
 		return;
+	}
 
 	func = rna_alloc_function_name(srna->identifier, rna_safe_id(prop->identifier), "");
 
@@ -1719,8 +1720,9 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
 
 	prop = dp->prop;
 
-	if (prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN))
+	if (prop->flag & PROP_IDPROPERTY || prop->flag_internal & PROP_INTERN_BUILTIN) {
 		return;
+	}
 	
 	/* disabled for now to avoid msvc compiler error due to large file size */
 #if 0
@@ -1822,8 +1824,9 @@ static void rna_def_property_funcs_header_cpp(FILE *f, StructRNA *srna, Property
 			CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)dp->prop;
 			const char *collection_funcs = "DefaultCollectionFunctions";
 
-			if (!(dp->prop->flag & (PROP_IDPROPERTY | PROP_BUILTIN)) && cprop->property.srna)
+			if (!(dp->prop->flag & PROP_IDPROPERTY || dp->prop->flag_internal & PROP_INTERN_BUILTIN) && 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,
@@ -1879,7 +1882,7 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *UNUSED(srn
 		WRITE_PARAM("Context C");
 
 	for (dp = dfunc->cont.properties.first; dp; dp = dp->next) {
-		int type, flag, pout;
+		int type, flag, flag_parameter, pout;
 		const char *ptrstr;
 
 		if (dp->prop == func->c_ret)
@@ -1887,7 +1890,8 @@ static void rna_def_struct_function_prototype_cpp(FILE *f, StructRNA *UNUSED(srn
 
 		type = dp->prop->type;
 		flag = dp->prop->flag;
-		pout = (flag & PROP_OUTPUT);
+		flag_parameter = dp->prop->flag_parameter;
+		pout = (flag_parameter & PARM_OUTPUT);
 
 		if (flag & PROP_DYNAMIC)
 			ptrstr = pout ? "**" : "*";
@@ -1903,7 +1907,7 @@ static void rna_def_struct_function_prototype_cpp(FILE *f

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list