Exemple #1
0
        public PySwitchSection Simplify(IPySimplifier s, out bool wasChanged)
        {
            wasChanged = false;
            var nLabels = new List <PySwitchLabel>();

            foreach (var lab in Labels)
            {
                nLabels.Add(lab.Simplify(s, out var labelWasChanged));
                if (labelWasChanged)
                {
                    wasChanged = true;
                }
            }

            var nStatement = s.Simplify(Statement);

            if (!PySourceBase.EqualCode(nStatement, Statement))
            {
                wasChanged = true;
            }
            if (!wasChanged)
            {
                return(this);
            }
            return(new PySwitchSection
            {
                Labels = nLabels.ToArray(),
                Statement = nStatement
            });
        }
Exemple #2
0
        public override IPyStatement Simplify(IPySimplifier s)
        {
            var changed = false;
            var e1      = s.Simplify(Expression);

            if (!EqualCode(e1, Expression))
            {
                changed = true;
            }

            var s1 = new List <PySwitchSection>();

            foreach (var i in Sections)
            {
                bool wasChanged;
                var  n = i.Simplify(s, out wasChanged);
                if (wasChanged)
                {
                    changed = true;
                }
                s1.Add(n);
            }

            if (!changed)
            {
                return(this);
            }
            return(new PySwitchStatement
            {
                Expression = e1,
                Sections = s1
            });
        }
        public override IPyStatement Simplify(IPySimplifier s)
        {
            if (ReturnValue == null)
            {
                return(this);
            }
            var newReturnValue = s.Simplify(ReturnValue);

            return(ReturnValue == newReturnValue ? this : new PyReturnStatement(newReturnValue));
        }
        public override IPyStatement Simplify(IPySimplifier s)
        {
            var newCondition = s.Simplify(Condition);
            var newStatement = s.Simplify(Statement);

            if (newCondition == Condition && newStatement == Statement)
            {
                return(this);
            }
            return(new PyWhileStatement(newCondition, newStatement));
        }
Exemple #5
0
        public override IPyStatement Simplify(IPySimplifier s)
        {
            var newIfTrue    = s.Simplify(_ifTrue);
            var newIfFalse   = s.Simplify(_ifFalse);
            var newCondition = s.Simplify(Condition);

            if (newIfTrue == _ifTrue && newIfFalse == _ifFalse && newCondition == Condition)
            {
                return(this);
            }
            return(new PyIfStatement(newCondition, newIfTrue, newIfFalse));
        }
Exemple #6
0
        public override IPyStatement Simplify(IPySimplifier s)
        {
            var collection = s.Simplify(Collection);
            var statement  = s.Simplify(Statement);

            if (collection == Collection && statement == Statement)
            {
                return(this);
            }
            if (string.IsNullOrEmpty(_keyVarname))
            {
                return(new PyForEachStatement(_valueVarname, collection, statement));
            }
            return(new PyForEachStatement(_keyVarname, _valueVarname, collection, statement));
        }
Exemple #7
0
        public PySwitchLabel Simplify(IPySimplifier s, out bool wasChanged)
        {
            wasChanged = false;
            if (IsDefault)
            {
                return(this);
            }
            var e1 = s.Simplify(Value);

            wasChanged = !PySourceBase.EqualCode(e1, Value);
            if (wasChanged)
            {
                return(new PySwitchLabel(e1));
            }
            return(this);
        }
Exemple #8
0
        public override IPyStatement Simplify(IPySimplifier s)
        {
            var initVariables = InitVariables == null
                ? null
                : InitVariables.Select(u => s.Simplify(u)).Cast <PyAssignExpression>().ToArray();
            var condition    = s.Simplify(Condition);
            var statement    = s.Simplify(Statement);
            var incrementors = Incrementors == null
                ? null
                : Incrementors.Select(u => s.Simplify(u)).ToArray();
            var theSame = EqualCode(condition, Condition) && EqualCode(statement, Statement) &&
                          EqualCode_Array(initVariables, InitVariables) &&
                          EqualCode_Array(incrementors, Incrementors);

            if (theSame)
            {
                return(this);
            }
            return(new PyForStatement(initVariables, condition, statement, incrementors));
        }
Exemple #9
0
 public virtual IPyStatement Simplify(IPySimplifier s)
 {
     return(this);
 }