Esempio n. 1
0
        public PrtEventBuffer CloneAndResolve(StateImpl s)
        {
            PrtEventBuffer x = Clone();

            x.Resolve(s);
            return(x);
        }
Esempio n. 2
0
        public PrtSpecMachine Clone(StateImpl app)
        {
            var clonedMachine = MakeSkeleton();

            //base class fields
            clonedMachine.instanceNumber = this.instanceNumber;
            foreach (var fd in fields)
            {
                clonedMachine.fields.Add(fd.Clone());
            }
            clonedMachine.eventValue       = this.eventValue;
            clonedMachine.stateStack       = this.stateStack.Clone();
            clonedMachine.invertedFunStack = this.invertedFunStack.Clone();
            clonedMachine.continuation     = this.continuation.Clone();
            clonedMachine.currentTrigger   = this.currentTrigger;
            clonedMachine.currentPayload   = this.currentPayload.Clone();

            clonedMachine.currentStatus   = this.currentStatus;
            clonedMachine.nextSMOperation = this.nextSMOperation;
            clonedMachine.stateExitReason = this.stateExitReason;
            clonedMachine.sends           = this.sends;
            clonedMachine.renamedName     = this.renamedName;
            clonedMachine.isSafe          = this.isSafe;
            clonedMachine.stateImpl       = app;

            //spec class fields
            clonedMachine.observes           = this.observes.ToList();
            clonedMachine.currentTemperature = this.currentTemperature;

            return(clonedMachine);
        }
Esempio n. 3
0
 public void Resolve(StateImpl state)
 {
     foreach (var f in funStack)
     {
         f.Resolve(state);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Add <paramref name="this"/> to abstract successors if <paramref name="this"/> satisfies the invariants.
        /// </summary>
        /// <param name="currIndex"></param>
        /// <param name="pred"></param>
        /// <param name="abstract_succs"></param>
        /// <param name="abstract_succs_SW"></param>
        void AddToAbstractSuccessorsIfInvSat(int currIndex, StateImpl pred, HashSet <int> abstract_succs, StreamWriter abstract_succs_SW)
        {
            int p_hash = symmetryReduction ? pred.GetHashCode(true) : pred.GetHashCode();
            int hash   = symmetryReduction ?      GetHashCode(true) :      GetHashCode();

            // Console.WriteLine(this.ToPrettyString());

            if (mode == ExploreMode.Find_A_AP) // if we are locating a and ap
            {
                if (succHash == hash)
                {
                    predHash = p_hash;
                    throw new SuccessorFound(pred, this);
                }
            }

            if (invariant ? CheckAbstractStateInvariant(currIndex) && CheckTransInvariant(currIndex, pred) : true)
            {
                if (abstract_succs.Add(hash))
                {
                    if (FileDump)
                    {
                        abstract_succs_SW.Write(ToPrettyString());
                        abstract_succs_SW.WriteLine("==================================================");
                    }
                }
            }
        }
Esempio n. 5
0
        public PrtEventNode Clone_Resolve(StateImpl s)
        {
            PrtEventNode x = Clone();

            x.Resolve(s);
            return(x);
        }
Esempio n. 6
0
 public PrtSpecMachine(StateImpl app) : base()
 {
     observes           = new List <PrtEventValue>();
     currentTemperature = StateTemperature.Warm;
     stateImpl          = app;
     //Push the start state function on the funStack.
     PrtPushState(StartState);
 }
Esempio n. 7
0
 public virtual void Resolve(StateImpl state)
 {
     fields.ForEach(v => v.Resolve(state));
     eventValue.Resolve(state);
     invertedFunStack.Resolve(state);
     continuation.Resolve(state);
     currentTrigger.Resolve(state);
     currentPayload.Resolve(state);
 }
Esempio n. 8
0
 public PrtSpecMachine(StateImpl app) : base()
 {
     observes  = new List <PrtEventValue>();
     IsHot     = false;
     stateImpl = app;
     //Push the start state function on the funStack.
     PrtPushState(StartState);
     //Execute the entry function
     PrtEnqueueEvent(PrtValue.@null, PrtValue.@null, null);
 }
Esempio n. 9
0
 public PrtValue ExecuteToCompletion(StateImpl application, PrtMachine parent, params PrtValue[] args)
 {
     parent.PrtPushFunStackFrame(this, CreateLocals(args));
     Execute(application, parent);
     if (parent.continuation.reason != PrtContinuationReason.Return)
     {
         throw new PrtInternalException("Unexpected continuation reason");
     }
     return(parent.continuation.retVal.Clone());
 }
Esempio n. 10
0
 public PrtImplMachine(StateImpl app, int maxBuff) : base()
 {
     this.instanceNumber = this.NextInstanceNumber(app);
     this.eventQueue     = new PrtEventBuffer();
     this.receiveSet     = new HashSet <PrtValue>();
     this.maxBufferSize  = maxBuff;
     this.stateImpl      = app;
     //Push the start state function on the funStack.
     PrtPushState(StartState);
 }
Esempio n. 11
0
 public PrtSpecMachine(StateImpl app) : base()
 {
     observes           = new List <PrtEventValue>();
     currentTemperature = StateTemperature.Warm;
     stateImpl          = app;
     //Push the start state function on the funStack.
     PrtPushState(StartState);
     //Execute the entry function
     PrtEnqueueEvent(PrtValue.@null, PrtValue.@null, null);
 }
Esempio n. 12
0
        public override void Resolve(StateImpl state)
        {
            var list = keyToValueMap.ToList();

            list.ForEach(tup =>
            {
                tup.Key.Resolve(state);
                tup.Value.Resolve(state);
            });
            keyToValueMap = new Dictionary <PrtMapKey, PrtValue>();
            list.ForEach(tup => keyToValueMap.Add(tup.Key, tup.Value));
        }
Esempio n. 13
0
 public PrtImplMachine(StateImpl app, int maxBuff, bool assume) : base()
 {
     this.instanceNumber = this.NextInstanceNumber(app);
     this.eventQueue     = new PrtEventBuffer();
     this.receiveSet     = new HashSet <PrtValue>();
     this.maxBufferSize  = maxBuff;
     this.doAssume       = assume;
     this.stateImpl      = app;
     this.self           = new PrtInterfaceValue(this, new List <PrtEventValue>());
     //Push the start state function on the funStack.
     PrtPushState(StartState);
 }
Esempio n. 14
0
        public PrtMachine()
        {
            this.instanceNumber   = 0;
            this.fields           = new List <PrtValue>();
            this.eventValue       = PrtValue.NullValue;
            this.stateStack       = new PrtStateStack();
            this.invertedFunStack = new PrtFunStack();
            this.continuation     = new PrtContinuation();
            this.currentTrigger   = PrtValue.NullValue;
            this.currentPayload   = PrtValue.NullValue;
            this.currentStatus    = PrtMachineStatus.Enabled;
            this.nextSMOperation  = PrtNextStatemachineOperation.EntryOperation;
            this.stateExitReason  = PrtStateExitReason.NotExit;

            this.stateImpl = null;
        }
Esempio n. 15
0
        public void DbgCompare(StateImpl state)
        {
            Debug.Assert(implMachines.Count == state.implMachines.Count);
            for (int i = 0; i < implMachines.Count; i++)
            {
                implMachines[i].DbgCompare(state.implMachines[i]);
            }

            Debug.Assert(specMachinesMap.Count == state.specMachinesMap.Count);
            foreach (var tup in specMachinesMap)
            {
                Debug.Assert(state.specMachinesMap.ContainsKey(tup.Key));
                tup.Value.DbgCompare(state.specMachinesMap[tup.Key]);
            }

            Debug.Assert(GetHashCode() == state.GetHashCode());
        }
Esempio n. 16
0
        /// <summary>
        /// Compute the abstract successors caused by updating the queue of <paramref name="currIndex"/> machine.
        ///
        /// </summary>
        /// <param name="currIndex">The index for the machine about to explore</param>
        /// <param name="abstract_succs"></param>
        /// <param name="abstract_succs_SW"></param>
        void CollectAbstractSuccessorsFromList(int currIndex, HashSet <int> abstract_succs, StreamWriter abstract_succs_SW)
        {
            List <PrtEventNode> preDequeEvents = ImplMachines[currIndex].eventQueue.events; // pre-dequeue events list

            var  choiceVector = new List <bool>();
            bool more;

            do
            {
                StateImpl           succ           = (StateImpl)Clone();
                PrtImplMachine      machineOfSucc  = succ.ImplMachines[currIndex]; // the machine of successor indexing in currIndex
                PrtEventBuffer      queueOfMachine = machineOfSucc.eventQueue;     // the message queue of successor machine
                List <PrtEventNode> queueEvents    = queueOfMachine.events;        // the events list of successor machine

                more = machineOfSucc.PrtRunStateMachineNextChoice(choiceVector);
                Debug.Assert(preDequeEvents.Count - queueOfMachine.Size() <= 1); // we have dequeued at most one event
                /// If dequeing was unsuccessful, then there is nothing left to do.
                /// No more nondeterministic choices to try
                if (preDequeEvents.Count == queueOfMachine.Size() || succ.CheckFailure(0)) //
                {
                    return;                                                                //
                }
                int          idxOfEventDequeuedFromSuffix = Math.Max(PrtEventBuffer.idxOfLastDequeuedEvent, PrtEventBuffer.p);
                PrtEventNode eventDequeuedFromSuffix      = preDequeEvents[idxOfEventDequeuedFromSuffix];

                /// <remarks>Choice 1: </remarks> The eventDequeuedFromSuffix, aka the last dequeued event, existed
                /// exactly once in the concrete suffix.
                /// Then it is gone after the dequeue, in both abstract and concrete. The new state abstract is valid.
                succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);

                ///  <remarks>Choice 1: </remarks> The eventDequeuedFromSuffix, aka the last dequeued event, existed
                ///  >= twice in concrete suffix.
                ///  We need to find all positions where to re-introduce it in the abstract queue, and try them all
                ///  non-deterministically.
                for (int pos = idxOfEventDequeuedFromSuffix; pos < queueOfMachine.Size(); ++pos)
                {
                    // insert eventDequeuedFromSuffix at position pos (push the rest to the right)
                    queueEvents.Insert(pos, eventDequeuedFromSuffix);
                    succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);
                    queueEvents.RemoveAt(pos);            // restore previous state
                }
                queueEvents.Add(eventDequeuedFromSuffix); // finally, insert eventDequeuedFromSuffix at end
                succ.AddToAbstractSuccessorsIfInvSat(currIndex, this, abstract_succs, abstract_succs_SW);
            } while (more);
        }
Esempio n. 17
0
 public PrtMachine()
 {
     this.instanceNumber   = 0;
     this.fields           = new List <PrtValue>();
     this.eventValue       = PrtValue.@null;
     this.stateStack       = new PrtStateStack();
     this.invertedFunStack = new PrtFunStack();
     this.continuation     = new PrtContinuation();
     this.currentTrigger   = PrtValue.@null;
     this.currentPayload   = PrtValue.@null;
     this.currentStatus    = PrtMachineStatus.Enabled;
     this.nextSMOperation  = PrtNextStatemachineOperation.ExecuteFunctionOperation;
     this.stateExitReason  = PrtStateExitReason.NotExit;
     this.sends            = new List <PrtEventValue>();
     this.stateImpl        = null;
     this.renamedName      = null;
     this.isSafe           = false;
 }
Esempio n. 18
0
        public PrtImplMachine Clone(StateImpl app)
        {
            var clonedMachine = MakeSkeleton();

            //base class fields
            clonedMachine.instanceNumber = this.instanceNumber;
            foreach (var fd in fields)
            {
                clonedMachine.fields.Add(fd.Clone());
            }
            clonedMachine.eventValue       = this.eventValue;
            clonedMachine.stateStack       = this.stateStack.Clone();
            clonedMachine.invertedFunStack = this.invertedFunStack.Clone();
            clonedMachine.continuation     = this.continuation.Clone();
            clonedMachine.currentTrigger   = this.currentTrigger;
            clonedMachine.currentPayload   = this.currentPayload.Clone();

            clonedMachine.currentStatus   = this.currentStatus;
            clonedMachine.nextSMOperation = this.nextSMOperation;
            clonedMachine.stateExitReason = this.stateExitReason;
            clonedMachine.sends           = this.sends;
            clonedMachine.renamedName     = this.renamedName;
            clonedMachine.isSafe          = this.isSafe;
            clonedMachine.stateImpl       = app;

            //impl class fields
            clonedMachine.eventQueue = this.eventQueue.Clone();
            foreach (var ev in this.receiveSet)
            {
                clonedMachine.receiveSet.Add(ev);
            }
            clonedMachine.maxBufferSize = this.maxBufferSize;
            clonedMachine.doAssume      = this.doAssume;
            clonedMachine.self          = new PrtInterfaceValue(clonedMachine, this.self.permissions);


            return(clonedMachine);
        }
Esempio n. 19
0
 public abstract int NextInstanceNumber(StateImpl app);
Esempio n. 20
0
 public abstract void Execute(StateImpl application, PrtMachine parent);
Esempio n. 21
0
 public override void Execute(StateImpl application, PrtMachine parent)
 {
     throw new NotImplementedException();
 }
Esempio n. 22
0
 public virtual void Resolve(StateImpl state)
 {
 }
Esempio n. 23
0
 public void Resolve(StateImpl state)
 {
     retVal.Resolve(state);
     retLocals.ForEach(l => l.Resolve(state));
 }
Esempio n. 24
0
 public override void Resolve(StateImpl state)
 {
     fieldValues.ForEach(f => f.Resolve(state));
 }
Esempio n. 25
0
 public override void Resolve(StateImpl state)
 {
     elements.ForEach(f => f.Resolve(state));
 }
Esempio n. 26
0
 public void Resolve(StateImpl state)
 {
     locals.ForEach(l => l.Resolve(state));
 }
Esempio n. 27
0
 public void Resolve(StateImpl state)
 {
     events.ForEach(n => n.Resolve(state));
 }
Esempio n. 28
0
 public void Resolve(StateImpl state)
 {
     key.Resolve(state);
 }
Esempio n. 29
0
 public override void Resolve(StateImpl state)
 {
     mach = state.ImplMachines.First(m => m.renamedName == mach.renamedName && m.instanceNumber == mach.instanceNumber);
 }
Esempio n. 30
0
 public void Resolve(StateImpl state)
 {
     ev.Resolve(state);
     arg.Resolve(state);
 }