private TConstruct EmitUnpackToCollectionLoopBody(TContext context, ForLoopContext forLoopContext, CollectionTraits traitsOfTheCollection, TConstruct unpacker, TConstruct collection, PolymorphismSchema itemsSchema)
        {
            /*
             *  if ( !unpacker.Read() )
             *      {
             *              throw SerializationExceptions.NewMissingItem( i );
             *      }
             *
             *      T item;
             *      if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader )
             *      {
             *              item = serializer.UnpackFrom( unpacker );
             *      }
             *      else
             *      {
             *              using ( Unpacker subtreeUnpacker = unpacker.ReadSubtree() )
             *              {
             *                      item = serializer.UnpackFrom( subtreeUnpacker );
             *              }
             *      }
             *
             *      addition( item );
             */

            return
                (this.EmitUnpackItemValueExpression(
                     context,
                     traitsOfTheCollection.ElementType,
                     context.CollectionItemNilImplication,
                     unpacker,
                     forLoopContext.Counter,
                     this.EmitInvariantStringFormat(context, "item{0}", forLoopContext.Counter),
                     null,
                     null,
                     null,
                     itemsSchema,
                     unpackedItem =>
                     this.EmitAppendCollectionItem(
                         context,
                         null,
                         traitsOfTheCollection,
                         collection,
                         unpackedItem
                         )
                     ));
        }
Esempio n. 2
0
        public void VisitForLoop(ForLoopContext context)
        {
            VisitExpression(context.asgn);

            var startLabel = builder.CreateLabelAndSet();
            var endLabel   = builder.CreateLabel();

            VisitExpression(context.comp);

            builder.OutputOperation(Operation.OpJumpNotIf, endLabel);

            VisitStatementBlock(context.statementblock());

            VisitExpression(context.inc);

            builder.OutputOperation(Operation.OpJump, startLabel);

            builder.SetLabelPosition(endLabel);
        }
Esempio n. 3
0
        public override Symbol VisitForLoop([NotNull] ForLoopContext context)
        {
            var forLoopInitializer = context.forLoopArguments().forLoopInitializer();
            var booleanExpression  = context.forLoopArguments().booleanExpression();
            var unaryExpression    = context.forLoopArguments().unaryExpression();
            var statementBlock     = context.statementBlock();

            forLoopInitializer.Accept(this);

            seleniumLogger.Log($"Entering for loop", SeleniumScriptLogLevel.InterpreterDetails);
            while (booleanExpression.Accept(this).AsBool)
            {
                seleniumLogger.Log($"Loop condition holds, exeucting statement block", SeleniumScriptLogLevel.InterpreterDetails);
                statementBlock.Accept(this);
                unaryExpression.Accept(this);
            }
            seleniumLogger.Log($"Exited for loop", SeleniumScriptLogLevel.InterpreterDetails);

            return(null);
        }
        protected override ILConstruct EmitForLoop(TContext context, ILConstruct count, Func <ForLoopContext, ILConstruct> loopBodyEmitter)
        {
            var i =
                this.DeclareLocal(
                    context,
                    typeof(int),
                    "i"
                    );

            var loopContext = new ForLoopContext(i);

            return
                (this.EmitSequentialStatements(
                     context,
                     i.ContextType,
                     i,
                     ILConstruct.Instruction(
                         "for",
                         typeof(void),
                         false,
                         il =>
            {
                var forCond = il.DefineLabel("FOR_COND");
                il.EmitBr(forCond);
                var body = il.DefineLabel("BODY");
                il.MarkLabel(body);
                loopBodyEmitter(loopContext).Evaluate(il);
                // increment
                i.LoadValue(il, false);
                il.EmitLdc_I4_1();
                il.EmitAdd();
                i.StoreValue(il);
                // cond
                il.MarkLabel(forCond);
                i.LoadValue(il, false);
                count.LoadValue(il, false);
                il.EmitBlt(body);
            }
                         )
                     ));
        }
Esempio n. 5
0
        protected override ExpressionConstruct EmitForLoop(ExpressionTreeContext context, ExpressionConstruct count, Func <ForLoopContext, ExpressionConstruct> loopBodyEmitter)
        {
            var counter     = Expression.Variable(typeof(int), "i");
            var loopContext = new ForLoopContext(counter);
            var endFor      = Expression.Label("END_FOR");

            return
                (Expression.Block(
                     new[] { counter },
                     Expression.Loop(
                         Expression.IfThenElse(
                             Expression.LessThan(counter, count),
                             Expression.Block(
                                 loopBodyEmitter(loopContext),
                                 Expression.Assign(counter, Expression.Increment(counter))
                                 ),
                             Expression.Break(endFor)
                             ),
                         endFor
                         )
                     ));
        }
        private TConstruct EmitUnpackToMapLoopBody(TContext context, ForLoopContext forLoopContext, CollectionTraits traits, TConstruct unpacker)
        {
            /*
             *              if ( !unpacker.Read() )
             *              {
             *                      throw SerializationExceptions.NewMissingItem( i );
             *              }
             *
             *              TKey key;
             *              if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader )
             *              {
             *                      key = keySerializer.UnpackFrom( unpacker );
             *              }
             *              else
             *              {
             *                      using ( Unpacker subtreeUnpacker = unpacker.ReadSubtree() )
             *                      {
             *                              key = keySerializer.UnpackFrom( subtreeUnpacker );
             *                      }
             *              }
             *
             *
             *              if ( !unpacker.Read() )
             *              {
             *                      throw SerializationExceptions.NewMissingItem( i );
             *              }
             *
             *              TValue value;
             *              if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader )
             *              {
             *                      value = valueSerializer.UnpackFrom( unpacker );
             *              }
             *              else
             *              {
             *                      using ( Unpacker subtreeUnpacker = unpacker.ReadSubtree() )
             *                      {
             *                              value = valueSerializer.UnpackFrom( subtreeUnpacker );
             *                      }
             *              }
             *
             *              dictionary.Add( key, value );
             */

            Type keyType, valueType;

            GetDictionaryKeyValueType(traits.ElementType, out keyType, out valueType);

            var key   = this.DeclareLocal(context, keyType, "key");
            var value = this.DeclareLocal(context, valueType, "value");

            // ReSharper disable ImplicitlyCapturedClosure
            return
                (this.EmitSequentialStatements(
                     context,
                     typeof(void),
                     key,
                     value,
                     this.EmitUnpackItemValueExpression(
                         context,
                         keyType,
                         context.DictionaryKeyNilImplication,
                         unpacker,
                         forLoopContext.Counter,
                         this.EmitInvariantStringFormat(context, "key{0}", forLoopContext.Counter),
                         null,
                         null,
                         null,
                         unpackedKey =>
                         this.EmitStoreVariableStatement(
                             context,
                             key,
                             unpackedKey
                             )
                         ),
                     this.EmitUnpackItemValueExpression(
                         context,
                         valueType,
                         context.CollectionItemNilImplication,
                         unpacker,
                         forLoopContext.Counter,
                         this.EmitInvariantStringFormat(context, "value{0}", forLoopContext.Counter),
                         null,
                         null,
                         null,
                         unpackedValue =>
                         this.EmitStoreVariableStatement(
                             context,
                             value,
                             unpackedValue
                             )
                         ),
                     this.EmitAppendDictionaryItem(
                         context,
                         traits,
                         context.UnpackToTarget,
                         keyType,
                         key,
                         valueType,
                         value,
                         traits.ElementType == typeof(DictionaryEntry)
                         )
                     ));
            // ReSharper restore ImplicitlyCapturedClosure
        }