Пример #1
0
        /// <summary>
        ///     Provides the graph of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the graph</param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = null;

            Graph graph = null;

            Function function = context.FindOnStack(Function).Value as Function;

            if (function != null)
            {
                int       token = context.LocalScope.PushContext();
                Parameter p     = (Parameter)function.FormalParameters[0];
                context.LocalScope.SetGraphParameter(p);
                graph = createGraphForValue(context, function, explain, p);
                context.LocalScope.PopContext(token);
            }

            if (graph != null)
            {
                Function increment = context.FindOnStack(Increment).Value as Function;
                retVal = graph.AddIncrement(context, increment, explain);
            }
            else
            {
                Function.AddError("Cannot create graph for " + Function);
            }

            return(retVal);
        }
Пример #2
0
        /// <summary>
        ///     Provides the graph of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the graph</param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph CreateGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = null;

            Graph graph = createGraphForValue(context, context.FindOnStack(Function).Value, explain, parameter);

            if (graph != null)
            {
                double speed     = GetDoubleValue(context.FindOnStack(Speed).Value);
                double solutionX = graph.SolutionX(speed);
                if (solutionX == double.MaxValue)
                {
                    // No value found, return Unknown
                    Range     distanceType    = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance");
                    EnumValue unknownDistance = distanceType.findEnumValue("Unknown");
                    retVal = Graph.createGraph(distanceType.getValueAsDouble(unknownDistance));
                }
                else
                {
                    // Create the graph for this solution
                    retVal = Graph.createGraph(solutionX);
                }
            }
            else
            {
                Function.AddError("Cannot create graph for " + Function);
            }

            return(retVal);
        }
Пример #3
0
        /// <summary>
        ///     Provides the value of the function
        /// </summary>
        /// <param name="context"></param>
        /// <param name="actuals">the actual parameters values</param>
        /// <param name="explain"></param>
        /// <returns>The value for the function application</returns>
        public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals,
                                        ExplanationPart explain)
        {
            IValue retVal = null;

            int token = context.LocalScope.PushContext();

            AssignParameters(context, actuals);
            Function function = context.FindOnStack(Function).Value as Function;

            if (function != null)
            {
                double speed = GetDoubleValue(context.FindOnStack(Speed).Value);

                Parameter parameter = (Parameter)function.FormalParameters[0];
                int       token2    = context.LocalScope.PushContext();
                context.LocalScope.SetGraphParameter(parameter);
                Graph graph = function.CreateGraph(context, (Parameter)function.FormalParameters[0], explain);
                context.LocalScope.PopContext(token2);
                if (graph != null)
                {
                    double solutionX = graph.SolutionX(speed);
                    if (solutionX == double.MaxValue)
                    {
                        Range distanceType = (Range)EFSSystem.FindByFullName("Default.BaseTypes.Distance");
                        retVal = distanceType.findEnumValue("Unknown");
                    }
                    else
                    {
                        retVal = new DoubleValue(EFSSystem.DoubleType, solutionX);
                    }
                }
                else
                {
                    Function.AddError("Cannot evaluate graph for function while computing the distance for the given speed");
                }
            }
            else
            {
                Function.AddError("Cannot get function for " + Function);
            }
            context.LocalScope.PopContext(token);

            return(retVal);
        }
Пример #4
0
        protected void AddFunctionType(Function function)
        {
            string space = DataModel == SchemaDataModelOption.EntityDataModel ? "Conceptual" : "Storage";

            if (this.SchemaVersion >= XmlConstants.EdmVersionForV2 && this.SchemaManager.SchemaTypes.ContainsKey(function.FQName))
            {
                function.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error,
                    System.Data.Entity.Strings.AmbiguousFunctionAndType(function.FQName, space));
            }
            else
            {
                AddErrorKind error = this.SchemaManager.SchemaTypes.TryAdd(function);
                Debug.Assert(error != AddErrorKind.MissingNameError, "Function identity can never be null while adding global functions");

                if (error != AddErrorKind.Succeeded)
                {
                    function.AddError(ErrorCode.AlreadyDefined, EdmSchemaErrorSeverity.Error,
                        System.Data.Entity.Strings.AmbiguousFunctionOverload(function.FQName, space));
                }
                else
                {
                    this.SchemaTypes.Add(function);
                }
            }
        }