コード例 #1
0
ファイル: ChannelInput.cs プロジェクト: cnacha/PAT.ADL
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);
            try {
                ChannelQueue Buffer = null;

                string channelName = this.ChannelName;

                if (ChannelIndex != null)
                {
                    int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value;
                    if (size >= Specification.ChannelArrayDatabase[ChannelName])
                    {
                        throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString());
                    }
                    channelName = channelName + "[" + size + "]";
                }

                if (GlobalEnv.Channels.TryGetValue(channelName, out Buffer))
                {
                    if (Buffer.Count > 0)
                    {
                        ChannelQueue      newBuffer = Buffer.Clone();
                        ExpressionValue[] values    = newBuffer.Dequeue();

                        if (values.Length == ExpressionList.Length)
                        {
                            Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(values.Length);

                            Valuation newEnv = GlobalEnv.GetChannelClone();
                            newEnv.Channels[channelName] = newBuffer;

                            string eventName = channelName + "?";
                            string eventID   = channelName + "?";


                            for (int i = 0; i < ExpressionList.Length; i++)
                            {
                                ExpressionValue v = values[i];
                                if (i == ExpressionList.Length - 1)
                                {
                                    eventName += v;
                                    eventID   += v.ExpressionID;//.GetID();
                                }
                                else
                                {
                                    eventName += v + ".";
                                    eventID   += v.ExpressionID + ".";
                                }

                                if (ExpressionList[i] is Variable)
                                {
                                    mapping.Add(ExpressionList[i].ExpressionID, v); //.GetID()
                                }
                                else
                                {
                                    if (v.ExpressionID != ExpressionList[i].ExpressionID) //.GetID() .GetID()
                                    {
                                        return;                                           //list
                                    }
                                }
                            }

                            Process newProcess = mapping.Count > 0 ? Process.ClearConstant(mapping) : Process;

                            if (eventID != eventName)
                            {
                                list.Add(new Configuration(newProcess, eventID, eventName, newEnv, false));
                            }
                            else
                            {
                                list.Add(new Configuration(newProcess, eventID, null, newEnv, false));
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
            //return list;
        }
コード例 #2
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            ChannelQueue Buffer = null;

            string channelName = this.ChannelName;

            if (ChannelIndex != null)
            {
                int size = ((IntConstant)EvaluatorDenotational.Evaluate(ChannelIndex, GlobalEnv)).Value;
                if (size >= Specification.ChannelArrayDatabase[ChannelName])
                {
                    throw new PAT.Common.Classes.Expressions.ExpressionClass.IndexOutOfBoundsException("Channel index out of bounds for expression " + this.ToString());
                }

                channelName = channelName + "[" + size + "]";
            }

            if (GlobalEnv.Channels.TryGetValue(channelName, out Buffer))
            {
                if (Buffer.Count > 0)
                {
                    ChannelQueue      newBuffer = Buffer.Clone();
                    ExpressionValue[] values    = newBuffer.Dequeue();

                    if (values.Length == this.ExpressionList.Length)
                    {
                        Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(values.Length);

                        Valuation newChannelEvn = GlobalEnv.GetChannelClone();
                        newChannelEvn.Channels[channelName] = newBuffer;

                        string eventName = channelName + "?";
                        string eventID   = channelName + "?";

                        for (int i = 0; i < ExpressionList.Length; i++)
                        {
                            ExpressionValue v = values[i];
                            if (i == ExpressionList.Length - 1)
                            {
                                eventName += v;
                                eventID   += v.ExpressionID;
                            }
                            else
                            {
                                eventName += v + ".";
                                eventID   += v.ExpressionID + ".";
                            }

                            if (ExpressionList[i] is Variable)
                            {
                                mapping.Add(ExpressionList[i].ExpressionID, v);
                            }
                            else
                            {
                                if (v.ExpressionID != ExpressionList[i].ExpressionID)
                                {
                                    return; //list
                                }
                            }
                        }

                        Expression guard = GuardExpression.ClearConstant(mapping);

                        ExpressionValue value = EvaluatorDenotational.Evaluate(guard, newChannelEvn);

                        if ((value as BoolConstant).Value)
                        {
                            Valuation newGlobleEnv = newChannelEvn.GetVariableClone();

                            EvaluatorDenotational.Evaluate(AssignmentExpr.ClearConstant(mapping), newGlobleEnv);

                            if (HasLocalVar)
                            {
                                Valuation tempEnv = newChannelEvn.GetVariableClone();
                                for (int i = 0; i < tempEnv.Variables._entries.Length; i++)
                                {
                                    StringDictionaryEntryWithKey <ExpressionValue> pair = tempEnv.Variables._entries[i];
                                    if (pair != null)
                                    {
                                        pair.Value = newGlobleEnv.Variables[pair.Key];
                                    }
                                }

                                newGlobleEnv = tempEnv;
                            }

                            Process newProcess = mapping.Count > 0 ? Process.ClearConstant(mapping) : Process;

                            if (eventID != eventName)
                            {
                                list.Add(new Configuration(newProcess, eventID, eventName, newGlobleEnv, false));
                            }
                            else
                            {
                                list.Add(new Configuration(newProcess, eventID, null, newGlobleEnv, false));
                            }
                        }
                    }
                }
            }

            //return list;
        }
コード例 #3
0
        public override void MoveOneStep(Valuation GlobalEnv, List <Configuration> list)
        {
            System.Diagnostics.Debug.Assert(list.Count == 0);

            ChannelQueue Buffer = null;

            if (GlobalEnv.Channels.TryGetValue(this.ChannelName, out Buffer))
            {
                if (Buffer.Count > 0)
                {
                    ChannelQueue      newBuffer = Buffer.Clone();
                    ExpressionValue[] values    = newBuffer.Dequeue();

                    if (values.Length == ExpressionList.Length)
                    {
                        Dictionary <string, Expression> mapping = new Dictionary <string, Expression>(values.Length);

                        Valuation newEnv = GlobalEnv.GetChannelClone();
                        newEnv.Channels[ChannelName] = newBuffer;

                        string eventName = ChannelName + "?";
                        string eventID   = ChannelName + "?";


                        for (int i = 0; i < ExpressionList.Length; i++)
                        {
                            ExpressionValue v = values[i];
                            if (i == ExpressionList.Length - 1)
                            {
                                eventName += v;
                                eventID   += v.ExpressionID;//.GetID();
                            }
                            else
                            {
                                eventName += v + ".";
                                eventID   += v.ExpressionID + ".";
                            }

                            if (ExpressionList[i] is Variable)
                            {
                                mapping.Add(ExpressionList[i].ExpressionID, v); //.GetID()
                            }
                            else
                            {
                                if (v.ExpressionID != ExpressionList[i].ExpressionID) //.GetID() .GetID()
                                {
                                    return;                                           //list
                                }
                            }
                        }

                        Process newProcess = mapping.Count > 0 ? Process.ClearConstant(mapping) : Process;

                        if (eventID != eventName)
                        {
                            list.Add(new Configuration(newProcess, eventID, eventName, newEnv, false));
                        }
                        else
                        {
                            list.Add(new Configuration(newProcess, eventID, null, newEnv, false));
                        }
                    }
                }
            }

            //return list;
        }