Beispiel #1
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        return(lhsResult ?? rhsResult);
    }
Beispiel #2
0
    protected override object OnEvaluate(Context context)
    {
        object lhs = Lhs.Evaluate(context);
        object rhs = Rhs.Evaluate(context);

        return(!lhs.Equals(rhs));
    }
Beispiel #3
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object amount      = Rhs.Evaluate(context);
        float  floatAmount = TypeCoercer.CoerceToType <float>(this, amount);

        float floatCurrent = 0;

        // If the value doesn't already exists (and we can detect that) we start with zero.
        bool readCurrentValue = true;

        if (Lhs is ExistsSupport)
        {
            readCurrentValue = ((ExistsSupport)Lhs).Exists(context);
        }
        if (readCurrentValue)
        {
            object current = Lhs.Evaluate(context);
            floatCurrent = TypeCoercer.CoerceToType <float>(this, current);
        }

        float result = floatCurrent + floatAmount;

        ((AssignableToken)Lhs).Assign(context, result);

        return(result);
    }
Beispiel #4
0
 public string LhsTyped(IModel model)
 {
     if (!(Lhs is Constant) && (model.Get(Lhs.AsParsable())?.Full ?? false))
     {
         return(Lhs.AsParsable());
     }
     return((string)TypeConverter.To(Lhs.Evaluate(model), typeof(string)));
 }
Beispiel #5
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        int lhsInt = TypeCoercer.CoerceToType <int>(this, lhsResult);
        int rhsInt = TypeCoercer.CoerceToType <int>(this, rhsResult);

        return(lhsInt % rhsInt);
    }
Beispiel #6
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult);
        float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult);

        return(FastExponent(lhsFloat, rhsFloat));
    }
Beispiel #7
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        bool lhsBool = TypeCoercer.CoerceToType <bool>(this, lhsResult);
        bool rhsBool = TypeCoercer.CoerceToType <bool>(this, rhsResult);

        return(lhsBool && rhsBool);
    }
        public decimal LhsTyped(IModel model)
        {
            if (Lhs == null)
            {
                throw ExpressionParseException.MissingExpression("lhs").Decorate(Token);
            }
            var raw = Lhs.Evaluate(model);

            if (raw == null)
            {
                throw ExpressionParseException.UnexpectedNullValue("lhs").Decorate(Token);
            }
            return((decimal)TypeConverter.To(raw, ParameterType));
        }
Beispiel #9
0
        public override object Evaluate(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            var left = (bool[]) Lhs.Evaluate(eventsPerStream, isNewData, context);
            var right = (bool[]) Rhs.Evaluate(eventsPerStream, isNewData, context);

            if (left == null || right == null) { // null comparison
                return null;
            }

            return Arrays.AreEqual(left, right) ^ parent.IsNotEquals;
        }
Beispiel #10
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);

        if (Rhs is NullToken)
        {
            // Special case...
            if (lhsResult == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }

        return(DoEvaluate(context, lhsResult));
    }
        public override object Evaluate(
            EventBean[] eventsPerStream,
            bool isNewData,
            ExprEvaluatorContext context)
        {
            var left = (int[]) Lhs.Evaluate(eventsPerStream, isNewData, context);
            var right = (int[]) Rhs.Evaluate(eventsPerStream, isNewData, context);

            bool result;
            if (left == null) {
                result = right == null;
            }
            else {
                result = right != null && Arrays.AreEqual(left, right);
            }

            result = result ^ parent.IsNotEquals;

            return result;
        }
Beispiel #12
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);

        if (Rhs is NullToken)
        {
            // Special case...
            if (lhsResult != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }

        // Otherwise, just invert the result of the base class
        return(!DoEvaluate(context, lhsResult));
    }
Beispiel #13
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        if (lhsResult is float || lhsResult is int)
        {
            float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult);
            float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult);

            return(lhsFloat == rhsFloat);
        }
        else if (lhsResult != null)
        {
            return(lhsResult.Equals(rhsResult));
        }
        else
        {
            return(rhsResult == null);
        }
    }
Beispiel #14
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        string rhsTypeName = TypeCoercer.CoerceToType <string>(this, rhsResult);

        if (rhsTypeName == null)
        {
            throw new ParserException("Right-hand side of 'as' evaluated to null");
        }

        if ("int".Equals(rhsTypeName))
        {
            return(TypeCoercer.CoerceToType <int>(this, lhsResult));
        }
        else if ("float".Equals(rhsTypeName))
        {
            return(TypeCoercer.CoerceToType <float>(this, lhsResult));
        }
        else if ("string".Equals(rhsTypeName))
        {
            return(TypeCoercer.CoerceToType <string>(this, lhsResult));
        }
        else if ("bool".Equals(rhsTypeName))
        {
            return(TypeCoercer.CoerceToType <bool>(this, lhsResult));
        }
        else
        {
            Type type = Type.GetType(rhsTypeName);
            if (type == null)
            {
                throw new ParserException($"Could not resolve type from string: {rhsTypeName}");
            }

            return(TypeCoercer.CoerceToType(type, this, lhsResult));
        }
    }
Beispiel #15
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        if (lhsResult.GetType() == typeof(string))
        {
            // String addition
            string lhsString = TypeCoercer.CoerceToType <string>(this, lhsResult);
            string rhsString = TypeCoercer.CoerceToType <string>(this, rhsResult);

            return(lhsString + rhsString);
        }
        else
        {
            // Mathmatic addition
            float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult);
            float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult);

            return(lhsFloat + rhsFloat);
        }
    }
Beispiel #16
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        // See if the lhs supports an operator overload for the rhs
        if (lhsResult != null)
        {
            OperatorInfo info = FindOperator(lhsResult.GetType(), "op_Multiply", rhsResult);
            if (info != null)
            {
                object coercedRhs = TypeCoercer.CoerceToType(info.OperandType, this, rhsResult);
                return(info.Method.Invoke(null, new object[] { lhsResult, coercedRhs }));
            }
        }

        // Otherwise just use a float multiplication
        float lhsFloat = TypeCoercer.CoerceToType <float>(this, lhsResult);
        float rhsFloat = TypeCoercer.CoerceToType <float>(this, rhsResult);

        return(lhsFloat * rhsFloat);
    }
    public override object Evaluate(UnityELEvaluator context)
    {
        float oldValue = 0;

        // If the value doesn't already exists (and we can detect that) we start with zero.
        bool readCurrentValue = true;

        if (Lhs is ExistsSupport)
        {
            readCurrentValue = ((ExistsSupport)Lhs).Exists(context);
        }
        if (readCurrentValue)
        {
            object current = Lhs.Evaluate(context);
            oldValue = TypeCoercer.CoerceToType <float>(this, current);
        }

        float newValue = oldValue + 1;

        ((AssignableToken)Lhs).Assign(context, newValue);

        return(oldValue);
    }
Beispiel #18
0
 public override decimal?Evaluate() => Lhs.Evaluate() *Rhs.Evaluate();
Beispiel #19
0
 public IComparable LhsTyped(IModel model)
 {
     return((IComparable)Lhs.Evaluate(model));
 }
 public bool LhsTyped(IModel model)
 {
     return((bool)TypeConverter.To(Lhs.Evaluate(model), ParameterType));
 }