Exemplo n.º 1
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object rhsResult = Rhs.Evaluate(context);
        bool   rhsBool   = TypeCoercer.CoerceToType <bool>(this, rhsResult);

        return(!rhsBool);
    }
Exemplo n.º 2
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object rhsResult = Rhs.Evaluate(context);
        float  rhsFloat  = TypeCoercer.CoerceToType <float>(this, rhsResult);

        return(-rhsFloat);
    }
Exemplo n.º 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);
    }
Exemplo n.º 4
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object rhsResult = Rhs.Evaluate(context);
        int    rhsInt    = TypeCoercer.CoerceToType <int>(this, rhsResult);

        return(~rhsInt);
    }
Exemplo n.º 5
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object lhsResult = Lhs.Evaluate(context);
        object rhsResult = Rhs.Evaluate(context);

        return(lhsResult ?? rhsResult);
    }
Exemplo n.º 6
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object value = Rhs.Evaluate(context);

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

        return(value);
    }
Exemplo n.º 7
0
    protected bool DoEvaluate(UnityELEvaluator context, object lhsResult)
    {
        Type lhsType = lhsResult?.GetType();

        // Otherwise the rhs must identify the type to match
        object rhsResult = Rhs.Evaluate(context);

        if (rhsResult == null)
        {
            return(false);
        }
        string rhsString = TypeCoercer.CoerceToType <string>(this, rhsResult);

        // Special handling for some primitives
        if (rhsString.Equals("int", StringComparison.InvariantCultureIgnoreCase) ||
            rhsString.Equals("integer", StringComparison.InvariantCultureIgnoreCase))
        {
            // Is it an int?
            if (typeof(int).Equals(lhsType))
            {
                return(true);
            }
            else if (typeof(float).Equals(lhsType))
            {
                // We use floats internally, so we allow them to be considered as 'ints' if it would
                // not result in the loss of any data
                float floatValue = (float)lhsResult;
                int   intValue   = (int)floatValue;

                return(intValue == floatValue);
            }
            else
            {
                return(false);
            }
        }
        else if (rhsString.Equals("float", StringComparison.InvariantCultureIgnoreCase))
        {
            // Allow floats or ints?
            return(typeof(float).Equals(lhsType) || typeof(int).Equals(lhsType));
        }
        else if (rhsString.Equals("bool", StringComparison.InvariantCultureIgnoreCase) ||
                 rhsString.Equals("boolean", StringComparison.InvariantCultureIgnoreCase))
        {
            return(typeof(bool).Equals(lhsType));
        }
        else if (lhsType != null)
        {
            // Otherwise we must match the end of the type name
            return(lhsType.FullName.EndsWith(rhsString, StringComparison.InvariantCultureIgnoreCase));
        }
        else
        {
            return(false);
        }
    }
Exemplo n.º 8
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));
    }
Exemplo n.º 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;
        }
Exemplo n.º 10
0
        public decimal RhsTyped(IModel model)
        {
            if (Rhs == null)
            {
                throw ExpressionParseException.MissingExpression("rhs").Decorate(Token);
            }
            var raw = Rhs.Evaluate(model);

            if (raw == null)
            {
                throw ExpressionParseException.UnexpectedNullValue("rhs").Decorate(Token);
            }
            return((decimal)TypeConverter.To(raw, ParameterType));
        }
        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;
        }
Exemplo n.º 12
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);
        }
    }
Exemplo n.º 13
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));
        }
    }
Exemplo n.º 14
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);
        }
    }
Exemplo n.º 15
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);
    }
Exemplo n.º 16
0
    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 (Rhs is ExistsSupport)
        {
            readCurrentValue = ((ExistsSupport)Rhs).Exists(context);
        }
        if (readCurrentValue)
        {
            object current = Rhs.Evaluate(context);
            oldValue = TypeCoercer.CoerceToType <float>(this, current);
        }

        float newValue = oldValue - 1;

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

        return(newValue);
    }
Exemplo n.º 17
0
    public override object Evaluate(UnityELEvaluator context)
    {
        object rhsResult = Rhs.Evaluate(context);

        if (rhsResult is string)
        {
            string s = (string)rhsResult;
            return(s.Length == 0);
        }
        else if (rhsResult is ICollection)
        {
            ICollection collection = (ICollection)rhsResult;
            return(collection.Count == 0);
        }
        else if (rhsResult is IEnumerable)
        {
            IEnumerable enumer = (IEnumerable)rhsResult;
            return(!enumer.GetEnumerator().MoveNext());
        }
        else
        {
            return(rhsResult == null);
        }
    }
Exemplo n.º 18
0
 public IComparable RhsTyped(IModel model)
 {
     return((IComparable)Rhs.Evaluate(model));
 }
 public bool RhsTyped(IModel model)
 {
     return((bool)TypeConverter.To(Rhs.Evaluate(model), ParameterType));
 }
Exemplo n.º 20
0
 public override object InternalEvaluate(IModel model)
 {
     return(model[LhsTyped(model)] = Rhs.Evaluate(model));
 }