예제 #1
0
        public override void Generate(ILGenerator gen)
        {
            if (trueBlock == null)
            {
                throw new InvalidOperationException("Incomplete If statement");
            }

            Label falseLabel = gen.DefineLabel();
            Label endLabel   = gen.DefineLabel();

            if (falseBlock == null)
            {
                GenerateCondition(gen, endLabel);
                trueBlock.Generate(gen);
            }
            else
            {
                GenerateCondition(gen, falseLabel);
                trueBlock.Generate(gen);
                gen.Emit(OpCodes.Br, endLabel);
                gen.MarkLabel(falseLabel);
                falseBlock.Generate(gen);
            }
            gen.MarkLabel(endLabel);
        }
예제 #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);
        }
예제 #6
0
        public void Generate(ILGenerator gen)
        {
//			try {
            mainBlock.Generate(gen);

/*
 *                      }
 *                      catch (Exception ex) {
 *                              string m = ex.Message + "\nCode block:\n";
 *                              m += "-----------------------\n";
 *                              m += PrintCode ();
 *                              m += "-----------------------\n";
 *                              throw new Exception (m, ex);
 *                      }
 */
        }
예제 #7
0
		public override void Generate (ILGenerator gen)
		{
			gen.BeginExceptionBlock ();
			tryBlock.Generate (gen);
			foreach (DictionaryEntry de in catchBlocks) {
				CodeVariableDeclaration vd = (CodeVariableDeclaration) de.Key;
				gen.BeginCatchBlock (vd.Variable.Type);
				if (vd.Variable.Name.Length > 0) {
					vd.Generate (gen);
					// FIXME: assign exception to this local declaration
				}
				((CodeBlock) de.Value).Generate (gen);
			}
			if (!finallyBlock.IsEmpty) {
				gen.BeginFinallyBlock ();
				finallyBlock.Generate (gen);
			}
			gen.EndExceptionBlock ();
		}
예제 #8
0
        public override void Generate(ILGenerator gen)
        {
            Label startLabel = gen.DefineLabel();
            Label checkLabel = gen.DefineLabel();

            gen.Emit(OpCodes.Br, checkLabel);
            gen.MarkLabel(startLabel);
            whileBlock.Generate(gen);
            gen.MarkLabel(checkLabel);

            if (condition is CodeConditionExpression)
            {
                ((CodeConditionExpression)condition).GenerateForBranch(gen, startLabel, true);
            }
            else
            {
                condition.Generate(gen);
                gen.Emit(OpCodes.Brtrue, startLabel);
            }
        }