/////////////////////////////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { code = Value.FixupVariants( this, operand1, operand2, null, null, false, false, ref error); if (code == ReturnCode.Ok) { if (operand1.IsDouble()) { value = ((double)operand1.Value >= (double)operand2.Value); } else if (operand1.IsDecimal()) { value = ((decimal)operand1.Value >= (decimal)operand2.Value); } else if (operand1.IsWideInteger()) { value = ((long)operand1.Value >= (long)operand2.Value); } else if (operand1.IsInteger()) { value = ((int)operand1.Value >= (int)operand2.Value); } else if (operand1.IsBoolean()) { value = (ConversionOps.ToInt((bool)operand1.Value) >= ConversionOps.ToInt((bool)operand2.Value)); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } else { // // NOTE: Fine, try to treat the operands as strings. // code = Value.FixupStringVariants( this, operand1, operand2, ref error); if (code == ReturnCode.Ok) { if (operand1.IsString()) { value = (String.Compare( (string)operand1.Value, (string)operand2.Value, StringOps.UserStringComparisonType) >= 0); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { code = Value.FixupVariants( this, operand1, operand2, null, null, false, false, ref error); if (code == ReturnCode.Ok) { if (operand1.IsWideInteger()) { value = ((long)operand1.Value ^ (long)operand2.Value); } else if (operand1.IsInteger()) { value = ((int)operand1.Value ^ (int)operand2.Value); } else if (operand1.IsBoolean()) { value = ((bool)operand1.Value ^ (bool)operand2.Value); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { if (operand1 != null) { if (operand1.ConvertTo(typeof(bool))) { if (operand1.IsBoolean()) { value = LogicOps.Not((bool)operand1.Value); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } else { error = String.Format( "failed to convert operand to type \"{0}\"", typeof(bool)); code = ReturnCode.Error; } } else { error = String.Format( "operand for operator {0} is invalid", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { // // NOTE: Fine, try to treat the operands as strings. // code = Value.FixupStringVariants( this, operand1, operand2, ref error); if (code == ReturnCode.Ok) { if (operand1.IsString()) { string str1 = (string)operand1.Value; string str2 = (string)operand2.Value; value = (str1.StartsWith(str2)); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { if (operand1 != null) { // // BUGBUG: This is not correct. We need to use the smallest type // possible here (this will have to be corrected in // GetVariant). // if (operand1.IsWideInteger()) { value = ~(long)operand1.Value; } else if (operand1.IsInteger()) { value = ~(int)operand1.Value; } else if (operand1.IsBoolean()) { value = ~ConversionOps.ToInt((bool)operand1.Value); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } else { error = String.Format( "operand for operator {0} is invalid", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }
/////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { if (interpreter == null) { error = "invalid interpreter"; return(ReturnCode.Error); } if (arguments == null) { error = "invalid argument list"; return(ReturnCode.Error); } string localName = (arguments.Count > 0) ? (string)arguments[0] : this.Name; if (arguments.Count != (this.Operands + 1)) { if (ExpressionParser.IsOperatorNameOnly(localName)) { error = String.Format(InfixSyntaxError, FormatOps.OperatorName(localName), Characters.Colon); } else { error = String.Format(PrefixSyntaxError, FormatOps.OperatorName(localName)); } return(ReturnCode.Error); } string errorInfo = "{0} (\"if\" expression)"; Result localResult = null; /* REUSED */ if (interpreter.EvaluateExpressionWithErrorInfo( arguments[1], errorInfo, ref localResult) != ReturnCode.Ok) { error = localResult; return(ReturnCode.Error); } bool boolValue = false; if (Engine.ToBoolean( localResult, interpreter.CultureInfo, ref boolValue, ref localResult) != ReturnCode.Ok) { error = localResult; return(ReturnCode.Error); } if (boolValue) { errorInfo = "{0} (\"then\" expression)"; localResult = null; if (interpreter.EvaluateExpressionWithErrorInfo( arguments[2], errorInfo, ref localResult) == ReturnCode.Ok) { value = localResult; return(ReturnCode.Ok); } else { error = localResult; return(ReturnCode.Error); } } else { errorInfo = "{0} (\"else\" expression)"; localResult = null; if (interpreter.EvaluateExpressionWithErrorInfo( arguments[3], errorInfo, ref localResult) == ReturnCode.Ok) { value = localResult; return(ReturnCode.Ok); } else { error = localResult; return(ReturnCode.Error); } } }
/////////////////////////////////////////////////////////////////////////////////////////////// #region IExecuteArgument Members public override ReturnCode Execute( Interpreter interpreter, IClientData clientData, ArgumentList arguments, ref Argument value, ref Result error ) { ReturnCode code = ReturnCode.Ok; if (interpreter != null) { if (arguments != null) { try { string name = null; Variant operand1 = null; Variant operand2 = null; code = Value.GetOperandsFromArguments(interpreter, this, arguments, ValueFlags.AnyVariant, interpreter.CultureInfo, ref name, ref operand1, ref operand2, ref error); if (code == ReturnCode.Ok) { if (arguments.Count == 3) { code = Value.FixupVariants( this, operand1, operand2, null, null, false, false, ref error); if (code == ReturnCode.Ok) { if (operand1.IsDouble()) { value = Interpreter.FixIntermediatePrecision( (double)operand1.Value + (double)operand2.Value); } else if (operand1.IsDecimal()) { value = Interpreter.FixIntermediatePrecision( (decimal)operand1.Value + (decimal)operand2.Value); } else if (operand1.IsWideInteger()) { value = ((long)operand1.Value + (long)operand2.Value); } else if (operand1.IsInteger()) { value = ((int)operand1.Value + (int)operand2.Value); } else if (operand1.IsBoolean()) { value = (ConversionOps.ToInt((bool)operand1.Value) + ConversionOps.ToInt((bool)operand2.Value)); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } } else if (arguments.Count == 2) { if (operand1.IsDouble()) { value = Interpreter.FixIntermediatePrecision( +(double)operand1.Value); } else if (operand1.IsDecimal()) { value = Interpreter.FixIntermediatePrecision( +(decimal)operand1.Value); } else if (operand1.IsWideInteger()) { value = (+(long)operand1.Value); } else if (operand1.IsInteger()) { value = (+(int)operand1.Value); } else if (operand1.IsBoolean()) { value = (+ConversionOps.ToInt((bool)operand1.Value)); } else { error = String.Format( "unsupported operand type for operator {0}", FormatOps.OperatorName(name, this.Lexeme)); code = ReturnCode.Error; } } else { error = String.Format( "wrong # args: should be \"{0} operand\" or \"{1}\"", name, String.Format(ExpressionParser.IsOperatorNameOnly( name) ? "operand1 {0} operand2" : "{0} operand1 operand2", name)); code = ReturnCode.Error; } } } catch (Exception e) { Engine.SetExceptionErrorCode(interpreter, e); error = String.Format( "caught math exception: {0}", e); code = ReturnCode.Error; } } else { error = "invalid argument list"; code = ReturnCode.Error; } } else { error = "invalid interpreter"; code = ReturnCode.Error; } return(code); }