/// <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); if (Term != null) { retVal = Functions.Surface.createSurface(xParam, yParam, GetValue(context)); } else if (Expression != null) { if (UnaryOp == null) { retVal = Expression.createSurface(context, xParam, yParam); } else { if (UnaryOp == MINUS) { retVal = Expression.createSurface(context, xParam, yParam); retVal.Negate(); } else { AddError("Cannot create surface with unary op " + UnaryOp); } } } retVal.XParameter = xParam; retVal.YParameter = yParam; return(retVal); }
/// <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(Interpreter.InterpretationContext context, Parameter parameter) { 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, p); context.LocalScope.PopContext(token); } if (graph != null) { Function increment = context.findOnStack(Increment).Value as Function; retVal = graph.AddIncrement(context, increment); } else { Log.Error("Cannot create graph for " + Function.ToString()); } return(retVal); }
/// <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; try { recursionCount += 1; if (recursionCount > 10) { System.Diagnostics.Debugger.Break(); } int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Function function = (Function)Generated.acceptor.getFactory().createFunction(); function.Name = "MIN (" + getName(First) + ", " + getName(Second) + ")"; function.Enclosing = EFSSystem; Parameter parameter = (Parameter)Generated.acceptor.getFactory().createParameter(); parameter.Name = "X"; parameter.Type = EFSSystem.DoubleType; function.appendParameters(parameter); function.ReturnType = EFSSystem.DoubleType; function.Graph = createGraph(context, parameter); retVal = function; context.LocalScope.PopContext(token); } finally { recursionCount -= 1; } return(retVal); }
/// <summary> /// Performs the arithmetic operation based on the type of the result /// </summary> /// <param name="context">The context used to perform this operation</param> /// <param name="left"></param> /// <param name="Operation"></param> /// <param name="right"></param> /// <returns></returns> public override Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, Interpreter.BinaryExpression.OPERATOR Operation, Values.IValue right) // left +/-/*/div/exp right { Values.IValue retVal = null; Constants.EnumValue enumValue = left as Constants.EnumValue; if (enumValue != null) { left = enumValue.Value; } enumValue = right as Constants.EnumValue; if (enumValue != null) { right = enumValue.Value; } Values.IntValue int1 = left as Values.IntValue; Values.IntValue int2 = right as Values.IntValue; if (int1 == null || int2 == null) { retVal = EFSSystem.DoubleType.PerformArithmericOperation(context, left, Operation, right); } else { retVal = EFSSystem.IntegerType.PerformArithmericOperation(context, left, Operation, right); } return(retVal); }
/// <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 virtual Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = Graph; if (retVal == null) { try { Interpreter.InterpretationContext ctxt = new Interpreter.InterpretationContext(context); if (Cases.Count > 0) { // For now, just create graphs for functions using 0 or 1 parameter. if (FormalParameters.Count == 0) { Values.IValue value = Evaluate(ctxt, new Dictionary <Variables.Actual, Values.IValue>()); retVal = Graph.createGraph(value, parameter); } else if (FormalParameters.Count == 1) { Parameter param = (Parameter)FormalParameters[0]; int token = ctxt.LocalScope.PushContext(); Values.IValue actualValue = null; if (parameter != null) { Variables.IVariable actual = ctxt.findOnStack(parameter); if (actual != null) { actualValue = actual.Value; } else { actualValue = new Values.PlaceHolder(parameter.Type, 1); } ctxt.LocalScope.setParameter(param, actualValue); } retVal = createGraphForParameter(ctxt, param); if (getCacheable() && actualValue is Values.PlaceHolder) { Graph = retVal; } ctxt.LocalScope.PopContext(token); } else { Values.IValue value = Evaluate(ctxt, new Dictionary <Variables.Actual, Values.IValue>()); retVal = Graph.createGraph(value, parameter); } } } catch (Exception e) { AddError("Cannot create graph of function, reason : " + e.Message); } } return(retVal); }
/// <summary> /// Assigns the values of the function parameters with values provided in the list Parameters /// </summary> /// <param name="context">The interpretation context</param> /// <param name="parameterValues">The values of the parameters</param> public void AssignParameters(Interpreter.InterpretationContext context, Dictionary <Variables.Actual, Values.IValue> parameterValues) { foreach (KeyValuePair <Variables.Actual, Values.IValue> pair in parameterValues) { context.LocalScope.setVariable(pair.Key, pair.Value); } }
/// <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> /// <returns></returns> public override Surface createSurface(Interpreter.InterpretationContext context) { Surface retVal = null; Values.IValue firstValue = context.findOnStack(First).Value; Values.IValue secondValue = context.findOnStack(Second).Value; Surface firstSurface = createSurfaceForValue(context, firstValue); if (firstSurface != null) { Surface secondSurface = createSurfaceForValue(context, secondValue); 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); }
/// <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); Function function = (Function)Generated.acceptor.getFactory().createFunction(); function.Name = "AddIncrement ( Function => " + getName(Function) + ", Value => " + getName(Increment) + ")"; function.Enclosing = EFSSystem; Parameter parameter = (Parameter)Generated.acceptor.getFactory().createParameter(); parameter.Name = "X"; parameter.Type = EFSSystem.DoubleType; function.appendParameters(parameter); function.ReturnType = EFSSystem.DoubleType; function.Graph = createGraph(context, parameter); retVal = function; context.LocalScope.PopContext(token); return(retVal); }
/// <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(Interpreter.InterpretationContext context, Interpreter.BinaryExpression expression) { bool retVal = false; if (expression != null) { foreach (Types.ITypedElement element in expression.GetRightSides()) { Parameter parameter = element as Parameter; if (parameter != null) { Variables.IVariable variable = context.findOnStack(parameter); if (variable != null) { Values.PlaceHolder placeHolder = variable.Value as Values.PlaceHolder; if (placeHolder != null) { retVal = true; break; } } } } } return(retVal); }
/// <summary> /// Provides the surface of this function if it has been statically defined /// </summary> /// <param name="context">the context used to create the graph</param> /// <returns></returns> public virtual Surface createSurface(Interpreter.InterpretationContext context) { Surface retVal = Surface; if (retVal == null) { try { if (FormalParameters.Count == 2) { // Select which parameter is the X axis of the surface, and which is the Y Parameter Xparameter = SelectXAxisParameter(context); Parameter Yparameter = SelectYAxisParameter(Xparameter); if (Xparameter != null && Yparameter != null) { int token = context.LocalScope.PushContext(); context.LocalScope.setSurfaceParameters(Xparameter, Yparameter); retVal = createSurfaceForParameters(context, Xparameter, Yparameter); context.LocalScope.PopContext(token); } } else { AddError("Wrong number of parameters for function " + FullName + " to create a surface"); } } catch (Exception e) { AddError("Cannot create surface of function, reason : " + e.Message); } } return(retVal); }
/// <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); }
/// <summary> /// Perform additional checks based on the parameter types /// </summary> /// <param name="root">The element on which the errors should be reported</param> /// <param name="context">The evaluation context</param> /// <param name="actualParameters">The parameters applied to this function call</param> public override void additionalChecks(ModelElement root, Interpreter.InterpretationContext context, Dictionary <string, Interpreter.Expression> actualParameters) { CheckFunctionalParameter(root, context, actualParameters[First.Name], 2); CheckFunctionalParameter(root, context, actualParameters[Second.Name], 0); Function function1 = actualParameters[First.Name].GetExpressionType() as Function; Function function2 = actualParameters[Second.Name].GetExpressionType() as Function; if (function1 != null && function2 != null) { if (function1.FormalParameters.Count == 2 && function2.FormalParameters.Count == 0) { Parameter p1 = (Parameter)function1.FormalParameters[0]; Parameter p2 = (Parameter)function1.FormalParameters[1]; if (p1.Type != EFSSystem.DoubleType || p2.Type != EFSSystem.DoubleType) { root.AddError("The formal parameters for the first function are not double"); } } if (function1.ReturnType != function2.ReturnType && function1.ReturnType != EFSSystem.DoubleType && function2.ReturnType != EFSSystem.DoubleType) { root.AddError("The return values for the functions provided as parameter are not the same"); } } }
/// <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); Function function = (Function)Generated.acceptor.getFactory().createFunction(); function.Name = "MINSURFACE (" + getName(First) + ", " + getName(Second) + ")"; function.Enclosing = EFSSystem; function.Surface = createSurface(context); Parameter parameterX = (Parameter)Generated.acceptor.getFactory().createParameter(); parameterX.Name = "X"; parameterX.Type = EFSSystem.DoubleType; function.appendParameters(parameterX); Parameter parameterY = (Parameter)Generated.acceptor.getFactory().createParameter(); parameterY.Name = "Y"; parameterY.Type = EFSSystem.DoubleType; function.appendParameters(parameterY); function.ReturnType = EFSSystem.DoubleType; retVal = function; context.LocalScope.PopContext(token); return(retVal); }
/// <summary> /// Creates a list of changes to be applied on the system /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list of changes to be updated</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <returns>The list to fill with the changes</param> public void GetChanges(Interpreter.InterpretationContext context, ChangeList changes, Interpreter.ExplanationPart explanation, bool apply) { long start = System.Environment.TickCount; try { if (Statement != null) { Statement.GetChanges(context, changes, explanation, apply); } else { AddError("Invalid actions statement"); } } catch (Exception e) { AddException(e); } long stop = System.Environment.TickCount; long span = (stop - start); if (RuleCondition != null && RuleCondition.EnclosingRule != null) { // Rule execution execution time (as opposed to guard evaluation) RuleCondition.EnclosingRule.ExecutionTimeInMilli += span; RuleCondition.EnclosingRule.ExecutionCount += 1; } }
/// <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> /// <returns></returns> public override Surface createSurface(Interpreter.InterpretationContext context) { Surface retVal = null; Surface defaultSurface = createSurfaceForValue(context, context.findOnStack(DefaultFunction).Value); if (defaultSurface != null) { Surface overrideSurface = createSurfaceForValue(context, context.findOnStack(OverrideFunction).Value); 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); }
/// <summary> /// Creates the graph associated to the parameter provided /// </summary> /// <param name="value">The value for which the graph must be created</param> /// <returns></returns> protected Graph createGraphForValue(Interpreter.InterpretationContext context, Values.IValue value, Parameter parameter = null) { Graph retVal = new Graph(); Function function = value as Function; if (function != null) { if (parameter == null) { parameter = (Parameter)function.FormalParameters[0]; int token = context.LocalScope.PushContext(); context.LocalScope.setGraphParameter(parameter); retVal = function.createGraph(context, parameter); context.LocalScope.PopContext(token); } else { retVal = function.createGraph(context, parameter); } } else { Values.DoubleValue val = value as Values.DoubleValue; retVal.addSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0.0, val.Val, 0.0))); } return(retVal); }
/// <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(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = null; Graph firstGraph = createGraphForValue(context, context.findOnStack(First).Value); if (firstGraph != null) { Graph secondGraph = createGraphForValue(context, context.findOnStack(Second).Value); if (secondGraph != null) { retVal = firstGraph.Min(secondGraph); } else { Log.Error("Cannot create graph for " + Second.ToString()); } } else { Log.Error("Cannot create graph for " + First.ToString()); } return(retVal); }
/// <summary> /// Provides the actual value for the preconditions /// </summary> /// <param name="context">The context on which the precondition must be evaluated</param> /// <returns></returns> public bool EvaluatePreConditions(Interpreter.InterpretationContext context) { bool retVal = true; foreach (DataDictionary.Rules.PreCondition preCondition in PreConditions) { try { Interpreter.Expression expression = preCondition.ExpressionTree; Values.BoolValue value = expression.GetValue(context) as Values.BoolValue; if (value != null) { retVal = retVal && value.Val; } else { retVal = false; // TODO : Handle Error } if (!retVal) { break; } } catch (Exception e) { preCondition.AddException(e); retVal = false; break; } } return(retVal); }
/// <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 Functions.Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter) { Functions.Graph retVal = base.createGraph(context, parameter); retVal = Functions.Graph.createGraph(GetValue(context), parameter); return(retVal); }
/// <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); } }
/// <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; AssignParameters(context, actuals); Graph graph = createGraphForValue(context, context.findOnStack(FunctionA).Value); if (graph != null) { foreach (Graph.Segment segment in graph.Segments) { if (segment.Expression.a == 0.0) { double speed = segment.Expression.v0; Function function = context.findOnStack(FunctionB).Value as Function; if (function.FormalParameters.Count > 0) { Parameter functionParameter = function.FormalParameters[0] as Parameter; Variables.Actual actual = functionParameter.createActual(); actual.Value = new Values.DoubleValue(EFSSystem.DoubleType, speed); Dictionary <Variables.Actual, Values.IValue> values = new Dictionary <Variables.Actual, Values.IValue>(); values[actual] = new Values.DoubleValue(EFSSystem.DoubleType, speed); Values.IValue solution = function.Evaluate(context, values); double doubleValue = getDoubleValue(solution); if (doubleValue >= segment.Start && doubleValue <= segment.End) { retVal = new Values.DoubleValue(EFSSystem.DoubleType, doubleValue); break; } } else { Log.Error("The FunctionB doesn't have any parameter"); break; } } else { Log.Error("The FunctionA is not a step function"); break; } } } else { Log.Error("Cannot create graph for " + FunctionA.ToString()); } if (retVal == null) { Log.Error("Cannot compute the intersection of " + FunctionA.ToString() + " and " + FunctionB.ToString()); } return(retVal); }
/// <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 = EFSSystem.BoolType.False; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Values.ListValue collection = context.findOnStack(Collection).Value as Values.ListValue; if (collection != null) { Values.IValue expectedFirst = context.findOnStack(ExpectedFirst).Value; if (expectedFirst != null) { int firstIndex = collection.Val.IndexOf(expectedFirst); if (firstIndex >= 0) { Values.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); }
/// <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); retVal = Functions.Surface.createSurface(GetValue(context), xParam, yParam); if (retVal == null) { throw new Exception("Cannot create surface for " + ToString()); } retVal.XParameter = xParam; retVal.YParameter = yParam; return(retVal); }
/// <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); }
/// <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); }
public override Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = null; Variables.IVariable variable = context.findOnStack(Value); if (variable != null) { retVal = Graph.createGraph(Functions.Function.getDoubleValue(variable.Value), parameter); } else { AddError("Cannot find variable " + Value + " on the stack"); } return(retVal); }
/// <summary> /// Computes the changes related to this event /// </summary> /// <param name="apply">Indicates that the changes should be applied directly</param> public override bool ComputeChanges(bool apply) { bool retVal = base.ComputeChanges(apply); if (retVal) { Explanation = new Interpreter.ExplanationPart(Action); Explanation.Message = "Action " + Action.Name; Interpreter.InterpretationContext context = new Interpreter.InterpretationContext(Instance); Changes = new ChangeList(); Action.GetChanges(context, Changes, Explanation, apply); Changes.CheckChanges(Action); Message = Explanation.ToString(); } return(retVal); }
/// <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 = EFSSystem.BoolType.False; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); if (context.findOnStack(Element).Value != EFSSystem.EmptyValue) { retVal = EFSSystem.BoolType.True; } context.LocalScope.PopContext(token); return(retVal); }
/// <summary> /// Provides the value of the expression provided /// </summary> /// <param name="expect"></param> /// <returns></returns> private bool getBoolValue(ModelElement instance, Expression expression) { bool retVal = false; Interpreter.InterpretationContext context = new Interpreter.InterpretationContext(instance); BoolValue val = expression.GetValue(context) as BoolValue; if (val != null) { retVal = val.Val; } else { throw new Exception("Cannot evaluate vaue of " + expression); } return(retVal); }
/// <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(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = null; Graph graph = createGraphForValue(context, context.findOnStack(Function).Value, parameter); if (graph != null) { double speed = Functions.Function.getDoubleValue(context.findOnStack(Speed).Value); retVal = Graph.createGraph(graph.SolutionX(speed)); } else { Log.Error("Cannot create graph for " + Function.ToString()); } return(retVal); }
/// <summary> /// Provides the value of the expression provided /// </summary> /// <param name="expect"></param> /// <returns></returns> private bool getBoolValue(ModelElement instance, Expression expression) { bool retVal = false; Interpreter.InterpretationContext context = new Interpreter.InterpretationContext(instance); BoolValue val = expression.GetValue(context) as BoolValue; if (val != null) { retVal = val.Val; } else { throw new Exception("Cannot evaluate vaue of " + expression); } return retVal; }
/// <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 virtual Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = Graph; if (retVal == null) { try { Interpreter.InterpretationContext ctxt = new Interpreter.InterpretationContext(context); if (Cases.Count > 0) { // For now, just create graphs for functions using 0 or 1 parameter. if (FormalParameters.Count == 0) { Values.IValue value = Evaluate(ctxt, new Dictionary<Variables.Actual, Values.IValue>()); retVal = Graph.createGraph(value, parameter); } else if (FormalParameters.Count == 1) { Parameter param = (Parameter)FormalParameters[0]; int token = ctxt.LocalScope.PushContext(); Values.IValue actualValue = null; if (parameter != null) { Variables.IVariable actual = ctxt.findOnStack(parameter); if (actual != null) { actualValue = actual.Value; } else { actualValue = new Values.PlaceHolder(parameter.Type, 1); } ctxt.LocalScope.setParameter(param, actualValue); } retVal = createGraphForParameter(ctxt, param); if (getCacheable() && actualValue is Values.PlaceHolder) { Graph = retVal; } ctxt.LocalScope.PopContext(token); } else { Values.IValue value = Evaluate(ctxt, new Dictionary<Variables.Actual, Values.IValue>()); retVal = Graph.createGraph(value, parameter); } } } catch (Exception e) { AddError("Cannot create graph of function, reason : " + e.Message); } } return retVal; }
/// <summary> /// Computes the changes related to this event /// </summary> /// <param name="apply">Indicates that the changes should be applied directly</param> public override bool ComputeChanges(bool apply) { bool retVal = base.ComputeChanges(apply); if (retVal) { Explanation = new Interpreter.ExplanationPart(Action); Explanation.Message = "Action " + Action.Name; Interpreter.InterpretationContext context = new Interpreter.InterpretationContext(Instance); Changes = new ChangeList(); Action.GetChanges(context, Changes, Explanation, apply); Changes.CheckChanges(Action); Message = Explanation.ToString(); } return retVal; }
/// <summary> /// Evaluates the rule and its sub rules /// </summary> /// <param name="runner"></param> /// <param name="priority">the priority level : a rule can be activated only if its priority level == priority</param> /// <param name="instance">The instance on which the rule must be evaluated</param> /// <param name="ruleConditions">the rule conditions to be activated</param> /// <returns>the number of actions that were activated during this evaluation</returns> public bool Evaluate(Tests.Runner.Runner runner, Generated.acceptor.RulePriority priority, Utils.IModelElement instance, List<RuleCondition> ruleConditions) { bool retVal = false; Interpreter.InterpretationContext context = new Interpreter.InterpretationContext(instance); retVal = EvaluatePreConditions(context); if (retVal) { foreach (Rule subRule in SubRules) { subRule.Evaluate(runner, priority, instance, ruleConditions); } if (EnclosingRule.getPriority() == priority) { ruleConditions.Add(this); } } return retVal; }