Example #1
0
        public BaseState GetLastState()
        {
            BaseState res;

            if (states.Count == 0)
            {
                res = Controller.GetInstance().RuningState;
            }
            else
            {
                TemporaryState expectedValidState = states.Dequeue();

                while ((Time.time - expectedValidState.startTime) > stateLifeTime)
                {
                    if (states.Count >= 1)
                    {
                        expectedValidState = states.Dequeue();
                    }
                    else
                    {
                        expectedValidState.state = new RuningState(Controller.GetInstance());
                        break;
                    }
                }
                res = expectedValidState.state;
            }
            return(res);
        }
        /// <summary>
        /// Used by the symbolic evaluator to obtain the symbolic value of <paramref name="id"/>.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Expression GetValue(Identifier id)
        {
            var        reg = id.Storage as RegisterStorage;
            Expression value;

            if (reg != null && RegisterState.TryGetValue(reg, out value))
            {
                return(value);
            }
            var tmp = id.Storage as TemporaryStorage;

            if (tmp != null && TemporaryState.TryGetValue(tmp, out value))
            {
                return(value);
            }
            var local = id.Storage as StackLocalStorage;

            if (local != null)
            {
                return(GetStackValue(local.StackOffset, local.DataType));
            }

            //$REVIEW: this is cheating a little; some flags could
            // actually have been set to 0 or 1. The problem is we
            // are doing "poor man's value propagation", and should
            // really be doing this after SSA transformation has been
            // done on the code.
            if (id.Storage is FlagGroupStorage)
            {
                return(Constant.Invalid);
            }
            return(id);
        }
Example #3
0
        public void PutState(BaseState newState)
        {
            int countValidStates = 0;

            foreach (TemporaryState one in states)
            {
                if ((Time.time - one.startTime) < stateLifeTime)
                {
                    countValidStates++;
                }
            }


            if (countValidStates < maxStates)
            {
                TemporaryState containerNewState = new TemporaryState(newState, Time.time);
                bool           existSameState    = false;
                float          timeOfExistedSame = 0f;

                foreach (TemporaryState one in states)
                {
                    if (one.state.Equals(newState))
                    {
                        existSameState    = true;
                        timeOfExistedSame = Time.time - one.startTime;
                        break;
                    }
                }



                if ((existSameState && (timeOfExistedSame > stateLifeTime)) || !existSameState)
                {
                    states.Enqueue(containerNewState);
                }
            }
        }
Example #4
0
 void ITemporaryState.OnDeactivation(TemporaryState state)
 {
     freezableDelegate.OnUnfreeze(this);
 }
Example #5
0
 void ITemporaryState.OnActivation(TemporaryState state, float duration)
 {
     freezableDelegate.OnFreeze(this, duration);
 }
Example #6
0
 bool ITemporaryState.CanDeactivate(TemporaryState state)
 {
     return(freezableDelegate.CanUnfreeze(this));
 }
Example #7
0
 bool ITemporaryState.CanActivate(TemporaryState state, ref float duration)
 {
     return(freezableDelegate.CanFreeze(this, ref duration));
 }