Example #1
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData input, bool opOnLeft)
        {
            if (input.IsConstant)
            {
                object i = input.Value;

                if (i is bool)
                {
                    return(new SBExpressionData(!(bool)i));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                if (input.IsValueType)
                {
                    if (input.IsBool)
                    {
                        return(new SBExpressionData(Expression.Not(input.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Example #2
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData input, bool opOnLeft)
        {
            switch (input.ReferencedType)
            {
            case SBExpressionType.Namespace:
                break;

            case SBExpressionType.Constant:
                break;

            case SBExpressionType.Identifier:
                break;

            case SBExpressionType.GlobalVariableReference:
                break;

            case SBExpressionType.Expression:
            case SBExpressionType.LocalVariableReference:
            case SBExpressionType.Indexing:
            case SBExpressionType.PropertyReference:
                if (input.IsValueType)
                {
                    if (input.IsInt)
                    {
                        if (opOnLeft)
                        {
                            return(new SBExpressionData(Expression.PreDecrementAssign(input.ExpressionCode)));
                        }
                        else
                        {
                            return(new SBExpressionData(Expression.PostDecrementAssign(input.ExpressionCode)));
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                break;

            case SBExpressionType.TypeReference:
                break;

            case SBExpressionType.MethodReference:
                break;

            case SBExpressionType.ProcedureReference:
                break;

            case SBExpressionType.DatatableReference:
                break;

            default:
                break;
            }

            throw new NotImplementedException();
        }
Example #3
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData input, bool opOnLeft)
        {
            if (input.IsConstant)
            {
                object i = input.Value;

                if (i is long)
                {
                    return(new SBExpressionData(-(long)i));
                }
                else if (i is double)
                {
                    return(new SBExpressionData(-(double)i));
                }
                else if (i is TimeSpan)
                {
                    return(new SBExpressionData(((TimeSpan)i).Negate()));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                if (input.IsValueType)
                {
                    if (input.IsInt)
                    {
                        return(new SBExpressionData(Expression.Negate(input.ExpressionCode)));
                    }
                    else if (input.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Negate(input.ExpressionCode)));
                    }
                    else if (input.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.Call(input.ExpressionCode, "Negate", new Type[] { })));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
        }
Example #4
0
        internal virtual void ParsePropertyBlock(StepBroListener listener)
        {
            if (m_propertyBlock == null)
            {
                return;
            }
            int i = -1;

            foreach (var entry in m_propertyBlock)
            {
                i++;    // Increment here; first value will be 0.
                if (entry.BlockEntryType == PropertyBlockEntryType.Flag)
                {
                    if (this.ParsePropertyBlockFlag(entry.Name))
                    {
                        // Flag was a known one.
                        entry.IsUsedOrApproved = true;
                        continue;
                    }
                    if (i == 0)
                    {
                        m_baseElementName = entry.Name;
                        if (!this.ParseBaseElement())
                        {
                            throw new ParsingErrorException(entry.Line, m_baseElementName, "Base element unknown.");
                        }
                        entry.IsUsedOrApproved = true;
                    }
                    continue;
                }
                if (entry.BlockEntryType == PropertyBlockEntryType.Value)
                {
                    var    valueProp = entry as PropertyBlockValue;
                    var    typename  = entry.SpecifiedTypeName;
                    object value     = valueProp.Value;

                    if (this.ParsePartnerProperty(listener, entry.Line, typename, entry.Name, value))
                    {
                        entry.IsUsedOrApproved = true;
                        continue;
                    }
                }
            }
        }
Example #5
0
        private bool ParsePartnerProperty(StepBroListener listener, int line, string type, string name, object value)
        {
            System.Diagnostics.Debug.Assert(!String.IsNullOrWhiteSpace(name));
            if (type != null &&
                (type.Equals("partner", StringComparison.InvariantCulture) ||
                 type.Equals("partner new", StringComparison.InvariantCulture) ||
                 type.Equals("partner override", StringComparison.InvariantCulture)))
            {
                string reference = null;
                if (value is string)
                {
                    reference = value as string;
                }
                else if (value is Identifier)
                {
                    reference = ((Identifier)value).Name;
                }
                else
                {
                    throw new ParsingErrorException(line, name, "Value is not a string or an identifier.");
                }

                var element = listener.TryGetFileElementInScope(reference);
                if (element != null)
                {
                    if (element is IFileProcedure)
                    {
                        m_partners.Add(new FileElementPartner(this, name, reference, element as IFileProcedure));
                    }
                    else
                    {
                        throw new ParsingErrorException(line, name, $"Element '{reference}' is not a procedure.");
                    }
                }
                else
                {
                    throw new ParsingErrorException(line, name, $"Element '{reference}' was not found.");
                }

                return(true);
            }
            return(false);
        }
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            switch (first.ReferencedType)
            {
            case SBExpressionType.GlobalVariableReference:
                break;

            case SBExpressionType.LocalVariableReference:
            case SBExpressionType.Indexing:
            case SBExpressionType.PropertyReference:
                return(new SBExpressionData(Expression.AddAssignChecked(first.ExpressionCode, last.ExpressionCode)));

            case SBExpressionType.DatatableReference:
                break;

            default:
                throw new NotImplementedException();
            }
            throw new NotImplementedException();
        }
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is bool && s is bool)
                {
                    return(new SBExpressionData((bool)f || (bool)s));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsBool && last.IsBool)
                    {
                        return(new SBExpressionData(Expression.OrElse(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #8
0
        internal override int ParseSignature(StepBroListener listener, bool reportErrors)
        {
            int unresolvedTypes = 0;

            if (m_returnType == null)
            {
                m_returnType = listener.ParseTypeString(m_returnTypeData.Item1, reportErrors: reportErrors, token: m_returnTypeData.Item2);
                if (m_returnType == null)
                {
                    unresolvedTypes++;
                }
            }

            foreach (var p in m_formalParameters)
            {
                if (p.Type == null)
                {
                    var type = listener.ParseTypeString(p.TypeName, reportErrors: reportErrors, token: p.TypeToken);
                    if (type == null)
                    {
                        unresolvedTypes++;
                        continue;
                    }
                    else
                    {
                        p.SetType(type);
                    }
                }
            }

            if (unresolvedTypes == 0)
            {
                this.CreateDelegateType();
            }

            return(unresolvedTypes);
        }
Example #9
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f / (long)s));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f / (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f / (long)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((long)f / (double)s));
                }
                else if (f is TimeSpan && s is long)
                {
                    return(new SBExpressionData((long)f / (double)s));
                }
                else if (f is TimeSpan && s is double)
                {
                    return(new SBExpressionData((long)f / (double)s));
                }
                else if (f is TimeSpan && s is long)
                {
                    return(new SBExpressionData(((TimeSpan)f).Divide((long)s)));
                }
                else if (f is TimeSpan && s is double)
                {
                    return(new SBExpressionData(((TimeSpan)f).Divide((double)s)));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Divide(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Divide(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Divide(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Divide(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsInt)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Divide", new Type[] { typeof(TimeSpan), typeof(long) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        first.ExpressionCode,
                                                        last.ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsDecimal)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Divide", new Type[] { typeof(TimeSpan), typeof(double) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        first.ExpressionCode,
                                                        last.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f >= (long)s));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData(ExecutionHelperMethods.GreaterThanOrApprox((double)f, (double)s)));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData(ExecutionHelperMethods.GreaterThanOrApprox((double)f, (long)s)));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData(ExecutionHelperMethods.GreaterThanOrApprox((long)f, (double)s)));
                }
                else if (f is TimeSpan && s is TimeSpan)
                {
                    return(new SBExpressionData((TimeSpan)f > (TimeSpan)s));
                }
                else if (f is DateTime && s is DateTime)
                {
                    return(new SBExpressionData((DateTime)f > (DateTime)s));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.GreaterThanOrEqual(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(
                                       typeof(ExecutionHelperMethods).GetMethod("GreaterThanApprox", new Type[] { typeof(double), typeof(double) }),
                                       first.ExpressionCode,
                                       last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(
                                       typeof(ExecutionHelperMethods).GetMethod("GreaterThanApprox", new Type[] { typeof(long), typeof(double) }),
                                       first.ExpressionCode,
                                       last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(
                                       typeof(ExecutionHelperMethods).GetMethod("GreaterThanApprox", new Type[] { typeof(double), typeof(long) }),
                                       first.ExpressionCode,
                                       last.ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.GreaterThan(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsDateTime && last.IsDateTime)
                    {
                        return(new SBExpressionData(Expression.GreaterThan(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #11
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f <= (long)s));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f <= (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f <= (long)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((long)f <= (double)s));
                }
                else if (f is TimeSpan && s is TimeSpan)
                {
                    return(new SBExpressionData((TimeSpan)f <= (TimeSpan)s));
                }
                else if (f is DateTime && s is DateTime)
                {
                    return(new SBExpressionData((DateTime)f <= (DateTime)s));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsDateTime && last.IsDateTime)
                    {
                        return(new SBExpressionData(Expression.LessThanOrEqual(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #12
0
        public static SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, int op1, SBExpressionData middle, int op2, SBExpressionData last)
        {
            if (first.IsValueType && middle.IsValueType && last.IsValueType)
            {
                var f = first.ExpressionCode;
                var l = last.ExpressionCode;
                var m = middle.ExpressionCode;

                if (first.IsInt && middle.IsInt && last.IsInt)
                {
                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.IsBetweenIntegerExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   first.ExpressionCode,
                                   Expression.Constant(OpToLimitType(op1)),
                                   middle.ExpressionCode,
                                   Expression.Constant(OpToLimitType(op2)),
                                   last.ExpressionCode)));
                }
                else if (middle.IsDecimal || middle.IsInt)
                {
                    if (first.IsInt)
                    {
                        f = Expression.Convert(f, typeof(double));
                    }
                    else if (!first.IsDecimal)
                    {
                        throw new NotImplementedException("Error");
                    }
                    if (last.IsInt)
                    {
                        l = Expression.Convert(l, typeof(double));
                    }
                    else if (!last.IsDecimal)
                    {
                        throw new NotImplementedException("Error");
                    }

                    if (middle.IsInt)
                    {
                        m = Expression.Convert(m, typeof(double));
                    }

                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.IsBetweenDecimalExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   f,
                                   Expression.Constant(OpToLimitType(op1)),
                                   m,
                                   Expression.Constant(OpToLimitType(op2)),
                                   l)));
                }
                else if (middle.IsTimespan)
                {
                    if (first.IsDecimal)
                    {
                        f = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            f);
                    }
                    else if (first.IsInt)
                    {
                        f = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            Expression.Convert(f, typeof(double)));
                    }
                    else if (!first.IsTimespan)
                    {
                        throw new NotImplementedException("Error");
                    }
                    if (last.IsDecimal)
                    {
                        l = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            l);
                    }
                    else if (last.IsInt)
                    {
                        l = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            Expression.Convert(l, typeof(double)));
                    }
                    else if (!last.IsTimespan)
                    {
                        throw new NotImplementedException("Error");
                    }

                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.IsBetweenTimespanExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   f,
                                   Expression.Constant(OpToLimitType(op1)),
                                   m,
                                   Expression.Constant(OpToLimitType(op2)),
                                   l)));
                }
                else if (first.IsDateTime && middle.IsDateTime && last.IsDateTime)
                {
                    //return new TSExpressionData(Expression.LessThan(first.ExpressionCode, last.ConvertToDouble().ExpressionCode));
                    throw new NotImplementedException();
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
 public abstract SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last);
Example #14
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f - (long)s));
                }
                else if (f is string && s is string)
                {
                    var fs = (string)f;
                    var ss = (string)s;
                    return(new SBExpressionData(fs.Replace(ss, "")));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f - (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f - (long)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((long)f - (double)s));
                }
                else if (f is TimeSpan && s is TimeSpan)
                {
                    return(new SBExpressionData((TimeSpan)f - (TimeSpan)s));
                }
                else if (f is DateTime && s is TimeSpan)
                {
                    return(new SBExpressionData((DateTime)f - (TimeSpan)s));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsString && last.IsString)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(first.ExpressionCode, typeof(string).GetMethod("Replace", new Type[] { typeof(string), typeof(string) }),
                                                   last.ExpressionCode, Expression.Constant(""))));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Subtract(
                                                        first.ExpressionCode,
                                                        Expression.Call(typeof(TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }), last.ExpressionCode))));
                    }
                    else if (first.IsDateTime && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDateTime && last.IsDateTime)
                    {
                        return(new SBExpressionData(Expression.Subtract(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #15
0
 public abstract SBExpressionData Resolve(StepBroListener listener, SBExpressionData input, bool opOnLeft);
Example #16
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f * (long)s));
                }
                else if (f is string && s is long)
                {
                    var fs     = (string)f;
                    var n      = (long)s;
                    var result = StepBro.Core.Execution.ExecutionHelperMethods.StringMultiply(fs, n);
                    return(new SBExpressionData(result));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f * (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f * (long)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((long)f * (double)s));
                }
                else if (f is TimeSpan && s is long)
                {
                    return(new SBExpressionData(((TimeSpan)f).Multiply((long)s)));
                }
                else if (f is long && s is TimeSpan)
                {
                    return(new SBExpressionData(((TimeSpan)s).Multiply((long)f)));
                }
                else if (f is TimeSpan && s is double)
                {
                    return(new SBExpressionData(((TimeSpan)f).Multiply((double)s)));
                }
                else if (f is double && s is TimeSpan)
                {
                    return(new SBExpressionData(((TimeSpan)s).Multiply((double)f)));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Multiply(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsString && last.IsInt)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(
                                       typeof(StepBro.Core.Execution.ExecutionHelperMethods).GetMethod("StringMultiply", new Type[] { typeof(string), typeof(long) }),
                                       first.ExpressionCode,
                                       last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Multiply(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Multiply(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Multiply(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsInt)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Multiply", new Type[] { typeof(TimeSpan), typeof(long) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        first.ExpressionCode,
                                                        last.ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsDecimal)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Multiply", new Type[] { typeof(TimeSpan), typeof(double) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        first.ExpressionCode,
                                                        last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsTimespan)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Multiply", new Type[] { typeof(TimeSpan), typeof(long) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        last.ExpressionCode,
                                                        first.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsTimespan)
                    {
                        var method = typeof(StepBro.Core.Data.TimeUtils).GetMethod("Multiply", new Type[] { typeof(TimeSpan), typeof(double) });
                        return(new SBExpressionData(Expression.Call(
                                                        method,
                                                        last.ExpressionCode,
                                                        first.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
        public static SBExpressionData Resolve(StepBroListener listener, SBExpressionData value, int op, SBExpressionData expected, SBExpressionData tolerance)
        {
            bool isApprox = (op == SBP.OP_EQ_APPROX);

            if (value.IsValueType && expected.IsValueType && tolerance.IsValueType)
            {
                var v = value.ExpressionCode;
                var e = expected.ExpressionCode;
                var t = tolerance.ExpressionCode;

                if (value.IsInt)
                {
                    if (!expected.IsInt || !tolerance.IsInt)
                    {
                        throw new NotSupportedException("Expected value and tolerance must be integer values too.");
                    }
                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.EqualsWithToleranceIntegerExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   v,
                                   e,
                                   t)));
                }
                else if (value.IsDecimal)
                {
                    if (expected.IsInt)
                    {
                        e = Expression.Convert(e, typeof(double));
                    }
                    else if (!expected.IsDecimal)
                    {
                        throw new ArgumentException("Error");
                    }
                    if (tolerance.IsInt)
                    {
                        t = Expression.Convert(t, typeof(double));
                    }
                    else if (!tolerance.IsDecimal)
                    {
                        throw new ArgumentException("Error");
                    }

                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.EqualsWithToleranceDecimalExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   Expression.Constant(isApprox),
                                   v,
                                   e,
                                   t)));
                }
                else if (value.IsTimespan)
                {
                    if (expected.IsDecimal)
                    {
                        e = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            e);
                    }
                    else if (expected.IsInt)
                    {
                        e = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            Expression.Convert(e, typeof(double)));
                    }
                    else if (!expected.IsTimespan)
                    {
                        throw new ArgumentException("Error");
                    }
                    if (tolerance.IsDecimal)
                    {
                        t = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            t);
                    }
                    else if (tolerance.IsInt)
                    {
                        t = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            Expression.Convert(t, typeof(double)));
                    }
                    else if (!tolerance.IsTimespan)
                    {
                        throw new ArgumentException("Error");
                    }

                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.EqualsWithToleranceTimespanExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   Expression.Constant(isApprox),
                                   v,
                                   e,
                                   t)));
                }
                else if (value.IsDateTime)
                {
                    if (!expected.IsDateTime)
                    {
                        throw new ArgumentException("Error");
                    }
                    if (tolerance.IsDecimal)
                    {
                        t = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            t);
                    }
                    else if (tolerance.IsInt)
                    {
                        t = Expression.Call(
                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                            Expression.Convert(t, typeof(double)));
                    }
                    else if (!tolerance.IsTimespan)
                    {
                        throw new ArgumentException("Error");
                    }

                    var helper = typeof(ExecutionHelperMethods).GetMethod(
                        nameof(ExecutionHelperMethods.EqualsWithToleranceDateTimeExpression));

                    return(new SBExpressionData(
                               Expression.Call(
                                   helper,
                                   Expression.Convert(Expression.Constant(null), typeof(IScriptCallContext)),
                                   Expression.Constant(isApprox),
                                   v,
                                   e,
                                   t)));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Example #18
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f + (long)s));
                }
                else if (f is string && s is string)
                {
                    return(new SBExpressionData((string)f + (string)s));
                }
                else if (f is string && s is long)
                {
                    return(new SBExpressionData((string)f + ((long)s).ToString()));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f + (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f + (long)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((long)f + (double)s));
                }
                else if (f is TimeSpan && s is TimeSpan)
                {
                    return(new SBExpressionData((TimeSpan)f + (TimeSpan)s));
                }
                else if (f is TimeSpan && s is double)
                {
                    return(new SBExpressionData((TimeSpan)f + TimeSpan.FromSeconds((double)s)));
                }
                else if (f is DateTime && s is TimeSpan)
                {
                    return(new SBExpressionData((DateTime)f + (TimeSpan)s));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Add(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsString && last.IsString)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }),
                                                   first.ExpressionCode,
                                                   last.ExpressionCode)));
                    }
                    else if (first.IsString)
                    {
                        Expression lastAsText;
                        if (last.IsString)
                        {
                            lastAsText = last.ExpressionCode;
                        }
                        else if (last.DataType.Type != typeof(object) && typeof(IEnumerable).IsAssignableFrom(last.DataType.Type))
                        {
                            var m = typeof(StringUtils).GetMethod(nameof(StringUtils.ListToString), new Type[] { typeof(IEnumerable) });
                            lastAsText = Expression.Call(m, Expression.Convert(last.ExpressionCode, typeof(IEnumerable)));
                        }
                        else
                        {
                            lastAsText = Expression.Call(
                                typeof(ExecutionHelperMethods).GetMethod(nameof(ExecutionHelperMethods.ObjectToString), new Type[] { typeof(object) }),
                                Expression.Convert(last.ExpressionCode, typeof(object)));
                        }
                        return(new SBExpressionData(
                                   Expression.Call(typeof(string).GetMethod("Concat", new Type[] { typeof(string), typeof(string) }),
                                                   first.ExpressionCode,
                                                   lastAsText)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Add(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Add(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Add(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.Call(
                                                        first.ExpressionCode,
                                                        typeof(System.TimeSpan).GetMethod("Add", new Type[] { typeof(TimeSpan) }),
                                                        last.ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Call(
                                                        first.ExpressionCode,
                                                        typeof(System.TimeSpan).GetMethod("Add", new Type[] { typeof(TimeSpan) }),
                                                        Expression.Call(
                                                            typeof(System.TimeSpan).GetMethod("FromSeconds", new Type[] { typeof(double) }),
                                                            last.ExpressionCode))));
                    }
                    else if (first.IsDateTime && last.IsTimespan)
                    {
                        return(new SBExpressionData(Expression.Call(
                                                        first.ExpressionCode,
                                                        typeof(System.DateTime).GetMethod("Add", new Type[] { typeof(TimeSpan) }),
                                                        last.ExpressionCode)));
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #19
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData((long)f % (long)s));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData((double)f % (double)s));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData((double)(long)f % (double)s));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData((double)f % (double)(long)s));
                }
                else if (f is TimeSpan && s is long)
                {
                    return(new SBExpressionData(TimeSpan.FromTicks(((TimeSpan)f).Ticks % (long)s)));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.IsInt && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Modulo(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Modulo(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(Expression.Modulo(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(Expression.Modulo(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsTimespan && last.IsInt)
                    {
                        return(new SBExpressionData(
                                   Expression.Call(
                                       null,
                                       typeof(TimeSpan).GetMethod("FromTicks", new Type[] { typeof(long) }),
                                       Expression.Modulo(
                                           Expression.Property(first.ExpressionCode, "Ticks"),
                                           last.ExpressionCode))));
                    }
                    //else if (first.IsTimespan && last.IsDecimal)
                    //{
                    //    return new TSExpressionData(
                    //        Expression.Call(
                    //            null,
                    //            typeof(TimeSpan).GetMethod("FromTicks", new Type[] { typeof(long) }),
                    //            Expression.Call(
                    //                typeof(System.Convert).GetMethod("ToInt64", new Type[] { typeof(double) }),
                    //                Expression.Modulo(
                    //                    Expression.Property(first.ExpressionCode, "Ticks"),
                    //                    last.ExpressionCode))));
                    //}
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #20
0
        public override SBExpressionData Resolve(StepBroListener listener, SBExpressionData first, SBExpressionData last)
        {
            if (first.IsConstant && last.IsConstant)
            {
                #region Const
                object f = first.Value;
                object s = last.Value;

                if (f is long && s is long)
                {
                    return(new SBExpressionData(((long)f == (long)s) ^ m_invert));
                }
                else if (f is double && s is double)
                {
                    return(new SBExpressionData(((double)f == (double)s) ^ m_invert));
                }
                else if (f is double && s is long)
                {
                    return(new SBExpressionData(((double)f == (long)s) ^ m_invert));
                }
                else if (f is long && s is double)
                {
                    return(new SBExpressionData(((long)f == (double)s) ^ m_invert));
                }
                else if (f is TimeSpan && s is TimeSpan)
                {
                    return(new SBExpressionData(((TimeSpan)f == (TimeSpan)s) ^ m_invert));
                }
                else if (f is DateTime && s is DateTime)
                {
                    return(new SBExpressionData(((DateTime)f == (DateTime)s) ^ m_invert));
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
            else
            {
                #region Variable
                if (first.IsValueType && last.IsValueType)
                {
                    if (first.DataType.Equals(last.DataType))
                    {
                        return(new SBExpressionData(this.EqualityExpression(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsInt && last.IsDecimal)
                    {
                        return(new SBExpressionData(this.EqualityExpression(first.ConvertToDouble().ExpressionCode, last.ExpressionCode)));
                    }
                    else if (first.IsDecimal && last.IsInt)
                    {
                        return(new SBExpressionData(this.EqualityExpression(first.ExpressionCode, last.ConvertToDouble().ExpressionCode)));
                    }
                    else if (first.IsObject && last.IsObject)
                    {
                        return(new SBExpressionData(this.EqualityExpression(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else if ((first.IsString && last.IsObject && last.IsConstant && last.Value == null && last.DataType.Type == typeof(object)) ||
                             (last.IsString && first.IsObject && first.IsConstant && first.Value == null && first.DataType.Type == typeof(object)))
                    {
                        return(new SBExpressionData(this.EqualityExpression(first.ExpressionCode, last.ExpressionCode)));
                    }
                    else
                    {
                        if (first.DataType.Equals(last.DataType))
                        {
                            throw new NotImplementedException();
                        }
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
                #endregion
            }
        }
Example #21
0
 internal virtual int ParseSignature(StepBroListener listener, bool reportErrors)
 {
     return(0);
 }