当前位置: 首页>>代码示例>>C#>>正文


C# InterpretationContext.findOnStack方法代码示例

本文整理汇总了C#中DataDictionary.Interpreter.InterpretationContext.findOnStack方法的典型用法代码示例。如果您正苦于以下问题:C# InterpretationContext.findOnStack方法的具体用法?C# InterpretationContext.findOnStack怎么用?C# InterpretationContext.findOnStack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataDictionary.Interpreter.InterpretationContext的用法示例。


在下文中一共展示了InterpretationContext.findOnStack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Evaluate

        /// <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 = EFSSystem.BoolType.False;

            int token = context.LocalScope.PushContext();
            AssignParameters(context, actuals);

            ListValue collection = context.findOnStack(Collection).Value as ListValue;
            if (collection != null)
            {
                IValue expectedFirst = context.findOnStack(ExpectedFirst).Value;
                if (expectedFirst != null)
                {
                    int firstIndex = collection.Val.IndexOf(expectedFirst);
                    if (firstIndex >= 0)
                    {
                        IValue expectedSecond = context.findOnStack(ExpectedSecond).Value;
                        if (expectedSecond != null)
                        {
                            int secondIndex = collection.Val.IndexOf(expectedSecond);

                            if (secondIndex >= 0)
                            {
                                if (firstIndex < secondIndex)
                                {
                                    retVal = EFSSystem.BoolType.True;
                                }
                            }
                            else
                            {
                                Collection.AddError("Cannot find " + expectedSecond.FullName + " in " +
                                                    collection.ToString() + " to evaluate " + Name);
                            }
                        }
                        else
                        {
                            Collection.AddError("Cannot evaluate second element to evaluate " + Name);
                        }
                    }
                    else
                    {
                        Collection.AddError("Cannot find " + expectedFirst.FullName + " in " + collection.ToString() +
                                            " to evaluate " + Name);
                    }
                }
                else
                {
                    Collection.AddError("Cannot evaluate first element to evaluate " + Name);
                }
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:62,代码来源:Before.cs

示例2: createGraph

        /// <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>
        /// <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
            {
                Log.Error("Cannot create graph for " + Function.ToString());
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:34,代码来源:DistanceForSpeed.cs

示例3: createSurface

        /// <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="explain"></param>
        /// <returns></returns>
        public override Surface createSurface(InterpretationContext context, ExplanationPart explain)
        {
            Surface retVal = null;

            Surface defaultSurface = createSurfaceForValue(context, context.findOnStack(DefaultFunction).Value, explain);
            if (defaultSurface != null)
            {
                Surface overrideSurface = createSurfaceForValue(context, context.findOnStack(OverrideFunction).Value,
                    explain);
                if (overrideSurface != null)
                {
                    retVal = defaultSurface.Override(overrideSurface);
                }
                else
                {
                    Log.Error("Cannot create graph for OVERRIDE argument");
                }
            }
            else
            {
                Log.Error("Cannot create graph for DEFAULT argument");
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:31,代码来源:Override.cs

示例4: createGraph

        /// <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;

            IValue firstValue = context.findOnStack(First).Value;
            IValue secondValue = context.findOnStack(Second).Value;

            Graph firstGraph = createGraphForValue(context, firstValue, explain, parameter);
            if (firstGraph != null)
            {
                Graph secondGraph = createGraphForValue(context, secondValue, explain, parameter);
                if (secondGraph != null)
                {
                    retVal = firstGraph.Max(secondGraph) as Graph;
                }
                else
                {
                    Log.Error("Cannot create graph for " + Second.ToString());
                }
            }
            else
            {
                Log.Error("Cannot create graph for " + First.ToString());
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:34,代码来源:Max.cs

示例5: ExpressionBasedOnPlaceHolder

        /// <summary>
        ///     Indicates whether the expression is based on a placeholder value, ommiting the parameter provided
        /// </summary>
        /// <param name="context">The current interpretation context</param>
        /// <param name="expression">The expression to evaluate</param>
        /// <returns></returns>
        private bool ExpressionBasedOnPlaceHolder(InterpretationContext context, BinaryExpression expression)
        {
            bool retVal = false;

            if (expression != null)
            {
                foreach (ITypedElement element in expression.GetRightSides())
                {
                    Parameter parameter = element as Parameter;
                    if (parameter != null)
                    {
                        IVariable variable = context.findOnStack(parameter);
                        if (variable != null)
                        {
                            PlaceHolder placeHolder = variable.Value as PlaceHolder;

                            if (placeHolder != null)
                            {
                                retVal = true;
                                break;
                            }
                        }
                    }
                }
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:34,代码来源:Function.cs

示例6: Evaluate

        /// <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);

            StructureValue startDate = context.findOnStack(StartDate).Value as StructureValue;
            if (startDate != null)
            {
                int year = GetIntValue(startDate, "Year");
                int month = GetIntValue(startDate, "Month");
                int day = GetIntValue(startDate, "Day");
                int hour = GetIntValue(startDate, "Hour");
                int minute = GetIntValue(startDate, "Minute");
                int second = GetIntValue(startDate, "Second");
                int tts = GetIntValue(startDate, "TTS");

                DoubleValue addedTime = context.findOnStack(Increment).Value as DoubleValue;
                if (addedTime != null)
                {
                    DateTime start = new DateTime(year, month, day, hour, minute, second, tts);
                    DateTime currentTime = start.AddSeconds((double) addedTime.Val);

                    retVal = GetEFSDate(currentTime, startDate.Type as Structure);
                }
            }

            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:40,代码来源:AddToDate.cs

示例7: createGraph

        /// <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;

            IVariable variable = context.findOnStack(Value);

            if (variable != null)
            {
                retVal = Graph.createGraph(getDoubleValue(variable.Value), parameter);
            }
            else
            {
                AddError("Cannot find variable " + Value + " on the stack");
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:24,代码来源:Cast.cs

示例8: Evaluate

        /// <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);
            BoolValue val = context.findOnStack(Value).Value as BoolValue;
            if (val != null)
            {
                if (val.Val)
                {
                    retVal = EFSSystem.BoolType.False;
                }
                else
                {
                    retVal = EFSSystem.BoolType.True;
                }
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:30,代码来源:Not.cs

示例9: Evaluate

        /// <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);

            DoubleValue value = context.findOnStack(Value).Value as DoubleValue;
            DoubleValue multiple = context.findOnStack(Multiple).Value as DoubleValue;
            if (value != null && multiple != null)
            {
                double res = Math.Floor(value.Val);
                while (res > 0 && res%multiple.Val != 0)
                {
                    res--;
                }
                retVal = new DoubleValue(ReturnType, res);
            }

            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:31,代码来源:RoundToMultiple.cs

示例10: Evaluate

        /// <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);
            IValue value = context.findOnStack(Value).Value;
            if (value is Function)
            {
                retVal = value;
            }
            else
            {
                retVal = TargetType.convert(value);
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:27,代码来源:Cast.cs

示例11: createSurface

        /// <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="explain"></param>
        /// <returns></returns>
        public override Surface createSurface(InterpretationContext context, ExplanationPart explain)
        {
            Surface retVal = null;

            IValue firstValue = context.findOnStack(First).Value;
            IValue secondValue = context.findOnStack(Second).Value;
            Surface firstSurface = createSurfaceForValue(context, firstValue, explain);
            if (firstSurface != null)
            {
                Surface secondSurface = createSurfaceForValue(context, secondValue, explain);
                if (secondSurface != null)
                {
                    retVal = firstSurface.Min(secondSurface);
                }
                else
                {
                    Log.Error("Cannot create surface for " + Second.ToString());
                }
            }
            else
            {
                Log.Error("Cannot create surface for " + First.ToString());
            }

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:32,代码来源:MinSurface.cs

示例12: Evaluate

        /// <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);

            ListValue value = context.findOnStack(Collection) as ListValue;
            if (value != null)
            {
                Collection collectionType = value.Type as Collection;
                if (collectionType != null && collectionType.Type != null)
                {
                    Type elementType = collectionType.Type;

                    int i = 0;
                    while (i < value.Val.Count && value.Val[i] != EFSSystem.EmptyValue)
                    {
                        i += 1;
                    }

                    if (i < value.Val.Count)
                    {
                        retVal = elementType.DefaultValue;
                        value.Val[i] = retVal;
                    }
                    else
                    {
                        AddError("Cannot allocate element in list : list full");
                    }
                }
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:44,代码来源:Allocate.cs

示例13: createGraph

        /// <summary>
        ///     Creates a graph for the function
        /// </summary>
        /// <param name="context"></param>
        /// <param name="parameter"></param>
        /// <param name="explain"></param>
        /// <returns></returns>
        public override Graph createGraph(InterpretationContext context, Parameter parameter, ExplanationPart explain)
        {
            Graph retVal = new Graph();

            StructureValue LocationStruct = context.findOnStack(Target).Value as StructureValue;

            SiDistance location;
            SiSpeed speed;

            if (LocationStruct != null)
            {
                Variable Location = LocationStruct.Val["Location"] as Variable;
                location = new SiDistance((Location.Value as DoubleValue).Val);
                Variable Speed = LocationStruct.Val["Speed"] as Variable;
                speed = new SiSpeed((Speed.Value as DoubleValue).Val, SiSpeed_SubUnits.KiloMeter_per_Hour);

                Function decelerationFactor = context.findOnStack(DecelerationFactor).Value as Function;
                if (decelerationFactor != null)
                {
                    Surface DecelerationSurface = decelerationFactor.createSurface(context, explain);
                    if (DecelerationSurface != null)
                    {
                        AccelerationSpeedDistanceSurface accelerationSurface =
                            DecelerationSurface.createAccelerationSpeedDistanceSurface(double.MaxValue, double.MaxValue);

                        QuadraticSpeedDistanceCurve BrakingCurve = null;

                        try
                        {
                            BrakingCurve = EtcsBrakingCurveBuilder.Build_Deceleration_Curve(accelerationSurface, speed,
                                location);
                        }
                        catch (Exception e)
                        {
                            retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, 0, 0)));
                        }

                        SiSpeed finalSpeed = new SiSpeed(getDoubleValue(context.findOnStack(EndSpeed).Value), SiSpeed_SubUnits.KiloMeter_per_Hour);
                        for (int i = 0; i < BrakingCurve.SegmentCount; i++)
                        {
                            QuadraticCurveSegment segment = BrakingCurve[i];

                            SiSpeed endSpeed = Max(finalSpeed, segment.Get(segment.X.X1));

                            SiDistance endDistance;
                            if (endSpeed == finalSpeed)
                            {
                                // Ensures that a braking curve is calculated until the finalSpeed
                                // but not further than the end of the curve segment
                                SiSpeed tmp = Max(  segment.Get(segment.X.X1),
                                                            endSpeed - new SiSpeed(0.001));
                                endDistance = segment.IntersectAt(tmp);
                            }
                            else
                            {
                                endDistance = segment.X.X1;
                            }

                            Graph.Segment newSegment = new Graph.Segment(
                                segment.X.X0.ToUnits(),
                                endDistance.ToUnits(),
                                new Graph.Segment.Curve(
                                    segment.A.ToSubUnits(SiAcceleration_SubUnits.Meter_per_SecondSquare),
                                    segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour),
                                    segment.D0.ToSubUnits(SiDistance_SubUnits.Meter)
                                    )
                                );
                            retVal.AddSegment(newSegment);

                            if (endSpeed == finalSpeed)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:86,代码来源:FullDecelerationForTarget.cs

示例14: Evaluate

        /// <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);
                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
            {
                Log.Error("Cannot get function for " + Function.ToString());
            }
            context.LocalScope.PopContext(token);

            return retVal;
        }
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:43,代码来源:DistanceForSpeed.cs

示例15: createGraph

        /// <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 MRSPGraph = null;
            Function speedRestriction = context.findOnStack(SpeedRestrictions).Value as Function;
            if (speedRestriction != null)
            {
                Parameter p = (Parameter) speedRestriction.FormalParameters[0];

                int token = context.LocalScope.PushContext();
                context.LocalScope.setGraphParameter(p);
                MRSPGraph = createGraphForValue(context, context.findOnStack(SpeedRestrictions).Value, explain, p);
                context.LocalScope.PopContext(token);
            }

            if (MRSPGraph != null)
            {
                Function deceleratorFactor = context.findOnStack(DecelerationFactor).Value as Function;
                if (deceleratorFactor != null)
                {
                    Surface DecelerationSurface = deceleratorFactor.createSurface(context, explain);
                    if (DecelerationSurface != null)
                    {
                        FlatSpeedDistanceCurve MRSPCurve = MRSPGraph.FlatSpeedDistanceCurve(MRSPGraph.ExpectedEndX());
                        AccelerationSpeedDistanceSurface accelerationSurface =
                            DecelerationSurface.createAccelerationSpeedDistanceSurface(double.MaxValue, double.MaxValue);
                        QuadraticSpeedDistanceCurve BrakingCurve = null;
                        try
                        {
                            BrakingCurve = EtcsBrakingCurveBuilder.Build_A_Safe_Backward(accelerationSurface, MRSPCurve);
                        }
                        catch (Exception e)
                        {
                            retVal = new Graph();
                            retVal.AddSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, 0, 0)));
                        }

                        if (BrakingCurve != null)
                        {
                            retVal = new Graph();

                            // TODO : Remove the distinction between linear curves and quadratic curves
                            bool isLinear = true;
                            for (int i = 0; i < BrakingCurve.SegmentCount; i++)
                            {
                                QuadraticCurveSegment segment = BrakingCurve[i];
                                if (segment.A.ToUnits() != 0.0 || segment.V0.ToUnits() != 0.0)
                                {
                                    isLinear = false;
                                    break;
                                }
                            }

                            for (int i = 0; i < BrakingCurve.SegmentCount; i++)
                            {
                                QuadraticCurveSegment segment = BrakingCurve[i];

                                Graph.Segment newSegment;
                                if (isLinear)
                                {
                                    newSegment = new Graph.Segment(
                                        segment.X.X0.ToUnits(),
                                        segment.X.X1.ToUnits(),
                                        new Graph.Segment.Curve(0.0,
                                            segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour), 0.0));
                                }
                                else
                                {
                                    newSegment = new Graph.Segment(
                                        segment.X.X0.ToUnits(),
                                        segment.X.X1.ToUnits(),
                                        new Graph.Segment.Curve(
                                            segment.A.ToSubUnits(SiAcceleration_SubUnits.Meter_per_SecondSquare),
                                            segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour),
                                            segment.D0.ToSubUnits(SiDistance_SubUnits.Meter)
                                            )
                                        );
                                }
                                retVal.AddSegment(newSegment);
                            }
                        }
                    }
                    else
                    {
                        Log.Error("Cannot create surface for " + DecelerationFactor.ToString());
                    }
                }
                else
                {
                    Log.Error("Cannot evaluate " + DecelerationFactor.ToString() + " as a function");
                }
            }
//.........这里部分代码省略.........
开发者ID:JamesOakey,项目名称:ERTMSFormalSpecs,代码行数:101,代码来源:DecelerationProfile.cs


注:本文中的DataDictionary.Interpreter.InterpretationContext.findOnStack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。