public sealed override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var leftNodeValueType = GetNodeValueType(leftNodeValue);

            if (leftNodeValueType == NodeValueType.Boolean)
            {
                // give base a chance to yield a result without evaluating the right node
                var result = this.DetermineResultPreRightEvaluation((bool)leftNodeValue);

                if (result.HasValue)
                {
                    return(result.Value);
                }
            }

            var rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (rightNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var rightNodeValueType = GetNodeValueType(rightNodeValue);

            exceptionHelper.ResolveAndThrowIf(leftNodeValueType != NodeValueType.Boolean || rightNodeValueType != NodeValueType.Boolean, "OperandsNotBoolean", this.OperatorSymbols, leftNodeValueType, rightNodeValueType);

            return(this.DetermineResultPostRightEvaluation((bool)leftNodeValue, (bool)rightNodeValue));
        }
Beispiel #2
0
        public override dynamic Evaluate(SymbolTable table)
        {
            var _value  = (int)((uint)LeftNode.Evaluate(table) >> RightNode.Evaluate(table));
            var _leftId = GetLeftValue();

            table.AddSymbol(_leftId.Name, _value);
            return(_value);
        }
Beispiel #3
0
        public override dynamic Evaluate(SymbolTable table)
        {
            var _value  = RightNode.Evaluate(table);
            var _idLeft = GetLeftValue();

            //table.AddSymbol(_idLeft.Name,_value);
            _idLeft.SetValue(_value, table);
            return(_value);
        }
Beispiel #4
0
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue != null)
            {
                return(leftNodeValue);
            }

            return(RightNode.Evaluate(evaluationContext));
        }
Beispiel #5
0
 private void EvaluateModulo()
 {
     if (typeof(T1) == typeof(int))
     {
         int l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(l % r);
     }
     else if (typeof(T1) == typeof(double))
     {
         double l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(l % r);
     }
 }
Beispiel #6
0
 private void EvaluatePower()
 {
     if (typeof(T1) == typeof(int))
     {
         int l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         int res = (int)Math.Pow(l, r);
         this.Content = (T1)(Object)(res);
     }
     else if (typeof(T1) == typeof(double))
     {
         double l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(Math.Pow(l, r));
     }
 }
Beispiel #7
0
        public override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue = LeftNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (rightNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var leftNodeValueType  = GetNodeValueType(leftNodeValue);
            var rightNodeValueType = GetNodeValueType(rightNodeValue);

            // right operand must always be Int32
            exceptionHelper.ResolveAndThrowIf(!Node.IsNumericalNodeValueType(leftNodeValueType) || rightNodeValueType != NodeValueType.Int32, "NodeValuesNotSupportedTypes", this.OperatorSymbols, leftNodeValueType, rightNodeValueType);

            switch (leftNodeValueType)
            {
            case NodeValueType.Byte:
                return(this.DoByte((byte)leftNodeValue, (int)rightNodeValue));

            case NodeValueType.Int16:
                return(this.DoInt16((short)leftNodeValue, (int)rightNodeValue));

            case NodeValueType.Int32:
                return(this.DoInt32((int)leftNodeValue, (int)rightNodeValue));

            case NodeValueType.Int64:
                return(this.DoInt64((long)leftNodeValue, (int)rightNodeValue));
            }

            Debug.Assert(false);
            return(null);
        }
Beispiel #8
0
 private void EvaluatePlus()
 {
     if (typeof(T1) == typeof(int))
     {
         int l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(l + r);
     }
     else if (typeof(T1) == typeof(double))
     {
         double l = 0, r = 0;
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(l + r);
     }
     else if (typeof(T1) == typeof(string))
     {
         string l = "", r = "";
         LeftNode.Evaluate(out l);
         RightNode.Evaluate(out r);
         this.Content = (T1)(Object)(string.Format("{0}{1}", l, r));
     }
 }
Beispiel #9
0
        public sealed override object Evaluate(NodeEvaluationContext evaluationContext)
        {
            var leftNodeValue  = LeftNode.Evaluate(evaluationContext);
            var rightNodeValue = RightNode.Evaluate(evaluationContext);

            if (leftNodeValue == DependencyProperty.UnsetValue || rightNodeValue == DependencyProperty.UnsetValue)
            {
                return(DependencyProperty.UnsetValue);
            }

            var leftNodeValueType  = GetNodeValueType(leftNodeValue);
            var rightNodeValueType = GetNodeValueType(rightNodeValue);

            // determine the type to which we will need to widen any narrower value
            var maxNodeValueType = (NodeValueType)Math.Max((int)leftNodeValueType, (int)rightNodeValueType);

            // we have to convert rather than just cast because the value is boxed
            var convertibleLeftNodeValue  = leftNodeValue as IConvertible;
            var convertibleRightNodeValue = rightNodeValue as IConvertible;

            Debug.Assert(convertibleLeftNodeValue != null || maxNodeValueType == NodeValueType.String);
            Debug.Assert(convertibleRightNodeValue != null || maxNodeValueType == NodeValueType.String);

            var    succeeded = false;
            object result    = null;

            switch (maxNodeValueType)
            {
            case NodeValueType.String:
                succeeded = this.DoString(convertibleLeftNodeValue == null ? null : convertibleLeftNodeValue.ToString(null), convertibleRightNodeValue == null ? null : convertibleRightNodeValue.ToString(null), out result);
                break;

            case NodeValueType.Boolean:
                succeeded = this.DoBoolean(convertibleLeftNodeValue.ToBoolean(null), convertibleRightNodeValue.ToBoolean(null), out result);
                break;

            case NodeValueType.Byte:
                succeeded = this.DoByte(convertibleLeftNodeValue.ToByte(null), convertibleRightNodeValue.ToByte(null), out result);
                break;

            case NodeValueType.Int16:
                succeeded = this.DoInt16(convertibleLeftNodeValue.ToInt16(null), convertibleRightNodeValue.ToInt16(null), out result);
                break;

            case NodeValueType.Int32:
                succeeded = this.DoInt32(convertibleLeftNodeValue.ToInt32(null), convertibleRightNodeValue.ToInt32(null), out result);
                break;

            case NodeValueType.Int64:
                succeeded = this.DoInt64(convertibleLeftNodeValue.ToInt64(null), convertibleRightNodeValue.ToInt64(null), out result);
                break;

            case NodeValueType.Single:
                succeeded = this.DoSingle(convertibleLeftNodeValue.ToSingle(null), convertibleRightNodeValue.ToSingle(null), out result);
                break;

            case NodeValueType.Double:
                succeeded = this.DoDouble(convertibleLeftNodeValue.ToDouble(null), convertibleRightNodeValue.ToDouble(null), out result);
                break;

            case NodeValueType.Decimal:
                succeeded = this.DoDecimal(convertibleLeftNodeValue.ToDecimal(null), convertibleRightNodeValue.ToDecimal(null), out result);
                break;

            case NodeValueType.ValueType:
                succeeded = this.DoValueType(leftNodeValue, rightNodeValue, out result);
                break;

            case NodeValueType.ReferenceType:
                succeeded = this.DoReferenceType(leftNodeValue, rightNodeValue, out result);
                break;
            }

            exceptionHelper.ResolveAndThrowIf(!succeeded, "OperatorNotSupportedWithOperands", OperatorSymbols, leftNodeValueType, rightNodeValueType);
            return(result);
        }
Beispiel #10
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return(LeftNode.Evaluate(table) > RightNode.Evaluate(table));
 }
Beispiel #11
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return(LeftNode.Evaluate(table) % 2 != 0 || RightNode.Evaluate(table) % 2 != 0
         ? ((float)LeftNode.Evaluate(table) / (float)RightNode.Evaluate(table))
         : LeftNode.Evaluate(table) / RightNode.Evaluate(table));
 }
 public override double Evaluate()
 {
     return(LeftNode.Evaluate() * RightNode.Evaluate());
 }
Beispiel #13
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return((LeftNode.GetType() == RightNode.GetType()) && (LeftNode.Evaluate(table) == RightNode.Evaluate(table)));
 }
Beispiel #14
0
 public override dynamic Evaluate(SymbolTable table)
 {
     return((int)((uint)LeftNode.Evaluate(table) >> RightNode.Evaluate(table)));
 }