本文整理汇总了C#中UnaryExpression类的典型用法代码示例。如果您正苦于以下问题:C# UnaryExpression类的具体用法?C# UnaryExpression怎么用?C# UnaryExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryExpression类属于命名空间,在下文中一共展示了UnaryExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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));
}
示例2: E
ISemantic E(UnaryExpression x)
{
if (x is NewExpression)
return E((NewExpression)x);
else if (x is CastExpression)
return E((CastExpression)x);
else if (x is UnaryExpression_Cat)
return E((UnaryExpression_Cat)x);
else if (x is UnaryExpression_Increment)
return E((UnaryExpression_Increment)x);
else if (x is UnaryExpression_Decrement)
return E((UnaryExpression_Decrement)x);
else if (x is UnaryExpression_Add)
return E((UnaryExpression_Add)x);
else if (x is UnaryExpression_Sub)
return E((UnaryExpression_Sub)x);
else if (x is UnaryExpression_Not)
return E((UnaryExpression_Not)x);
else if (x is UnaryExpression_Mul)
return E((UnaryExpression_Mul)x);
else if (x is UnaryExpression_And)
return E((UnaryExpression_And)x);
else if (x is DeleteExpression)
return E((DeleteExpression)x);
else if (x is UnaryExpression_Type)
return E((UnaryExpression_Type)x);
return null;
}
示例3: TestDoFoldConstantInPositiveSquareRoot
public void TestDoFoldConstantInPositiveSquareRoot()
{
AbstractExpr input = new UnaryExpression(Polynomial.CreateConstant(4), new PositiveSquareroot());
IAbstractExpr result = input.Accept(visitor, Ig.nore);
Assert.AreNotEqual(input, result);
Assert.AreEqual(Polynomial.CreateConstant(2), result);
}
示例4: getSimpleIsTrue
/// <summary>
/// 获取简单表达式
/// </summary>
/// <param name="binaryExpression">一元表达式</param>
/// <returns>简单表达式</returns>
private static Expression getSimpleIsTrue(UnaryExpression binaryExpression)
{
if (binaryExpression.Expression.IsConstant)
{
return new logicConstantExpression((bool)((ConstantExpression)binaryExpression.Expression).Value);
}
return binaryExpression;
}
示例5: EmitUnaryExpression
void EmitUnaryExpression(UnaryExpression expr, MethodInfo method)
{
// Compute the operands
VisitExpression(expr.Operand);
// Call the operator method
IL.Emit(OpCodes.Call, method);
}
示例6: getSimpleNot
/// <summary>
/// 获取简单表达式
/// </summary>
/// <param name="binaryExpression">一元表达式</param>
/// <returns>简单表达式</returns>
private static Expression getSimpleNot(UnaryExpression binaryExpression)
{
if (binaryExpression.Expression.IsConstant)
{
return new ConstantExpression(!(bool)((ConstantExpression)binaryExpression.Expression).Value);
}
return binaryExpression;
}
示例7: Match
public bool Match(UnaryExpression unary)
{
if (unary.Operator == Operator.Neg)
{
bin = unary.Expression as BinaryExpression;
if (bin != null && bin.Operator == Operator.ISub)
return true;
}
return false;
}
示例8: VisitRefTypeExpression
public override Expression VisitRefTypeExpression(RefTypeExpression reftypexp) {
if (reftypexp == null) return null;
Expression result = base.VisitRefTypeExpression (reftypexp);
if (result != reftypexp) return result;
UnaryExpression refanytype = new UnaryExpression(reftypexp.Operand, NodeType.Refanytype, SystemTypes.RuntimeTypeHandle, reftypexp.SourceContext);
ExpressionList arguments = new ExpressionList(1);
arguments.Add(refanytype);
MemberBinding mb = new MemberBinding(null, Runtime.GetTypeFromHandle);
return new MethodCall(mb, arguments, NodeType.Call, SystemTypes.Type);
}
示例9: EmitThrow
private void EmitThrow(UnaryExpression expr, CompilationFlags flags) {
if (expr.Operand == null) {
CheckRethrow();
_ilg.Emit(OpCodes.Rethrow);
} else {
EmitExpression(expr.Operand);
_ilg.Emit(OpCodes.Throw);
}
EmitUnreachable(expr, flags);
}
示例10: EmitUnary
//CONFORMING
private void EmitUnary(UnaryExpression node) {
if (node.Method != null) {
EmitUnaryMethod(node);
} else if (node.NodeType == ExpressionType.NegateChecked && TypeUtils.IsInteger(node.Operand.Type)) {
_ilg.EmitInt(0);
_ilg.EmitConvertToType(typeof(int), node.Operand.Type, false);
EmitExpression(node.Operand);
EmitBinaryOperator(ExpressionType.SubtractChecked, node.Operand.Type, node.Operand.Type, node.Type, false);
} else {
EmitExpression(node.Operand);
EmitUnaryOperator(node.NodeType, node.Operand.Type, node.Type);
}
}
示例11: EmitThrow
private void EmitThrow(UnaryExpression expr, EmitAs emitAs) {
if (expr.Operand == null) {
CheckRethrow();
_ilg.Emit(OpCodes.Rethrow);
} else {
EmitExpression(expr.Operand);
_ilg.Emit(OpCodes.Throw);
}
if (emitAs != EmitAs.Void && expr.Type != typeof(void)) {
_ilg.EmitDefault(expr.Type);
}
}
示例12: EmitQuote
private void EmitQuote(UnaryExpression quote) {
// emit the quoted expression as a runtime constant
EmitConstant(quote.Operand, quote.Type);
// Heuristic: only emit the tree rewrite logic if we have hoisted
// locals.
if (_scope.NearestHoistedLocals != null) {
// HoistedLocals is internal so emit as System.Object
EmitConstant(_scope.NearestHoistedLocals, typeof(object));
_scope.EmitGet(_scope.NearestHoistedLocals.SelfVariable);
_ilg.Emit(OpCodes.Call, typeof(RuntimeOps).GetMethod("Quote"));
if (quote.Type != typeof(Expression)) {
_ilg.Emit(OpCodes.Castclass, quote.Type);
}
}
}
示例13: EmitUnary
private void EmitUnary(UnaryExpression node, CompilationFlags flags) {
if (node.Method != null) {
EmitUnaryMethod(node, flags);
} else if (node.NodeType == ExpressionType.NegateChecked && TypeUtils.IsInteger(node.Operand.Type)) {
EmitExpression(node.Operand);
LocalBuilder loc = GetLocal(node.Operand.Type);
_ilg.Emit(OpCodes.Stloc, loc);
_ilg.EmitInt(0);
_ilg.EmitConvertToType(typeof(int), node.Operand.Type, false);
_ilg.Emit(OpCodes.Ldloc, loc);
FreeLocal(loc);
EmitBinaryOperator(ExpressionType.SubtractChecked, node.Operand.Type, node.Operand.Type, node.Type, false);
} else {
EmitExpression(node.Operand);
EmitUnaryOperator(node.NodeType, node.Operand.Type, node.Type);
}
}
示例14: EmitQuote
//CONFORMING
private void EmitQuote(UnaryExpression quote) {
// emit the quoted expression as a runtime constant
EmitConstant(quote.Operand, quote.Type);
// Heuristic: only emit the tree rewrite logic if we have hoisted
// locals. TODO: we could use an even smarter logic here by
// detecting if any nodes actually need to be rewritten
if (_scope.NearestHoistedLocals != null) {
// HoistedLocals is internal so emit as System.Object
EmitConstant(_scope.NearestHoistedLocals, typeof(object));
_scope.EmitGet(_scope.NearestHoistedLocals.SelfVariable);
_ilg.EmitCall(typeof(RuntimeOps).GetMethod("Quote"));
if (quote.Type != typeof(Expression)) {
_ilg.Emit(OpCodes.Castclass, quote.Type);
}
}
}
示例15: PostWalk
public virtual void PostWalk(UnaryExpression node) { }