From 62e98c84cbe6b60aba67019effaba8978066d679 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 11 Apr 2019 09:07:13 +0200 Subject: [PATCH] [bgen] Make the Frameworks class instance based. --- src/btouch.cs | 2 ++ src/generate-frameworks.csharp | 6 +++--- src/generator-typemanager.cs | 1 + src/generator.cs | 16 ++++++++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/btouch.cs b/src/btouch.cs index 85197e05d8..e0f93dcf10 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -51,6 +51,7 @@ public class BindingTouch { List libs = new List (); public Universe universe; + public Frameworks Frameworks; public TargetFramework TargetFramework { get { return target_framework.Value; } @@ -515,6 +516,7 @@ public class BindingTouch { AttributeManager.BindingTouch = this; Stret.BindingTouch = this; + Frameworks = new Frameworks (CurrentPlatform); Assembly corlib_assembly = universe.LoadFile (LocateAssembly ("mscorlib")); Assembly platform_assembly = baselib; diff --git a/src/generate-frameworks.csharp b/src/generate-frameworks.csharp index caf104ee84..6b8795942a 100755 --- a/src/generate-frameworks.csharp +++ b/src/generate-frameworks.csharp @@ -26,7 +26,7 @@ Console.WriteLine ("partial class Frameworks {"); for (int i = 0; i < names.Length; i++) { var name = names [i]; var frameworks = allframeworks [i]; - Console.Write ($"\tstatic readonly HashSet {name} = new HashSet {{\""); + Console.Write ($"\treadonly HashSet {name} = new HashSet {{\""); Console.Write (string.Join ("\", \"", frameworks)); Console.WriteLine ("\"};"); } @@ -34,8 +34,8 @@ for (int i = 0; i < names.Length; i++) { var allArray = all.ToArray (); Array.Sort (allArray); foreach (var fw in allArray) - Console.WriteLine ($"\tstatic bool? _{fw.Replace (".", "")};"); + Console.WriteLine ($"\tbool? _{fw.Replace (".", "")};"); foreach (var fw in allArray) - Console.WriteLine ($"\tpublic static bool Have{fw} {{ get {{ if (!_{fw}.HasValue) _{fw} = GetValue (\"{fw}\"); return _{fw}.Value; }} }}"); + Console.WriteLine ($"\tpublic bool Have{fw} {{ get {{ if (!_{fw}.HasValue) _{fw} = GetValue (\"{fw}\"); return _{fw}.Value; }} }}"); Console.WriteLine ("}"); Environment.Exit (0); \ No newline at end of file diff --git a/src/generator-typemanager.cs b/src/generator-typemanager.cs index 478edea907..38b0a52934 100644 --- a/src/generator-typemanager.cs +++ b/src/generator-typemanager.cs @@ -5,6 +5,7 @@ using Type = IKVM.Reflection.Type; public static class TypeManager { public static BindingTouch BindingTouch; + static Frameworks Frameworks { get { return BindingTouch.Frameworks; } } public static Type System_Attribute; public static Type System_Boolean; public static Type System_Byte; diff --git a/src/generator.cs b/src/generator.cs index a66ea5512a..43d90bc7a7 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -641,6 +641,7 @@ public class NamespaceManager public BindingTouch BindingTouch; PlatformName CurrentPlatform { get { return BindingTouch.CurrentPlatform; } } bool UnifiedAPI { get { return BindingTouch.Unified; } } + Frameworks Frameworks { get { return BindingTouch.Frameworks; } } public string Prefix { get; private set; } @@ -808,11 +809,17 @@ public enum EnumMode { } public partial class Frameworks { - static HashSet frameworks; - static bool GetValue (string framework) + HashSet frameworks; + readonly PlatformName CurrentPlatform; + public Frameworks (PlatformName current_platform) + { + CurrentPlatform = current_platform; + } + + bool GetValue (string framework) { if (frameworks == null) { - switch (Generator.CurrentPlatform) { + switch (CurrentPlatform) { case PlatformName.iOS: frameworks = iosframeworks; break; @@ -826,7 +833,7 @@ public partial class Frameworks { frameworks = macosframeworks; break; default: - throw new BindingException (1047, "Unsupported platform: {0}. Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", Generator.CurrentPlatform); + throw new BindingException (1047, "Unsupported platform: {0}. Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", CurrentPlatform); } } @@ -839,6 +846,7 @@ public partial class Generator : IMemberGatherer { static NamespaceManager ns; static BindingTouch BindingTouch; + static Frameworks Frameworks { get { return BindingTouch.Frameworks; } } Dictionary> selectors = new Dictionary> (); Dictionary need_static = new Dictionary (); Dictionary need_abstract = new Dictionary ();