Restructure log warnings in validation.

* generator/*.cs: Add a LogWriter class which formats warnings
consistently on the console.  Supports the concept of non-fatal
validation warnings, since it doesn't rely on the unrolling of the
validation stack to associate a warning to a given type.

Main purpose was to add a non-fatal warning for missing element_type
attributes on list return values, though it results in cleaner log
output, and also updates some warning messages to be more helpful in
how to resolve them.
This commit is contained in:
Mike Kestner 2011-02-20 12:11:08 -06:00
parent 0a094c2662
commit 2ba496479f
24 changed files with 105 additions and 122 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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,41 +133,33 @@ 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);
invalids.Clear ();

View file

@ -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;
}
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}
}

View file

@ -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) {

View file

@ -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;
}
}
}

View file

@ -31,6 +31,7 @@ sources = \
IManualMarshaler.cs \
InterfaceGen.cs \
InterfaceVM.cs \
LogWriter.cs \
LPGen.cs \
LPUGen.cs \
ManagedCallString.cs \

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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,11 +295,9 @@ 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);
}
}

View file

@ -77,14 +77,14 @@ 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);

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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,25 +128,21 @@ 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;
}
}
}
}