本文整理汇总了C#中BinaryExpression类的典型用法代码示例。如果您正苦于以下问题:C# BinaryExpression类的具体用法?C# BinaryExpression怎么用?C# BinaryExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BinaryExpression类属于命名空间,在下文中一共展示了BinaryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileBinaryExpression
public static void CompileBinaryExpression(BinaryExpression expression, bool useInterpreter, bool expected)
{
Expression<Func<bool>> e = Expression.Lambda<Func<bool>>(expression, Enumerable.Empty<ParameterExpression>());
Func<bool> f = e.Compile(useInterpreter);
Assert.Equal(expected, f());
}
示例2: GetResultIndexExpression
protected Expression GetResultIndexExpression()
{
var resultVarIndex = ReadWord();
Expression resultVarIndexExp = resultVarIndex.ToLiteral();
if ((resultVarIndex & 0x2000) == 0x2000)
{
int a = ReadWord();
if ((a & 0x2000) == 0x2000)
{
var variableExp = ReadVariable(a & ~0x2000);
var literalExp = variableExp as IntegerLiteralExpression;
if (literalExp != null)
{
resultVarIndex += Convert.ToInt32(literalExp.Value);
resultVarIndex &= ~0x2000;
resultVarIndexExp = resultVarIndex.ToLiteral();
}
else
{
resultVarIndexExp = new BinaryExpression(
new BinaryExpression(resultVarIndexExp, Operator.Add, variableExp),
Operator.And,
new UnaryExpression(0x2000.ToLiteral(), Operator.Not));
}
}
else
{
resultVarIndex = resultVarIndex + (a & 0xFFF);
resultVarIndex &= ~0x2000;
resultVarIndexExp = resultVarIndex.ToLiteral();
}
}
return resultVarIndexExp;
}
示例3: Match
public bool Match(BinaryExpression exp)
{
if (exp.Operator != Operator.IAdd)
return false;
id = exp.Left as Identifier;
bin = exp.Right as BinaryExpression;
if ((id == null || bin == null) && exp.Operator == Operator.IAdd)
{
id = exp.Right as Identifier;
bin = exp.Left as BinaryExpression;
}
if (id == null || bin == null)
return false;
if (bin.Operator != Operator.SMul && bin.Operator != Operator.UMul && bin.Operator != Operator.IMul)
return false;
Identifier idInner = bin.Left as Identifier;
cInner = bin.Right as Constant;
if (idInner == null ||cInner == null)
return false;
if (idInner != id)
return false;
return true;
}
示例4: EmitBinaryMethod
//CONFORMING
private void EmitBinaryMethod(BinaryExpression b) {
if (b.IsLifted) {
ParameterExpression p1 = Expression.Variable(TypeUtils.GetNonNullableType(b.Left.Type), null);
ParameterExpression p2 = Expression.Variable(TypeUtils.GetNonNullableType(b.Right.Type), null);
MethodCallExpression mc = Expression.Call(null, b.Method, p1, p2);
Type resultType = null;
if (b.IsLiftedToNull) {
resultType = TypeUtils.GetNullableType(mc.Type);
} else {
switch (b.NodeType) {
case ExpressionType.Equal:
case ExpressionType.NotEqual:
case ExpressionType.LessThan:
case ExpressionType.LessThanOrEqual:
case ExpressionType.GreaterThan:
case ExpressionType.GreaterThanOrEqual:
if (mc.Type != typeof(bool)) {
throw Error.ArgumentMustBeBoolean();
}
resultType = typeof(bool);
break;
default:
resultType = TypeUtils.GetNullableType(mc.Type);
break;
}
}
IList<ParameterExpression> variables = new ParameterExpression[] { p1, p2 };
IList<Expression> arguments = new Expression[] { b.Left, b.Right };
ValidateLift(variables, arguments);
EmitLift(b.NodeType, resultType, mc, variables, arguments);
} else {
EmitMethodCallExpression(Expression.Call(null, b.Method, b.Left, b.Right));
}
}
示例5: AddressOf
private void AddressOf(BinaryExpression node, Type type)
{
Debug.Assert(node.NodeType == ExpressionType.ArrayIndex && node.Method == null);
if (TypeUtils.AreEquivalent(type, node.Type))
{
EmitExpression(node.Left);
EmitExpression(node.Right);
Type rightType = node.Right.Type;
if (TypeUtils.IsNullableType(rightType))
{
LocalBuilder loc = GetLocal(rightType);
_ilg.Emit(OpCodes.Stloc, loc);
_ilg.Emit(OpCodes.Ldloca, loc);
_ilg.EmitGetValue(rightType);
FreeLocal(loc);
}
Type indexType = TypeUtils.GetNonNullableType(rightType);
if (indexType != typeof(int))
{
_ilg.EmitConvertToType(indexType, typeof(int), isChecked: true);
}
_ilg.Emit(OpCodes.Ldelema, node.Type);
}
else
{
EmitExpressionAddress(node, type);
}
}
示例6: VisitBinaryExpression
public override Expression VisitBinaryExpression(BinaryExpression binaryExpression){
if (binaryExpression == null) return null;
binaryExpression.Operand2 = this.VisitExpression(binaryExpression.Operand2);
binaryExpression.Operand1 = this.VisitExpression(binaryExpression.Operand1);
if (binaryExpression.Type == null) binaryExpression.Type = binaryExpression.Operand1.Type; //Hack: need proper inferencing
return binaryExpression;
}
示例7: Exs_OrWithSelf
public void Exs_OrWithSelf()
{
BuildExpressionSimplifier();
var expr = new BinaryExpression(Operator.Or, foo.DataType, foo, foo);
var result = expr.Accept(simplifier);
Assert.AreSame(foo, result);
}
示例8: TestComplexExpression
public void TestComplexExpression()
{
const string VAR_X = "x";
const string VAR_Y = "y";
const string VAR_Z = "z";
var ctx = new Context();
ctx.SetValue(VAR_X, true);
ctx.SetValue(VAR_Y, true);
ctx.SetValue(VAR_Z, false);
var constExp = new ConstExpression(TRUE_TOKEN);
var unaryExp = new UnaryExpression(constExp);
Assert.AreEqual(false, unaryExp.Interpret(ctx));
var binaryExp =
new BinaryExpression(
new BinaryExpression(VAR_X,
BinaryOp.And,
unaryExp),
BinaryOp.Or,
new BinaryExpression(new UnaryExpression(VAR_Y),
BinaryOp.And,
VAR_Z));
Assert.AreEqual(false, binaryExp.Interpret(ctx));
}
示例9: MatchMul
public bool MatchMul(BinaryExpression b)
{
if (b.Operator == Operator.SMul || b.Operator == Operator.UMul || b.Operator == Operator.IMul)
{
Constant c = b.Left as Constant;
Expression e = b.Right;
if (c == null)
{
c = b.Right as Constant;
e = b.Left;
}
if (c != null)
{
elemSize = c;
Index = e;
return true;
}
}
if (b.Operator == Operator.Shl)
{
Constant c = b.Right as Constant;
if (c != null)
{
elemSize = b.Operator.ApplyConstants(Constant.Create(b.Left.DataType, 1), c);
Index = b.Left;
return true;
}
}
return false;
}
示例10: VisitBinaryExpression
public override Expression VisitBinaryExpression(BinaryExpression be) {
be.Operand1 = this.VisitExpression(be.Operand1);
bool hcr = this.hasContextReference;
this.hasContextReference = false;
be.Operand2 = this.VisitExpression(be.Operand2);
this.hasContextReference |= hcr;
return (Expression) this.Compose(be, this.GetComposer(be.Operand1), this.GetComposer(be.Operand2));
}
示例11: EvcBinaryExpression
public void EvcBinaryExpression()
{
Identifier a = new Identifier("a", PrimitiveType.Word32, new TemporaryStorage("a", 1, PrimitiveType.Word32));
BinaryExpression a1 = new BinaryExpression(Operator.IAdd, PrimitiveType.Word32, a, a);
BinaryExpression a2 = new BinaryExpression(Operator.IAdd, PrimitiveType.Word32, a, a);
Assert.IsTrue(eq.Equals(a1, a2));
Assert.AreEqual(eq.GetHashCode(a1), eq.GetHashCode(a2));
}
示例12: ExsConstants
public void ExsConstants()
{
BuildExpressionSimplifier();
Expression expr = new BinaryExpression(Operator.IAdd, PrimitiveType.Word32,
Constant.Word32(1), Constant.Word32(2));
Constant c = (Constant) expr.Accept(simplifier);
Assert.AreEqual(3, c.ToInt32());
}
示例13: EmitBinaryExpression
void EmitBinaryExpression(BinaryExpression expr, MethodInfo method)
{
// Compute the operands
VisitExpression(expr.Left);
VisitExpression(expr.Right);
// Call the operator method
IL.Emit(OpCodes.Call, method);
}
示例14: AddZeroToEffectiveAddress
/// <summary>
/// Extends an effective address ''id'' to ''id'' + 0.
/// </summary>
/// <remarks>
/// The purpose here is to extend the effective address to avoid premature typing of id.
/// If later in the type inference process [[id]] is discovered to be a signed integer, the
/// decompiler can accomodate that by having the added 0 be [[pointer]] or [[member pointer]].
/// This is not possible if all we have is the id.
/// </remarks>
/// <param name="ea"></param>
/// <returns></returns>
private Expression AddZeroToEffectiveAddress(Expression ea)
{
BinaryExpression bin = new BinaryExpression(
Operator.IAdd,
PrimitiveType.CreateWord(ea.DataType.Size),
ea,
Constant.Create(PrimitiveType.CreateWord(ea.DataType.Size), 0));
return bin;
}
示例15: VpAddZero
public void VpAddZero()
{
Identifier r = Reg32("r");
Identifier s = Reg32("s");
var sub = new BinaryExpression(Operator.ISub, PrimitiveType.Word32, new MemoryAccess(MemoryIdentifier.GlobalMemory, r, PrimitiveType.Word32), Constant.Word32(0));
var vp = new ExpressionSimplifier(new SsaEvaluationContext(arch, ssaIds));
var exp = sub.Accept(vp);
Assert.AreEqual("Mem0[r:word32]", exp.ToString());
}