public void ExpressionCalculatorUnary() { var ast = new AstUnary("-", new AstConstant(1)); var f = MakeFunc <Func <object> >(ast); Assert.AreEqual(-1, f()); }
public Expression CompileUnOp(AstUnary uo) { var operand = CompileExpression(uo.Operand); if (operand.IsInvalid) { return(Expression.Invalid); } switch (uo.Type) { case AstUnaryType.IncreasePrefix: case AstUnaryType.DecreasePrefix: case AstUnaryType.IncreasePostfix: case AstUnaryType.DecreasePostfix: return(!operand.ReturnType.IsIntegralType && !operand.ReturnType.IsFloatingPointType ? Error(uo.Source, ErrorCode.E2063, "Incremental operators can only be used on integers") : new FixOp(uo.Source, (FixOpType)uo.Type, operand)); } var args = new[] { operand }; var opOp = uo.Type.ToSymbol(); var op = TryResolveOperatorOverload(uo.Source, NameResolver.GetTypeOperators(operand.ReturnType, opOp), args); return(op != null ? new CallUnOp(uo.Source, op, args[0]) : Error(uo.Source, ErrorCode.E2065, operand.ReturnType.Quote() + " has no operators matching the argument list")); }
public Expression Visit(AstUnary unary) { switch (unary.Name) { case "-": case "!": return(Expression.Call(typeof(Functions).GetMethod("Negate", BindingFlags.Static | BindingFlags.Public), unary.Operand.Accept(this))); default: throw new NotSupportedException(string.Format("Operator {0} is not supported", unary.Name)); } }
public object Visit(AstUnary unary) { switch (unary.Name) { case "-": return(-Convert.ToDecimal(unary.Operand.Accept(this))); case "!": return(!(bool)unary.Operand.Accept(this)); default: throw new NotSupportedException(string.Format("Unary operator is not supported: {0}", unary.Name)); } }
public string Visit(AstUnary unary) { return(string.Format("{0} {1}", unary.Name, unary.Operand.Accept(this))); }
public void WriteUnary(AstUnary a) { Write(a.Source); Write(a.Operand); }
public T Visit(AstUnary unary) { throw new System.NotImplementedException(); }