diff --git a/ChangeLog b/ChangeLog index 836807dbc..37d5e975b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2005-08-04 Dan Winship + + Change the way generatable validation works. Some generatable + properties can't be set until Validate-time (eg, Method.IsGetter), + but it's annoying for every potential user of those properties to + have to make sure it has Validated the generatable first. So now + we add an explicit Validate() step after everything is loaded but + before anything is Generated, so that at Generation time, + everything can be assumed to have been Validated. + + * generator/IGeneratable.cs: add "bool Validate()" + + * generator/CodeGenerator.cs (Main): after loading all of the + generatables, DeAlias the SymbolTable, Validate() all the + generatables, and discard any invalid ones. + + * generator/*.cs: Implement Validate() trivially in generatables + that didn't implement it before. Move Validate() calls from + Generate() to Validate(). Remove non-hierarchical Validate() + calls. + + * generator/SymbolTable.cs: GPtrArray is IntPtr, not IntPtr[] + 2005-08-04 Dan Winship * gtk/TargetList.custom: add an operator for casting to diff --git a/doc/en/Atk/Relation.xml b/doc/en/Atk/Relation.xml index 91a1db1a5..8cb9fbaed 100644 --- a/doc/en/Atk/Relation.xml +++ b/doc/en/Atk/Relation.xml @@ -173,5 +173,17 @@ + + + Property + + System.IntPtr + + + To be added. + To be added. + To be added. + + diff --git a/doc/en/Gnome.Vfs/SocketSetTimeoutFunc.xml b/doc/en/Gnome.Vfs/SocketSetTimeoutFunc.xml deleted file mode 100644 index b150395bc..000000000 --- a/doc/en/Gnome.Vfs/SocketSetTimeoutFunc.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - gnome-vfs-sharp - 2.6.0.0 - - - System.Delegate - - - - Gnome.Vfs.Result - - - To be added. - To be added. - To be added. - - diff --git a/doc/en/GnomeDb/ControlWidget.xml b/doc/en/GnomeDb/ControlWidget.xml index fb686f664..1402472d3 100644 --- a/doc/en/GnomeDb/ControlWidget.xml +++ b/doc/en/GnomeDb/ControlWidget.xml @@ -111,5 +111,14 @@ System.Obsolete(Message=null, IsError=False) + + + Constructor + + + To be added. + To be added. + + diff --git a/doc/en/index.xml b/doc/en/index.xml index 3f3427a8c..a29a11f4b 100644 --- a/doc/en/index.xml +++ b/doc/en/index.xml @@ -1224,7 +1224,6 @@ - diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 94e28e2e4..3d95c375d 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -33,9 +33,6 @@ namespace GtkSharp.Generation { { gen_info.CurrentType = Name; - if (!Validate ()) - return; - StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); sw.WriteLine ("\t\t[DllImport(\"glibsharpglue-2\")]"); diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index d0ef2d935..90c7efe0f 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -39,6 +39,23 @@ namespace GtkSharp.Generation { parms.HideData = true; } + public override bool Validate () + { + if (!retval.Validate ()) { + Console.WriteLine ("rettype: " + retval.CType + " in callback " + CName); + Statistics.ThrottledCount++; + return false; + } + + if (!parms.Validate ()) { + Console.WriteLine (" in callback " + CName); + Statistics.ThrottledCount++; + return false; + } + + return true; + } + public override string MarshalType { get { return NS + "Sharp." + Name + "Native"; @@ -173,16 +190,6 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { gen_info.CurrentType = Name; - if (!retval.Validate ()) { - Console.WriteLine("rettype: " + retval.CType + " in callback " + CName); - Statistics.ThrottledCount++; - return; - } - - if (!parms.Validate ()) { - Console.WriteLine(" in callback " + CName + " **** Stubbing it out ****"); - Statistics.ThrottledCount++; - } sig = new Signature (parms); diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 01ff80be6..a68085636 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -123,6 +123,77 @@ namespace GtkSharp.Generation { } } + public override bool Validate () + { + if (Parent != null && !Parent.Validate ()) + return false; + foreach (string iface in interfaces) { + IGeneratable gen = SymbolTable.Table[iface]; + if (!(gen is InterfaceGen)) { + Console.WriteLine (QualifiedName + " implements unknown GInterface " + iface); + return false; + } + if (!gen.Validate ()) { + Console.WriteLine (QualifiedName + " implements invalid GInterface " + iface); + return false; + } + } + + ArrayList invalids = new ArrayList (); + + foreach (Property prop in props.Values) { + if (!prop.Validate ()) { + Console.WriteLine ("in type " + QualifiedName); + invalids.Add (prop); + } + } + foreach (Property prop in invalids) + props.Remove (prop.Name); + invalids.Clear (); + + foreach (Signal sig in sigs.Values) { + if (!sig.Validate ()) { + Console.WriteLine ("in type " + QualifiedName); + invalids.Add (sig); + } + } + foreach (Signal sig in invalids) + sigs.Remove (sig.Name); + invalids.Clear (); + + foreach (ObjectField field in fields.Values) { + if (!field.Validate ()) { + Console.WriteLine ("in type " + QualifiedName); + invalids.Add (field); + } + } + foreach (ObjectField field in invalids) + fields.Remove (field.Name); + invalids.Clear (); + + foreach (Method method in methods.Values) { + if (!method.Validate ()) { + Console.WriteLine ("in type " + QualifiedName); + invalids.Add (method); + } + } + foreach (Method method in invalids) + methods.Remove (method.Name); + invalids.Clear (); + + foreach (Ctor ctor in ctors) { + if (!ctor.Validate ()) { + Console.WriteLine ("in type " + QualifiedName); + invalids.Add (ctor); + } + } + foreach (Ctor ctor in invalids) + ctors.Remove (ctor); + invalids.Clear (); + + return true; + } + public bool IsDeprecated { get { return deprecated; @@ -161,12 +232,8 @@ namespace GtkSharp.Generation { if (props.Count == 0) return; - foreach (Property prop in props.Values) { - if (prop.Validate ()) - prop.Generate (gen_info, "\t\t", implementor); - else - Console.WriteLine("in Object " + QualifiedName); - } + foreach (Property prop in props.Values) + prop.Generate (gen_info, "\t\t", implementor); } public void GenSignals (GenerationInfo gen_info, ClassBase implementor) @@ -174,22 +241,14 @@ namespace GtkSharp.Generation { if (sigs == null) return; - foreach (Signal sig in sigs.Values) { - if (sig.Validate ()) - sig.Generate (gen_info, implementor); - else - Console.WriteLine("in Object " + QualifiedName); - } + foreach (Signal sig in sigs.Values) + sig.Generate (gen_info, implementor); } protected void GenFields (GenerationInfo gen_info) { - foreach (ObjectField field in fields.Values) { - if (field.Validate ()) - field.Generate (gen_info, "\t\t"); - else - Console.WriteLine("in Object " + QualifiedName); - } + foreach (ObjectField field in fields.Values) + field.Generate (gen_info, "\t\t"); } private void ParseImplements (XmlElement member) @@ -222,25 +281,18 @@ namespace GtkSharp.Generation { if (IgnoreMethod (method)) continue; - if (method.Validate ()) - { - string oname = null, oprotection = null; - if (collisions != null && collisions.Contains (method.Name)) - { - oname = method.Name; - oprotection = method.Protection; - method.Name = QualifiedName + "." + method.Name; - method.Protection = ""; - } - method.Generate (gen_info, implementor); - if (oname != null) - { - method.Name = oname; - method.Protection = oprotection; - } + string oname = null, oprotection = null; + if (collisions != null && collisions.Contains (method.Name)) { + oname = method.Name; + oprotection = method.Protection; + method.Name = QualifiedName + "." + method.Name; + method.Protection = ""; + } + method.Generate (gen_info, implementor); + if (oname != null) { + method.Name = oname; + method.Protection = oprotection; } - else - Console.WriteLine("in Object " + QualifiedName); } } @@ -357,19 +409,16 @@ namespace GtkSharp.Generation { clash_map = new Hashtable(); foreach (Ctor ctor in ctors) { - if (ctor.Validate ()) { - if (clash_map.Contains (ctor.Signature.Types)) { - Ctor clash = clash_map [ctor.Signature.Types] as Ctor; - Ctor alter = ctor.Preferred ? clash : ctor; - alter.IsStatic = true; - if (Parent != null && Parent.HasStaticCtor (alter.StaticName)) - alter.Modifiers = "new "; - } else - clash_map [ctor.Signature.Types] = ctor; - - valid_ctors.Add (ctor); + if (clash_map.Contains (ctor.Signature.Types)) { + Ctor clash = clash_map [ctor.Signature.Types] as Ctor; + Ctor alter = ctor.Preferred ? clash : ctor; + alter.IsStatic = true; + if (Parent != null && Parent.HasStaticCtor (alter.StaticName)) + alter.Modifiers = "new "; } else - Console.WriteLine("in Type " + QualifiedName); + clash_map [ctor.Signature.Types] = ctor; + + valid_ctors.Add (ctor); } ctors = valid_ctors; diff --git a/generator/CodeGenerator.cs b/generator/CodeGenerator.cs index 10d18ddbd..f45c7a0ef 100644 --- a/generator/CodeGenerator.cs +++ b/generator/CodeGenerator.cs @@ -89,6 +89,16 @@ namespace GtkSharp.Generation { gens.AddRange (curr_gens); } + // Now that everything is loaded, validate all the to-be- + // generated generatables and then remove the invalid ones. + ArrayList invalids = new ArrayList (); + foreach (IGeneratable gen in gens) { + if (!gen.Validate ()) + invalids.Add (gen); + } + foreach (IGeneratable gen in invalids) + gens.Remove (gen); + GenerationInfo gen_info = null; if (dir != "" || assembly_name != "" || glue_filename != "" || glue_includes != "" || gluelib_name != "") gen_info = new GenerationInfo (dir, custom_dir, assembly_name, glue_filename, glue_includes, gluelib_name); diff --git a/generator/EnumGen.cs b/generator/EnumGen.cs index 0151cbd9d..056e4eec7 100644 --- a/generator/EnumGen.cs +++ b/generator/EnumGen.cs @@ -50,7 +50,11 @@ namespace GtkSharp.Generation { } } - + public override bool Validate () + { + return true; + } + public override string MarshalType { get { return "int"; diff --git a/generator/GenBase.cs b/generator/GenBase.cs index 77c847bd3..d858407d0 100644 --- a/generator/GenBase.cs +++ b/generator/GenBase.cs @@ -116,6 +116,8 @@ namespace GtkSharp.Generation { return CallByName (var); } + public abstract bool Validate (); + public void Generate () { GenerationInfo geninfo = new GenerationInfo (ns); diff --git a/generator/IGeneratable.cs b/generator/IGeneratable.cs index 28864d30f..001bc0afc 100644 --- a/generator/IGeneratable.cs +++ b/generator/IGeneratable.cs @@ -56,6 +56,8 @@ namespace GtkSharp.Generation { // Generates an expression to convert var to ToNativeReturnType string ToNativeReturn (string var); + bool Validate (); + void Generate (); void Generate (GenerationInfo gen_info); diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index d34fe39ee..7fee5923b 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -171,11 +171,8 @@ namespace GtkSharp.Generation { sw.WriteLine (); sw.WriteLine ("\t\t// signals"); foreach (Signal sig in sigs.Values) { - if (sig.Validate ()) { - sig.GenerateDecl (sw); - sig.GenEventHandler (gen_info); - } else - Console.WriteLine ("of interface " + QualifiedName); + sig.GenerateDecl (sw); + sig.GenEventHandler (gen_info); } } @@ -204,17 +201,14 @@ namespace GtkSharp.Generation { //if (IgnoreMethod (method)) //continue; - if (method.Validate ()) { - if (!vm_decls.Contains (method.Declaration) && method.Name != "GetGType") { - if (need_comment) { - sw.WriteLine (); - sw.WriteLine ("\t\t// non-virtual methods"); - need_comment = false; - } - method.GenerateDecl (sw); + if (!vm_decls.Contains (method.Declaration) && method.Name != "GetGType") { + if (need_comment) { + sw.WriteLine (); + sw.WriteLine ("\t\t// non-virtual methods"); + need_comment = false; } - } else - Console.WriteLine ("of interface " + QualifiedName); + method.GenerateDecl (sw); + } } } @@ -271,28 +265,18 @@ namespace GtkSharp.Generation { sw.WriteLine (); foreach (Signal sig in sigs.Values) { - if (sig.Validate ()) { - sig.GenerateDecl (sw); - sig.GenEventHandler (gen_info); - } else - Console.WriteLine ("of interface " + QualifiedName); + sig.GenerateDecl (sw); + sig.GenEventHandler (gen_info); } foreach (Method method in methods.Values) { - if (method.Validate ()) { - if (IgnoreMethod (method)) - continue; - method.GenerateDecl (sw); - } else - Console.WriteLine ("of interface " + QualifiedName); + if (IgnoreMethod (method)) + continue; + method.GenerateDecl (sw); } - foreach (Property prop in props.Values) { - if (prop.Validate ()) - prop.GenerateDecl (sw, "\t\t"); - else - Console.WriteLine ("of interface " + QualifiedName); - } + foreach (Property prop in props.Values) + prop.GenerateDecl (sw, "\t\t"); AppendCustom (sw, gen_info.CustomDir); diff --git a/generator/Method.cs b/generator/Method.cs index a0679ea47..0aa20d111 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -31,7 +31,6 @@ namespace GtkSharp.Generation { private ReturnValue retval; - private bool initialized = false; private string call; private string name; private string protection = "public"; @@ -90,31 +89,19 @@ namespace GtkSharp.Generation { } } - private bool Initialize () + public override bool Validate () { - if (initialized) - return true; + if (!retval.Validate () || !base.Validate ()) { + Console.Write(" in method " + Name + " "); + return false; + } Parameters parms = Parameters; is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && Name.Length > 3 && (Name.StartsWith ("Get") || Name.StartsWith ("Is") || Name.StartsWith ("Has"))); is_set = ((parms.IsAccessor || (parms.VisibleCount == 1 && retval.IsVoid)) && (Name.Length > 3 && Name.Substring(0, 3) == "Set")); - + call = "(" + (IsStatic ? "" : container_type.CallByName () + (parms.Count > 0 ? ", " : "")) + Body.GetCallString (is_set) + ")"; - initialized = true; - return true; - } - - public override bool Validate () - { - if (!base.Validate () || !Initialize ()) - return false; - - if (!retval.Validate ()) { - Console.Write(" in method " + Name + " "); - return false; - } - return true; } @@ -150,7 +137,7 @@ namespace GtkSharp.Generation { sw.Write("override "); else if (Name == "GetGType" && container_type is ObjectGen) sw.Write("new "); - else if (Modifiers == "new " || (dup != null && dup.Initialize () && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null)))) + else if (Modifiers == "new " || (dup != null && ((dup.Signature != null && Signature != null && dup.Signature.ToString() == Signature.ToString()) || (dup.Signature == null && Signature == null)))) sw.Write("new "); if (is_get || is_set) { @@ -173,16 +160,13 @@ namespace GtkSharp.Generation { public void GenerateDecl (StreamWriter sw) { - if (!Initialize ()) - return; - if (IsStatic) return; if (is_get || is_set) { Method comp = GetComplement (); - if (comp != null && comp.Validate () && is_set) + if (comp != null && is_set) return; sw.Write("\t\t"); @@ -225,9 +209,6 @@ namespace GtkSharp.Generation { { Method comp = null; - if (!Initialize ()) - return; - gen_info.CurrentMember = Name; if (implementor != null && IsStatic) return; @@ -238,13 +219,14 @@ namespace GtkSharp.Generation { if (Modifiers != "new " && container_type.GetPropertyRecursively (Name.Substring (3)) != null) return; comp = GetComplement (); - if (comp != null && comp.Validate () && is_set && Parameters.AccessorReturnType == comp.ReturnType) - return; - if (comp != null && is_set && Parameters.AccessorReturnType != comp.ReturnType) - { - is_set = false; - call = "(Handle, " + Body.GetCallString (false) + ")"; - comp = null; + if (comp != null && is_set) { + if (Parameters.AccessorReturnType == comp.ReturnType) + return; + else { + is_set = false; + call = "(Handle, " + Body.GetCallString (false) + ")"; + comp = null; + } } /* some setters take more than one arg */ if (comp != null && !comp.is_set) diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 8ba5205d2..45e9152c4 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -71,6 +71,22 @@ namespace GtkSharp.Generation { } } + public override bool Validate () + { + ArrayList invalids = new ArrayList (); + + foreach (ChildProperty prop in childprops.Values) { + if (!prop.Validate ()) { + Console.WriteLine ("in Object " + QualifiedName); + invalids.Add (prop); + } + } + foreach (ChildProperty prop in invalids) + childprops.Remove (prop); + + return base.Validate (); + } + private bool DisableVoidCtor { get { return Elem.HasAttribute ("disable_void_ctor"); @@ -274,12 +290,8 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t\tprotected internal " + Name + "Child (Gtk.Container parent, Gtk.Widget child) : base (parent, child) {}"); sw.WriteLine (""); - foreach (ChildProperty prop in childprops.Values) { - if (prop.Validate ()) - prop.Generate (gen_info, "\t\t\t", null); - else - Console.WriteLine("in Object " + QualifiedName); - } + foreach (ChildProperty prop in childprops.Values) + prop.Generate (gen_info, "\t\t\t", null); sw.WriteLine ("\t\t}"); sw.WriteLine (""); diff --git a/generator/PropertyBase.cs b/generator/PropertyBase.cs index 83935be70..d031bd8dc 100644 --- a/generator/PropertyBase.cs +++ b/generator/PropertyBase.cs @@ -86,7 +86,7 @@ namespace GtkSharp.Generation { if (getter == null) { getter = container_type.GetMethod ("Get" + Name); if (getter != null && getter.Name == "Get" + Name && - getter.Validate () && getter.IsGetter) + getter.IsGetter) cstype = getter.ReturnType; else getter = null; @@ -101,7 +101,7 @@ namespace GtkSharp.Generation { if (setter == null) { setter = container_type.GetMethod ("Set" + Name); if (setter != null && setter.Name == "Set" + Name && - setter.Validate () && setter.IsSetter) + setter.IsSetter) cstype = setter.Signature.Types; else setter = null; diff --git a/generator/SimpleBase.cs b/generator/SimpleBase.cs index 1620237a1..b30513778 100644 --- a/generator/SimpleBase.cs +++ b/generator/SimpleBase.cs @@ -96,6 +96,11 @@ namespace GtkSharp.Generation { return CallByName (var); } + public bool Validate () + { + return true; + } + public void Generate () { } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index a3b082d2b..91abd93ee 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -131,7 +131,7 @@ namespace GtkSharp.Generation { } } - public bool Validate () + public override bool Validate () { foreach (StructField field in fields) { if (!field.Validate ()) { @@ -141,7 +141,7 @@ namespace GtkSharp.Generation { } } - return true; + return base.Validate (); } public override void Generate (GenerationInfo gen_info) diff --git a/generator/StructGen.cs b/generator/StructGen.cs index a1eb66f0b..4d615ad15 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -33,9 +33,6 @@ namespace GtkSharp.Generation { { gen_info.CurrentType = Name; - if (!Validate ()) - return; - StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); if (GetMethod ("GetType") == null && GetMethod ("GetGType") == null) { diff --git a/generator/SymbolTable.cs b/generator/SymbolTable.cs index 94444f1c3..227f8e775 100644 --- a/generator/SymbolTable.cs +++ b/generator/SymbolTable.cs @@ -111,7 +111,7 @@ namespace GtkSharp.Generation { AddType (new SimpleGen ("GC", "IntPtr")); AddType (new SimpleGen ("GError", "IntPtr")); AddType (new SimpleGen ("GMemChunk", "IntPtr")); - AddType (new SimpleGen ("GPtrArray", "IntPtr[]")); + AddType (new SimpleGen ("GPtrArray", "IntPtr")); AddType (new SimpleGen ("GTimeVal", "IntPtr")); AddType (new SimpleGen ("GClosure", "IntPtr")); AddType (new SimpleGen ("GArray", "IntPtr"));