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;
        }
Exemplo n.º 2
0
        private static void CalculateNullableAverage(RewriteDesign design, TypeBridge elementType, TypedValueBridge selectionValue, LocalVariable sumVariable)
        {
            var inlinedValue = selectionValue.Reusable(design);

            design.ForAdd(If(inlinedValue.IsEqual(null), Continue()));
            design.ForAdd(sumVariable.AddAssign(inlinedValue.Cast(elementType)));
            design.Indexer = null;

            if (design.Unchecked)
            {
                design.ResultAdd(sumVariable.Cast(design.ReturnType.Type) / design.Indexer);
            }
            else
            {
                design.ResultAdd(Return(SyntaxFactory.ConditionalExpression(design.Indexer.IsEqual(0),
                                                                            Null, sumVariable.Cast(design.ReturnType.Type) / design.Indexer)));
            }
        }
Exemplo n.º 3
0
        public static LocalVariable CreateLocalVariable(RewriteDesign design, TypeBridge type)
        {
            var stringType    = type.ToString();
            var foundVariable = design.Variables.FirstOrDefault(x => stringType == x.Type.ToString() && !x.IsGlobal && !x.IsUsed);

            if (foundVariable != null)
            {
                foundVariable.IsUsed = true;
                return(foundVariable);
            }
            string variable = "v" + VariableIndex++ % Constants.VariablesPeek;
            var    created  = new LocalVariable(variable, type);

            design.Variables.Add(created);

            design.InitialAdd(LocalVariableCreation(variable, type));
            design.SimpleEnumeration = false;
            return(created);
        }
Exemplo n.º 4
0
 public static CastExpressionSyntax Cast(this ExpressionSyntax a, TypeBridge type)
 => CastExpression(type, a);
Exemplo n.º 5
0
 public static CastExpressionSyntax Cast(this int a, TypeBridge type)
 => Cast((ValueBridge)a, type);
Exemplo n.º 6
0
 public static ValueBridge Is(this TypedValueBridge a, TypeBridge type)
 => BinaryExpression(SyntaxKind.IsExpression, a, type);
Exemplo n.º 7
0
 public static LocalDeclarationStatementSyntax LocalVariableCreation(string name, TypeBridge type)
 => SyntaxFactory.LocalDeclarationStatement(VariableCreation(name, type));