GetValue() 공개 메소드

Provides the value associated to this Expression
public GetValue ( DataDictionary.Interpreter.InterpretationContext context, ExplanationPart explain ) : IValue
context DataDictionary.Interpreter.InterpretationContext The context on which the value must be found
explain ExplanationPart
리턴 IValue
예제 #1
0
        /// <summary>
        ///     Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <param name="explain">The explanation to fill, if any</param>
        /// <returns></returns>
        protected internal override IValue GetValue(InterpretationContext context, ExplanationPart explain)
        {
            IValue retVal = null;

            if (Term != null)
            {
                retVal = Term.GetValue(context, explain);
            }
            else
            {
                if (Not.Equals(UnaryOp))
                {
                    BoolValue b = Expression.GetValue(context, explain) as BoolValue;
                    if (b != null)
                    {
                        if (b.Val)
                        {
                            retVal = EfsSystem.Instance.BoolType.False;
                        }
                        else
                        {
                            retVal = EfsSystem.Instance.BoolType.True;
                        }
                    }
                    else
                    {
                        AddError("Expression " + Expression + " does not evaluate to boolean", RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else if (Minus.Equals(UnaryOp))
                {
                    IValue   val      = Expression.GetValue(context, explain);
                    IntValue intValue = val as IntValue;
                    if (intValue != null)
                    {
                        retVal = new IntValue(intValue.Type, -intValue.Val);
                    }
                    else
                    {
                        DoubleValue doubleValue = val as DoubleValue;
                        if (doubleValue != null)
                        {
                            retVal = new DoubleValue(doubleValue.Type, -doubleValue.Val);
                        }
                    }

                    if (retVal == null)
                    {
                        AddError("Cannot negate value for " + Expression, RuleChecksEnum.SemanticAnalysisError);
                    }
                }
                else
                {
                    retVal = Expression.GetValue(context, explain);
                }
            }

            return(retVal);
        }
예제 #2
0
        /// <summary>
        /// Provides the value associated to this Expression
        /// </summary>
        /// <param name="context">The context on which the value must be found</param>
        /// <returns></returns>
        public override Values.IValue GetValue(InterpretationContext context)
        {
            Values.IValue retVal = null;

            if (Term != null)
            {
                retVal = Term.GetValue(context);
            }
            else
            {
                if (NOT.CompareTo(UnaryOp) == 0)
                {
                    Values.BoolValue b = Expression.GetValue(context) as Values.BoolValue;
                    if (b != null)
                    {
                        if (b.Val)
                        {
                            retVal = EFSSystem.BoolType.False;
                        }
                        else
                        {
                            retVal = EFSSystem.BoolType.True;
                        }
                    }
                    else
                    {
                        AddError("Expression " + Expression.ToString() + " does not evaluate to boolean");
                    }
                }
                else if (MINUS.CompareTo(UnaryOp) == 0)
                {
                    Values.IValue   val      = Expression.GetValue(context);
                    Values.IntValue intValue = val as Values.IntValue;
                    if (intValue != null)
                    {
                        retVal = new Values.IntValue(intValue.Type, -intValue.Val);
                    }
                    else
                    {
                        Values.DoubleValue doubleValue = val as Values.DoubleValue;
                        if (doubleValue != null)
                        {
                            retVal = new Values.DoubleValue(doubleValue.Type, -doubleValue.Val);
                        }
                    }

                    if (retVal == null)
                    {
                        AddError("Cannot negate value for " + Expression.ToString());
                    }
                }
                else
                {
                    retVal = Expression.GetValue(context);
                }
            }

            return(retVal);
        }