/// <summary>
        /// Creates the graph of the function on which the increment function has been added
        /// </summary>
        /// <param name="context">the context used to evaluate the function</param>
        /// <param name="increment">The increment function do add</param>
        /// <returns></returns>
        public Graph AddIncrement(Interpreter.InterpretationContext context, Functions.Function increment)
        {
            Graph retVal = new Graph();

            if (IsFlat() && increment.FormalParameters.Count == 1)
            {
                Parameter parameter = (Parameter)increment.FormalParameters[0];
                foreach (Segment segment in Segments)
                {
                    Dictionary <Variables.Actual, Values.IValue> actuals = new Dictionary <Variables.Actual, Values.IValue>();
                    Variables.Actual actual = parameter.createActual();
                    actuals[actual] = new Values.DoubleValue(increment.EFSSystem.DoubleType, segment.Expression.v0);
                    Values.IValue result     = increment.Evaluate(context, actuals);
                    Segment       newSegment = new Segment(segment);
                    newSegment.Expression.v0 = segment.Expression.v0 + Function.getDoubleValue(result);
                    retVal.addSegment(newSegment);
                }
            }

            return(retVal);
        }
Example #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;
            ExplanationPart previous = SetupExplanation();

            Functions.Function function = getFunction(context);
            if (function != null)
            {
                long start = System.Environment.TickCount;

                Dictionary <Variables.Actual, Values.IValue> parameterValues = AssignParameterValues(context, function, true);
                List <Parameter> parameters = GetPlaceHolders(function, parameterValues);
                if (parameters == null)
                {
                    retVal = function.Evaluate(context, parameterValues);
                    if (retVal == null)
                    {
                        AddError("Call " + function.Name + " ( " + ParameterValues(parameterValues) + " ) returned nothing");
                    }
                }
                else if (parameters.Count == 1) // graph
                {
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.setGraphParameter(parameters[0]);
                    Functions.Graph graph = function.createGraphForParameter(context, parameters[0]);
                    context.LocalScope.PopContext(token);
                    if (graph != null)
                    {
                        retVal = graph.Function;
                    }
                    else
                    {
                        AddError("Cannot create graph on Call " + function.Name + " ( " + ParameterValues(parameterValues) + " )");
                    }
                }
                else // surface
                {
                    Functions.Surface surface = function.createSurfaceForParameters(context, parameters[0], parameters[1]);
                    if (surface != null)
                    {
                        retVal = surface.Function;
                    }
                    else
                    {
                        AddError("Cannot create surface on Call " + function.Name + " ( " + ParameterValues(parameterValues) + " )");
                    }
                }

                long stop = System.Environment.TickCount;
                long span = (stop - start);
                function.ExecutionTimeInMilli += span;
                function.ExecutionCount       += 1;

                if (explain)
                {
                    CompleteExplanation(previous, function.Name + " ( " + ParameterValues(parameterValues) + " ) returned " + explainNamable(retVal) + "\n");
                }
            }
            else
            {
                AddError("Cannot find function " + ToString());
            }

            return(retVal);
        }