Author: danw
Date: 2005-05-02 14:40:30 -0400 (Mon, 02 May 2005)
New Revision: 43896

Added:
   trunk/gtk-sharp/generator/FieldBase.cs
   trunk/gtk-sharp/generator/PropertyBase.cs
   trunk/gtk-sharp/generator/StructField.cs
Removed:
   trunk/gtk-sharp/generator/Field.cs
Modified:
   trunk/gtk-sharp/ChangeLog
   trunk/gtk-sharp/generator/Makefile.am
   trunk/gtk-sharp/generator/Property.cs
   trunk/gtk-sharp/generator/StructBase.cs
   trunk/gtk-sharp/gnome/Gnome.metadata
Log:
        Apply the parts of the generator reorganization from #69514 that
        don't actually affect the generated output
        
        * generator/PropertyBase.cs: new base class for fields and
        properties (mostly containing code formerly in Property.cs).

        * generator/Property.cs: derive from PropertyBase

        * generator/FieldBase.cs: base class for fields (containing some
        code formerly in Field.cs)

        * generator/StructField.cs: class for struct fields (the rest of
        what used to be Field.cs)

        * generator/StructBase.cs: s/Field/StructField/

        * gnome/Gnome.metadata: hide a few funky _get_ methods that the
        generator is just now noticing, to preserve the old output.


Modified: trunk/gtk-sharp/ChangeLog
===================================================================
--- trunk/gtk-sharp/ChangeLog   2005-05-02 18:23:04 UTC (rev 43895)
+++ trunk/gtk-sharp/ChangeLog   2005-05-02 18:40:30 UTC (rev 43896)
@@ -1,3 +1,24 @@
+2005-05-02  Dan Winship  <[EMAIL PROTECTED]>
+
+       Apply the parts of the generator reorganization from #69514 that
+       don't actually affect the generated output
+       
+       * generator/PropertyBase.cs: new base class for fields and
+       properties (mostly containing code formerly in Property.cs).
+
+       * generator/Property.cs: derive from PropertyBase
+
+       * generator/FieldBase.cs: base class for fields (containing some
+       code formerly in Field.cs)
+
+       * generator/StructField.cs: class for struct fields (the rest of
+       what used to be Field.cs)
+
+       * generator/StructBase.cs: s/Field/StructField/
+
+       * gnome/Gnome.metadata: hide a few _get_ methods that the
+       generator is just now noticing, to preserve the old output.
+
 2005-05-02  Mike Kestner  <[EMAIL PROTECTED]>
 
        * generator/Property.cs : fix interface setter generation.

Deleted: trunk/gtk-sharp/generator/Field.cs
===================================================================
--- trunk/gtk-sharp/generator/Field.cs  2005-05-02 18:23:04 UTC (rev 43895)
+++ trunk/gtk-sharp/generator/Field.cs  2005-05-02 18:40:30 UTC (rev 43896)
@@ -1,225 +0,0 @@
-// GtkSharp.Generation.Field.cs - The Field generation Class.
-//
-// Author: Mike Kestner <[EMAIL PROTECTED]>
-//
-// Copyright (c) 2004 Novell, Inc.
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of version 2 of the GNU General Public
-// License as published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public
-// License along with this program; if not, write to the
-// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-// Boston, MA 02111-1307, USA.
-
-
-namespace GtkSharp.Generation {
-
-       using System;
-       using System.IO;
-       using System.Xml;
-
-       public class Field {
-
-               public static int bitfields;
-
-               XmlElement elem;
-
-               public Field (XmlElement elem)
-               {
-                       this.elem = elem;
-               }
-
-               public string Access {
-                       get {
-                               return elem.HasAttribute ("access") ? 
elem.GetAttribute ("access") : "public";
-                       }
-               }
-
-               public int ArrayLength {
-                       get {
-                               if (!IsArray)
-                                       return 0;
-                               
-                               int result;
-                               try {
-                                       result = Int32.Parse 
(elem.GetAttribute("array_len"));
-                               } catch (Exception e) {
-                                       Console.Write ("Non-numeric array_len: 
" + elem.GetAttribute("array_len"));
-                                       Console.WriteLine (" warning: array 
field {0} incorrectly generated", Name);
-                                       result = 0;
-                               }
-                               return result;
-                       }
-               }
-
-               public string CSType {
-                       get {
-                               string type = SymbolTable.Table.GetCSType 
(CType);
-                               if (IsArray)
-                                       type += "[]";
-                               else if (IsBit)
-                                       type = "uint";
-                               else if ((IsPointer || 
SymbolTable.Table.IsOpaque (CType)) && type != "string")
-                                       type = "IntPtr";
-                               else if (SymbolTable.Table.IsCallback (CType))
-                                       type = "IntPtr";
-
-                               return type;
-                       }
-               }
-
-               public string CType {
-                       get {
-                               return elem.GetAttribute ("type");
-                       }
-               }
-
-               public bool Hidden {
-                       get {
-                               return elem.HasAttribute("hidden");
-                       }
-               }
-
-               public bool IsArray {
-                       get {
-                               return elem.HasAttribute("array_len");
-                       }
-               }
-
-               public bool IsBit {
-                       get {
-                               return (elem.HasAttribute("bits") && 
(elem.GetAttribute("bits") == "1"));
-                       }
-               }
-
-               public bool IsPadding {
-                       get {
-                               string c_name = elem.GetAttribute ("cname");
-                               return (c_name.StartsWith ("dummy") || 
c_name.StartsWith ("padding"));
-                       }
-               }
-
-               public bool IsPointer {
-                       get {
-                               return (CType.EndsWith ("*") || CType.EndsWith 
("pointer"));
-                       }
-               }
-
-               public string Name {
-                       get {
-                               string result = "";
-                               if ((IsPointer || SymbolTable.Table.IsOpaque 
(CType)) && CSType != "string")
-                                       result = "_";
-
-                               if (IsBit)
-                                       result = String.Format ("_bitfield{0}", 
bitfields++);
-                               else
-                                       result += SymbolTable.Table.MangleName 
(elem.GetAttribute ("cname"));
-
-                               return result;
-                       }
-               }
-
-               public string StudlyName {
-                       get {
-                               string studly = elem.GetAttribute ("name");
-                               if (studly != "")
-                                       return studly;
-
-                               // FIXME: this is backward compatibility for 
API files
-                               // output by older versions of the parser. It 
can go
-                               // away at some point.
-                               string name = elem.GetAttribute ("cname");
-                               string[] segs = name.Split('_');
-                               foreach (string s in segs) {
-                                       if (s.Trim () == "")
-                                               continue;
-                                       studly += (s.Substring(0,1).ToUpper() + 
s.Substring(1));
-                               }
-                               return studly;
-                       }
-               }
-
-               public bool Validate ()
-               {
-                       if (CSType == "" && !Hidden) {
-                               Console.Write ("Field has unknown Type {0} ", 
CType);
-                               Statistics.ThrottledCount++;
-                               return false;
-                       }
-                       return true;
-               }
-
-               public void Generate (StreamWriter sw)
-               {
-                       if (Hidden)
-                               return;
-
-                       SymbolTable table = SymbolTable.Table;
-
-                       if (IsArray) 
-                               sw.WriteLine ("\t\t[MarshalAs 
(UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
-
-                       string wrapped = table.GetCSType (CType);
-                       string wrapped_name = SymbolTable.Table.MangleName 
(elem.GetAttribute ("cname"));
-                       IGeneratable gen = table [CType];
-
-                       if (IsArray) {
-                               sw.WriteLine ("\t\t{0} {1} {2};", Access, 
CSType, StudlyName);
-                       } else if (IsPadding) {
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-                       } else if (IsBit) {
-                               // FIXME
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-                       } else if (table.IsCallback (CType)) {
-                               // FIXME
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-                       } else if (gen is LPGen || gen is LPUGen) {
-                               sw.WriteLine ("\t\tprivate " + gen.MarshalType 
+ " " + Name + ";");
-                               sw.WriteLine ("\t\tpublic " + CSType + " " + 
StudlyName + " {");
-                               sw.WriteLine ("\t\t\tget {");
-                               sw.WriteLine ("\t\t\t\treturn " + 
gen.FromNative (Name) + ";");
-                               sw.WriteLine ("\t\t\t}");
-                               sw.WriteLine ("\t\t\tset {");
-                               sw.WriteLine ("\t\t\t\t" + Name + " = " + 
gen.CallByName ("value") + ";");
-                               sw.WriteLine ("\t\t\t}");
-                               sw.WriteLine ("\t\t}");
-                       } else if (table.IsObject (CType) || table.IsOpaque 
(CType)) {
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-
-                               if (Access != "private") {
-                                       sw.WriteLine ("\t\t" + Access + " " + 
wrapped + " " + wrapped_name + " {");
-                                       sw.WriteLine ("\t\t\tget { ");
-                                       sw.WriteLine ("\t\t\t\treturn " + 
table.FromNativeReturn(CType, Name) + ";");
-                                       sw.WriteLine ("\t\t\t}");
-
-                                       sw.WriteLine ("\t\t\tset { " + Name + " 
= " + table.CallByName (CType, "value") + "; }");
-                                       sw.WriteLine ("\t\t}");
-                               }
-                       } else if (IsPointer && (table.IsStruct (CType) || 
table.IsBoxed (CType))) {
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-                               sw.WriteLine ();
-                               if (Access != "private") {
-                                       sw.WriteLine ("\t\t" + Access + " " + 
wrapped + " " + wrapped_name + " {");
-                                       sw.WriteLine ("\t\t\tget { return " + 
table.FromNativeReturn (CType, Name) + "; }");
-                                       sw.WriteLine ("\t\t}");
-                               }
-                       } else if (IsPointer && CSType != "string") {
-                               // FIXME: probably some fields here which 
should be visible.
-                               sw.WriteLine ("\t\tprivate {0} {1};", CSType, 
Name);
-                       } else if (Access != "public") {
-                               sw.WriteLine ("\t\t{0} {1} {2};", Access, 
CSType, Name);
-                       } else {
-                               sw.WriteLine ("\t\tpublic {0} {1};", CSType, 
StudlyName);
-                       }
-               }
-       }
-}
-

Added: trunk/gtk-sharp/generator/FieldBase.cs
===================================================================
--- trunk/gtk-sharp/generator/FieldBase.cs      2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/generator/FieldBase.cs      2005-05-02 18:40:30 UTC (rev 
43896)
@@ -0,0 +1,70 @@
+// GtkSharp.Generation.FieldBase.cs - base class for struct and object
+// fields
+//
+// Copyright (c) 2004 Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of version 2 of the GNU General Public
+// License as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this program; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+
+namespace GtkSharp.Generation {
+
+       using System;
+       using System.Collections;
+       using System.IO;
+       using System.Xml;
+
+       public abstract class FieldBase : PropertyBase {
+               public FieldBase (XmlElement elem, ClassBase container_type) : 
base (elem, container_type) {}
+
+               protected virtual bool Readable {
+                       get {
+                               return elem.GetAttribute ("readable") != 
"false";
+                       }
+               }
+
+               protected virtual bool Writable {
+                       get {
+                               return elem.GetAttribute ("writeable") != 
"false";
+                       }
+               }
+
+               protected abstract string DefaultAccess { get; }
+
+               protected string Access {
+                       get {
+                               return elem.HasAttribute ("access") ? 
elem.GetAttribute ("access") : DefaultAccess;
+                       }
+               }
+
+               public bool IsArray {
+                       get {
+                               return elem.HasAttribute("array_len") || 
elem.HasAttribute("array");
+                       }
+               }
+
+               public bool IsBitfield {
+                       get {
+                               return elem.HasAttribute("bits");
+                       }
+               }
+
+               public bool Ignored {
+                       get {
+                               return IsArray || Access == "private";
+                       }
+               }
+       }
+}
+

Modified: trunk/gtk-sharp/generator/Makefile.am
===================================================================
--- trunk/gtk-sharp/generator/Makefile.am       2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/generator/Makefile.am       2005-05-02 18:40:30 UTC (rev 
43896)
@@ -18,7 +18,7 @@
        ConstStringGen.cs               \
        Ctor.cs                         \
        EnumGen.cs                      \
-       Field.cs                        \
+       FieldBase.cs                    \
        GenBase.cs                      \
        GenerationInfo.cs               \
        IGeneratable.cs                 \
@@ -38,6 +38,7 @@
        Parameters.cs                   \
        Parser.cs                       \
        Property.cs                     \
+       PropertyBase.cs                 \
        ReturnValue.cs                  \
        Signal.cs                       \
        Signature.cs                    \
@@ -45,6 +46,7 @@
        SimpleGen.cs                    \
        Statistics.cs                   \
        StructBase.cs                   \
+       StructField.cs                  \
        StructGen.cs                    \
        SymbolTable.cs                  \
        VirtualMethod.cs                \

Modified: trunk/gtk-sharp/generator/Property.cs
===================================================================
--- trunk/gtk-sharp/generator/Property.cs       2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/generator/Property.cs       2005-05-02 18:40:30 UTC (rev 
43896)
@@ -27,31 +27,14 @@
        using System.IO;
        using System.Xml;
 
-       public class Property {
+       public class Property : PropertyBase {
 
-               protected XmlElement elem;
-               protected ClassBase container_type;
+               public Property (XmlElement elem, ClassBase container_type) : 
base (elem, container_type) {}
 
-               public string Name {
-                       get {
-                               return elem.GetAttribute ("name");
-                       }
-               }
-
-               public Property (XmlElement elem, ClassBase container_type)
-               {
-                       this.elem = elem;
-                       this.container_type = container_type;
-               }
-
                public bool Validate ()
                {
-                       string c_type = elem.GetAttribute("type");
-                       SymbolTable table = SymbolTable.Table;
-                       string cs_type = table.GetCSType(c_type);
-
-                       if (cs_type == "") {
-                               Console.Write("Property has unknown Type {0} ", 
c_type);
+                       if (CSType == "" && !Hidden) {
+                               Console.Write("Property has unknown Type {0} ", 
CType);
                                Statistics.ThrottledCount++;
                                return false;
                        }
@@ -59,6 +42,19 @@
                        return true;
                }
 
+               bool Readable {
+                       get {
+                               return elem.GetAttribute ("readable") == "true";
+                       }
+               }
+
+               bool Writable {
+                       get {
+                               return elem.GetAttribute ("writeable") == 
"true" &&
+                                       !elem.HasAttribute ("construct-only");
+                       }
+               }
+
                protected virtual string PropertyAttribute (string qpname) {
                        return "[GLib.Property (" + qpname + ")]";
                }
@@ -71,92 +67,57 @@
                        return "SetProperty(" + qpname + ", val)";
                }
 
-               public void Generate (GenerationInfo gen_info, string indent)
+               public override void Generate (GenerationInfo gen_info, string 
indent)
                {
                        SymbolTable table = SymbolTable.Table;
                        StreamWriter sw = gen_info.Writer;
 
-                       string c_type = elem.GetAttribute("type");
-                       string cs_type = table.GetCSType(c_type);
+                       if (Hidden || (!Readable && !Writable))
+                               return;
+
                        string modifiers = "";
 
-                       if (elem.HasAttribute("new_flag") || 
(container_type.Parent != null && container_type.Parent.GetPropertyRecursively 
(Name) != null))
+                       if (IsNew || (container_type.Parent != null && 
container_type.Parent.GetPropertyRecursively (Name) != null))
                                modifiers = "new ";
 
                        string name = Name;
                        if (name == container_type.Name) {
                                name += "Prop";
                        }
-                       string qpname = "\"" + elem.GetAttribute("cname") + 
"\"";
+                       string qpname = "\"" + CName + "\"";
 
                        string v_type = "";
-                       if (table.IsEnum(c_type)) {
+                       if (table.IsEnum(CType)) {
                                v_type = "(int) (GLib.EnumWrapper)";
-                       } else if (table.IsObject(c_type) || table.IsInterface 
(c_type)) {
+                       } else if (table.IsObject(CType) || table.IsInterface 
(CType)) {
                                v_type = "(GLib.UnwrappedObject)";
-                       } else if (table.IsBoxed (c_type)) {
+                       } else if (table.IsBoxed (CType)) {
                                v_type = "(GLib.Boxed)";
-                       } else if (table.IsOpaque (c_type)) {
+                       } else if (table.IsOpaque (CType)) {
                                v_type = "(GLib.Opaque)";
                        }
 
-                       if (elem.HasAttribute("construct-only") && 
!elem.HasAttribute("readable")) {
-                               return;
-                       }
+                       GenerateImports (gen_info, indent);
 
-                       bool has_getter = false;
-                       bool has_setter = false;
-                       string getter_type = String.Empty;
-                       string setter_type = String.Empty;
-
-                       Method getter = container_type.GetMethod("Get" + Name);
-                       if (getter != null && getter.Validate () && 
getter.IsGetter)
-                               getter_type = getter.ReturnType;
-
-                       Method setter = container_type.GetMethod("Set" + Name);
-                       if (setter != null && setter.Validate () && 
setter.IsSetter)
-                               setter_type = setter.Signature.Types;
-
-                       if (getter_type != String.Empty && getter_type == 
setter_type) {
-                               has_getter = has_setter = true;
-                               getter.GenerateImport (sw);
-                               setter.GenerateImport (sw);
-                               cs_type = getter_type;
-                       } else {
-                               if (getter_type == cs_type) {
-                                       has_getter = true;
-                                       getter.GenerateImport(sw);
-                               }
-                               if (setter_type != String.Empty) {
-                                       has_setter = true;
-                                       setter.GenerateImport(sw);
-                               }
-
-                               if (has_setter && setter_type != cs_type)
-                                       cs_type = setter_type;
-                               else if (has_getter && getter_type != cs_type)
-                                       cs_type = getter_type;
-                       }
-
                        sw.WriteLine (indent + PropertyAttribute (qpname));
-                       sw.WriteLine (indent + "public " + modifiers + cs_type 
+ " " + name + " {");
+                       sw.WriteLine (indent + "public " + modifiers + CSType + 
" " + name + " {");
                        indent += "\t";
 
-                       if (has_getter) {
+                       if (Getter != null) {
                                sw.Write(indent + "get ");
-                               getter.GenerateBody(gen_info, "\t");
+                               Getter.GenerateBody(gen_info, "\t");
                                sw.WriteLine();
-                       } else if (elem.HasAttribute("readable")) {
+                       } else if (Readable) {
                                sw.WriteLine(indent + "get {");
                                sw.WriteLine(indent + "\tGLib.Value val = " + 
RawGetter (qpname) + ";");
-                               if (table.IsObject (c_type) || 
table.IsInterface (c_type)) {
+                               if (table.IsObject (CType) || table.IsInterface 
(CType)) {
                                        sw.WriteLine(indent + "\tSystem.IntPtr 
raw_ret = (System.IntPtr) {0} val;", v_type);
-                                       sw.WriteLine(indent + "\t" + cs_type + 
" ret = " + table.FromNativeReturn(c_type, "raw_ret") + ";");
-                               } else if (table.IsOpaque (c_type) || 
table.IsBoxed (c_type)) {
-                                       sw.WriteLine(indent + "\t" + cs_type + 
" ret = (" + cs_type + ") val;");
+                                       sw.WriteLine(indent + "\t" + CSType + " 
ret = " + table.FromNativeReturn(CType, "raw_ret") + ";");
+                               } else if (table.IsOpaque (CType) || 
table.IsBoxed (CType)) {
+                                       sw.WriteLine(indent + "\t" + CSType + " 
ret = (" + CSType + ") val;");
                                } else {
-                                       sw.Write(indent + "\t" + cs_type + " 
ret = ");
-                                       sw.Write ("(" + cs_type + ") ");
+                                       sw.Write(indent + "\t" + CSType + " ret 
= ");
+                                       sw.Write ("(" + CSType + ") ");
                                        if (v_type != "") {
                                                sw.Write(v_type + " ");
                                        }
@@ -168,22 +129,22 @@
                                sw.WriteLine(indent + "}");
                        }
 
-                       if (has_setter) {
+                       if (Setter != null) {
                                sw.Write(indent + "set ");
-                               setter.GenerateBody(gen_info, "\t");
+                               Setter.GenerateBody(gen_info, "\t");
                                sw.WriteLine();
-                       } else if (elem.HasAttribute("writeable") && 
!elem.HasAttribute("construct-only")) {
+                       } else if (Writable) {
                                sw.WriteLine(indent + "set {");
                                sw.Write(indent + "\tGLib.Value val = ");
-                               if (table.IsEnum(c_type)) {
-                                       sw.WriteLine("new GLib.Value(new 
GLib.EnumWrapper ((int) value, {0}), \"{1}\");", table.IsEnumFlags (c_type) ? 
"true" : "false", c_type);
-                               } else if (table.IsBoxed (c_type)) {
+                               if (table.IsEnum(CType)) {
+                                       sw.WriteLine("new GLib.Value(new 
GLib.EnumWrapper ((int) value, {0}), \"{1}\");", table.IsEnumFlags (CType) ? 
"true" : "false", CType);
+                               } else if (table.IsBoxed (CType)) {
                                        sw.WriteLine("(GLib.Value) value;");
-                               } else if (table.IsOpaque (c_type)) {
-                                       sw.WriteLine("new GLib.Value(value, 
\"{0}\");", c_type);
+                               } else if (table.IsOpaque (CType)) {
+                                       sw.WriteLine("new GLib.Value(value, 
\"{0}\");", CType);
                                } else {
                                        sw.Write("new GLib.Value(");
-                                       if (v_type != "" && !(table.IsObject 
(c_type) || table.IsInterface (c_type) || table.IsOpaque (c_type))) {
+                                       if (v_type != "" && !(table.IsObject 
(CType) || table.IsInterface (CType) || table.IsOpaque (CType))) {
                                                sw.Write(v_type + " ");
                                        }
                                        sw.WriteLine("value);");

Added: trunk/gtk-sharp/generator/PropertyBase.cs
===================================================================
--- trunk/gtk-sharp/generator/PropertyBase.cs   2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/generator/PropertyBase.cs   2005-05-02 18:40:30 UTC (rev 
43896)
@@ -0,0 +1,120 @@
+// GtkSharp.Generation.PropertyBase.cs - base class for properties and
+// fields
+//
+// Copyright (c) 2005 Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of version 2 of the GNU General Public
+// License as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this program; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+
+namespace GtkSharp.Generation {
+
+       using System;
+       using System.Xml;
+
+       public abstract class PropertyBase {
+
+               protected XmlElement elem;
+               protected ClassBase container_type;
+
+               public PropertyBase (XmlElement elem, ClassBase container_type)
+               {
+                       this.elem = elem;
+                       this.container_type = container_type;
+               }
+
+               public string Name {
+                       get {
+                               return elem.GetAttribute ("name");
+                       }
+               }
+
+               public string CName {
+                       get {
+                               return elem.GetAttribute ("cname");
+                       }
+               }
+
+               protected string ctype;
+               public string CType {
+                       get {
+                               if (ctype == null)
+                                       ctype = elem.GetAttribute ("type");
+                               return ctype;
+                       }
+               }
+
+               protected string cstype;
+               public string CSType {
+                       get {
+                               if (cstype == null)
+                                       cstype = SymbolTable.Table.GetCSType 
(CType);
+                               return cstype;
+                       }
+               }
+
+               public bool Hidden {
+                       get {
+                               return elem.HasAttribute("hidden");
+                       }
+               }
+
+               protected bool IsNew {
+                       get {
+                               return elem.HasAttribute("new_flag");
+                       }
+               }
+
+               Method getter;
+               protected Method Getter {
+                       get {
+                               if (getter == null) {
+                                       getter = container_type.GetMethod 
("Get" + Name);
+                                       if (getter != null && getter.Name == 
"Get" + Name &&
+                                           getter.Validate () && 
getter.IsGetter)
+                                               cstype = getter.ReturnType;
+                                       else
+                                               getter = null;
+                               }
+                               return getter;
+                       }
+               }
+
+               Method setter;
+               protected Method Setter {
+                       get {
+                               if (setter == null) {
+                                       setter = container_type.GetMethod 
("Set" + Name);
+                                       if (setter != null && setter.Name == 
"Set" + Name &&
+                                           setter.Validate () && 
setter.IsSetter)
+                                               cstype = setter.Signature.Types;
+                                       else
+                                               setter = null;
+                               }
+                               return setter;
+                       }
+               }
+
+               protected virtual void GenerateImports (GenerationInfo 
gen_info, string indent)
+               {
+                       if (Getter != null)
+                               Getter.GenerateImport (gen_info.Writer);
+                       if (Setter != null)
+                               Setter.GenerateImport (gen_info.Writer);
+               }
+
+               public abstract void Generate (GenerationInfo gen_info, string 
indent);
+       }
+}
+

Modified: trunk/gtk-sharp/generator/StructBase.cs
===================================================================
--- trunk/gtk-sharp/generator/StructBase.cs     2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/generator/StructBase.cs     2005-05-02 18:40:30 UTC (rev 
43896)
@@ -40,7 +40,7 @@
 
                                switch (node.Name) {
                                case "field":
-                                       fields.Add (new Field (member));
+                                       fields.Add (new StructField (member, 
this));
                                        break;
 
                                case "callback":
@@ -112,11 +112,11 @@
                        }
                }
 
-               protected void GenFields (StreamWriter sw)
+               protected void GenFields (GenerationInfo gen_info)
                {
-                       Field.bitfields = 0;
+                       StructField.bitfields = 0;
                        bool need_field = true;
-                       foreach (Field field in fields) {
+                       foreach (StructField field in fields) {
                                if (field.IsBit) {
                                        if (need_field)
                                                need_field = false;
@@ -124,13 +124,13 @@
                                                continue;
                                } else
                                        need_field = true;
-                               field.Generate (sw);    
+                               field.Generate (gen_info, "\t\t");
                        }
                }
 
                public bool Validate ()
                {
-                       foreach (Field field in fields) {
+                       foreach (StructField field in fields) {
                                if (!field.Validate ()) {
                                        Console.WriteLine ("in Struct " + 
QualifiedName);
                                        return false;
@@ -162,7 +162,7 @@
                        sw.WriteLine ("\tpublic struct " + Name + " {");
                        sw.WriteLine ();
 
-                       GenFields (sw);
+                       GenFields (gen_info);
                        sw.WriteLine ();
                        GenCtors (gen_info);
                        GenMethods (gen_info, null, null);

Copied: trunk/gtk-sharp/generator/StructField.cs (from rev 43789, 
trunk/gtk-sharp/generator/Field.cs)
===================================================================
--- trunk/gtk-sharp/generator/Field.cs  2005-04-29 14:03:33 UTC (rev 43789)
+++ trunk/gtk-sharp/generator/StructField.cs    2005-05-02 18:40:30 UTC (rev 
43896)
@@ -0,0 +1,203 @@
+// GtkSharp.Generation.StructField.cs - The Structure Field generation
+// Class.
+//
+// Author: Mike Kestner <[EMAIL PROTECTED]>
+//
+// Copyright (c) 2004 Novell, Inc.
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of version 2 of the GNU General Public
+// License as published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public
+// License along with this program; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+
+namespace GtkSharp.Generation {
+
+       using System;
+       using System.IO;
+       using System.Xml;
+
+       public class StructField : FieldBase {
+
+               public static int bitfields;
+
+               public StructField (XmlElement elem, ClassBase container_type) 
: base (elem, container_type) {}
+
+               protected override string DefaultAccess {
+                       get {
+                               return "public";
+                       }
+               }
+
+               public int ArrayLength {
+                       get {
+                               if (!IsArray)
+                                       return 0;
+                               
+                               int result;
+                               try {
+                                       result = Int32.Parse 
(elem.GetAttribute("array_len"));
+                               } catch (Exception e) {
+                                       Console.Write ("Non-numeric array_len: 
" + elem.GetAttribute("array_len"));
+                                       Console.WriteLine (" warning: array 
field {0} incorrectly generated", Name);
+                                       result = 0;
+                               }
+                               return result;
+                       }
+               }
+
+               public new string CSType {
+                       get {
+                               string type = base.CSType;
+                               if (IsArray)
+                                       type += "[]";
+                               else if (IsBit)
+                                       type = "uint";
+                               else if ((IsPointer || 
SymbolTable.Table.IsOpaque (CType)) && type != "string")
+                                       type = "IntPtr";
+                               else if (SymbolTable.Table.IsCallback (CType))
+                                       type = "IntPtr";
+
+                               return type;
+                       }
+               }
+
+               public bool IsBit {
+                       get {
+                               return elem.GetAttribute("bits") == "1";
+                       }
+               }
+
+               public bool IsPadding {
+                       get {
+                               return (CName.StartsWith ("dummy") || 
CName.StartsWith ("padding"));
+                       }
+               }
+
+               public bool IsPointer {
+                       get {
+                               return (CType.EndsWith ("*") || CType.EndsWith 
("pointer"));
+                       }
+               }
+
+               public new string Name {
+                       get {
+                               string result = "";
+                               if ((IsPointer || SymbolTable.Table.IsOpaque 
(CType)) && CSType != "string")
+                                       result = "_";
+
+                               if (IsBit)
+                                       result = String.Format ("_bitfield{0}", 
bitfields++);
+                               else
+                                       result += SymbolTable.Table.MangleName 
(CName);
+
+                               return result;
+                       }
+               }
+
+               public string StudlyName {
+                       get {
+                               string studly = base.Name;
+                               if (studly != "")
+                                       return studly;
+
+                               // FIXME: this is backward compatibility for 
API files
+                               // output by older versions of the parser. It 
can go
+                               // away at some point.
+                               string name = CName;
+                               string[] segs = name.Split('_');
+                               foreach (string s in segs) {
+                                       if (s.Trim () == "")
+                                               continue;
+                                       studly += (s.Substring(0,1).ToUpper() + 
s.Substring(1));
+                               }
+                               return studly;
+                       }
+               }
+
+               public bool Validate ()
+               {
+                       if (CSType == "" && !Hidden) {
+                               Console.Write ("Field {0} has unknown Type {1} 
", Name, CType);
+                               Statistics.ThrottledCount++;
+                               return false;
+                       }
+                       return true;
+               }
+
+               public override void Generate (GenerationInfo gen_info, string 
indent)
+               {
+                       if (Hidden)
+                               return;
+
+                       StreamWriter sw = gen_info.Writer;
+                       SymbolTable table = SymbolTable.Table;
+
+                       if (IsArray) 
+                               sw.WriteLine (indent + "[MarshalAs 
(UnmanagedType.ByValArray, SizeConst=" + ArrayLength + ")]");
+
+                       string wrapped = table.GetCSType (CType);
+                       string wrapped_name = SymbolTable.Table.MangleName 
(CName);
+                       IGeneratable gen = table [CType];
+
+                       if (IsArray) {
+                               sw.WriteLine (indent + "{0} {1} {2};", Access, 
CSType, StudlyName);
+                       } else if (IsPadding) {
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+                       } else if (IsBit) {
+                               // FIXME
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+                       } else if (table.IsCallback (CType)) {
+                               // FIXME
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+                       } else if (gen is LPGen || gen is LPUGen) {
+                               sw.WriteLine (indent + "private " + 
gen.MarshalType + " " + Name + ";");
+                               sw.WriteLine (indent + "public " + CSType + " " 
+ StudlyName + " {");
+                               sw.WriteLine (indent + "\tget {");
+                               sw.WriteLine (indent + "\t\treturn " + 
gen.FromNative (Name) + ";");
+                               sw.WriteLine (indent + "\t}");
+                               sw.WriteLine (indent + "\tset {");
+                               sw.WriteLine (indent + "\t\t" + Name + " = " + 
gen.CallByName ("value") + ";");
+                               sw.WriteLine (indent + "\t}");
+                               sw.WriteLine (indent + "}");
+                       } else if (table.IsObject (CType) || table.IsOpaque 
(CType)) {
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+
+                               if (Access != "private") {
+                                       sw.WriteLine (indent + "" + Access + " 
" + wrapped + " " + wrapped_name + " {");
+                                       sw.WriteLine (indent + "\tget { ");
+                                       sw.WriteLine (indent + "\t\treturn " + 
table.FromNativeReturn(CType, Name) + ";");
+                                       sw.WriteLine (indent + "\t}");
+
+                                       sw.WriteLine (indent + "\tset { " + 
Name + " = " + table.CallByName (CType, "value") + "; }");
+                                       sw.WriteLine (indent + "}");
+                               }
+                       } else if (IsPointer && (table.IsStruct (CType) || 
table.IsBoxed (CType))) {
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+                               sw.WriteLine ();
+                               if (Access != "private") {
+                                       sw.WriteLine (indent + "" + Access + " 
" + wrapped + " " + wrapped_name + " {");
+                                       sw.WriteLine (indent + "\tget { return 
" + table.FromNativeReturn (CType, Name) + "; }");
+                                       sw.WriteLine (indent + "}");
+                               }
+                       } else if (IsPointer && CSType != "string") {
+                               // FIXME: probably some fields here which 
should be visible.
+                               sw.WriteLine (indent + "private {0} {1};", 
CSType, Name);
+                       } else if (Access != "public") {
+                               sw.WriteLine (indent + "{0} {1} {2};", Access, 
CSType, Name);
+                       } else {
+                               sw.WriteLine (indent + "public {0} {1};", 
CSType, StudlyName);
+                       }
+               }
+       }
+}
+

Modified: trunk/gtk-sharp/gnome/Gnome.metadata
===================================================================
--- trunk/gtk-sharp/gnome/Gnome.metadata        2005-05-02 18:23:04 UTC (rev 
43895)
+++ trunk/gtk-sharp/gnome/Gnome.metadata        2005-05-02 18:40:30 UTC (rev 
43896)
@@ -55,6 +55,7 @@
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeCanvasShape']/[EMAIL 
PROTECTED]'Dash']" name="type">ArtVpathDash</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeClient']/[EMAIL 
PROTECTED]'Connect']" name="name">Connected</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeClient']/[EMAIL 
PROTECTED]'Disconnect']" name="name">Disconnected</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDateEdit']/[EMAIL 
PROTECTED]'GetInitialTime']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDialog']/[EMAIL 
PROTECTED]'Close']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDialog']/[EMAIL 
PROTECTED]'SetClose']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDialog']/[EMAIL 
PROTECTED]'SetDefault']" name="new_flag">1</attr>
@@ -68,7 +69,7 @@
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDruidPageEdge']/[EMAIL 
PROTECTED]'gnome_druid_page_edge_new']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDruidPageEdge']/[EMAIL 
PROTECTED]'gnome_druid_page_edge_new_with_vals']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeDruidPageEdge']/[EMAIL 
PROTECTED]'gnome_druid_page_edge_new_aa']" name="hidden">1</attr>
-  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeEntry']/[EMAIL 
PROTECTED]'GtkEntry']" name="name">GetGtkEntry</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeEntry']/[EMAIL 
PROTECTED]'GtkEntry']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeEntry']/[EMAIL 
PROTECTED]'Activate']" name="name">Activated</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFileEntry']/[EMAIL 
PROTECTED]'GnomeEntry']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFileEntry']/[EMAIL 
PROTECTED]'GtkEntry']" name="hidden">1</attr>
@@ -78,14 +79,16 @@
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/[EMAIL 
PROTECTED]'StyleList']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/[EMAIL 
PROTECTED]'StyleListFree']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/method/*/[EMAIL 
PROTECTED]'const-guchar*']" name="type">const-gchar*</attr>
-  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/method/*/[EMAIL 
PROTECTED]'const-guchar*']" name="type">const-gchar*</attr>
-  <attr path="/api/namespace/[EMAIL 
PROTECTED]'GnomeFontPreview']/method/*/[EMAIL PROTECTED]'const-guchar*']" 
name="type">const-gchar*</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/[EMAIL 
PROTECTED]'GetFamilyName']/return-type" name="type">const-gchar*</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFont']/[EMAIL 
PROTECTED]'GetFullName']/return-type" name="type">gchar*</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFace']/method/[EMAIL 
PROTECTED]'const-guchar*']" name="type">const-gchar*</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFace']/method/*/[EMAIL 
PROTECTED]'const-guchar*']" name="type">const-gchar*</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFamily']/[EMAIL 
PROTECTED]'List']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFamily']/[EMAIL 
PROTECTED]'ListFree']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFamily']/[EMAIL 
PROTECTED]'StyleList']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontFamily']/[EMAIL 
PROTECTED]'StyleListFree']" name="hidden">1</attr>
+  <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeFontPicker']/[EMAIL 
PROTECTED]'GetFont']" name="hidden">1</attr>
+  <attr path="/api/namespace/[EMAIL 
PROTECTED]'GnomeFontPreview']/method/*/[EMAIL PROTECTED]'const-guchar*']" 
name="type">const-gchar*</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeIconEntry']/[EMAIL 
PROTECTED]'PickDialog']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeIconList']/[EMAIL 
PROTECTED]'gnome_icon_list_new']" name="hidden">1</attr>
   <attr path="/api/namespace/[EMAIL PROTECTED]'GnomeIconList']/[EMAIL 
PROTECTED]'GetSelection']" name="hidden">1</attr>

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to