示例#1
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);
		}
示例#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);
			}
		}
		public override void Generate (ILGenerator gen)
		{
			if (blocks.Count == 0) return;
			
			CodeIf initialIf = new CodeIf ((CodeExpression)conditions[0]);
			initialIf.TrueBlock = (CodeBlock) blocks[0];
			CodeIf prevCif = initialIf;
			
			for (int n=1; n<blocks.Count; n++) {
				CodeIf cif = new CodeIf ((CodeExpression)conditions[n]);
				cif.TrueBlock = (CodeBlock) blocks[n];
				CodeBlock cb = new CodeBlock ();
				cb.Add (cif);
				prevCif.FalseBlock = cb;
				prevCif = cif;
			}

			initialIf.Generate (gen);
		}
		public void AddCase (CodeExpression condition, CodeBlock block)
		{
			conditions.Add (condition);
			blocks.Add (block);
		}
		CodeBuilder (CodeBlock block)
		{
			currentBlock = block;
		}
		public CodeBuilder (CodeClass codeClass)
		{
			this.codeClass = codeClass;
			mainBlock = new CodeBlock ();
			currentBlock = mainBlock;
		}
		CodeBlock PopBlock ()
		{
			CodeBlock block = currentBlock;
			currentBlock = (CodeBlock) blockStack.Pop ();
			return block;
		}
		void PushNewBlock ()
		{
			blockStack.Push (currentBlock);
			currentBlock = new CodeBlock ();
		}
示例#9
0
		public CodeTry ()
		{
			tryBlock = new CodeBlock ();
			catchBlocks = new ArrayList ();
			finallyBlock = new CodeBlock ();
		}
示例#10
0
 public CodeTry()
 {
     tryBlock     = new CodeBlock();
     catchBlocks  = new ArrayList();
     finallyBlock = new CodeBlock();
 }
示例#11
0
 CodeBuilder(CodeBlock block)
 {
     currentBlock = block;
 }
示例#12
0
 void PushNewBlock()
 {
     blockStack.Push(currentBlock);
     currentBlock = new CodeBlock();
 }
示例#13
0
 public CodeBuilder(CodeClass codeClass)
 {
     this.codeClass = codeClass;
     mainBlock      = new CodeBlock();
     currentBlock   = mainBlock;
 }
示例#14
0
 public void AddCase(CodeExpression condition, CodeBlock block)
 {
     conditions.Add(condition);
     blocks.Add(block);
 }