Esempio n. 1
0
        /// <summary>
        /// Performs the arithmetic operation based on the type of the result
        /// </summary>
        /// <param name="context">The context used to perform this operation</param>
        /// <param name="left"></param>
        /// <param name="Operation"></param>
        /// <param name="right"></param>
        /// <returns></returns>
        public override Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, Interpreter.BinaryExpression.OPERATOR Operation, Values.IValue right)  // left +/-/*/div/exp right
        {
            Values.IValue retVal = null;

            Constants.EnumValue enumValue = left as Constants.EnumValue;
            if (enumValue != null)
            {
                left = enumValue.Value;
            }

            enumValue = right as Constants.EnumValue;
            if (enumValue != null)
            {
                right = enumValue.Value;
            }

            Values.IntValue int1 = left as Values.IntValue;
            Values.IntValue int2 = right as Values.IntValue;

            if (int1 == null || int2 == null)
            {
                retVal = EFSSystem.DoubleType.PerformArithmericOperation(context, left, Operation, right);
            }
            else
            {
                retVal = EFSSystem.IntegerType.PerformArithmericOperation(context, left, Operation, right);
            }

            return(retVal);
        }
        /// <summary>
        /// Provides the double value according to the value provided
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double getDoubleValue(Values.IValue value)
        {
            double retVal = 0;

            if (!(value is Values.EmptyValue))
            {
                Constants.EnumValue enumValue = value as Constants.EnumValue;
                if (enumValue != null)
                {
                    value = enumValue.Value;
                }

                Values.IntValue intValue = value as Values.IntValue;
                if (intValue != null)
                {
                    retVal = (double)intValue.Val;
                }
                else
                {
                    Values.DoubleValue doubleValue = value as Values.DoubleValue;

                    if (doubleValue != null)
                    {
                        retVal = doubleValue.Val;
                    }
                    else if (value != null)
                    {
                        throw new Exception("Value " + value.Name + " cannot be converted to double");
                    }
                }
            }

            return(retVal);
        }
Esempio n. 3
0
        /// <summary>
        /// Provides the enum value which corresponds to the name provided
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Constants.EnumValue findEnumValue(string name)
        {
            Constants.EnumValue retVal = null;

            retVal = (Constants.EnumValue)Utils.INamableUtils.findByName(name, SpecialValues);

            return(retVal);
        }
Esempio n. 4
0
        /// <summary>
        /// Provides the enum value which corresponds to the name provided
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Constants.EnumValue findEnumValue(string name)
        {
            Constants.EnumValue retVal = (Constants.EnumValue)Utils.INamableUtils.findByName(name, Values);

            if (retVal != null && EnclosingEnum != null)
            {
                retVal = EnclosingEnum.findEnumValue(name);
            }

            return(retVal);
        }
Esempio n. 5
0
        /// <summary>
        /// Adds a model element in this model element
        /// </summary>
        /// <param name="copy"></param>
        public override void AddModelElement(Utils.IModelElement element)
        {
            {
                Constants.EnumValue item = element as Constants.EnumValue;
                if (item != null)
                {
                    appendSpecialValues(item);
                }
            }

            base.AddModelElement(element);
        }
Esempio n. 6
0
        /// <summary>
        /// Converts a value in this type
        /// </summary>
        /// <param name="value">The value to convert</param>
        /// <returns></returns>
        public Values.IValue convert(Values.IValue value)
        {
            Values.IValue retVal = null;

            Constants.EnumValue enumValue = value as Constants.EnumValue;
            if (enumValue != null && enumValue.Range != null)
            {
                retVal = findEnumValue(enumValue.Name);
                if (retVal == null)
                {
                    Log.Error("Cannot convert " + enumValue.Name + " to " + FullName);
                }
            }
            else
            {
                try
                {
                    switch (getPrecision())
                    {
                    case Generated.acceptor.PrecisionEnum.aIntegerPrecision:
                    {
                        Decimal val = getValueAsInt(value);
                        Decimal min = MinValueAsLong;
                        Decimal max = MaxValueAsLong;
                        if (val >= min && val <= max)
                        {
                            retVal = new Values.IntValue(this, val);
                        }
                    }
                    break;

                    case Generated.acceptor.PrecisionEnum.aDoublePrecision:
                    {
                        double val = getValueAsDouble(value);
                        double min = MinValueAsDouble;
                        double max = MaxValueAsDouble;
                        if (val >= min && val <= max)
                        {
                            retVal = new Values.DoubleValue(this, val);
                        }
                        break;
                    }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Cannot convert range value", exception);
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Provides the double value from the IValue provided
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        private double getValue(Values.IValue val)
        {
            double retVal = 0;

            Constants.EnumValue enumValue = val as Constants.EnumValue;
            if (enumValue != null)
            {
                val = enumValue.Value;
            }

            Values.DoubleValue vd = val as Values.DoubleValue;
            if (vd != null)
            {
                retVal = vd.Val;
            }
            else
            {
                Values.IntValue vi = val as Values.IntValue;
                if (vi != null)
                {
                    retVal = (double)vi.Val;
                }
                else
                {
                    Functions.Function function = val as Functions.Function;
                    if (function != null)
                    {
                        Functions.Graph graph = function.Graph;
                        if (graph != null)
                        {
                            if (graph.Segments.Count == 1)
                            {
                                retVal = graph.Val(0);
                            }
                        }
                    }
                }
            }

            return(retVal);
        }