public void TestListExpression() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Structure s1 = CreateStructure(n1, "S1"); StructureElement el1 = CreateStructureElement(s1, "E1", "Boolean"); Structure s2 = CreateStructure(n1, "S2"); StructureElement el2 = CreateStructureElement(s2, "E2", "S1"); Function function = CreateFunction(n1, "f", "S1"); Collection collection = CreateCollection(n1, "Col", "S1", 10); Variable v = CreateVariable(n1, "V", "Col"); Compiler.Compile_Synchronous(true, true); RuleCondition rc = CreateRuleAndCondition(n1, "Rule1"); Parser parser = new Parser(); { VariableUpdateStatement statement = parser.Statement(rc, "V <- [S1 { E1 => Tr", true, true) as VariableUpdateStatement; Assert.IsNotNull(statement); UnaryExpression unaryExpression = statement.Expression as UnaryExpression; Assert.IsNotNull(unaryExpression); ListExpression listExpression = unaryExpression.Term.LiteralValue as ListExpression; Assert.IsNotNull(listExpression); Assert.AreEqual(listExpression.ListElements.Count, 1); StructExpression structExpression = listExpression.ListElements[0] as StructExpression; Assert.IsNotNull(structExpression); } }
/// <summary> /// Constructor /// </summary> /// <param name="preCondition">The precondition which setup the initial state</param> /// <param name="initialState">The initial stae of this transition</param> /// <param name="update">The statement which set up the target state</param> /// <param name="targetState">The target state of this transition</param> public Transition(PreCondition preCondition, State initialState, VariableUpdateStatement update, State targetState) { PreCondition = preCondition; Source = initialState; Update = update; Target = targetState; }
public void TestFunctionCall() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Structure s1 = CreateStructure(n1, "S1"); StructureElement el1 = CreateStructureElement(s1, "E1", "Boolean"); Structure s2 = CreateStructure(n1, "S2"); StructureElement el2 = CreateStructureElement(s2, "E2", "S1"); Variable v = CreateVariable(n1, "V", "S1"); v.setDefaultValue("N1.S1 { E1 => True }"); Function function = CreateFunction(n1, "f", "S1"); Compiler.Compile_Synchronous(true, true); RuleCondition rc = CreateRuleAndCondition(n1, "Rule1"); Parser parser = new Parser(); { // 0 1 // 012345678901 const string text = "V <- f().S"; VariableUpdateStatement statement = parser.Statement(rc, text, true, true) as VariableUpdateStatement; ContextGrabber grabber = new ContextGrabber(); Assert.AreEqual(v, grabber.GetContext(0, statement)); Assert.AreEqual(v, grabber.GetContext(1, statement)); Assert.IsNull(grabber.GetContext(2, statement)); Assert.IsNull(grabber.GetContext(3, statement)); Assert.IsNull(grabber.GetContext(4, statement)); Assert.AreEqual(function, grabber.GetContext(5, statement)); Assert.AreEqual(function, grabber.GetContext(6, statement)); Assert.AreEqual(function, grabber.GetContext(7, statement)); Assert.AreEqual(s1, grabber.GetContext(8, statement)); Assert.IsNull(grabber.GetContext(9, statement)); Assert.IsNull(grabber.GetContext(10, statement)); } { // 0 // 0123456789 const string text = "V <- f()."; VariableUpdateStatement statement = parser.Statement(rc, text, true, true) as VariableUpdateStatement; ContextGrabber grabber = new ContextGrabber(); Assert.AreEqual(v, grabber.GetContext(0, statement)); Assert.AreEqual(v, grabber.GetContext(1, statement)); Assert.IsNull(grabber.GetContext(2, statement)); Assert.IsNull(grabber.GetContext(3, statement)); Assert.IsNull(grabber.GetContext(4, statement)); Assert.AreEqual(function, grabber.GetContext(5, statement)); Assert.AreEqual(function, grabber.GetContext(6, statement)); Assert.AreEqual(function, grabber.GetContext(7, statement)); Assert.AreEqual(s1, grabber.GetContext(8, statement)); Assert.IsNull(grabber.GetContext(9, statement)); } }
/// <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> /// Browses through the statement to find the structures to edit /// </summary> /// <param name="statement"></param> private Statement VisitStatement(Statement statement) { Statement retVal = statement; VariableUpdateStatement variableUpdateStatement = statement as VariableUpdateStatement; if (variableUpdateStatement != null) { variableUpdateStatement.Expression = VisitExpression(variableUpdateStatement.Expression); } return(retVal); }
/// <summary> /// Indicates the name of the updated variable, if any /// </summary> /// <returns></returns> public string UpdatedVariable() { string retVal = null; VariableUpdateStatement update = Statement as VariableUpdateStatement; if (update != null) { retVal = update.VariableIdentification.ToString(); } 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 VariableUpdateStatement Modifies(ITypedElement variable) { VariableUpdateStatement retVal = null; foreach (Action action in Actions) { retVal = action.Modifies(variable); if (retVal != null) { return(retVal); } } return(retVal); }
public void TestListExpression() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Structure s1 = CreateStructure(n1, "S1"); StructureElement el1 = CreateStructureElement(s1, "E1", "Boolean"); Structure s2 = CreateStructure(n1, "S2"); StructureElement el2 = CreateStructureElement(s2, "E2", "S1"); Function function = CreateFunction(n1, "f", "S1"); Collection collection = CreateCollection(n1, "Col", "S1", 10); Variable v = CreateVariable(n1, "V", "Col"); Compiler.Compile_Synchronous(true, true); RuleCondition rc = CreateRuleAndCondition(n1, "Rule1"); Parser parser = new Parser(); { // 0 1 2 // 012345678901234567890123456 const string text = "V <- [S1 { E1 => Tr"; VariableUpdateStatement statement = parser.Statement(rc, text, true, true) as VariableUpdateStatement; ContextGrabber grabber = new ContextGrabber(); Assert.AreEqual(v, grabber.GetContext(0, statement)); Assert.AreEqual(v, grabber.GetContext(1, statement)); Assert.IsNull(grabber.GetContext(2, statement)); Assert.IsNull(grabber.GetContext(3, statement)); Assert.IsNull(grabber.GetContext(4, statement)); Assert.IsNull(grabber.GetContext(5, statement)); Assert.AreEqual(s1, grabber.GetContext(6, statement)); Assert.AreEqual(s1, grabber.GetContext(7, statement)); Assert.AreEqual(s1, grabber.GetContext(8, statement)); Assert.AreEqual(s1, grabber.GetContext(9, statement)); Assert.AreEqual(s1, grabber.GetContext(10, statement)); Assert.AreEqual(s1, grabber.GetContext(11, statement)); Assert.AreEqual(s1, grabber.GetContext(12, statement)); Assert.AreEqual(s1, grabber.GetContext(13, statement)); Assert.AreEqual(s1, grabber.GetContext(14, statement)); Assert.AreEqual(s1, grabber.GetContext(15, statement)); Assert.AreEqual(s1, grabber.GetContext(16, statement)); Assert.IsNull(grabber.GetContext(17, statement)); Assert.IsNull(grabber.GetContext(18, statement)); } }
/// <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> /// Splits the selected action to several sub-actions /// </summary> public virtual void SplitHandler(object sender, EventArgs args) { Statement statement = new Parser().Statement(Item, Item.ExpressionText); VariableUpdateStatement variableUpdateStatement = statement as VariableUpdateStatement; if (variableUpdateStatement != null) { Expression expression = variableUpdateStatement.Expression; StructExpression structExpression = expression as StructExpression; if (structExpression != null) { Dictionary <Designator, Expression> associations = structExpression.Associations; foreach (KeyValuePair <Designator, Expression> value in associations) { Action action = (Action)acceptor.getFactory().createAction(); action.ExpressionText = structExpression.Structure + "." + value.Key + " <- " + value.Value; ActionTreeNode actionTreeNode = new ActionTreeNode(action, true); BaseTreeNode parent = Parent as BaseTreeNode; if (parent != null) { RuleCondition ruleCondition = Item.Enclosing as RuleCondition; if (ruleCondition != null) { ruleCondition.appendActions(action); } else { SubStep subStep = Item.Enclosing as SubStep; if (subStep != null) { subStep.appendActions(action); } } parent.Nodes.Add(actionTreeNode); } } } } Delete(); }
public void TestFunctionCall() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Structure s1 = CreateStructure(n1, "S1"); StructureElement el1 = CreateStructureElement(s1, "E1", "Boolean"); Structure s2 = CreateStructure(n1, "S2"); StructureElement el2 = CreateStructureElement(s2, "E2", "S1"); Variable v = CreateVariable(n1, "V", "S1"); v.setDefaultValue("N1.S1 { E1 => True }"); Function function = CreateFunction(n1, "f", "S1"); Compiler.Compile_Synchronous(true, true); RuleCondition rc = CreateRuleAndCondition(n1, "Rule1"); Parser parser = new Parser(); { VariableUpdateStatement statement = parser.Statement(rc, "V <- f().S", true, true) as VariableUpdateStatement; Assert.IsNotNull(statement); Assert.AreEqual(statement.VariableIdentification.Ref, v); DerefExpression deref = statement.Expression as DerefExpression; Assert.IsNotNull(deref); Assert.AreEqual(deref.Arguments[0].Ref, s1); } { VariableUpdateStatement statement = parser.Statement(rc, "V <- f().", true, true) as VariableUpdateStatement; Assert.IsNotNull(statement); Assert.AreEqual(statement.VariableIdentification.Ref, v); DerefExpression deref = statement.Expression as DerefExpression; Assert.IsNotNull(deref); Assert.AreEqual(deref.Arguments[0].Ref, s1); } }