/// <summary> /// Called when the item is an if item. /// </summary> /// <param name="target">The object that was passed to IParseItem.Visit.</param> /// <returns>The passed target or a modification of it.</returns> /// <exception cref="System.ArgumentNullException">If target is null.</exception> public IParseItem Visit(IfItem target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.Exp.Accept(this); using (tree.Block(true)) target.Block.Accept(this); for (int i = 0; i < target.Elses.Count; i++) { using (tree.Block(true)) { target.Elses[i].Expression.Accept(this); target.Elses[i].Block.Accept(this); } } if (target.ElseBlock != null) { using (tree.Block(true)) target.ElseBlock.Accept(this); } return(target); }
public IParseItem Visit(IfItem target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } target.Expression.Accept(this); using (_tree.Block(true)) { target.Block.Accept(this); } foreach (IfItem.ElseInfo info in target.Elses) { using (_tree.Block(true)) { info.Expression.Accept(this); info.Block.Accept(this); } } if (target.ElseBlock != null) { using (_tree.Block(true)) { target.ElseBlock.Accept(this); } } return(target); }
public IParseItem Visit(IfItem target) { if (target == null) { throw new ArgumentNullException(nameof(target)); } ILGenerator gen = _compiler.CurrentGenerator; Label next = gen.DefineLabel(); Label end = gen.DefineLabel(); // if (!{Exp}.IsTrue) goto next; target.Expression.Accept(this); gen.Emit(OpCodes.Callvirt, typeof(ILuaValue).GetProperty(nameof(ILuaValue.IsTrue)).GetGetMethod()); gen.Emit(OpCodes.Brfalse, next); // {Block} target.Block.Accept(this); // goto end; gen.Emit(OpCodes.Br, end); // next: gen.MarkLabel(next); foreach (var item in target.Elses) { // if (!{item.Item1}.IsTrue) goto next; next = gen.DefineLabel(); item.Expression.Accept(this); gen.Emit(OpCodes.Callvirt, typeof(ILuaValue).GetProperty(nameof(ILuaValue.IsTrue)).GetGetMethod()); gen.Emit(OpCodes.Brfalse, next); // {item.Item2} item.Block.Accept(this); // goto end; gen.Emit(OpCodes.Br, end); // next: gen.MarkLabel(next); } if (target.ElseBlock != null) { target.ElseBlock.Accept(this); } // end: gen.MarkLabel(end); return(target); }