diff --git a/src/Core/Diagnostics.cs b/src/Core/Diagnostics.cs index 8b556375..1eb83488 100644 --- a/src/Core/Diagnostics.cs +++ b/src/Core/Diagnostics.cs @@ -138,8 +138,13 @@ namespace CppSharp public class TextDiagnosticPrinter : IDiagnosticConsumer { + public bool Verbose; + public void Emit(DiagnosticInfo info) { + if (info.Kind == DiagnosticKind.Debug && !Verbose) + return; + Console.WriteLine(info.Message); System.Diagnostics.Debug.WriteLine(info.Message); } diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 5e78bfc9..807f1b25 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -324,10 +324,14 @@ namespace CppSharp public static void Run(ILibrary library) { var options = new DriverOptions(); - var driver = new Driver(options, new TextDiagnosticPrinter()); + + var Log = new TextDiagnosticPrinter(); + var driver = new Driver(options, Log); + library.Setup(driver); driver.Setup(); - var Log = driver.Diagnostics; + + Log.Verbose = driver.Options.Verbose; if (!options.Quiet) Log.EmitMessage("Parsing libraries..."); diff --git a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs index 90c70a01..3420f6eb 100644 --- a/src/Generator/Generators/CLI/CLIHeadersTemplate.cs +++ b/src/Generator/Generators/CLI/CLIHeadersTemplate.cs @@ -613,7 +613,7 @@ namespace CppSharp.Generators.CLI } else { - Log.EmitMessage("Unhandled typedef type: {0}", typedef); + Log.Debug("Unresolved typedef type: {0}", typedef); } return false; diff --git a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs index 4ab5f56d..398a97e2 100644 --- a/src/Generator/Generators/CSharp/CSharpTextTemplate.cs +++ b/src/Generator/Generators/CSharp/CSharpTextTemplate.cs @@ -2258,7 +2258,7 @@ namespace CppSharp.Generators.CSharp } else { - Log.EmitWarning("Unhandled typedef type: {0}", typedef); + Log.Debug("Unresolved typedef type: {0}", typedef); return false; } diff --git a/src/Generator/Passes/CheckAmbiguousFunctions.cs b/src/Generator/Passes/CheckAmbiguousFunctions.cs index bad22625..0ac1e226 100644 --- a/src/Generator/Passes/CheckAmbiguousFunctions.cs +++ b/src/Generator/Passes/CheckAmbiguousFunctions.cs @@ -53,7 +53,7 @@ namespace CppSharp.Passes } if (function.IsAmbiguous) - Driver.Diagnostics.EmitWarning("Found ambiguous overload: {0}", + Driver.Diagnostics.Debug("Found ambiguous overload: {0}", function.QualifiedOriginalName); return true; diff --git a/src/Generator/Passes/CheckIgnoredDecls.cs b/src/Generator/Passes/CheckIgnoredDecls.cs index 33e1aba2..76979786 100644 --- a/src/Generator/Passes/CheckIgnoredDecls.cs +++ b/src/Generator/Passes/CheckIgnoredDecls.cs @@ -23,7 +23,7 @@ namespace CppSharp.Passes if (decl.IsDependent) { decl.ExplicityIgnored = true; - Log.EmitMessage("Decl '{0}' was ignored due to dependent context", + Log.Debug("Decl '{0}' was ignored due to dependent context", decl.Name); } @@ -43,7 +43,7 @@ namespace CppSharp.Passes field.ExplicityIgnored = true; - Log.EmitMessage("Field '{0}' was ignored due to {1} type", + Log.Debug("Field '{0}' was ignored due to {1} type", field.Name, msg); return true; @@ -60,7 +60,7 @@ namespace CppSharp.Passes if (HasInvalidType(ret.Type, out msg)) { function.ExplicityIgnored = true; - Log.EmitMessage("Function '{0}' was ignored due to {1} return decl", + Log.Debug("Function '{0}' was ignored due to {1} return decl", function.Name, msg); return false; } @@ -70,7 +70,7 @@ namespace CppSharp.Passes if (HasInvalidDecl(param, out msg)) { function.ExplicityIgnored = true; - Log.EmitMessage("Function '{0}' was ignored due to {1} param", + Log.Debug("Function '{0}' was ignored due to {1} param", function.Name, msg); return false; } @@ -78,7 +78,7 @@ namespace CppSharp.Passes if (HasInvalidType(param.Type, out msg)) { function.ExplicityIgnored = true; - Log.EmitMessage("Function '{0}' was ignored due to {1} param", + Log.Debug("Function '{0}' was ignored due to {1} param", function.Name, msg); return false; } @@ -90,7 +90,7 @@ namespace CppSharp.Passes if (retClass == null) { function.ExplicityIgnored = true; - Driver.Diagnostics.EmitWarning( + Log.Debug( "Function '{0}' was ignored due to an indirect return param not of a tag type", function.Name); return false; @@ -121,7 +121,7 @@ namespace CppSharp.Passes Class ignoredBase; if (HasIgnoredBaseClass(method, @class, out ignoredBase)) { - Driver.Diagnostics.EmitMessage( + Log.Debug( "Virtual method '{0}' was ignored due to ignored base '{1}'", method.QualifiedOriginalName, ignoredBase.Name); @@ -134,7 +134,7 @@ namespace CppSharp.Passes var baseOverride = @class.GetRootBaseMethod(method); if (baseOverride != null && baseOverride.Ignore) { - Driver.Diagnostics.EmitMessage( + Log.Debug( "Virtual method '{0}' was ignored due to ignored override '{1}'", method.QualifiedOriginalName, baseOverride.Name); @@ -182,7 +182,7 @@ namespace CppSharp.Passes if (HasInvalidType(typedef.Type, out msg)) { typedef.ExplicityIgnored = true; - Log.EmitMessage("Typedef '{0}' was ignored due to {1} type", + Log.Debug("Typedef '{0}' was ignored due to {1} type", typedef.Name, msg); return false; } @@ -199,7 +199,7 @@ namespace CppSharp.Passes if (HasInvalidDecl(property, out msg)) { property.ExplicityIgnored = true; - Log.EmitMessage("Property '{0}' was ignored due to {1} decl", + Log.Debug("Property '{0}' was ignored due to {1} decl", property.Name, msg); return false; } @@ -207,7 +207,7 @@ namespace CppSharp.Passes if (HasInvalidType(property.Type, out msg)) { property.ExplicityIgnored = true; - Log.EmitMessage("Property '{0}' was ignored due to {1} type", + Log.Debug("Property '{0}' was ignored due to {1} type", property.Name, msg); return false; } @@ -215,7 +215,7 @@ namespace CppSharp.Passes if (property.GetMethod != null && !VisitFunctionDecl(property.GetMethod)) { property.ExplicityIgnored = true; - Log.EmitMessage("Property '{0}' was ignored due to ignored getter", + Log.Debug("Property '{0}' was ignored due to ignored getter", property.Name, msg); return false; } @@ -223,7 +223,7 @@ namespace CppSharp.Passes if (property.SetMethod != null && !VisitFunctionDecl(property.SetMethod)) { property.ExplicityIgnored = true; - Log.EmitMessage("Property '{0}' was ignored due to ignored setter", + Log.Debug("Property '{0}' was ignored due to ignored setter", property.Name, msg); return false; } @@ -240,7 +240,7 @@ namespace CppSharp.Passes if (HasInvalidDecl(variable, out msg)) { variable.ExplicityIgnored = true; - Log.EmitMessage("Variable '{0}' was ignored due to {1} decl", + Log.Debug("Variable '{0}' was ignored due to {1} decl", variable.Name, msg); return false; } @@ -248,7 +248,7 @@ namespace CppSharp.Passes if (HasInvalidType(variable.Type, out msg)) { variable.ExplicityIgnored = true; - Log.EmitMessage("Variable '{0}' was ignored due to {1} type", + Log.Debug("Variable '{0}' was ignored due to {1} type", variable.Name, msg); return false; } @@ -265,7 +265,7 @@ namespace CppSharp.Passes if (HasInvalidDecl(@event, out msg)) { @event.ExplicityIgnored = true; - Log.EmitMessage("Event '{0}' was ignored due to {1} decl", + Log.Debug("Event '{0}' was ignored due to {1} decl", @event.Name, msg); return false; } @@ -275,7 +275,7 @@ namespace CppSharp.Passes if (HasInvalidDecl(param, out msg)) { @event.ExplicityIgnored = true; - Log.EmitMessage("Event '{0}' was ignored due to {1} param", + Log.Debug("Event '{0}' was ignored due to {1} param", @event.Name, msg); return false; } @@ -283,7 +283,7 @@ namespace CppSharp.Passes if (HasInvalidType(param.Type, out msg)) { @event.ExplicityIgnored = true; - Log.EmitMessage("Event '{0}' was ignored due to {1} param", + Log.Debug("Event '{0}' was ignored due to {1} param", @event.Name, msg); return false; } diff --git a/src/Generator/Passes/FieldToPropertyPass.cs b/src/Generator/Passes/FieldToPropertyPass.cs index 6d9bd468..86457f92 100644 --- a/src/Generator/Passes/FieldToPropertyPass.cs +++ b/src/Generator/Passes/FieldToPropertyPass.cs @@ -41,8 +41,7 @@ namespace CppSharp.Passes }; @class.Properties.Add(prop); - Driver.Diagnostics.EmitMessage(DiagnosticId.PropertySynthetized, - "Property created from field: {0}::{1}", @class.Name, field.Name); + Log.Debug("Property created from field: {0}::{1}", @class.Name, field.Name); field.ExplicityIgnored = true; diff --git a/src/Generator/Utils/TestsUtils.cs b/src/Generator/Utils/TestsUtils.cs index 06dea3c6..9cd76512 100644 --- a/src/Generator/Utils/TestsUtils.cs +++ b/src/Generator/Utils/TestsUtils.cs @@ -62,7 +62,8 @@ namespace CppSharp.Utils options.Quiet = true; options.IgnoreParseWarnings = true; - driver.Diagnostics.EmitMessage("Generating bindings for {0} in {1} mode", + driver.Diagnostics.EmitMessage(""); + driver.Diagnostics.EmitMessage("Generating bindings for {0} ({1})", options.LibraryName, options.GeneratorKind.ToString()); // Workaround for CLR which does not check for .dll if the