/// <summary> /// Provides the statement which modifies the element /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(Types.ITypedElement variable) { VariableUpdateStatement retVal = null; if (variable == Target) { retVal = this; } return(retVal); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(ITypedElement variable) { VariableUpdateStatement retVal = null; foreach (Action action in Actions) { retVal = action.Modifies(variable); if (retVal != null) { break; } } return(retVal); }
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> /// Provides the Term at position Index of the Buffer. /// </summary> /// <param name="root">The root element for which this term is built</param> /// <returns></returns> private Statement.Statement Statement(ModelElement root) { Statement.Statement retVal = null; Root = root; if (LookAhead("APPLY")) { Match("APPLY"); Call callExpression = Expression(0) as Call; if (callExpression != null) { Statement.ProcedureCallStatement call = new Statement.ProcedureCallStatement(root, callExpression); Match("ON"); Expression listExpression = Expression(0); Expression condition = null; if (LookAhead("|")) { Match("|"); condition = Expression(0); } retVal = new Statement.ApplyStatement(root, call, listExpression, condition); } else { Root.AddError("Cannot parse call expression"); } } else if (LookAhead("INSERT")) { Match("INSERT"); Expression value = Expression(0); if (value != null) { Match("IN"); Expression list = Expression(0); Expression replaceElement = null; if (LookAhead("WHEN")) { Match("WHEN"); Match("FULL"); Match("REPLACE"); replaceElement = Expression(0); } retVal = new Statement.InsertStatement(root, value, list, replaceElement); } } else if (LookAhead("REMOVE")) { Match("REMOVE"); Statement.RemoveStatement.PositionEnum position = Interpreter.Statement.RemoveStatement.PositionEnum.First; if (LookAhead("FIRST")) { Match("FIRST"); } else if (LookAhead("LAST")) { Match("LAST"); position = Interpreter.Statement.RemoveStatement.PositionEnum.Last; } else if (LookAhead("ALL")) { Match("ALL"); position = Interpreter.Statement.RemoveStatement.PositionEnum.All; } Expression condition = null; if (!LookAhead("IN")) { condition = Expression(0); } Match("IN"); Expression list = Expression(0); retVal = new Statement.RemoveStatement(root, condition, position, list); } else if (LookAhead("REPLACE")) { Match("REPLACE"); Expression condition = Expression(0); Match("IN"); Expression list = Expression(0); Match("BY"); Expression value = Expression(0); retVal = new Statement.ReplaceStatement(root, value, list, condition); } else { Expression expression = Expression(0); if (expression != null) { if (LookAhead("<-")) { // This is a variable update Match("<-"); if (LookAhead("%")) { Match("%"); } Expression expression2 = Expression(0); if (expression2 != null) { retVal = new Statement.VariableUpdateStatement(root, expression, expression2); } else { Root.AddError("Invalid <- right side"); } expression.Enclosing = retVal; } else { // This is a procedure call Call call = expression as Call; if (call != null) { retVal = new Statement.ProcedureCallStatement(root, call); } else { Root.AddError("Cannot parse call expression"); } } } else { Root.AddError("Cannot parse expression"); } } return(retVal); }
/// <summary> /// Visits a Variable update statement /// </summary> /// <param name="variableUpdateStatement"></param> protected virtual void VisitVariableUpdateStatement(VariableUpdateStatement variableUpdateStatement) { if (variableUpdateStatement.VariableIdentification != null) { VisitExpression(variableUpdateStatement.VariableIdentification); } if (variableUpdateStatement.Expression != null) { VisitExpression(variableUpdateStatement.Expression); } }
/// <summary> /// Adds a transition in the transitions sets /// </summary> /// <param name="update">The update state which provides the target of the transition</param> /// <param name="target">The target state, as determined by the update statement</param> /// <param name="filteredOut"></param> /// <param name="preCondition">the precondition (if any) which is used to determine the initial state</param> /// <param name="initial">The initial state</param> /// <returns> /// true if the transition has been filtered out. A transition can be filtered out if the target state is equal to the /// initial state or the initial state is null /// </returns> private bool AddTransition(VariableUpdateStatement update, State target, PreCondition preCondition, State initial) { bool retVal = false; if (SameParentStateMachine(initial, target)) { State initialState = StateMachine.StateInThisStateMachine(initial); // TargetState is the target state either in this state machine or in a sub state machine State targetState = StateMachine.StateInThisStateMachine(target); // Determine the rule condition (if any) related to this state machine Rules.RuleCondition condition = null; if (update != null) { Action action = update.Root as Action; condition = action.RuleCondition; } if (targetState != null || initialState != null) { // This transition is about this state machine. if (initialState != targetState && initialState != null) { // Check that the transition is not yet present // This case can occur when the same RuleCondition references two different states // in a substate machine. Only draws the transition once. if (!findMatchingTransition(condition, initialState, targetState)) { Transitions.Add(new Transition(preCondition, initialState, update, targetState)); } } else { if (initialState == initial) { retVal = true; } } } } return retVal; }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(ITypedElement variable) { VariableUpdateStatement retVal = AppliedStatement.Modifies(variable); return(retVal); }
/// <summary> /// Provides the statement which modifies the variable /// </summary> /// <param name="variable"></param> /// <returns>null if no statement modifies the element</returns> public override VariableUpdateStatement Modifies(Types.ITypedElement variable) { VariableUpdateStatement retVal = null; return(retVal); }
/// <summary> /// Parses a statement /// </summary> /// <returns></returns> private Statement.Statement InnerParseStatement() { Statement.Statement retVal = null; int start = Index; if (LookAhead("APPLY")) { Match("APPLY"); Statement.Statement appliedStatement = InnerParseStatement(); if (appliedStatement != null) { Match("ON"); Expression listExpression = Expression(0); Expression condition = null; if (LookAhead("|")) { Match("|"); condition = Expression(0); } retVal = new ApplyStatement(Root, RootLog, appliedStatement, listExpression, condition, start, Index); } else { RootLog.AddError("Cannot parse call expression"); } } else if (LookAhead("INSERT")) { Match("INSERT"); Expression value = Expression(0); if (value != null) { Match("IN"); Expression list = Expression(0); Expression replaceElement = null; if (LookAhead("WHEN")) { Match("WHEN"); Match("FULL"); Match("REPLACE"); replaceElement = Expression(0); } retVal = new InsertStatement(Root, RootLog, value, list, replaceElement, start, Index); } } else if (LookAhead("REMOVE")) { Match("REMOVE"); RemoveStatement.PositionEnum position = RemoveStatement.PositionEnum.First; if (LookAhead("FIRST")) { Match("FIRST"); } else if (LookAhead("LAST")) { Match("LAST"); position = RemoveStatement.PositionEnum.Last; } else if (LookAhead("ALL")) { Match("ALL"); position = RemoveStatement.PositionEnum.All; } Expression condition = null; if (!LookAhead("IN")) { condition = Expression(0); } Match("IN"); Expression list = Expression(0); retVal = new RemoveStatement(Root, RootLog, condition, position, list, start, Index); } else if (LookAhead("REPLACE")) { Match("REPLACE"); Expression condition = Expression(0); Match("IN"); Expression list = Expression(0); Match("BY"); Expression value = Expression(0); retVal = new ReplaceStatement(Root, RootLog, value, list, condition, start, Index); } else { Expression expression = Expression(0); if (expression != null) { string assignOp = LookAhead(AssignOps); if (assignOp != null) { // This is a variable update Match(assignOp); if (LookAhead("%")) { Match("%"); } Expression expression2 = Expression(0); if (expression2 != null) { retVal = new VariableUpdateStatement(Root, RootLog, expression, expression2, start, Index); } else { RootLog.AddError("Invalid <- right side"); } expression.Enclosing = retVal; } else { // This is a procedure call Call call = expression as Call; if (call != null) { retVal = new ProcedureCallStatement(Root, RootLog, call, start, Index); } } } } return retVal; }
/// <summary> /// Provides the Term at position Index of the Buffer. /// </summary> /// <param name="root">The root element for which this term is built</param> /// <returns></returns> private Statement.Statement Statement(ModelElement root) { Statement.Statement retVal = null; Root = root; if (LookAhead("APPLY")) { Match("APPLY"); Call callExpression = Expression(0) as Call; if (callExpression != null) { Statement.ProcedureCallStatement call = new Statement.ProcedureCallStatement(root, callExpression); Match("ON"); Expression listExpression = Expression(0); Expression condition = null; if (LookAhead("|")) { Match("|"); condition = Expression(0); } retVal = new Statement.ApplyStatement(root, call, listExpression, condition); } else { Root.AddError("Cannot parse call expression"); } } else if (LookAhead("INSERT")) { Match("INSERT"); Expression value = Expression(0); if (value != null) { Match("IN"); Expression list = Expression(0); Expression replaceElement = null; if (LookAhead("WHEN")) { Match("WHEN"); Match("FULL"); Match("REPLACE"); replaceElement = Expression(0); } retVal = new Statement.InsertStatement(root, value, list, replaceElement); } } else if (LookAhead("REMOVE")) { Match("REMOVE"); Statement.RemoveStatement.PositionEnum position = Interpreter.Statement.RemoveStatement.PositionEnum.First; if (LookAhead("FIRST")) { Match("FIRST"); } else if (LookAhead("LAST")) { Match("LAST"); position = Interpreter.Statement.RemoveStatement.PositionEnum.Last; } else if (LookAhead("ALL")) { Match("ALL"); position = Interpreter.Statement.RemoveStatement.PositionEnum.All; } Expression condition = null; if (!LookAhead("IN")) { condition = Expression(0); } Match("IN"); Expression list = Expression(0); retVal = new Statement.RemoveStatement(root, condition, position, list); } else if (LookAhead("REPLACE")) { Match("REPLACE"); Expression condition = Expression(0); Match("IN"); Expression list = Expression(0); Match("BY"); Expression value = Expression(0); retVal = new Statement.ReplaceStatement(root, value, list, condition); } else { Expression expression = Expression(0); if (expression != null) { if (LookAhead("<-")) { // This is a variable update Match("<-"); if (LookAhead("%")) { Match("%"); } Expression expression2 = Expression(0); if (expression2 != null) { retVal = new Statement.VariableUpdateStatement(root, expression, expression2); } else { Root.AddError("Invalid <- right side"); } expression.Enclosing = retVal; } else { // This is a procedure call Call call = expression as Call; if (call != null) { retVal = new Statement.ProcedureCallStatement(root, call); } else { Root.AddError("Cannot parse call expression"); } } } else { Root.AddError("Cannot parse expression"); } } return retVal; }