本文整理汇总了C#中BlockStatement.AddStatement方法的典型用法代码示例。如果您正苦于以下问题:C# BlockStatement.AddStatement方法的具体用法?C# BlockStatement.AddStatement怎么用?C# BlockStatement.AddStatement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockStatement
的用法示例。
在下文中一共展示了BlockStatement.AddStatement方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceJump
static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block)
{
if (jump.StartOffset < block.StartOffset)
throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block");
if (jump.JumpOffset > block.EndOffset)
throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block");
var newBlock = new BlockStatement();
var ifStatement = new IfStatement(Not(jump.Condition), new BlockStatement()){ StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset };
var inside = false;
foreach (var statement in block)
{
if (statement is IfStatement && statement.Contains(jump.StartOffset.Value) && statement.EndOffset >= jump.JumpOffset)
{
var ifStatement2 = (IfStatement)statement;
var b2 = ReplaceJump(jump, (BlockStatement)ifStatement2.TrueStatement);
var newIfStatement2 = new IfStatement(ifStatement2.Condition, new BlockStatement()){ StartOffset = ifStatement2.StartOffset, EndOffset = ifStatement2.EndOffset };
((BlockStatement)newIfStatement2.TrueStatement).AddStatements((IEnumerable<Statement>)b2);
newBlock.AddStatement(newIfStatement2);
}
else if (statement.StartOffset == jump.StartOffset)
{
inside = true;
}
else if (statement.StartOffset == jump.JumpOffset)
{
if (ifStatement == null)
throw new InvalidOperationException("ifStatement can't be null");
newBlock.AddStatement(ifStatement);
newBlock.AddStatement(statement);
ifStatement = null;
inside = false;
}
else if (inside)
{
((BlockStatement)ifStatement.TrueStatement).AddStatement(statement);
}
else
{
var lastStatement = newBlock.LastOrDefault();
if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset)
{
throw new NotSupportedException("invalid Statement");
}
newBlock.AddStatement(statement);
}
}
return newBlock;
}
示例2: ReplaceJump
static BlockStatement ReplaceJump(JumpStatement jump, BlockStatement block)
{
if (jump.StartOffset < block.StartOffset)
throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block");
if (jump.JumpOffset > block.EndOffset)
throw new ArgumentOutOfRangeException("jump", "jump should be inside the given block");
var newBlock = new BlockStatement();
var doWhileStatement = new DoWhileStatement(jump.Condition, new BlockStatement()){ StartOffset = jump.StartOffset, EndOffset = jump.JumpOffset };
var inside = false;
foreach (var statement in block)
{
if (statement.StartOffset == jump.JumpOffset)
{
((BlockStatement)doWhileStatement.Statement).AddStatement(statement);
inside = true;
}
else if (statement.StartOffset == jump.StartOffset)
{
if (doWhileStatement == null)
throw new InvalidOperationException("DoWhileStatement can't be null");
newBlock.AddStatement(doWhileStatement);
doWhileStatement = null;
inside = false;
}
else if (inside)
{
((BlockStatement)doWhileStatement.Statement).AddStatement(statement);
}
else
{
var lastStatement = newBlock.LastOrDefault();
if (lastStatement != null && lastStatement.EndOffset > statement.StartOffset)
{
throw new NotSupportedException("invalid Statement");
}
newBlock.AddStatement(statement);
}
}
return newBlock;
}
示例3: ParseBlockStatement
/// <summary>
/// Parser for BlockStatement
/// </summary>
/// <returns>Parsed BlockStatement</returns>
public BlockStatement ParseBlockStatement()
{
BlockStatement blockStatement = new BlockStatement();
//Skip { token
NextToken("{", "{ statements* }", '{');
//Parse statements
while (TokenStream.HasNext())
{
if (TokenStream.Peek(1).GetValue().ToString() == "}")
{ //End of blockstatement
break;
}
blockStatement.AddStatement(ParseStatement());
}
//Skip } token
NextToken("}", "{ statements* }", '}');
return blockStatement;
}
示例4: TransformByteCode_Internal
AstNode TransformByteCode_Internal(MethodDefinition methodDef, ILExpression byteCode, List<Ast.Expression> args)
{
// throw new NotImplementedException();
OpCode opCode = byteCode.OpCode;
object operand = byteCode.Operand;
AstType operandAsTypeRef = AstBuilder.ConvertType(operand as Cecil.TypeReference);
ILExpression operandAsByteCode = operand as ILExpression;
Ast.Expression arg1 = args.Count >= 1 ? args[0] : null;
Ast.Expression arg2 = args.Count >= 2 ? args[1] : null;
Ast.Expression arg3 = args.Count >= 3 ? args[2] : null;
BlockStatement branchCommand = null;
if (byteCode.Operand is ILLabel) {
branchCommand = new BlockStatement();
branchCommand.AddStatement(new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name));
}
switch(opCode.Code) {
#region Arithmetic
case Code.Add: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
case Code.Add_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
case Code.Add_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Add, arg2);
case Code.Div: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
case Code.Div_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Divide, arg2);
case Code.Mul: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
case Code.Mul_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
case Code.Mul_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Multiply, arg2);
case Code.Rem: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
case Code.Rem_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Modulus, arg2);
case Code.Sub: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
case Code.Sub_Ovf: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
case Code.Sub_Ovf_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Subtract, arg2);
case Code.And: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseAnd, arg2);
case Code.Or: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.BitwiseOr, arg2);
case Code.Xor: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ExclusiveOr, arg2);
case Code.Shl: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftLeft, arg2);
case Code.Shr: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);
case Code.Shr_Un: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.ShiftRight, arg2);
case Code.Neg: return new Ast.UnaryOperatorExpression(UnaryOperatorType.Minus, arg1);
case Code.Not: return new Ast.UnaryOperatorExpression(UnaryOperatorType.BitNot, arg1);
#endregion
#region Arrays
case Code.Newarr:
operandAsTypeRef = operandAsTypeRef.MakeArrayType(0);
return new Ast.ArrayCreateExpression {
Type = operandAsTypeRef,
Arguments = new Expression[] {arg1}
};
case Code.Ldlen:
return arg1.Member("Length");
case Code.Ldelem_I:
case Code.Ldelem_I1:
case Code.Ldelem_I2:
case Code.Ldelem_I4:
case Code.Ldelem_I8:
case Code.Ldelem_U1:
case Code.Ldelem_U2:
case Code.Ldelem_U4:
case Code.Ldelem_R4:
case Code.Ldelem_R8:
case Code.Ldelem_Ref:
return arg1.Indexer(arg2);
case Code.Ldelem_Any:
throw new NotImplementedException();
case Code.Ldelema:
return MakeRef(arg1.Indexer(arg2));
case Code.Stelem_I:
case Code.Stelem_I1:
case Code.Stelem_I2:
case Code.Stelem_I4:
case Code.Stelem_I8:
case Code.Stelem_R4:
case Code.Stelem_R8:
case Code.Stelem_Ref:
return new Ast.AssignmentExpression(arg1.Indexer(arg2), arg3);
case Code.Stelem_Any:
throw new NotImplementedException();
#endregion
#region Branching
case Code.Br: return new Ast.GotoStatement(((ILLabel)byteCode.Operand).Name);
case Code.Brfalse: return new Ast.IfElseStatement(new Ast.UnaryOperatorExpression(UnaryOperatorType.Not, arg1), branchCommand);
case Code.Brtrue: return new Ast.IfElseStatement(arg1, branchCommand);
case Code.Beq: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, arg2), branchCommand);
case Code.Bge: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand);
case Code.Bge_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThanOrEqual, arg2), branchCommand);
case Code.Bgt: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand);
case Code.Bgt_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.GreaterThan, arg2), branchCommand);
case Code.Ble: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand);
case Code.Ble_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThanOrEqual, arg2), branchCommand);
case Code.Blt: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand);
case Code.Blt_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.LessThan, arg2), branchCommand);
case Code.Bne_Un: return new Ast.IfElseStatement(new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.InEquality, arg2), branchCommand);
#endregion
#region Comparison
case Code.Ceq: return new Ast.BinaryOperatorExpression(arg1, BinaryOperatorType.Equality, ConvertIntToBool(arg2));
//.........这里部分代码省略.........