Example #1
0
        public bool Idempotency()
        {
            int j = Branches.Length;

            for (var k = 0; k < Branches.Length; k++)
            {
                if ((Branches[k] == null) || (!(Branches[k] is ParameterLogicExpression)))
                    continue;
                var localLogicLeaf1 = (ParameterLogicExpression) Branches[k];

                for (int n = k + 1; n < Branches.Length; n++)
                {
                    if ((Branches[n] == null) || (!(Branches[n] is ParameterLogicExpression)))
                        continue;
                    var localLogicLeaf2 = (ParameterLogicExpression) Branches[n];

                    if (!localLogicLeaf1.Name.Equals(localLogicLeaf2.Name))
                        continue;
                    if (Branches[k].Negated != Branches[n].Negated)
                    {
                        switch (Operator)
                        {
                            case Operator.And:
                                Branches[k] = new LogicValue(false);
                                break;
                            case Operator.Or:
                                Branches[k] = new LogicValue(true);
                                break;
                            default:
                                Console.Error.WriteLine("Software Error: Unimplemented operator: " + Operator);
                                break;
                        }
                    }

                    Branches[n] = null;
                    j--;
                }
            }

            if (j == Branches.Length)
                return false;
            if (j == 1)
            {
                var localObject1 = Parent;

                if (localObject1 != null)
                {
                    localObject1.SetBranch(Branches[0], GetPositionInParent());
                }
            }
            else
            {

                var localObject = new LogicExpression[j];
                j = 0;

                foreach (LogicExpression t in Branches.Where(t => t != null))
                {
                    localObject[j++] = t;
                }
                Branches = localObject;
            }
            return true;
        }
Example #2
0
        public void CarryOutBoolValues()
        {
            var expression = _next;

            int i = expression.GetDepth();

            for (int m = 2; m <= i; m++)
            {
                int k = 0;
                int j = 0;
                LogicExpression localLogicExpression;
                while ((localLogicExpression = expression.GetSubExpression(m, j)) != null)
                {
                    var localLogicBranch1 = (OperatorExpression) localLogicExpression;
                    BoolResolution n = LogicHandler.GetBoolResolution(localLogicBranch1);
                    if (n == BoolResolution.BoolRemoveBoolValues)
                    {
                        LogicExpression[] arrayOfLogicExpression = localLogicBranch1.Branches;
                        int i1 = arrayOfLogicExpression.Length;

                        foreach (LogicExpression t in arrayOfLogicExpression.Where(t => (t is LogicValue)))
                        {
                            i1--;
                        }
                        if (i1 == 1)
                        {
                            var localObject2 = arrayOfLogicExpression.FirstOrDefault(t => (!(t is LogicValue)));

                            OperatorExpression localLogicBranch2 = localLogicExpression.Parent;

                            if (localLogicBranch2 == null)
                            {
                                expression = localObject2;
                                localObject2.SetParent(null, -1);
                            }
                            else
                            {
                                localLogicBranch2.SetBranch(localObject2, localLogicExpression.GetPositionInParent());
                            }
                        }
                        else
                        {
                            var expressions = new LogicExpression[i1];

                            int i4 = 0;

                            foreach (LogicExpression t in arrayOfLogicExpression.Where(t => !(t is LogicValue)))
                            {
                                expressions[i4++] = t;
                            }
                            localLogicBranch1.Branches = expressions;

                            j++;
                        }

                        k = 1;
                    }
                    else if ((n == BoolResolution.BoolResolveTrue) || (n == BoolResolution.BoolResolveFalse))
                    {
                        bool @bool = n == BoolResolution.BoolResolveTrue;
                        var localLogicValue = new LogicValue(@bool);

                        var localObject2 = localLogicBranch1.Parent;

                        if (localObject2 == null)
                        {
                            localLogicValue.SetParent(null, -1);
                            _next = localLogicValue.Clone();

                            AddStep(localLogicValue, "Resolved bool values");
                            break;
                        }

                        localObject2.SetBranch(localLogicValue, localLogicBranch1.GetPositionInParent());

                        k = 1;
                    }
                    else
                    {
                        j++;
                    }
                }

                if (k == 0)
                    continue;
                _next = expression.Clone();

                AddStep(expression, "Removed redundant bool values");
                expression = _next;
            }
        }