コード例 #1
0
 private static void assignStatusAndSyncToAVariable(Module module, IVar variable)
 {
     if (variable is Variable)
     {
         CaseLine caseLine      = new CaseLine();
         Variable var           = (Variable)variable;
         String   exchangeState = SynchStates.EXCHANGE;
         //For Copy variables inside module
         if (var.Origin == VariableOrigin.Copy || var.Origin == VariableOrigin.CopyOfCommVar)
         {
             Expression result = new Expression("0");
             caseLine.Rule.Condition = getStatusAndSynchCondition(module, exchangeState);
             caseLine.Result         = result;
             var.Next.CaseStatement.CaseLines.Add(caseLine);
         }
         //For Original variables inside module
         else if (var.Origin == VariableOrigin.Original && var.Behaviour != VariableBehaviour.COMMUNICATION)
         {
             //if it has copy var, then add  var + var_cp
             if (module.isVariableExist(SMVPreFix.getCopyName(var)))
             {
                 OperExp result = new OperExp();
                 result.Exp        = variable.Name;
                 result.Oper.Value = MathOper.ADD;
                 //if variable is a division variable, then it has go to main part, like comm vars, so it will be instanced.
                 if (var.Behaviour == VariableBehaviour.DIVISION)
                 {
                     result.Result = new InstancedExp(variable.Name + SMVPreFix.COPY);
                 }
                 else
                 {
                     result.Result = new Expression(variable.Name + SMVPreFix.COPY);
                 }
                 ICondition boundCondition = getBoundCondition(var, result);
                 caseLine.Rule.Condition = new CompoundBoolExpression(getStatusAndSynchCondition(module, exchangeState), BinaryOperator.AND, boundCondition);
                 caseLine.Result         = result;
                 var.Next.CaseStatement.CaseLines.Add(caseLine);
             }
         }
         //for communication variables, goes into main module.
         else if (var.Origin == VariableOrigin.OriginalCommVar && var.Behaviour == VariableBehaviour.COMMUNICATION)
         {
             CaseLine commCaseLine = assignStatusAndSyncToACommVariable(module, var);
             var.Next.CaseStatement.CaseLines.Add(commCaseLine);
         }
     }
 }
コード例 #2
0
        private static CaseLine assignStatusAndSyncToACommVariable(Module module, Variable variable)
        {
            CaseLine commCaseLine = new CaseLine();
            OperExp  result       = new OperExp();

            result.Exp        = new InstancedExp(module.Instance.Name, variable.Name).ToString();
            result.Oper.Value = MathOper.ADD;
            //if it has copy var, then add  var + var_cp
            string res = "";

            if (module.isVariableExist(SMVPreFix.getCopyName(variable)))
            {
                res += new InstancedExp(module.Instance.Name, SMVPreFix.getCopyName(variable));
            }
            foreach (var connectedInstance in module.Instance.ConnectedTo)
            {
                if (connectedInstance.Module.isVariableExist(SMVPreFix.getConnectedCopyCommVarName(variable, module)))
                {
                    if (!string.IsNullOrWhiteSpace(res))
                    {
                        res += " + ";
                    }

                    res += new InstancedExp(connectedInstance.Name, SMVPreFix.getConnectedCopyCommVarName(variable, module));
                }
            }
            result.Result = new Expression(res);

            //(c1.status = _ACTIVE)
            CompoundBoolExpression statusAndSync = getInstancedStatusAndSyncCondition(module);

            ICondition boundCondition = getBoundCondition(variable, result);

            ICondition compound = new CompoundBoolExpression(statusAndSync, BinaryOperator.AND, boundCondition);

            CommunicationRule rule = new CommunicationRule();

            rule.Condition = compound;
            //commCaseLine.Rule.Condition = compound;
            commCaseLine.Rule   = rule;
            commCaseLine.Result = result;
            return(commCaseLine);
        }