[Gtk-sharp-list] Struct privatization

Rachel Hestilow rachel@nullenvoid.com
Wed, 17 Sep 2003 18:42:29 -0700


--LZvS9be/3tNcYl/X
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

The attached patch to the generator makes the following kinds
of struct fields private:
   1) Bitfields (those which compile as bitfield0, bitfield1, etc)
   2) Fields which have wrapper properties (for example, IntPtr _widget)
   3) Generic pointer fields
   4) 'dummy' fields
   5) Fields that currently compile to IntPtr as a workaround (fixed-size
      arrays, callbacks)

This fixes bug #46394 and should make the documenters' work easier
in general. I do not anticipate this would break any existing code --
obviously fixes eventually should be provided for #1 and #5 but
nobody should be using those fields in their current form.

Good to commit? (with a suitable ChangeLog entry of course)

-- Rachel

--LZvS9be/3tNcYl/X
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="StructBase.patch"

Index: generator/StructBase.cs
===================================================================
RCS file: /cvs/public/gtk-sharp/generator/StructBase.cs,v
retrieving revision 1.38
diff -u -p -r1.38 StructBase.cs
--- generator/StructBase.cs	28 Aug 2003 16:49:29 -0000	1.38
+++ generator/StructBase.cs	18 Sep 2003 01:39:41 -0000
@@ -95,7 +95,13 @@ namespace GtkSharp.Generation {
 		bool IsPointer (XmlElement field)
 		{
 			string c_type = field.GetAttribute("type");
-			return (c_type[c_type.Length - 1] == '*');
+			return (c_type[c_type.Length - 1] == '*' || c_type == "gpointer" || c_type == "gconstpointer");
+		}
+
+		bool IsPadding (XmlElement field)
+		{
+			string c_name = field.GetAttribute ("cname");
+			return (c_name.StartsWith ("dummy"));
 		}
 
 		protected void GenFields (StreamWriter sw)
@@ -114,29 +120,39 @@ namespace GtkSharp.Generation {
 			}
 		}
 
-		protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name)
+		protected bool GetFieldInfo (XmlElement field, out string c_type, out string type, out string name, out string protection)
 		{
 			name = "";
+			protection = "";
 			c_type = field.GetAttribute ("type");
 			type = SymbolTable.Table.GetCSType (c_type);
 			if (IsBit (field)) {
 				type = "uint";
+				protection = "private";
 			} else if ((IsPointer (field) || SymbolTable.Table.IsOpaque (c_type)) && type != "string") {
 				type = "IntPtr";
 				name = "_";
+				protection = "private";
 			} else if (SymbolTable.Table.IsCallback (c_type)) {
 				type = "IntPtr";
+				protection = "private";
+			} else if (IsPadding (field)) {
+				protection = "private";
 			} else {
 				if (type == "") {
 					Console.WriteLine ("Field has unknown Type {0}", c_type);
 					Statistics.ThrottledCount++;
 					return false;
 				}
+
+				protection = "public";
 			}
 			
 			// FIXME: marshalling not implemented here in mono 
-			if (field.HasAttribute("array_len"))
+			if (field.HasAttribute("array_len")) {
 				type = "IntPtr";
+				protection = "private";
+			}
 
 			if (IsBit (field))
 				name = String.Format ("_bitfield{0}", bitfields++);
@@ -148,10 +164,10 @@ namespace GtkSharp.Generation {
 
 		protected bool GenField (XmlElement field, StreamWriter sw)
 		{
-			string c_type, type, name;
-			if (!GetFieldInfo (field, out c_type, out type, out name))
+			string c_type, type, name, protection;
+			if (!GetFieldInfo (field, out c_type, out type, out name, out protection))
 				return false;
-			sw.WriteLine ("\t\tpublic {0} {1};", type, SymbolTable.Table.MangleName (name));
+			sw.WriteLine ("\t\t{0} {1} {2};", protection, type, SymbolTable.Table.MangleName (name));
 
 			if (field.HasAttribute("array_len"))
 				Console.WriteLine ("warning: array field {0}.{1} probably incorrectly generated", QualifiedName, name);

--LZvS9be/3tNcYl/X--