本文整理汇总了C#中UnaryExpression类的典型用法代码示例。如果您正苦于以下问题:C# UnaryExpression类的具体用法?C# UnaryExpression怎么用?C# UnaryExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnaryExpression类属于命名空间,在下文中一共展示了UnaryExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:solarplexus6,项目名称:Oop,代码行数:27,代码来源:Zad2Test.cs
示例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;
}
开发者ID:DinrusGroup,项目名称:DinrusIDE,代码行数:29,代码来源:Evaluation.UnaryExpressions.cs
示例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);
}
开发者ID:hmmueller,项目名称:Movimentum,代码行数:7,代码来源:TestConstantFoldingVisitor.cs
示例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;
}
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:13,代码来源:UnaryExpression.cs
示例5: EmitUnaryExpression
void EmitUnaryExpression(UnaryExpression expr, MethodInfo method)
{
// Compute the operands
VisitExpression(expr.Operand);
// Call the operator method
IL.Emit(OpCodes.Call, method);
}
开发者ID:MilesBoulanger,项目名称:game-creator,代码行数:8,代码来源:NaiveDotNetTraverser.cs
示例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;
}
开发者ID:khaliyo,项目名称:fastCSharp,代码行数:13,代码来源:UnaryExpression.cs
示例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;
}
开发者ID:gitter-badger,项目名称:reko,代码行数:10,代码来源:NegSub_Rule.cs
示例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);
}
开发者ID:dbremner,项目名称:specsharp,代码行数:10,代码来源:Normalizer.cs
示例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);
}
开发者ID:stabbylambda,项目名称:mono,代码行数:12,代码来源:LambdaCompiler.Unary.cs
示例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);
}
}
开发者ID:mscottford,项目名称:ironruby,代码行数:14,代码来源:LambdaCompiler.Unary.cs
示例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);
}
}
开发者ID:mscottford,项目名称:ironruby,代码行数:13,代码来源:LambdaCompiler.Unary.cs
示例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);
}
}
}
开发者ID:stabbylambda,项目名称:mono,代码行数:17,代码来源:LambdaCompiler.Unary.cs
示例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);
}
}
开发者ID:stabbylambda,项目名称:mono,代码行数:17,代码来源:LambdaCompiler.Unary.cs
示例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);
}
}
}
开发者ID:mscottford,项目名称:ironruby,代码行数:19,代码来源:LambdaCompiler.Unary.cs
示例15: PostWalk
public virtual void PostWalk(UnaryExpression node) { }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:1,代码来源:PythonWalker.Generated.cs
示例16: Walk
// UnaryExpression
public virtual bool Walk(UnaryExpression node) { return true; }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:2,代码来源:PythonWalker.Generated.cs
示例17: AddressOf
private void AddressOf(UnaryExpression node, Type type)
{
Debug.Assert(node.NodeType == ExpressionType.Unbox);
Debug.Assert(type.GetTypeInfo().IsValueType);
// Unbox leaves a pointer to the boxed value on the stack
EmitExpression(node.Operand);
_ilg.Emit(OpCodes.Unbox, type);
}
开发者ID:alessandromontividiu03,项目名称:corefx,代码行数:9,代码来源:LambdaCompiler.Address.cs
示例18: VisitUnaryExpression
public void VisitUnaryExpression(UnaryExpression unary)
{
throw new NotImplementedException();
}
开发者ID:nemerle,项目名称:reko,代码行数:4,代码来源:AddressTraitCollector.cs
示例19: VisitUnaryExpression
public virtual Expression VisitUnaryExpression(UnaryExpression unaryExpression, UnaryExpression changes, UnaryExpression deletions, UnaryExpression insertions){
this.UpdateSourceContext(unaryExpression, changes);
if (unaryExpression == null) return changes;
if (changes != null){
if (deletions == null || insertions == null)
Debug.Assert(false);
else{
}
}else if (deletions != null)
return null;
return unaryExpression;
}
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:12,代码来源:Updater.cs
示例20: ParseStatement
private bool ParseStatement(Block/*!*/ block) {
//parse instructions and put in expression tree until an assignment, void call, branch target, or branch is encountered
StatementList statementList = block.Statements;
Expression expr = null;
Statement statement = null;
bool transferStatement = false;
int startingAddress = 0;
#if !FxCop
SourceContext sourceContext = new SourceContext();
sourceContext.StartPos = this.counter;
#endif
#if !ROTOR
if (this.method.contextForOffset != null){
object sctx = this.method.contextForOffset[this.counter+1];
if (sctx != null) sourceContext = (SourceContext)sctx;
}
#endif
while (true){
bool isStatement = false;
startingAddress = this.counter+1; //Add one so that it is never zero (the latter means no entry to the TrivialHashtable)
#if FxCop || ILOFFSETS
this.ilOffset = this.counter;
this.opCode = this.GetOpCode();
#else
OpCode opCode = this.GetOpCode();
#endif
#if FxCop
if (this.handlerMap.TryGetValue(this.ilOffset, out expr)){
expr.sourceContext = sourceContext;
expr.ILOffset = this.ilOffset;
this.operandStack.Push(expr);
}
#endif
switch (opCode){
case OpCode.Nop: statement = new Statement(NodeType.Nop); goto done;
case OpCode.Break: statement = new Statement(NodeType.DebugBreak); goto done;
case OpCode.Ldarg_0: expr = this.Parameters(0); break;
case OpCode.Ldarg_1: expr = this.Parameters(1); break;
case OpCode.Ldarg_2: expr = this.Parameters(2); break;
case OpCode.Ldarg_3: expr = this.Parameters(3); break;
case OpCode.Ldloc_0: expr = this.locals[0]; break;
case OpCode.Ldloc_1: expr = this.locals[1]; break;
case OpCode.Ldloc_2: expr = this.locals[2]; break;
case OpCode.Ldloc_3: expr = this.locals[3]; break;
case OpCode.Stloc_0: statement = new AssignmentStatement(this.locals[0], PopOperand()); goto done;
case OpCode.Stloc_1: statement = new AssignmentStatement(this.locals[1], PopOperand()); goto done;
case OpCode.Stloc_2: statement = new AssignmentStatement(this.locals[2], PopOperand()); goto done;
case OpCode.Stloc_3: statement = new AssignmentStatement(this.locals[3], PopOperand()); goto done;
case OpCode.Ldarg_S: expr = this.Parameters(this.GetByte()); break;
case OpCode.Ldarga_S: expr = SetType(new UnaryExpression(this.Parameters(this.GetByte()), NodeType.AddressOf)); break;
case OpCode.Starg_S: statement = new AssignmentStatement(this.Parameters(this.GetByte()), PopOperand()); goto done;
case OpCode.Ldloc_S: expr = this.locals[this.GetByte()]; break;
case OpCode.Ldloca_S: expr = SetType(new UnaryExpression(this.locals[this.GetByte()], NodeType.AddressOf)); break;
case OpCode.Stloc_S: statement = new AssignmentStatement(this.locals[this.GetByte()], PopOperand()); goto done;
case OpCode.Ldnull: expr = new Literal(null, CoreSystemTypes.Object); break;
case OpCode.Ldc_I4_M1: expr = new Literal(-1, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_0: expr = new Literal(0, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_1: expr = new Literal(1, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_2: expr = new Literal(2, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_3: expr = new Literal(3, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_4: expr = new Literal(4, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_5: expr = new Literal(5, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_6: expr = new Literal(6, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_7: expr = new Literal(7, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_8: expr = new Literal(8, CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4_S: expr = new Literal((int)this.GetSByte(), CoreSystemTypes.Int32); break;
case OpCode.Ldc_I4: expr = new Literal(this.GetInt32(), CoreSystemTypes.Int32); break;
case OpCode.Ldc_I8: expr = new Literal(this.GetInt64(), CoreSystemTypes.Int64); break;
case OpCode.Ldc_R4: expr = new Literal(this.GetSingle(), CoreSystemTypes.Single); break;
case OpCode.Ldc_R8: expr = new Literal(this.GetDouble(), CoreSystemTypes.Double); break;
case OpCode.Dup: statement = new ExpressionStatement(new Expression(NodeType.Dup)); goto done;
case OpCode.Pop: statement = new ExpressionStatement(new UnaryExpression(PopOperand(), NodeType.Pop)); goto done;
case OpCode.Jmp: expr = this.ParseCall(NodeType.Jmp, out isStatement); if (isStatement) goto done; break;
case OpCode.Call: expr = this.ParseCall(NodeType.Call, out isStatement); if (isStatement) goto done; break;
case OpCode.Calli: expr = this.ParseCalli(out isStatement); if (isStatement) goto done; break;
case OpCode.Ret:
Expression retVal = BodyParser.TypeIsVoid(this.method.ReturnType) ? null : PopOperand();
statement = new Return(retVal);
transferStatement = true; goto done;
case OpCode.Br_S: statement = this.ParseBranch(NodeType.Nop, 0, true, false); transferStatement = true; goto done;
case OpCode.Brfalse_S: statement = this.ParseBranch(NodeType.LogicalNot, 1, true, false); transferStatement = true; goto done;
case OpCode.Brtrue_S: statement = this.ParseBranch(NodeType.Nop, 1, true, false); transferStatement = true; goto done;
case OpCode.Beq_S: statement = this.ParseBranch(NodeType.Eq, 2, true, false); transferStatement = true; goto done;
case OpCode.Bge_S: statement = this.ParseBranch(NodeType.Ge, 2, true, false); transferStatement = true; goto done;
case OpCode.Bgt_S: statement = this.ParseBranch(NodeType.Gt, 2, true, false); transferStatement = true; goto done;
case OpCode.Ble_S: statement = this.ParseBranch(NodeType.Le, 2, true, false); transferStatement = true; goto done;
case OpCode.Blt_S: statement = this.ParseBranch(NodeType.Lt, 2, true, false); transferStatement = true; goto done;
case OpCode.Bne_Un_S: statement = this.ParseBranch(NodeType.Ne, 2, true, true); transferStatement = true; goto done;
case OpCode.Bge_Un_S: statement = this.ParseBranch(NodeType.Ge, 2, true, true); transferStatement = true; goto done;
case OpCode.Bgt_Un_S: statement = this.ParseBranch(NodeType.Gt, 2, true, true); transferStatement = true; goto done;
case OpCode.Ble_Un_S: statement = this.ParseBranch(NodeType.Le, 2, true, true); transferStatement = true; goto done;
case OpCode.Blt_Un_S: statement = this.ParseBranch(NodeType.Lt, 2, true, true); transferStatement = true; goto done;
case OpCode.Br: statement = this.ParseBranch(NodeType.Nop, 0, false, false); transferStatement = true; goto done;
case OpCode.Brfalse: statement = this.ParseBranch(NodeType.LogicalNot, 1, false, false); transferStatement = true; goto done;
case OpCode.Brtrue: statement = this.ParseBranch(NodeType.Nop, 1, false, false); transferStatement = true; goto done;
case OpCode.Beq: statement = this.ParseBranch(NodeType.Eq, 2, false, false); transferStatement = true; goto done;
case OpCode.Bge: statement = this.ParseBranch(NodeType.Ge, 2, false, false); transferStatement = true; goto done;
case OpCode.Bgt: statement = this.ParseBranch(NodeType.Gt, 2, false, false); transferStatement = true; goto done;
case OpCode.Ble: statement = this.ParseBranch(NodeType.Le, 2, false, false); transferStatement = true; goto done;
case OpCode.Blt: statement = this.ParseBranch(NodeType.Lt, 2, false, false); transferStatement = true; goto done;
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:IL2JS,代码行数:101,代码来源:Reader.cs
注:本文中的UnaryExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论