Ejemplo n.º 1
0
        public virtual bool Contains(Antlr4.Runtime.Atn.ATNConfig subconfig)
        {
            if (this.State.stateNumber != subconfig.State.stateNumber || this.Alt != subconfig
                .Alt || !this.SemanticContext.Equals(subconfig.SemanticContext))
            {
                return(false);
            }
            Stack <PredictionContext> leftWorkList  = new Stack <PredictionContext>();
            Stack <PredictionContext> rightWorkList = new Stack <PredictionContext>();

            leftWorkList.Push(Context);
            rightWorkList.Push(subconfig.Context);
            while (leftWorkList.Count > 0)
            {
                PredictionContext left  = leftWorkList.Pop();
                PredictionContext right = rightWorkList.Pop();
                if (left == right)
                {
                    return(true);
                }
                if (left.Size < right.Size)
                {
                    return(false);
                }
                if (right.IsEmpty)
                {
                    return(left.HasEmpty);
                }
                else
                {
                    for (int i = 0; i < right.Size; i++)
                    {
                        int index = left.FindReturnState(right.GetReturnState(i));
                        if (index < 0)
                        {
                            // assumes invokingStates has no duplicate entries
                            return(false);
                        }
                        leftWorkList.Push(left.GetParent(index));
                        rightWorkList.Push(right.GetParent(i));
                    }
                }
            }
            return(false);
        }