示例#1
0
        public void EndWhile()
        {
            CodeBlock block = PopBlock();
            CodeWhile cif   = currentBlock.GetLastItem() as CodeWhile;

            if (cif == null || cif.WhileBlock != null)
            {
                throw new InvalidOperationException("'EndWhile' not allowed here");
            }

            cif.WhileBlock = block;
        }
示例#2
0
        public override void Generate(ILGenerator gen)
        {
            Type t = array.GetResultType();

            if (t.IsArray)
            {
                CodeBlock block = new CodeBlock();
                CodeVariableDeclaration indexDec;
                CodeWhile          cw;
                CodeValueReference index;
                CodeValueReference item;

                block.Add(itemDec);
                item = itemDec.Variable;
                block.Add(indexDec = new CodeVariableDeclaration(typeof(int), "n"));
                index = indexDec.Variable;
                block.Add(new CodeAssignment(index, new CodeLiteral(0)));

                block.Add(cw = new CodeWhile(CodeExpression.IsSmallerThan(index, array.ArrayLength)));
                CodeBlock loopBlock = new CodeBlock();
                loopBlock.Add(new CodeAssignment(item, array[index]));
                loopBlock.Add(new CodeIncrement(index));
                loopBlock.Add(forBlock);
                cw.WhileBlock = loopBlock;

                block.Generate(gen);
            }
            else
            {
                CodeBlock block = new CodeBlock();
                CodeVariableDeclaration dec;
                CodeWhile          cw;
                CodeValueReference enumerator;
                CodeValueReference item;

                block.Add(itemDec);
                item          = itemDec.Variable;
                block.Add(dec = new CodeVariableDeclaration(typeof(IEnumerator), "e"));
                enumerator    = dec.Variable;
                block.Add(new CodeAssignment(enumerator, array.Call("GetEnumerator")));

                block.Add(cw = new CodeWhile(enumerator.Call("MoveNext")));
                CodeBlock loopBlock = new CodeBlock();
                loopBlock.Add(new CodeAssignment(item, enumerator["Current"]));
                loopBlock.Add(forBlock);
                cw.WhileBlock = loopBlock;

                block.Generate(gen);
            }
        }
示例#3
0
文件: CodeFor.cs 项目: nlhepler/mono
		public override void Generate (ILGenerator gen)
		{
			CodeBlock block = new CodeBlock();
			CodeWhile cw;
			
			block.Add (initExp);
			block.Add (cw = new CodeWhile (conditionExp));
			CodeBlock loopBlock = new CodeBlock ();
			loopBlock.Add (forBlock);
			loopBlock.Add (nextExp);
			cw.WhileBlock = loopBlock;
			
			block.Generate (gen);
		}
示例#4
0
		public override void Generate (ILGenerator gen)
		{
			Type t = array.GetResultType ();
			if (t.IsArray)
			{
				CodeBlock block = new CodeBlock();
				CodeVariableDeclaration indexDec;
				CodeWhile cw;
				CodeValueReference index;
				CodeValueReference item;
				
				block.Add (itemDec);
				item = itemDec.Variable;
				block.Add (indexDec = new CodeVariableDeclaration (typeof(int), "n"));
				index = indexDec.Variable;
				block.Add (new CodeAssignment (index, new CodeLiteral (0)));
				
				block.Add (cw = new CodeWhile (CodeExpression.IsSmallerThan (index, array.ArrayLength)));
				CodeBlock loopBlock = new CodeBlock ();
				loopBlock.Add (new CodeAssignment (item, array[index]));
				loopBlock.Add (new CodeIncrement(index));
				loopBlock.Add (forBlock);
				cw.WhileBlock = loopBlock;
				
				block.Generate (gen);
			}
			else
			{
				CodeBlock block = new CodeBlock();
				CodeVariableDeclaration dec;
				CodeWhile cw;
				CodeValueReference enumerator;
				CodeValueReference item;
				
				block.Add (itemDec);
				item = itemDec.Variable;
				block.Add (dec = new CodeVariableDeclaration (typeof(IEnumerator), "e"));
				enumerator = dec.Variable;
				block.Add (new CodeAssignment (enumerator, array.Call("GetEnumerator")));
				
				block.Add (cw = new CodeWhile (enumerator.Call ("MoveNext")));
				CodeBlock loopBlock = new CodeBlock ();
				loopBlock.Add (new CodeAssignment (item, enumerator["Current"]));
				loopBlock.Add (forBlock);
				cw.WhileBlock = loopBlock;
				
				block.Generate (gen);
			}
		}
示例#5
0
文件: CodeFor.cs 项目: raj581/Marvin
        public override void Generate(ILGenerator gen)
        {
            CodeBlock block = new CodeBlock();
            CodeWhile cw;

            block.Add(initExp);
            block.Add(cw = new CodeWhile(conditionExp));
            CodeBlock loopBlock = new CodeBlock();

            loopBlock.Add(forBlock);
            loopBlock.Add(nextExp);
            cw.WhileBlock = loopBlock;

            block.Generate(gen);
        }