/// <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; if (value.Val.Count >= collectionType.getMaxSize()) { AddError("Cannot allocate element in list : list full"); } else { retVal = elementType.DefaultValue; value.Val.Add(retVal); } } } context.LocalScope.PopContext(token); return retVal; }
/// <summary> /// Provides the value of the function. /// The function returns true if the string passes the check. /// </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); StringValue number = context.findOnStack(Number).Value as StringValue; if (number != null && number.Val != "") { char[] tmp = number.Val.ToCharArray(); // Each character in the string is checked. The expected format is // #########FFFFF // ie. a sequence of digits, possibly followed by a sequence of 'F'. // numbersequence indicates that we are in the first part of the string bool numberSequence = true; for (int i = 0; i < tmp.Length; i++) { // If we encounter a letter that is not F, the value is incorrect if (Char.IsLetter(tmp[i]) && !tmp[i].Equals('F')) { break; } // If we encounter a number after the first 'F' character, the value is incorrect if (!numberSequence && Char.IsDigit(tmp[i])) { break; } if (Char.IsLetter(tmp[i])) { numberSequence = false; } // Once the whole string has been checked without error, set the return to true if (i == tmp.Length - 1) { retVal = EFSSystem.BoolType.True; } } } context.LocalScope.PopContext(token); return retVal; }
/// <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); if (context.FindOnStack(Element).Value != EFSSystem.EmptyValue) { retVal = EFSSystem.BoolType.True; } context.LocalScope.PopContext(token); return retVal; }
/// <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; if (value != null) { int res = (int) Math.Round(value.Val); retVal = new IntValue(ReturnType, res); } context.LocalScope.PopContext(token); return retVal; }
/// <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; }
/// <summary> /// Constructor /// </summary> /// <param name="root">The root element for which this element is built</param> /// <param name="call">The corresponding function call designator</param> /// <param name="parameters">The expressions used to compute the parameters</param> /// <param name="start">The start character for this expression in the original string</param> /// <param name="end">The end character for this expression in the original string</param> public ApplyStatement(ModelElement root, ModelElement log, Statement appliedStatement, Expression listExpression, Expression conditionExpression, int start, int end) : base(root, log, start, end) { DeclaredElements = new Dictionary<string, List<INamable>>(); AppliedStatement = appliedStatement; AppliedStatement.Enclosing = this; ListExpression = listExpression; ListExpression.Enclosing = this; ConditionExpression = conditionExpression; if (ConditionExpression != null) { ConditionExpression.Enclosing = this; } IteratorVariable = (Variable) acceptor.getFactory().createVariable(); IteratorVariable.Enclosing = this; IteratorVariable.Name = "X"; InitDeclaredElements(); }
/// <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; }
/// <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; }
/// <summary> /// Initialises the declared elements /// </summary> public void InitDeclaredElements() { DeclaredElements = new Dictionary<string, List<INamable>>(); foreach (Parameter parameter in Parameters) { parameter.Enclosing = this; ISubDeclaratorUtils.AppendNamable(this, parameter); } }
/// <summary> /// Applies the selected actions and update the system state /// </summary> /// <param name="activations"></param> /// <param name="updates"></param> /// <param name="priority"></param> public void EvaluateActivations(HashSet<Activation> activations, acceptor.RulePriority priority, ref List<VariableUpdate> updates) { Dictionary<IVariable, Change> changes = new Dictionary<IVariable, Change>(); Dictionary<Change, VariableUpdate> traceBack = new Dictionary<Change, VariableUpdate>(); foreach (Activation activation in activations) { if (activation.RuleCondition.Actions.Count > 0) { // Register the fact that a rule has been triggered RuleFired ruleFired = new RuleFired(activation, priority); EventTimeLine.AddModelEvent(ruleFired, this, true); ExplanationPart changesExplanation = ExplanationPart.CreateSubExplanation(activation.Explanation, "Changes"); // Registers all model updates due to this rule triggering foreach (Action action in activation.RuleCondition.Actions) { if (action.Statement != null) { VariableUpdate variableUpdate = new VariableUpdate(action, activation.Instance, priority); variableUpdate.ComputeChanges(false, this); EventTimeLine.AddModelEvent(variableUpdate, this, false); ruleFired.AddVariableUpdate(variableUpdate); if (changesExplanation != null) { changesExplanation.SubExplanations.Add(variableUpdate.Explanation); } updates.Add(variableUpdate); if (CheckForCompatibleChanges) { ChangeList actionChanges = variableUpdate.Changes; if (variableUpdate.Action.Statement is ProcedureCallStatement) { Dictionary<IVariable, Change> procedureChanges = new Dictionary<IVariable, Change>(); foreach (Change change in variableUpdate.Changes.Changes) { procedureChanges[change.Variable] = change; } actionChanges = new ChangeList(); foreach (Change change in procedureChanges.Values) { actionChanges.Add(change, false, this); } } foreach (Change change in actionChanges.Changes) { IVariable variable = change.Variable; if (changes.ContainsKey(change.Variable)) { Change otherChange = changes[change.Variable]; Action otherAction = traceBack[otherChange].Action; if (!variable.Type.CompareForEquality(otherChange.NewValue, change.NewValue)) { string action1 = ((INamable) action.Enclosing).FullName + " : " + variableUpdate.Action.FullName; string action2 = ((INamable) otherAction.Enclosing).FullName + " : " + traceBack[otherChange].Action.FullName; variableUpdate.Action.AddError( "Simultaneous change of the variable " + variable.FullName + " with different values. Conflit between\n" + action1 + "\n and \n" + action2); } } else { changes.Add(change.Variable, change); traceBack.Add(change, variableUpdate); } } } } else { action.AddError("Cannot parse action statement"); } } } } // Handles the leave & enter state rules List<VariableUpdate> updatesToProcess = updates; updates = new List<VariableUpdate>(); // Avoid considering twice the same transition List<Tuple<State, State>> transitions = new List<Tuple<State, State>>(); while (updatesToProcess.Count > 0) { List<VariableUpdate> newUpdates = new List<VariableUpdate>(); foreach (VariableUpdate update in updatesToProcess) { updates.Add(update); foreach (Change change in update.Changes.Changes) { if (change.Variable.Type is StateMachine) { State leavingState = (State) change.PreviousValue; State enteringState = (State) change.NewValue; bool transitionFound = false; foreach (Tuple<State, State> transition in transitions) { if ((transition.Item1 == leavingState) && (transition.Item2 == enteringState)) { transitionFound = true; break; } } if (! transitionFound) { Tuple<State, State> transition = new Tuple<State, State>(leavingState, enteringState); transitions.Add(transition); HandleLeaveState(priority, newUpdates, change.Variable, leavingState, enteringState); HandleEnterState(priority, newUpdates, change.Variable, leavingState, enteringState); } } } } updatesToProcess = newUpdates; } }
/// <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) { StringValue retVal = null; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); StringValue string1 = context.FindOnStack(String1).Value as StringValue; StringValue string2 = context.FindOnStack(String2).Value as StringValue; if (string1 != null && string2 != null) { retVal = new StringValue(EfsSystem.Instance.StringType, string1.Val + string2.Val); } context.LocalScope.PopContext(token); return retVal; }
/// <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; }
/// <summary> /// Registers the errors raised during evaluation and create ModelInterpretationFailure for each one of them /// </summary> /// <param name="errors"></param> private void RegisterErrors(Dictionary<Utils.ModelElement, List<ElementLog>> errors) { foreach (KeyValuePair<Utils.ModelElement, List<ElementLog>> pair in errors) { foreach (ElementLog log in pair.Value) { switch (log.Level) { case ElementLog.LevelEnum.Error: ModelInterpretationFailure modelInterpretationFailure = new ModelInterpretationFailure(log, pair.Key, null); ModelElement modelElement = pair.Key as ModelElement; if (modelElement != null) { modelInterpretationFailure.Explanation = modelElement.Explain; } EventTimeLine.AddModelEvent(modelInterpretationFailure, this, true); break; case ElementLog.LevelEnum.Warning: break; case ElementLog.LevelEnum.Info: break; } } } }
/// <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, InterpretationContext context, Dictionary<string, Expression> actualParameters) { CheckFunctionalParameter(root, context, actualParameters[DefaultFunction.Name], 2); CheckFunctionalParameter(root, context, actualParameters[OverrideFunction.Name], 2); }
/// <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); Collection collectionType = (Collection) EFSSystem.FindType( OverallNameSpaceFinder.INSTANCE.findByName(EFSSystem.Dictionaries[0], "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring"), "Kernel.SpeedAndDistanceMonitoring.TargetSpeedMonitoring.SpeedRestrictions"); ListValue collection = new ListValue(collectionType, new List<IValue>()); Function function = context.findOnStack(Targets).Value as Function; if (function != null && !function.Name.Equals("EMPTY")) { Graph graph1 = createGraphForValue(context, function, explain); ComputeTargets(graph1.Function, collection); } context.LocalScope.PopContext(token); retVal = collection; return retVal; }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <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> /// <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 = (Function) acceptor.getFactory().createFunction(); function.Name = "AddIncrement ( Function => " + getName(Function) + ", Value => " + getName(Increment) + ")"; function.Enclosing = EFSSystem; Parameter parameter = (Parameter) acceptor.getFactory().createParameter(); parameter.Name = "X"; parameter.Type = EFSSystem.DoubleType; function.appendParameters(parameter); function.ReturnType = EFSSystem.DoubleType; function.Graph = createGraph(context, parameter, explain); retVal = function; context.LocalScope.PopContext(token); return retVal; }
/// <summary> /// Initialises the declared elements /// </summary> public void InitDeclaredElements() { DeclaredElements = new Dictionary<string, List<INamable>>(); ISubDeclaratorUtils.AppendNamable(this, True); ISubDeclaratorUtils.AppendNamable(this, False); }
/// <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, InterpretationContext context, Dictionary<string, Expression> actualParameters) { CheckFunctionalParameter(root, context, actualParameters[First.Name], 1); CheckFunctionalParameter(root, context, actualParameters[Second.Name], 1); 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 == 1 && function2.FormalParameters.Count == 1) { Parameter p1 = (Parameter) function1.FormalParameters[0]; Parameter p2 = (Parameter) function2.FormalParameters[0]; if (p1.Type != p2.Type && p1.Type != EFSSystem.DoubleType && p2.Type != EFSSystem.DoubleType) { root.AddError("The formal parameters for the functions provided as parameter are not the same"); } } 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="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; }
/// <summary> /// Evaluates the current input as a structure /// </summary> /// <returns></returns> public Expression EvaluateStructure() { StructExpression retVal = null; SkipWhiteSpaces(); int start = Index; Expression structureId = DerefExpression(); if (structureId != null) { if (LookAhead("{")) { Match("{"); Dictionary<Designator, Expression> associations = new Dictionary<Designator, Expression>(); if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, RootLog, structureId, associations, start, Index); } else { while (true) { SkipWhiteSpaces(); int startId = Index; string id = Identifier(); if (id != null) { Designator designator = new Designator(Root, RootLog, id, startId, startId + id.Length); string assignOp = LookAhead(AssignOps); if (assignOp != null) { Match(assignOp); Expression expression = Expression(0); if (expression != null) { associations[designator] = expression; } else { RootLog.AddError("Cannot parse expression after " + id + " " + assignOp + " "); break; } } else { throw new ParseErrorException("<- or => expected", Index, Buffer); } } else { if (Index < Buffer.Length) { RootLog.AddError("Identifier expected, but found " + Buffer[Index]); } else { RootLog.AddError("Identifier expected, but EOF found "); } break; } if (LookAhead(",")) { Match(","); } else if (LookAhead("}")) { Match("}"); retVal = new StructExpression(Root, RootLog, structureId, associations, start, Index); break; } else { if (Index < Buffer.Length) { RootLog.AddError(", or } expected, but found " + Buffer[Index]); } else { RootLog.AddError(", or } expected, but EOF found "); } break; } } } } } if (retVal == null) { Index = start; } return retVal; }
/// <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; int token = context.LocalScope.PushContext(); AssignParameters(context, actuals); Function function = (Function) acceptor.getFactory().createFunction(); function.Name = "Override ( Default => " + getName(DefaultFunction) + ", Override => " + getName(OverrideFunction) + ")"; function.Enclosing = EFSSystem; function.Surface = CreateSurface(context, explain); Parameter parameter = (Parameter) acceptor.getFactory().createParameter(); parameter.Name = "X"; parameter.Type = EFSSystem.DoubleType; function.appendParameters(parameter); parameter = (Parameter) acceptor.getFactory().createParameter(); parameter.Name = "Y"; parameter.Type = EFSSystem.DoubleType; function.appendParameters(parameter); function.ReturnType = EFSSystem.DoubleType; retVal = function; context.LocalScope.PopContext(token); return retVal; }
/// <summary> /// Initialises the declared elements /// </summary> public void InitDeclaredElements() { DeclaredElements = new Dictionary<string, List<INamable>>(); ISubDeclaratorUtils.AppendNamable(this, IteratorVariable); ISubDeclaratorUtils.AppendNamable(this, PreviousIteratorVariable); }
/// <summary> /// Provides all constant values for this type /// </summary> /// <param name="scope"></param> /// <param name="retVal"></param> public void Constants(string scope, Dictionary<string, object> retVal) { if (Utils.Util.isEmpty(scope)) { retVal[True.Name] = True; retVal[False.Name] = False; } }
/// <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; AssignParameters(context, actuals); Graph graph = createGraphForValue(context, context.FindOnStack(FunctionA).Value, explain); 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 = (Parameter) function.FormalParameters[0]; Actual actual = functionParameter.CreateActual(); actual.Value = new DoubleValue(EFSSystem.DoubleType, speed); Dictionary<Actual, IValue> values = new Dictionary<Actual, IValue>(); values[actual] = new DoubleValue(EFSSystem.DoubleType, speed); IValue solution = function.Evaluate(context, values, explain); double doubleValue = GetDoubleValue(solution); if (doubleValue >= segment.Start && doubleValue <= segment.End) { retVal = new DoubleValue(EFSSystem.DoubleType, doubleValue); break; } } else { FunctionB.AddError("The FunctionB doesn't have any parameter"); break; } } else { FunctionA.AddError("The FunctionA is not a step function"); break; } } } else { FunctionA.AddError("Cannot create graph for " + FunctionA); } if (retVal == null) { FunctionA.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB); FunctionB.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB); } return retVal; }
/// <summary> /// Creates a test frame in the enclosing dictionary /// </summary> /// <param name="enclosing"></param> /// <param name="name"></param> /// <returns></returns> protected Frame CreateTestFrame(Dictionary enclosing, string name) { Frame retVal = (Frame) Factory.createFrame(); enclosing.appendTests(retVal); retVal.Name = name; 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, InterpretationContext context, Dictionary<string, Expression> actualParameters) { CheckFunctionalParameter(root, context, actualParameters[SpeedRestrictions.Name], 1); CheckFunctionalParameter(root, context, actualParameters[DecelerationFactor.Name], 2); }
/// <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; }
/// <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; }
/// <summary> /// Perform additional checks based on the parameter type /// </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, InterpretationContext context, Dictionary<string, Expression> actualParameters) { CheckFunctionalParameter(root, context, actualParameters[Targets.Name], 1); }
/// <summary> /// Initialises the declared elements /// </summary> public void InitDeclaredElements() { DeclaredElements = new Dictionary<string, List<INamable>>(); ISubDeclaratorUtils.AppendNamable(this, LastIteration); ISubDeclaratorUtils.AppendNamable(this, CurrentIteration); }