public override void visit(Generated.Case obj, bool visitSubNodes)
        {
            Functions.Case cas = obj as Functions.Case;

            try
            {
                Interpreter.Expression expression = cas.Expression;
                if (expression != null)
                {
                    expression.checkExpression();
                    Types.Type expressionType = cas.Expression.GetExpressionType();
                    if (expressionType != null)
                    {
                        if (!cas.EnclosingFunction.ReturnType.Match(expressionType))
                        {
                            cas.AddError("Expression type (" + expressionType.FullName + ") does not match function return type (" + cas.EnclosingFunction.ReturnType.Name + ")");
                        }
                    }
                    else
                    {
                        cas.AddError("Cannot determine expression type (6) for " + cas.Expression.ToString());
                    }
                }
                else
                {
                    cas.AddError("Cannot evaluate expression " + cas.ExpressionText);
                }
            }
            catch (Exception e)
            {
                cas.AddException(e);
            }

            base.visit(obj, visitSubNodes);
        }
Esempio n. 2
0
        public override Case createCase()
        {
            Case retVal = new Functions.Case();

            _defaultValueSetter.SetDefaultValue(retVal);

            return(retVal);
        }
Esempio n. 3
0
        public void AddCaseHandler(object sender, EventArgs args)
        {
            DataDictionaryTreeView treeView = BaseTreeView as DataDictionaryTreeView;

            if (treeView != null)
            {
                DataDictionary.Functions.Case aCase = (DataDictionary.Functions.Case)DataDictionary.Generated.acceptor.getFactory().createCase();
                aCase.Name = "Case" + (Item.Cases.Count + 1);
                Cases.AddCase(aCase);
            }
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public CaseModelControl(ModelDiagramPanel panel, Case model)
     : base(panel, model)
 {
     BoxMode = BoxModeEnum.RoundedCorners;
     NormalColor = Color.LightBlue;
 }
        public override Case createCase()
        {
            Case retVal = new Functions.Case();

            _defaultValueSetter.SetDefaultValue(retVal);

            return retVal;
        }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="panel"></param>
 /// <param name="model"></param>
 public CaseModelControl(ModelDiagramPanel panel, Case model)
     : base(panel, model)
 {
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 /// <param name="item"></param>
 /// <param name="buildSubNodes"></param>
 public PreConditionsTreeNode(Case item, bool buildSubNodes)
     : base(item, buildSubNodes, "Pre condition", true)
 {
 }
        /// <summary>
        /// Reduces the X axis of the surface according to the preconditions of this case
        /// </summary>
        /// <param name="context">The context used to reduce the surface</param>
        /// <param name="cas">The case used to reduce the surface</param>
        /// <param name="surface">The surface to reduce</param>
        /// <param name="parameter">The parameter for which the reduction has been performed</param>
        /// <returns>The reduced surface</returns>
        private Surface ReduceSurface(Interpreter.InterpretationContext context, Case cas, Surface surface, out Parameter parameter)
        {
            Surface retVal;

            // Evaluate the axis
            parameter = null;
            foreach (Rules.PreCondition preCondition in cas.PreConditions)
            {
                List <Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.XParameter);
                if (boundaries.Count != 0 && !fullRange(boundaries))
                {
                    if (parameter != surface.YParameter)
                    {
                        parameter = surface.XParameter;
                    }
                    else
                    {
                        throw new Exception("Cannot reduce a graph on both X axis and Y axis on the same time (1)");
                    }
                }
                else
                {
                    boundaries = EvaluateBoundaries(context, preCondition, surface.YParameter);
                    if (boundaries.Count != 0 && !fullRange(boundaries))
                    {
                        if (parameter != surface.XParameter)
                        {
                            parameter = surface.YParameter;
                        }
                        else
                        {
                            throw new Exception("Cannot reduce a graph on both X axis and Y axis on the same time (2)");
                        }
                    }
                }
            }

            if (parameter == surface.XParameter)
            {
                // Reduce the surface on the X axis
                retVal = new Surface(surface.XParameter, surface.YParameter);
                foreach (Surface.Segment segment in surface.Segments)
                {
                    retVal.AddSegment(new Surface.Segment(segment));
                }

                // Reduces the segments according to this preconditions
                foreach (Rules.PreCondition preCondition in cas.PreConditions)
                {
                    List <Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.XParameter);
                    retVal.Reduce(boundaries);
                }
            }
            else if (parameter == surface.YParameter)
            {
                // Reduce the surface, for all segments of the X axis, on the Y axis
                retVal = new Surface(surface.XParameter, surface.YParameter);
                foreach (Surface.Segment segment in surface.Segments)
                {
                    // Reduces the segments according to this preconditions
                    foreach (Rules.PreCondition preCondition in cas.PreConditions)
                    {
                        List <Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.YParameter);
                        segment.Graph.Reduce(boundaries);
                    }
                    if (!segment.Empty())
                    {
                        retVal.AddSegment(segment);
                    }
                }
            }
            else
            {
                retVal = surface;
            }

            return(retVal);
        }
        /// <summary>
        /// Indicates whether all preconditions are satisfied for a given case, ignoring expressions like x (y) <= xxx or x (y) >= xxx
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="cas">The case to evaluate</param>
        /// <param name="x">First parameter</param>
        /// <param name="y">Second parameter</param>
        /// <returns></returns>
        private bool PreconditionSatisfied(Interpreter.InterpretationContext context, Case cas, Parameter x, Parameter y)
        {
            bool retVal = true;

            foreach (Rules.PreCondition preCondition in cas.PreConditions)
            {
                if (!ExpressionBasedOnParameter(x, preCondition.ExpressionTree) && !ExpressionBasedOnParameter(y, preCondition.ExpressionTree))
                {
                    Values.BoolValue boolValue = preCondition.ExpressionTree.GetValue(context) as Values.BoolValue;
                    if (boolValue == null)
                    {
                        throw new Exception("Cannot evaluate precondition " + preCondition.Name);
                    }
                    else if (!boolValue.Val)
                    {
                        retVal = false;
                        break;
                    }
                }
            }

            return(retVal);
        }
Esempio n. 10
0
 /// <summary>
 /// Reduces the graph to the only part releated to the preconditions
 /// </summary>
 /// <param name="context">The context used to evaluate the precondition and segment value</param>
 /// <param name="graph">The graph to reduce</param>
 /// <param name="cas">The case which is used to reduce the graph</param>
 /// <param name="parameter"></param>
 /// <returns></returns>
 private void ReduceGraph(Interpreter.InterpretationContext context, Graph graph, Case cas, Parameter parameter)
 {
     foreach (Rules.PreCondition preCondition in cas.PreConditions)
     {
         List <Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, parameter);
         graph.Reduce(boundaries);
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Reduces the X axis of the surface according to the preconditions of this case
        /// </summary>
        /// <param name="context">The context used to reduce the surface</param>
        /// <param name="cas">The case used to reduce the surface</param>
        /// <param name="surface">The surface to reduce</param>
        /// <param name="parameter">The parameter for which the reduction has been performed</param>
        /// <returns>The reduced surface</returns>
        private Surface ReduceSurface(Interpreter.InterpretationContext context, Case cas, Surface surface, out Parameter parameter)
        {
            Surface retVal;

            // Evaluate the axis
            parameter = null;
            foreach (Rules.PreCondition preCondition in cas.PreConditions)
            {
                List<Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.XParameter);
                if (boundaries.Count != 0 && !fullRange(boundaries))
                {
                    if (parameter != surface.YParameter)
                    {
                        parameter = surface.XParameter;
                    }
                    else
                    {
                        throw new Exception("Cannot reduce a graph on both X axis and Y axis on the same time (1)");
                    }
                }
                else
                {
                    boundaries = EvaluateBoundaries(context, preCondition, surface.YParameter);
                    if (boundaries.Count != 0 && !fullRange(boundaries))
                    {
                        if (parameter != surface.XParameter)
                        {
                            parameter = surface.YParameter;
                        }
                        else
                        {
                            throw new Exception("Cannot reduce a graph on both X axis and Y axis on the same time (2)");
                        }
                    }
                }
            }

            if (parameter == surface.XParameter)
            {
                // Reduce the surface on the X axis
                retVal = new Surface(surface.XParameter, surface.YParameter);
                foreach (Surface.Segment segment in surface.Segments)
                {
                    retVal.AddSegment(new Surface.Segment(segment));
                }

                // Reduces the segments according to this preconditions
                foreach (Rules.PreCondition preCondition in cas.PreConditions)
                {
                    List<Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.XParameter);
                    retVal.Reduce(boundaries);
                }
            }
            else if (parameter == surface.YParameter)
            {
                // Reduce the surface, for all segments of the X axis, on the Y axis
                retVal = new Surface(surface.XParameter, surface.YParameter);
                foreach (Surface.Segment segment in surface.Segments)
                {
                    // Reduces the segments according to this preconditions
                    foreach (Rules.PreCondition preCondition in cas.PreConditions)
                    {
                        List<Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, surface.YParameter);
                        segment.Graph.Reduce(boundaries);
                    }
                    if (!segment.Empty())
                    {
                        retVal.AddSegment(segment);
                    }
                }
            }
            else
            {
                retVal = surface;
            }

            return retVal;
        }
Esempio n. 12
0
 /// <summary>
 /// Reduces the graph to the only part releated to the preconditions
 /// </summary>
 /// <param name="context">The context used to evaluate the precondition and segment value</param>
 /// <param name="graph">The graph to reduce</param>
 /// <param name="cas">The case which is used to reduce the graph</param>
 /// <param name="parameter"></param>
 /// <returns></returns>
 private void ReduceGraph(Interpreter.InterpretationContext context, Graph graph, Case cas, Parameter parameter)
 {
     foreach (Rules.PreCondition preCondition in cas.PreConditions)
     {
         List<Graph.Segment> boundaries = EvaluateBoundaries(context, preCondition, parameter);
         graph.Reduce(boundaries);
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Indicates whether all preconditions are satisfied for a given case, ignoring expressions like x (y) <= xxx or x (y) >= xxx
        /// </summary>
        /// <param name="context">The interpretation context</param>
        /// <param name="cas">The case to evaluate</param>
        /// <param name="x">First parameter</param>
        /// <param name="y">Second parameter</param>
        /// <returns></returns>
        private bool PreconditionSatisfied(Interpreter.InterpretationContext context, Case cas, Parameter x, Parameter y)
        {
            bool retVal = true;

            foreach (Rules.PreCondition preCondition in cas.PreConditions)
            {
                if (!ExpressionBasedOnParameter(x, preCondition.ExpressionTree) && !ExpressionBasedOnParameter(y, preCondition.ExpressionTree))
                {
                    Values.BoolValue boolValue = preCondition.ExpressionTree.GetValue(context) as Values.BoolValue;
                    if (boolValue == null)
                    {
                        throw new Exception("Cannot evaluate precondition " + preCondition.Name);
                    }
                    else if (!boolValue.Val)
                    {
                        retVal = false;
                        break;
                    }
                }
            }

            return retVal;
        }