Esempio n. 1
0
        public static (ValueBridge currentLength, VariableBridge result) GetResultVariable(RewriteDesign design, TypeSyntax itemType)
        {
            var arrayType = itemType.ArrayType();

            if (design.ResultSize != null)
            {
                return(design.ResultSize, CreateGlobalVariable(design, arrayType, CreateArray(arrayType, design.ResultSize)));
            }

            var currentResultValue = design.IncompleteIterators.TakeWhile(x =>
            {
                if (!TryGetInt(x.ForInc, out var inc))
                {
                    return(false);
                }
                return(x.Collection != null &&
                       !x.IsReversed && x.ListEnumeration &&
                       x.ForFrom != null && x.ForTo != null && inc == 1);
            }).Aggregate((ValueBridge)0, (x, y) => x + (y.IsReversed ? y.ForFrom - y.ForTo + 1 : y.ForTo - y.ForFrom + 1));

            if (TryGetInt(currentResultValue, out var currentResultInt) && currentResultInt <= Constants.MinArraySize)
            {
                currentResultValue = Constants.MinArraySize;
            }

            return(currentResultValue, CreateGlobalVariable(design, arrayType, CreateArray(arrayType, currentResultValue)));
        }