/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply) { if (Call != null) { InterpretationContext ctxt = getContext(context); Functions.Procedure procedure = Call.getProcedure(ctxt); if (procedure != null) { ExplanationPart part = new ExplanationPart(Root); part.Message = procedure.FullName; explanation.SubExplanations.Add(part); int token = ctxt.LocalScope.PushContext(); foreach (KeyValuePair <Variables.Actual, Values.IValue> pair in Call.AssignParameterValues(context, procedure, true)) { ctxt.LocalScope.setVariable(pair.Key, pair.Value); } foreach (Rules.Rule rule in Rules) { ApplyRule(rule, changes, ctxt, part); } ctxt.LocalScope.PopContext(token); } else { AddError("Cannot determine the called procedure for " + ToString()); } } else { AddError("Expression " + ToString() + " is not a valid procedure call"); } }
/// <summary> /// Provides the changes performed by this statement /// </summary> /// <param name="context">The context on which the changes should be computed</param> /// <param name="changes">The list to fill with the changes</param> /// <param name="explanation">The explanatino to fill, if any</param> /// <param name="apply">Indicates that the changes should be applied immediately</param> /// <param name="runner"></param> public override void GetChanges(InterpretationContext context, ChangeList changes, ExplanationPart explanation, bool apply, Runner runner) { if (Call != null) { // Explain what happens in this statement explanation = ExplanationPart.CreateSubExplanation(explanation, this); InterpretationContext ctxt = GetContext(context, explanation); Procedure procedure = Call.GetProcedure(ctxt, explanation); if (procedure != null) { ctxt.HasSideEffects = true; // If the procedure has been defined in a structure, // ensure that it is applied to an instance of that structure Structure structure = procedure.Enclosing as Structure; if (structure != null) { ITypedElement current = ctxt.Instance as ITypedElement; while (current != null) { if (current.Type != structure) { current = current.Enclosing as ITypedElement; } else { ctxt.Instance = current; ExplanationPart.CreateSubExplanation(explanation, "Instance", current); current = null; } } } ExplanationPart part = ExplanationPart.CreateSubExplanation(explanation, procedure); if (ctxt.Instance is IVariable) { ExplanationPart.SetNamable(part, ctxt.Instance); ExplanationPart instanceExplanation = ExplanationPart.CreateSubExplanation(part, "instance = "); ExplanationPart.SetNamable(instanceExplanation, ctxt.Instance); } int token = ctxt.LocalScope.PushContext(); foreach ( KeyValuePair <Actual, IValue> pair in Call.AssignParameterValues(context, procedure, true, part)) { ctxt.LocalScope.SetVariable(pair.Key, pair.Value); } foreach (Rule rule in procedure.Rules) { ApplyRule(rule, changes, ctxt, part, runner); } ctxt.LocalScope.PopContext(token); } else { AddError("Cannot determine the called procedure for " + ToString(), RuleChecksEnum.ExecutionFailed); } } else { AddError("Expression " + ToString() + " is not a valid procedure call", RuleChecksEnum.ExecutionFailed); } }