本文整理汇总了C#中BinaryExpression.ToStatement方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpression.ToStatement方法的具体用法?C# BinaryExpression.ToStatement怎么用?C# BinaryExpression.ToStatement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryExpression
的用法示例。
在下文中一共展示了BinaryExpression.ToStatement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExpressionFunc
Statement ExpressionFunc()
{
var stack = new Stack<Expression>();
var resultExp = GetResultIndexExpression();
if (!(resultExp is IntegerLiteralExpression))
throw new InvalidOperationException(string.Format("ResultExpression was expected to be an integer but was a {0} instead", resultExp.GetType()));
var dst = ((IntegerLiteralExpression)resultExp).Value;
while ((_opCode = ReadByte()) != 0xFF)
{
switch (_opCode & 0x1F)
{
case 1:
// var
stack.Push(GetVarOrDirectWord(OpCodeParameter.Param1));
break;
case 2:
// add
{
var i = stack.Pop();
stack.Push(new BinaryExpression(i, Operator.Add, stack.Pop()));
}
break;
case 3:
// sub
{
var i = stack.Pop();
stack.Push(new BinaryExpression(stack.Pop(), Operator.Subtract, i));
}
break;
case 4:
// mul
{
var i = stack.Pop();
stack.Push(new BinaryExpression(i, Operator.Multiply, stack.Pop()));
}
break;
case 5:
// div
{
var i = stack.Pop();
stack.Push(new BinaryExpression(stack.Pop(), Operator.Divide, i));
}
break;
case 6:
// normal opcode
{
_opCode = ReadByte();
var statement = ExecuteOpCode();
var expStatement = statement as ExpressionStatement;
if (expStatement == null)
throw new InvalidOperationException("ExpressionStatement expected");
var binExp = expStatement.Expression as BinaryExpression;
if (binExp == null)
throw new InvalidOperationException("BinaryExpression expected");
if (!((binExp.Left is ElementAccess) && ((ElementAccess)binExp.Left).Target is SimpleName))
throw new InvalidOperationException("Variables[0] was expected expected");
stack.Push(binExp.Right);
}
break;
default:
throw new NotImplementedException();
}
}
var exp = new BinaryExpression(GetResultIndex(dst), Operator.Assignment, stack.Pop());
return exp.ToStatement();
}