generator: Enhance logging avoiding the use of simple prints
And adding a LogWriter.Info method enabled with the GENERATOR_DEBUG environment variable.
This commit is contained in:
parent
89aeba8b13
commit
2d71de1360
11 changed files with 60 additions and 30 deletions
|
@ -47,7 +47,7 @@ namespace GtkSharp.Generation {
|
|||
public override bool Validate ()
|
||||
{
|
||||
valid = true;
|
||||
LogWriter log = new LogWriter ();
|
||||
LogWriter log = new LogWriter (QualifiedName);
|
||||
log.Type = QualifiedName;
|
||||
if (!retval.Validate (log) || !parms.Validate (log)) {
|
||||
Statistics.ThrottledCount++;
|
||||
|
@ -196,7 +196,8 @@ namespace GtkSharp.Generation {
|
|||
if (!Validate ())
|
||||
return String.Empty;
|
||||
|
||||
body = new MethodBody (parms);
|
||||
LogWriter log = new LogWriter (qualname);
|
||||
body = new MethodBody (parms, log);
|
||||
|
||||
StreamWriter save_sw = gen_info.Writer;
|
||||
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);
|
||||
|
|
|
@ -143,15 +143,14 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
protected virtual bool CanGenerateABIStruct {
|
||||
get {
|
||||
return (abi_fields_valid);
|
||||
}
|
||||
protected virtual bool CanGenerateABIStruct(LogWriter log) {
|
||||
return (abi_fields_valid);
|
||||
}
|
||||
|
||||
bool CheckABIStructParent(LogWriter log, out string cs_parent_struct) {
|
||||
cs_parent_struct = null;
|
||||
if (!CanGenerateABIStruct)
|
||||
|
||||
if (!CanGenerateABIStruct(log))
|
||||
return false;
|
||||
|
||||
var parent = SymbolTable.Table[Elem.GetAttribute("parent")];
|
||||
|
|
|
@ -29,6 +29,8 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public class CodeGenerator {
|
||||
|
||||
static LogWriter log = new LogWriter ("CodeGenerator");
|
||||
|
||||
public static int Main (string[] args)
|
||||
{
|
||||
bool show_help = false;
|
||||
|
@ -104,11 +106,13 @@ namespace GtkSharp.Generation {
|
|||
|
||||
Parser p = new Parser ();
|
||||
foreach (string include in includes) {
|
||||
log.Info("Parsing included gapi: " + include);
|
||||
IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
|
||||
table.AddTypes (curr_gens);
|
||||
}
|
||||
|
||||
foreach (string filename in filenames) {
|
||||
log.Info("Parsing included gapi: " + filename);
|
||||
IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
|
||||
table.AddTypes (curr_gens);
|
||||
gens.AddRange (curr_gens);
|
||||
|
|
|
@ -28,10 +28,18 @@ namespace GtkSharp.Generation {
|
|||
|
||||
string type;
|
||||
string member;
|
||||
int level;
|
||||
|
||||
public LogWriter () {}
|
||||
public LogWriter () {
|
||||
var l = Environment.GetEnvironmentVariable("CODEGEN_DEBUG");
|
||||
|
||||
public LogWriter (string type)
|
||||
level = 1;
|
||||
if (l != null) {
|
||||
level = Int32.Parse(l);
|
||||
}
|
||||
}
|
||||
|
||||
public LogWriter (string type): this()
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
@ -53,7 +61,14 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public void Warn (string warning)
|
||||
{
|
||||
Console.WriteLine ("{0}{1} - {2}", Type, String.IsNullOrEmpty (Member) ? String.Empty : "." + Member, warning);
|
||||
if (level > 0)
|
||||
Console.WriteLine ("WARN: {0}{1} - {2}", Type, String.IsNullOrEmpty (Member) ? String.Empty : "." + Member, warning);
|
||||
}
|
||||
|
||||
public void Info (string info)
|
||||
{
|
||||
if (level > 1)
|
||||
Console.WriteLine ("INFO: {0}{1} - {2}", Type, String.IsNullOrEmpty (Member) ? String.Empty : "." + Member, info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,8 +70,10 @@ namespace GtkSharp.Generation {
|
|||
MethodBody body;
|
||||
public MethodBody Body {
|
||||
get {
|
||||
if (body == null)
|
||||
body = new MethodBody (parms);
|
||||
if (body == null) {
|
||||
LogWriter log = new LogWriter (Name);
|
||||
body = new MethodBody (parms, log);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,12 @@ namespace GtkSharp.Generation {
|
|||
public class MethodBody {
|
||||
|
||||
Parameters parameters;
|
||||
LogWriter log;
|
||||
|
||||
public MethodBody (Parameters parms)
|
||||
public MethodBody (Parameters parms, LogWriter _log)
|
||||
{
|
||||
parameters = parms;
|
||||
log = _log;
|
||||
}
|
||||
|
||||
private string CastFromInt (string type)
|
||||
|
@ -131,7 +133,7 @@ namespace GtkSharp.Generation {
|
|||
case "call":
|
||||
default:
|
||||
if (p.Scope == String.Empty)
|
||||
Console.WriteLine (gen_info.CurrentMember + " - defaulting " + gen.Name + " param to 'call' scope. Specify callback scope (call|async|notified) attribute with fixup.");
|
||||
log.Warn (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;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ namespace GtkSharp.Generation
|
|||
|
||||
public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||
{
|
||||
LogWriter log = new LogWriter (QualifiedName);
|
||||
|
||||
foreach (XmlNode node in elem.ChildNodes) {
|
||||
|
||||
if (!(node is XmlElement)) continue;
|
||||
|
@ -44,7 +46,7 @@ namespace GtkSharp.Generation
|
|||
|
||||
default:
|
||||
if (!IsNodeNameHandled (node.Name))
|
||||
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
||||
log.Warn ("Unexpected node " + node.Name + " in " + CName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,19 +187,20 @@ namespace GtkSharp.Generation {
|
|||
}
|
||||
}
|
||||
|
||||
protected override bool CanGenerateABIStruct {
|
||||
get {
|
||||
if (!abi_fields_valid) {
|
||||
Console.WriteLine("invalid fields");
|
||||
return false;
|
||||
}
|
||||
protected override bool CanGenerateABIStruct(LogWriter log) {
|
||||
if (!abi_fields_valid) {
|
||||
log.Info(CName + " has invalid fields");
|
||||
|
||||
// No instance structure for interfaces
|
||||
if (is_interface)
|
||||
return false;
|
||||
|
||||
return class_struct_name != null;
|
||||
return false;
|
||||
}
|
||||
|
||||
// No instance structure for interfaces
|
||||
if (is_interface) {
|
||||
log.Info(CName + " Is interface");
|
||||
return false;
|
||||
}
|
||||
|
||||
return class_struct_name != null;
|
||||
}
|
||||
|
||||
protected void GenerateClassStruct (GenerationInfo gen_info)
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace GtkSharp.Generation {
|
|||
string cstype = SymbolTable.Table.GetCSType(CType, true);
|
||||
|
||||
if (cstype == null || cstype == "") {
|
||||
Console.WriteLine("(" + container_type.CName + ") VOOM " + CName + " " + CType + "=> " + cstype);
|
||||
log.Warn (" field \"" + CName + "\" has no cstype, can't generate ABI field.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -50,8 +50,10 @@ namespace GtkSharp.Generation {
|
|||
try {
|
||||
result = Int32.Parse (elem.GetAttribute("array_len"));
|
||||
} catch (Exception) {
|
||||
Console.Write ("Non-numeric array_len: " + elem.GetAttribute("array_len"));
|
||||
Console.WriteLine (" warning: array field {0} incorrectly generated", Name);
|
||||
LogWriter log = new LogWriter (container_type.Name + "." + Name);
|
||||
|
||||
log.Warn("Non-numeric array_len: \"" + elem.GetAttribute("array_len") +
|
||||
"\" incorrectly generated");
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace GtkSharp.Generation {
|
|||
public class SymbolTable {
|
||||
|
||||
static SymbolTable table = null;
|
||||
static LogWriter log = new LogWriter ("SymbolTable");
|
||||
|
||||
IDictionary<string, IGeneratable> types = new Dictionary<string, IGeneratable> ();
|
||||
|
||||
|
@ -163,13 +164,14 @@ namespace GtkSharp.Generation {
|
|||
|
||||
public void AddType (IGeneratable gen)
|
||||
{
|
||||
log.Info("Adding " + gen.CName + " = " + gen);
|
||||
types [gen.CName] = gen;
|
||||
}
|
||||
|
||||
public void AddTypes (IGeneratable[] gens)
|
||||
{
|
||||
foreach (IGeneratable gen in gens)
|
||||
types [gen.CName] = gen;
|
||||
AddType(gen);
|
||||
}
|
||||
|
||||
public int Count {
|
||||
|
|
Loading…
Reference in a new issue