From 2290e06cbd40f9a4d9baea4d80473d6074c1531a Mon Sep 17 00:00:00 2001 From: Stefanos A Date: Sun, 1 Dec 2013 18:26:01 +0100 Subject: [PATCH] Use untyped int for enums in unmanaged callsites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By using untyped integers instead of typed integers in the unmanaged callsites, we allow monolinker to keep the exact set of enums that are used by the user. Without this, we’d have to keep every single enum in place to avoid missing type exceptions. This does not affect the public signatures or the generated code in any way. --- Source/Bind/CSharpSpecWriter.cs | 37 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/Source/Bind/CSharpSpecWriter.cs b/Source/Bind/CSharpSpecWriter.cs index c9ad9c70..82c4e3ae 100644 --- a/Source/Bind/CSharpSpecWriter.cs +++ b/Source/Bind/CSharpSpecWriter.cs @@ -1,4 +1,4 @@ -#region License +#region License // // The Open Toolkit Library License // @@ -405,7 +405,7 @@ namespace Bind sw.WriteLine("[AutoGenerated(Category = \"{0}\", Version = \"{1}\", EntryPoint = \"{2}\")]", f.Category, f.Version, Settings.FunctionPrefix + f.WrappedDelegate.EntryPoint); - sw.WriteLine("public static extern {0};", GetDeclarationString(f)); + sw.WriteLine("public static extern {0};", GetDeclarationString(f, Settings.Compatibility)); } DocProcessor processor_; @@ -675,11 +675,11 @@ namespace Bind sb.Append(d.Unsafe ? "unsafe " : ""); if (is_delegate) sb.Append("delegate "); - sb.Append(GetDeclarationString(d.ReturnType)); + sb.Append(GetDeclarationString(d.ReturnType, Settings.Legacy.ConstIntEnums)); sb.Append(" "); sb.Append(Settings.FunctionPrefix); sb.Append(d.Name); - sb.Append(GetDeclarationString(d.Parameters)); + sb.Append(GetDeclarationString(d.Parameters, Settings.Legacy.ConstIntEnums)); return sb.ToString(); } @@ -717,12 +717,12 @@ namespace Bind return sb.ToString(); } - string GetDeclarationString(Function f) + string GetDeclarationString(Function f, Settings.Legacy settings) { StringBuilder sb = new StringBuilder(); sb.Append(f.Unsafe ? "unsafe " : ""); - sb.Append(GetDeclarationString(f.ReturnType)); + sb.Append(GetDeclarationString(f.ReturnType, settings)); sb.Append(" "); if ((Settings.Compatibility & Settings.Legacy.NoTrimFunctionEnding) != Settings.Legacy.None) { @@ -745,7 +745,7 @@ namespace Bind sb.Append(">"); } - sb.Append(GetDeclarationString(f.Parameters)); + sb.Append(GetDeclarationString(f.Parameters, settings)); if (f.Parameters.HasGenericParameters) { @@ -760,7 +760,7 @@ namespace Bind return sb.ToString(); } - string GetDeclarationString(Parameter p, bool override_unsafe_setting) + string GetDeclarationString(Parameter p, bool override_unsafe_setting, Settings.Legacy settings) { StringBuilder sb = new StringBuilder(); @@ -785,12 +785,12 @@ namespace Bind } else { - sb.Append(GetDeclarationString(p as Type)); + sb.Append(GetDeclarationString(p as Type, settings)); } } else { - sb.Append(GetDeclarationString(p as Type)); + sb.Append(GetDeclarationString(p as Type, settings)); } if (!String.IsNullOrEmpty(p.Name)) { @@ -801,7 +801,7 @@ namespace Bind return sb.ToString(); } - string GetDeclarationString(ParameterCollection parameters) + string GetDeclarationString(ParameterCollection parameters, Settings.Legacy settings) { StringBuilder sb = new StringBuilder(); @@ -810,7 +810,7 @@ namespace Bind { foreach (Parameter p in parameters) { - sb.Append(GetDeclarationString(p, false)); + sb.Append(GetDeclarationString(p, false, settings)); sb.Append(", "); } sb.Replace(", ", ")", sb.Length - 2, 2); @@ -823,10 +823,19 @@ namespace Bind return sb.ToString(); } - string GetDeclarationString(Type type) + string GetDeclarationString(Type type, Settings.Legacy settings) { + var t = type.QualifiedType; + if ((settings & Settings.Legacy.ConstIntEnums) != 0) + { + if (type.IsEnum) + { + t = "System.Int32"; + } + } + return String.Format("{0}{1}{2}", - type.QualifiedType, + t, pointer_levels[type.Pointer], array_levels[type.Array]); }