diff --git a/generator/BoxedGen.cs b/generator/BoxedGen.cs index 5ad6d8749..28656f23f 100644 --- a/generator/BoxedGen.cs +++ b/generator/BoxedGen.cs @@ -36,7 +36,7 @@ namespace GtkSharp.Generation { methods.Remove ("Copy"); methods.Remove ("Free"); - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); diff --git a/generator/CallbackGen.cs b/generator/CallbackGen.cs index b293f5127..40f25c426 100644 --- a/generator/CallbackGen.cs +++ b/generator/CallbackGen.cs @@ -46,22 +46,15 @@ namespace GtkSharp.Generation { public override bool Validate () { - if (!retval.Validate ()) { - Console.WriteLine ("rettype: " + retval.CType + " in callback " + CName); - Statistics.ThrottledCount++; - valid = false; - return false; - } - - if (!parms.Validate ()) { - Console.WriteLine (" in callback " + CName); - Statistics.ThrottledCount++; - valid = false; - return false; - } - valid = true; - return true; + LogWriter log = new LogWriter (); + log.Type = QualifiedName; + if (!retval.Validate (log) || !parms.Validate (log)) { + Statistics.ThrottledCount++; + valid = false; + } + + return valid; } public string InvokerName { @@ -281,7 +274,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; sig = new Signature (parms); diff --git a/generator/ClassBase.cs b/generator/ClassBase.cs index 407f58f44..a3b1d0e4e 100644 --- a/generator/ClassBase.cs +++ b/generator/ClassBase.cs @@ -116,14 +116,16 @@ namespace GtkSharp.Generation { public override bool Validate () { + LogWriter log = new LogWriter (QualifiedName); + foreach (string iface in interfaces) { InterfaceGen igen = SymbolTable.Table[iface] as InterfaceGen; if (igen == null) { - Console.WriteLine (QualifiedName + " implements unknown GInterface " + iface); + log.Warn ("implements unknown GInterface " + iface); return false; } if (!igen.ValidateForSubclass ()) { - Console.WriteLine (QualifiedName + " implements invalid GInterface " + iface); + log.Warn ("implements invalid GInterface " + iface); return false; } } @@ -131,40 +133,32 @@ namespace GtkSharp.Generation { ArrayList invalids = new ArrayList (); foreach (Property prop in props.Values) { - if (!prop.Validate ()) { - Console.WriteLine ("in type " + QualifiedName); + if (!prop.Validate (log)) invalids.Add (prop); - } } foreach (Property prop in invalids) props.Remove (prop.Name); invalids.Clear (); foreach (ObjectField field in fields.Values) { - if (!field.Validate ()) { - Console.WriteLine ("in type " + QualifiedName); + if (!field.Validate (log)) 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); + if (!method.Validate (log)) 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); + if (!ctor.Validate (log)) invalids.Add (ctor); - } } foreach (Ctor ctor in invalids) ctors.Remove (ctor); diff --git a/generator/ClassField.cs b/generator/ClassField.cs index e5276d42b..c67006cb5 100644 --- a/generator/ClassField.cs +++ b/generator/ClassField.cs @@ -31,13 +31,17 @@ namespace GtkSharp.Generation { this.container_type = container_type; } - public override bool Validate () { + public override bool Validate (LogWriter log) + { + if (!base.Validate (log)) + return false; + if (IsBitfield) { - Console.WriteLine ("Field {0}.{1} is a bitfield which is not supported yet", container_type.ClassStructName, Name); + log.Warn ("bitfields are not supported"); return false; } - return base.Validate (); + return true; } } } diff --git a/generator/ClassGen.cs b/generator/ClassGen.cs index d36c77db3..299393cf0 100644 --- a/generator/ClassGen.cs +++ b/generator/ClassGen.cs @@ -60,7 +60,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream(Name); diff --git a/generator/Ctor.cs b/generator/Ctor.cs index 8b06d2089..53d583607 100644 --- a/generator/Ctor.cs +++ b/generator/Ctor.cs @@ -92,9 +92,6 @@ namespace GtkSharp.Generation { public void Generate (GenerationInfo gen_info) { - if (!Validate ()) - return; - StreamWriter sw = gen_info.Writer; gen_info.CurrentMember = CName; diff --git a/generator/FieldBase.cs b/generator/FieldBase.cs index 91a764464..6a9b78294 100644 --- a/generator/FieldBase.cs +++ b/generator/FieldBase.cs @@ -28,10 +28,11 @@ namespace GtkSharp.Generation { public abstract class FieldBase : PropertyBase { public FieldBase (XmlElement elem, ClassBase container_type) : base (elem, container_type) {} - public virtual bool Validate () + public virtual bool Validate (LogWriter log) { + log.Member = Name; if (!Ignored && !Hidden && CSType == "") { - Console.Write("Field {0} has unknown Type {1} ", Name, CType); + log.Warn ("field has unknown type: " + CType); Statistics.ThrottledCount++; return false; } @@ -141,10 +142,10 @@ namespace GtkSharp.Generation { return; CheckGlue (); - if ((getterName != null || setterName != null || getOffsetName != null) && - gen_info.GlueWriter == null) { - Console.WriteLine ("No glue-filename specified, can't create glue for {0}.{1}", - container_type.Name, Name); + if ((getterName != null || setterName != null || getOffsetName != null) && gen_info.GlueWriter == null) { + LogWriter log = new LogWriter (container_type.QualifiedName); + log.Member = Name; + log.Warn ("needs glue for field access. Specify --glue-filename"); return; } diff --git a/generator/GObjectVM.cs b/generator/GObjectVM.cs index 6e03c8d27..a5e4555fd 100644 --- a/generator/GObjectVM.cs +++ b/generator/GObjectVM.cs @@ -342,26 +342,26 @@ namespace GtkSharp.Generation { sw.WriteLine (); } - public override bool Validate () + public override bool Validate (LogWriter log) { - if (!base.Validate ()) return false; + if (!base.Validate (log)) + return false; + bool is_valid = true; if (this.IsStatic) { switch (OverrideType) { case VMOverrideType.Unspecified: - Console.Write ("Static virtual methods can only be generated if you provide info on how to override this method via the metadata "); + log.Warn ("Static virtual methods can only be generated if you provide info on how to override this method via the metadata "); is_valid = false; break; case VMOverrideType.ImplementingClass: - Console.Write ("Overriding static virtual methods in the implementing class is not supported yet "); + log.Warn ("Overriding static virtual methods in the implementing class is not supported yet "); is_valid = false; break; } } - if (!is_valid) - Console.WriteLine (" (in virtual method {0}.{1})", container_type.QualifiedName, this.Name); return is_valid; } } diff --git a/generator/InterfaceGen.cs b/generator/InterfaceGen.cs index 7330464dc..e237d559b 100644 --- a/generator/InterfaceGen.cs +++ b/generator/InterfaceGen.cs @@ -46,7 +46,7 @@ namespace GtkSharp.Generation { break; default: if (!base.IsNodeNameHandled (node.Name)) - Console.WriteLine ("Unexpected node " + node.Name + " in " + CName); + new LogWriter (QualifiedName).Warn ("Unexpected node " + node.Name); break; } } @@ -70,19 +70,20 @@ namespace GtkSharp.Generation { public override bool ValidateForSubclass () { - ArrayList invalids = new ArrayList (); + if (!base.ValidateForSubclass ()) + return false; + LogWriter log = new LogWriter (QualifiedName); + ArrayList invalids = new ArrayList (); foreach (Method method in methods.Values) { - if (!method.Validate ()) { - Console.WriteLine ("in type " + QualifiedName); + if (!method.Validate (log)) invalids.Add (method); - } } foreach (Method method in invalids) methods.Remove (method.Name); invalids.Clear (); - return base.ValidateForSubclass (); + return true; } void GenerateStaticCtor (StreamWriter sw) @@ -93,7 +94,7 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t{"); sw.WriteLine ("\t\t\tGLib.GType.Register (_gtype, typeof({0}Adapter));", Name); foreach (InterfaceVM vm in interface_vms) { - if (vm.IsValid) + if (vm.Validate (new LogWriter (QualifiedName))) sw.WriteLine ("\t\t\tiface.{0} = new {0}NativeDelegate ({0}_cb);", vm.Name); } sw.WriteLine ("\t\t}"); @@ -288,7 +289,7 @@ namespace GtkSharp.Generation { foreach (InterfaceVM vm in interface_vms) { if (vm_table [vm.Name] == null) continue; - else if (!vm.IsValid) { + else if (!vm.Validate (new LogWriter (QualifiedName))) { vm_table.Remove (vm.Name); continue; } else if (vm.IsGetter || vm.IsSetter) { diff --git a/generator/InterfaceVM.cs b/generator/InterfaceVM.cs index cfa9b1476..39308c09a 100644 --- a/generator/InterfaceVM.cs +++ b/generator/InterfaceVM.cs @@ -85,13 +85,17 @@ namespace GtkSharp.Generation { sw.WriteLine ("\t\t" + retval.CSType + " " + Name + " (" + Signature + ");"); } - public override bool Validate () + public override bool Validate (LogWriter log) { + if (!base.Validate (log)) + return false; + if (target == null && !(container_type as InterfaceGen).IsConsumeOnly) { - Console.WriteLine ("Virtual method {0}->{1} has no matching target to invoke", container_type.CName, CName); + log.Warn ("No matching target method to invoke. Add target_method attribute with fixup."); return false; } - return base.Validate (); + + return true; } } } diff --git a/generator/Makefile.am b/generator/Makefile.am index b4581376f..d6b10db4b 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -31,6 +31,7 @@ sources = \ IManualMarshaler.cs \ InterfaceGen.cs \ InterfaceVM.cs \ + LogWriter.cs \ LPGen.cs \ LPUGen.cs \ ManagedCallString.cs \ diff --git a/generator/Method.cs b/generator/Method.cs index 25803af72..c2444bb0f 100644 --- a/generator/Method.cs +++ b/generator/Method.cs @@ -82,12 +82,11 @@ namespace GtkSharp.Generation { } } - public override bool Validate () + public override bool Validate (LogWriter log) { - if (!retval.Validate () || !base.Validate ()) { - Console.Write(" in method " + Name + " "); + log.Member = Name; + if (!retval.Validate (log) || !base.Validate (log)) return false; - } Parameters parms = Parameters; is_get = ((((parms.IsAccessor && retval.IsVoid) || (parms.Count == 0 && !retval.IsVoid)) || (parms.Count == 0 && !retval.IsVoid)) && HasGetterName); @@ -214,9 +213,6 @@ namespace GtkSharp.Generation { public void Generate (GenerationInfo gen_info, ClassBase implementor) { - if (!Validate ()) - return; - Method comp = null; gen_info.CurrentMember = Name; diff --git a/generator/MethodBase.cs b/generator/MethodBase.cs index 2faaef156..ce6aa726c 100644 --- a/generator/MethodBase.cs +++ b/generator/MethodBase.cs @@ -168,10 +168,10 @@ namespace GtkSharp.Generation { } } - public virtual bool Validate () + public virtual bool Validate (LogWriter log) { - if (!parms.Validate ()) { - Console.Write("in " + CName + " "); + log.Member = Name; + if (!parms.Validate (log)) { Statistics.ThrottledCount++; return false; } diff --git a/generator/MethodBody.cs b/generator/MethodBody.cs index cee70790f..31ed62d5f 100644 --- a/generator/MethodBody.cs +++ b/generator/MethodBody.cs @@ -122,7 +122,7 @@ namespace GtkSharp.Generation { case "call": default: if (p.Scope == String.Empty) - Console.WriteLine ("Defaulting " + gen.Name + " param to 'call' scope in method " + gen_info.CurrentMember); + Console.WriteLine (gen_info.CurrentMember + " - defaulting " + gen.Name + " param to 'call' scope. Specify callback scope (call|async|notified) attribute with fixup."); sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name); break; } diff --git a/generator/ObjectBase.cs b/generator/ObjectBase.cs index 16ee88e56..31a86db27 100644 --- a/generator/ObjectBase.cs +++ b/generator/ObjectBase.cs @@ -261,13 +261,16 @@ namespace GtkSharp.Generation { public override bool Validate () { + if (Parent != null && !(Parent as ObjectBase).ValidateForSubclass ()) return false; + LogWriter log = new LogWriter (QualifiedName); + ArrayList invalids = new ArrayList (); foreach (GObjectVM vm in virtual_methods) - if (!vm.Validate ()) + if (!vm.Validate (log)) invalids.Add (vm); foreach (VirtualMethod invalid_vm in invalids) { @@ -278,11 +281,11 @@ namespace GtkSharp.Generation { class_fields_valid = true; foreach (ClassField field in class_fields) - if (!field.Validate ()) + if (!field.Validate (log)) class_fields_valid = false; foreach (InterfaceVM vm in interface_vms) - if (!vm.Validate ()) + if (!vm.Validate (log)) invalids.Add (vm); foreach (InterfaceVM invalid_vm in invalids) { @@ -292,10 +295,8 @@ namespace GtkSharp.Generation { invalids.Clear (); foreach (Signal sig in sigs.Values) { - if (!sig.Validate ()) { - Console.WriteLine ("in type " + QualifiedName); + if (!sig.Validate (log)) invalids.Add (sig); - } } foreach (Signal sig in invalids) sigs.Remove (sig.Name); @@ -305,11 +306,11 @@ namespace GtkSharp.Generation { public virtual bool ValidateForSubclass () { + LogWriter log = new LogWriter (QualifiedName); ArrayList invalids = new ArrayList (); foreach (Signal sig in sigs.Values) { - if (!sig.Validate ()) { - Console.WriteLine ("in type " + QualifiedName); + if (!sig.Validate (log)) { invalids.Add (sig); } } diff --git a/generator/ObjectGen.cs b/generator/ObjectGen.cs index 7a06a8574..8fe27b6f3 100644 --- a/generator/ObjectGen.cs +++ b/generator/ObjectGen.cs @@ -77,13 +77,13 @@ namespace GtkSharp.Generation { public override bool Validate () { + LogWriter log = new LogWriter (QualifiedName); + ArrayList invalids = new ArrayList (); foreach (ChildProperty prop in childprops.Values) { - if (!prop.Validate ()) { - Console.WriteLine ("in Object " + QualifiedName); + if (!prop.Validate (log)) invalids.Add (prop); - } } foreach (ChildProperty prop in invalids) childprops.Remove (prop); @@ -129,7 +129,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; string asm_name = gen_info.AssemblyName.Length == 0 ? NS.ToLower () + "-sharp" : gen_info.AssemblyName; DirectoryInfo di = GetDirectoryInfo (gen_info.Dir, asm_name); diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index a46008822..eb56c945c 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -43,7 +43,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 40ae25543..7af599d50 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -622,7 +622,7 @@ namespace GtkSharp.Generation { bool valid = false; - public bool Validate () + public bool Validate (LogWriter log) { if (valid) return true; @@ -637,14 +637,14 @@ namespace GtkSharp.Generation { Parameter p = new Parameter (parm); if (p.IsEllipsis) { - Console.Write("Ellipsis parameter "); + log.Warn ("Ellipsis parameter: hide and bind manually if no alternative exists. "); Clear (); return false; } if ((p.CSType == "") || (p.Name == "") || (p.MarshalType == "") || (SymbolTable.Table.CallByName(p.CType, p.Name) == "")) { - Console.Write ("Invalid parameter {0} of type {1}", p.Name, p.CType); + log.Warn ("Unknown type {1} on parameter {0}", p.Name, p.CType); Clear (); return false; } diff --git a/generator/Property.cs b/generator/Property.cs index fbf940b81..91dd066e4 100644 --- a/generator/Property.cs +++ b/generator/Property.cs @@ -31,10 +31,11 @@ namespace GtkSharp.Generation { public Property (XmlElement elem, ClassBase container_type) : base (elem, container_type) {} - public bool Validate () + public bool Validate (LogWriter log) { if (CSType == "" && !Hidden) { - Console.Write("Property has unknown Type {0} ", CType); + log.Member = Name; + log.Warn ("property has unknown type '{0}' ", CType); Statistics.ThrottledCount++; return false; } diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index 927f4be00..e30171e36 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -158,12 +158,13 @@ namespace GtkSharp.Generation { return IGen.CallByName (var); } - public bool Validate () + public bool Validate (LogWriter log) { if (MarshalType == "" || CSType == "") { - Console.Write("rettype: " + CType); + log.Warn ("Unknown return type: {0}", CType); return false; - } + } else if ((CSType == "GLib.List" || CSType == "GLib.SList") && String.IsNullOrEmpty (ElementType)) + log.Warn ("Returns {0} with unknown element type. Add element_type attribute with gapi-fixup.", CType); return true; } diff --git a/generator/Signal.cs b/generator/Signal.cs index fa499bcfa..5cccd30b1 100644 --- a/generator/Signal.cs +++ b/generator/Signal.cs @@ -60,20 +60,17 @@ namespace GtkSharp.Generation { } } - public bool Validate () + public bool Validate (LogWriter log) { + log.Member = Name; if (Name == "") { - Console.Write ("Nameless signal "); + log.Warn ("Nameless signal found. Add name attribute with fixup."); + Statistics.ThrottledCount++; + return false; + } else if (!parms.Validate (log) || !retval.Validate (log)) { Statistics.ThrottledCount++; return false; } - - if (!parms.Validate () || !retval.Validate ()) { - Console.Write (" in signal " + Name + " "); - Statistics.ThrottledCount++; - return false; - } - return true; } diff --git a/generator/StructBase.cs b/generator/StructBase.cs index 6c7cd0454..217c8ca03 100644 --- a/generator/StructBase.cs +++ b/generator/StructBase.cs @@ -127,9 +127,9 @@ namespace GtkSharp.Generation { public override bool Validate () { + LogWriter log = new LogWriter (QualifiedName); foreach (StructField field in fields) { - if (!field.Validate ()) { - Console.WriteLine ("in Struct " + QualifiedName); + if (!field.Validate (log)) { if (!field.IsPointer) return false; } diff --git a/generator/StructGen.cs b/generator/StructGen.cs index 4d615ad15..be38c14fb 100644 --- a/generator/StructGen.cs +++ b/generator/StructGen.cs @@ -31,7 +31,7 @@ namespace GtkSharp.Generation { public override void Generate (GenerationInfo gen_info) { - gen_info.CurrentType = Name; + gen_info.CurrentType = QualifiedName; StreamWriter sw = gen_info.Writer = gen_info.OpenStream (Name); base.Generate (gen_info); diff --git a/generator/VirtualMethod.cs b/generator/VirtualMethod.cs index 275662028..cb4410dd3 100644 --- a/generator/VirtualMethod.cs +++ b/generator/VirtualMethod.cs @@ -61,7 +61,9 @@ namespace GtkSharp.Generation { */ public void GenerateCallback (StreamWriter sw, ClassBase implementor) { - if (!Validate ()) + LogWriter log = new LogWriter (); + log.Type = container_type.QualifiedName; + if (!Validate (log)) return; string native_signature = ""; @@ -118,12 +120,6 @@ namespace GtkSharp.Generation { sw.WriteLine (); } - public bool IsValid { - get { - return Validate (); - } - } - enum ValidState { Unvalidated, Invalid, @@ -132,24 +128,20 @@ namespace GtkSharp.Generation { ValidState vstate = ValidState.Unvalidated; - public override bool Validate () + public override bool Validate (LogWriter log) { if (vstate != ValidState.Unvalidated) return vstate == ValidState.Valid; vstate = ValidState.Valid; - if (!parms.Validate () || !retval.Validate ()) { + log.Member = Name; + if (!parms.Validate (log) || !retval.Validate (log)) { vstate = ValidState.Invalid; + return false; } - if (vstate == ValidState.Invalid) { - Console.WriteLine ("(in virtual method " + container_type.QualifiedName + "." + Name + ")"); - return false; - } else { - // The call string has to be created *after* the params have been validated since the Parameters class contains no elements before validation - call = new ManagedCallString (parms); - return true; - } + call = new ManagedCallString (parms); + return true; } } }