/// <summary>
        /// Creates the result as a surface
        /// </summary>
        /// <param name="context"></param>
        /// <param name="leftFunction"></param>
        /// <param name="unboundLeft"></param>
        /// <param name="rightFunction"></param>
        /// <param name="unboundRight"></param>
        /// <returns></returns>
        private ICallable createGraphResult(InterpretationContext context, Functions.Function leftFunction, List <Parameter> unboundLeft, Functions.Function rightFunction, List <Parameter> unboundRight)
        {
            ICallable retVal = null;

            Functions.Graph leftGraph = createGraphForUnbound(context, Left, leftFunction, unboundLeft);
            if (leftGraph != null)
            {
                Functions.Graph rightGraph = createGraphForUnbound(context, Right, rightFunction, unboundRight);

                if (rightGraph != null)
                {
                    retVal = combineGraph(leftGraph, rightGraph).Function;
                }
                else
                {
                    AddError("Cannot create graph for " + Right);
                }
            }
            else
            {
                AddError("Cannot create graph for " + Left);
            }

            return(retVal);
        }
Пример #2
0
        public void Push(Functions.Function in_func)
        {
            if (Count >= in_func.ParameterCount)
            {
                List <double> parameters = new List <double>();

                for (int i = in_func.ParameterCount; i > 0; i--)
                {
                    parameters.Add(this[Count - i].Value);
                    RemoveAt(Count - i);
                }

                string expression = in_func.Name + "(";

                for (int i = 0; i < parameters.Count; i++)
                {
                    expression += parameters[i].ToString();
                    if (i != parameters.Count - 1)
                    {
                        expression += ",";
                    }
                }

                expression += ")";

                Push(in_func.Call(parameters), expression);
            }
            else
            {
                throw new Exception("Not enough operand on the stack.  Add at least two numbers in the stack.");
            }
        }
Пример #3
0
        /// <summary>
        /// Provides the states used in an expression
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        public static List <Constants.State> GetStates(Interpreter.Expression expression)
        {
            List <Constants.State> retval = new List <Constants.State>();

            if (expression != null)
            {
                foreach (Values.IValue value in expression.GetLiterals())
                {
                    Constants.State state = value as Constants.State;
                    if (state != null)
                    {
                        retval.Add(state);
                    }
                }

                Interpreter.Call call = expression as Interpreter.Call;
                if (call != null)
                {
                    Functions.Function function = call.Called.getStaticCallable() as Functions.Function;
                    if (function != null)
                    {
                        foreach (Values.IValue value in function.GetLiterals())
                        {
                            Constants.State state = value as Constants.State;
                            if (state != null)
                            {
                                retval.Add(state);
                            }
                        }
                    }
                }
            }

            return(retval);
        }
Пример #4
0
        private static double ResolvePostfix(Queue <object> postFix)
        {
            Stack <double> state = new Stack <double>();

            while (postFix.Count > 0)
            {
                while (postFix.Count > 0 && postFix.Peek() is double)
                {
                    state.Push((double)postFix.Dequeue());
                }

                if (postFix.Count > 0)
                {
                    Functions.Function func = postFix.Dequeue() as Functions.Function;

                    List <double> parameters = new List <double>();
                    for (int i = 0; i < func.ParameterCount; i++)
                    {
                        parameters.Add(state.Pop());
                    }

                    parameters.Reverse();

                    state.Push(func.Call(parameters));
                }
            }

            if (state.Count != 1)
            {
                throw new Exception("Failed to evaluate expression.  No result available");
            }

            return(state.Pop());
        }
Пример #5
0
 public List <Point> FindPath(Point start, Point goal, Functions.Function heuristicCostFunction, Functions.Function moveCostFunction,
                              out uint pathCost, out int nodesOpen, out int nodesClosed)
 {
     this.heuristicFunction = heuristicCostFunction;
     this.moveCostFunction  = moveCostFunction;
     return(base.FindPath(start, goal, out pathCost, out nodesOpen, out nodesClosed));
 }
Пример #6
0
        /// <summary>
        /// Provides the value of the function
        /// </summary>
        /// <param name="instance">the instance on which the function is evaluated</param>
        /// <param name="actuals">the actual parameters values</param>
        /// <param name="localScope">the values of local variables</param>
        /// <returns>The value for the function application</returns>
        public override Values.IValue Evaluate(Interpreter.InterpretationContext context, Dictionary <Variables.Actual, Values.IValue> actuals)
        {
            Values.IValue retVal = null;

            int token = context.LocalScope.PushContext();

            AssignParameters(context, actuals);
            Functions.Function function = context.findOnStack(Function).Value as Functions.Function;
            if (function != null)
            {
                double speed = Functions.Function.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]);
                context.LocalScope.PopContext(token2);
                retVal = new Values.DoubleValue(EFSSystem.DoubleType, graph.SolutionX(speed));
            }
            else
            {
                Log.Error("Cannot get function for " + Function.ToString());
            }
            context.LocalScope.PopContext(token);

            return(retVal);
        }
Пример #7
0
        /// <summary>
        /// Creates a surface for an Ivalue provided
        /// </summary>
        /// <param name="xParam"></param>
        /// <param name="yParam"></param>
        /// <param name="iValue"></param>
        /// <returns></returns>
        public static Surface createSurface(Parameter xParam, Parameter yParam, Values.IValue iValue)
        {
            Surface retVal = null;

            if (retVal == null)
            {
                Functions.Function function = iValue as Function;
                if (function != null)
                {
                    retVal = function.Surface;
                    if (retVal == null)
                    {
                        Graph graph = function.Graph;
                        if (graph != null)
                        {
                            retVal = new Surface(xParam, yParam);
                            Segment segment = new Segment(0, double.MaxValue, graph);
                            retVal.AddSegment(segment);
                        }
                    }
                }
            }

            if (retVal == null)
            {
                retVal = new Surface(xParam, yParam);
                Segment segment = new Segment(0, double.MaxValue, Graph.createGraph(iValue, yParam));
                retVal.AddSegment(segment);
            }

            return(retVal);
        }
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Path3D"/> class.
 /// </summary>
 /// <param name="start">
 /// The start color
 /// </param>
 /// <param name="end">
 /// The end color
 /// </param>
 /// <param name="duration">
 /// The duration of changes
 /// </param>
 /// <param name="delay">
 /// The delay of changes.
 /// </param>
 /// <param name="function">
 /// The animation function.
 /// </param>
 public Path3D(Color start, Color end, float duration, float delay = 0, Functions.Function function = null)
     : this(
         new Path(start.R, end.R, duration, delay, function),
         new Path(start.G, end.G, duration, delay, function),
         new Path(start.B, end.B, duration, delay, function))
 {
 }
Пример #9
0
 /// <summary>
 /// Adds a model element in this model element
 /// </summary>
 /// <param name="copy"></param>
 public override void AddModelElement(Utils.IModelElement element)
 {
     {
         Range item = element as Range;
         if (item != null)
         {
             appendRanges(item);
         }
     }
     {
         Enum item = element as Enum;
         if (item != null)
         {
             appendEnumerations(item);
         }
     }
     {
         Structure item = element as Structure;
         if (item != null)
         {
             appendStructures(item);
         }
     }
     {
         Collection item = element as Collection;
         if (item != null)
         {
             appendCollections(item);
         }
     }
     {
         Functions.Function item = element as Functions.Function;
         if (item != null)
         {
             appendFunctions(item);
         }
     }
     {
         Functions.Procedure item = element as Functions.Procedure;
         if (item != null)
         {
             appendProcedures(item);
         }
     }
     {
         Rules.Rule item = element as Rules.Rule;
         if (item != null)
         {
             appendRules(item);
         }
     }
     {
         Variables.Variable item = element as Variables.Variable;
         if (item != null)
         {
             appendVariables(item);
         }
     }
 }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Path2D"/> class.
 /// </summary>
 /// <param name="startX">
 /// The starting value of X.
 /// </param>
 /// <param name="endX">
 /// The ending value of X.
 /// </param>
 /// <param name="startY">
 /// The starting value of Y.
 /// </param>
 /// <param name="endY">
 /// The ending value of y.
 /// </param>
 /// <param name="duration">
 /// The duration of changes.
 /// </param>
 /// <param name="delay">
 /// The delay of changes.
 /// </param>
 /// <param name="function">
 /// The animation function.
 /// </param>
 // ReSharper disable once UnusedMember.Global
 public Path2D(
     float startX,
     float endX,
     float startY,
     float endY,
     float duration,
     float delay = 0,
     Functions.Function function = null)
     : this(new Path(startX, endX, duration, delay, function), new Path(startY, endY, duration, delay, function))
 {
 }
Пример #11
0
 private static void Add(Hashtable m, OperationPtg ptgKey, Functions.Function instance)
 {
     // make sure ptg has single private constructor because map lookups assume singleton keys
     ConstructorInfo[] cc = ptgKey.GetType().GetConstructors();
     if (cc.Length > 1 || (cc.Length > 0 && !cc[0].IsPrivate))
     {
         throw new Exception("Failed to verify instance ("
                             + ptgKey.GetType().Name + ") is a singleton.");
     }
     m[ptgKey] = instance;
 }
Пример #12
0
        /// <summary>
        ///     Clear the cache of all functions
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="visitSubNodes"></param>
        public override void visit(Function obj, bool visitSubNodes)
        {
            Functions.Function function = obj as Functions.Function;

            if (function != null)
            {
                function.ClearCache();
            }

            base.visit(obj, visitSubNodes);
        }
        public override void visit(Function obj, bool visitSubNodes)
        {
            Functions.Function function = obj as Functions.Function;

            if (function != null)
            {
                function.ExecutionCount       = 0;
                function.ExecutionTimeInMilli = 0L;
            }

            base.visit(obj, visitSubNodes);
        }
Пример #14
0
        /// <summary>
        /// Creates a surface for the value provided expression
        /// </summary>
        /// <param name="iValue"></param>
        /// <param name="xParam"></param>
        /// <param name="yParam"></param>
        /// <returns></returns>
        public static Surface createSurface(Values.IValue namable, Parameter xParam, Parameter yParam)
        {
            Surface retVal = null;

            Functions.Function function = namable as Functions.Function;
            Values.IValue      value    = namable as Values.IValue;
            if (function != null)
            {
                if (function.Surface != null)
                {
                    retVal = function.Surface;
                }
                else if (function.Graph != null)
                {
                    retVal = new Surface(xParam, yParam);

                    // Extend the graph to a Surface
                    if (xParam != null)
                    {
                        foreach (Graph.Segment segment in function.Graph.Segments)
                        {
                            Graph graph = new Graph();
                            graph.addSegment(new Graph.Segment(0, double.MaxValue, segment.Expression));
                            retVal.AddSegment(new Segment(segment.Start, segment.End, graph));
                        }
                    }
                    else if (yParam != null)
                    {
                        retVal.AddSegment(new Segment(0, double.MaxValue, function.Graph));
                    }
                }
                else
                {
                    throw new Exception("Cannot create graph for function");
                }
            }
            else if (value != null)
            {
                if (value != null)
                {
                    retVal = createSurface(Function.getDoubleValue(value), xParam, yParam);
                }
            }
            else
            {
                throw new Exception("Cannot create surface for value " + namable);
            }

            return(retVal);
        }
Пример #15
0
            /// <summary>
            /// Fills the list of functions to be cleared
            /// </summary>
            /// <param name="obj"></param>
            /// <param name="visitSubNodes"></param>
            public override void visit(Generated.Function obj, bool visitSubNodes)
            {
                Functions.Function function = obj as Functions.Function;

                if (function != null)
                {
                    if (function.getCacheable())
                    {
                        CachedFunctions.Add(function);
                    }
                }

                base.visit(obj, visitSubNodes);
            }
Пример #16
0
        /// <summary>
        /// Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Functions.Surface createSurface(Interpreter.InterpretationContext context, Parameter xParam, Parameter yParam)
        {
            Functions.Surface retVal = base.createSurface(context, xParam, yParam);

            Functions.Function function             = getFunction(context);
            Functions.PredefinedFunctions.Cast cast = Called.Ref as Functions.PredefinedFunctions.Cast;
            if (cast != null)
            {
                // In case of cast, just take the surface of the enclosed expression
                Expression actual = (Expression)ActualParameters[0];
                retVal = actual.createSurface(context, xParam, yParam);
            }
            else
            {
                Parameter Xaxis = null;
                Parameter Yaxis = null;

                if (function == null)
                {
                    function = Called.getCalled(context) as Function;
                }

                SelectXandYAxis(context, xParam, yParam, function, out Xaxis, out Yaxis);
                if (Xaxis != null || Yaxis != null)
                {
                    int token = context.LocalScope.PushContext();
                    function.AssignParameters(context, AssignParameterValues(context, function, true));
                    retVal = function.createSurfaceForParameters(context, Xaxis, Yaxis);
                    context.LocalScope.PopContext(token);
                }
                else
                {
                    Values.IValue value = GetValue(context);
                    if (value != null)
                    {
                        retVal = Functions.Surface.createSurface(value, xParam, yParam);
                    }
                    else
                    {
                        throw new Exception("Cannot create surface for expression");
                    }
                }
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
Пример #17
0
        /// <summary>
        /// Provides the type of this expression
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <returns></returns>
        public override Types.Type GetExpressionType()
        {
            Types.Type retVal = null;

            Functions.Function function = Called.getStaticCallable() as Functions.Function;
            if (function != null)
            {
                retVal = function.ReturnType;
            }
            else
            {
                AddError("Cannot get type of function call " + ToString());
            }

            return(retVal);
        }
Пример #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Path2D"/> class.
 /// </summary>
 /// <param name="startX">
 /// The starting value of X.
 /// </param>
 /// <param name="endX">
 /// The ending value of X.
 /// </param>
 /// <param name="startY">
 /// The starting value of Y.
 /// </param>
 /// <param name="endY">
 /// The ending value of y.
 /// </param>
 /// <param name="durationX">
 /// The duration of X changes.
 /// </param>
 /// <param name="durationY">
 /// The duration of Y changes.
 /// </param>
 /// <param name="delayX">
 /// The delay of X changes.
 /// </param>
 /// <param name="delayY">
 /// The delay of Y changes.
 /// </param>
 /// <param name="functionX">
 /// The animation function for X.
 /// </param>
 /// <param name="functionY">
 /// The animation function for Y.
 /// </param>
 public Path2D(
     float startX,
     float endX,
     float startY,
     float endY,
     float durationX,
     float durationY,
     float delayX = 0,
     float delayY = 0,
     Functions.Function functionX = null,
     Functions.Function functionY = null)
     : this(
         new Path(startX, endX, durationX, delayX, functionX),
         new Path(startY, endY, durationY, delayY, functionY))
 {
 }
Пример #19
0
        /// <summary>
        /// Provides the callable that is called by this expression
        /// </summary>
        /// <param name="namable"></param>
        /// <returns></returns>
        public override ICallable getCalled(InterpretationContext context)
        {
            ICallable retVal = null;

            Functions.Function function = InitialValue.Ref as Functions.Function;
            if (function == null)
            {
                function = InitialValue.getCalled(context) as Functions.Function;
            }

            if (function != null)
            {
                if (function.FormalParameters.Count == 1)
                {
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.setGraphParameter((Parameter)function.FormalParameters[0]);
                    Functions.Graph graph = createGraph(context, (Parameter)function.FormalParameters[0]);
                    context.LocalScope.PopContext(token);
                    if (graph != null)
                    {
                        retVal = graph.Function;
                    }
                }
                else if (function.FormalParameters.Count == 2)
                {
                    int token = context.LocalScope.PushContext();
                    context.LocalScope.setSurfaceParameters((Parameter)function.FormalParameters[0], (Parameter)function.FormalParameters[1]);
                    Functions.Surface surface = createSurface(context, (Parameter)function.FormalParameters[0], (Parameter)function.FormalParameters[1]);
                    context.LocalScope.PopContext(token);
                    if (surface != null)
                    {
                        retVal = surface.Function;
                    }
                }
                else
                {
                    AddError("Cannot evaluate REDUCE expression to a function");
                }
            }
            else
            {
                AddError("Cannot evaluate REDUCE expression to a function");
            }

            return(retVal);
        }
Пример #20
0
        /// <summary>
        /// Provides the type of this expression
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <returns></returns>
        public override Types.Type GetExpressionType()
        {
            Functions.Function retVal = (Functions.Function)Generated.acceptor.getFactory().createFunction();
            retVal.Name       = ToString();
            retVal.ReturnType = Expression.GetExpressionType();

            foreach (Parameter parameter in Parameters)
            {
                Parameter param = (Parameter)Generated.acceptor.getFactory().createParameter();
                param.Name = parameter.Name;
                param.Type = parameter.Type;
                retVal.appendParameters(param);
            }
            retVal.Enclosing = Root;

            return(retVal);
        }
Пример #21
0
        /// <summary>
        /// Provides the surface of this function if it has been statically defined
        /// </summary>
        /// <param name="context">the context used to create the surface</param>
        /// <param name="xParam">The X axis of this surface</param>
        /// <param name="yParam">The Y axis of this surface</param>
        /// <returns>The surface which corresponds to this expression</returns>
        public override Functions.Surface createSurface(Interpreter.InterpretationContext context, Parameter xParam, Parameter yParam)
        {
            Functions.Surface retVal = base.createSurface(context, xParam, yParam);

            Functions.Surface surface = InitialValue.createSurface(context, xParam, yParam);
            if (surface != null)
            {
                Values.ListValue value = ListExpression.GetValue(context) as Values.ListValue;
                if (value != null)
                {
                    int token = PrepareIteration(context);
                    AccumulatorVariable.Value = surface.Function;

                    foreach (Values.IValue v in value.Val)
                    {
                        if (v != EFSSystem.EmptyValue)
                        {
                            IteratorVariable.Value = v;
                            if (conditionSatisfied(context))
                            {
                                AccumulatorVariable.Value = IteratorExpression.GetValue(context);
                            }
                        }
                        NextIteration();
                    }
                    Functions.Function function = AccumulatorVariable.Value as Functions.Function;
                    if (function != null)
                    {
                        retVal = function.Surface;
                    }
                    else
                    {
                        throw new Exception("Expression does not reduces to a function");
                    }
                    EndIteration(context, token);
                }
            }
            else
            {
                throw new Exception("Cannot create surface for initial value " + InitialValue.ToString());
            }
            retVal.XParameter = xParam;
            retVal.YParameter = yParam;

            return(retVal);
        }
Пример #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Path"/> class.
        /// </summary>
        /// <param name="start">
        /// The starting value.
        /// </param>
        /// <param name="end">
        /// The ending value.
        /// </param>
        /// <param name="duration">
        /// The duration of changes.
        /// </param>
        /// <param name="delay">
        /// The delay of changes.
        /// </param>
        /// <param name="function">
        /// The animation function.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// Duration is less than zero
        /// </exception>
        public Path(float start, float end, float duration, float delay = 0, Functions.Function function = null)
        {
            this.Start  = start;
            this.End    = end;
            this.Change = this.End - this.Start;
            if (this.Duration < 0)
            {
                throw new ArgumentOutOfRangeException();
            }

            this.Duration = duration;
            this.Function = function;
            this.Delay    = delay;
            if (this.Function == null)
            {
                this.Function = Functions.Liner;
            }
        }
Пример #23
0
        /// <summary>
        /// Creates the graph associated to this expression, when the given parameter ranges over the X axis
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="parameter">The parameters of *the enclosing function* for which the graph should be created</param>
        /// <returns></returns>
        public override Functions.Graph createGraph(InterpretationContext context, Parameter parameter)
        {
            Functions.Graph retVal = base.createGraph(context, parameter);

            Functions.Graph graph = InitialValue.createGraph(context, parameter);
            if (graph != null)
            {
                Values.ListValue value = ListExpression.GetValue(context) as Values.ListValue;
                if (value != null)
                {
                    int token = PrepareIteration(context);
                    AccumulatorVariable.Value = graph.Function;

                    foreach (Values.IValue v in value.Val)
                    {
                        if (v != EFSSystem.EmptyValue)
                        {
                            IteratorVariable.Value = v;
                            if (conditionSatisfied(context))
                            {
                                AccumulatorVariable.Value = IteratorExpression.GetValue(context);
                            }
                        }
                        NextIteration();
                    }
                    Functions.Function function = AccumulatorVariable.Value as Functions.Function;
                    if (function != null)
                    {
                        retVal = function.Graph;
                    }
                    else
                    {
                        retVal = Functions.Function.createGraphForValue(AccumulatorVariable.Value);
                    }
                    EndIteration(context, token);
                }
            }
            else
            {
                throw new Exception("Cannot create graph for initial value " + InitialValue.ToString());
            }

            return(retVal);
        }
        /// <summary>
        /// Indicates that the other type can be placed in variables of this type
        /// </summary>
        /// <param name="otherType"></param>
        /// <returns></returns>
        public override bool Match(Type otherType)
        {
            bool retVal = base.Match(otherType);

            if (!retVal)
            {
                Functions.Function function = otherType as Functions.Function;
                if (function != null && function.ReturnType.IsDouble() && function.FormalParameters.Count == 1)
                {
                    DataDictionary.Parameter parameter = function.FormalParameters[0] as DataDictionary.Parameter;
                    if (parameter != null && parameter.Type.IsDouble())
                    {
                        retVal = true;
                    }
                }
            }

            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);
        }
Пример #26
0
        /// <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);
        }
Пример #27
0
        /// <summary>
        /// Provides the graph associated to the namable
        /// </summary>
        /// <param name="namable"></param>
        /// <returns></returns>
        public static Graph createGraph(Utils.INamable namable, Parameter parameter)
        {
            Graph retVal = null;

            Functions.Function function = namable as Functions.Function;
            if (function != null)
            {
                retVal = function.createGraphForParameter(new Interpreter.InterpretationContext(), parameter);
            }

            if (retVal == null)
            {
                Values.IValue value = namable as Values.IValue;
                if (value != null)
                {
                    retVal = createGraph(Function.getDoubleValue(value), parameter);
                }
            }

            return(retVal);
        }
        /// <summary>
        /// Gets the unbound parameters from the function definition and place holders
        /// </summary>
        /// <param name="context"></param>
        /// <param name="function"></param>
        /// <returns></returns>
        private List <Parameter> getUnboundParameter(InterpretationContext context, Functions.Function function)
        {
            List <Parameter> retVal = new List <Parameter>();

            if (function != null)
            {
                foreach (Parameter formal in function.FormalParameters)
                {
                    Variables.IVariable actual = context.findOnStack(formal);
                    if (actual != null)
                    {
                        Values.PlaceHolder placeHolder = actual.Value as Values.PlaceHolder;
                        if (placeHolder != null)
                        {
                            retVal.Add(formal);
                        }
                    }
                }
            }

            return(retVal);
        }
Пример #29
0
        /// <summary>
        /// Provides the parameters whose value are place holders
        /// </summary>
        /// <param name="function">The function on which the call is performed</param>
        /// <param name="parameterValues">The actual parameter values</param>
        /// <returns></returns>
        private List <Parameter> GetPlaceHolders(Functions.Function function, Dictionary <Variables.Actual, Values.IValue> parameterValues)
        {
            List <Parameter> retVal = new List <Parameter>();

            foreach (KeyValuePair <Variables.Actual, Values.IValue> pair in parameterValues)
            {
                Variables.Actual actual = pair.Key;

                Values.PlaceHolder placeHolder = pair.Value as Values.PlaceHolder;
                if (placeHolder != null && actual.Parameter.Enclosing == function)
                {
                    retVal.Add(actual.Parameter);
                }
            }

            if (retVal.Count != parameterValues.Count || retVal.Count == 0)
            {
                retVal = null;
            }

            return(retVal);
        }
        /// <summary>
        /// Creates the result as a surface
        /// </summary>
        /// <param name="context"></param>
        /// <param name="leftFunction"></param>
        /// <param name="unboundLeft"></param>
        /// <param name="rightFunction"></param>
        /// <param name="unboundRight"></param>
        /// <returns></returns>
        private ICallable createSurfaceResult(InterpretationContext context, Functions.Function leftFunction, List <Parameter> unboundLeft, Functions.Function rightFunction, List <Parameter> unboundRight)
        {
            ICallable retVal = null;

            Functions.Surface leftSurface = createSurfaceForUnbound(context, Left, leftFunction, unboundLeft);
            if (leftSurface != null)
            {
                Functions.Surface rightSurface = createSurfaceForUnbound(context, Right, rightFunction, unboundRight);
                if (rightSurface != null)
                {
                    retVal = combineSurface(leftSurface, rightSurface).Function;
                }
                else
                {
                    AddError("Cannot create surface for " + Right);
                }
            }
            else
            {
                AddError("Cannot create surface for " + Left);
            }

            return(retVal);
        }