/// <summary> /// Take care of all conditions /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(Generated.RuleCondition obj, bool visitSubNodes) { RuleCondition ruleCondition = (RuleCondition)obj; if (ruleCondition.Uses(Target)) { Usages.Add(ruleCondition); } base.visit(obj, visitSubNodes); }
public override void visit(Generated.RuleCondition obj, bool subNodes) { Rules.RuleCondition ruleCondition = obj as Rules.RuleCondition; if (ruleCondition != null) { try { bool found = false; ruleCondition.Messages.Clear(); foreach (Rules.PreCondition preCondition in ruleCondition.PreConditions) { Interpreter.BinaryExpression expression = checkExpression(preCondition, preCondition.Expression) as Interpreter.BinaryExpression; if (expression != null) { if (expression.IsSimpleEquality()) { Types.ITypedElement variable = expression.Left.Ref as Types.ITypedElement; if (variable != null) { if (variable.Type != null) { // Check that when preconditions are based on a request, // the corresponding action affects the value Request.Disabled to the same variable if (variable.Type.Name.Equals("Request") && expression.Right != null && expression.Right is Interpreter.UnaryExpression) { Values.IValue val2 = expression.Right.Ref as Values.IValue; if (val2 != null && "Response".CompareTo(val2.Name) == 0) { if (ruleCondition != null) { found = false; foreach (Rules.Action action in ruleCondition.Actions) { Variables.IVariable var = OverallVariableFinder.INSTANCE.findByName(action, preCondition.findVariable()); Interpreter.Statement.VariableUpdateStatement update = action.Modifies(var); if (update != null) { Interpreter.UnaryExpression updateExpr = update.Expression as Interpreter.UnaryExpression; if (updateExpr != null) { Values.IValue val3 = updateExpr.Ref as Values.IValue; if (val3 != null && val3.Name.CompareTo("Disabled") == 0) { found = true; break; } } } } if (!found) { preCondition.AddError("Rules where the Pre conditions is based on a Request type variable must assign that variable the value 'Request.Disabled'"); } } } } } // Check that the outgoing variables are not read if (variable.Mode == Generated.acceptor.VariableModeEnumType.aOutgoing) { if (ruleCondition.Reads(variable)) { preCondition.AddError("An outgoing variable cannot be read"); } } // Check that the incoming variables are not modified if (variable.Mode == Generated.acceptor.VariableModeEnumType.aIncoming) { if (ruleCondition.Modifies(variable) != null) { preCondition.AddError("An incoming variable cannot be written"); } } } } } } } catch (Exception exception) { ruleCondition.AddException(exception); } } base.visit(obj, subNodes); }
/// <summary> /// Check if this rule corresponds to a transition for this state machine /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(Generated.RuleCondition obj, bool visitSubNodes) { Rules.RuleCondition ruleCondition = (Rules.RuleCondition)obj; foreach (Rules.Action action in ruleCondition.Actions) { foreach (Interpreter.Statement.VariableUpdateStatement update in action.UpdateStatements) { Types.Type targetType = update.TargetType; if (targetType is StateMachine) { Interpreter.Expression expressionTree = update.Expression; if (expressionTree != null) { // HaCK: This is a bit rough, but should be sufficient for now... foreach (Constants.State stt1 in GetStates(expressionTree)) { // TargetState is the target state either in this state machine or in a sub state machine Constants.State targetState = StateMachine.StateInThisStateMachine(stt1); int transitionCount = Transitions.Count; bool filteredOut = false; // Finds the enclosing state of this action to determine the source state of this transition Constants.State enclosingState = Utils.EnclosingFinder <Constants.State> .find(action); if (enclosingState != null) { filteredOut = filteredOut || AddTransition(update, stt1, null, enclosingState); } if (!filteredOut) { foreach (Rules.PreCondition preCondition in ruleCondition.AllPreConditions) { // A transition from one state to another has been found foreach (Constants.State stt2 in GetStates(preCondition.ExpressionTree)) { filteredOut = filteredOut || AddTransition(update, stt1, preCondition, stt2); } } } if (Transitions.Count == transitionCount) { if (targetState == stt1 && targetState.EnclosingStateMachine == StateMachine) { if (!filteredOut) { // No precondition could be found => one can reach this state at anytime Transitions.Add(new Rules.Transition(null, null, update, targetState)); } } } } } else { action.AddError("Cannot parse expression"); } } } } base.visit(obj, visitSubNodes); }
/// <summary> /// Cleans all text fields in this element /// </summary> /// <param name="obj"></param> /// <param name="visitSubNodes"></param> public override void visit(Generated.RuleCondition obj, bool visitSubNodes) { base.visit(obj, visitSubNodes); }