public static void ArrayEnumeration(RewriteDesign design, TypeBridge itemType, ValueBridge count, ValueBridge collection, LocalVariable variable = null)
        {
            design.CurrentIterator.ForFrom    = 0;
            design.CurrentIterator.ForTo      = count - 1;
            design.CurrentIterator.ForIndexer = CreateGlobalVariable(design, Int);

            if (design.CurrentIndexer == null)
            {
                design.CurrentIterator.Indexer          = design.CurrentIterator.ForIndexer;
                design.CurrentIterator.Indexer.IsGlobal = true;
            }

            if (variable == null)
            {
                design.LastValue = new TypedValueBridge(itemType, collection[design.CurrentIterator.ForIndexer]);
            }
            else
            {
                design.CurrentIterator.BodyAdd(variable.Assign(collection[design.CurrentIterator.ForIndexer]));
                design.LastValue = new TypedValueBridge(itemType, variable);
            }

            design.ResultSize        = count;
            design.SourceSize        = count;
            design.SimpleEnumeration = true;
            design.ListEnumeration   = true;
        }
Ejemplo n.º 2
0
        public static void Rewrite(RewriteDesign design, RewrittenValueBridge[] args)
        {
            var enlarging = args.FirstOrDefault()?.ToString() switch
            {
                "EnlargingCoefficient.By2" => 1,
                "EnlargingCoefficient.By4" => 2,
                "EnlargingCoefficient.By8" => 3,
                _ when design.SourceSize != null => 2,
                _ => 1
            };

            var(currentLength, currentResult) = RewriteToArray.GetResultVariable(design, design.LastValue.Type);
            VariableBridge result = RewriteToArray.RewriteOther(design, currentLength, currentResult, enlarging);

            RewriteToArray.SimplifyPart(design, result);

            var           listResultType = ParseTypeName($"LinqRewrite.Core.SimpleList.SimpleList<{design.LastValue.Type}>");
            LocalVariable finalResult    = CreateGlobalVariable(design, listResultType);

            design.ResultAdd(finalResult.Assign(New(listResultType)));
            design.ResultAdd(finalResult.Access("Items").Assign(result));
            design.ResultAdd(finalResult.Access("Count").Assign(design.ResultSize ?? design.Indexer));
            design.ResultAdd(Return(finalResult));
        }
    }
        public static void EnumerableEnumeration(RewriteDesign design, CollectionValueBridge collection, LocalVariable variable = null)
        {
            design.CurrentIterator.ForFrom         = null;
            design.CurrentIterator.ForTo           = null;
            design.CurrentIterator.Enumerator      = CreateGlobalVariable(design, ParseTypeName($"System.Collections.Generic.IEnumerator<{collection.ItemType}>"));
            design.CurrentIterator.ListEnumeration = false;

            if (variable == null)
            {
                design.LastValue = new TypedValueBridge(collection.ItemType, design.CurrentIterator.Enumerator.Access("Current"));
            }
            else
            {
                design.CurrentForAdd(variable.Assign(design.CurrentIterator.Enumerator.Access("Current")));
                design.LastValue = new TypedValueBridge(collection.ItemType, variable);
            }

            design.SourceSize = null;
            var listEnumerations = design.Iterators.Select(x => x.ListEnumeration).ToArray();

            design.ListEnumeration = false;
            listEnumerations.Select((x, i) => (x, i)).ForEach(x => design.Iterators[x.i].ListEnumeration = x.x);
            design.ModifiedEnumeration = true;
        }