/// <summary> /// Public Constructor /// </summary> /// <param name="tt">The Token Type</param> /// <param name="param1">The Parameter</param> public OPCodeUnary(TokenType tt, OPCode param1) { Param1 = param1; EvalType v1Type = Param1.EvalType; switch (tt) { case TokenType.OperatorNot: { if (v1Type == EvalType.Boolean) { mValueDelegate = BOOLEAN_NOT; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorMinus: { if (v1Type == EvalType.Number) { mValueDelegate = NUM_CHGSIGN; mEvalType = EvalType.Number; } break; } } }
/// <summary> /// Swaps the two Parameters /// </summary> /// <param name="param1">New parameter 2</param> /// <param name="param2">New parameter 1</param> protected void SwapParams(ref OPCode param1, ref OPCode param2) { OPCode swp = param1; param1 = param2; param2 = swp; }
/// <summary> /// Public Constructor /// </summary> /// <param name="array">Array to Index</param> /// <param name="params">The Parameter of the Index Operation</param> public OPCodeGetArrayEntry(OPCode array, IList @params) { IEvalTypedValue[] newParams = new IEvalTypedValue[@params.Count]; int[] newValues = new int[@params.Count]; @params.CopyTo(newParams, 0); Array = array; mParams = newParams; mValues = newValues; mResultSystemType = array.SystemType.GetElementType(); mResultEvalType = Globals.GetEvalType(mResultSystemType); }
/// <summary> /// Converts the Specified OPCode to the Specified EvalType /// </summary> /// <param name="tokenizer">The Tokenizer Instance</param> /// <param name="param1">The OPCode to Convert</param> /// <param name="evalType">Target Type</param> protected internal void Convert(Tokenizer tokenizer, ref OPCode param1, EvalType evalType) { if (param1.EvalType != evalType) { if (param1.CanReturn(evalType)) { param1 = new OPCodeConvert(tokenizer, param1, evalType); } else { tokenizer.RaiseError("Cannot convert " + param1.Name + " into " + (int)evalType); } } }
/// <summary> /// Public Constructor /// </summary> /// <param name="tokenizer">The Tokenizer Instance</param> /// <param name="param1">First Parameter</param> /// <param name="tt">The Token Type</param> /// <param name="param2">Second Parameter</param> public OPCodeBinary(Tokenizer tokenizer, OPCode param1, TokenType tt, OPCode param2) { Param1 = param1; Param2 = param2; EvalType v1Type = Param1.EvalType; EvalType v2Type = Param2.EvalType; switch (tt) { case TokenType.OperatorPlus: { if ((v1Type == EvalType.Number) & (v2Type == EvalType.Number)) { mValueDelegate = NUM_PLUS_NUM; mEvalType = EvalType.Number; } else if ((v1Type == EvalType.Number) & (v2Type == EvalType.Date)) { OPCode argParam1 = Param1; OPCode argParam2 = Param2; SwapParams(ref argParam1, ref argParam2); Param1 = argParam1; Param2 = argParam2; mValueDelegate = DATE_PLUS_NUM; mEvalType = EvalType.Date; } else if ((v1Type == EvalType.Date) & (v2Type == EvalType.Number)) { mValueDelegate = DATE_PLUS_NUM; mEvalType = EvalType.Date; } else if (Param1.CanReturn(EvalType.String) & Param2.CanReturn(EvalType.String)) { Convert(tokenizer, ref param1, EvalType.String); mValueDelegate = STR_CONCAT_STR; mEvalType = EvalType.String; } break; } case TokenType.OperatorMinus: { if ((v1Type == EvalType.Number) & (v2Type == EvalType.Number)) { mValueDelegate = NUM_MINUS_NUM; mEvalType = EvalType.Number; } else if ((v1Type == EvalType.Date) & (v2Type == EvalType.Number)) { mValueDelegate = DATE_MINUS_NUM; mEvalType = EvalType.Date; } else if ((v1Type == EvalType.Date) & (v2Type == EvalType.Date)) { mValueDelegate = DATE_MINUS_DATE; mEvalType = EvalType.Number; } break; } case TokenType.OperatorMul: { if ((v1Type == EvalType.Number) & (v2Type == EvalType.Number)) { mValueDelegate = NUM_MUL_NUM; mEvalType = EvalType.Number; } break; } case TokenType.OperatorDiv: { if ((v1Type == EvalType.Number) & (v2Type == EvalType.Number)) { mValueDelegate = NUM_DIV_NUM; mEvalType = EvalType.Number; } break; } case TokenType.OperatorPercent: { if ((v1Type == EvalType.Number) & (v2Type == EvalType.Number)) { mValueDelegate = NUM_PERCENT_NUM; mEvalType = EvalType.Number; } break; } case TokenType.OperatorAnd: case TokenType.OperatorOr: { OPCode argparam1 = Param1; Convert(tokenizer, ref argparam1, EvalType.Boolean); Param1 = argparam1; OPCode argparam11 = Param2; Convert(tokenizer, ref argparam11, EvalType.Boolean); Param2 = argparam11; switch (tt) { case TokenType.OperatorOr: { mValueDelegate = BOOL_OR_BOOL; mEvalType = EvalType.Boolean; break; } case TokenType.OperatorAnd: { mValueDelegate = BOOL_AND_BOOL; mEvalType = EvalType.Boolean; break; } } break; } case TokenType.OperatorNe: { if (v1Type == EvalType.Boolean && v2Type == EvalType.Boolean) { mValueDelegate = BOOL_NE_BOOL; mEvalType = EvalType.Boolean; } else if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_NE_NUM; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorGt: { if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_GT_NUM; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorGe: { if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_GE_NUM; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorEq: { if (v1Type == EvalType.Boolean && v2Type == EvalType.Boolean) { mValueDelegate = BOOL_EQ_BOOL; mEvalType = EvalType.Boolean; } else if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_EQ_NUM; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorLe: { if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_LE_NUM; mEvalType = EvalType.Boolean; } break; } case TokenType.OperatorLt: { if (v1Type == EvalType.Number && v2Type == EvalType.Number) { mValueDelegate = NUM_LT_NUM; mEvalType = EvalType.Boolean; } break; } } if (mValueDelegate is null) { tokenizer.RaiseError( "Cannot apply the operator " + tt.ToString().Replace("operator_", "") + " on " + v1Type + " and " + v2Type ); } }