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 ()
|
public override bool Validate ()
|
||||||
{
|
{
|
||||||
valid = true;
|
valid = true;
|
||||||
LogWriter log = new LogWriter ();
|
LogWriter log = new LogWriter (QualifiedName);
|
||||||
log.Type = QualifiedName;
|
log.Type = QualifiedName;
|
||||||
if (!retval.Validate (log) || !parms.Validate (log)) {
|
if (!retval.Validate (log) || !parms.Validate (log)) {
|
||||||
Statistics.ThrottledCount++;
|
Statistics.ThrottledCount++;
|
||||||
|
@ -196,7 +196,8 @@ namespace GtkSharp.Generation {
|
||||||
if (!Validate ())
|
if (!Validate ())
|
||||||
return String.Empty;
|
return String.Empty;
|
||||||
|
|
||||||
body = new MethodBody (parms);
|
LogWriter log = new LogWriter (qualname);
|
||||||
|
body = new MethodBody (parms, log);
|
||||||
|
|
||||||
StreamWriter save_sw = gen_info.Writer;
|
StreamWriter save_sw = gen_info.Writer;
|
||||||
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);
|
StreamWriter sw = gen_info.Writer = gen_info.OpenStream (qualname, NS);
|
||||||
|
|
|
@ -143,15 +143,14 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual bool CanGenerateABIStruct {
|
protected virtual bool CanGenerateABIStruct(LogWriter log) {
|
||||||
get {
|
return (abi_fields_valid);
|
||||||
return (abi_fields_valid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CheckABIStructParent(LogWriter log, out string cs_parent_struct) {
|
bool CheckABIStructParent(LogWriter log, out string cs_parent_struct) {
|
||||||
cs_parent_struct = null;
|
cs_parent_struct = null;
|
||||||
if (!CanGenerateABIStruct)
|
|
||||||
|
if (!CanGenerateABIStruct(log))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var parent = SymbolTable.Table[Elem.GetAttribute("parent")];
|
var parent = SymbolTable.Table[Elem.GetAttribute("parent")];
|
||||||
|
|
|
@ -29,6 +29,8 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public class CodeGenerator {
|
public class CodeGenerator {
|
||||||
|
|
||||||
|
static LogWriter log = new LogWriter ("CodeGenerator");
|
||||||
|
|
||||||
public static int Main (string[] args)
|
public static int Main (string[] args)
|
||||||
{
|
{
|
||||||
bool show_help = false;
|
bool show_help = false;
|
||||||
|
@ -104,11 +106,13 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
Parser p = new Parser ();
|
Parser p = new Parser ();
|
||||||
foreach (string include in includes) {
|
foreach (string include in includes) {
|
||||||
|
log.Info("Parsing included gapi: " + include);
|
||||||
IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
|
IGeneratable[] curr_gens = p.Parse (include, schema_name, gapidir);
|
||||||
table.AddTypes (curr_gens);
|
table.AddTypes (curr_gens);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string filename in filenames) {
|
foreach (string filename in filenames) {
|
||||||
|
log.Info("Parsing included gapi: " + filename);
|
||||||
IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
|
IGeneratable[] curr_gens = p.Parse (filename, schema_name, gapidir);
|
||||||
table.AddTypes (curr_gens);
|
table.AddTypes (curr_gens);
|
||||||
gens.AddRange (curr_gens);
|
gens.AddRange (curr_gens);
|
||||||
|
|
|
@ -28,10 +28,18 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
string type;
|
string type;
|
||||||
string member;
|
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;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +61,14 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public void Warn (string warning)
|
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;
|
MethodBody body;
|
||||||
public MethodBody Body {
|
public MethodBody Body {
|
||||||
get {
|
get {
|
||||||
if (body == null)
|
if (body == null) {
|
||||||
body = new MethodBody (parms);
|
LogWriter log = new LogWriter (Name);
|
||||||
|
body = new MethodBody (parms, log);
|
||||||
|
}
|
||||||
return body;
|
return body;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,12 @@ namespace GtkSharp.Generation {
|
||||||
public class MethodBody {
|
public class MethodBody {
|
||||||
|
|
||||||
Parameters parameters;
|
Parameters parameters;
|
||||||
|
LogWriter log;
|
||||||
|
|
||||||
public MethodBody (Parameters parms)
|
public MethodBody (Parameters parms, LogWriter _log)
|
||||||
{
|
{
|
||||||
parameters = parms;
|
parameters = parms;
|
||||||
|
log = _log;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string CastFromInt (string type)
|
private string CastFromInt (string type)
|
||||||
|
@ -131,7 +133,7 @@ namespace GtkSharp.Generation {
|
||||||
case "call":
|
case "call":
|
||||||
default:
|
default:
|
||||||
if (p.Scope == String.Empty)
|
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);
|
sw.WriteLine (indent + "\t\t\t{0} {1}_wrapper = new {0} ({1});", wrapper, name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,8 @@ namespace GtkSharp.Generation
|
||||||
|
|
||||||
public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
public NativeStructGen (XmlElement ns, XmlElement elem) : base (ns, elem)
|
||||||
{
|
{
|
||||||
|
LogWriter log = new LogWriter (QualifiedName);
|
||||||
|
|
||||||
foreach (XmlNode node in elem.ChildNodes) {
|
foreach (XmlNode node in elem.ChildNodes) {
|
||||||
|
|
||||||
if (!(node is XmlElement)) continue;
|
if (!(node is XmlElement)) continue;
|
||||||
|
@ -44,7 +46,7 @@ namespace GtkSharp.Generation
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (!IsNodeNameHandled (node.Name))
|
if (!IsNodeNameHandled (node.Name))
|
||||||
Console.WriteLine ("Unexpected node " + node.Name + " in " + CName);
|
log.Warn ("Unexpected node " + node.Name + " in " + CName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,19 +187,20 @@ namespace GtkSharp.Generation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool CanGenerateABIStruct {
|
protected override bool CanGenerateABIStruct(LogWriter log) {
|
||||||
get {
|
if (!abi_fields_valid) {
|
||||||
if (!abi_fields_valid) {
|
log.Info(CName + " has invalid fields");
|
||||||
Console.WriteLine("invalid fields");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// No instance structure for interfaces
|
return false;
|
||||||
if (is_interface)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return class_struct_name != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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)
|
protected void GenerateClassStruct (GenerationInfo gen_info)
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace GtkSharp.Generation {
|
||||||
string cstype = SymbolTable.Table.GetCSType(CType, true);
|
string cstype = SymbolTable.Table.GetCSType(CType, true);
|
||||||
|
|
||||||
if (cstype == null || cstype == "") {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,8 +50,10 @@ namespace GtkSharp.Generation {
|
||||||
try {
|
try {
|
||||||
result = Int32.Parse (elem.GetAttribute("array_len"));
|
result = Int32.Parse (elem.GetAttribute("array_len"));
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
Console.Write ("Non-numeric array_len: " + elem.GetAttribute("array_len"));
|
LogWriter log = new LogWriter (container_type.Name + "." + Name);
|
||||||
Console.WriteLine (" warning: array field {0} incorrectly generated", Name);
|
|
||||||
|
log.Warn("Non-numeric array_len: \"" + elem.GetAttribute("array_len") +
|
||||||
|
"\" incorrectly generated");
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -28,6 +28,7 @@ namespace GtkSharp.Generation {
|
||||||
public class SymbolTable {
|
public class SymbolTable {
|
||||||
|
|
||||||
static SymbolTable table = null;
|
static SymbolTable table = null;
|
||||||
|
static LogWriter log = new LogWriter ("SymbolTable");
|
||||||
|
|
||||||
IDictionary<string, IGeneratable> types = new Dictionary<string, IGeneratable> ();
|
IDictionary<string, IGeneratable> types = new Dictionary<string, IGeneratable> ();
|
||||||
|
|
||||||
|
@ -163,13 +164,14 @@ namespace GtkSharp.Generation {
|
||||||
|
|
||||||
public void AddType (IGeneratable gen)
|
public void AddType (IGeneratable gen)
|
||||||
{
|
{
|
||||||
|
log.Info("Adding " + gen.CName + " = " + gen);
|
||||||
types [gen.CName] = gen;
|
types [gen.CName] = gen;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTypes (IGeneratable[] gens)
|
public void AddTypes (IGeneratable[] gens)
|
||||||
{
|
{
|
||||||
foreach (IGeneratable gen in gens)
|
foreach (IGeneratable gen in gens)
|
||||||
types [gen.CName] = gen;
|
AddType(gen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Count {
|
public int Count {
|
||||||
|
|
Loading…
Reference in a new issue