AlphaConvertArglist() static private method

Substitutes occurances of newVars for all occurances of oldVars in argList. Returns new array, if substitutions were made, the original array if not. Original array is not modified
static private AlphaConvertArglist ( object argList, List oldVars, LogicVariable newVars, PrologContext context, bool evalIndexicals ) : object[]
argList object
oldVars List
newVars LogicVariable
context PrologContext
evalIndexicals bool
return object[]
        internal override IEnumerable <CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
        {
            object[] goal1Args = null;
            var      newVars   = new LogicVariable[FreeVariables.Count];

            object[] newArgs = Term.AlphaConvertArglist(HeadArgs, FreeVariables, newVars, context, true);
            // ReSharper disable UnusedVariable
#pragma warning disable 414, 168, 219
            foreach (bool ignore in Term.UnifyArraysFast(args, newArgs, context))
#pragma warning restore 414, 168, 219
            {
                if (goal1Args == null)
                {
                    goal1Args = Term.AlphaConvertArglist(BodyGoals[0].Arguments, FreeVariables, newVars, context, false);
                }

#pragma warning disable 414, 168, 219
                foreach (CutState ignoreFreeze in context.ProveAllWokenGoals())
#pragma warning restore 414, 168, 219
                {
                    // ReSharper restore UnusedVariable
                    foreach (CutState state1 in context.KnowledgeBase.Prove(BodyGoals[0].Functor, goal1Args, context, parentFrame))
                    {
                        yield return(state1);
                    }
                }
            }
        }
        internal override IEnumerable <CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
        {
            var newVars = new LogicVariable[FreeVariables.Count];

            object[] newArgs = Term.AlphaConvertArglist(HeadArgs, FreeVariables, newVars, context, true);
            // ReSharper disable UnusedVariable
#pragma warning disable 414, 168, 219
            foreach (bool ignore in Term.UnifyArrays(args, newArgs))
#pragma warning restore 414, 168, 219
            {
                // ReSharper restore UnusedVariable
                yield return(CutState.Continue);
            }
        }
        internal override IEnumerable <CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
        {
            object[] goal1Args = null;
            object[] goal2Args = null;
            object[] goal3Args = null;
            object[] goal4Args = null;
            object[] goal5Args = null;
            object[] goal6Args = null;
            object[] goal7Args = null;
            object[] goal8Args = null;

            var newVars = new LogicVariable[FreeVariables.Count];

            object[] newArgs = Term.AlphaConvertArglist(HeadArgs, FreeVariables, newVars, context, true);
// ReSharper disable UnusedVariable
            foreach (bool ignore in Term.UnifyArraysFast(args, newArgs, context))
            {
                if (goal1Args == null)
                {
                    goal1Args = Term.AlphaConvertArglist(BodyGoals[0].Arguments, FreeVariables, newVars, context, false);
                }

                foreach (CutState ignoreFreeze in context.ProveAllWokenGoals())
                {
                    // ReSharper restore UnusedVariable
                    foreach (CutState state1 in context.KnowledgeBase.Prove(BodyGoals[0].Functor, goal1Args, context, parentFrame))
                    {
                        if (state1 == CutState.ForceFail)
                        {
                            yield return(CutState.ForceFail);
                        }
                        if (goal2Args == null)
                        {
                            goal2Args = Term.AlphaConvertArglist(BodyGoals[1].Arguments, FreeVariables, newVars, context, false);
                        }

                        foreach (CutState state2 in context.KnowledgeBase.Prove(BodyGoals[1].Functor, goal2Args, context, parentFrame))
                        {
                            if (state2 == CutState.ForceFail)
                            {
                                yield return(CutState.ForceFail);
                            }
                            if (goal3Args == null)
                            {
                                goal3Args = Term.AlphaConvertArglist(BodyGoals[2].Arguments, FreeVariables, newVars, context, false);
                            }

                            foreach (CutState state3 in context.KnowledgeBase.Prove(BodyGoals[2].Functor, goal3Args, context, parentFrame))
                            {
                                if (state3 == CutState.ForceFail)
                                {
                                    yield return(CutState.ForceFail);
                                }
                                if (goal4Args == null)
                                {
                                    goal4Args = Term.AlphaConvertArglist(BodyGoals[3].Arguments, FreeVariables, newVars, context, false);
                                }

                                foreach (CutState state4 in context.KnowledgeBase.Prove(BodyGoals[3].Functor, goal4Args, context, parentFrame))
                                {
                                    if (state4 == CutState.ForceFail)
                                    {
                                        yield return(CutState.ForceFail);
                                    }
                                    if (goal5Args == null)
                                    {
                                        goal5Args = Term.AlphaConvertArglist(BodyGoals[4].Arguments, FreeVariables, newVars, context, false);
                                    }

                                    foreach (CutState state5 in context.KnowledgeBase.Prove(BodyGoals[4].Functor, goal5Args, context, parentFrame))
                                    {
                                        if (state5 == CutState.ForceFail)
                                        {
                                            yield return(CutState.ForceFail);
                                        }
                                        if (goal6Args == null)
                                        {
                                            goal6Args = Term.AlphaConvertArglist(BodyGoals[5].Arguments, FreeVariables, newVars, context, false);
                                        }

                                        foreach (CutState state6 in context.KnowledgeBase.Prove(BodyGoals[5].Functor, goal6Args, context, parentFrame))
                                        {
                                            if (state6 == CutState.ForceFail)
                                            {
                                                yield return(CutState.ForceFail);
                                            }
                                            if (goal7Args == null)
                                            {
                                                goal7Args = Term.AlphaConvertArglist(BodyGoals[6].Arguments, FreeVariables, newVars, context, false);
                                            }

                                            foreach (CutState state7 in context.KnowledgeBase.Prove(BodyGoals[6].Functor, goal7Args, context, parentFrame))
                                            {
                                                if (state7 == CutState.ForceFail)
                                                {
                                                    yield return(CutState.ForceFail);
                                                }
                                                if (goal8Args == null)
                                                {
                                                    goal8Args = Term.AlphaConvertArglist(BodyGoals[7].Arguments, FreeVariables, newVars, context, false);
                                                }

                                                foreach (CutState state8 in context.KnowledgeBase.Prove(BodyGoals[7].Functor, goal8Args, context, parentFrame))
                                                {
                                                    yield return(state8);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }