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; }
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); } }
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); }
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); } }
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); }