Beispiel #1
0
        protected static T[] Create <T>(IEnumerableCollectionProcessor processor, string name, params string[] descriptions)
            where T : String2BoolMatrixTuple, IDoubleApi
        {
            var array  = processor.NameCollection.ToArray();
            var answer = descriptions.Length == 0 ? Array.Empty <T>() : new T[descriptions.Length];
            var index  = 0;

            foreach (var description in descriptions)
            {
                answer[index] = CreateInstance <T>();
                ref var api = ref answer[index++];
                ((IDoubleApi)api).Name = name;
                api.Description        = description;
                api.EnumerableArray    = new string[array.Length];
                for (var i = 0; i < array.Length; i++)
                {
                    api.EnumerableArray[i] = array[i];
                }
                api.EnabledArray = new bool[api.Count * api.Count];
                for (int i = 0; i < api.EnabledArray.Length; i++)
                {
                    api.EnabledArray[i] = true;
                }
                AssetDatabase.CreateAsset(api, "Assets/UniNativeLinq/Editor/ApiDouble/" + name + "___" + (description.Length <= 10 ? description : description.GetHashCode().ToString("X")) + ".asset");
            }
Beispiel #2
0
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            var @static = mainModule.GetType("UniNativeLinq", "NativeEnumerable");

            var method = new MethodDefinition(Api.Name, Helper.StaticMethodAttributes, mainModule.TypeSystem.Boolean)
            {
                DeclaringType      = @static,
                AggressiveInlining = true,
            };

            @static.Methods.Add(method);

            var T = new GenericParameter("T", method)
            {
                HasNotNullableValueTypeConstraint = true,
                HasDefaultConstructorConstraint   = true,
            };

            method.GenericParameters.Add(T);

            var typeDefinition = method.Module.GetType("UniNativeLinq", "NativeEnumerable`1");

            method.ReturnType = new GenericInstanceType(typeDefinition)
            {
                GenericArguments = { T }
            };
            GenerateNativeEnumerable(method, method.ReturnType, T, systemModule);
        }
        private void RemoveUnnecessaryEnumerable(IEnumerableCollectionProcessor processor, IDependency[] dependencies, out Dictionary <string, TypeDefinition> enumerableDefinitionDictionary, out Dictionary <string, IDependency> dependencyDictionary)
        {
            enumerableDefinitionDictionary = new Dictionary <string, TypeDefinition>();
            var names = processor.NameCollection.ToArray();

            foreach (var name in names)
            {
                if (!processor.IsSpecialType(name, out var value) || value)
                {
                    continue;
                }
                enumerableDefinitionDictionary.Add(name, mainModule.GetType("UniNativeLinq", string.Intern(name + "Enumerable`" + processor.GetGenericParameterCount(name))));
            }
            dependencyDictionary = dependencies.ToDictionary(x => x.Enumerable, x => x);

            foreach (var name in names)
            {
                if (!processor.IsSpecialType(name, out var isSpecial) || isSpecial)
                {
                    continue;
                }
                if (!processor.TryGetEnabled(name, out var enabled) || enabled)
                {
                    continue;
                }
                var type = enumerableDefinitionDictionary[name];

                if (dependencyDictionary.TryGetValue(name, out var dependency))
                {
                    RemoveDependency(type, dependency);
                }

                mainModule.Types.Remove(type);
            }
        }
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            TypeDefinition @static;

            mainModule.Types.Add(@static = mainModule.DefineStatic(Api.Name + (IsNullable ? Api.Description.Replace('<', '_').Replace('>', '_') : Api.Description) + "Helper"));

            foreach (var name in array)
            {
                if (!processor.IsSpecialType(name, out var isSpecial))
                {
                    throw new KeyNotFoundException();
                }
                if (!Api.TryGetEnabled(name, out var apiEnabled) || !apiEnabled)
                {
                    continue;
                }
                GenerateEach(name, isSpecial, @static, mainModule, systemModule);
            }
        }
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            if (!processor.TryGetEnabled(Api.Name, out var enabled) || !enabled)
            {
                return;
            }
            var names = Api.NameCollection;

            if (names.All(name => !Api.TryGetEnabled(name, out var e) || !e))
            {
                return;
            }

            var @static = mainModule.GetType("UniNativeLinq", "Enumerable");

            if (@static is null)
            {
                @static = mainModule.DefineStatic("Enumerable");
                @static.CustomAttributes.Clear();
                mainModule.Types.Add(@static);
            }

            foreach (var name in names.Where(name => Api.TryGetEnabled(name, out var e) && e))
            {
                GenerateEach(name, @static, mainModule, systemModule, unityModule);
            }
        }
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            var returnTypeReference = CalculateReturnType(mainModule);
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            TypeDefinition @static;

            mainModule.Types.Add(@static = mainModule.DefineStatic(Api.Name + processType + "FuncHelper"));

            if (Api.TryGetEnabled("TEnumerable", out var genericEnabled) && genericEnabled)
            {
                GenerateGeneric(@static, mainModule, systemModule, returnTypeReference);
            }

            foreach (var name in array)
            {
                if (!processor.IsSpecialType(name, out var isSpecial))
                {
                    throw new KeyNotFoundException();
                }
                if (!Api.TryGetEnabled(name, out var apiEnabled) || !apiEnabled)
                {
                    continue;
                }
                GenerateEach(name, isSpecial, @static, mainModule, systemModule, returnTypeReference);
            }
        }
Beispiel #7
0
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            if (!processor.TryGetEnabled(Api.Name, out var enabled) || !enabled)
            {
                return;
            }
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            TypeDefinition @static;

            mainModule.Types.Add(@static = mainModule.DefineStatic(Api.Name + Api.Description + "Helper"));
            TypeReference elementTypeReference;

            switch (elementTypeName)
            {
            case "Double":
                elementTypeReference = mainModule.TypeSystem.Double;
                break;

            case "Single":
                elementTypeReference = mainModule.TypeSystem.Single;
                break;

            case "Int32":
                elementTypeReference = mainModule.TypeSystem.Int32;
                break;

            case "UInt32":
                elementTypeReference = mainModule.TypeSystem.UInt32;
                break;

            case "Int64":
                elementTypeReference = mainModule.TypeSystem.Int64;
                break;

            case "UInt64":
                elementTypeReference = mainModule.TypeSystem.UInt64;
                break;

            default: throw new ArgumentException();
            }
            foreach (var name in array)
            {
                if (!processor.IsSpecialType(name, out var isSpecial))
                {
                    throw new KeyNotFoundException();
                }
                if (!Api.TryGetEnabled(name, out var apiEnabled) || !apiEnabled)
                {
                    continue;
                }
                GenerateEach(name, isSpecial, @static, mainModule, systemModule, elementTypeReference);
            }
        }
 public void Execute(IEnumerableCollectionProcessor processor, IApiExtensionMethodGenerator[] generators, IDependency[] dependencies)
 {
     Console.WriteLine("EXE 0");
     RemoveUnnecessaryEnumerable(processor, dependencies, out var enumerableDefinitionDictionary, out _);
     Console.WriteLine("EXE 1");
     GenerateExtensionMethods(processor, generators, enumerableDefinitionDictionary);
     Console.WriteLine("EXE 2");
     Write();
 }
 private void GenerateExtensionMethods(IEnumerableCollectionProcessor processor, IApiExtensionMethodGenerator[] generators, Dictionary <string, TypeDefinition> definitions)
 {
     foreach (var generator in generators)
     {
         if (generator is ITypeDictionaryHolder holder)
         {
             holder.Dictionary = definitions;
         }
         generator.Generate(processor, mainModule, systemModule, unityCoreModule);
     }
 }
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            if (!Api.TryGetEnabled("TEnumerable", out var genericEnabled) || !genericEnabled)
            {
                return;
            }
            var @static = mainModule.DefineStatic(nameof(AggregateRefValue2Operators) + "Helper");

            @static.CustomAttributes.Clear();
            mainModule.Types.Add(@static);
            GenerateGeneric(@static, mainModule);
        }
Beispiel #11
0
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            if (!processor.TryGetEnabled(Api.Name, out var enabled) || !enabled || !Api.TryGetEnabled("", out enabled) || !enabled)
            {
                return;
            }
            var @static = mainModule.GetType("UniNativeLinq", "Enumerable");

            if (@static is null)
            {
                @static = mainModule.DefineStatic("Enumerable");
                @static.CustomAttributes.Clear();
                mainModule.Types.Add(@static);
            }

            var method = new MethodDefinition(Api.Description, Helper.StaticMethodAttributes, mainModule.TypeSystem.Boolean)
            {
                DeclaringType      = @static,
                AggressiveInlining = true,
            };

            @static.Methods.Add(method);

            var T = method.DefineUnmanagedGenericParameter();

            method.GenericParameters.Add(T);

            var NoAction = new GenericInstanceType(mainModule.GetType("UniNativeLinq", "NoAction`1"))
            {
                GenericArguments = { T }
            };

            method.ReturnType = new GenericInstanceType(mainModule.GetType("UniNativeLinq", "RangeRepeatEnumerable`2"))
            {
                GenericArguments = { T, NoAction }
            };

            method.Parameters.Add(new ParameterDefinition("value", ParameterAttributes.In, new ByReferenceType(T))
            {
                CustomAttributes = { Helper.GetSystemRuntimeCompilerServicesIsReadOnlyAttributeTypeReference() }
            });
            method.Parameters.Add(new ParameterDefinition("count", ParameterAttributes.None, mainModule.TypeSystem.Int64));

            method.Body.GetILProcessor()
            .LdArgs(0, 2)
            .NewObj(method.ReturnType.FindMethod(".ctor", 2))
            .Ret();
        }
        protected static T[] Create <T>(IEnumerableCollectionProcessor processor, string name, params string[] descriptions)
            where T : String2BoolArrayTuple, ISingleApi
        {
            var array  = processor.NameCollection.ToArray();
            var answer = descriptions.Length == 0 ? Array.Empty <T>() : new T[descriptions.Length];
            var index  = 0;

            foreach (var description in descriptions)
            {
                answer[index] = CreateInstance <T>();
                ref var api = ref answer[index++];
                api.EnabledArray = new StringBoolValueTuple[array.Length];
                for (var i = 0; i < array.Length; i++)
                {
                    ref var tuple = ref api.EnabledArray[i];
                    tuple.Enumerable = array[i];
                    tuple.Enabled    = true;
                }
 public DrawableImplWhetherToUseApiOrNot(IEnumerableCollectionProcessor processor, ISingleApi[] singleApis, IDoubleApi[] doubleApis)
 {
     this.processor  = processor;
     this.singleApis = singleApis ?? Array.Empty <ISingleApi>();
     this.doubleApis = doubleApis ?? Array.Empty <IDoubleApi>();
     try
     {
         Array.Sort(this.singleApis);
         Array.Sort(this.doubleApis);
     }
     catch (Exception e)
     {
         Debug.LogWarning(e);
     }
     foreach (var api in doubleApis)
     {
         ((IDrawableWithEnumerableAndScrollPosition)api).RegisterEnumerableCollectionProcessor(processor);
     }
 }
        public static void HelpWithGenerate(this IDoubleApi Api, IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, Action <string, bool, string, bool, TypeDefinition, ModuleDefinition, ModuleDefinition> GenerateEachPair)
        {
            if (!processor.TryGetEnabled(Api.Name, out var enabled) || !enabled)
            {
                return;
            }
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            TypeDefinition @static;

            mainModule.Types.Add(@static = mainModule.DefineStatic(Api.Name + Api.Description + "Helper"));
            var count = Api.Count;

            for (var row = 0; row < count; row++)
            {
                var rowName = Api.NameCollection[row];
                if (!processor.IsSpecialType(rowName, out var isRowSpecial))
                {
                    throw new KeyNotFoundException();
                }

                for (var column = 0; column < count; column++)
                {
                    var columnName = Api.NameCollection[column];
                    if (!processor.IsSpecialType(columnName, out var isColumnSpecial))
                    {
                        throw new KeyNotFoundException();
                    }

                    if (!Api.TryGetEnabled(rowName, columnName, out var apiEnabled) || !apiEnabled)
                    {
                        continue;
                    }

                    GenerateEachPair(rowName, isRowSpecial, columnName, isColumnSpecial, @static, mainModule, systemModule);
                }
            }
        }
Beispiel #15
0
        public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
        {
            var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();

            if (!Api.ShouldDefine(array))
            {
                return;
            }
            var @static = mainModule.GetType("UniNativeLinq", "NativeEnumerable");

            foreach (var name in array)
            {
                if (!processor.IsSpecialType(name, out var isSpecial))
                {
                    throw new KeyNotFoundException();
                }
                if (!Api.TryGetEnabled(name, out var apiEnabled) || !apiEnabled)
                {
                    continue;
                }
                GenerateEach(name, isSpecial, @static, mainModule, systemModule);
            }
        }
 public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
 {
     if (!processor.TryGetEnabled(Name + keyName, out var enabled) || !enabled) return;
     var array = processor.EnabledNameCollection.Intersect(Api.NameCollection).ToArray();
     if (!Api.ShouldDefine(array)) return;
     TypeDefinition @static;
     mainModule.Types.Add(@static = mainModule.DefineStatic(Name + "RefFunc" + keyName + "Helper"));
     TypeReference keyType;
     switch (keyName)
     {
         case "Double":
             keyType = mainModule.TypeSystem.Double;
             break;
         case "Single":
             keyType = mainModule.TypeSystem.Single;
             break;
         case "Int32":
             keyType = mainModule.TypeSystem.Int32;
             break;
         case "UInt32":
             keyType = mainModule.TypeSystem.UInt32;
             break;
         case "Int64":
             keyType = mainModule.TypeSystem.Int64;
             break;
         case "UInt64":
             keyType = mainModule.TypeSystem.UInt64;
             break;
         default: throw new ArgumentOutOfRangeException();
     }
     foreach (var name in array)
     {
         if (!processor.IsSpecialType(name, out var isSpecial)) throw new KeyNotFoundException();
         if (!Api.TryGetEnabled(name, out var apiEnabled) || !apiEnabled) continue;
         GenerateEach(name, isSpecial, @static, mainModule, systemModule, keyType);
     }
 }
        public void Initialize()
        {
            Console.WriteLine("INITIALIZE");
            Helper.Initialize();

            T1[] Gets <T0, T1>()
                where T0 : Object
                where T1 : class
            {
                var paths  = AssetDatabase.FindAssets("t:" + typeof(T0).Name);
                var answer = paths.Length == 0 ? Array.Empty <T1>() : new T1[paths.Length];

                for (var i = 0; i < paths.Length; i++)
                {
                    answer[i] = AssetDatabase.LoadAssetAtPath <T0>(AssetDatabase.GUIDToAssetPath(paths[i])) as T1;
                }
                return(answer);
            }

            T0[] Gets0 <T0>()
                where T0 : Object
            {
                var paths  = AssetDatabase.FindAssets("t:" + typeof(T0).Name);
                var answer = paths.Length == 0 ? Array.Empty <T0>() : new T0[paths.Length];

                for (var i = 0; i < paths.Length; i++)
                {
                    answer[i] = AssetDatabase.LoadAssetAtPath <T0>(AssetDatabase.GUIDToAssetPath(paths[i]));
                }
                return(answer);
            }

            if (EnumerableCollectionProcessor is null)
            {
                EnumerableCollectionProcessor = new EnumerableCollectionProcessor(Gets0 <StringBoolTuple>());
            }
            if (whetherToIncludeEnumerableOrNotView is null)
            {
                whetherToIncludeEnumerableOrNotView = new DrawableImplWhetherToIncludeEnumerable(EnumerableCollectionProcessor);
            }
            if (SingleApis is null)
            {
                SingleApis = Gets <String2BoolArrayTuple, ISingleApi>();
            }
            if (DoubleApis is null)
            {
                DoubleApis = Gets <String2BoolMatrixTuple, IDoubleApi>();
            }
            if (Dependencies is null)
            {
                Dependencies = Gets <DependencyObject, IDependency>();
            }
            if (whetherToUseApiOrNotView is null)
            {
                whetherToUseApiOrNotView = new DrawableImplWhetherToUseApiOrNot(EnumerableCollectionProcessor, SingleApis, DoubleApis);
            }
            DllGenerator?.Dispose();
            DllGenerator = new DllGenerator(Helper.MainModule, Helper.SystemModule, Helper.UnityCoreModule);

            settings = GlobalSettings.Instance;

            Console.WriteLine("INITIALIZE 2");
            InitializeExtensionMethodsGenerator();
        }
 public void Generate(IEnumerableCollectionProcessor processor, ModuleDefinition mainModule, ModuleDefinition systemModule, ModuleDefinition unityModule)
 {
     Api.GenerateSingleWithEnumerable(processor, mainModule, systemModule, unityModule, GenerateEach);
 }
Beispiel #19
0
 public DrawableImplWhetherToIncludeEnumerable(IEnumerableCollectionProcessor processor)
 {
     this.processor = processor;
 }