Esempio n. 1
0
        public override Dependency GetOppositeDependencies()
        {
            ApplyOver newF = null;

            if (_valid)
            {
                newF             = new ApplyOver(_listGroup, _trueIf);
                newF._lineNumber = _lineNumber;
            }
            else
            {
                newF = new ApplyOver(_listGroupName, _lineNumber, _trueIf);
            }

            switch (_trueIf)
            {
            case ApplyType.Any:
                newF._trueIf = ApplyType.None;
                break;

            case ApplyType.None:
                newF._trueIf = ApplyType.Any;
                break;

            case ApplyType.All:
                newF._trueIf = ApplyType.Any;
                // also negate formulas below
                break;
            }

            IEnumerator e = GetDependencies();

            while (e.MoveNext())
            {
                if (_trueIf == ApplyType.All)
                {
                    newF.AddDependency(((Dependency)e.Current).GetOppositeDependencies());
                }
                else
                {
                    newF.AddDependency((Dependency)e.Current);
                }
            }

            return(newF);
        }
Esempio n. 2
0
        public override Dependency Simplify()
        {
            if (IsEmpty())
            {
                return(null);
            }

            ApplyOver newF = null;

            if (_valid)
            {
                newF             = new ApplyOver(_listGroup, _trueIf);
                newF._lineNumber = _lineNumber;
            }
            else
            {
                newF = new ApplyOver(_listGroupName, _lineNumber, _trueIf);
            }

            IEnumerator e = GetDependencies();

            while (e.MoveNext())
            {
                Dependency d = ((Dependency)e.Current).Simplify();

                if (d is FalseDependency)
                {
                    return((Dependency)e.Current);
                }
                else if (d.IsFormula())
                {
                    Formula df = (Formula)d;

                    if (d is AND)
                    {
                        // collapse nested AND formulas into each other
                        IEnumerator e2 = df.GetDependencies();
                        while (e2.MoveNext())
                        {
                            newF.AddDependency((Dependency)e2.Current);
                        }
                    }
                    else if (d != null)
                    {
                        newF.AddDependency(d);
                    }
                }
                else if (!(d is TrueDependency))
                {
                    // remove TrueDependencies from within an AND
                    newF.AddDependency((Dependency)e.Current);
                }
            }

            if (newF.Count == 0)
            {
                return(null);
            }
            else
            {
                return(newF);
            }
        }